Guest User

Untitled

a guest
Aug 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TODO: FIX SPRITES
  2.  
  3. package
  4. {
  5.     import net.flashpunk.Entity;
  6.     import net.flashpunk.FP;
  7.     import net.flashpunk.graphics.Image;
  8.     import net.flashpunk.graphics.Spritemap;
  9.     import net.flashpunk.utils.Input;
  10.     import net.flashpunk.utils.Key;
  11.    
  12.     public class Player extends Entity
  13.     {
  14.         [Embed(source = "assets/player.png")]
  15.         private const GFX_PLAYER:Class;
  16.        
  17.         public var sPlayer:Spritemap = new Spritemap(GFX_PLAYER,28,40);
  18.         public var LEFT:Boolean;
  19.         public var RIGHT:Boolean;
  20.        
  21.         public function Player()
  22.         {
  23.            
  24.             LEFT=true;
  25.             RIGHT=false;
  26.            
  27.             graphic = sPlayer;
  28.            
  29.             sPlayer.add("idleL",[0],20,true);
  30.             sPlayer.add("idleR",[5],20,true);
  31.             sPlayer.add("runL",[1,2,3,4],20,true);
  32.             sPlayer.add("runR",[6,7,8,9],20,true);
  33.            
  34.             setHitbox(28,40);
  35.            
  36.             x=288;
  37.             y=32;
  38.         }
  39.        
  40.         override public function update():void
  41.         {
  42.             if(Input.check(Key.D))
  43.             {
  44.                 x += 120 * FP.elapsed;
  45.                 LEFT=false;
  46.                 RIGHT=true;
  47.             }
  48.             if(Input.check(Key.A))
  49.             {
  50.                 x -= 120 * FP.elapsed;
  51.                 LEFT=true;
  52.                 RIGHT=false;
  53.             }
  54.             if(Input.check(Key.W))
  55.             {
  56.                 y -= 120 * FP.elapsed;
  57.             }
  58.             if(Input.check(Key.S))
  59.             {
  60.                 y += 120 * FP.elapsed;
  61.             }
  62.             if(Input.check(Key.RIGHT))
  63.             {
  64.                
  65.             }
  66.            
  67.             if(LEFT==true)
  68.             {
  69.                 if(Input.released(Key.D))
  70.                 {
  71.                     sPlayer.play("idleL");
  72.                 }
  73.                 else{
  74.                     sPlayer.play("runL");
  75.                 }
  76.             }
  77.             if(RIGHT==true)
  78.             {
  79.                 if(Input.released(Key.A))
  80.                 {
  81.                     sPlayer.play("idleR");
  82.                 }else{
  83.                     sPlayer.play("runR");
  84.                 }
  85.             }
  86.            
  87.             if(x>660)
  88.             {
  89.                 x = -30;
  90.             }
  91.             if(x<-30)
  92.             {
  93.                 x = 660;
  94.             }
  95.             if(y<-36)
  96.             {
  97.                 y = 500;
  98.             }
  99.             if(y>516)
  100.             {
  101.                 y = -36;
  102.             }
  103.            
  104.             if(collide("level",x,y))
  105.             {
  106.                
  107.             }
  108.         }
  109.     }
  110. }
Add Comment
Please, Sign In to add comment