Tower Defense‎ game Army Turrent - help please

I am working on a small Tower Defense / Army Turret example game.?

My question is how do you get the Tower / Turret to know when the enemy is in range and start firing?

I was thinking of useing physics.queryRegion() or physics.rayCast.

But I wanted to get some feedback from others on this.

Also The game could have many towers and many enemys and would hate to manage lots of rayCast.

Side Note:

Next I’ll have to get it to turn towards the enemy

Thanks in advance.

Larry

TandG Apps published an interesting tutorial on this, as has Webdevils. Neither are current so you’re going to need to update them to work with Graphics 2.0, but the concepts still work and would let you get well on your way to getting your game made.

I personally the physics interactions would add quite a bit of overhead to the game logic when you can just incorporate something within your gameloop, but I haven’t attempted it so I have zero idea. 

YMMV HTH.

Yeah I have seen both of those and mine does have a Ending Base area where they enemy is trying to reach like in TandG’s example
But what about a tower in the middle of the field that is able to shoot in all direction?
When an enemy gets close enough I want it to react and start shooting it.
Are you thinking that in the Game Loop that it would be better to loop through a table and of enemy’s and check their xy locations to each and every tower on the screen?
 

Larry

TandG’s example is different than their old one.

The look they are doing exactly what I was asking you about.

In the game loop checking position in relatiion to each enemy in a loop…

I’ll give that a shot.

Thanks

Larry

Here is a simple, non-physics way of determining the distance between two objects:

local function distBetween( point1, point2 )     local xFactor = point2.x-point1.x ; local yFactor = point2.y-point1.y     local dist = math\_sqrt((xFactor\*xFactor) + (yFactor\*yFactor))     return dist end

Then if your range is say 100px, you could say:

if distBetween(tower, creep) < 100 then

    – fire away

end

Rob

TandG Apps published an interesting tutorial on this, as has Webdevils. Neither are current so you’re going to need to update them to work with Graphics 2.0, but the concepts still work and would let you get well on your way to getting your game made.

I personally the physics interactions would add quite a bit of overhead to the game logic when you can just incorporate something within your gameloop, but I haven’t attempted it so I have zero idea. 

YMMV HTH.

Yeah I have seen both of those and mine does have a Ending Base area where they enemy is trying to reach like in TandG’s example
But what about a tower in the middle of the field that is able to shoot in all direction?
When an enemy gets close enough I want it to react and start shooting it.
Are you thinking that in the Game Loop that it would be better to loop through a table and of enemy’s and check their xy locations to each and every tower on the screen?
 

Larry

TandG’s example is different than their old one.

The look they are doing exactly what I was asking you about.

In the game loop checking position in relatiion to each enemy in a loop…

I’ll give that a shot.

Thanks

Larry

Here is a simple, non-physics way of determining the distance between two objects:

local function distBetween( point1, point2 ) &nbsp;&nbsp;&nbsp; local xFactor = point2.x-point1.x ; local yFactor = point2.y-point1.y &nbsp;&nbsp;&nbsp; local dist = math\_sqrt((xFactor\*xFactor) + (yFactor\*yFactor)) &nbsp;&nbsp;&nbsp; return dist end

Then if your range is say 100px, you could say:

if distBetween(tower, creep) < 100 then

    – fire away

end

Rob