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 bg 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;
- private var dedrotation:Number = 0;
- public function bg () : 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(dedrotation)) * speed;
- vx += Math.cos(degreesToRadians(dedrotation)) * speed;
- } else {
- vy *= friction;
- vx *= friction;
- }
- if (key.isDown(Keyboard.RIGHT))
- dedrotation += rotateSpeed;
- else if (key.isDown(Keyboard.LEFT))
- dedrotation -= rotateSpeed;
- y -= vy;
- x -= vx;
- }
- public function degreesToRadians(degrees:Number) : Number
- {
- return degrees * Math.PI / 180;
- }
- }
- }
Add Comment
Please, Sign In to add comment