-rw-r--r-- | noncore/games/kpacman/referee.cpp | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/noncore/games/kpacman/referee.cpp b/noncore/games/kpacman/referee.cpp index 81f331b..6d8f3fb 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp | |||
@@ -1,1431 +1,1417 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #include <kaccel.h> | 8 | #include <kaccel.h> |
9 | #include <referee.h> | 9 | #include <referee.h> |
10 | #include <referee.moc> | 10 | #include <referee.moc> |
11 | #elif defined( QPE_PORT ) | 11 | #elif defined( QPE_PORT ) |
12 | #include <qaccel.h> | 12 | #include <qaccel.h> |
13 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
14 | #include "config.h" | 14 | #include "config.h" |
15 | #include "referee.h" | 15 | #include "referee.h" |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | #include <qdatetm.h> | 18 | #include <qdatetm.h> |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qevent.h> | 21 | #include <qevent.h> |
22 | #include <qcolor.h> | 22 | #include <qcolor.h> |
23 | #include <qkeycode.h> | 23 | #include <qkeycode.h> |
24 | #include <qfileinfo.h> | 24 | #include <qfileinfo.h> |
25 | 25 | ||
26 | #include "board.h" | 26 | #include "board.h" |
27 | #include "pacman.h" | 27 | #include "pacman.h" |
28 | #include "monster.h" | 28 | #include "monster.h" |
29 | #include "fruit.h" | 29 | #include "fruit.h" |
30 | #include "painter.h" | 30 | #include "painter.h" |
31 | 31 | ||
32 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) | 32 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) |
33 | : QWidget( parent, name ) | 33 | : QWidget( parent, name ) |
34 | { | 34 | { |
35 | gameState.resize(12); | 35 | gameState.resize(12); |
36 | gameTimer = 0; | 36 | gameTimer = 0; |
37 | energizerTimer = 0; | 37 | energizerTimer = 0; |
38 | 38 | ||
39 | focusedPause = FALSE; | 39 | focusedPause = FALSE; |
40 | setFocusPolicy(QWidget::StrongFocus); | 40 | setFocusPolicy(QWidget::StrongFocus); |
41 | 41 | ||
42 | initKeys(); | 42 | initKeys(); |
43 | 43 | ||
44 | scheme = Scheme; | 44 | scheme = Scheme; |
45 | mode = Mode; | 45 | mode = Mode; |
46 | confScheme(); | 46 | confScheme(); |
47 | 47 | ||
48 | board = new Board(BoardWidth*BoardHeight); | 48 | board = new Board(BoardWidth*BoardHeight); |
49 | 49 | ||
50 | pix = new Painter(board, this, scheme, mode, font); | 50 | pix = new Painter(board, this, scheme, mode, font); |
51 | setFixedSize(pix->levelPix().size()); | 51 | setFixedSize(pix->levelPix().size()); |
52 | 52 | ||
53 | pacman = new Pacman(board); | 53 | pacman = new Pacman(board); |
54 | 54 | ||
55 | fruit = new Fruit(board); | 55 | fruit = new Fruit(board); |
56 | 56 | ||
57 | monsters = new QList<Monster>; | 57 | monsters = new QList<Monster>; |
58 | monsters->setAutoDelete(TRUE); | 58 | monsters->setAutoDelete(TRUE); |
59 | 59 | ||
60 | monsterRect = new QList<QRect>; | 60 | monsterRect = new QList<QRect>; |
61 | monsterRect->setAutoDelete(TRUE); | 61 | monsterRect->setAutoDelete(TRUE); |
62 | 62 | ||
63 | energizers = new QList<Energizer>; | 63 | energizers = new QList<Energizer>; |
64 | energizers->setAutoDelete(TRUE); | 64 | energizers->setAutoDelete(TRUE); |
65 | 65 | ||
66 | energizerRect = new QList<QRect>; | 66 | energizerRect = new QList<QRect>; |
67 | energizerRect->setAutoDelete(TRUE); | 67 | energizerRect->setAutoDelete(TRUE); |
68 | 68 | ||
69 | pacmanRect.setRect(0, 0, 0, 0); | 69 | pacmanRect.setRect(0, 0, 0, 0); |
70 | fruitRect.setRect(0, 0, 0, 0); | 70 | fruitRect.setRect(0, 0, 0, 0); |
71 | 71 | ||
72 | QTime midnight( 0, 0, 0 ); | 72 | QTime midnight( 0, 0, 0 ); |
73 | srand( midnight.secsTo(QTime::currentTime()) ); | 73 | srand( midnight.secsTo(QTime::currentTime()) ); |
74 | 74 | ||
75 | lifes = 0; | 75 | lifes = 0; |
76 | points = 0; | 76 | points = 0; |
77 | 77 | ||
78 | emit setLifes(lifes); | 78 | emit setLifes(lifes); |
79 | emit setPoints(points); | 79 | emit setPoints(points); |
80 | 80 | ||
81 | intro(); | 81 | intro(); |
82 | } | 82 | } |
83 | 83 | ||
84 | void Referee::paintEvent( QPaintEvent *e) | 84 | void Referee::paintEvent( QPaintEvent *e) |
85 | { | 85 | { |
86 | if (gameState.testBit(HallOfFame)) | 86 | if (gameState.testBit(HallOfFame)) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | QRect rect = e->rect(); | 89 | QRect rect = e->rect(); |
90 | 90 | ||
91 | if (!rect.isEmpty()) { | 91 | if (!rect.isEmpty()) { |
92 | QPixmap p = pix->levelPix(); | 92 | QPixmap p = pix->levelPix(); |
93 | bitBlt(this, rect.x(), rect.y(), | 93 | bitBlt(this, rect.x(), rect.y(), |
94 | &p, rect.x(), rect.y(), rect.width(), rect.height()); | 94 | &p, rect.x(), rect.y(), rect.width(), rect.height()); |
95 | } | 95 | } |
96 | 96 | ||
97 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && | 97 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && |
98 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) | 98 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) |
99 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); | 99 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); |
100 | 100 | ||
101 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { | 101 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { |
102 | if (e && e->state() == on && | 102 | if (e && e->state() == on && |
103 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && | 103 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && |
104 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { | 104 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { |
105 | if (e->pix() != -1) | 105 | if (e->pix() != -1) |
106 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); | 106 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | if (!gameState.testBit(Init)) { | 110 | if (!gameState.testBit(Init)) { |
111 | 111 | ||
112 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) | 112 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) |
113 | if (fruit->state() != active) { | 113 | if (fruit->state() != active) { |
114 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) | 114 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) |
115 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); | 115 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); |
116 | } else { | 116 | } else { |
117 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) | 117 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) |
118 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); | 118 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); |
119 | } | 119 | } |
120 | 120 | ||
121 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 121 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
122 | if (m && m->state() == harmless && | 122 | if (m && m->state() == harmless && |
123 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 123 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
124 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 124 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
125 | if (m->body() != -1) | 125 | if (m->body() != -1) |
126 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 126 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
127 | if (m->eyes() != -1) | 127 | if (m->eyes() != -1) |
128 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 128 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
129 | } | 129 | } |
130 | 130 | ||
131 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && | 131 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && |
132 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) | 132 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) |
133 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 133 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
134 | 134 | ||
135 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 135 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
136 | if (m && m->state() != harmless && | 136 | if (m && m->state() != harmless && |
137 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 137 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
138 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 138 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
139 | if (m->body() != -1) | 139 | if (m->body() != -1) |
140 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 140 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
141 | if (m->eyes() != -1) | 141 | if (m->eyes() != -1) |
142 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 142 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | if (gameState.testBit(Scoring) && | 146 | if (gameState.testBit(Scoring) && |
147 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) | 147 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) |
148 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); | 148 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); |
149 | 149 | ||
150 | if (gameState.testBit(Init) && gameState.testBit(Dying) && | 150 | if (gameState.testBit(Init) && gameState.testBit(Dying) && |
151 | timerCount < pix->maxPixmaps(DyingPix) && | 151 | timerCount < pix->maxPixmaps(DyingPix) && |
152 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 152 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
153 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); | 153 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); |
154 | 154 | ||
155 | if (gameState.testBit(LevelDone) && | 155 | if (gameState.testBit(LevelDone) && |
156 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 156 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
157 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 157 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
158 | 158 | ||
159 | if (gameState.testBit(Player) && | 159 | if (gameState.testBit(Player) && |
160 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) | 160 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) |
161 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); | 161 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); |
162 | 162 | ||
163 | if (gameState.testBit(Ready) && | 163 | if (gameState.testBit(Ready) && |
164 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) | 164 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) |
165 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); | 165 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); |
166 | 166 | ||
167 | if (gameState.testBit(Paused) && | 167 | if (gameState.testBit(Paused) && |
168 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) | 168 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) |
169 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); | 169 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); |
170 | } | 170 | } |
171 | 171 | ||
172 | void Referee::timerEvent( QTimerEvent *e ) | 172 | void Referee::timerEvent( QTimerEvent *e ) |
173 | { | 173 | { |
174 | if (gameState.testBit(HallOfFame)) | 174 | if (gameState.testBit(HallOfFame)) |
175 | return; | 175 | return; |
176 | 176 | ||
177 | QRect lastRect; | 177 | QRect lastRect; |
178 | int lastPix; | 178 | int lastPix; |
179 | bool moved = FALSE; | 179 | bool moved = FALSE; |
180 | int eated = 0; | 180 | int eated = 0; |
181 | 181 | ||
182 | if (e->timerId() == energizerTimer) { | 182 | if (e->timerId() == energizerTimer) { |
183 | for (int e = 0; e < board->energizers(); e++) { | 183 | for (int e = 0; e < board->energizers(); e++) { |
184 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); | 184 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); |
185 | lastPix = energizers->at(e)->pix(); | 185 | lastPix = energizers->at(e)->pix(); |
186 | if (energizers->at(e)->move()) { | 186 | if (energizers->at(e)->move()) { |
187 | moved = TRUE; | 187 | moved = TRUE; |
188 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); | 188 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); |
189 | if (lastPix == energizers->at(e)->pix() && | 189 | if (lastPix == energizers->at(e)->pix() && |
190 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) | 190 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) |
191 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 191 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
192 | else | 192 | else |
193 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); | 193 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | for (int e = 0; e < board->energizers(); e++) | 197 | for (int e = 0; e < board->energizers(); e++) |
198 | if (!energizerRect->at(e)->isNull()) | 198 | if (!energizerRect->at(e)->isNull()) |
199 | repaint(*energizerRect->at(e), FALSE); | 199 | repaint(*energizerRect->at(e), FALSE); |
200 | 200 | ||
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | 203 | ||
204 | timerCount++; | 204 | timerCount++; |
205 | 205 | ||
206 | lastRect = pix->rect(pacman->position(), PacmanPix); | 206 | lastRect = pix->rect(pacman->position(), PacmanPix); |
207 | lastPix = pacman->pix(); | 207 | lastPix = pacman->pix(); |
208 | 208 | ||
209 | if (moved = pacman->move()) { // pacman really moved | 209 | if (moved = pacman->move()) { // pacman really moved |
210 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 210 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
211 | if (lastPix == pacman->pix() && | 211 | if (lastPix == pacman->pix() && |
212 | lastRect == pix->rect(pacman->position(), PacmanPix)) | 212 | lastRect == pix->rect(pacman->position(), PacmanPix)) |
213 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap | 213 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap |
214 | else // and the position isn't changed. | 214 | else // and the position isn't changed. |
215 | pacmanRect = pix->rect(pacmanRect, lastRect); | 215 | pacmanRect = pix->rect(pacmanRect, lastRect); |
216 | } else | 216 | } else |
217 | pacmanRect.setRect(0, 0, 0, 0); | 217 | pacmanRect.setRect(0, 0, 0, 0); |
218 | 218 | ||
219 | int pos = pacman->position(); | 219 | int pos = pacman->position(); |
220 | 220 | ||
221 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { | 221 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { |
222 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 222 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
223 | if (m && m->position() == pos) { | 223 | if (m && m->position() == pos) { |
224 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 224 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
225 | m->setREM(remTicks[level]); | 225 | m->setREM(remTicks[level]); |
226 | m->setDirection(X); // prevent movement before eaten() | 226 | m->setDirection(X); // prevent movement before eaten() |
227 | eated++; | 227 | eated++; |
228 | if (gameState.testBit(Introducing)) | 228 | if (gameState.testBit(Introducing)) |
229 | m->setPosition(OUT); | 229 | m->setPosition(OUT); |
230 | } | 230 | } |
231 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 231 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
232 | killed(); | 232 | killed(); |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | if (moved && !gameState.testBit(Dying)) { | 236 | if (moved && !gameState.testBit(Dying)) { |
237 | if (board->isPoint(pos)) { | 237 | if (board->isPoint(pos)) { |
238 | board->reset(pos, Point); | 238 | board->reset(pos, Point); |
239 | score(pointScore); | 239 | score(pointScore); |
240 | pix->erase(pos, PointPix); | 240 | pix->erase(pos, PointPix); |
241 | } | 241 | } |
242 | if (board->isEnergizer(pos)) { | 242 | if (board->isEnergizer(pos)) { |
243 | for (int e = 0; e < board->energizers();e++) { | 243 | for (int e = 0; e < board->energizers();e++) { |
244 | if (energizers->at(e)->position() == pos) { | 244 | if (energizers->at(e)->position() == pos) { |
245 | energizers->at(e)->setOff(); | 245 | energizers->at(e)->setOff(); |
246 | energizers->remove(e); | 246 | energizers->remove(e); |
247 | energizerRect->remove(e); | 247 | energizerRect->remove(e); |
248 | e = board->energizers(); | 248 | e = board->energizers(); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | board->reset(pos, energizer); | 251 | board->reset(pos, energizer); |
252 | score(energizerScore); | 252 | score(energizerScore); |
253 | monstersEaten = 0; | 253 | monstersEaten = 0; |
254 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 254 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
255 | if (m && m->state() != rem) { | 255 | if (m && m->state() != rem) { |
256 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], | 256 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], |
257 | harmlessWarnTicks[level]); | 257 | harmlessWarnTicks[level]); |
258 | if (gameState.testBit(Introducing)) | 258 | if (gameState.testBit(Introducing)) |
259 | m->setDirection(board->turn(m->direction())); | 259 | m->setDirection(board->turn(m->direction())); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | if (pos == fruit->position() && fruit->state() == active) { | 262 | if (pos == fruit->position() && fruit->state() == active) { |
263 | fruit->setEaten(fruitScoreDurTicks[level]); | 263 | fruit->setEaten(fruitScoreDurTicks[level]); |
264 | initFruit(FALSE); | 264 | initFruit(FALSE); |
265 | score(fruitScore[fruit->pix()]); | 265 | score(fruitScore[fruit->pix()]); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | if (!gameState.testBit(Introducing)) { | 269 | if (!gameState.testBit(Introducing)) { |
270 | if (fruit->state() != active && fruit->pix() >= 0) | 270 | if (fruit->state() != active && fruit->pix() >= 0) |
271 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 271 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
272 | else | 272 | else |
273 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 273 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
274 | 274 | ||
275 | lastPix = fruit->pix(); | 275 | lastPix = fruit->pix(); |
276 | if (fruit->move()) { | 276 | if (fruit->move()) { |
277 | if (pos == fruit->position() && fruit->state() == active) { | 277 | if (pos == fruit->position() && fruit->state() == active) { |
278 | fruit->setEaten(fruitScoreDurTicks[level]); | 278 | fruit->setEaten(fruitScoreDurTicks[level]); |
279 | initFruit(FALSE); | 279 | initFruit(FALSE); |
280 | score(fruitScore[fruit->pix()]); | 280 | score(fruitScore[fruit->pix()]); |
281 | } | 281 | } |
282 | if (fruit->state() != active && fruit->pix() >= 0) | 282 | if (fruit->state() != active && fruit->pix() >= 0) |
283 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 283 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
284 | else | 284 | else |
285 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 285 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
286 | if (lastPix == fruit->pix() && lastRect == fruitRect) | 286 | if (lastPix == fruit->pix() && lastRect == fruitRect) |
287 | fruitRect.setRect(0, 0, 0, 0); | 287 | fruitRect.setRect(0, 0, 0, 0); |
288 | else | 288 | else |
289 | fruitRect = pix->rect(fruitRect, lastRect); | 289 | fruitRect = pix->rect(fruitRect, lastRect); |
290 | } else | 290 | } else |
291 | fruitRect.setRect(0, 0, 0, 0); | 291 | fruitRect.setRect(0, 0, 0, 0); |
292 | } else | 292 | } else |
293 | fruitRect.setRect(0, 0, 0, 0); | 293 | fruitRect.setRect(0, 0, 0, 0); |
294 | 294 | ||
295 | int lastBodyPix; | 295 | int lastBodyPix; |
296 | int lastEyesPix; | 296 | int lastEyesPix; |
297 | 297 | ||
298 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 298 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
299 | if (m) { | 299 | if (m) { |
300 | lastRect = pix->rect(m->position(), MonsterPix); | 300 | lastRect = pix->rect(m->position(), MonsterPix); |
301 | lastBodyPix = m->body(); | 301 | lastBodyPix = m->body(); |
302 | lastEyesPix = m->eyes(); | 302 | lastEyesPix = m->eyes(); |
303 | if (m->move()) { | 303 | if (m->move()) { |
304 | moved = TRUE; | 304 | moved = TRUE; |
305 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); | 305 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); |
306 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && | 306 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && |
307 | lastRect == pix->rect(m->position(), MonsterPix)) | 307 | lastRect == pix->rect(m->position(), MonsterPix)) |
308 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 308 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
309 | else | 309 | else |
310 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); | 310 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); |
311 | if (m->position() == pos && !gameState.testBit(Dying)) { | 311 | if (m->position() == pos && !gameState.testBit(Dying)) { |
312 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 312 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
313 | m->setREM(remTicks[level]); | 313 | m->setREM(remTicks[level]); |
314 | eated++; | 314 | eated++; |
315 | if (gameState.testBit(Introducing)) { | 315 | if (gameState.testBit(Introducing)) { |
316 | m->setPosition(OUT); | 316 | m->setPosition(OUT); |
317 | m->setDirection(X); | 317 | m->setDirection(X); |
318 | } | 318 | } |
319 | } | 319 | } |
320 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 320 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
321 | killed(); | 321 | killed(); |
322 | } | 322 | } |
323 | } else | 323 | } else |
324 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 324 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
325 | } | 325 | } |
326 | 326 | ||
327 | for (int m = 0; m < board->monsters(); m++) | 327 | for (int m = 0; m < board->monsters(); m++) |
328 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 328 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
329 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 329 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
330 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 330 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
331 | } else | 331 | } else |
332 | for (int im = m+1; im < board->monsters(); im++) | 332 | for (int im = m+1; im < board->monsters(); im++) |
333 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 333 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
334 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 334 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
335 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 335 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
336 | } | 336 | } |
337 | 337 | ||
338 | if (!pacmanRect.isNull()) | 338 | if (!pacmanRect.isNull()) |
339 | repaint(pacmanRect, FALSE); | 339 | repaint(pacmanRect, FALSE); |
340 | 340 | ||
341 | if (!fruitRect.isNull()) | 341 | if (!fruitRect.isNull()) |
342 | repaint(fruitRect, FALSE); | 342 | repaint(fruitRect, FALSE); |
343 | 343 | ||
344 | for (int m = 0; m < board->monsters(); m++) | 344 | for (int m = 0; m < board->monsters(); m++) |
345 | if (!monsterRect->at(m)->isNull()) | 345 | if (!monsterRect->at(m)->isNull()) |
346 | repaint(*monsterRect->at(m), FALSE); | 346 | repaint(*monsterRect->at(m), FALSE); |
347 | 347 | ||
348 | if (board->points() == 0 && !gameState.testBit(Dying)) | 348 | if (board->points() == 0 && !gameState.testBit(Dying)) |
349 | levelUp(); | 349 | levelUp(); |
350 | 350 | ||
351 | if (eated > 0 && !gameState.testBit(Dying)) { | 351 | if (eated > 0 && !gameState.testBit(Dying)) { |
352 | timerCount = eated; | 352 | timerCount = eated; |
353 | eaten(); | 353 | eaten(); |
354 | } | 354 | } |
355 | 355 | ||
356 | if (gameState.testBit(Introducing) && moved) | 356 | if (gameState.testBit(Introducing) && moved) |
357 | introPlay(); | 357 | introPlay(); |
358 | } | 358 | } |
359 | 359 | ||
360 | void Referee::repaintFigures() | 360 | void Referee::repaintFigures() |
361 | { | 361 | { |
362 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 362 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
363 | 363 | ||
364 | for (int e = 0; e < board->energizers(); e++) { | 364 | for (int e = 0; e < board->energizers(); e++) { |
365 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); | 365 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); |
366 | 366 | ||
367 | if (pacmanRect.intersects(*energizerRect->at(e))) { | 367 | if (pacmanRect.intersects(*energizerRect->at(e))) { |
368 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); | 368 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); |
369 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 369 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
370 | } else | 370 | } else |
371 | for (int ie = e+1; ie < board->energizers(); ie++) | 371 | for (int ie = e+1; ie < board->energizers(); ie++) |
372 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { | 372 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { |
373 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); | 373 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); |
374 | energizerRect->at(ie)->setRect(0, 0, 0, 0); | 374 | energizerRect->at(ie)->setRect(0, 0, 0, 0); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | if (fruit->pix() != -1 && fruit->state() != active) | 378 | if (fruit->pix() != -1 && fruit->state() != active) |
379 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 379 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
380 | else | 380 | else |
381 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 381 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
382 | 382 | ||
383 | if (pacmanRect.intersects(fruitRect)) { | 383 | if (pacmanRect.intersects(fruitRect)) { |
384 | pacmanRect = pix->rect(pacmanRect, fruitRect); | 384 | pacmanRect = pix->rect(pacmanRect, fruitRect); |
385 | fruitRect.setRect(0, 0, 0, 0); | 385 | fruitRect.setRect(0, 0, 0, 0); |
386 | } | 386 | } |
387 | 387 | ||
388 | for (int m = 0; m < board->monsters(); m++) { | 388 | for (int m = 0; m < board->monsters(); m++) { |
389 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); | 389 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); |
390 | 390 | ||
391 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 391 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
392 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 392 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
393 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 393 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
394 | } else | 394 | } else |
395 | for (int im = m+1; im < board->monsters(); im++) | 395 | for (int im = m+1; im < board->monsters(); im++) |
396 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 396 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
397 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 397 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
398 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 398 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | if (!pacmanRect.isNull()) | 402 | if (!pacmanRect.isNull()) |
403 | repaint(pacmanRect, FALSE); | 403 | repaint(pacmanRect, FALSE); |
404 | 404 | ||
405 | if (!fruitRect.isNull()) | 405 | if (!fruitRect.isNull()) |
406 | repaint(fruitRect, FALSE); | 406 | repaint(fruitRect, FALSE); |
407 | 407 | ||
408 | for (int m = 0; m < board->monsters(); m++) | 408 | for (int m = 0; m < board->monsters(); m++) |
409 | if (!monsterRect->at(m)->isNull()) | 409 | if (!monsterRect->at(m)->isNull()) |
410 | repaint(*monsterRect->at(m), FALSE); | 410 | repaint(*monsterRect->at(m), FALSE); |
411 | 411 | ||
412 | for (int e = 0; e < board->energizers(); e++) | 412 | for (int e = 0; e < board->energizers(); e++) |
413 | if (!energizerRect->at(e)->isNull()) | 413 | if (!energizerRect->at(e)->isNull()) |
414 | repaint(*energizerRect->at(e), FALSE); | 414 | repaint(*energizerRect->at(e), FALSE); |
415 | 415 | ||
416 | } | 416 | } |
417 | 417 | ||
418 | void Referee::initKeys() | 418 | void Referee::initKeys() |
419 | { | 419 | { |
420 | APP_CONFIG_BEGIN( cfg ); | 420 | APP_CONFIG_BEGIN( cfg ); |
421 | QString up("Up"); | 421 | QString up("Up"); |
422 | up = cfg->readEntry("upKey", (const char*) up); | 422 | up = cfg->readEntry("upKey", (const char*) up); |
423 | UpKey = KAccel::stringToKey(up); | 423 | UpKey = KAccel::stringToKey(up); |
424 | 424 | ||
425 | QString down("Down"); | 425 | QString down("Down"); |
426 | down = cfg->readEntry("downKey", (const char*) down); | 426 | down = cfg->readEntry("downKey", (const char*) down); |
427 | DownKey = KAccel::stringToKey(down); | 427 | DownKey = KAccel::stringToKey(down); |
428 | 428 | ||
429 | QString left("Left"); | 429 | QString left("Left"); |
430 | left = cfg->readEntry("leftKey", (const char*) left); | 430 | left = cfg->readEntry("leftKey", (const char*) left); |
431 | LeftKey = KAccel::stringToKey(left); | 431 | LeftKey = KAccel::stringToKey(left); |
432 | 432 | ||
433 | QString right("Right"); | 433 | QString right("Right"); |
434 | right = cfg->readEntry("rightKey", (const char*) right); | 434 | right = cfg->readEntry("rightKey", (const char*) right); |
435 | RightKey = KAccel::stringToKey(right); | 435 | RightKey = KAccel::stringToKey(right); |
436 | APP_CONFIG_END( cfg ); | 436 | APP_CONFIG_END( cfg ); |
437 | } | 437 | } |
438 | 438 | ||
439 | void Referee::fillArray(QArray<int> &array, QString values, int max) | 439 | void Referee::fillArray(QArray<int> &array, QString values, int max) |
440 | { | 440 | { |
441 | if (max < 0) | 441 | if (max < 0) |
442 | max = values.contains(',')+1; | 442 | max = values.contains(',')+1; |
443 | 443 | ||
444 | array.resize(max); | 444 | array.resize(max); |
445 | int last = 0; | 445 | int last = 0; |
446 | bool ok; | 446 | bool ok; |
447 | QString value; | 447 | QString value; |
448 | 448 | ||
449 | for (uint i = 0; i < array.size(); i++) { | 449 | for (uint i = 0; i < array.size(); i++) { |
450 | if (values.find(',') < 0 && values.length() > 0) { | 450 | if (values.find(',') < 0 && values.length() > 0) { |
451 | value = values; | 451 | value = values; |
452 | values = ""; | 452 | values = ""; |
453 | } | 453 | } |
454 | if (values.find(',') >= 0) { | 454 | if (values.find(',') >= 0) { |
455 | value = values.left(values.find(',')); | 455 | value = values.left(values.find(',')); |
456 | values.remove(0,values.find(',')+1); | 456 | values.remove(0,values.find(',')+1); |
457 | } | 457 | } |
458 | array[i] = value.toInt(&ok); | 458 | array[i] = value.toInt(&ok); |
459 | if (ok) | 459 | if (ok) |
460 | last = array[i]; | 460 | last = array[i]; |
461 | else | 461 | else |
462 | array[i] = last; | 462 | array[i] = last; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | 465 | ||
466 | void Referee::fillStrList(QStrList &list, QString values, int max) | 466 | void Referee::fillStrList(QStrList &list, QString values, int max) |
467 | { | 467 | { |
468 | if (!list.isEmpty()) | 468 | if (!list.isEmpty()) |
469 | list.clear(); | 469 | list.clear(); |
470 | 470 | ||
471 | QString last = ""; | 471 | QString last = ""; |
472 | QString value; | 472 | QString value; |
473 | 473 | ||
474 | for (uint i = 0; i < (uint) max; i++) { | 474 | for (uint i = 0; i < (uint) max; i++) { |
475 | if (values.find(',') < 0 && values.length() > 0) { | 475 | if (values.find(',') < 0 && values.length() > 0) { |
476 | value = values; | 476 | value = values; |
477 | values = ""; | 477 | values = ""; |
478 | } | 478 | } |
479 | if (values.find(',') >= 0) { | 479 | if (values.find(',') >= 0) { |
480 | value = values.left(values.find(',')); | 480 | value = values.left(values.find(',')); |
481 | values.remove(0,values.find(',')+1); | 481 | values.remove(0,values.find(',')+1); |
482 | } | 482 | } |
483 | if (!value.isEmpty()) | 483 | if (!value.isEmpty()) |
484 | last = value; | 484 | last = value; |
485 | 485 | ||
486 | list.append(last); | 486 | list.append(last); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | 489 | ||
490 | void Referee::fillMapName() | 490 | void Referee::fillMapName() |
491 | { | 491 | { |
492 | QStrList list = mapName; | 492 | QStrList list = mapName; |
493 | 493 | ||
494 | if (!mapName.isEmpty()) | 494 | if (!mapName.isEmpty()) |
495 | mapName.clear(); | 495 | mapName.clear(); |
496 | 496 | ||
497 | QString map; | 497 | QString map; |
498 | 498 | ||
499 | QFileInfo fileInfo; | 499 | QFileInfo fileInfo; |
500 | 500 | ||
501 | for (uint i = 0; i < list.count(); i++) { | 501 | for (uint i = 0; i < list.count(); i++) { |
502 | map = list.at(i); | 502 | map = list.at(i); |
503 | 503 | ||
504 | if (map.left(1) != "/" && map.left(1) != "~") | 504 | if (map.left(1) != "/" && map.left(1) != "~") |
505 | map = FIND_APP_DATA( mapDirectory+map ); | 505 | map = FIND_APP_DATA( mapDirectory+map ); |
506 | 506 | ||
507 | fileInfo.setFile(map); | 507 | fileInfo.setFile(map); |
508 | if (!fileInfo.isReadable()) | 508 | if (!fileInfo.isReadable()) |
509 | map = ""; | 509 | map = ""; |
510 | 510 | ||
511 | mapName.append(map); | 511 | mapName.append(map); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | void Referee::confLevels(bool defGroup) | 515 | void Referee::confLevels(bool defGroup) |
516 | { | 516 | { |
517 | APP_CONFIG_BEGIN( cfg ); | 517 | APP_CONFIG_BEGIN( cfg ); |
518 | if (defGroup || cfg->hasKey("Levels")) | 518 | if (defGroup || cfg->hasKey("Levels")) |
519 | maxLevel = cfg->readNumEntry("Levels", 13); | 519 | maxLevel = cfg->readNumEntry("Levels", 13); |
520 | APP_CONFIG_END( cfg ); | 520 | APP_CONFIG_END( cfg ); |
521 | } | 521 | } |
522 | 522 | ||
523 | void Referee::confMisc(bool defGroup) | 523 | void Referee::confMisc(bool defGroup) |
524 | { | 524 | { |
525 | APP_CONFIG_BEGIN( cfg ); | 525 | APP_CONFIG_BEGIN( cfg ); |
526 | if (defGroup || cfg->hasKey("PixmapDirectory")) { | 526 | if (defGroup || cfg->hasKey("PixmapDirectory")) { |
527 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); | 527 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); |
528 | 528 | ||
529 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") | 529 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") |
530 | pixmapDirectory.insert(0, "pics/"); | 530 | pixmapDirectory.insert(0, "pics/"); |
531 | if (pixmapDirectory.right(1) != "/") | 531 | if (pixmapDirectory.right(1) != "/") |
532 | pixmapDirectory.append("/"); | 532 | pixmapDirectory.append("/"); |
533 | } | 533 | } |
534 | 534 | ||
535 | if (defGroup || cfg->hasKey("MapDirectory")) { | 535 | if (defGroup || cfg->hasKey("MapDirectory")) { |
536 | mapDirectory = cfg->readEntry("MapDirectory"); | 536 | mapDirectory = cfg->readEntry("MapDirectory"); |
537 | 537 | ||
538 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") | 538 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") |
539 | mapDirectory.insert(0, "maps/"); | 539 | mapDirectory.insert(0, "maps/"); |
540 | if (mapDirectory.right(1) != "/") | 540 | if (mapDirectory.right(1) != "/") |
541 | mapDirectory.append("/"); | 541 | mapDirectory.append("/"); |
542 | } | 542 | } |
543 | 543 | ||
544 | if (defGroup || cfg->hasKey("MapName")) | 544 | if (defGroup || cfg->hasKey("MapName")) |
545 | fillStrList(mapName, cfg->readEntry("MapName", "map"), maxLevel+1); | 545 | fillStrList(mapName, cfg->readEntry("MapName", "map"), maxLevel+1); |
546 | 546 | ||
547 | if (defGroup || cfg->hasKey("MonsterIQ")) | 547 | if (defGroup || cfg->hasKey("MonsterIQ")) |
548 | fillArray(monsterIQ, cfg->readEntry("MonsterIQ", "0,170,180,170,180,170,180"), maxLevel+1); | 548 | fillArray(monsterIQ, cfg->readEntry("MonsterIQ", "0,170,180,170,180,170,180"), maxLevel+1); |
549 | if (defGroup || cfg->hasKey("FruitIQ")) | 549 | if (defGroup || cfg->hasKey("FruitIQ")) |
550 | fillArray(fruitIQ, cfg->readEntry("FruitIQ", "0,170,180,170,180,170,180"), maxLevel+1); | 550 | fillArray(fruitIQ, cfg->readEntry("FruitIQ", "0,170,180,170,180,170,180"), maxLevel+1); |
551 | if (defGroup || cfg->hasKey("FruitIndex")) | 551 | if (defGroup || cfg->hasKey("FruitIndex")) |
552 | fillArray(fruitIndex, cfg->readEntry("FruitIndex", "0"), maxLevel+1); | 552 | fillArray(fruitIndex, cfg->readEntry("FruitIndex", "0"), maxLevel+1); |
553 | APP_CONFIG_END( cfg ); | 553 | APP_CONFIG_END( cfg ); |
554 | } | 554 | } |
555 | 555 | ||
556 | void Referee::confTiming(bool defGroup) | 556 | void Referee::confTiming(bool defGroup) |
557 | { | 557 | { |
558 | APP_CONFIG_BEGIN( cfg ); | 558 | APP_CONFIG_BEGIN( cfg ); |
559 | if (defGroup || cfg->hasKey("SpeedMS")) | 559 | if (defGroup || cfg->hasKey("SpeedMS")) |
560 | fillArray(speed, cfg->readEntry("SpeedMS", "20"), maxLevel+1); | 560 | fillArray(speed, cfg->readEntry("SpeedMS", "20"), maxLevel+1); |
561 | if (defGroup || cfg->hasKey("PacmanTicks")) | 561 | if (defGroup || cfg->hasKey("PacmanTicks")) |
562 | fillArray(pacmanTicks,cfg->readEntry("PacmanTicks", "3"), maxLevel+1); | 562 | fillArray(pacmanTicks,cfg->readEntry("PacmanTicks", "3"), maxLevel+1); |
563 | if (defGroup || cfg->hasKey("RemTicks")) | 563 | if (defGroup || cfg->hasKey("RemTicks")) |
564 | fillArray(remTicks, cfg->readEntry("RemTicks", "1"), maxLevel+1); | 564 | fillArray(remTicks, cfg->readEntry("RemTicks", "1"), maxLevel+1); |
565 | if (defGroup || cfg->hasKey("DangerousTicks")) | 565 | if (defGroup || cfg->hasKey("DangerousTicks")) |
566 | fillArray(dangerousTicks, cfg->readEntry("DangerousTicks", "3"), maxLevel+1); | 566 | fillArray(dangerousTicks, cfg->readEntry("DangerousTicks", "3"), maxLevel+1); |
567 | if (defGroup || cfg->hasKey("HarmlessTicks")) | 567 | if (defGroup || cfg->hasKey("HarmlessTicks")) |
568 | fillArray(harmlessTicks, cfg->readEntry("HarmlessTicks", "7,6,,5,,4"), maxLevel+1); | 568 | fillArray(harmlessTicks, cfg->readEntry("HarmlessTicks", "7,6,,5,,4"), maxLevel+1); |
569 | if (defGroup || cfg->hasKey("HarmlessDurationTicks")) | 569 | if (defGroup || cfg->hasKey("HarmlessDurationTicks")) |
570 | fillArray(harmlessDurTicks, cfg->readEntry("HarmlessDurationTicks", "375,,,300,,250,200,150"), maxLevel+1); | 570 | fillArray(harmlessDurTicks, cfg->readEntry("HarmlessDurationTicks", "375,,,300,,250,200,150"), maxLevel+1); |
571 | if (defGroup || cfg->hasKey("HarmlessWarningTicks")) | 571 | if (defGroup || cfg->hasKey("HarmlessWarningTicks")) |
572 | fillArray(harmlessWarnTicks, cfg->readEntry("HarmlessWarningTicks", "135"), maxLevel+1); | 572 | fillArray(harmlessWarnTicks, cfg->readEntry("HarmlessWarningTicks", "135"), maxLevel+1); |
573 | if (defGroup || cfg->hasKey("ArrestTicks")) | 573 | if (defGroup || cfg->hasKey("ArrestTicks")) |
574 | fillArray(arrestTicks, cfg->readEntry("ArrestTicks", "6"), maxLevel+1); | 574 | fillArray(arrestTicks, cfg->readEntry("ArrestTicks", "6"), maxLevel+1); |
575 | if (defGroup || cfg->hasKey("ArrestDurationTicks")) | 575 | if (defGroup || cfg->hasKey("ArrestDurationTicks")) |
576 | fillArray(arrestDurTicks, cfg->readEntry("ArrestDurationTicks", "200,,,150"), maxLevel+1); | 576 | fillArray(arrestDurTicks, cfg->readEntry("ArrestDurationTicks", "200,,,150"), maxLevel+1); |
577 | if (defGroup || cfg->hasKey("FruitTicks")) | 577 | if (defGroup || cfg->hasKey("FruitTicks")) |
578 | fillArray(fruitTicks, cfg->readEntry("FruitTicks", "7,6,,5,,4"), maxLevel+1); | 578 | fillArray(fruitTicks, cfg->readEntry("FruitTicks", "7,6,,5,,4"), maxLevel+1); |
579 | if (defGroup || cfg->hasKey("FruitAppearsTicks")) | 579 | if (defGroup || cfg->hasKey("FruitAppearsTicks")) |
580 | fillArray(fruitAppearsTicks, cfg->readEntry("FruitAppearsTicks", "1000,,1500,2000,2500,3000,3500,4000"), maxLevel+1); | 580 | fillArray(fruitAppearsTicks, cfg->readEntry("FruitAppearsTicks", "1000,,1500,2000,2500,3000,3500,4000"), maxLevel+1); |
581 | if (defGroup || cfg->hasKey("FruitDurationTicks")) | 581 | if (defGroup || cfg->hasKey("FruitDurationTicks")) |
582 | fillArray(fruitDurTicks, cfg->readEntry("FruitDurationTicks", "500,,,400,350,300,,250,200,150"), maxLevel+1); | 582 | fillArray(fruitDurTicks, cfg->readEntry("FruitDurationTicks", "500,,,400,350,300,,250,200,150"), maxLevel+1); |
583 | if (defGroup || cfg->hasKey("FruitScoreDurationTicks")) | 583 | if (defGroup || cfg->hasKey("FruitScoreDurationTicks")) |
584 | fillArray(fruitScoreDurTicks, cfg->readEntry("FruitScoreDurationTicks", "150"), maxLevel+1); | 584 | fillArray(fruitScoreDurTicks, cfg->readEntry("FruitScoreDurationTicks", "150"), maxLevel+1); |
585 | 585 | ||
586 | if (defGroup || cfg->hasKey("MonsterScoreDurationMS")) | 586 | if (defGroup || cfg->hasKey("MonsterScoreDurationMS")) |
587 | monsterScoreDurMS = cfg->readNumEntry("MonsterScoreDurationMS", 1000); | 587 | monsterScoreDurMS = cfg->readNumEntry("MonsterScoreDurationMS", 1000); |
588 | if (defGroup || cfg->hasKey("PlayerDurationMS")) | 588 | if (defGroup || cfg->hasKey("PlayerDurationMS")) |
589 | playerDurMS = cfg->readNumEntry("PlayerDurationMS", 3000); | 589 | playerDurMS = cfg->readNumEntry("PlayerDurationMS", 3000); |
590 | if (defGroup || cfg->hasKey("ReadyDurationMS")) | 590 | if (defGroup || cfg->hasKey("ReadyDurationMS")) |
591 | readyDurMS = cfg->readNumEntry("ReadyDurationMS", 2000); | 591 | readyDurMS = cfg->readNumEntry("ReadyDurationMS", 2000); |
592 | if (defGroup || cfg->hasKey("GameOverDurationMS")) | 592 | if (defGroup || cfg->hasKey("GameOverDurationMS")) |
593 | gameOverDurMS = cfg->readNumEntry("GameOverDurationMS", 3000); | 593 | gameOverDurMS = cfg->readNumEntry("GameOverDurationMS", 3000); |
594 | if (defGroup || cfg->hasKey("AfterPauseMS")) | 594 | if (defGroup || cfg->hasKey("AfterPauseMS")) |
595 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); | 595 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); |
596 | if (defGroup || cfg->hasKey("DyingPreAnimationMS")) | 596 | if (defGroup || cfg->hasKey("DyingPreAnimationMS")) |
597 | dyingPreAnimationMS = cfg->readNumEntry("DyingPreAnimationMS", 1000); | 597 | dyingPreAnimationMS = cfg->readNumEntry("DyingPreAnimationMS", 1000); |
598 | if (defGroup || cfg->hasKey("DyingAnimationMS")) | 598 | if (defGroup || cfg->hasKey("DyingAnimationMS")) |
599 | dyingAnimationMS = cfg->readNumEntry("DyingAnimationMS", 100); | 599 | dyingAnimationMS = cfg->readNumEntry("DyingAnimationMS", 100); |
600 | if (defGroup || cfg->hasKey("DyingPostAnimationMS")) | 600 | if (defGroup || cfg->hasKey("DyingPostAnimationMS")) |
601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); | 601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); |
602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) | 602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) |
603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); | 603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); |
604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) | 604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) |
605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); | 605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); |
606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) | 606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) |
607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); | 607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); |
608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) | 608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) |
609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); | 609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); |
610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) | 610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) |
611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); | 611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); |
612 | APP_CONFIG_END( cfg ); | 612 | APP_CONFIG_END( cfg ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void Referee::confScoring(bool defGroup) | 615 | void Referee::confScoring(bool defGroup) |
616 | { | 616 | { |
617 | APP_CONFIG_BEGIN( cfg ); | 617 | APP_CONFIG_BEGIN( cfg ); |
618 | if (defGroup || cfg->hasKey("PointScore")) | 618 | if (defGroup || cfg->hasKey("PointScore")) |
619 | pointScore = cfg->readNumEntry("PointScore", 10); | 619 | pointScore = cfg->readNumEntry("PointScore", 10); |
620 | if (defGroup || cfg->hasKey("EnergizerScore")) | 620 | if (defGroup || cfg->hasKey("EnergizerScore")) |
621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); | 621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); |
622 | if (defGroup || cfg->hasKey("FruitScore")) | 622 | if (defGroup || cfg->hasKey("FruitScore")) |
623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); | 623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); |
624 | if (defGroup || cfg->hasKey("MonsterScore")) | 624 | if (defGroup || cfg->hasKey("MonsterScore")) |
625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); | 625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); |
626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) | 626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) |
627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); | 627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); |
628 | APP_CONFIG_END( cfg ); | 628 | APP_CONFIG_END( cfg ); |
629 | } | 629 | } |
630 | 630 | ||
631 | void Referee::confScheme() | 631 | void Referee::confScheme() |
632 | { | 632 | { |
633 | APP_CONFIG_BEGIN( cfg ); | 633 | APP_CONFIG_BEGIN( cfg ); |
634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
635 | QString newgroup; | 635 | QString newgroup; |
636 | 636 | ||
637 | // if not set, read mode and scheme from the configfile | 637 | // if not set, read mode and scheme from the configfile |
638 | if (mode == -1 && scheme == -1) { | 638 | if (mode == -1 && scheme == -1) { |
639 | scheme = cfg->readNumEntry("Scheme", -1); | 639 | scheme = cfg->readNumEntry("Scheme", -1); |
640 | mode = cfg->readNumEntry("Mode", -1); | 640 | mode = cfg->readNumEntry("Mode", -1); |
641 | 641 | ||
642 | // if mode is not set in the defGroup-group, lookup the scheme group | 642 | // if mode is not set in the defGroup-group, lookup the scheme group |
643 | if (scheme != -1 || mode == -1) { | 643 | if (scheme != -1 || mode == -1) { |
644 | newgroup.sprintf("Scheme %d", scheme); | 644 | newgroup.sprintf("Scheme %d", scheme); |
645 | cfg->setGroup(newgroup); | 645 | cfg->setGroup(newgroup); |
646 | 646 | ||
647 | mode = cfg->readNumEntry("Mode", -1); | 647 | mode = cfg->readNumEntry("Mode", -1); |
648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
649 | } | 649 | } |
650 | } | 650 | } |
651 | 651 | ||
652 | confLevels(); | 652 | confLevels(); |
653 | 653 | ||
654 | if (mode != -1) { | 654 | if (mode != -1) { |
655 | newgroup.sprintf("Mode %d", mode); | 655 | newgroup.sprintf("Mode %d", mode); |
656 | cfg->setGroup(newgroup); | 656 | cfg->setGroup(newgroup); |
657 | 657 | ||
658 | confLevels(FALSE); | 658 | confLevels(FALSE); |
659 | } | 659 | } |
660 | 660 | ||
661 | if (scheme != -1) { | 661 | if (scheme != -1) { |
662 | newgroup.sprintf("Scheme %d", scheme); | 662 | newgroup.sprintf("Scheme %d", scheme); |
663 | cfg->setGroup(newgroup); | 663 | cfg->setGroup(newgroup); |
664 | 664 | ||
665 | confLevels(FALSE); | 665 | confLevels(FALSE); |
666 | } | 666 | } |
667 | 667 | ||
668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
669 | 669 | ||
670 | confMisc(); | 670 | confMisc(); |
671 | confTiming(); | 671 | confTiming(); |
672 | confScoring(); | 672 | confScoring(); |
673 | 673 | ||
674 | if (mode != -1) { | 674 | if (mode != -1) { |
675 | newgroup.sprintf("Mode %d", mode); | 675 | newgroup.sprintf("Mode %d", mode); |
676 | cfg->setGroup(newgroup); | 676 | cfg->setGroup(newgroup); |
677 | 677 | ||
678 | confMisc(FALSE); | 678 | confMisc(FALSE); |
679 | confTiming(FALSE); | 679 | confTiming(FALSE); |
680 | confScoring(FALSE); | 680 | confScoring(FALSE); |
681 | } | 681 | } |
682 | 682 | ||
683 | if (scheme != -1) { | 683 | if (scheme != -1) { |
684 | newgroup.sprintf("Scheme %d", scheme); | 684 | newgroup.sprintf("Scheme %d", scheme); |
685 | cfg->setGroup(newgroup); | 685 | cfg->setGroup(newgroup); |
686 | 686 | ||
687 | confMisc(FALSE); | 687 | confMisc(FALSE); |
688 | confTiming(FALSE); | 688 | confTiming(FALSE); |
689 | confScoring(FALSE); | 689 | confScoring(FALSE); |
690 | } | 690 | } |
691 | 691 | ||
692 | fillMapName(); | 692 | fillMapName(); |
693 | 693 | ||
694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
695 | APP_CONFIG_END( cfg ); | 695 | APP_CONFIG_END( cfg ); |
696 | } | 696 | } |
697 | 697 | ||
698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) | 698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) |
699 | { | 699 | { |
700 | mode = Mode; | 700 | mode = Mode; |
701 | scheme = Scheme; | 701 | scheme = Scheme; |
702 | 702 | ||
703 | confScheme(); | 703 | confScheme(); |
704 | 704 | ||
705 | pix->setScheme(scheme, mode, font); | 705 | pix->setScheme(scheme, mode, font); |
706 | 706 | ||
707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); | 707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); |
708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); | 708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); |
709 | 709 | ||
710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
711 | if (m) | 711 | if (m) |
712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
713 | 713 | ||
714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) | 714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) |
715 | if (e) | 715 | if (e) |
716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); | 716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); |
717 | 717 | ||
718 | if (gameState.testBit(Introducing)) | 718 | if (gameState.testBit(Introducing)) |
719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) | 719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) |
720 | introPaint(i); | 720 | introPaint(i); |
721 | 721 | ||
722 | setFixedSize(pix->levelPix().size()); | 722 | setFixedSize(pix->levelPix().size()); |
723 | repaint(); | 723 | repaint(); |
724 | } | 724 | } |
725 | 725 | ||
726 | void Referee::keyPressEvent( QKeyEvent *k ) | 726 | void Referee::keyPressEvent( QKeyEvent *k ) |
727 | { | 727 | { |
728 | uint key = k->key(); | 728 | uint key = k->key(); |
729 | #ifdef QWS | 729 | |
730 | // "OK" => new game | 730 | if ( !gameState.testBit(Playing) && ( key == Key_Up || key == Key_Down || key == Key_Left || key == Key_Right ) ) |
731 | if ( key == Key_F33 || key == Key_F2 || key == Key_Enter ) | ||
732 | play(); | ||
733 | else if ( !gameState.testBit(Playing) && | ||
734 | ( key == Key_Up || | ||
735 | key == Key_Down || | ||
736 | key == Key_Right || | ||
737 | key == Key_Left )) | ||
738 | play(); | 731 | play(); |
739 | // "Space" => pause | ||
740 | //else if ( key == Key_Space || key == Key_F3 ) | ||
741 | // pause(); | ||
742 | // "Menu" => hall of fame | ||
743 | //else if ( key == Key_F11 || key == Key_F4 ) | ||
744 | // toggleHallOfFame(); | ||
745 | #endif | ||
746 | 732 | ||
747 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || | 733 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || |
748 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || | 734 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || |
749 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || | 735 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || |
750 | !gameState.testBit(Playing)) | 736 | !gameState.testBit(Playing)) |
751 | return; | 737 | return; |
752 | 738 | ||
753 | if (key == UpKey) | 739 | if (key == UpKey) |
754 | pacman->setDirection(N); | 740 | pacman->setDirection(N); |
755 | else if (key == DownKey) | 741 | else if (key == DownKey) |
756 | pacman->setDirection(S); | 742 | pacman->setDirection(S); |
757 | else if (key == RightKey) | 743 | else if (key == RightKey) |
758 | pacman->setDirection(E); | 744 | pacman->setDirection(E); |
759 | else if (key == LeftKey) | 745 | else if (key == LeftKey) |
760 | pacman->setDirection(W); | 746 | pacman->setDirection(W); |
761 | 747 | ||
762 | #ifdef CHEATS | 748 | #ifdef CHEATS |
763 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } | 749 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } |
764 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } | 750 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } |
765 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } | 751 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } |
766 | #endif | 752 | #endif |
767 | 753 | ||
768 | else { | 754 | else { |
769 | k->ignore(); | 755 | k->ignore(); |
770 | return; | 756 | return; |
771 | } | 757 | } |
772 | k->accept(); | 758 | k->accept(); |
773 | } | 759 | } |
774 | 760 | ||
775 | void Referee::score(int p) | 761 | void Referee::score(int p) |
776 | { | 762 | { |
777 | if (!gameState.testBit(Playing)) | 763 | if (!gameState.testBit(Playing)) |
778 | return; | 764 | return; |
779 | 765 | ||
780 | if ((points += p) < 0) | 766 | if ((points += p) < 0) |
781 | points = 0; | 767 | points = 0; |
782 | 768 | ||
783 | emit setPoints(points); | 769 | emit setPoints(points); |
784 | 770 | ||
785 | if (points >= nextExtraLifeScore) { | 771 | if (points >= nextExtraLifeScore) { |
786 | emit setLifes(++lifes); | 772 | emit setLifes(++lifes); |
787 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) | 773 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) |
788 | extraLifeScoreIndex++; | 774 | extraLifeScoreIndex++; |
789 | if (extraLifeScore[extraLifeScoreIndex] < 0) | 775 | if (extraLifeScore[extraLifeScoreIndex] < 0) |
790 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; | 776 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; |
791 | else | 777 | else |
792 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; | 778 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; |
793 | } | 779 | } |
794 | } | 780 | } |
795 | 781 | ||
796 | void Referee::eaten() | 782 | void Referee::eaten() |
797 | { | 783 | { |
798 | if (gameState.testBit(Ready)) | 784 | if (gameState.testBit(Ready)) |
799 | return; | 785 | return; |
800 | 786 | ||
801 | stop(); | 787 | stop(); |
802 | 788 | ||
803 | if (monstersEaten < 4) | 789 | if (monstersEaten < 4) |
804 | monstersEaten++; | 790 | monstersEaten++; |
805 | 791 | ||
806 | gameState.setBit(Scoring); | 792 | gameState.setBit(Scoring); |
807 | score(monsterScore[monstersEaten-1]); | 793 | score(monsterScore[monstersEaten-1]); |
808 | 794 | ||
809 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), | 795 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), |
810 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); | 796 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); |
811 | 797 | ||
812 | if (--timerCount > 0) | 798 | if (--timerCount > 0) |
813 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); | 799 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); |
814 | else { | 800 | else { |
815 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 801 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
816 | if (m && m->direction() == X && !gameState.testBit(Introducing)) | 802 | if (m && m->direction() == X && !gameState.testBit(Introducing)) |
817 | m->setDirection(N); | 803 | m->setDirection(N); |
818 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) | 804 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) |
819 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); | 805 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); |
820 | } | 806 | } |
821 | } | 807 | } |
822 | 808 | ||
823 | void Referee::toggleHallOfFame() | 809 | void Referee::toggleHallOfFame() |
824 | { | 810 | { |
825 | gameState.toggleBit(HallOfFame); | 811 | gameState.toggleBit(HallOfFame); |
826 | } | 812 | } |
827 | 813 | ||
828 | void Referee::hallOfFame() | 814 | void Referee::hallOfFame() |
829 | { | 815 | { |
830 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the | 816 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the |
831 | toggleHallOfFame(); // bit twice. | 817 | toggleHallOfFame(); // bit twice. |
832 | 818 | ||
833 | emit setLevel(0); // Clear status display for hall of fame | 819 | emit setLevel(0); // Clear status display for hall of fame |
834 | emit setScore(level, 0); | 820 | emit setScore(level, 0); |
835 | emit forcedHallOfFame(TRUE); | 821 | emit forcedHallOfFame(TRUE); |
836 | } | 822 | } |
837 | 823 | ||
838 | void Referee::pause() | 824 | void Referee::pause() |
839 | { | 825 | { |
840 | static int pausedTimer = 0; | 826 | static int pausedTimer = 0; |
841 | 827 | ||
842 | if (!gameState.testBit(Paused)) { | 828 | if (!gameState.testBit(Paused)) { |
843 | pausedTimer = gameTimer; | 829 | pausedTimer = gameTimer; |
844 | stop(); | 830 | stop(); |
845 | stopEnergizer(); | 831 | stopEnergizer(); |
846 | gameState.setBit(Paused); | 832 | gameState.setBit(Paused); |
847 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 833 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
848 | } else { | 834 | } else { |
849 | gameState.clearBit(Paused); | 835 | gameState.clearBit(Paused); |
850 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 836 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
851 | if (pausedTimer) { | 837 | if (pausedTimer) { |
852 | pausedTimer = 0; | 838 | pausedTimer = 0; |
853 | start(); | 839 | start(); |
854 | } | 840 | } |
855 | } | 841 | } |
856 | emit togglePaused(); | 842 | emit togglePaused(); |
857 | } | 843 | } |
858 | 844 | ||
859 | void Referee::intro() | 845 | void Referee::intro() |
860 | { | 846 | { |
861 | stop(); | 847 | stop(); |
862 | stopEnergizer(); | 848 | stopEnergizer(); |
863 | bool paused = gameState.testBit(Paused); | 849 | bool paused = gameState.testBit(Paused); |
864 | 850 | ||
865 | gameState.fill(FALSE); | 851 | gameState.fill(FALSE); |
866 | gameState.setBit(Introducing); | 852 | gameState.setBit(Introducing); |
867 | gameState.setBit(Init); | 853 | gameState.setBit(Init); |
868 | 854 | ||
869 | if (paused) | 855 | if (paused) |
870 | gameState.setBit(Paused); | 856 | gameState.setBit(Paused); |
871 | 857 | ||
872 | level = 0; | 858 | level = 0; |
873 | emit setLevel(level); | 859 | emit setLevel(level); |
874 | 860 | ||
875 | board->init(Intro); | 861 | board->init(Intro); |
876 | pix->setLevel(level); | 862 | pix->setLevel(level); |
877 | 863 | ||
878 | initPacman(); | 864 | initPacman(); |
879 | initFruit(); | 865 | initFruit(); |
880 | initMonsters(); | 866 | initMonsters(); |
881 | initEnergizers(); | 867 | initEnergizers(); |
882 | 868 | ||
883 | repaint(); | 869 | repaint(); |
884 | 870 | ||
885 | monstersEaten = 0; | 871 | monstersEaten = 0; |
886 | timerCount = 0; | 872 | timerCount = 0; |
887 | introPlay(); | 873 | introPlay(); |
888 | } | 874 | } |
889 | 875 | ||
890 | void Referee::introMonster(int id) | 876 | void Referee::introMonster(int id) |
891 | { | 877 | { |
892 | Monster *m = new Monster(board, id); | 878 | Monster *m = new Monster(board, id); |
893 | 879 | ||
894 | m->setPosition((10+id*6)*BoardWidth+10); | 880 | m->setPosition((10+id*6)*BoardWidth+10); |
895 | m->setDirection(E); | 881 | m->setDirection(E); |
896 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); | 882 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); |
897 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 883 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
898 | 884 | ||
899 | if (m->body() != -1) | 885 | if (m->body() != -1) |
900 | pix->draw(m->position(), RoomPix, MonsterPix, m->body()); | 886 | pix->draw(m->position(), RoomPix, MonsterPix, m->body()); |
901 | if (m->eyes() != -1) | 887 | if (m->eyes() != -1) |
902 | pix->draw(m->position(), RoomPix, EyesPix, m->eyes()); | 888 | pix->draw(m->position(), RoomPix, EyesPix, m->eyes()); |
903 | 889 | ||
904 | repaint(pix->rect(m->position(), MonsterPix), FALSE); | 890 | repaint(pix->rect(m->position(), MonsterPix), FALSE); |
905 | m->setPosition(OUT); | 891 | m->setPosition(OUT); |
906 | } | 892 | } |
907 | 893 | ||
908 | void Referee::introPaint(int t) | 894 | void Referee::introPaint(int t) |
909 | { | 895 | { |
910 | QString pts; | 896 | QString pts; |
911 | 897 | ||
912 | switch (t) { | 898 | switch (t) { |
913 | case 0 : repaint(pix->draw(16, 6, RoomPix, tr("CHARACTER"), WHITE, QColor(), AlignLeft), FALSE); | 899 | case 0 : repaint(pix->draw(16, 6, RoomPix, tr("CHARACTER"), WHITE, QColor(), AlignLeft), FALSE); |
914 | repaint(pix->draw(36, 6, RoomPix, tr("/"), WHITE, QColor(), AlignLeft), FALSE); | 900 | repaint(pix->draw(36, 6, RoomPix, tr("/"), WHITE, QColor(), AlignLeft), FALSE); |
915 | repaint(pix->draw(40, 6, RoomPix, tr("NICKNAME"), WHITE, QColor(), AlignLeft), FALSE); | 901 | repaint(pix->draw(40, 6, RoomPix, tr("NICKNAME"), WHITE, QColor(), AlignLeft), FALSE); |
916 | break; | 902 | break; |
917 | case 1 : introMonster(0); | 903 | case 1 : introMonster(0); |
918 | break; | 904 | break; |
919 | case 2 : repaint(pix->draw(16, 10, RoomPix, tr("-SHADOW"), RED, QColor(), AlignLeft), FALSE); | 905 | case 2 : repaint(pix->draw(16, 10, RoomPix, tr("-SHADOW"), RED, QColor(), AlignLeft), FALSE); |
920 | break; | 906 | break; |
921 | case 3 : repaint(pix->draw(38, 10, RoomPix, tr("\"BLINKY\""), RED, QColor(), AlignLeft), FALSE); | 907 | case 3 : repaint(pix->draw(38, 10, RoomPix, tr("\"BLINKY\""), RED, QColor(), AlignLeft), FALSE); |
922 | break; | 908 | break; |
923 | case 4 : introMonster(1); | 909 | case 4 : introMonster(1); |
924 | break; | 910 | break; |
925 | case 5 : repaint(pix->draw(16, 16, RoomPix, tr("-SPEEDY"), PINK, QColor(), AlignLeft), FALSE); | 911 | case 5 : repaint(pix->draw(16, 16, RoomPix, tr("-SPEEDY"), PINK, QColor(), AlignLeft), FALSE); |
926 | break; | 912 | break; |
927 | case 6 : repaint(pix->draw(38, 16, RoomPix, tr("\"PINKY\""), PINK, QColor(), AlignLeft), FALSE); | 913 | case 6 : repaint(pix->draw(38, 16, RoomPix, tr("\"PINKY\""), PINK, QColor(), AlignLeft), FALSE); |
928 | break; | 914 | break; |
929 | case 7 : introMonster(2); | 915 | case 7 : introMonster(2); |
930 | break; | 916 | break; |
931 | case 8 : repaint(pix->draw(16, 22, RoomPix, tr("-BASHFUL"), CYAN, QColor(), AlignLeft), FALSE); | 917 | case 8 : repaint(pix->draw(16, 22, RoomPix, tr("-BASHFUL"), CYAN, QColor(), AlignLeft), FALSE); |
932 | break; | 918 | break; |
933 | case 9 : repaint(pix->draw(38, 22, RoomPix, tr("\"INKY\""), CYAN, QColor(), AlignLeft), FALSE); | 919 | case 9 : repaint(pix->draw(38, 22, RoomPix, tr("\"INKY\""), CYAN, QColor(), AlignLeft), FALSE); |
934 | break; | 920 | break; |
935 | case 10 : introMonster(3); | 921 | case 10 : introMonster(3); |
936 | break; | 922 | break; |
937 | case 11 : repaint(pix->draw(16, 28, RoomPix, tr("-POKEY"), ORANGE, QColor(), AlignLeft), FALSE); | 923 | case 11 : repaint(pix->draw(16, 28, RoomPix, tr("-POKEY"), ORANGE, QColor(), AlignLeft), FALSE); |
938 | break; | 924 | break; |
939 | case 12 : repaint(pix->draw(38, 28, RoomPix, tr("\"CLYDE\""), ORANGE, QColor(), AlignLeft), FALSE); | 925 | case 12 : repaint(pix->draw(38, 28, RoomPix, tr("\"CLYDE\""), ORANGE, QColor(), AlignLeft), FALSE); |
940 | break; | 926 | break; |
941 | case 13 : pts.sprintf("%d", pointScore); | 927 | case 13 : pts.sprintf("%d", pointScore); |
942 | repaint(pix->draw(28, 44, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); | 928 | repaint(pix->draw(28, 44, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); |
943 | repaint(pix->draw(31, 44, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); | 929 | repaint(pix->draw(31, 44, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); |
944 | pts.sprintf("%d", energizerScore); | 930 | pts.sprintf("%d", energizerScore); |
945 | repaint(pix->draw(28, 48, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); | 931 | repaint(pix->draw(28, 48, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); |
946 | repaint(pix->draw(31, 48, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); | 932 | repaint(pix->draw(31, 48, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); |
947 | break; | 933 | break; |
948 | case 14 : // "@ 1980 MIDWAY MFG.CO." | 934 | case 14 : // "@ 1980 MIDWAY MFG.CO." |
949 | #if defined( KDE2_PORT ) | 935 | #if defined( KDE2_PORT ) |
950 | repaint(pix->draw(30, 58, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); | 936 | repaint(pix->draw(30, 58, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); |
951 | #elif defined( QPE_PORT ) | 937 | #elif defined( QPE_PORT ) |
952 | repaint(pix->draw(30, 55, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); | 938 | repaint(pix->draw(30, 55, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); |
953 | repaint(pix->draw(29, 58, RoomPix, tr("QTOPIA PORT: CATALIN CLIMOV"), GREEN), FALSE); | 939 | repaint(pix->draw(29, 58, RoomPix, tr("QTOPIA PORT: CATALIN CLIMOV"), GREEN), FALSE); |
954 | repaint(pix->draw(29, 61, RoomPix, tr("PRESS CURSOR TO START"), GREEN), FALSE); | 940 | repaint(pix->draw(29, 61, RoomPix, tr("PRESS CURSOR TO START"), GREEN), FALSE); |
955 | #endif | 941 | #endif |
956 | break; | 942 | break; |
957 | } | 943 | } |
958 | } | 944 | } |
959 | 945 | ||
960 | void Referee::introPlay() | 946 | void Referee::introPlay() |
961 | { | 947 | { |
962 | if (!gameState.testBit(Introducing) || gameState.testBit(Ready)) | 948 | if (!gameState.testBit(Introducing) || gameState.testBit(Ready)) |
963 | return; | 949 | return; |
964 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 950 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
965 | QTimer::singleShot(afterPauseMS, this, SLOT(introPlay())); | 951 | QTimer::singleShot(afterPauseMS, this, SLOT(introPlay())); |
966 | return; | 952 | return; |
967 | } | 953 | } |
968 | 954 | ||
969 | if (!gameState.testBit(Init)) { | 955 | if (!gameState.testBit(Init)) { |
970 | if (monstersEaten == 4) { | 956 | if (monstersEaten == 4) { |
971 | stop(); | 957 | stop(); |
972 | QTimer::singleShot(introPostAnimationMS, this, SLOT(demo())); | 958 | QTimer::singleShot(introPostAnimationMS, this, SLOT(demo())); |
973 | } | 959 | } |
974 | if (pacman->direction() == W) { | 960 | if (pacman->direction() == W) { |
975 | int id = -1; | 961 | int id = -1; |
976 | if (pacman->position() == 37*BoardWidth-6) | 962 | if (pacman->position() == 37*BoardWidth-6) |
977 | id = 0; | 963 | id = 0; |
978 | else | 964 | else |
979 | if (board->isMonster(37*BoardWidth-6)) | 965 | if (board->isMonster(37*BoardWidth-6)) |
980 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 966 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
981 | if (m && m->position() == 37*BoardWidth-6) { | 967 | if (m && m->position() == 37*BoardWidth-6) { |
982 | id = m->id(); | 968 | id = m->id(); |
983 | id++; | 969 | id++; |
984 | break; | 970 | break; |
985 | } | 971 | } |
986 | 972 | ||
987 | if (id >= 0 && id <= 4) | 973 | if (id >= 0 && id <= 4) |
988 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 974 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
989 | if (m && m->id() == id && m->position() == OUT) { | 975 | if (m && m->id() == id && m->position() == OUT) { |
990 | m->setPosition(37*BoardWidth-1); | 976 | m->setPosition(37*BoardWidth-1); |
991 | m->setDirection(W); | 977 | m->setDirection(W); |
992 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); | 978 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); |
993 | board->set(37*BoardWidth-1, monsterhome, id); | 979 | board->set(37*BoardWidth-1, monsterhome, id); |
994 | repaint(pix->rect(m->position(), MonsterPix)); | 980 | repaint(pix->rect(m->position(), MonsterPix)); |
995 | break; | 981 | break; |
996 | } | 982 | } |
997 | } | 983 | } |
998 | return; | 984 | return; |
999 | } | 985 | } |
1000 | 986 | ||
1001 | if (timerCount < 15) | 987 | if (timerCount < 15) |
1002 | introPaint(timerCount); | 988 | introPaint(timerCount); |
1003 | 989 | ||
1004 | switch (timerCount) { | 990 | switch (timerCount) { |
1005 | case 13 : board->set(44*BoardWidth+22, Point); | 991 | case 13 : board->set(44*BoardWidth+22, Point); |
1006 | pix->drawPoint(44*BoardWidth+22); | 992 | pix->drawPoint(44*BoardWidth+22); |
1007 | repaint(pix->rect(44*BoardWidth+22, PointPix), FALSE); | 993 | repaint(pix->rect(44*BoardWidth+22, PointPix), FALSE); |
1008 | energizers->at(0)->setPosition(48*BoardWidth+22); | 994 | energizers->at(0)->setPosition(48*BoardWidth+22); |
1009 | energizers->at(0)->setOn(); | 995 | energizers->at(0)->setOn(); |
1010 | repaint(pix->rect(48*BoardWidth+22, EnergizerPix), FALSE); | 996 | repaint(pix->rect(48*BoardWidth+22, EnergizerPix), FALSE); |
1011 | break; | 997 | break; |
1012 | case 14 : energizers->at(1)->setPosition(36*BoardWidth+10); | 998 | case 14 : energizers->at(1)->setPosition(36*BoardWidth+10); |
1013 | energizers->at(1)->setOn(); | 999 | energizers->at(1)->setOn(); |
1014 | repaint(pix->rect(36*BoardWidth+10, EnergizerPix), FALSE); | 1000 | repaint(pix->rect(36*BoardWidth+10, EnergizerPix), FALSE); |
1015 | for (int pos = 8; pos < BoardWidth; pos++) { | 1001 | for (int pos = 8; pos < BoardWidth; pos++) { |
1016 | board->set(34*BoardWidth+pos, out); | 1002 | board->set(34*BoardWidth+pos, out); |
1017 | board->set(38*BoardWidth+pos, out); | 1003 | board->set(38*BoardWidth+pos, out); |
1018 | } | 1004 | } |
1019 | board->set(36*BoardWidth+8, out); | 1005 | board->set(36*BoardWidth+8, out); |
1020 | break; | 1006 | break; |
1021 | case 15 : gameState.clearBit(Init); | 1007 | case 15 : gameState.clearBit(Init); |
1022 | initPacman(); | 1008 | initPacman(); |
1023 | pacman->setDemo(TRUE); | 1009 | pacman->setDemo(TRUE); |
1024 | pacman->setPosition(37*BoardWidth-1); | 1010 | pacman->setPosition(37*BoardWidth-1); |
1025 | repaintFigures(); | 1011 | repaintFigures(); |
1026 | start(); | 1012 | start(); |
1027 | return; | 1013 | return; |
1028 | } | 1014 | } |
1029 | 1015 | ||
1030 | if (timerCount++ < 15) | 1016 | if (timerCount++ < 15) |
1031 | QTimer::singleShot(introAnimationMS, this, SLOT(introPlay())); | 1017 | QTimer::singleShot(introAnimationMS, this, SLOT(introPlay())); |
1032 | } | 1018 | } |
1033 | 1019 | ||
1034 | void Referee::demo() | 1020 | void Referee::demo() |
1035 | { | 1021 | { |
1036 | if (gameState.testBit(Ready)) | 1022 | if (gameState.testBit(Ready)) |
1037 | return; | 1023 | return; |
1038 | 1024 | ||
1039 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1025 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1040 | QTimer::singleShot(afterPauseMS, this, SLOT(demo())); | 1026 | QTimer::singleShot(afterPauseMS, this, SLOT(demo())); |
1041 | return; | 1027 | return; |
1042 | } | 1028 | } |
1043 | 1029 | ||
1044 | stop(); | 1030 | stop(); |
1045 | stopEnergizer(); | 1031 | stopEnergizer(); |
1046 | 1032 | ||
1047 | gameState.fill(FALSE); | 1033 | gameState.fill(FALSE); |
1048 | gameState.setBit(Init); | 1034 | gameState.setBit(Init); |
1049 | gameState.setBit(Demonstration); | 1035 | gameState.setBit(Demonstration); |
1050 | 1036 | ||
1051 | level = 0; | 1037 | level = 0; |
1052 | emit setLevel(level); | 1038 | emit setLevel(level); |
1053 | 1039 | ||
1054 | board->init(Demo, mapName.at(0)); | 1040 | board->init(Demo, mapName.at(0)); |
1055 | pix->setLevel(level); | 1041 | pix->setLevel(level); |
1056 | 1042 | ||
1057 | initPacman(); | 1043 | initPacman(); |
1058 | initFruit(); | 1044 | initFruit(); |
1059 | initMonsters(); | 1045 | initMonsters(); |
1060 | initEnergizers(); | 1046 | initEnergizers(); |
1061 | 1047 | ||
1062 | gameState.clearBit(Init); | 1048 | gameState.clearBit(Init); |
1063 | 1049 | ||
1064 | repaint(); | 1050 | repaint(); |
1065 | 1051 | ||
1066 | timerCount = 0; | 1052 | timerCount = 0; |
1067 | QTimer::singleShot(playerDurMS, this, SLOT(start())); | 1053 | QTimer::singleShot(playerDurMS, this, SLOT(start())); |
1068 | } | 1054 | } |
1069 | 1055 | ||
1070 | void Referee::play() | 1056 | void Referee::play() |
1071 | { | 1057 | { |
1072 | stop(); | 1058 | stop(); |
1073 | stopEnergizer(); | 1059 | stopEnergizer(); |
1074 | 1060 | ||
1075 | gameState.fill(FALSE); | 1061 | gameState.fill(FALSE); |
1076 | gameState.setBit(Init); | 1062 | gameState.setBit(Init); |
1077 | gameState.setBit(Playing); | 1063 | gameState.setBit(Playing); |
1078 | gameState.setBit(Player); | 1064 | gameState.setBit(Player); |
1079 | gameState.setBit(Ready); | 1065 | gameState.setBit(Ready); |
1080 | 1066 | ||
1081 | lifes = 3; | 1067 | lifes = 3; |
1082 | level = 1; | 1068 | level = 1; |
1083 | points = 0; | 1069 | points = 0; |
1084 | 1070 | ||
1085 | extraLifeScoreIndex = 0; | 1071 | extraLifeScoreIndex = 0; |
1086 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex]; | 1072 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex]; |
1087 | if (nextExtraLifeScore < 0) | 1073 | if (nextExtraLifeScore < 0) |
1088 | nextExtraLifeScore *= -1; | 1074 | nextExtraLifeScore *= -1; |
1089 | 1075 | ||
1090 | board->init(Level, mapName.at(level)); | 1076 | board->init(Level, mapName.at(level)); |
1091 | pix->setLevel(level); | 1077 | pix->setLevel(level); |
1092 | 1078 | ||
1093 | initPacman(); | 1079 | initPacman(); |
1094 | initFruit(); | 1080 | initFruit(); |
1095 | initMonsters(); | 1081 | initMonsters(); |
1096 | initEnergizers(); | 1082 | initEnergizers(); |
1097 | 1083 | ||
1098 | repaint(); | 1084 | repaint(); |
1099 | emit toggleNew(); | 1085 | emit toggleNew(); |
1100 | emit setLifes(lifes); | 1086 | emit setLifes(lifes); |
1101 | emit setLevel(level); | 1087 | emit setLevel(level); |
1102 | emit setPoints(points); | 1088 | emit setPoints(points); |
1103 | 1089 | ||
1104 | repaint(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")), FALSE); | 1090 | repaint(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")), FALSE); |
1105 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); | 1091 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); |
1106 | 1092 | ||
1107 | timerCount = 0; | 1093 | timerCount = 0; |
1108 | QTimer::singleShot(playerDurMS, this, SLOT(ready())); | 1094 | QTimer::singleShot(playerDurMS, this, SLOT(ready())); |
1109 | } | 1095 | } |
1110 | 1096 | ||
1111 | void Referee::ready() | 1097 | void Referee::ready() |
1112 | { | 1098 | { |
1113 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1099 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1114 | QTimer::singleShot(afterPauseMS, this, SLOT(ready())); | 1100 | QTimer::singleShot(afterPauseMS, this, SLOT(ready())); |
1115 | return; | 1101 | return; |
1116 | } | 1102 | } |
1117 | 1103 | ||
1118 | if (gameState.testBit(Player)) { | 1104 | if (gameState.testBit(Player)) { |
1119 | emit setLifes(--lifes); | 1105 | emit setLifes(--lifes); |
1120 | gameState.clearBit(Player); | 1106 | gameState.clearBit(Player); |
1121 | gameState.clearBit(Init); | 1107 | gameState.clearBit(Init); |
1122 | repaint(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")), FALSE); | 1108 | repaint(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")), FALSE); |
1123 | repaintFigures(); | 1109 | repaintFigures(); |
1124 | QTimer::singleShot(playerDurMS, this, SLOT(ready())); | 1110 | QTimer::singleShot(playerDurMS, this, SLOT(ready())); |
1125 | return; | 1111 | return; |
1126 | } | 1112 | } |
1127 | 1113 | ||
1128 | if (gameState.testBit(Ready)) { | 1114 | if (gameState.testBit(Ready)) { |
1129 | gameState.clearBit(Ready); | 1115 | gameState.clearBit(Ready); |
1130 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); | 1116 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); |
1131 | start(); | 1117 | start(); |
1132 | } else { | 1118 | } else { |
1133 | gameState.setBit(Ready); | 1119 | gameState.setBit(Ready); |
1134 | gameState.clearBit(Init); | 1120 | gameState.clearBit(Init); |
1135 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); | 1121 | repaint(pix->rect(board->position(fruithome), tr("READY!")), FALSE); |
1136 | QTimer::singleShot(readyDurMS, this, SLOT(ready())); | 1122 | QTimer::singleShot(readyDurMS, this, SLOT(ready())); |
1137 | } | 1123 | } |
1138 | } | 1124 | } |
1139 | 1125 | ||
1140 | 1126 | ||
1141 | void Referee::levelUp() | 1127 | void Referee::levelUp() |
1142 | { | 1128 | { |
1143 | stop(); | 1129 | stop(); |
1144 | stopEnergizer(); | 1130 | stopEnergizer(); |
1145 | 1131 | ||
1146 | gameState.setBit(LevelDone); | 1132 | gameState.setBit(LevelDone); |
1147 | pacman->setPosition(pacman->position()); // set mouthPosition to "0" | 1133 | pacman->setPosition(pacman->position()); // set mouthPosition to "0" |
1148 | repaint(pix->rect(pacman->position(), PacmanPix)); | 1134 | repaint(pix->rect(pacman->position(), PacmanPix)); |
1149 | 1135 | ||
1150 | timerCount = 0; | 1136 | timerCount = 0; |
1151 | QTimer::singleShot(levelUpPreAnimationMS, this, SLOT(levelUpPlay())); | 1137 | QTimer::singleShot(levelUpPreAnimationMS, this, SLOT(levelUpPlay())); |
1152 | } | 1138 | } |
1153 | 1139 | ||
1154 | void Referee::levelUpPlay() | 1140 | void Referee::levelUpPlay() |
1155 | { | 1141 | { |
1156 | if (gameState.testBit(Ready)) | 1142 | if (gameState.testBit(Ready)) |
1157 | return; | 1143 | return; |
1158 | 1144 | ||
1159 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1145 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1160 | QTimer::singleShot(afterPauseMS, this, SLOT(levelUpPlay())); | 1146 | QTimer::singleShot(afterPauseMS, this, SLOT(levelUpPlay())); |
1161 | return; | 1147 | return; |
1162 | } | 1148 | } |
1163 | 1149 | ||
1164 | switch (timerCount) { | 1150 | switch (timerCount) { |
1165 | case 0 : gameState.setBit(Init); | 1151 | case 0 : gameState.setBit(Init); |
1166 | setOnEnergizers(); | 1152 | setOnEnergizers(); |
1167 | repaintFigures(); | 1153 | repaintFigures(); |
1168 | break; | 1154 | break; |
1169 | case 1 : gameState.clearBit(LevelDone); | 1155 | case 1 : gameState.clearBit(LevelDone); |
1170 | repaint(pix->rect(pacman->position(), PacmanPix)); | 1156 | repaint(pix->rect(pacman->position(), PacmanPix)); |
1171 | break; | 1157 | break; |
1172 | } | 1158 | } |
1173 | 1159 | ||
1174 | if (timerCount++ < 2) { | 1160 | if (timerCount++ < 2) { |
1175 | QTimer::singleShot(levelUpAnimationMS, this, SLOT(levelUpPlay())); | 1161 | QTimer::singleShot(levelUpAnimationMS, this, SLOT(levelUpPlay())); |
1176 | return; | 1162 | return; |
1177 | } | 1163 | } |
1178 | 1164 | ||
1179 | gameState.clearBit(Init); | 1165 | gameState.clearBit(Init); |
1180 | 1166 | ||
1181 | if (gameState.testBit(Demonstration)) { | 1167 | if (gameState.testBit(Demonstration)) { |
1182 | hallOfFame(); | 1168 | hallOfFame(); |
1183 | return; | 1169 | return; |
1184 | } | 1170 | } |
1185 | 1171 | ||
1186 | if (level < maxLevel) | 1172 | if (level < maxLevel) |
1187 | level++; | 1173 | level++; |
1188 | 1174 | ||
1189 | board->init(Level, mapName.at(level)); | 1175 | board->init(Level, mapName.at(level)); |
1190 | pix->setLevel(level); | 1176 | pix->setLevel(level); |
1191 | 1177 | ||
1192 | initPacman(); | 1178 | initPacman(); |
1193 | initFruit(); | 1179 | initFruit(); |
1194 | initMonsters(); | 1180 | initMonsters(); |
1195 | initEnergizers(); | 1181 | initEnergizers(); |
1196 | 1182 | ||
1197 | repaint(); | 1183 | repaint(); |
1198 | emit setLevel(level); | 1184 | emit setLevel(level); |
1199 | 1185 | ||
1200 | ready(); | 1186 | ready(); |
1201 | } | 1187 | } |
1202 | 1188 | ||
1203 | void Referee::start() | 1189 | void Referee::start() |
1204 | { | 1190 | { |
1205 | if (gameState.testBit(Ready)) | 1191 | if (gameState.testBit(Ready)) |
1206 | return; | 1192 | return; |
1207 | 1193 | ||
1208 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1194 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1209 | QTimer::singleShot(afterPauseMS, this, SLOT(start())); | 1195 | QTimer::singleShot(afterPauseMS, this, SLOT(start())); |
1210 | return; | 1196 | return; |
1211 | } | 1197 | } |
1212 | 1198 | ||
1213 | if (gameState.testBit(Scoring)) { | 1199 | if (gameState.testBit(Scoring)) { |
1214 | gameState.clearBit(Scoring); | 1200 | gameState.clearBit(Scoring); |
1215 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), | 1201 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), |
1216 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); | 1202 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); |
1217 | } | 1203 | } |
1218 | 1204 | ||
1219 | if (!gameTimer) | 1205 | if (!gameTimer) |
1220 | gameTimer = startTimer( speed [level] ); | 1206 | gameTimer = startTimer( speed [level] ); |
1221 | 1207 | ||
1222 | if (!energizerTimer) | 1208 | if (!energizerTimer) |
1223 | energizerTimer = startTimer( energizerAnimationMS ); | 1209 | energizerTimer = startTimer( energizerAnimationMS ); |
1224 | } | 1210 | } |
1225 | 1211 | ||
1226 | void Referee::start(int t) | 1212 | void Referee::start(int t) |
1227 | { | 1213 | { |
1228 | gameTimer = startTimer(t); | 1214 | gameTimer = startTimer(t); |
1229 | } | 1215 | } |
1230 | 1216 | ||
1231 | void Referee::stop() | 1217 | void Referee::stop() |
1232 | { | 1218 | { |
1233 | if (gameTimer) { | 1219 | if (gameTimer) { |
1234 | killTimer (gameTimer); | 1220 | killTimer (gameTimer); |
1235 | gameTimer = 0; | 1221 | gameTimer = 0; |
1236 | } | 1222 | } |
1237 | } | 1223 | } |
1238 | 1224 | ||
1239 | void Referee::stopEnergizer() | 1225 | void Referee::stopEnergizer() |
1240 | { | 1226 | { |
1241 | if (energizerTimer) { | 1227 | if (energizerTimer) { |
1242 | killTimer (energizerTimer); | 1228 | killTimer (energizerTimer); |
1243 | energizerTimer = 0; | 1229 | energizerTimer = 0; |
1244 | } | 1230 | } |
1245 | } | 1231 | } |
1246 | 1232 | ||
1247 | void Referee::killed() | 1233 | void Referee::killed() |
1248 | { | 1234 | { |
1249 | if (gameState.testBit(Ready)) | 1235 | if (gameState.testBit(Ready)) |
1250 | return; | 1236 | return; |
1251 | 1237 | ||
1252 | if (!gameState.testBit(Dying)) { | 1238 | if (!gameState.testBit(Dying)) { |
1253 | gameState.setBit(Dying); | 1239 | gameState.setBit(Dying); |
1254 | 1240 | ||
1255 | pacman->setDirection(X, TRUE); | 1241 | pacman->setDirection(X, TRUE); |
1256 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 1242 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
1257 | if (m) | 1243 | if (m) |
1258 | m->setDirection(X); | 1244 | m->setDirection(X); |
1259 | QTimer::singleShot(dyingPreAnimationMS, this, SLOT(killed())); | 1245 | QTimer::singleShot(dyingPreAnimationMS, this, SLOT(killed())); |
1260 | } else { | 1246 | } else { |
1261 | stop(); | 1247 | stop(); |
1262 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1248 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1263 | QTimer::singleShot(afterPauseMS, this, SLOT(killed())); | 1249 | QTimer::singleShot(afterPauseMS, this, SLOT(killed())); |
1264 | return; | 1250 | return; |
1265 | } | 1251 | } |
1266 | 1252 | ||
1267 | gameState.setBit(Init); | 1253 | gameState.setBit(Init); |
1268 | 1254 | ||
1269 | repaintFigures(); | 1255 | repaintFigures(); |
1270 | 1256 | ||
1271 | timerCount = 0; | 1257 | timerCount = 0; |
1272 | killedPlay(); | 1258 | killedPlay(); |
1273 | } | 1259 | } |
1274 | } | 1260 | } |
1275 | 1261 | ||
1276 | void Referee::killedPlay() | 1262 | void Referee::killedPlay() |
1277 | { | 1263 | { |
1278 | if (!gameState.testBit(Dying) || gameState.testBit(Ready)) | 1264 | if (!gameState.testBit(Dying) || gameState.testBit(Ready)) |
1279 | return; | 1265 | return; |
1280 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 1266 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
1281 | QTimer::singleShot(afterPauseMS, this, SLOT(killedPlay())); | 1267 | QTimer::singleShot(afterPauseMS, this, SLOT(killedPlay())); |
1282 | return; | 1268 | return; |
1283 | } | 1269 | } |
1284 | 1270 | ||
1285 | if (timerCount <= pix->maxPixmaps(DyingPix)) { | 1271 | if (timerCount <= pix->maxPixmaps(DyingPix)) { |
1286 | repaint(pix->rect(pacman->position(), PacmanPix), FALSE); | 1272 | repaint(pix->rect(pacman->position(), PacmanPix), FALSE); |
1287 | if (timerCount >= pix->maxPixmaps(DyingPix)-1 || timerCount == 0) | 1273 | if (timerCount >= pix->maxPixmaps(DyingPix)-1 || timerCount == 0) |
1288 | QTimer::singleShot(dyingPostAnimationMS, this, SLOT(killedPlay())); | 1274 | QTimer::singleShot(dyingPostAnimationMS, this, SLOT(killedPlay())); |
1289 | else | 1275 | else |
1290 | QTimer::singleShot(dyingAnimationMS, this, SLOT(killedPlay())); | 1276 | QTimer::singleShot(dyingAnimationMS, this, SLOT(killedPlay())); |
1291 | timerCount++; | 1277 | timerCount++; |
1292 | } else { | 1278 | } else { |
1293 | gameState.clearBit(Dying); | 1279 | gameState.clearBit(Dying); |
1294 | stopEnergizer(); | 1280 | stopEnergizer(); |
1295 | if (lifes == 0) { | 1281 | if (lifes == 0) { |
1296 | gameState.setBit(GameOver); | 1282 | gameState.setBit(GameOver); |
1297 | gameState.clearBit(Playing); | 1283 | gameState.clearBit(Playing); |
1298 | for (int e = 0; e < board->energizers(); e++) { | 1284 | for (int e = 0; e < board->energizers(); e++) { |
1299 | energizers->at(e)->setOff(); | 1285 | energizers->at(e)->setOff(); |
1300 | repaint(pix->rect(board->position(energizer, e), EnergizerPix), FALSE); | 1286 | repaint(pix->rect(board->position(energizer, e), EnergizerPix), FALSE); |
1301 | } | 1287 | } |
1302 | repaint(pix->rect(board->position(fruithome), tr("GAME OVER")), FALSE); | 1288 | repaint(pix->rect(board->position(fruithome), tr("GAME OVER")), FALSE); |
1303 | QTimer::singleShot(gameOverDurMS, this, SLOT(hallOfFame())); | 1289 | QTimer::singleShot(gameOverDurMS, this, SLOT(hallOfFame())); |
1304 | } else { | 1290 | } else { |
1305 | gameState.clearBit(Init); | 1291 | gameState.clearBit(Init); |
1306 | initPacman(); | 1292 | initPacman(); |
1307 | initFruit(); | 1293 | initFruit(); |
1308 | initMonsters(); | 1294 | initMonsters(); |
1309 | initEnergizers(); | 1295 | initEnergizers(); |
1310 | emit setLifes(--lifes); | 1296 | emit setLifes(--lifes); |
1311 | repaintFigures(); | 1297 | repaintFigures(); |
1312 | ready(); | 1298 | ready(); |
1313 | } | 1299 | } |
1314 | } | 1300 | } |
1315 | } | 1301 | } |
1316 | 1302 | ||
1317 | void Referee::initPacman() | 1303 | void Referee::initPacman() |
1318 | { | 1304 | { |
1319 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); | 1305 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); |
1320 | pacman->setDemo(gameState.testBit(Demonstration)); | 1306 | pacman->setDemo(gameState.testBit(Demonstration)); |
1321 | pacman->setPosition(board->position(pacmanhome)); | 1307 | pacman->setPosition(board->position(pacmanhome)); |
1322 | pacman->setDirection(W, TRUE); | 1308 | pacman->setDirection(W, TRUE); |
1323 | pacman->setAlive(pacmanTicks[level]); | 1309 | pacman->setAlive(pacmanTicks[level]); |
1324 | } | 1310 | } |
1325 | 1311 | ||
1326 | void Referee::initFruit(bool fullInitialization) | 1312 | void Referee::initFruit(bool fullInitialization) |
1327 | { | 1313 | { |
1328 | if (fullInitialization) { | 1314 | if (fullInitialization) { |
1329 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); | 1315 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); |
1330 | if (fruitIndex[level] == 0) | 1316 | if (fruitIndex[level] == 0) |
1331 | fruit->setLevel(level, fruitAppearsTicks[level], | 1317 | fruit->setLevel(level, fruitAppearsTicks[level], |
1332 | fruitDurTicks[level], fruitTicks[level]); | 1318 | fruitDurTicks[level], fruitTicks[level]); |
1333 | else if (fruitIndex[level] < 0) | 1319 | else if (fruitIndex[level] < 0) |
1334 | fruit->setLevel(pix->maxPixmaps(FruitPix)+1, | 1320 | fruit->setLevel(pix->maxPixmaps(FruitPix)+1, |
1335 | fruitAppearsTicks[level], | 1321 | fruitAppearsTicks[level], |
1336 | fruitDurTicks[level], fruitTicks[level]); | 1322 | fruitDurTicks[level], fruitTicks[level]); |
1337 | else | 1323 | else |
1338 | fruit->setLevel(fruitIndex[level], fruitAppearsTicks[level], | 1324 | fruit->setLevel(fruitIndex[level], fruitAppearsTicks[level], |
1339 | fruitDurTicks[level], fruitTicks[level]); | 1325 | fruitDurTicks[level], fruitTicks[level]); |
1340 | } | 1326 | } |
1341 | 1327 | ||
1342 | if (board->tunnels() > 0) | 1328 | if (board->tunnels() > 0) |
1343 | fruit->setMovement(board->position(tunnel, rand() % board->tunnels()), | 1329 | fruit->setMovement(board->position(tunnel, rand() % board->tunnels()), |
1344 | board->position(tunnel, rand() % board->tunnels()), | 1330 | board->position(tunnel, rand() % board->tunnels()), |
1345 | fruitIQ[level]); | 1331 | fruitIQ[level]); |
1346 | } | 1332 | } |
1347 | 1333 | ||
1348 | void Referee::initMonsters() | 1334 | void Referee::initMonsters() |
1349 | { | 1335 | { |
1350 | if( !monsters->isEmpty()) | 1336 | if( !monsters->isEmpty()) |
1351 | monsters->clear(); | 1337 | monsters->clear(); |
1352 | if( !monsterRect->isEmpty()) | 1338 | if( !monsterRect->isEmpty()) |
1353 | monsterRect->clear(); | 1339 | monsterRect->clear(); |
1354 | 1340 | ||
1355 | for (int id = 0; id < (gameState.testBit(Introducing) ? 4 : board->monsters()); id++) { | 1341 | for (int id = 0; id < (gameState.testBit(Introducing) ? 4 : board->monsters()); id++) { |
1356 | Monster *m = new Monster(board, id); | 1342 | Monster *m = new Monster(board, id); |
1357 | monsters->append(m); | 1343 | monsters->append(m); |
1358 | QRect *r = new QRect(); | 1344 | QRect *r = new QRect(); |
1359 | monsterRect->append(r); | 1345 | monsterRect->append(r); |
1360 | if (!gameState.testBit(Introducing)) { | 1346 | if (!gameState.testBit(Introducing)) { |
1361 | m->setFreedom(board->position(prisonexit)); | 1347 | m->setFreedom(board->position(prisonexit)); |
1362 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); | 1348 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); |
1363 | if (id == 0) | 1349 | if (id == 0) |
1364 | m->setPrison(board->position(prisonentry)); | 1350 | m->setPrison(board->position(prisonentry)); |
1365 | else { | 1351 | else { |
1366 | m->setPrison(board->position(monsterhome, id)); | 1352 | m->setPrison(board->position(monsterhome, id)); |
1367 | m->setArrested(arrestTicks[level], arrestDurTicks[level]*id); | 1353 | m->setArrested(arrestTicks[level], arrestDurTicks[level]*id); |
1368 | } | 1354 | } |
1369 | m->setPosition(board->position(monsterhome, id)); | 1355 | m->setPosition(board->position(monsterhome, id)); |
1370 | switch(id) { | 1356 | switch(id) { |
1371 | case 0 : m->setDirection(W); break; | 1357 | case 0 : m->setDirection(W); break; |
1372 | case 1 : m->setDirection(N); break; | 1358 | case 1 : m->setDirection(N); break; |
1373 | default : m->setDirection(S); | 1359 | default : m->setDirection(S); |
1374 | } | 1360 | } |
1375 | } | 1361 | } |
1376 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 1362 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
1377 | } | 1363 | } |
1378 | } | 1364 | } |
1379 | 1365 | ||
1380 | void Referee::initEnergizers() | 1366 | void Referee::initEnergizers() |
1381 | { | 1367 | { |
1382 | if( !energizers->isEmpty()) | 1368 | if( !energizers->isEmpty()) |
1383 | energizers->clear(); | 1369 | energizers->clear(); |
1384 | if( !energizerRect->isEmpty()) | 1370 | if( !energizerRect->isEmpty()) |
1385 | energizerRect->clear(); | 1371 | energizerRect->clear(); |
1386 | 1372 | ||
1387 | for (int id = 0; id < (gameState.testBit(Introducing) ? 2 : board->energizers()); id++) { | 1373 | for (int id = 0; id < (gameState.testBit(Introducing) ? 2 : board->energizers()); id++) { |
1388 | Energizer *e = new Energizer(board); | 1374 | Energizer *e = new Energizer(board); |
1389 | energizers->append(e); | 1375 | energizers->append(e); |
1390 | QRect *r = new QRect(); | 1376 | QRect *r = new QRect(); |
1391 | energizerRect->append(r); | 1377 | energizerRect->append(r); |
1392 | if (!gameState.testBit(Introducing)) { | 1378 | if (!gameState.testBit(Introducing)) { |
1393 | e->setPosition(board->position(energizer, id)); | 1379 | e->setPosition(board->position(energizer, id)); |
1394 | e->setOn(); | 1380 | e->setOn(); |
1395 | } | 1381 | } |
1396 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); | 1382 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); |
1397 | } | 1383 | } |
1398 | } | 1384 | } |
1399 | 1385 | ||
1400 | void Referee::setOnEnergizers() | 1386 | void Referee::setOnEnergizers() |
1401 | { | 1387 | { |
1402 | for (int e = 0; e < board->energizers(); e++) { | 1388 | for (int e = 0; e < board->energizers(); e++) { |
1403 | energizers->at(e)->setOn(); | 1389 | energizers->at(e)->setOn(); |
1404 | } | 1390 | } |
1405 | } | 1391 | } |
1406 | 1392 | ||
1407 | void Referee::setFocusOutPause(bool FocusOutPause) | 1393 | void Referee::setFocusOutPause(bool FocusOutPause) |
1408 | { | 1394 | { |
1409 | focusOutPause = FocusOutPause; | 1395 | focusOutPause = FocusOutPause; |
1410 | } | 1396 | } |
1411 | 1397 | ||
1412 | void Referee::setFocusInContinue(bool FocusInContinue) | 1398 | void Referee::setFocusInContinue(bool FocusInContinue) |
1413 | { | 1399 | { |
1414 | focusInContinue = FocusInContinue; | 1400 | focusInContinue = FocusInContinue; |
1415 | } | 1401 | } |
1416 | 1402 | ||
1417 | void Referee::focusInEvent(QFocusEvent *) | 1403 | void Referee::focusInEvent(QFocusEvent *) |
1418 | { | 1404 | { |
1419 | if (focusInContinue && focusedPause && | 1405 | if (focusInContinue && focusedPause && |
1420 | gameState.testBit(Paused) && gameState.testBit(Playing)) { | 1406 | gameState.testBit(Paused) && gameState.testBit(Playing)) { |
1421 | pause(); | 1407 | pause(); |
1422 | } | 1408 | } |
1423 | } | 1409 | } |
1424 | 1410 | ||
1425 | void Referee::focusOutEvent(QFocusEvent *) | 1411 | void Referee::focusOutEvent(QFocusEvent *) |
1426 | { | 1412 | { |
1427 | if (focusOutPause && !gameState.testBit(Paused) && gameState.testBit(Playing)) { | 1413 | if (focusOutPause && !gameState.testBit(Paused) && gameState.testBit(Playing)) { |
1428 | focusedPause = TRUE; | 1414 | focusedPause = TRUE; |
1429 | pause(); | 1415 | pause(); |
1430 | } | 1416 | } |
1431 | } | 1417 | } |