var hitObstacle:Boolean=false; // keeps track if obstacle is hitvar health=20; health_txt.text=health.toString();stage.addEventListener(KeyboardEvent.KEY_DOWN, checkkeysdown);stage.addEventListener(KeyboardEvent.KEY_UP, checkkeysup);var speed=10;var moveup=false;var movedown=false;var moveleft=false; var moveright=false;
function checkkeysdown(mykey:KeyboardEvent) { if (mykey.keyCode==Keyboard.UP) { moveup=true; } if (mykey.keyCode==Keyboard.DOWN) { movedown=true; } if (mykey.keyCode==Keyboard.LEFT) { moveleft=true; } if (mykey.keyCode==Keyboard.RIGHT) { moveright=true; }}function checkkeysup(mykey:KeyboardEvent) { if (mykey.keyCode==Keyboard.UP) { moveup=false; } if (mykey.keyCode==Keyboard.DOWN) { movedown=false; } if (mykey.keyCode==Keyboard.LEFT) { moveleft=false; } if (mykey.keyCode==Keyboard.RIGHT) { moveright=false; }
stage.addEventListener(Event.ENTER_FRAME, gameloop);function gameloop(evt:Event):void { obstacle_mc.x-=-15;{ if (obstacle_mc.x>600) obstacle_mc.x=-20; arrow_mc.x-=-10;{ if (arrow_mc.x>550) arrow_mc.x=-20; }} if (xena_mc.hitTestObject(obstacle_mc)(arrow_mc)) { if (hitObstacle==false){ //only subtract health if hitObstacle is false health--; } hitObstacle=true; health_txt.text=health.toString();
if (moveup==true) { xena_mc.y-=speed; } if (movedown==true) { xena_mc.y+=speed; } if (moveleft==true) { xena_mc.x-=speed; } if (moveright==true) { xena_mc.x+=speed; } }
why dosent this work??? thanks! your help is greatly appreciated