-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cs
53 lines (42 loc) · 2.01 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
using GoRogue;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using SadConsole;
namespace RunicQuest
{
// Custom class for the player is used in this example just so we can handle input. This could be done via a component, or in a main screen, but for simplicity we do it here.
internal class Player : BasicEntity
{
private static readonly Dictionary<Keys, Direction> s_movementDirectionMapping = new Dictionary<Keys, Direction>
{
{ Keys.NumPad7, Direction.UP_LEFT }, { Keys.NumPad8, Direction.UP }, { Keys.NumPad9, Direction.UP_RIGHT },
{ Keys.NumPad4, Direction.LEFT }, { Keys.NumPad6, Direction.RIGHT },
{ Keys.NumPad1, Direction.DOWN_LEFT }, { Keys.NumPad2, Direction.DOWN }, { Keys.NumPad3, Direction.DOWN_RIGHT },
{ Keys.Up, Direction.UP }, { Keys.Down, Direction.DOWN }, { Keys.Left, Direction.LEFT }, { Keys.Right, Direction.RIGHT }
};
public int FOVRadius;
public Player(Coord position)
: base(Color.Red, Color.Black, '@', position, (int)MapLayer.PLAYER, isWalkable: false, isTransparent: true) => FOVRadius = 2;
public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
{
Direction moveDirection = Direction.NONE;
// Simplified way to check if any key we care about is pressed and set movement direction.
foreach (Keys key in s_movementDirectionMapping.Keys)
{
if (info.IsKeyPressed(key))
{
moveDirection = s_movementDirectionMapping[key];
PlayerStats.StepsTaken += 1;
System.Console.WriteLine($"{PlayerStats.StepsTaken}");
break;
}
}
Position += moveDirection;
if (moveDirection != Direction.NONE)
return true;
else
return base.ProcessKeyboard(info);
}
}
}