Recent Posts
None | 1 sec ago
None | 25 sec ago
None | 27 sec ago
None | 53 sec ago
C++ | 56 sec ago
ABAP | 56 sec ago
None | 1 min ago
mIRC | 1 min ago
ActionScript 3 | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By - on the 13th of Oct 2009 02:52:10 PM Download | Raw | Embed | Report
  1. package
  2. { // start package
  3.        
  4.         import flash.display.MovieClip;
  5.         import flash.events.*;
  6.        
  7.         public class Main extends MovieClip
  8.         { // start public class Main
  9.                 var speed:Number = 5;
  10.                
  11.                 var handChar:HandChar = new HandChar(); // define MovieClip "handChar"
  12.                
  13.                 var leftKeyDown:Boolean = false; // move left
  14.                 var upKeyDown:Boolean = false; // jump
  15.                 var rightKeyDown:Boolean = false; // move right
  16.                 var downKeyDown:Boolean = false; // disabled
  17.                
  18.                 var hKeyDown:Boolean = false; // scissor attack
  19.                 var jKeyDown:Boolean = false; // paper attack
  20.                 var kKeyDown:Boolean = false; // rock attack
  21.                
  22.                 var mainJumping:Boolean = false;
  23.                 var jumpSpeedLimit:int = 15;
  24.                 var jumpSpeed:Number = jumpSpeedLimit;
  25.                
  26.                 public function Main()
  27.                 { // start public function Main (constructor)
  28.                         addEventListener(Event.ENTER_FRAME, moveHand);
  29.                         addEventListener(Event.ENTER_FRAME, boundaries);
  30.                         stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  31.                         stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
  32.                         handChar.handCharobject.addEventListener (Event.ENTER_FRAME, endKeyDown);
  33.                        
  34.                         createHand();
  35.                         } // end public function Main (constructor)
  36.                
  37.                 private function createHand():void
  38.                 { // start private function createHand
  39.                         handChar.x = 200;
  40.                         handChar.y = 145;
  41.                         handChar.scaleX = 1;
  42.                         handChar.scaleX = 1;
  43.                         addChild(handChar);
  44.                 } // end private function createHand
  45.                
  46.                 private function endKeyDown (event:Event):void
  47.                 {
  48.                         if(handChar.handCharobject.currentLabel == "endofclip")
  49.                         {
  50.                                 hKeyDown = false;
  51.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  52.                         }
  53.                         if(handChar.handCharobject.currentLabel == "endofclip")
  54.                         {
  55.                                 jKeyDown = false;
  56.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  57.                         }
  58.                         if(handChar.handCharobject.currentLabel == "endofclip")
  59.                         {
  60.                                 kKeyDown = false;
  61.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  62.                         }
  63.                 }
  64.                
  65.                 private function checkKeysDown (event:KeyboardEvent):void
  66.                 { // start private function checkKeysDown
  67.                         if(event.keyCode == 37 || event.keyCode == 65)
  68.                         {
  69.                                 leftKeyDown = true;
  70.                         }
  71.                         if(event.keyCode == 38 || event.keyCode == 87)
  72.                         {
  73.                                 upKeyDown = true;
  74.                         }
  75.                         if(event.keyCode == 39 || event.keyCode == 68)
  76.                         {
  77.                                 rightKeyDown = true;
  78.                         }
  79.                         if(event.keyCode == 40 || event.keyCode == 83)
  80.                         {
  81.                                 downKeyDown = true;
  82.                         }
  83.                         if(event.keyCode == 72)
  84.                         {
  85.                                 hKeyDown = true;
  86.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  87.                         }
  88.                         if(event.keyCode == 74)
  89.                         {
  90.                                 jKeyDown = true;
  91.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  92.                         }
  93.                         if(event.keyCode == 75)
  94.                         {
  95.                                 kKeyDown = true;
  96.                                 stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  97.                         }
  98.                 } // end private function checkKeysDown
  99.                
  100.                 private function checkKeysUp (event:KeyboardEvent):void
  101.                 { // start private function checkKeysUp
  102.                         if(event.keyCode == 37 || event.keyCode == 65)
  103.                         {
  104.                                 leftKeyDown = false;
  105.                         }
  106.                         if(event.keyCode == 38 || event.keyCode == 87)
  107.                         {
  108.                                 upKeyDown = false;
  109.                         }
  110.                         if(event.keyCode == 39 || event.keyCode == 68)
  111.                         {
  112.                                 rightKeyDown = false;
  113.                         }
  114.                         if(event.keyCode == 40 || event.keyCode == 83)
  115.                         {
  116.                                 downKeyDown = false;
  117.                         }
  118.  
  119.                         // :-)
  120.                         if(event.keyCode == 72 && hKeyDown)
  121.                         {
  122.                                 hKeyDown = false;
  123.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  124.                         }
  125.                         if(event.keyCode == 74 && jKeyDown)
  126.                         {
  127.                                 jKeyDown = false;
  128.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  129.                         }
  130.                         if(event.keyCode == 75 && kKeyDown)
  131.                         {
  132.                                 kKeyDown = false;
  133.                                 stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
  134.                         }
  135.                 } // end private function checkKeysUp
  136.                        
  137.                 private function moveHand (e:Event) : void
  138.                 { // start private function moveHand
  139.                         if(leftKeyDown)
  140.                         {
  141.                                 if(upKeyDown || mainJumping)
  142.                                 {
  143.                                         handChar.x -=speed;
  144.                                         handChar.scaleX = -1;
  145.                                         handChar.gotoAndPlay(5);
  146.                                         mainJump();
  147.                                         return;
  148.                                 }
  149.                                 handChar.x -= speed;
  150.                                 handChar.scaleX = -1;
  151.                                 handChar.gotoAndPlay(1);
  152.                                 return;
  153.                         }
  154.                        
  155.                         if(rightKeyDown)
  156.                         {
  157.                                 if(upKeyDown || mainJumping)
  158.                                 {
  159.                                         handChar.x +=speed;
  160.                                         handChar.scaleX = 1;
  161.                                         handChar.gotoAndPlay(5);
  162.                                         mainJump();
  163.                                         return;
  164.                                 }
  165.                                 handChar.x += speed;
  166.                                 handChar.scaleX = 1;
  167.                                 handChar.gotoAndPlay(1);
  168.                                 return;
  169.                         }
  170.                        
  171.                         if(upKeyDown || mainJumping)
  172.                         {
  173.                                 handChar.gotoAndPlay(5);
  174.                                 mainJump();
  175.                                 return;
  176.                         }
  177.                        
  178.                         if(hKeyDown)
  179.                         {
  180.                                 handChar.gotoAndStop("scissor");
  181.                                 return;
  182.                         }
  183.                        
  184.                         if(jKeyDown)
  185.                         {
  186.                                 handChar.gotoAndStop("paper");
  187.                                 return;
  188.                         }
  189.                        
  190.                         if(kKeyDown)
  191.                         {
  192.                                 handChar.gotoAndStop("rock");
  193.                                 return;
  194.                         }
  195.                        
  196.                         handChar.gotoAndPlay(3);
  197.                 } // end private function Movehand
  198.                
  199.                 private function boundaries (e:Event):void
  200.                  { // start private function boundaries
  201.                          if(handChar.x > stage.stageWidth - handChar.width/2)
  202.                          {
  203.                                  handChar.x = stage.stageWidth - handChar.width/2;
  204.                          }
  205.                          if(handChar.x < 15)
  206.                          {
  207.                                  handChar.x = 15;
  208.                          }
  209.          } // end private function boundaries
  210.                        
  211.                
  212.                 private function mainJump():void
  213.                 { // start private function mainJump
  214.                         if(!mainJumping)
  215.                         {
  216.                                 mainJumping = true;
  217.                                 jumpSpeed = jumpSpeedLimit*-1;
  218.                                 handChar.y += jumpSpeed;
  219.                         }
  220.                         else
  221.                         {
  222.                         if(jumpSpeed < 0)
  223.                         {
  224.                                 jumpSpeed *= 1 - jumpSpeedLimit/75;
  225.                         if(jumpSpeed > -jumpSpeedLimit/5)
  226.                                 {
  227.                                         jumpSpeed *= -1;
  228.                                 }
  229.                         }
  230.                         if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
  231.                                 {
  232.                                         jumpSpeed *= 1 + jumpSpeedLimit/50;
  233.                                 }
  234.                         handChar.y += jumpSpeed;
  235.                        
  236.                         if(handChar.y >= stage.stageHeight - handChar.height)
  237.                                 {
  238.                                 mainJumping = false;
  239.                                 handChar.y = stage.stageHeight - handChar.height;
  240.                                 }
  241.                         }
  242.                 } // end private function mainJump
  243.                 } // end public class Main
  244. } // end package
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: