The code for the bullets:
var bullet:MovieClip;
//+other vars needed below
function bulletFire(){
if(reloadComplete==true){
bullet = attachMovie("bullet", "bullet_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_b_x, _y:start_b_y});
bullet._rotation=player._rotation;//bullet rotation
bullet.bulletLifeTimer = 0; //bullet offset
randomNum = Math.random() * bulletOffset - (bulletOffset / 2);
var bulletAngle = player._rotation-90 + randomNum;
bullet.dirx = Math.cos(bulletAngle*Math.PI/180)*firePower;
bullet.diry = Math.sin(bulletAngle*Math.PI/180)*firePower;
bullet.onEnterFrame = function() {
//moving bullet
this._x += this.dirx;
this._y += this.diry;
//checking bullet lifetime
if (this.bulletLifeTimer>=bulletLifeTimerTotal) {
this.removeMovieClip();//delete the bullet
}
this.bulletLifeTimer++; };
}
startReloading();
}
}
function startReloading()
{
reloadComplete = false;//reload started
reloadTimer = setInterval(gunReloaded, reloadSpeed);//pistol - 350, smg - 100
}
function gunReloaded()
{
clearInterval(reloadTimer);//clear timer
reloadComplete = true;//reload complete
}
And for the zombies:
function enemy(){
for(i=1;i<=20;i++){
if(enemySpawned==false){
if(i<20){
attachMovie("zombie","zombie_"+i,100+i,{_x:random(800),_y:random(800),enemyHp:10});
}
}
if(i==20){
enemySpawned=true;
}
_root["zombie_"+i].onEnterFrame = function(){
if(this.hitTest(bullet)){
crit=random(10);
if(crit==0){
this.removeMovieClip();//10% of headshot
}else{
this.enemyHp-=dm;
}
bullet.removeMovieClip();
if(this.enemyHp<=0){
this.removeMovieClip();
}
}
}
}
}