|
|
@ -9,16 +9,16 @@ namespace Jumpy { |
|
|
|
enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping }; |
|
|
|
enum AirState { Jumping, Ground }; |
|
|
|
|
|
|
|
private const int spriteSize = 144; |
|
|
|
private const int spriteWidth = 20; |
|
|
|
private const int moveSpeed = 600; |
|
|
|
private const int jumpSpeed = 1800; |
|
|
|
private const int gravity = 6000; |
|
|
|
private const int spriteSize = 48; |
|
|
|
private const int spriteWidth = 8; |
|
|
|
private const int moveSpeed = 200; |
|
|
|
private const int jumpSpeed = 600; |
|
|
|
private const int gravity = 2000; |
|
|
|
private Texture2D texture; |
|
|
|
|
|
|
|
// TODO: stop assuming 1920x1080.
|
|
|
|
private const int groundLevel = 1080 - spriteSize / 2 - 200; |
|
|
|
private Vector2 position = new Vector2(200, groundLevel); |
|
|
|
private const int groundLevel = 180 - spriteSize / 2 - 10; |
|
|
|
private Point position = new Point(200, groundLevel); |
|
|
|
private Facing facing = Facing.Right; |
|
|
|
private Pose pose = Pose.Standing; |
|
|
|
private AirState airState = AirState.Ground; |
|
|
@ -48,11 +48,11 @@ namespace Jumpy { |
|
|
|
if (gamePad.DPad.Left == ButtonState.Pressed || leftStick.X < -0.5) { |
|
|
|
facing = Facing.Left; |
|
|
|
pose = Pose.Walking; |
|
|
|
position.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; |
|
|
|
position.X -= (int) (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds); |
|
|
|
} else if (gamePad.DPad.Right == ButtonState.Pressed || leftStick.X > 0.5) { |
|
|
|
facing = Facing.Right; |
|
|
|
pose = Pose.Walking; |
|
|
|
position.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; |
|
|
|
position.X += (int) (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds); |
|
|
|
} else if (gamePad.DPad.Down == ButtonState.Pressed || leftStick.Y < -0.5) { |
|
|
|
pose = Pose.Crouching; |
|
|
|
} else if (gamePad.DPad.Up == ButtonState.Pressed || leftStick.Y > 0.5) { |
|
|
@ -70,8 +70,8 @@ namespace Jumpy { |
|
|
|
} |
|
|
|
|
|
|
|
if (airState == AirState.Jumping) { |
|
|
|
position.Y += (float)(ySpeed * gameTime.ElapsedGameTime.TotalSeconds); |
|
|
|
ySpeed += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; |
|
|
|
position.Y += (int) (ySpeed * gameTime.ElapsedGameTime.TotalSeconds); |
|
|
|
ySpeed += gravity * (float) gameTime.ElapsedGameTime.TotalSeconds; |
|
|
|
if (position.Y > groundLevel) { |
|
|
|
position.Y = groundLevel; |
|
|
|
ySpeed = 0; |
|
|
@ -82,7 +82,7 @@ namespace Jumpy { |
|
|
|
pose = Pose.Jumping; |
|
|
|
} |
|
|
|
|
|
|
|
position.X = Math.Min(Math.Max(position.X, 0 + spriteWidth), 1920 - spriteWidth); |
|
|
|
position.X = (int) Math.Min(Math.Max(position.X, 0 + spriteWidth), 320 - spriteWidth); |
|
|
|
} |
|
|
|
|
|
|
|
private Point spritePosition(Pose pose, GameTime time) { |
|
|
@ -126,7 +126,8 @@ namespace Jumpy { |
|
|
|
Vector2 spriteCenter = new Vector2(spriteSize / 2, spriteSize / 2); |
|
|
|
SpriteEffects effect = facing == Facing.Right ? |
|
|
|
SpriteEffects.FlipHorizontally : SpriteEffects.None; |
|
|
|
spriteBatch.Draw(texture, position, textureSource, Color.White, 0f, spriteCenter, |
|
|
|
Vector2 drawPos = new Vector2(position.X, position.Y); |
|
|
|
spriteBatch.Draw(texture, drawPos, textureSource, Color.White, 0f, spriteCenter, |
|
|
|
Vector2.One, effect, 0f); |
|
|
|
} |
|
|
|
} |
|
|
|