forked from rliebz/Puddle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controls.cs
59 lines (51 loc) · 1.63 KB
/
Controls.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 System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
namespace Puddle
{
class Controls
{
public KeyboardState kb;
public KeyboardState kbo;
public GamePadState gp;
public GamePadState gpo;
public Controls()
{
this.kb = Keyboard.GetState();
this.kbo = Keyboard.GetState();
this.gp = GamePad.GetState(PlayerIndex.One);
this.gpo = GamePad.GetState(PlayerIndex.One);
}
public void Update()
{
kbo = kb;
gpo = gp;
kb = Keyboard.GetState();
this.gp = GamePad.GetState(PlayerIndex.One);
}
public bool isPressed(Keys key, Buttons button)
{
return kb.IsKeyDown(key) || gp.IsButtonDown(button);
}
public bool onPress(Keys key, Buttons button)
{
return (kb.IsKeyDown(key) && kbo.IsKeyUp(key)) ||
(gp.IsButtonDown(button) && gpo.IsButtonUp(button));
}
public bool onRelease(Keys key, Buttons button)
{
return (kb.IsKeyUp(key) && kbo.IsKeyDown(key)) ||
(gp.IsButtonUp(button) && gpo.IsButtonDown(button));
}
public bool isHeld(Keys key, Buttons button)
{
return (kb.IsKeyDown(key) && kbo.IsKeyDown(key)) ||
(gp.IsButtonDown(button) && gpo.IsButtonDown(button));
}
}
}