Commits

Tao Chen committed e01a99a

roll in sprite

Comments (0)

Files changed (5)

 		[Embed(source="./data/masktile.png")]
 		private static var s_tileImg:Class;
 		
-		
 		public function Level() 
 		{
 			super();

woot/PlayState.as

 			FlxG.camera.follow(player1);
 			// DEBUG
 			FlxG.watch(BulletMan.playerBullet, "length");
-						FlxG.watch(BulletMan.enemyBullet, "length");
+			FlxG.watch(BulletMan.enemyBullet, "length");
 		}
 		
 		override public function update():void
 	 */
 	public class Player extends FlxSprite 
 	{
+		[Embed(source="./data/player.png")]
+		private static var s_player:Class;
+		
 		static private var SPEED : int = 180;
 		static private var JUMP : int = 800;
 		static private var MAXSPEED_Y : int = 300;
 		{
 			super(0, 0);
 			fill(0xFFFF0000);
-			width = 32;
+			width = 48;
 			height = 64;
 			pid = n;
-			centerOffsets();
 			
 			acceleration.y = Comm.GRAVITY;
 			maxVelocity.y = MAXSPEED_Y;
 			
+			// animation
+			loadGraphic(s_player, true, true, 48, 64);
+			addAnimation("idle", [1]);
+			addAnimation("lookfront", [0, 1, 2], 6);
+			addAnimation("lookupper", [3, 4, 5], 6);
+			addAnimation("looklower", [6, 7, 8], 6);
+			addAnimation("lookup", [9, 10, 11], 6);
+			addAnimation("crouch", [12]);
+			addAnimation("dead", [13, 14]);
+			addAnimation("roll", [15, 16, 17], 6);
+			
 			allowCollisions = FlxObject.DOWN;
+			centerOffsets();
 		}
 		
 		override public function update():void
 		{
-			if (pid == 1)
+
+			if (FlxG.keys.A)
 			{
-				if (FlxG.keys.A)
+				velocity.x = -SPEED;
+			}
+			else if (FlxG.keys.D)
+			{
+				velocity.x = SPEED;
+			}
+			else
+			{
+				velocity.x = 0;
+			}
+			
+			if (FlxG.keys.justPressed("S")) {
+				solid = false;
+				_fallingStart = y;
+			}
+			
+			if (FlxG.keys.justPressed("W") && isTouching(FlxObject.FLOOR))
+			{
+				velocity.y = -JUMP;
+			}
+			
+			var screenXY : FlxPoint = getScreenXY();
+			var dx : Number = FlxG.mouse.screenX - screenXY.x - origin.x;
+			var dy : Number = FlxG.mouse.screenY - screenXY.y - origin.y;
+			var deg : Number = Comm.rad2deg(Math.atan2(dy, dx));
+			var dir : uint = Comm.deg2dir(deg);
+			
+			if (FlxG.mouse.justPressed())
+			{
+				BulletMan.AddPlayerBullet(dir, this);
+			}
+			
+			// animation
+			if (!isTouching(DOWN))
+			{
+				play("roll");
+			}
+			else
+			{
+				if (velocity.x < 0) {
+					facing = LEFT
+				} else {
+					facing = RIGHT;
+				}
+				switch (dir)
 				{
-					velocity.x = -SPEED;
-				}
-				else if (FlxG.keys.D)
-				{
-					velocity.x = SPEED;
-				}
-				else
-				{
-					velocity.x = 0;
-				}
-				
-				if (FlxG.keys.justPressed("S")) {
-					solid = false;
-					_fallingStart = y;
-				}
-				
-				if (FlxG.keys.justPressed("W") && isTouching(FlxObject.FLOOR))
-				{
-					velocity.y = -JUMP;
-				}
-				
-				if (FlxG.mouse.justPressed())
-				{
-					var dir : uint;
-					var screenXY : FlxPoint = getScreenXY();
-					var dx : Number = FlxG.mouse.screenX - screenXY.x - origin.x;
-					var dy : Number = FlxG.mouse.screenY - screenXY.y - origin.y;
-					var deg : Number = Comm.rad2deg(Math.atan2(dy, dx));
-					FlxG.log(deg);
-					FlxG.log(Comm.deg2dir(deg));
-					BulletMan.AddPlayerBullet(Comm.deg2dir(deg), this);
+					case 3:
+					case 1:
+						play("looklower");
+						break;
+					case 4:
+					case 6:
+						play("lookfront");
+						break;
+					case 7:
+					case 9:
+						play("lookupper");
+						break;
+					case 8:
+						play("lookup");
+						break;
 				}
 			}
 			
 			
+
+			
 			if (!solid && y - _fallingStart > 32)
 			{
 				solid = true;

woot/data/player.png

Added
New image

woot/data/player.xml

Binary file added.