Been working on a TD game, Iv'e seen a bunch of failures, I thought I could do better. I can get everything to work except for one thing.
I need to know how I can program the turrets to shoot the butterfly that is closest to the goal. Any ideas?
In case your wondering its a TD game in space... Against butterfly's. It's about how scientist sent caterpillars into space to see if they could become butterflies.
So, any ideas? Iv'e tried stuff already. Hasn't worked too well.
P.S. try to keep it simple, I don't want scratch flipping out on me.

Offline
What I would do is make each tower check every enemy and see if any are in the tower's shooting range. Then if there are enemies in range, shoot at the one that is farthest from the tower.
Offline
Well it works for me. What about the method I described isn't working?
Offline
It doesn't matter whether it aims for the farthest or closest, just as long as it picks a specific one in range. If its shooting at a target then it is doing its job right?
Offline
Ok, then have each enemy count down to see how close it is to the goal. Then your towers aim for the closest one. This seems like it would be CPU intensive though.
Offline
archmage wrote:
Ok, then have each enemy count down to see how close it is to the goal. Then your towers aim for the closest one. This seems like it would be CPU intensive though.
Yeah that would take a while to calculate.
Offline
liphttam, do you know who archmage is?
anyway. one of the rules of programming is:
2. get it to work before optimizing.
____________________________________---
start out with that idea, get it to work, then get it to work more effieciently.
Offline
cds56 wrote:
liphttam, do you know who archmage is?
anyway. one of the rules of programming is:
2. get it to work before optimizing.
____________________________________---
start out with that idea, get it to work, then get it to work more effieciently.
Yeah, in truth I am not that good with code. Its just a hobby.
Anyways, liphttam1, I think the best solution is to post your non working or partially working scripts and see if people can find solutions.
Offline
I'm making a (huge) tower defense game at the moment. This is how i got around the problem above:
Say there were 10 enemies in a level. I would name each of them E1, E2 .. E10. E1 is released first so it is the closest to the goal (E10 the furthest). Then, with a nice script on my 'turret' sprite, it checks if E1 is in range. If it is, it shoots at it, if it's not, it checks if E2 is in range. If E2 is in range, it shoots at it, THEN it checks if now E1 is in range, if it's not, it will shoot at E2 again. Hypothetically, after E2 having been shot twice, E1 has now entered the range of that tower. So, because after every shot, the 'turret' checks if anything preceding it is in range, it will now leave E2 alone and shoot at E1, untill E1 is out of range or has died. If you managed to follow this so far, I have done this using variables and the "join ( ) ( )" blocks to continually check if another enemy, that has a lower NUMBER, is in range.
That could be a bit hard to follow, but it works for me
Offline
liphttam1 wrote:
Been working on a TD game, Iv'e seen a bunch of failures, I thought I could do better. I can get everything to work except for one thing.
I need to know how I can program the turrets to shoot the butterfly that is closest to the goal. Any ideas?
In case your wondering its a TD game in space... Against butterfly's. It's about how scientist sent caterpillars into space to see if they could become butterflies.
So, any ideas? Iv'e tried stuff already. Hasn't worked too well.
P.S. try to keep it simple, I don't want scratch flipping out on me.
Maybe you should stop working on the project for a little while and then, later try to program it. That is what I did when I had trouble with something on scratch! Hope that helps!
Offline
Can't, I think I might use it as a final project for GameProggraming course I'm taking. I thought we would use adobe flash though.
[blocks]
<switch to costume[ SadFace
[/blocks]
Last edited by liphttam1 (2009-12-19 10:01:33)

Offline
liphttam1 wrote:
Can't, I think I might use it as a final project for GameProggraming course I'm taking. I thought we would use adobe flash though.
[blocks]
<switch to costume[ SadFace
[/blocks]
Adobe Flash is way harder just too tell you. Stick with a easier game maybe?
Offline
liphttam1 wrote:
I understood it. I didn't want to resort to that, but if there is no easier way, that's what I will need to do.
It does not take too long to code. This is how I did it:
The variable "Plane" is a variable only used with this sprite, and this script of this sprite. Same with "Current Plane".
( [Plane#] of [Buttons] ) -- This is how many planes (my form of enemies) there are in the current level.
<broadcast[ B1- -- This tells the bullet to shoot.
Any troubles with this script, just ask. My tower defense game will be out soon.
Offline