Fixes for datatype size on amd64.
[crack-attack.git] / src / Controller.cxx
blob525f4748ad753d57045dacfabfa7c82713ac7e98
1 /*
2 * Controller.cxx
3 * Daniel Nelson - 8/25/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Keeps track of the button pressing.
28 #include "Controller.h"
30 #include <GL/glut.h>
31 #include <cassert>
33 #include "glext.h"
35 #include "Game.h"
36 #include "ActionRecorder.h"
37 #include "MetaState.h"
38 #include "Grid.h"
40 #ifdef DEVELOPMENT
41 #include "Displayer.h"
42 #endif
45 int Controller::state;
47 void Controller::gameStart ( )
49 state = 0;
52 void Controller::keyboardPlay ( unsigned char key, int x, int y )
54 bool keypressed = true;
55 switch (key) {
56 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
57 state |= CC_LEFT;
58 break;
59 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
60 state |= CC_RIGHT;
61 break;
62 case GC_UP_KEY: case (GC_UP_KEY - 32):
63 state |= CC_UP;
64 break;
65 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
66 state |= CC_DOWN;
67 break;
68 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
69 state |= CC_SWAP;
70 break;
71 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
72 state |= CC_ADVANCE;
73 break;
74 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
75 state |= CC_PAUSE;
76 break;
77 #ifndef NDEBUG
78 case 'z':
79 Grid::dump();
80 break;
81 #endif
82 #ifdef DEVELOPMENT
83 case '.':
84 Displayer::screenShot();
85 break;
86 #endif
87 case 27:
88 Game::concession();
89 break;
90 default:
91 keypressed = false;
93 if(keypressed)
94 ActionRecorder::addAction(state);
97 void Controller::keyboardUpPlay ( unsigned char key, int x, int y )
99 bool keypressed = true;
100 switch (key) {
101 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
102 state &= ~CC_LEFT;
103 break;
104 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
105 state &= ~CC_RIGHT;
106 break;
107 case GC_UP_KEY: case (GC_UP_KEY - 32):
108 state &= ~CC_UP;
109 break;
110 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
111 state &= ~CC_DOWN;
112 break;
113 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
114 state &= ~CC_SWAP;
115 break;
116 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
117 state &= ~CC_ADVANCE;
118 break;
119 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
120 state &= ~CC_PAUSE;
121 break;
122 default:
123 keypressed = false;
125 if(keypressed)
126 ActionRecorder::addAction(state);
129 void Controller::specialPlay ( int key, int x, int y )
131 switch (key) {
132 case GLUT_KEY_LEFT:
133 state |= CC_LEFT;
134 break;
135 case GLUT_KEY_RIGHT:
136 state |= CC_RIGHT;
137 break;
138 case GLUT_KEY_UP:
139 state |= CC_UP;
140 break;
141 case GLUT_KEY_DOWN:
142 state |= CC_DOWN;
143 break;
147 void Controller::specialUpPlay ( int key, int x, int y )
149 switch (key) {
150 case GLUT_KEY_LEFT:
151 state &= ~CC_LEFT;
152 break;
153 case GLUT_KEY_RIGHT:
154 state &= ~CC_RIGHT;
155 break;
156 case GLUT_KEY_UP:
157 state &= ~CC_UP;
158 break;
159 case GLUT_KEY_DOWN:
160 state &= ~CC_DOWN;
161 break;
165 void Controller::keyboardMeta ( unsigned char key, int x, int y )
167 switch (key) {
168 #ifdef DEVELOPMENT
169 case '.':
170 Displayer::screenShot(); break;
171 #endif
172 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
173 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
174 case GC_UP_KEY: case (GC_UP_KEY - 32):
175 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
176 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
177 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
178 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
179 MESSAGE("game key pressed");
180 MetaState::localKeyPressed(false);
181 break;
182 default:
183 MESSAGE("game key not-pressed");
184 MetaState::localKeyPressed(true);
188 void Controller::keyboardUpMeta ( unsigned char key, int x, int y )
192 void Controller::specialMeta ( int key, int x, int y )
194 if (MetaState::mode * CM_SOLO)
195 switch (key) {
196 case GLUT_KEY_UP:
197 state |= CC_UP;
198 break;
199 case GLUT_KEY_DOWN:
200 state |= CC_DOWN;
201 break;
202 default:
203 MetaState::localKeyPressed(false);
204 break;
206 else
207 MetaState::localKeyPressed(false);
210 void Controller::specialUpMeta ( int key, int x, int y )
212 assert(MetaState::mode & CM_SOLO);
214 switch (key) {
215 case GLUT_KEY_UP:
216 state &= ~CC_UP;
217 break;
218 case GLUT_KEY_DOWN:
219 state &= ~CC_DOWN;
220 break;
224 void Controller::entry ( int mouse_state )
226 if (mouse_state == GLUT_LEFT)
227 state = 0;