Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9931994 to your computer and use it in GitHub Desktop.
Save anonymous/9931994 to your computer and use it in GitHub Desktop.
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
* @author Moynul Hussain
*/
public class player extends MovieClip
{
public static var attackKey:Boolean;
public static var yGravity:int = 0;
public static var gravity:Boolean;
public static var xSpeed:int;
public var ySpeed:int;
public static var rightKey:Boolean;
public static var leftKey:Boolean;
public static var upKey:Boolean;
public static var touchingGround:Boolean;
public function player()
{
xSpeed = 3;
ySpeed = 6;
addEventListener(Event.ADDED_TO_STAGE, init)
addEventListener(Event.REMOVED_FROM_STAGE, reset)
}
private function reset(e:Event):void
{
removeEventListener(Event.REMOVED_FROM_STAGE, reset);
//trace("removed");
//yGravity = 0;
//do something
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}
public function keyListner():void
{
this.y += yGravity++;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
}
public function movementChar()
{
if (leftKey)
{
this.x -= xSpeed;
this.gotoAndStop("run");
this.scaleX = -1;
//this.x += stage.x ;
}
if (rightKey)
{
this.x += xSpeed;
this.gotoAndStop("run");
this.scaleX = 1;
}
if (upKey)
{
this.y -= 15;
this.gotoAndStop("jump");
//this.scaleX = -1;
}
if (attackKey)
{
this.gotoAndStop("attack");
}
if (leftKey && attackKey)
{
this.x -= xSpeed;
this.gotoAndStop("attack");
}
if (!upKey && !leftKey && !rightKey && touchingGround &&!attackKey)
{
this.gotoAndStop("stop");
}
}
private function keyUp(e:KeyboardEvent):void
{
if (e.keyCode == 65)
{
attackKey = false;
}
if (e.keyCode == 37)
{
leftKey = false;
}
if (e.keyCode == 39)
{
rightKey = false;
}
if (e.keyCode == 38)
{
upKey = false;
}
}
private function keyDown(e:KeyboardEvent):void
{
if (e.keyCode == 65)
{
attackKey = true;
}
if (e.keyCode == 37)
{
leftKey = true;
}
if (e.keyCode == 39)
{
rightKey = true;
}
if (e.keyCode == 38)
{
upKey = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment