diff --git a/Tiles/Player.cs b/Tiles/Player.cs index 276e455..8cbdede 100644 --- a/Tiles/Player.cs +++ b/Tiles/Player.cs @@ -18,12 +18,21 @@ public class Player public int CurrentSelectedTileId = 1; private int _currentSelectedIndex = 0; + private int _direction = 1; + + private Rectangle _facingRightRect = new Rectangle(0, 0, 16, 24); + private Rectangle _facingLeftRect = new Rectangle(0, 0, -16, 24); + + private Rectangle _currentRect; + public Player(string name, int id = 0, string imagePath = "data/core/player/dude.png") { Name = name; Id = id; _imagePath = imagePath; + _currentRect = _facingRightRect; + InitTexture(); } @@ -35,7 +44,9 @@ public class Player public void Draw() { - Raylib.DrawTexture(Texture, (int)Position.X, (int)Position.Y, Color.White); + //Raylib.DrawTexture(Texture, (int)Position.X, (int)Position.Y, Color.White); + if (_direction == 0) Raylib.DrawTextureRec(Texture, _facingLeftRect, Position, Color.White); + else Raylib.DrawTextureRec(Texture, _facingRightRect, Position, Color.White); DrawPointer(); } @@ -48,9 +59,17 @@ public class Player { // WASD if (Raylib.IsKeyDown(KeyboardKey.W)) Position += new Vector2(0, -1) * Speed; - if (Raylib.IsKeyDown(KeyboardKey.A)) Position += new Vector2(-1, 0) * Speed; + if (Raylib.IsKeyDown(KeyboardKey.A)) + { + Position += new Vector2(-1, 0) * Speed; + _direction = 0; + } if (Raylib.IsKeyDown(KeyboardKey.S)) Position += new Vector2(0, 1) * Speed; - if (Raylib.IsKeyDown(KeyboardKey.D)) Position += new Vector2(1, 0) * Speed; + if (Raylib.IsKeyDown(KeyboardKey.D)) + { + Position += new Vector2(1, 0) * Speed; + _direction = 1; + } // Speed control if (Raylib.IsKeyReleased(KeyboardKey.Up)) Speed += 1f;