Are there any good Tower Defense game that show FIRING?!
And I mean real Tower Defense, as in AUTO TOWERS!!!
Oh, I'm getting off topic. CAN ANYONE get me a good Script for making Towers shoot at the enemies? I'm trying to make one, but I'm not certain how the heck to get the towers to shoot at the closest enemy (and with 100 Tower Limit, thats a lot of scripting)
Offline
I'm a bit rusty, but I think I can help. You are gonna have to modify this code some, but I think it should do the trick.
you are gonna need a ring sprite around the tower.
for the first if, make it if the enemy touches the ring.
point at towards the enemy and repeat until the enemy isnt touching.
This should make the tower point towards the enemy while the enemy is in range. You can only have one enemy in range at a time, otherwise it runs into trouble. For the bullet, you make a sprite and have it go to the tower. You will need one bullet for each tower. when the enemy touches the ring, broadcast something. When the bullet receives whatever the broadcast is, make it visible, point it towards teh enemy, and have it move towards teh enemy until it hits. keep pointing it at teh enemy. When it hits, reset it. You might have to set the enemy to broadcast the message every two seconds while it is hitting the ring to make it fire more than once. Does taht help?
Offline
@fishmonk
That will be difficult. I think I can modify that, just slightly, so that it can have more then one enemy in range. However, it might not work. And making it so that only one would be in range would be difficult, if not impossible.
As for the ring idea, that's perfect, but difficult. To have it be just the right size to match the range... hard.
Thanks for the help, all the same
Offline
A tower defense game will not run very well on Scratch. But I will tell you how to properly write the scripts for the towers.
First of all you use know how to properly check series of sprites.
Say we have baddies 1 to 25
We do this, to check which baddie is closest and within range.
//on tower
set i to 0
set nearest_baddie to (baddie1)
repeat 25{
change i by 1
if (distance to (join (baddie)(i)) < distance to (nearest_baddie)){
set nearest_baddie to (join (baddie) to (i))
}
}
}
When you are done with that, to fire at the enemy you do this. Each tower needs its own personal bullet for this.
//on tower
if (distance to nearest_baddie < shoot_radius){
broadcast shoot bullet1 //change the number depending on what tower is used
}
Now from this you can see that a tower defense game would require a lot of loops to check things. Scratch performs very poorly and slowly with loops which is why this game won't really work out in scratch.
Offline
My script EDITED:
baddie1:
<when green flag clicked>
<forever>
<if><( <distance to[ tower <<> {range of tower} )>
<add [baddie1] to list [threats]>
tower:
<when green flag clicked>
<forever>
<if><< <not><(length of list threats <=> 0 )> >>
<point towards( item (length of list threats) of list threats)
<broadcast[ shoot ]and wait c>
Last edited by ArrowHead (2011-01-03 19:21:07)
Offline
yo move it to requests
Offline
In fact, I'm making a tower defense game right now! Maybe once I'm done you can look at the script.
Offline
ArrowHead wrote:
My script EDITED:
baddie1:
<when green flag clicked>
<forever>
<if><( <distance to[ tower <<> {range of tower} )>
<add [baddie1] to list [threats]>
tower:
<when green flag clicked>
<forever>
<if><< <not><(length of list threats <=> 0 )> >>
<point towards( item (length of list threats) of list threats)
<broadcast[ shoot ]and wait c>
The problem with your script is that if the baddie is very far away, but visible, he won't be shot at, (won't be on the list of threats).
Offline
This thread is pretty old ...
But, I wrote a tower defense game.
http://scratch.mit.edu/projects/BoltBait/1897019
If you want to know how it works, I posted it in pieces to my test account here:
http://scratch.mit.edu/users/BoltTest
Offline
Thescratch3 wrote:
ArrowHead wrote:
My script EDITED:
baddie1:when gf clicked forever if<(distance to[tower v]) < (range of tower) > add [baddie1] to [threats v]tower:when gf clicked forever if<not<(length of [list threats v]) = (0)>> point towards( item (length of list [threats v]) of list [threats v]) broadcast[ shoot v]and waitThe problem with your script is that if the baddie is very far away, but visible, he won't be shot at, (won't be on the list of threats).
well, isn't that the point of having range? there is always the possibility of very high range (65,536 should be enough)
Offline