Guest User

Untitled

a guest
Oct 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.lordned
  2. {
  3.     import com.senocular.utils.KeyObject;
  4.     import flash.display.Sprite;
  5.     import flash.ui.Keyboard;
  6.     import me.Utils;
  7.     /**
  8.      * ...
  9.      * @author Matt "Lord Ned" Hoffman
  10.      */
  11.     public class Ramona extends MovieClipComponent
  12.     {
  13.        
  14.         //Keyboard Input
  15.         var key:KeyObject;
  16.        
  17.         //Player Movement Variables
  18.         var playerSpeed:int;
  19.         var playerIsMoving:Boolean;
  20.        
  21.         public function Ramona()
  22.         {
  23.             super();
  24.            
  25.             trace("Ramona created.");
  26.             playerSpeed = 5;
  27.             loops = false;
  28.             key = new KeyObject(this.parent.stage);
  29.            
  30.             Engine.profiler.Register(this, "x");
  31.             Engine.profiler.Register(this, "y");
  32.         }
  33.        
  34.         override public function Update():void
  35.         {
  36.             /*trace("Scale: " + (y/100) + ", Clamped: " + Utils.Clamp((y / 100), 0.8, 1.2));
  37.             scaleX = Utils.Clamp((y / 100), 0.9, 1.2);
  38.             scaleY = Utils.Clamp((y / 100), 0.9, 1.2);*/
  39.            
  40.             if (key.isDown(Keyboard.LEFT))
  41.             {
  42.                 if(currentLabel != "running")
  43.                     gotoAndPlay("running");
  44.                 loops = true;
  45.                 this.x -= playerSpeed;
  46.                
  47.                 scaleX = -1;
  48.                 playerIsMoving = true;
  49.             }
  50.             else if (key.isDown(Keyboard.RIGHT))
  51.             {
  52.                 loops = true;
  53.                 if(currentLabel != "running")
  54.                     gotoAndPlay("running");
  55.                 this.x += playerSpeed;
  56.                
  57.                 this.scaleX = 1;
  58.                 playerIsMoving = true;
  59.             }
  60.             else
  61.             {
  62.                 playerIsMoving = false;
  63.             }
  64.            
  65.             if (key.isDown(Keyboard.UP))
  66.             {
  67.                 this.y -= playerSpeed;
  68.             }
  69.             else if (key.isDown(Keyboard.DOWN))
  70.             {
  71.                 this.y += playerSpeed;
  72.             }
  73.            
  74.             if (key.isDown(Keyboard.SPACE))
  75.             {
  76.                 gotoAndPlay("attack_hammer");
  77.                 loops = true;
  78.                
  79.                 for (var i:int = 0; i < Engine.ComponentSprite.numChildren; i++)
  80.                 {
  81.                     if (hitTestObject(Engine.ComponentSprite.getChildAt(i)))
  82.                     {
  83.                         Component(Engine.ComponentSprite.getChildAt(i)).OnHit();
  84.                     }
  85.                 }
  86.             }
  87.             else
  88.             {
  89.                 if ((currentLabel != "attack_hammer") && (currentLabel != "running"))
  90.                 {
  91.                     loops = false;
  92.                     gotoAndStop("default");
  93.                 }
  94.             }
  95.            
  96.             trace("PlayerIsmoving: " + playerIsMoving);
  97.            
  98.             super.Update();
  99.         }
  100.        
  101.     }
  102.  
  103. }
Add Comment
Please, Sign In to add comment