Это нужно не исправлять
Вот отрывок, мои самые первые пробы в своё время, написано вообще не по конвенции, зато в теории довольно понятно
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
var ship:MovieClip;
var rotation_speed:Number = 0;
var motion_speed:Number = 0;
var motion_switch:int = 0;
var rotation_switch:int = 0;
const MAX_ROTATION_SPEED:Number = 3;
const MAX_MOTION_SPEED:Number = 5;
const ROTATION_ACCELERATION:Number = 0.2;
const MOTION_ACCELERATION:Number = 0.3;
const RESISTANCE:Number = 0.98;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownUpHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyDownUpHandler);
stage.addEventListener(Event.ENTER_FRAME, update);
function update(e:Event):void
{
rotateShip();
moveShip();
frameLimits();
}
function keyDownUpHandler(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.UP:
if ( e.type == KeyboardEvent.KEY_DOWN )
motion_switch = 1;
else
motion_switch = 0;
break;
case Keyboard.DOWN:
if ( e.type == KeyboardEvent.KEY_DOWN )
motion_switch = -1;
else
motion_switch = 0;
break;
case Keyboard.LEFT:
if ( e.type == KeyboardEvent.KEY_DOWN )
rotation_switch = -1;
else
rotation_switch = 0;
break;
case Keyboard.RIGHT:
if ( e.type == KeyboardEvent.KEY_DOWN )
rotation_switch = 1;
else
rotation_switch = 0;
break;
}
}
function rotateShip():void
{
rotation_speed += rotation_switch * ROTATION_ACCELERATION;
if ( Math.abs( rotation_speed ) > MAX_ROTATION_SPEED )
rotation_speed = MAX_ROTATION_SPEED * rotation_switch;
ship.rotation += rotation_speed;
rotation_speed *= RESISTANCE;
}
function moveShip():void
{
motion_speed += motion_switch * MOTION_ACCELERATION;
if ( Math.abs( motion_speed ) > MAX_MOTION_SPEED )
motion_speed = MAX_MOTION_SPEED * motion_switch;
ship.x -= Math.sin( ship.rotation * Math.PI / 180 ) * motion_speed;
ship.y += Math.cos( ship.rotation * Math.PI / 180 ) * motion_speed;
motion_speed *= RESISTANCE;
}
function frameLimits():void
{
if ( ship.x > stage.stageWidth )
ship.x = 0;
else if ( ship.x < 0 )
ship.x = stage.stageWidth;
if ( ship.y > stage.stageHeight )
ship.y = 0;
else if ( ship.y < 0 )
ship.y = stage.stageHeight;
}