-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerControls.cs
59 lines (47 loc) · 1.32 KB
/
PlayerControls.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
54
55
56
57
58
59
using Microsoft.Xna.Framework.Input;
/**
* Interface to define a player controller.
*
* Can be used to implement keyboard controlls or AI based controlls.
*/
interface PlayerControls
{
/**
* Move the player UP
*/
public bool up();
/**
* Move the player Down
*/
public bool down();
/**
* Move the player Left
*/
public bool left();
/**
* Move the player Right
*/
public bool right();
/**
* Place a bomb.
*/
public bool bomb();
}
class PlayerKeyboardControls : PlayerControls
{
public static Keys[] KeysP1 = { Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.M };
public static Keys[] KeysP2 = { Keys.W, Keys.S, Keys.A, Keys.D, Keys.Q };
/**
* List of keys to use in this player controller
*/
public Keys[] keys = PlayerKeyboardControls.KeysP1;
public PlayerKeyboardControls(Keys[] keys)
{
this.keys = keys;
}
public bool up() { return Keyboard.GetState().IsKeyDown(this.keys[0]); }
public bool down() { return Keyboard.GetState().IsKeyDown(this.keys[1]); }
public bool left() { return Keyboard.GetState().IsKeyDown(this.keys[2]); }
public bool right() { return Keyboard.GetState().IsKeyDown(this.keys[3]); }
public bool bomb() { return Keyboard.GetState().IsKeyDown(this.keys[4]); }
}