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
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
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
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 <pick random( -100 )to( 100 )> )y
<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