Цитата:
|
меня ещё интересуют заносы
|
Вот так можно:

Код AS3:
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.geom.Point;
var ship:MovieClip;
var ship_speed_xy:Point = new Point( 0, 0 );
var motion_speed:Number = 0;
var motion_speed_xy:Point = new Point( 0, 0 );
var motion_switch:int = 0;
var motion_angle:Number = 0;
var rotation_speed:Number = 0;
var rotation_switch:int = 0;
var skid_rotation:Number = 0;
const SKID_DELAY:Number = 0.05;
const MOTION_ACCELERATION:Number = 1;
const MOTION_SPEED_MAX:Number = 10;
const MOTION_RESISTANCE:Number = 0.95;
const ROTATION_ACCELERATION:Number = 1;
const ROTATION_SPEED_MAX:Number = 5;
const ROTATION_RESISTANCE:Number = 0.8;
stage.addEventListener( Event.ENTER_FRAME, update );
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownUpHandler );
stage.addEventListener( KeyboardEvent.KEY_UP, keyDownUpHandler );
function update( e:Event ):void
{
rotateShip();
moveShip();
frameLimits();
}
function rotateShip():void
{
rotation_speed += ROTATION_ACCELERATION * rotation_switch;
if ( rotation_speed * rotation_switch > ROTATION_SPEED_MAX )
rotation_speed = ROTATION_SPEED_MAX * rotation_switch;
ship.rotation += rotation_speed;
if ( rotation_switch == 0 )
rotation_speed *= ROTATION_RESISTANCE;
}
function moveShip():void
{
motion_speed += MOTION_ACCELERATION * motion_switch;
if ( motion_speed * motion_switch > MOTION_SPEED_MAX )
motion_speed = MOTION_SPEED_MAX * motion_switch;
if ( motion_switch != 0 )
skid_rotation = ship.rotation;
motion_angle = skid_rotation * Math.PI / 180;
motion_speed_xy.x = Math.sin( motion_angle ) * motion_speed;
motion_speed_xy.y = -Math.cos( motion_angle ) * motion_speed;
ship_speed_xy.x += ( motion_speed_xy.x - ship_speed_xy.x ) * SKID_DELAY;
ship_speed_xy.y += ( motion_speed_xy.y - ship_speed_xy.y ) * SKID_DELAY;
ship.x += ship_speed_xy.x;
ship.y += ship_speed_xy.y;
if ( motion_switch == 0 )
motion_speed *= MOTION_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;
}
function keyDownUpHandler( e:KeyboardEvent ):void
{
switch ( e.keyCode )
{
case Keyboard.UP:
case Keyboard.W:
if ( e.type == KeyboardEvent.KEY_DOWN )
motion_switch = 1;
else
motion_switch = 0;
break;
case Keyboard.DOWN:
case Keyboard.S:
if ( e.type == KeyboardEvent.KEY_DOWN )
motion_switch = -1;
else
motion_switch = 0;
break;
case Keyboard.LEFT:
case Keyboard.A:
if ( e.type == KeyboardEvent.KEY_DOWN )
rotation_switch = -1;
else
rotation_switch = 0;
break;
case Keyboard.RIGHT:
case Keyboard.D:
if ( e.type == KeyboardEvent.KEY_DOWN )
rotation_switch = 1;
else
rotation_switch = 0;
break;
}
}