Posted by sheel on Fri 9 Oct 20:38
report abuse | View followups from - | 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 = new HandChar(); // define MovieClip "handChar"
- var leftKeyDown:Boolean = false; // move left
- var upKeyDown:Boolean = false; // jump
- var rightKeyDown:Boolean = false; // move right
- var downKeyDown:Boolean = false; // disabled
- var hKeyDown:Boolean = false; // scissor attack
- var jKeyDown:Boolean = false; // paper attack
- var kKeyDown:Boolean = false; // rock attack
- var mainJumping:Boolean = false;
- var jumpSpeedLimit:int = 15;
- var jumpSpeed:Number = jumpSpeedLimit;
- public function Main()
- { // start public function Main (constructor)
- addEventListener(Event.ENTER_FRAME, moveHand);
- addEventListener(Event.ENTER_FRAME, boundaries);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
- handChar.handCharobject.addEventListener (Event.ENTER_FRAME, endKeyDown);
- createHand();
- } // end public function Main (constructor)
- private function createHand():void
- { // start private function createHand
- handChar.x = 200;
- handChar.y = 145;
- handChar.scaleX = 1;
- handChar.scaleX = 1;
- addChild(handChar);
- } // end private function createHand
- private function endKeyDown (event:Event):void
- {
- if(handChar.handCharobject.currentLabel == "endofclip")
- {
- hKeyDown = false;
- stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- if(handChar.handCharobject.currentLabel == "endofclip")
- {
- jKeyDown = false;
- stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- if(handChar.handCharobject.currentLabel == "endofclip")
- {
- kKeyDown = false;
- stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- }
- 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;
- }
- if(event.keyCode == 72)
- {
- hKeyDown = true;
- stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- if(event.keyCode == 74)
- {
- jKeyDown = true;
- stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- if(event.keyCode == 75)
- {
- kKeyDown = true;
- stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
- }
- } // 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
- private function moveHand (e:Event) : void
- { // start private 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;
- }
- if(hKeyDown)
- {
- handChar.gotoAndStop("scissor");
- return;
- }
- if(jKeyDown)
- {
- handChar.gotoAndStop("paper");
- return;
- }
- if(kKeyDown)
- {
- handChar.gotoAndStop("rock");
- return;
- }
- handChar.gotoAndPlay(3);
- } // end private function Movehand
- private function boundaries (e:Event):void
- { // start private function boundaries
- if(handChar.x > stage.stageWidth - handChar.width/2)
- {
- handChar.x = stage.stageWidth - handChar.width/2;
- }
- if(handChar.x < 15)
- {
- handChar.x = 15;
- }
- } // end private function boundaries
- private function mainJump():void
- { // start private 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 private 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.