change player sprite to ninja
GitOrigin-RevId: 73bc09808a1abf1a130986adfed1d3aa6d220b5c
This commit is contained in:
parent
a240f0dc31
commit
0e363de306
@ -18,8 +18,11 @@ namespace SemiColinGames {
|
|||||||
private const int gravity = 2400;
|
private const int gravity = 2400;
|
||||||
|
|
||||||
// Details of the sprite image.
|
// Details of the sprite image.
|
||||||
private const int spriteSize = 48;
|
// player_1x is 48 x 48, yOffset=5, halfSize=(7, 14)
|
||||||
private const int spriteCenterYOffset = 5;
|
// 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;
|
private readonly Texture2D texture;
|
||||||
|
|
||||||
// Details of the actual Player model.
|
// 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
|
// 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.
|
// centered at that point and extending out by halfSize.X and halfSize.Y.
|
||||||
private Point position = new Point(64, 16 * 13);
|
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 int jumps = 0;
|
||||||
private Facing facing = Facing.Right;
|
private Facing facing = Facing.Right;
|
||||||
private Pose pose = Pose.Jumping;
|
private Pose pose = Pose.Jumping;
|
||||||
private double swordSwingTime = 0;
|
private double swordSwingTime = 0;
|
||||||
private double jumpTime = 0;
|
|
||||||
private float ySpeed = 0;
|
private float ySpeed = 0;
|
||||||
|
|
||||||
public Player(Texture2D texture) {
|
public Player(Texture2D texture) {
|
||||||
@ -149,7 +151,6 @@ namespace SemiColinGames {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (input[0].Jump && !input[1].Jump && jumps > 0) {
|
if (input[0].Jump && !input[1].Jump && jumps > 0) {
|
||||||
jumpTime = 0.3;
|
|
||||||
jumps--;
|
jumps--;
|
||||||
ySpeed = jumpSpeed;
|
ySpeed = jumpSpeed;
|
||||||
}
|
}
|
||||||
@ -160,49 +161,42 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
result.Y = ySpeed * modelTime;
|
result.Y = ySpeed * modelTime;
|
||||||
ySpeed += gravity * modelTime;
|
ySpeed += gravity * modelTime;
|
||||||
jumpTime -= modelTime;
|
|
||||||
swordSwingTime -= modelTime;
|
swordSwingTime -= modelTime;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int SpriteIndex(Pose pose) {
|
private int SpriteIndex(Pose pose) {
|
||||||
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4;
|
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4;
|
||||||
if (frameNum == 3) {
|
if (frameNum == 3 && pose == Pose.Standing) {
|
||||||
frameNum = 1;
|
frameNum = 1;
|
||||||
}
|
}
|
||||||
switch (pose) {
|
switch (pose) {
|
||||||
case Pose.Walking:
|
case Pose.Walking:
|
||||||
return 6 + frameNum;
|
return 35 + frameNum;
|
||||||
case Pose.Stretching:
|
|
||||||
return 18 + frameNum;
|
|
||||||
case Pose.Jumping:
|
case Pose.Jumping:
|
||||||
if (jumpTime > 0.2) {
|
return 35 + frameNum;
|
||||||
|
case Pose.Stretching:
|
||||||
|
return 22 + (int) Clock.ModelTime.TotalMilliseconds / 125 % 2;
|
||||||
|
case Pose.SwordSwing:
|
||||||
|
if (swordSwingTime > 0.2) {
|
||||||
return 15;
|
return 15;
|
||||||
} else if (jumpTime > 0.1) {
|
} else if (swordSwingTime > 0.1) {
|
||||||
return 16;
|
return 16;
|
||||||
} else {
|
} else {
|
||||||
return 17;
|
return 17;
|
||||||
}
|
}
|
||||||
case Pose.SwordSwing:
|
|
||||||
if (swordSwingTime > 0.2) {
|
|
||||||
return 30;
|
|
||||||
} else if (swordSwingTime > 0.1) {
|
|
||||||
return 31;
|
|
||||||
} else {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
case Pose.Crouching:
|
case Pose.Crouching:
|
||||||
return 25;
|
return 26;
|
||||||
case Pose.Standing:
|
case Pose.Standing:
|
||||||
default:
|
default:
|
||||||
return 7;
|
return 29 + frameNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, Camera camera) {
|
public void Draw(SpriteBatch spriteBatch, Camera camera) {
|
||||||
int index = SpriteIndex(pose);
|
int index = SpriteIndex(pose);
|
||||||
Rectangle textureSource = new Rectangle(index * spriteSize, 0, spriteSize, spriteSize);
|
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight);
|
||||||
Vector2 spriteCenter = new Vector2(spriteSize / 2, spriteSize / 2 + spriteCenterYOffset);
|
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
|
||||||
SpriteEffects effect = facing == Facing.Right ?
|
SpriteEffects effect = facing == Facing.Right ?
|
||||||
SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
||||||
Vector2 drawPos = new Vector2(position.X - camera.Left, position.Y);
|
Vector2 drawPos = new Vector2(position.X - camera.Left, position.Y);
|
||||||
|
@ -57,7 +57,7 @@ namespace SemiColinGames {
|
|||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
font = Content.Load<SpriteFont>("font");
|
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"));
|
world = new World(Content.Load<Texture2D>("grassland"));
|
||||||
grasslandBg1 = Content.Load<Texture2D>("grassland_bg1");
|
grasslandBg1 = Content.Load<Texture2D>("grassland_bg1");
|
||||||
grasslandBg2 = Content.Load<Texture2D>("grassland_bg2");
|
grasslandBg2 = Content.Load<Texture2D>("grassland_bg2");
|
||||||
|
Loading…
Reference in New Issue
Block a user