Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[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   "console",
29   "peek-left",
30   "peek-right",
31   "peek-up",
32   "peek-down",
33   0
34 };
35
36 Controller::Controller()
37 {
38   reset();
39 }
40
41 Controller::~Controller()
42 {}
43
44 void
45 Controller::reset()
46 {
47   for(int i = 0; i < CONTROLCOUNT; ++i) {
48     controls[i] = false;
49     oldControls[i] = false;
50   }
51 }
52
53 bool
54 Controller::hold(Control control)
55 {
56   return controls[control];
57 }
58
59 bool
60 Controller::pressed(Control control)
61 {
62   return !oldControls[control] && controls[control];
63 }
64
65 bool
66 Controller::released(Control control)
67 {
68   return oldControls[control] && !controls[control];
69 }
70
71 void
72 Controller::update()
73 {
74   for(int i = 0; i < CONTROLCOUNT; ++i)
75     oldControls[i] = controls[i];
76 }
77
78 /* EOF */