First round of cleanup up the AddonManager a bit
[supertux.git] / src / control / controller.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "control/controller.hpp"
18
19 const char* Controller::controlNames[] = {
20   "left",
21   "right",
22   "up",
23   "down",
24   "jump",
25   "action",
26   "pause-menu",
27   "menu-select",
28   "menu-back",
29   "cheat-menu",
30   "console",
31   "peek-left",
32   "peek-right",
33   "peek-up",
34   "peek-down",
35   0
36 };
37
38 Controller::Controller()
39 {
40   reset();
41 }
42
43 Controller::~Controller()
44 {}
45
46 void
47 Controller::reset()
48 {
49   for(int i = 0; i < CONTROLCOUNT; ++i) {
50     controls[i] = false;
51     oldControls[i] = false;
52   }
53 }
54
55 void
56 Controller::set_control(Control control, bool value)
57 {
58   controls[control] = value;
59 }
60
61 bool
62 Controller::hold(Control control)
63 {
64   return controls[control];
65 }
66
67 bool
68 Controller::pressed(Control control)
69 {
70   return !oldControls[control] && controls[control];
71 }
72
73 bool
74 Controller::released(Control control)
75 {
76   return oldControls[control] && !controls[control];
77 }
78
79 void
80 Controller::update()
81 {
82   for(int i = 0; i < CONTROLCOUNT; ++i)
83     oldControls[i] = controls[i];
84 }
85
86 /* EOF */