Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TODO: FIX SPRITES
- package
- {
- import net.flashpunk.Entity;
- import net.flashpunk.FP;
- import net.flashpunk.graphics.Image;
- import net.flashpunk.graphics.Spritemap;
- import net.flashpunk.utils.Input;
- import net.flashpunk.utils.Key;
- public class Player extends Entity
- {
- [Embed(source = "assets/player.png")]
- private const GFX_PLAYER:Class;
- public var sPlayer:Spritemap = new Spritemap(GFX_PLAYER,28,40);
- public var LEFT:Boolean;
- public var RIGHT:Boolean;
- public function Player()
- {
- LEFT=true;
- RIGHT=false;
- graphic = sPlayer;
- sPlayer.add("idleL",[0],20,true);
- sPlayer.add("idleR",[5],20,true);
- sPlayer.add("runL",[1,2,3,4],20,true);
- sPlayer.add("runR",[6,7,8,9],20,true);
- setHitbox(28,40);
- x=288;
- y=32;
- }
- override public function update():void
- {
- if(Input.check(Key.D))
- {
- x += 120 * FP.elapsed;
- LEFT=false;
- RIGHT=true;
- }
- if(Input.check(Key.A))
- {
- x -= 120 * FP.elapsed;
- LEFT=true;
- RIGHT=false;
- }
- if(Input.check(Key.W))
- {
- y -= 120 * FP.elapsed;
- }
- if(Input.check(Key.S))
- {
- y += 120 * FP.elapsed;
- }
- if(Input.check(Key.RIGHT))
- {
- }
- if(LEFT==true)
- {
- if(Input.released(Key.D))
- {
- sPlayer.play("idleL");
- }
- else{
- sPlayer.play("runL");
- }
- }
- if(RIGHT==true)
- {
- if(Input.released(Key.A))
- {
- sPlayer.play("idleR");
- }else{
- sPlayer.play("runR");
- }
- }
- if(x>660)
- {
- x = -30;
- }
- if(x<-30)
- {
- x = 660;
- }
- if(y<-36)
- {
- y = 500;
- }
- if(y>516)
- {
- y = -36;
- }
- if(collide("level",x,y))
- {
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment