KunoNoOni

player.as

Apr 24th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import org.flixel.*;
  4.    
  5.     public class Player extends FlxSprite
  6.     {
  7.         public var bulletArray:Array;
  8.         private var bulletID:int = 0;
  9.         private var bullet:FlxSprite;
  10.         private var threshold:Number = 0.3;
  11.         private var counter:Number = 0;    
  12.        
  13.         public function Player(X:Number=0, Y:Number=0)
  14.         {
  15.             super(X*8,Y*8);
  16.             loadGraphic(Registry.player,true,true,8,8);
  17.         }
  18.        
  19.         override public function update():void
  20.         {
  21.             velocity.x = 0;
  22.             velocity.y = 0;
  23.             counter += FlxG.elapsed;
  24.             trace("timer: "+counter+" FlxG.elapsed: "+FlxG.elapsed+" threshold: "+threshold);
  25.            
  26.            
  27.             if(FlxG.keys.LEFT)
  28.             {
  29.                 velocity.x = -50;
  30.             }
  31.            
  32.             if(FlxG.keys.RIGHT)
  33.             {
  34.                 velocity.x = 50;
  35.             }
  36.            
  37.             if(FlxG.keys.UP)
  38.             {
  39.                 velocity.y = -50;
  40.             }
  41.            
  42.             if(FlxG.keys.DOWN)
  43.             {
  44.                 velocity.y = 50;
  45.             }
  46.            
  47.             if(FlxG.keys.justPressed("SPACE"))
  48.             {
  49.  
  50.                 if(counter >= threshold)
  51.                 {
  52.                     counter = 0;
  53.                     FlxG.play(Registry.fire,0.5);
  54.                     bullet = bulletArray[bulletID];
  55.                     bullet.reset(x + 3,y + 10);
  56.                     bullet.velocity.y = -400;
  57.                     bulletID++;
  58.                     if(bulletID == 20)
  59.                     {
  60.                         bulletID = 0;
  61.                     }  
  62.                 }
  63.             }
  64.             super.update();
  65.         }
  66.        
  67.         private function fireDelay():void
  68.         {
  69.            
  70.            
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment