Adding another round of custom snow tiles, thanks to dexnim
[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   "start",
27   "escape",
28   "menu-select",
29   "menu-back",
30   "cheat-menu",
31   "console",
32   "peek-left",
33   "peek-right",
34   "peek-up",
35   "peek-down",
36   0
37 };
38
39 Controller::Controller()
40 {
41   reset();
42 }
43
44 Controller::~Controller()
45 {}
46
47 void
48 Controller::reset()
49 {
50   for(int i = 0; i < CONTROLCOUNT; ++i) {
51     controls[i] = false;
52     oldControls[i] = false;
53   }
54 }
55
56 void
57 Controller::set_control(Control control, bool value)
58 {
59   controls[control] = value;
60 }
61
62 bool
63 Controller::hold(Control control) const
64 {
65   return controls[control];
66 }
67
68 bool
69 Controller::pressed(Control control) const
70 {
71   return !oldControls[control] && controls[control];
72 }
73
74 bool
75 Controller::released(Control control) const
76 {
77   return oldControls[control] && !controls[control];
78 }
79
80 void
81 Controller::update()
82 {
83   for(int i = 0; i < CONTROLCOUNT; ++i)
84     oldControls[i] = controls[i];
85 }
86
87 /* EOF */