You are on page 1of 2

package com.asgamer.helicopter { import import import import import flash.display.MovieClip; flash.events.Event; com.senocular.utils.KeyObject; flash.display.Stage; flash.ui.

Keyboard;

public class Helicopter extends MovieClip { var speed:Number = 10; private private private private private var var var var var gravity:Number = .4; vy:Number = 0; vx:Number = 0; key:KeyObject; stageRef:Stage;

private var maxspeedG:Number = 9; private var maxspeed:Number = 6; private var friction:Number = .92; public function Helicopter (stageRef:Stage) : void { this.stageRef =stageRef; addEventListener(Event.ENTER_FRAME, loop, false, 0, true ); //key = new KeyObject(stageRef); x = stageRef.stageWidth/2; y = stageRef.stageHeight/2; } public function loop(e:Event) : void { var yDistance:Number = stageRef.mouseY - y; var xDistance:Number = stageRef.mouseX - x; var radian:Number = Math.atan2(yDistance, xDistance); rotation = radian * 180 / Math.PI; x -= (x - stageRef.mouseX) / speed; y -= (y - stageRef.mouseY) / speed; } /*vy += gravity; y += vy; x += vx; if (vy > maxspeedG) vy = maxspeedG; else if (vy < -maxspeed) vy = -maxspeed; if (vx > maxspeed) vx = maxspeed; //easing //easing

else if (vx < -maxspeed) vx = -maxspeed; if (vx > 0) scaleX = 1; else if (vx < 0) scaleX = -1; if (y > stageRef.stageHeight) { y = stageRef.stageHeight; vy = -2;*/ } /*rotation = vx*2; if (key.isDown(Keyboard.RIGHT)) vx += .5; else if (key.isDown(Keyboard.LEFT)) vx -= .5; else vx *= friction; if (key.isDown(Keyboard.UP)) vy -= 1; else if (key.isDown(Keyboard.DOWN)) vy += .5;*/ }