This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-12-17 14:12:45

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Tower Defense Game Aiming

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.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#2 2009-12-17 14:41:48

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Tower Defense Game Aiming

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.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2009-12-17 15:12:56

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

That will create errors. It would not work.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#4 2009-12-17 15:25:10

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Tower Defense Game Aiming

Well it works for me. What about the method I described isn't working?


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2009-12-17 15:30:18

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

Because it will aim for the farthest. Which could end up being the one farthest down the path or the one that just came into range.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#6 2009-12-17 15:39:33

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Tower Defense Game Aiming

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?


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#7 2009-12-17 15:41:50

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

Trying to make it so it will fire at the closest to goal decreases the chance of having one slip by.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#8 2009-12-17 16:00:10

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Tower Defense Game Aiming

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.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#9 2009-12-17 16:03:51

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Tower Defense Game Aiming

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.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#10 2009-12-17 20:27:11

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

I tried that. That's why I said I wanted it to be simple...


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#11 2009-12-18 06:55:20

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: Tower Defense Game Aiming

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.


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#12 2009-12-18 07:20:26

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

I know who Archmage is. It doesn't matter to me. I know much better programmers then him. I said already, Everything ELSE is done. The aiming is the part I can't get.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#13 2009-12-18 09:50:05

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Tower Defense Game Aiming

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.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#14 2009-12-18 11:36:27

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

Alrighty then.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#15 2009-12-19 02:07:26

Dibbo222
Scratcher
Registered: 2007-11-03
Posts: 100+

Re: Tower Defense Game Aiming

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  tongue


The biggest tower defense game on Scratch?
http://scratch.mit.edu/projects/Dibbo222/929092

Offline

 

#16 2009-12-19 09:19:32

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

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.


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#17 2009-12-19 09:24:21

theThomasG
Scratcher
Registered: 2009-12-16
Posts: 100+

Re: Tower Defense Game Aiming

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

 

#18 2009-12-19 09:59:53

liphttam1
Scratcher
Registered: 2007-05-16
Posts: 30

Re: Tower Defense Game Aiming

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)


http://www.readwritethink.org/lesson_images/lesson936/butteredtoast-200.jpg

Offline

 

#19 2009-12-19 10:11:55

theThomasG
Scratcher
Registered: 2009-12-16
Posts: 100+

Re: Tower Defense Game Aiming

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

 

#20 2009-12-19 21:52:18

Dibbo222
Scratcher
Registered: 2007-11-03
Posts: 100+

Re: Tower Defense Game Aiming

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:

http://i46.tinypic.com/2j9jlj.jpg

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.


The biggest tower defense game on Scratch?
http://scratch.mit.edu/projects/Dibbo222/929092

Offline

 

Board footer