this.stage.addEventListener(KeyboardEven t.KEY_DOWN,down);
this.stage.addEventListener(KeyboardEven t.KEY_UP,up);
addEventListener(Event.ENTER_FRAME, enterFrame);
addEventListener(Event.ENTER_FRAME,moveB ullet);
addEventListener(Event.ENTER_FRAME,moveM olotov);
addEventListener(Event.ENTER_FRAME,shell Bounce);
addEventListener(Event.ENTER_FRAME,moveA rm);
addEventListener(Event.ENTER_FRAME,moveC ursor);
addEventListener(Event.ENTER_FRAME,zombi emovement);
addEventListener(MouseEvent.MOUSE_DOWN, shoot);
var leftdown=0;
var rightdown=0;
var jumpdown=0;
var downdown=0;
var gravity=0;
var jump=0;
var jumping=0;
var shooting=0;
var bulcount=1;
var running=0;
var turnrun=0;
var ballgravity=1;
var ballspeed=0;
var bullets:Array = new Array();
var molotovs:Array = new Array();
var shells:Array = new Array();
var zombies:Array = new Array();
var zombies2:Array = new Array();
var zombiesspawn=5;
var r;//molotov throw x
var throwy;//molotov throw y
var shot=0;
var lookup=0;
var idle=0;
var fallspeed;
var fallspeed1;
var Xd;
var Yd;
var radAngle;
var arm;
var bulletspeed=30;
var weaponselect=1;
var bulletdistance;
var cursordistance;
function zombiemovement(event:Event) {
for (var e:int = zombies.length-1; e>=0; e--) {
zombies[e].zombwalking==0;
zombies[e].zombdistance=player.x-zombies [e].x;
zombies[e].zombspeed=0;
if ((zombies[e].zombdistance>0 || zombies[e].zombdistance<0)) {
if (zombies[e].currentFrame!=2) {
zombies[e].gotoAndStop(2);
}
}
if (! ground.hitTestPoint(zombies[e].x,zombies [e].y-10,true)) {
zombies[e].y+=3;
}
if (ground.hitTestPoint(zombies[e].x,zombie s[e].y-10,true)) {
zombies[e].y-=3;
}
if (zombies[e].hitTestObject(zombies[e])&&z ombies[e].zombdead==0) {
zombies[e].x+=Math.random()*3-Math.rando m()*3;
}
if (zombies[e].zombdistance>0&&zombies[e].z ombdead==0) {
zombies[e].scaleX=-1;
//zombies[e].gotoAndStop(2);
zombies[e].zombspeed=-2*Math.random()*3;
//zombies[e].zombwalking=1;
}
if (zombies[e].zombdistance<0&&zombies[e].z ombdead==0) {
zombies[e].scaleX=1;
//zombies[e].gotoAndStop(2);
zombies[e].zombspeed=2*Math.random()*3;
//zombies[e].zombwalking=1;
}
if (zombies[e].zombhealth<=0) {
zombies[e].zombdead=1;
}
if (zombies[e].zombdead==1) {
zombies[e].rotation=90;
}
zombies[e].x-=zombies[e].zombspeed;
//trace(zombhealth)
}
}
function moveCursor(event:Event) {
if (player.scaleX>0) {
player.head.rotation = (arm.rotation)*.8;
} else if (player.scaleX <0) {
player.head.rotation = (arm.rotation*-1)*.8;
}
Mouse.hide();
cursor.x=mouseX;
cursor.y=mouseY;
}
function moveArm(event:Event) {
if (mouseX>player.x) {
player.scaleX=1;
}
if (mouseX<player.x) {
player.scaleX=-1;
}
arm.scaleX=player.scaleX;
if (player.scaleX>0) {
arm.x=player.x+5;
} else if (player.scaleX <0) {
arm.x=player.x-5;
}
arm.y=player.y-65;
Xd=arm.x-mouseX;
//Get _x distance from gun to mouse
Yd=arm.y-mouseY;
//Get _y distance from gun to mouse
radAngle=Math.atan2(Yd,Xd);
arm.rotation = int((radAngle*360/(2*Math.PI))-90);
}
function moveMolotov(event:Event) {
for (var e:int = molotovs.length-1; e>=0; e--) {
//bullets[u].x+=bullets[u].dx*8;
if (arm.hitTestPoint(molotovs[e].x,molotovs [e].y,true)) {
molotovs[e].visible=false;
} else if (!arm.hitTestPoint(molotovs[e].x,molotov s[e].y,true)) {
molotovs[e].visible=true;
}
molotovs[e].r=30;
if (! ground.hitTestPoint(molotovs[e].x,moloto vs[e].y,true)) {
molotovs[e].x += (10*Math.sin(Math.PI/180*molotovs[e].rot ation));
molotovs[e].y -= (5*Math.cos(Math.PI/180*molotovs[e].rota tion));
molotovs[e].y+=molotovs[e].throwy;
molotovs[e].throwy++;
}
molotovs[e].r-=.3;
//molotovs[e].x+=r
//molotovs[e].rotation+=r;
/*for(var ii:int=enemies.length-1;ii>0=0;ii--){
if(bullets[i].hitTestObject(enemies[ii].
mc)){
//enemyDie(ii)
continue
}
}*/
}
}
function moveBullet(event:Event) {
for (var u:int = bullets.length-1; u>=0; u--) {
//bullets[u].x+=bullets[u].dx*8;
if (arm.hitTestPoint(bullets[u].x,bullets[u ].y,true)) {
bullets[u].visible=false;
} else if (!arm.hitTestPoint(bullets[u].x,bullets[
u].y,true)) {
bullets[u].visible=true;
}
bullets[u].bulletdistance=Math.sqrt(Math .pow((bullets[u].x-player.x),2)+Math.pow ((bullets[u].y-player.y),2));
for (var i:int=zombies.length-1; i>0; i--) {
if (! ground.hitTestPoint(bullets[u].x,bullets [u].y,true)&& ! zombies[i].hitTestPoint(bullets[u].x,bul lets[u].y,true) && (bullets[u].bulletdistance<400)) {
bullets[u].x += (bulletspeed*Math.sin(Math.PI/180*bullet s[u].rotation));
bullets[u].y -= (bulletspeed*Math.cos(Math.PI/180*bullet s[u].rotation));
//removeChild(bullets[u]);
}
if (ground.hitTestPoint(bullets[u].x,bullet s[u].y,true)&&bullets[u].currentFrame==1 ) {
bullets[u].gotoAndStop(2);
bullets.splice(u,u);
trace(bullets)
}
if (zombies[i].hitTestPoint(bullets[u].x,bu llets[u].y,true)&&bullets[u].currentFram e==1) {
bullets[u].gotoAndStop(3);
//bullets.splice(u, 1);
zombies[i].zombhealth--
;
}
}
/*for(var ii:int=enemies.length-1;ii>0;ii--){
if(bullets[i].hitTestObject(enemies[ii].
mc)){
//enemyDie(ii)
continue
}
}*/
}
}
function shoot(event:MouseEvent):void {
if (weaponselect==1) {
if (shot==0) {
idle=0;
shooting=1;
if (arm.currentFrame==2) {
arm.shoot.gotoAndPlay(1);
} else {
arm.gotoAndStop(2);
}
var newBullet:Bullet = new Bullet();
newBullet.x=arm.x;
newBullet.y=arm.y;
newBullet.rotation=arm.rotation;
addChild(newBullet);
bullets.push(newBullet);
shot=1;
//
var newShell:Shell = new Shell();//calling Shell movie clip
newShell.x = arm.x+(40*Math.sin(Math.PI/180*arm.rotat ion));
//Move to gun _x
newShell.y = arm.y+((30*Math.cos(Math.PI/180*arm.rota tion))*-1);
newShell.rotation=arm.rotation+90;
addChild(newShell);
shells.push(newShell);
newShell.time1=70;
newShell.bulletdistance = Math.sqrt(Math.pow((newShell.x-player.x)
,2)+Math.pow((newShell.y-player.y),2));
newShell.fallspeed=-10;
newShell.fallspeed1=player.scaleX*.01;
}
} else if (weaponselect==2) {//molotov
if (shot==0) {
idle=0;
shooting=1;
if (arm.currentFrame==2) {
arm.armthrow.gotoAndPlay(1);
} else {
arm.gotoAndStop(4);
}
//arm.gotoAndStop(4);
var newMolotov:Molotov = new Molotov();
newMolotov.x=arm.x;
newMolotov.y=arm.y;
newMolotov.rotation=arm.rotation;
addChild(newMolotov);
molotovs.push(newMolotov);
//
newMolotov.throwy=-10;
newMolotov.r=1;
shot=1;
}
}
}
function shellBounce(event:Event) {
for (var u:int = shells.length-1; u>=0; u--) {
if (ground.hitTestPoint(shells[u].x,shells[
u].y,true)) {
shells[u].fallspeed*=-1;
shells[u].fallspeed*=.6;
shells[u].fallspeed1=0;
}
shells[u].y+=shells[u].fallspeed;
shells[u].fallspeed++;
shells[u].x+=shells[u].fallspeed1;
if (shells[u].fallspeed1>0) {
shells[u].fallspeed1+=.1;
} else if (shells[u].fallspeed1<0) {
shells[u].fallspeed1-=.1;
}
shells[u].time1--;
if (shells[u].time1<0) {
shells[u].alpha=0;
}
shells[u].rotation+=shells[u].fallspeed1 ;
}
}
function enterFrame(a) {
if (zombiesspawn>0) {
var newZombie:Zombie = new Zombie();
var zombdead=0;
newZombie.x=player.x+10+Math.random()*10 ;
newZombie.y=player.y;
//newZombie.rotation=arm.rotation;
addChild(newZombie);
zombies.push(newZombie);
newZombie.zombdead=0;
newZombie.zombhealth=3;
var zombspeed;
var zombdistance;
var zombwalking=0;
var zombwalk=0;
var zombhealth=3;
newZombie.zombiedistance=player.x-newZom bie.x;
zombiesspawn--;
}
cursordistance = Math.sqrt(Math.pow((cursor.x-player.x),2 )+Math.pow((cursor.y-player.y),2));
/*scaleX = 1+cursordistance*-.001
if(scaleX<.6){
scaleX = .6
}
scaleY = scaleX*/
//x += ((((player.x+x)*-1)+600/2)/2)
if (cursor.x>player.x) {
x += (((player.x-300+(cursordistance)/5)*-1)-
x)/6;
} else if (cursor.x<player.x) {
x += (((player.x-300-(cursordistance)/5)*-1)-
x)/6
;
}
//y += (((player.y-40+y)*-1)+400/2)/5;
if (cursor.y>player.y) {
y += (((player.y-200+(cursordistance)/5)*-1)-
y)/6;
} else if (cursor.y<player.y) {
y