From 0e363de3066b03be396a55670ed5fbceed4638a2 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 30 Jan 2020 16:42:31 -0500 Subject: [PATCH] change player sprite to ninja GitOrigin-RevId: 73bc09808a1abf1a130986adfed1d3aa6d220b5c --- Shared/Player.cs | 42 ++++++++++++++++++------------------------ Shared/SneakGame.cs | 2 +- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Shared/Player.cs b/Shared/Player.cs index bbca5cf..70d7b6e 100644 --- a/Shared/Player.cs +++ b/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); diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index ceea94e..cce78a6 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -57,7 +57,7 @@ namespace SemiColinGames { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load("font"); - player = new Player(Content.Load("player_1x")); + player = new Player(Content.Load("Ninja_Female")); world = new World(Content.Load("grassland")); grasslandBg1 = Content.Load("grassland_bg1"); grasslandBg2 = Content.Load("grassland_bg2");