Browse Source

change player sprite to ninja

GitOrigin-RevId: 73bc09808a
master
Colin McMillen 4 years ago
parent
commit
0e363de306
  1. 42
      Shared/Player.cs
  2. 2
      Shared/SneakGame.cs

42
Shared/Player.cs

@ -18,8 +18,11 @@ namespace SemiColinGames {
private const int gravity = 2400;
// Details of the sprite image.
private const int spriteSize = 48;
private const int spriteCenterYOffset = 5;
// player_1x is 48 x 48, yOffset=5, halfSize=(7, 14)
// Ninja_Female is 96 x 64, yOffset=1, halfSize=(11, 24)
private const int spriteWidth = 96;
private const int spriteHeight = 64;
private const int spriteCenterYOffset = 1;
private readonly Texture2D texture;
// Details of the actual Player model.
@ -27,13 +30,12 @@ namespace SemiColinGames {
// Position is tracked at the Player's center. The Player's bounding box is a rectangle
// centered at that point and extending out by halfSize.X and halfSize.Y.
private Point position = new Point(64, 16 * 13);
private Vector2 halfSize = new Vector2(7, 14);
private Vector2 halfSize = new Vector2(11, 24);
private int jumps = 0;
private Facing facing = Facing.Right;
private Pose pose = Pose.Jumping;
private double swordSwingTime = 0;
private double jumpTime = 0;
private float ySpeed = 0;
public Player(Texture2D texture) {
@ -149,7 +151,6 @@ namespace SemiColinGames {
};
if (input[0].Jump && !input[1].Jump && jumps > 0) {
jumpTime = 0.3;
jumps--;
ySpeed = jumpSpeed;
}
@ -160,49 +161,42 @@ namespace SemiColinGames {
result.Y = ySpeed * modelTime;
ySpeed += gravity * modelTime;
jumpTime -= modelTime;
swordSwingTime -= modelTime;
return result;
}
private int SpriteIndex(Pose pose) {
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4;
if (frameNum == 3) {
if (frameNum == 3 && pose == Pose.Standing) {
frameNum = 1;
}
switch (pose) {
case Pose.Walking:
return 6 + frameNum;
case Pose.Stretching:
return 18 + frameNum;
return 35 + frameNum;
case Pose.Jumping:
if (jumpTime > 0.2) {
return 15;
} else if (jumpTime > 0.1) {
return 16;
} else {
return 17;
}
return 35 + frameNum;
case Pose.Stretching:
return 22 + (int) Clock.ModelTime.TotalMilliseconds / 125 % 2;
case Pose.SwordSwing:
if (swordSwingTime > 0.2) {
return 30;
return 15;
} else if (swordSwingTime > 0.1) {
return 31;
return 16;
} else {
return 32;
return 17;
}
case Pose.Crouching:
return 25;
return 26;
case Pose.Standing:
default:
return 7;
return 29 + frameNum;
}
}
public void Draw(SpriteBatch spriteBatch, Camera camera) {
int index = SpriteIndex(pose);
Rectangle textureSource = new Rectangle(index * spriteSize, 0, spriteSize, spriteSize);
Vector2 spriteCenter = new Vector2(spriteSize / 2, spriteSize / 2 + spriteCenterYOffset);
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight);
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
SpriteEffects effect = facing == Facing.Right ?
SpriteEffects.FlipHorizontally : SpriteEffects.None;
Vector2 drawPos = new Vector2(position.X - camera.Left, position.Y);

2
Shared/SneakGame.cs

@ -57,7 +57,7 @@ namespace SemiColinGames {
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font");
player = new Player(Content.Load<Texture2D>("player_1x"));
player = new Player(Content.Load<Texture2D>("Ninja_Female"));
world = new World(Content.Load<Texture2D>("grassland"));
grasslandBg1 = Content.Load<Texture2D>("grassland_bg1");
grasslandBg2 = Content.Load<Texture2D>("grassland_bg2");

Loading…
Cancel
Save