# Multiple enemies

**URL:** <https://forum.kirupa.com/t/multiple-enemies/193317>\
**Category:** flash\
**Created:** [July 12, 2006, 4:24pm UTC](https://forum.kirupa.com/t/multiple-enemies/193317 "2006-07-12T16:24:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reachground](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/reachground/32/2106_2.png) [@reachground](https://forum.kirupa.com/u/reachground)\
**Post date:** [July 12, 2006, 4:24pm UTC](https://forum.kirupa.com/t/multiple-enemies/193317/1 "2006-07-12T16:24:30Z")

</div>

Hello again!

Here’s what I’d like some help with:

1. Add multiple enemies.
2. When a bullet hits an enemy they should both dissapear.
3. A moveable background (stacked in infinity).  
…and if it’s not to much to ask
4. After a while, change enemies that are a bit harder to kill.

Here’s the code now:

var mySound=new Sound();  
mySound.setVolume(“20”);  
mySound.loadSound(“song.mp3”,true);

\_root.score = 0;

chaosCopter\_mc.onEnterFrame = function() {  
if (Key.isDown(68)) {  
this.\_x += 10;  
if (this.\_x\>850) {  
this.\_x = 850;  
}  
}  
if (Key.isDown(65)) {  
this.\_x -= 10;  
if (this.\_x\<50) {  
this.\_x = 50;  
}  
}  
if (Key.isDown(87)) {  
this.\_y -= 10;  
if (this.\_y\<50) {  
this.\_y = 50;  
}  
}  
if (Key.isDown(83)) {  
this.\_y += 10;  
if (this.\_y\>655) {  
this.\_y = 655;  
}  
}  
if (this.hitTest(b1)) {  
// chaosCopter\_mc.\_y = 600;  
// chaosCopter\_mc.\_x = 500;  
\_root.score -= 1000;

}  
arrowX = this.\_x;  
arrowY = this.\_y;  
if (Key.isDown(Key.ENTER)) {  
chaosFire();  
} else {  
allowFire = 1;  
}  
}

var i:Number = 1;  
function chaosFire() {  
if (allowFire == 1) {  
i += 1;  
var newname = “chaosFire\_mc”+i;  
\_root.attachMovie(“chaosFire\_mc”, newname, i);  
\_root[newname].\_y = \_root.chaosCopter\_mc.\_y+2;  
\_root[newname].\_x = \_root.chaosCopter\_mc.\_x-19;  
allowFire = 0;  
\_root[newname].onEnterFrame = function() {  
var bullet\_speed = 10;  
this.\_y -= bullet\_speed;  
if (this.\_y\<0) {  
this.removeMovieClip();  
} else {  
if (this.hitTest(b1)) {  
\_root.score += 1000;  
this.removeMovieClip();  
}  
}  
}  
}  
}

b1.onEnterFrame = function(){  
this.\_y += 4;  
this.\_x += 1;

if (this.\_y \> 850){  
this.\_y = -15;  
this.\_x = random(800);  
}else{  
if (this.\_x \> 1100){  
this.\_y = -15;  
this.\_x = random(800);  
}else{  
if (this.hitTest(chaosCopter\_mc)) {  
}  
}  
}  
}

As you can see, only one enemy. The bullets dissapear when they hit the enemy and 1000 points are added to a dynamic textfield. If the enemy hits the chaosCopter there’s a 1000 point reduction.

Thanks in advance

//Henrik
