-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputHandler.cs
86 lines (72 loc) · 2.51 KB
/
InputHandler.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Insanity.Actors;
using Insanity.GameStates;
namespace Insanity
{
public class InputHandler : IInputAgent
{
KeyboardState CurrentKeyboardState;
KeyboardState OldKeyboardState;
public InputHandler()
{
}
public bool Quit()
{
return CurrentKeyboardState.IsKeyDown(Keys.Escape);
}
public void Update(GameTime gameTime, Actor agent = null)
{
OldKeyboardState = CurrentKeyboardState;
CurrentKeyboardState = Keyboard.GetState();
}
public bool MoveRight()
{
return CurrentKeyboardState.IsKeyDown(Keys.D) || CurrentKeyboardState.IsKeyDown(Keys.Right);
}
public bool MoveLeft()
{
return CurrentKeyboardState.IsKeyDown(Keys.A) || CurrentKeyboardState.IsKeyDown(Keys.Left);
}
public bool Jump()
{
return (CurrentKeyboardState.IsKeyDown(Keys.W) && !OldKeyboardState.IsKeyDown(Keys.W)) ||
(CurrentKeyboardState.IsKeyDown(Keys.Up) && !OldKeyboardState.IsKeyDown(Keys.Up));
}
public bool NewUpPress()
{
return (CurrentKeyboardState.IsKeyDown(Keys.W) && !OldKeyboardState.IsKeyDown(Keys.W)) ||
(CurrentKeyboardState.IsKeyDown(Keys.Up) && !OldKeyboardState.IsKeyDown(Keys.Up));
}
public bool NewDownPress()
{
return (CurrentKeyboardState.IsKeyDown(Keys.S) && !OldKeyboardState.IsKeyDown(Keys.S)) ||
(CurrentKeyboardState.IsKeyDown(Keys.Down) && !OldKeyboardState.IsKeyDown(Keys.Down));
}
public bool NewEnterPress()
{
return CurrentKeyboardState.IsKeyDown(Keys.Enter) && !OldKeyboardState.IsKeyDown(Keys.Enter);
}
public bool Pause()
{
return CurrentKeyboardState.IsKeyDown(Keys.Escape) && !OldKeyboardState.IsKeyDown(Keys.Escape);
}
public bool TakePill()
{
return CurrentKeyboardState.IsKeyDown(Keys.C) && !OldKeyboardState.IsKeyDown(Keys.C);
}
public bool ViewPhoto()
{
return CurrentKeyboardState.IsKeyDown(Keys.X) && !OldKeyboardState.IsKeyDown(Keys.X);
}
protected Level LevelRef;
public void GiveLevel(Level level)
{
LevelRef = level;
}
}
}