Star fighter game

hi kirupa-folk,

a friend of mine and me are together working on a kinda “star fighter” game in flash. you know, you’ve your space-ship and you’re flying through a level and trying to destroy as much enemy-ships as your fingers let you

i got to a point, where i may not be able to get further without some help of you experts :slight_smile:

my problem:
in the level you are flying through with your space-ship is a number of **n **enemy-space-ships. you’re able to fire bullets from your own space-ship, which should hit the other enemy-space-ships to destroy them.

so far, so good, but how can i discover, which bullet hits which enemy-space-ship? here is my code-snippet:

 ActionScript Code:
 [FONT=Courier New][LEFT][COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR] [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]hitTest[/COLOR][COLOR=#000000]([/COLOR]level1_MC[COLOR=#000000][[/COLOR][COLOR=#ff0000]"enemy_MC"[/COLOR] + i[COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR][INDENT]      removeMovieClip[COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR][COLOR=#000000])[/COLOR];

[/INDENT][INDENT] level1_MC[COLOR=#000000][[/COLOR][COLOR=#ff0000]“enemy_MC”[/COLOR] + i[COLOR=#000000]][/COLOR].[COLOR=#0000ff]_visible[/COLOR] = [COLOR=#000000]false[/COLOR]; [COLOR=#808080]// replace with removeMovieClip();[/COLOR]
[/INDENT][INDENT] delete [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]onEnterFrame[/COLOR];
[/INDENT][COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]

ok, this code-snippet is nested in an onEnterFrame-statement…the variable i is incremented every time, a new bullet is fired off. understandably, with this code i’m just able to discover whether a bullet hits one specific enemy-ship, but i’ve to check, if a single bullet hits all enemy-space-ships in the entire level, and if this happened, then the enemy-space-ship, which was hitted should be destroyed…

i hope, you know what i mean, sry for my terrible english! :ne:

maybe some of you, can help me out in a theoretical approach, would be very very cool…!!!

Not that I know the practical code I would think in the lines of an For loop. That every frame checks if the bullet hits ship one, two , three. like


for( var n = i; n <= numberOfEnemies; n++){
if( this.hitTest(level1_MC["enemy_MC" + n]) ) {

    removeMovieClip(this);

    level1_MC["enemy_MC" + n]._visible = false; // replace with removeMovieClip();

    delete this.onEnterFrame;

}
}

or something like that :confused:

hey joppe,

haha…you’re the man!!! it works perfect!!!

haha, the funny thing is, that i also thought of a for-loop possibility,
but with my version of the for-loop, i created an endless one by mistake
and my pc hung up…hahaha

but thx, anyway!!! i’m loving Kirupa from day to day more…:beam:

Thats great :slight_smile: