Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.asgamer.directionalmovement
- {
- import flash.display.MovieClip;
- import flash.display.Stage;
- import flash.events.Event;
- import com.senocular.utils.KeyObject;
- import flash.ui.Keyboard;
- public class Ship extends MovieClip
- {
- private var key:KeyObject;
- private var speed:Number = 0.3;
- private var rotateSpeed:Number = 5;
- private var vx:Number = 0;
- private var vy:Number = 0;
- private var friction:Number = 0.95;
- public function Ship () : void
- {
- key = new KeyObject(stage);
- addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
- }
- public function loop(e:Event) : void
- {
- if (key.isDown(Keyboard.UP))
- {
- vy += Math.sin(degreesToRadians(rotation)) * speed;
- vx += Math.cos(degreesToRadians(rotation)) * speed;
- flame.visible = true;
- } else {
- vy *= friction;
- vx *= friction;
- flame.visible = false;
- }
- if (key.isDown(Keyboard.RIGHT))
- rotation += rotateSpeed;
- else if (key.isDown(Keyboard.LEFT))
- rotation -= rotateSpeed;
- y += vy;
- x += vx;
- }
- public function degreesToRadians(degrees:Number) : Number
- {
- return degrees * Math.PI / 180;
- }
- }
- }
Add Comment
Please, Sign In to add comment