Posted by sheel on Tue 29 Sep 10:37
report abuse | View followups from sheel | download | new post
- package
- { // start package
- import flash.display.MovieClip;
- import flash.events.*;
- public class Main extends MovieClip
- { // start public class Main
- var speed:Number = 5;
- var handChar:HandChar;
- // define MovieClip "handChar"
- var leftKeyDown:Boolean = false;
- var upKeyDown:Boolean = false;
- var rightKeyDown:Boolean = false;
- var downKeyDown:Boolean = false;
- // define keys left, right, up, down - for movement (left, right, up, may add down)
- var hKeyDown:Boolean = false;
- var jKeyDown:Boolean = false;
- var kKeyDown:Boolean = false;
- //define keys h, j, k - for attacks (rock, paper, scissor)
- var mainJumping:Boolean = false;
- var jumpSpeedLimit:int = 15;
- var jumpSpeed:Number = jumpSpeedLimit;
- // define jump
- public function Main()
- { // start function Main
- addEventListener(Event.ENTER_FRAME, moveHand);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
- handChar= new HandChar ();
- handChar.x = 200;
- handChar.y = 90;
- handChar.scaleX = 1;
- handChar.scaleX = 1;
- addChild(handChar);
- } // end function Main
- private function checkKeysDown (event:KeyboardEvent):void
- { // start private function checkKeysDown
- if(event.keyCode == 37 || event.keyCode == 65)
- {
- leftKeyDown = true;
- }
- if(event.keyCode == 38 || event.keyCode == 87)
- {
- upKeyDown = true;
- }
- if(event.keyCode == 39 || event.keyCode == 68)
- {
- rightKeyDown = true;
- }
- if(event.keyCode == 40 || event.keyCode == 83)
- {
- downKeyDown = true;
- }
- } // end private function checkKeysDown
- private function checkKeysUp (event:KeyboardEvent):void
- { // start private function checkKeysUp
- if(event.keyCode == 37 || event.keyCode == 65)
- {
- leftKeyDown = false;
- }
- if(event.keyCode == 38 || event.keyCode == 87)
- {
- upKeyDown = false;
- }
- if(event.keyCode == 39 || event.keyCode == 68)
- {
- rightKeyDown = false;
- }
- if(event.keyCode == 40 || event.keyCode == 83)
- {
- downKeyDown = false;
- }
- } // end private function checkKeysUp
- public function moveHand (e:Event) : void
- { // start public function moveHand
- if(leftKeyDown)
- {
- if(upKeyDown || mainJumping)
- {
- handChar.x -=speed;
- handChar.scaleX = -1;
- handChar.gotoAndPlay(5);
- mainJump();
- return;
- }
- handChar.x -= speed;
- handChar.scaleX = -1;
- handChar.gotoAndPlay(1);
- return;
- }
- if(rightKeyDown)
- {
- if(upKeyDown || mainJumping)
- {
- handChar.x +=speed;
- handChar.scaleX = 1;
- handChar.gotoAndPlay(5);
- mainJump();
- return;
- }
- handChar.x += speed;
- handChar.scaleX = 1;
- handChar.gotoAndPlay(1);
- return;
- }
- if(upKeyDown || mainJumping)
- {
- handChar.gotoAndPlay(5);
- mainJump();
- return;
- }
- handChar.gotoAndPlay(3);
- } // end public function Movehand
- function mainJump():void
- { // start function mainJump
- if(!mainJumping)
- {
- mainJumping = true;
- jumpSpeed = jumpSpeedLimit*-1;
- handChar.y += jumpSpeed;
- }
- else
- {
- if(jumpSpeed < 0)
- {
- jumpSpeed *= 1 - jumpSpeedLimit/75;
- if(jumpSpeed > -jumpSpeedLimit/5)
- {
- jumpSpeed *= -1;
- }
- }
- if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
- {
- jumpSpeed *= 1 + jumpSpeedLimit/50;
- }
- handChar.y += jumpSpeed;
- if(handChar.y >= stage.stageHeight - handChar.height)
- {
- mainJumping = false;
- handChar.y = stage.stageHeight - handChar.height;
- }
- }
- } // end function mainJump
- } // end public class Main
- } // end package
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.