g_spawn_command_line_sync used for spawning the game now.
[crack-attack.git] / src / Controller.cxx
blobb52919944a4d6e7aa28520e71cd5844605f90a5f
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 #include "glext.h"
33 #include "Game.h"
34 #include "Controller.h"
35 #include "MetaState.h"
36 #include "Grid.h"
38 #ifdef DEVELOPMENT
39 #include "Displayer.h"
40 #endif
42 using namespace std;
44 int Controller::state;
46 void Controller::gameStart ( )
48 state = 0;
51 void Controller::keyboardPlay ( unsigned char key, int x, int y )
53 switch (key) {
54 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
55 state |= CC_LEFT;
56 break;
57 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
58 state |= CC_RIGHT;
59 break;
60 case GC_UP_KEY: case (GC_UP_KEY - 32):
61 state |= CC_UP;
62 break;
63 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
64 state |= CC_DOWN;
65 break;
66 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
67 state |= CC_SWAP;
68 break;
69 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
70 state |= CC_ADVANCE;
71 break;
72 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
73 state |= CC_PAUSE;
74 break;
75 #ifndef NDEBUG
76 case 'z':
77 Grid::dump();
78 break;
79 #endif
80 #ifdef DEVELOPMENT
81 case '.':
82 Displayer::screenShot();
83 break;
84 #endif
85 case 27:
86 Game::concession();
87 break;
91 void Controller::keyboardUpPlay ( unsigned char key, int x, int y )
93 switch (key) {
94 case GC_LEFT_KEY: case (GC_LEFT_KEY - 32):
95 state &= ~CC_LEFT;
96 break;
97 case GC_RIGHT_KEY: case (GC_RIGHT_KEY - 32):
98 state &= ~CC_RIGHT;
99 break;
100 case GC_UP_KEY: case (GC_UP_KEY - 32):
101 state &= ~CC_UP;
102 break;
103 case GC_DOWN_KEY: case (GC_DOWN_KEY - 32):
104 state &= ~CC_DOWN;
105 break;
106 case GC_SWAP_KEY: case (GC_SWAP_KEY - 32): case ' ':
107 state &= ~CC_SWAP;
108 break;
109 case GC_ADVANCE_KEY: case (GC_ADVANCE_KEY - 32): case '\r':
110 state &= ~CC_ADVANCE;
111 break;
112 case GC_PAUSE_KEY: case (GC_PAUSE_KEY - 32):
113 state &= ~CC_PAUSE;
114 break;
118 void Controller::specialPlay ( int key, int x, int y )
120 switch (key) {
121 case GLUT_KEY_LEFT:
122 state |= CC_LEFT;
123 break;
124 case GLUT_KEY_RIGHT:
125 state |= CC_RIGHT;
126 break;
127 case GLUT_KEY_UP:
128 state |= CC_UP;
129 break;
130 case GLUT_KEY_DOWN:
131 state |= CC_DOWN;
132 break;
136 void Controller::specialUpPlay ( int key, int x, int y )
138 switch (key) {
139 case GLUT_KEY_LEFT:
140 state &= ~CC_LEFT;
141 break;
142 case GLUT_KEY_RIGHT:
143 state &= ~CC_RIGHT;
144 break;
145 case GLUT_KEY_UP:
146 state &= ~CC_UP;
147 break;
148 case GLUT_KEY_DOWN:
149 state &= ~CC_DOWN;
150 break;
154 void Controller::keyboardMeta ( unsigned char key, int x, int y )
156 #ifdef DEVELOPMENT
157 if (key == '.') Displayer::screenShot();
158 #endif
159 MetaState::localKeyPressed(key == 27);
162 void Controller::keyboardUpMeta ( unsigned char key, int x, int y )
166 void Controller::specialMeta ( int key, int x, int y )
168 if (MetaState::mode * CM_SOLO)
169 switch (key) {
170 case GLUT_KEY_UP:
171 state |= CC_UP;
172 break;
173 case GLUT_KEY_DOWN:
174 state |= CC_DOWN;
175 break;
176 default:
177 MetaState::localKeyPressed(false);
178 break;
180 else
181 MetaState::localKeyPressed(false);
184 void Controller::specialUpMeta ( int key, int x, int y )
186 assert(MetaState::mode & CM_SOLO);
188 switch (key) {
189 case GLUT_KEY_UP:
190 state &= ~CC_UP;
191 break;
192 case GLUT_KEY_DOWN:
193 state &= ~CC_DOWN;
194 break;
198 void Controller::entry ( int mouse_state )
200 if (mouse_state == GLUT_LEFT)
201 state = 0;