Make autopackage work
[crack-attack.git] / src / Controller.cxx
blob8da804f9736e82ea1debef1af1f2126d4b60063b
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 <GL/glut.h>
29 #include <cassert>
31 #ifndef _WIN32
32 #else
33 # include <glext.h>
34 #endif
36 #include "Game.h"
37 #include "Controller.h"
38 #include "MetaState.h"
39 #include "Grid.h"
41 #ifdef DEVELOPMENT
42 #include "Displayer.h"
43 #endif
45 using namespace std;
47 int Controller::state;
49 void Controller::gameStart ( )
51 state = 0;
54 void Controller::keyboardPlay ( unsigned char key, int x, int y )
56 switch (key) {
57 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
58 state |= CC_LEFT;
59 break;
60 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
61 state |= CC_RIGHT;
62 break;
63 case GC_UP_KEY: case (GC_UP_KEY - 32):
64 state |= CC_UP;
65 break;
66 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
67 state |= CC_DOWN;
68 break;
69 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
70 state |= CC_SWAP;
71 break;
72 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
73 state |= CC_ADVANCE;
74 break;
75 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
76 state |= CC_PAUSE;
77 break;
78 #ifndef NDEBUG
79 case 'z':
80 Grid::dump();
81 break;
82 #endif
83 #ifdef DEVELOPMENT
84 case '.':
85 Displayer::screenShot();
86 break;
87 #endif
88 case 27:
89 Game::concession();
90 break;
94 void Controller::keyboardUpPlay ( unsigned char key, int x, int y )
96 switch (key) {
97 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
98 state &= ~CC_LEFT;
99 break;
100 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
101 state &= ~CC_RIGHT;
102 break;
103 case GC_UP_KEY: case (GC_UP_KEY - 32):
104 state &= ~CC_UP;
105 break;
106 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
107 state &= ~CC_DOWN;
108 break;
109 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
110 state &= ~CC_SWAP;
111 break;
112 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
113 state &= ~CC_ADVANCE;
114 break;
115 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
116 state &= ~CC_PAUSE;
117 break;
121 void Controller::specialPlay ( int key, int x, int y )
123 switch (key) {
124 case GLUT_KEY_LEFT:
125 state |= CC_LEFT;
126 break;
127 case GLUT_KEY_RIGHT:
128 state |= CC_RIGHT;
129 break;
130 case GLUT_KEY_UP:
131 state |= CC_UP;
132 break;
133 case GLUT_KEY_DOWN:
134 state |= CC_DOWN;
135 break;
139 void Controller::specialUpPlay ( int key, int x, int y )
141 switch (key) {
142 case GLUT_KEY_LEFT:
143 state &= ~CC_LEFT;
144 break;
145 case GLUT_KEY_RIGHT:
146 state &= ~CC_RIGHT;
147 break;
148 case GLUT_KEY_UP:
149 state &= ~CC_UP;
150 break;
151 case GLUT_KEY_DOWN:
152 state &= ~CC_DOWN;
153 break;
157 void Controller::keyboardMeta ( unsigned char key, int x, int y )
159 #ifdef DEVELOPMENT
160 if (key == '.') Displayer::screenShot();
161 #endif
162 MetaState::localKeyPressed(key == 27);
165 void Controller::keyboardUpMeta ( unsigned char key, int x, int y )
169 void Controller::specialMeta ( int key, int x, int y )
171 if (MetaState::mode * CM_SOLO)
172 switch (key) {
173 case GLUT_KEY_UP:
174 state |= CC_UP;
175 break;
176 case GLUT_KEY_DOWN:
177 state |= CC_DOWN;
178 break;
179 default:
180 MetaState::localKeyPressed(false);
181 break;
183 else
184 MetaState::localKeyPressed(false);
187 void Controller::specialUpMeta ( int key, int x, int y )
189 assert(MetaState::mode & CM_SOLO);
191 switch (key) {
192 case GLUT_KEY_UP:
193 state &= ~CC_UP;
194 break;
195 case GLUT_KEY_DOWN:
196 state &= ~CC_DOWN;
197 break;
201 void Controller::entry ( int mouse_state )
203 if (mouse_state == GLUT_LEFT)
204 state = 0;