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

#1 2009-06-21 12:44:31

Yakkers
Scratcher
Registered: 2007-06-03
Posts: 9

Need help with a coding bullets

My game will have a set of respawning enemies and I want to have a gun without a moving projectile. My idea was have the bullet a line the length of the screen pointing in the direction fired, but I only want it to hit one target. Is there any way to do this and have it check which of the hit enemies is closest to you and only damage that one?<point

Offline

 

#2 2009-06-21 14:20:51

Oneandonly
Scratcher
Registered: 2009-02-07
Posts: 100+

Re: Need help with a coding bullets

Probably not. In your case, if you want it to hit one target, you might want to use a moving projectile. Maybe make 2 or 3 that will fire after each other. Like, fire one, fire two, fire three, fire one, etc.

Offline

 

#3 2009-06-21 17:57:06

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Need help with a coding bullets

There is a way to do so.
Say you have 3 enemies on screen at once. You have three variabes like so in a forever script on the gun sprite:
<forever>
<set{ En 1 }to( <distance to[ En 1]
<set{ En 2 }to( <distance to[ En 2]
<set{ En 3 }to( <distance to[ En 3]

Then you put this script on the bullet:
<when[ Firing ]key pressed>
<point in direction( direstion of gun
<if> <<  <touching[ En 1 <and> <<  <not> << <touching[ En 2 <or> <touching[ En 3  >> >> >>

Repeat for all enemys

Then:
If touching En 1 and En 2 and not en 3
If Var En 1< Var En 2
Kill En1
Else Kill En 2

Repeat that for all enemys

And hopefully youll get the rest.

I hope this helps.

Offline

 

#4 2009-06-23 23:38:03

Yakkers
Scratcher
Registered: 2007-06-03
Posts: 9

Re: Need help with a coding bullets

Ah, that seems like it would work. Only thing is I would be having 10 to 20 enemies, so that's a lot of scripting.

Offline

 

#5 2009-06-24 10:08:28

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Need help with a coding bullets

Bullet:
[blocks]
<when I receive[ Fire ] >
<point in direction( of Player ) >
<repeat until><( <{ Hit }> <=> 1 )> >
<move( 5 )steps>
<end>
[/blocks]
Enemies (Enemy1 Enemy2, etc.):
[blocks]
<forever>
<if><touching[ Bullet ] > >
<switch to costume[ Dead ] >
<wait( 5 )secsc>
<hide>
<wait( <pick random( 1 )to( 10 )>) secsc>
<go to x sad  <pick random( -100 )to( 100 )> )y sad  <pick random( -100 )to( 100 )> )>
<switch to costume[ Not Dead ]>
<show>
<end>
(Add what you want here.)
<end>
[/blocks]
Not much but does work. (Hopefully.)

Last edited by Magnie (2009-06-24 10:09:47)

Offline

 

Board footer