-rw-r--r-- | noncore/games/qasteroids/toplevel.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/noncore/games/qasteroids/toplevel.cpp b/noncore/games/qasteroids/toplevel.cpp index 57242a0..090099f 100644 --- a/noncore/games/qasteroids/toplevel.cpp +++ b/noncore/games/qasteroids/toplevel.cpp | |||
@@ -1,85 +1,87 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************//* | 19 | **********************************************************************//* |
20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 | 20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 |
21 | * | 21 | * |
22 | * Part of the KDE project | 22 | * Part of the KDE project |
23 | */ | 23 | */ |
24 | //--- toplevel.cpp --- | 24 | //--- toplevel.cpp --- |
25 | 25 | ||
26 | #include "toplevel.h" | 26 | #include "toplevel.h" |
27 | #include "ledmeter.h" | 27 | #include "ledmeter.h" |
28 | 28 | ||
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
31 | 31 | ||
32 | #include <qaccel.h> | 32 | #include <qaccel.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qlcdnumber.h> | 35 | #include <qlcdnumber.h> |
36 | #include <qpushbutton.h> | 36 | #include <qpushbutton.h> |
37 | 37 | ||
38 | #include <sys/utsname.h> | ||
39 | |||
38 | 40 | ||
39 | #define SB_SCORE1 | 41 | #define SB_SCORE1 |
40 | #define SB_LEVEL2 | 42 | #define SB_LEVEL2 |
41 | #define SB_SHIPS3 | 43 | #define SB_SHIPS3 |
42 | 44 | ||
43 | struct SLevel | 45 | struct SLevel |
44 | { | 46 | { |
45 | int nrocks; | 47 | int nrocks; |
46 | double rockSpeed; | 48 | double rockSpeed; |
47 | }; | 49 | }; |
48 | 50 | ||
49 | #define MAX_LEVELS16 | 51 | #define MAX_LEVELS16 |
50 | 52 | ||
51 | SLevel levels[MAX_LEVELS] = | 53 | SLevel levels[MAX_LEVELS] = |
52 | { | 54 | { |
53 | { 1, 0.4 }, | 55 | { 1, 0.4 }, |
54 | { 1, 0.6 }, | 56 | { 1, 0.6 }, |
55 | { 2, 0.5 }, | 57 | { 2, 0.5 }, |
56 | { 2, 0.7 }, | 58 | { 2, 0.7 }, |
57 | { 2, 0.8 }, | 59 | { 2, 0.8 }, |
58 | { 3, 0.6 }, | 60 | { 3, 0.6 }, |
59 | { 3, 0.7 }, | 61 | { 3, 0.7 }, |
60 | { 3, 0.8 }, | 62 | { 3, 0.8 }, |
61 | { 4, 0.6 }, | 63 | { 4, 0.6 }, |
62 | { 4, 0.7 }, | 64 | { 4, 0.7 }, |
63 | { 4, 0.8 }, | 65 | { 4, 0.8 }, |
64 | { 5, 0.7 }, | 66 | { 5, 0.7 }, |
65 | { 5, 0.8 }, | 67 | { 5, 0.8 }, |
66 | { 5, 0.9 }, | 68 | { 5, 0.9 }, |
67 | { 5, 1.0 } | 69 | { 5, 1.0 } |
68 | }; | 70 | }; |
69 | 71 | ||
70 | const char *soundEvents[] = | 72 | const char *soundEvents[] = |
71 | { | 73 | { |
72 | "ShipDestroyed", | 74 | "ShipDestroyed", |
73 | "RockDestroyed", | 75 | "RockDestroyed", |
74 | 0 | 76 | 0 |
75 | }; | 77 | }; |
76 | 78 | ||
77 | const char *soundDefaults[] = | 79 | const char *soundDefaults[] = |
78 | { | 80 | { |
79 | "Explosion.wav", | 81 | "Explosion.wav", |
80 | "ploop.wav", | 82 | "ploop.wav", |
81 | 0 | 83 | 0 |
82 | }; | 84 | }; |
83 | 85 | ||
84 | 86 | ||
85 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) | 87 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) |
@@ -208,99 +210,115 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) | |||
208 | shieldLCD->setPalette( pal ); | 210 | shieldLCD->setPalette( pal ); |
209 | shieldLCD->setFixedHeight( 16 ); | 211 | shieldLCD->setFixedHeight( 16 ); |
210 | hbd->addWidget( shieldLCD ); | 212 | hbd->addWidget( shieldLCD ); |
211 | 213 | ||
212 | hbd->addSpacing( 5 ); | 214 | hbd->addSpacing( 5 ); |
213 | 215 | ||
214 | label = new QLabel( mainWin ); | 216 | label = new QLabel( mainWin ); |
215 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") ); | 217 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") ); |
216 | label->setFixedWidth( 16 ); | 218 | label->setFixedWidth( 16 ); |
217 | label->setPalette( pal ); | 219 | label->setPalette( pal ); |
218 | hbd->addWidget( label ); | 220 | hbd->addWidget( label ); |
219 | 221 | ||
220 | shootLCD = new QLCDNumber( 1, mainWin ); | 222 | shootLCD = new QLCDNumber( 1, mainWin ); |
221 | shootLCD->setFrameStyle( QFrame::NoFrame ); | 223 | shootLCD->setFrameStyle( QFrame::NoFrame ); |
222 | shootLCD->setSegmentStyle( QLCDNumber::Flat ); | 224 | shootLCD->setSegmentStyle( QLCDNumber::Flat ); |
223 | shootLCD->setPalette( pal ); | 225 | shootLCD->setPalette( pal ); |
224 | shootLCD->setFixedHeight( 16 ); | 226 | shootLCD->setFixedHeight( 16 ); |
225 | hbd->addWidget( shootLCD ); | 227 | hbd->addWidget( shootLCD ); |
226 | 228 | ||
227 | hbd->addStretch( 1 ); | 229 | hbd->addStretch( 1 ); |
228 | 230 | ||
229 | label = new QLabel( tr( "Fuel" ), mainWin ); | 231 | label = new QLabel( tr( "Fuel" ), mainWin ); |
230 | label->setFont( smallFont ); | 232 | label->setFont( smallFont ); |
231 | label->setFixedWidth( label->sizeHint().width() + 5 ); | 233 | label->setFixedWidth( label->sizeHint().width() + 5 ); |
232 | label->setPalette( pal ); | 234 | label->setPalette( pal ); |
233 | hbd->addWidget( label ); | 235 | hbd->addWidget( label ); |
234 | 236 | ||
235 | powerMeter = new KALedMeter( mainWin ); | 237 | powerMeter = new KALedMeter( mainWin ); |
236 | powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); | 238 | powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); |
237 | powerMeter->setRange( MAX_POWER_LEVEL ); | 239 | powerMeter->setRange( MAX_POWER_LEVEL ); |
238 | powerMeter->addColorRange( 10, darkRed ); | 240 | powerMeter->addColorRange( 10, darkRed ); |
239 | powerMeter->addColorRange( 20, QColor(160, 96, 0) ); | 241 | powerMeter->addColorRange( 20, QColor(160, 96, 0) ); |
240 | powerMeter->addColorRange( 70, darkGreen ); | 242 | powerMeter->addColorRange( 70, darkGreen ); |
241 | powerMeter->setCount( 15 ); | 243 | powerMeter->setCount( 15 ); |
242 | powerMeter->setPalette( pal ); | 244 | powerMeter->setPalette( pal ); |
243 | powerMeter->setFixedSize( 60, 12 ); | 245 | powerMeter->setFixedSize( 60, 12 ); |
244 | hbd->addWidget( powerMeter ); | 246 | hbd->addWidget( powerMeter ); |
245 | 247 | ||
246 | shipsRemain = 3; | 248 | shipsRemain = 3; |
247 | showHiscores = FALSE; | 249 | showHiscores = FALSE; |
248 | 250 | ||
249 | actions.insert( Qt::Key_Up, Thrust ); | 251 | actions.insert( Qt::Key_Up, Thrust ); |
250 | actions.insert( Qt::Key_Left, RotateLeft ); | 252 | actions.insert( Qt::Key_Left, RotateLeft ); |
251 | actions.insert( Qt::Key_Right, RotateRight ); | 253 | actions.insert( Qt::Key_Right, RotateRight ); |
252 | actions.insert( Qt::Key_Enter, Shoot ); | 254 | actions.insert( Qt::Key_Enter, Shoot ); |
253 | actions.insert( Qt::Key_Z, Teleport ); | 255 | actions.insert( Qt::Key_Z, Teleport ); |
254 | actions.insert( Qt::Key_Down, Brake ); | 256 | actions.insert( Qt::Key_Down, Brake ); |
255 | actions.insert( Qt::Key_P, Pause ); | 257 | actions.insert( Qt::Key_P, Pause ); |
256 | actions.insert( Key_F12, Launch ); | 258 | |
257 | actions.insert( Key_F11, Shield ); | 259 | |
258 | actions.insert( Key_F9, NewGame ); | 260 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
261 | lineo change string, this break | ||
262 | */ | ||
263 | if (uname(&name) != -1) { | ||
264 | QString release=name.release; | ||
265 | if(release.find("embedix",0,TRUE) !=-1) { | ||
266 | actions.insert( Key_F12, Launch ); | ||
267 | actions.insert( Key_F11, Shield ); | ||
268 | actions.insert( Key_F9, NewGame ); | ||
269 | } else { | ||
270 | // ipaq | ||
271 | actions.insert( Key_F12, Shoot ); | ||
272 | actions.insert( Key_F11, Shield ); | ||
273 | actions.insert( Key_F10, Launch ); | ||
274 | actions.insert( Key_F9, NewGame ); | ||
275 | } | ||
276 | } | ||
259 | 277 | ||
260 | // actions.insert( Qt::Key_S, Shield ); | 278 | // actions.insert( Qt::Key_S, Shield ); |
261 | // actions.insert( Qt::Key_X, Brake ); | 279 | // actions.insert( Qt::Key_X, Brake ); |
262 | // actions.insert( Qt::Key_L, Launch ); | 280 | // actions.insert( Qt::Key_L, Launch ); |
263 | actions.insert( Qt::Key_Space, Shoot ); | 281 | actions.insert( Qt::Key_Space, Shoot ); |
264 | 282 | ||
265 | view->showText( tr( "Press Calendar to start playing" ), yellow ); | 283 | view->showText( tr( "Press Calendar to start playing" ), yellow ); |
266 | 284 | ||
267 | setFocusPolicy( StrongFocus ); | 285 | setFocusPolicy( StrongFocus ); |
268 | 286 | ||
269 | slotNewGame(); | 287 | slotNewGame(); |
270 | } | 288 | } |
271 | 289 | ||
272 | KAstTopLevel::~KAstTopLevel() | 290 | KAstTopLevel::~KAstTopLevel() |
273 | { | 291 | { |
274 | } | 292 | } |
275 | 293 | ||
276 | void KAstTopLevel::playSound( const char * ) | 294 | void KAstTopLevel::playSound( const char * ) |
277 | { | 295 | { |
278 | } | 296 | } |
279 | 297 | ||
280 | void KAstTopLevel::keyPressEvent( QKeyEvent *event ) | 298 | void KAstTopLevel::keyPressEvent( QKeyEvent *event ) |
281 | { | 299 | { |
282 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) | 300 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
283 | { | 301 | { |
284 | event->ignore(); | 302 | event->ignore(); |
285 | return; | 303 | return; |
286 | } | 304 | } |
287 | 305 | ||
288 | Action a = actions[ event->key() ]; | 306 | Action a = actions[ event->key() ]; |
289 | 307 | ||
290 | switch ( a ) | 308 | switch ( a ) |
291 | { | 309 | { |
292 | case RotateLeft: | 310 | case RotateLeft: |
293 | view->rotateLeft( TRUE ); | 311 | view->rotateLeft( TRUE ); |
294 | break; | 312 | break; |
295 | 313 | ||
296 | case RotateRight: | 314 | case RotateRight: |
297 | view->rotateRight( TRUE ); | 315 | view->rotateRight( TRUE ); |
298 | break; | 316 | break; |
299 | 317 | ||
300 | case Thrust: | 318 | case Thrust: |
301 | view->thrust( TRUE ); | 319 | view->thrust( TRUE ); |
302 | break; | 320 | break; |
303 | 321 | ||
304 | case Shoot: | 322 | case Shoot: |
305 | view->shoot( TRUE ); | 323 | view->shoot( TRUE ); |
306 | break; | 324 | break; |
@@ -406,97 +424,97 @@ void KAstTopLevel::showEvent( QShowEvent *e ) | |||
406 | view->pause( FALSE ); | 424 | view->pause( FALSE ); |
407 | setFocus(); | 425 | setFocus(); |
408 | } | 426 | } |
409 | 427 | ||
410 | void KAstTopLevel::hideEvent( QHideEvent *e ) | 428 | void KAstTopLevel::hideEvent( QHideEvent *e ) |
411 | { | 429 | { |
412 | QMainWindow::hideEvent( e ); | 430 | QMainWindow::hideEvent( e ); |
413 | view->pause( TRUE ); | 431 | view->pause( TRUE ); |
414 | } | 432 | } |
415 | 433 | ||
416 | void KAstTopLevel::focusInEvent( QFocusEvent * ) | 434 | void KAstTopLevel::focusInEvent( QFocusEvent * ) |
417 | { | 435 | { |
418 | view->pause( FALSE ); | 436 | view->pause( FALSE ); |
419 | setFocus(); | 437 | setFocus(); |
420 | } | 438 | } |
421 | 439 | ||
422 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) | 440 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) |
423 | { | 441 | { |
424 | view->pause( TRUE ); | 442 | view->pause( TRUE ); |
425 | } | 443 | } |
426 | 444 | ||
427 | void KAstTopLevel::slotNewGame() | 445 | void KAstTopLevel::slotNewGame() |
428 | { | 446 | { |
429 | shipsRemain = 3; | 447 | shipsRemain = 3; |
430 | score = 0; | 448 | score = 0; |
431 | scoreLCD->display( 0 ); | 449 | scoreLCD->display( 0 ); |
432 | level = 0; | 450 | level = 0; |
433 | levelLCD->display( level+1 ); | 451 | levelLCD->display( level+1 ); |
434 | shipsLCD->display( shipsRemain-1 ); | 452 | shipsLCD->display( shipsRemain-1 ); |
435 | view->newGame(); | 453 | view->newGame(); |
436 | view->setRockSpeed( levels[0].rockSpeed ); | 454 | view->setRockSpeed( levels[0].rockSpeed ); |
437 | view->addRocks( levels[0].nrocks ); | 455 | view->addRocks( levels[0].nrocks ); |
438 | view->newShip(); | 456 | view->newShip(); |
439 | waitShip = FALSE; | 457 | waitShip = FALSE; |
440 | view->hideText(); | 458 | view->hideText(); |
441 | isPaused = FALSE; | 459 | isPaused = FALSE; |
442 | } | 460 | } |
443 | 461 | ||
444 | void KAstTopLevel::slotShipKilled() | 462 | void KAstTopLevel::slotShipKilled() |
445 | { | 463 | { |
446 | shipsRemain--; | 464 | shipsRemain--; |
447 | shipsLCD->display( shipsRemain-1 ); | 465 | shipsLCD->display( shipsRemain-1 ); |
448 | 466 | ||
449 | playSound( "ShipDestroyed" ); | 467 | playSound( "ShipDestroyed" ); |
450 | 468 | ||
451 | if ( shipsRemain > 0 ) | 469 | if ( shipsRemain > 0 ) |
452 | { | 470 | { |
453 | waitShip = TRUE; | 471 | waitShip = TRUE; |
454 | view->showText( tr( "Ship Destroyed.\nPress Launch/Home key."), yellow ); | 472 | view->showText( tr( "Ship Destroyed.\nPress Contacts/Home key."), yellow ); |
455 | } | 473 | } |
456 | else | 474 | else |
457 | { | 475 | { |
458 | view->endGame(); | 476 | view->endGame(); |
459 | doStats(); | 477 | doStats(); |
460 | } | 478 | } |
461 | } | 479 | } |
462 | 480 | ||
463 | void KAstTopLevel::slotRockHit( int size ) | 481 | void KAstTopLevel::slotRockHit( int size ) |
464 | { | 482 | { |
465 | switch ( size ) | 483 | switch ( size ) |
466 | { | 484 | { |
467 | case 0: | 485 | case 0: |
468 | score += 10; | 486 | score += 10; |
469 | break; | 487 | break; |
470 | 488 | ||
471 | case 1: | 489 | case 1: |
472 | score += 20; | 490 | score += 20; |
473 | break; | 491 | break; |
474 | 492 | ||
475 | default: | 493 | default: |
476 | score += 40; | 494 | score += 40; |
477 | } | 495 | } |
478 | 496 | ||
479 | playSound( "RockDestroyed" ); | 497 | playSound( "RockDestroyed" ); |
480 | 498 | ||
481 | scoreLCD->display( score ); | 499 | scoreLCD->display( score ); |
482 | } | 500 | } |
483 | 501 | ||
484 | void KAstTopLevel::slotRocksRemoved() | 502 | void KAstTopLevel::slotRocksRemoved() |
485 | { | 503 | { |
486 | level++; | 504 | level++; |
487 | 505 | ||
488 | if ( level >= MAX_LEVELS ) | 506 | if ( level >= MAX_LEVELS ) |
489 | level = MAX_LEVELS - 1; | 507 | level = MAX_LEVELS - 1; |
490 | 508 | ||
491 | view->setRockSpeed( levels[level-1].rockSpeed ); | 509 | view->setRockSpeed( levels[level-1].rockSpeed ); |
492 | view->addRocks( levels[level-1].nrocks ); | 510 | view->addRocks( levels[level-1].nrocks ); |
493 | 511 | ||
494 | levelLCD->display( level+1 ); | 512 | levelLCD->display( level+1 ); |
495 | } | 513 | } |
496 | 514 | ||
497 | void KAstTopLevel::doStats() | 515 | void KAstTopLevel::doStats() |
498 | { | 516 | { |
499 | QString r( "0.00" ); | 517 | QString r( "0.00" ); |
500 | if ( view->shots() ) | 518 | if ( view->shots() ) |
501 | r = QString::number( (double)view->hits() / view->shots() * 100.0, | 519 | r = QString::number( (double)view->hits() / view->shots() * 100.0, |
502 | 'g', 2 ); | 520 | 'g', 2 ); |