Page 1 of 1

Help needed on making a TD game!

PostPosted: Fri Jul 18, 2008 1:48 pm
by 98700
I am in the process of making a tower defense game and is was wondering if anyone could help me on how to make my turrets shoot when the badguy is in range. Thanks in advance. :D

Re: Help needed on making a TD game!

PostPosted: Fri Jul 18, 2008 11:26 pm
by feral
Your best bet is to use the distance function...


distance: Returns the distance between points (x1, y1) and (x2, y2).
example

Code: Select all
range=distance(turret.x, turret.y, badguy.x, badguy.y);



are your "badguys" cloned, or individuals ?

Re: Help needed on making a TD game!

PostPosted: Sun Jul 20, 2008 9:51 pm
by 98700
im sure im gonna make em clones

Re: Help needed on making a TD game!

PostPosted: Tue Jul 29, 2008 2:24 am
by 98700
Ok I used the code now how do i make the turrets turn and shoot the enemy when in range?

Re: Help needed on making a TD game!

PostPosted: Tue Jul 29, 2008 3:51 am
by feral
to make the turrents turn towards the enemy you will need to use the direction() function which returns the angle between one point and another.

you will also need to match that up with the right animations

try looking in the moon defender tutorial
http://game-editor.com/tutorials/moonde ... l_eng.html

to shoot when in range it is simply a matter of working out what shooting range is and setting a vaiable like "inrange" and saying something like

if (inrange<range)
{
//do turning and shooting code
}