stage.addEventListener(KeyboardEvent.KEY_DOWN, moveship);
this line is telling flash to lisen for any key being presed on the keyboard
function moveship(myevent:KeyboardEvent):void {
this gives the name of the function
if (myevent.keyCode==Keyboard.RIGHT){
ship.x+=5;
ship.rotation=90
if right key is hit, then rotate the ship 90%
} if (myevent.keyCode==Keyboard.LEFT){
ship.x-=5;
ship.rotation=270
if the left key is hit then rotated 170%
}
if (myevent.keyCode==Keyboard.UP){
ship.y-=5;
ship.rotation=0
if up key is hit then rotate nothing
} if (myevent.keyCode==Keyboard.DOWN){
ship.y+=5;
ship.rotation=180
}
if the down key is hit then rotate 180%
}
stage.addEventListener(Event.ENTER_FRAME, bounds);
listen to the stage then ad event called enter frame. function is called bounds
function bounds (event:Event) {
if (ship.x>=500) {
ship.x=0;
}
if (ship.x<0) {
ship.x=500;
}
if (ship.y>=400) {
ship.y=0;
}
if (ship.y<0) {
ship.y=500;
}
}
if the ship is near the bound then it makes the ship go back to the other side
No comments:
Post a Comment