player direction changes while moving
This commit is contained in:
parent
8781cab2aa
commit
df7c05c2e3
@ -18,12 +18,21 @@ public class Player
|
|||||||
public int CurrentSelectedTileId = 1;
|
public int CurrentSelectedTileId = 1;
|
||||||
private int _currentSelectedIndex = 0;
|
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")
|
public Player(string name, int id = 0, string imagePath = "data/core/player/dude.png")
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Id = id;
|
Id = id;
|
||||||
_imagePath = imagePath;
|
_imagePath = imagePath;
|
||||||
|
|
||||||
|
_currentRect = _facingRightRect;
|
||||||
|
|
||||||
InitTexture();
|
InitTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +44,9 @@ public class Player
|
|||||||
|
|
||||||
public void Draw()
|
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();
|
DrawPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +59,17 @@ public class Player
|
|||||||
{
|
{
|
||||||
// WASD
|
// WASD
|
||||||
if (Raylib.IsKeyDown(KeyboardKey.W)) Position += new Vector2(0, -1) * Speed;
|
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.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
|
// Speed control
|
||||||
if (Raylib.IsKeyReleased(KeyboardKey.Up)) Speed += 1f;
|
if (Raylib.IsKeyReleased(KeyboardKey.Up)) Speed += 1f;
|
||||||
|
Loading…
Reference in New Issue
Block a user