I have been trying to make my character shoot in both directions but so far I only manage to make the bullets or “blasts” to stop when the character faces left, or the character runs right when I shoot, or turns left when I shoot.
stage.focus=stage;
matazon.gotoAndStop(“stand”);
var moveRight:Boolean=false;
var moveLeft:Boolean=false;
var gravity:Number=2;
var velocity:Number=1.1;
var jumpPower:Number=0;
var isJumping:Boolean=false;
var ground:Number=630-matazon.height;
var droneDirection:Number=5;
var matazonScale:Number=matazon.scaleX;
import flash.ui.Keyboard;
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, shootBlast);
stage.addEventListener(Event.ENTER_FRAME, runAnimation);
stage.addEventListener(Event.ENTER_FRAME, leftWall);
stage.addEventListener(Event.ENTER_FRAME, rightWall);
stage.addEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.addEventListener(Event.ENTER_FRAME, nojump);
stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
stage.addEventListener(Event.ENTER_FRAME, moveOver);
stage.addEventListener(Event.ENTER_FRAME, matazonFunction);
stage.addEventListener(Event.ENTER_FRAME, droneLeft);
stage.addEventListener(Event.ENTER_FRAME,checkCollision);
function checkCollision(event:Event) {
if (matazon.hitTestObject(drone)) {
stage.removeEventListener(KeyboardEvent.KEY_DOWN, shootBlast);
stage.removeEventListener(Event.ENTER_FRAME, runAnimation);
stage.removeEventListener(Event.ENTER_FRAME, leftWall);
stage.removeEventListener(Event.ENTER_FRAME, rightWall);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.removeEventListener(Event.ENTER_FRAME, nojump);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, downKey);
stage.removeEventListener(KeyboardEvent.KEY_UP, upKey);
stage.removeEventListener(Event.ENTER_FRAME, moveOver);
stage.removeEventListener(Event.ENTER_FRAME, matazonFunction);
stage.removeEventListener(Event.ENTER_FRAME, droneLeft);
stage.removeEventListener(Event.ENTER_FRAME,checkCollision);
removeChild(drone);
gotoAndStop("endgame");
}
}
function shootBlast(event:KeyboardEvent) {
if (event.keyCode==Keyboard.SHIFT) {
var Blast:blast=new blast();
Blast.x=matazon.x+30;
Blast.y=matazon.y-50;
addChild(Blast);
Blast.addEventListener(Event.ENTER_FRAME, moveBlast);
}
}
function moveBlast(e:Event) {
e.target.x+=5;
if (e.target.x>=800) {
e.target.removeEventListener(Event.ENTER_FRAME, moveBlast);
removeChild(MovieClip(e.target));
}
}
function runAnimation(event:Event) {
if (moveRight==true &&(matazon.currentFrame == 14)) {
matazon.gotoAndStop(2);
} else {
matazon.gotoAndStop(matazon.currentFrame+1);
}
}
function rightWall(event:Event) {
if (matazon.x<25) {
matazon.x=25;
}
}
function leftWall(event:Event) {
if (matazon.x>775) {
matazon.x=775;
}
}
function jump(event:KeyboardEvent) {
if (event.keyCode==Keyboard.SPACE &&(!isJumping)) {
jumpPower=25;
isJumping=true;
}
}
function nojump(event:Event) {
if (isJumping) {
matazon.y-=jumpPower;
jumpPower-=2;
}
if (matazon.y+gravity<ground) {
matazon.y+=gravity;
matazon.gotoAndStop("jump");
} else {
matazon.y=ground;
isJumping=false;
}
}
function matazonFunction(event:Event) {
gravity*=velocity;
matazon.y+=gravity;
if (matazon.hitTestObject(floor)) {
velocity=0;
} else {
velocity=1.1;
}
}
function droneLeft(event:Event) {
drone.x=drone.x+droneDirection;
if ((drone.x < 75) || (drone.x > 725)) {
droneDirection=- droneDirection;
drone.scaleX=- drone.scaleX;
}
}
function downKey(event:KeyboardEvent) {
if (event.keyCode==Keyboard.RIGHT) {
moveRight=true;
}
if (event.keyCode==Keyboard.LEFT) {
moveLeft=true;
}
}
function upKey(event:KeyboardEvent) {
if (event.keyCode==Keyboard.RIGHT) {
moveRight=false;
}
if (event.keyCode==Keyboard.LEFT) {
moveLeft=false;
}
}
function moveOver(event:Event) {
if (moveRight==true) {
matazon.x+=20;
matazon.scaleX=matazonScale;
} else {
if (moveLeft==true) {
matazon.x-=20;
matazon.scaleX=- matazonScale;
} else {
matazon.gotoAndStop("stand");
}
}
}