author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:20:32 +0300 | |
changeset 34 | a33bf25e6f72 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
/* |
|
42 |
* KAsteroids - Copyright (c) Martin R. Jones 1997 |
|
43 |
* |
|
44 |
* Part of the KDE project |
|
45 |
*/ |
|
46 |
// --- toplevel.cpp --- |
|
47 |
#include <q3accel.h> |
|
48 |
#include <qlabel.h> |
|
49 |
#include <qlayout.h> |
|
50 |
#include <qlcdnumber.h> |
|
51 |
#include <qpushbutton.h> |
|
52 |
||
53 |
#include <qapplication.h> |
|
54 |
//Added by qt3to4: |
|
55 |
#include <Q3HBoxLayout> |
|
56 |
#include <QShowEvent> |
|
57 |
#include <Q3Frame> |
|
58 |
#include <QPixmap> |
|
59 |
#include <QHideEvent> |
|
60 |
#include <QKeyEvent> |
|
61 |
#include <Q3VBoxLayout> |
|
62 |
||
63 |
#include "toplevel.h" |
|
64 |
#include "ledmeter.h" |
|
65 |
||
66 |
||
67 |
#define SB_SCORE 1 |
|
68 |
#define SB_LEVEL 2 |
|
69 |
#define SB_SHIPS 3 |
|
70 |
||
71 |
struct SLevel |
|
72 |
{ |
|
73 |
int nrocks; |
|
74 |
double rockSpeed; |
|
75 |
}; |
|
76 |
||
77 |
#define MAX_LEVELS 16 |
|
78 |
||
79 |
SLevel levels[MAX_LEVELS] = |
|
80 |
{ |
|
81 |
{ 1, 0.4 }, |
|
82 |
{ 1, 0.6 }, |
|
83 |
{ 2, 0.5 }, |
|
84 |
{ 2, 0.7 }, |
|
85 |
{ 2, 0.8 }, |
|
86 |
{ 3, 0.6 }, |
|
87 |
{ 3, 0.7 }, |
|
88 |
{ 3, 0.8 }, |
|
89 |
{ 4, 0.6 }, |
|
90 |
{ 4, 0.7 }, |
|
91 |
{ 4, 0.8 }, |
|
92 |
{ 5, 0.7 }, |
|
93 |
{ 5, 0.8 }, |
|
94 |
{ 5, 0.9 }, |
|
95 |
{ 5, 1.0 } |
|
96 |
}; |
|
97 |
||
98 |
const char *soundEvents[] = |
|
99 |
{ |
|
100 |
"ShipDestroyed", |
|
101 |
"RockDestroyed", |
|
102 |
0 |
|
103 |
}; |
|
104 |
||
105 |
const char *soundDefaults[] = |
|
106 |
{ |
|
107 |
"Explosion.wav", |
|
108 |
"ploop.wav", |
|
109 |
0 |
|
110 |
}; |
|
111 |
||
112 |
||
113 |
KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) |
|
114 |
: Q3MainWindow( parent, name, 0 ) |
|
115 |
{ |
|
116 |
QWidget *border = new QWidget( this ); |
|
117 |
border->setBackgroundColor( Qt::black ); |
|
118 |
setCentralWidget( border ); |
|
119 |
||
120 |
Q3VBoxLayout *borderLayout = new Q3VBoxLayout( border ); |
|
121 |
borderLayout->addStretch( 1 ); |
|
122 |
||
123 |
QWidget *mainWin = new QWidget( border ); |
|
124 |
mainWin->setFixedSize(640, 480); |
|
125 |
borderLayout->addWidget( mainWin, 0, Qt::AlignHCenter ); |
|
126 |
||
127 |
borderLayout->addStretch( 1 ); |
|
128 |
||
129 |
view = new KAsteroidsView( mainWin ); |
|
130 |
view->setFocusPolicy( Qt::StrongFocus ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
connect( view, SIGNAL(shipKilled()), SLOT(slotShipKilled()) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
connect( view, SIGNAL(rockHit(int)), SLOT(slotRockHit(int)) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
connect( view, SIGNAL(rocksRemoved()), SLOT(slotRocksRemoved()) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
connect( view, SIGNAL(updateVitals()), SLOT(slotUpdateVitals()) ); |
0 | 135 |
|
136 |
Q3VBoxLayout *vb = new Q3VBoxLayout( mainWin ); |
|
137 |
Q3HBoxLayout *hb = new Q3HBoxLayout; |
|
138 |
Q3HBoxLayout *hbd = new Q3HBoxLayout; |
|
139 |
vb->addLayout( hb ); |
|
140 |
||
141 |
QFont labelFont( "helvetica", 24 ); |
|
142 |
QColorGroup grp( Qt::darkGreen, Qt::black, QColor( 128, 128, 128 ), |
|
143 |
QColor( 64, 64, 64 ), Qt::black, Qt::darkGreen, Qt::black ); |
|
144 |
QPalette pal( grp, grp, grp ); |
|
145 |
||
146 |
mainWin->setPalette( pal ); |
|
147 |
||
148 |
hb->addSpacing( 10 ); |
|
149 |
||
150 |
QLabel *label; |
|
151 |
label = new QLabel( tr("Score"), mainWin ); |
|
152 |
label->setFont( labelFont ); |
|
153 |
label->setPalette( pal ); |
|
154 |
label->setFixedWidth( label->sizeHint().width() ); |
|
155 |
hb->addWidget( label ); |
|
156 |
||
157 |
scoreLCD = new QLCDNumber( 6, mainWin ); |
|
158 |
scoreLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
159 |
scoreLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
160 |
scoreLCD->setFixedWidth( 150 ); |
|
161 |
scoreLCD->setPalette( pal ); |
|
162 |
hb->addWidget( scoreLCD ); |
|
163 |
hb->addStretch( 10 ); |
|
164 |
||
165 |
label = new QLabel( tr("Level"), mainWin ); |
|
166 |
label->setFont( labelFont ); |
|
167 |
label->setPalette( pal ); |
|
168 |
label->setFixedWidth( label->sizeHint().width() ); |
|
169 |
hb->addWidget( label ); |
|
170 |
||
171 |
levelLCD = new QLCDNumber( 2, mainWin ); |
|
172 |
levelLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
173 |
levelLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
174 |
levelLCD->setFixedWidth( 70 ); |
|
175 |
levelLCD->setPalette( pal ); |
|
176 |
hb->addWidget( levelLCD ); |
|
177 |
hb->addStretch( 10 ); |
|
178 |
||
179 |
label = new QLabel( tr("Ships"), mainWin ); |
|
180 |
label->setFont( labelFont ); |
|
181 |
label->setFixedWidth( label->sizeHint().width() ); |
|
182 |
label->setPalette( pal ); |
|
183 |
hb->addWidget( label ); |
|
184 |
||
185 |
shipsLCD = new QLCDNumber( 1, mainWin ); |
|
186 |
shipsLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
187 |
shipsLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
188 |
shipsLCD->setFixedWidth( 40 ); |
|
189 |
shipsLCD->setPalette( pal ); |
|
190 |
hb->addWidget( shipsLCD ); |
|
191 |
||
192 |
hb->addStrut( 30 ); |
|
193 |
||
194 |
vb->addWidget( view, 10 ); |
|
195 |
||
196 |
// -- bottom layout: |
|
197 |
vb->addLayout( hbd ); |
|
198 |
||
199 |
QFont smallFont( "helvetica", 14 ); |
|
200 |
hbd->addSpacing( 10 ); |
|
201 |
||
202 |
QString sprites_prefix = ":/trolltech/examples/graphicsview/portedasteroids/sprites/"; |
|
203 |
/* |
|
204 |
label = new QLabel( tr( "T" ), mainWin ); |
|
205 |
label->setFont( smallFont ); |
|
206 |
label->setFixedWidth( label->sizeHint().width() ); |
|
207 |
label->setPalette( pal ); |
|
208 |
hbd->addWidget( label ); |
|
209 |
||
210 |
teleportsLCD = new QLCDNumber( 1, mainWin ); |
|
211 |
teleportsLCD->setFrameStyle( QFrame::NoFrame ); |
|
212 |
teleportsLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
213 |
teleportsLCD->setPalette( pal ); |
|
214 |
teleportsLCD->setFixedHeight( 20 ); |
|
215 |
hbd->addWidget( teleportsLCD ); |
|
216 |
||
217 |
hbd->addSpacing( 10 ); |
|
218 |
*/ |
|
219 |
QPixmap pm( sprites_prefix + "powerups/brake.png" ); |
|
220 |
label = new QLabel( mainWin ); |
|
221 |
label->setPixmap( pm ); |
|
222 |
label->setFixedWidth( label->sizeHint().width() ); |
|
223 |
label->setPalette( pal ); |
|
224 |
hbd->addWidget( label ); |
|
225 |
||
226 |
brakesLCD = new QLCDNumber( 1, mainWin ); |
|
227 |
brakesLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
228 |
brakesLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
229 |
brakesLCD->setPalette( pal ); |
|
230 |
brakesLCD->setFixedHeight( 20 ); |
|
231 |
hbd->addWidget( brakesLCD ); |
|
232 |
||
233 |
hbd->addSpacing( 10 ); |
|
234 |
||
235 |
pm.load( sprites_prefix + "powerups/shield.png" ); |
|
236 |
label = new QLabel( mainWin ); |
|
237 |
label->setPixmap( pm ); |
|
238 |
label->setFixedWidth( label->sizeHint().width() ); |
|
239 |
label->setPalette( pal ); |
|
240 |
hbd->addWidget( label ); |
|
241 |
||
242 |
shieldLCD = new QLCDNumber( 1, mainWin ); |
|
243 |
shieldLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
244 |
shieldLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
245 |
shieldLCD->setPalette( pal ); |
|
246 |
shieldLCD->setFixedHeight( 20 ); |
|
247 |
hbd->addWidget( shieldLCD ); |
|
248 |
||
249 |
hbd->addSpacing( 10 ); |
|
250 |
||
251 |
pm.load( sprites_prefix + "powerups/shoot.png" ); |
|
252 |
label = new QLabel( mainWin ); |
|
253 |
label->setPixmap( pm ); |
|
254 |
label->setFixedWidth( label->sizeHint().width() ); |
|
255 |
label->setPalette( pal ); |
|
256 |
hbd->addWidget( label ); |
|
257 |
||
258 |
shootLCD = new QLCDNumber( 1, mainWin ); |
|
259 |
shootLCD->setFrameStyle( Q3Frame::NoFrame ); |
|
260 |
shootLCD->setSegmentStyle( QLCDNumber::Flat ); |
|
261 |
shootLCD->setPalette( pal ); |
|
262 |
shootLCD->setFixedHeight( 20 ); |
|
263 |
hbd->addWidget( shootLCD ); |
|
264 |
||
265 |
hbd->addStretch( 1 ); |
|
266 |
||
267 |
label = new QLabel( tr( "Fuel" ), mainWin ); |
|
268 |
label->setFont( smallFont ); |
|
269 |
label->setFixedWidth( label->sizeHint().width() + 10 ); |
|
270 |
label->setPalette( pal ); |
|
271 |
hbd->addWidget( label ); |
|
272 |
||
273 |
powerMeter = new KALedMeter( mainWin ); |
|
274 |
powerMeter->setFrameStyle( Q3Frame::Box | Q3Frame::Plain ); |
|
275 |
powerMeter->setRange( MAX_POWER_LEVEL ); |
|
276 |
powerMeter->addColorRange( 10, Qt::darkRed ); |
|
277 |
powerMeter->addColorRange( 20, QColor(160, 96, 0) ); |
|
278 |
powerMeter->addColorRange( 70, Qt::darkGreen ); |
|
279 |
powerMeter->setCount( 40 ); |
|
280 |
powerMeter->setPalette( pal ); |
|
281 |
powerMeter->setFixedSize( 200, 12 ); |
|
282 |
hbd->addWidget( powerMeter ); |
|
283 |
||
284 |
shipsRemain = 3; |
|
285 |
showHiscores = FALSE; |
|
286 |
||
287 |
actions.insert( Qt::Key_Up, Thrust ); |
|
288 |
actions.insert( Qt::Key_Left, RotateLeft ); |
|
289 |
actions.insert( Qt::Key_Right, RotateRight ); |
|
290 |
actions.insert( Qt::Key_Space, Shoot ); |
|
291 |
actions.insert( Qt::Key_Z, Teleport ); |
|
292 |
actions.insert( Qt::Key_X, Brake ); |
|
293 |
actions.insert( Qt::Key_S, Shield ); |
|
294 |
actions.insert( Qt::Key_P, Pause ); |
|
295 |
actions.insert( Qt::Key_L, Launch ); |
|
296 |
actions.insert( Qt::Key_N, NewGame ); |
|
297 |
||
298 |
view->showText( tr( "Press N to start playing" ), Qt::yellow ); |
|
299 |
} |
|
300 |
||
301 |
KAstTopLevel::~KAstTopLevel() |
|
302 |
{ |
|
303 |
} |
|
304 |
||
305 |
void KAstTopLevel::playSound( const char * ) |
|
306 |
{ |
|
307 |
} |
|
308 |
||
309 |
void KAstTopLevel::keyPressEvent( QKeyEvent *event ) |
|
310 |
{ |
|
311 |
if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
|
312 |
{ |
|
313 |
event->ignore(); |
|
314 |
return; |
|
315 |
} |
|
316 |
||
317 |
Action a = actions[ event->key() ]; |
|
318 |
||
319 |
switch ( a ) |
|
320 |
{ |
|
321 |
case RotateLeft: |
|
322 |
view->rotateLeft( TRUE ); |
|
323 |
break; |
|
324 |
||
325 |
case RotateRight: |
|
326 |
view->rotateRight( TRUE ); |
|
327 |
break; |
|
328 |
||
329 |
case Thrust: |
|
330 |
view->thrust( TRUE ); |
|
331 |
break; |
|
332 |
||
333 |
case Shoot: |
|
334 |
view->shoot( TRUE ); |
|
335 |
break; |
|
336 |
||
337 |
case Shield: |
|
338 |
view->setShield( TRUE ); |
|
339 |
break; |
|
340 |
||
341 |
case Teleport: |
|
342 |
view->teleport( TRUE ); |
|
343 |
break; |
|
344 |
||
345 |
case Brake: |
|
346 |
view->brake( TRUE ); |
|
347 |
break; |
|
348 |
||
349 |
default: |
|
350 |
event->ignore(); |
|
351 |
return; |
|
352 |
} |
|
353 |
event->accept(); |
|
354 |
} |
|
355 |
||
356 |
void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) |
|
357 |
{ |
|
358 |
if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
|
359 |
{ |
|
360 |
event->ignore(); |
|
361 |
return; |
|
362 |
} |
|
363 |
||
364 |
Action a = actions[ event->key() ]; |
|
365 |
||
366 |
switch ( a ) |
|
367 |
{ |
|
368 |
case RotateLeft: |
|
369 |
view->rotateLeft( FALSE ); |
|
370 |
break; |
|
371 |
||
372 |
case RotateRight: |
|
373 |
view->rotateRight( FALSE ); |
|
374 |
break; |
|
375 |
||
376 |
case Thrust: |
|
377 |
view->thrust( FALSE ); |
|
378 |
break; |
|
379 |
||
380 |
case Shoot: |
|
381 |
view->shoot( FALSE ); |
|
382 |
break; |
|
383 |
||
384 |
case Brake: |
|
385 |
view->brake( FALSE ); |
|
386 |
break; |
|
387 |
||
388 |
case Shield: |
|
389 |
view->setShield( FALSE ); |
|
390 |
break; |
|
391 |
||
392 |
case Teleport: |
|
393 |
view->teleport( FALSE ); |
|
394 |
break; |
|
395 |
||
396 |
case Launch: |
|
397 |
if ( waitShip ) |
|
398 |
{ |
|
399 |
view->newShip(); |
|
400 |
waitShip = FALSE; |
|
401 |
view->hideText(); |
|
402 |
} |
|
403 |
else |
|
404 |
{ |
|
405 |
event->ignore(); |
|
406 |
return; |
|
407 |
} |
|
408 |
break; |
|
409 |
||
410 |
case NewGame: |
|
411 |
slotNewGame(); |
|
412 |
break; |
|
413 |
/* |
|
414 |
case Pause: |
|
415 |
{ |
|
416 |
view->pause( TRUE ); |
|
417 |
QMessageBox::information( this, |
|
418 |
tr("KAsteroids is paused"), |
|
419 |
tr("Paused") ); |
|
420 |
view->pause( FALSE ); |
|
421 |
} |
|
422 |
break; |
|
423 |
*/ |
|
424 |
default: |
|
425 |
event->ignore(); |
|
426 |
return; |
|
427 |
} |
|
428 |
||
429 |
event->accept(); |
|
430 |
} |
|
431 |
||
432 |
void KAstTopLevel::showEvent( QShowEvent *e ) |
|
433 |
{ |
|
434 |
Q3MainWindow::showEvent( e ); |
|
435 |
view->pause( FALSE ); |
|
436 |
view->setFocus(); |
|
437 |
} |
|
438 |
||
439 |
void KAstTopLevel::hideEvent( QHideEvent *e ) |
|
440 |
{ |
|
441 |
Q3MainWindow::hideEvent( e ); |
|
442 |
view->pause( TRUE ); |
|
443 |
} |
|
444 |
||
445 |
void KAstTopLevel::slotNewGame() |
|
446 |
{ |
|
447 |
score = 0; |
|
448 |
shipsRemain = SB_SHIPS; |
|
449 |
scoreLCD->display( 0 ); |
|
450 |
level = 0; |
|
451 |
levelLCD->display( level+1 ); |
|
452 |
shipsLCD->display( shipsRemain-1 ); |
|
453 |
view->newGame(); |
|
454 |
view->setRockSpeed( levels[0].rockSpeed ); |
|
455 |
view->addRocks( levels[0].nrocks ); |
|
456 |
// view->showText( tr( "Press L to launch." ), yellow ); |
|
457 |
view->newShip(); |
|
458 |
waitShip = FALSE; |
|
459 |
view->hideText(); |
|
460 |
isPaused = FALSE; |
|
461 |
} |
|
462 |
||
463 |
void KAstTopLevel::slotShipKilled() |
|
464 |
{ |
|
465 |
shipsRemain--; |
|
466 |
shipsLCD->display( shipsRemain-1 ); |
|
467 |
||
468 |
playSound( "ShipDestroyed" ); |
|
469 |
||
470 |
if ( shipsRemain ) |
|
471 |
{ |
|
472 |
waitShip = TRUE; |
|
473 |
view->showText( tr( "Ship Destroyed. Press L to launch."), Qt::yellow ); |
|
474 |
} |
|
475 |
else |
|
476 |
{ |
|
477 |
view->showText( tr("Game Over!"), Qt::red ); |
|
478 |
view->endGame(); |
|
479 |
doStats(); |
|
480 |
// highscore->addEntry( score, level, showHiscores ); |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
void KAstTopLevel::slotRockHit( int size ) |
|
485 |
{ |
|
486 |
switch ( size ) |
|
487 |
{ |
|
488 |
case 0: |
|
489 |
score += 10; |
|
490 |
break; |
|
491 |
||
492 |
case 1: |
|
493 |
score += 20; |
|
494 |
break; |
|
495 |
||
496 |
default: |
|
497 |
score += 40; |
|
498 |
} |
|
499 |
||
500 |
playSound( "RockDestroyed" ); |
|
501 |
||
502 |
scoreLCD->display( score ); |
|
503 |
} |
|
504 |
||
505 |
void KAstTopLevel::slotRocksRemoved() |
|
506 |
{ |
|
507 |
level++; |
|
508 |
||
509 |
if ( level >= MAX_LEVELS ) |
|
510 |
level = MAX_LEVELS - 1; |
|
511 |
||
512 |
view->setRockSpeed( levels[level-1].rockSpeed ); |
|
513 |
view->addRocks( levels[level-1].nrocks ); |
|
514 |
||
515 |
levelLCD->display( level+1 ); |
|
516 |
} |
|
517 |
||
518 |
void KAstTopLevel::doStats() |
|
519 |
{ |
|
520 |
QString r( "0.00" ); |
|
521 |
if ( view->shots() ) |
|
522 |
r = QString::number( (double)view->hits() / view->shots() * 100.0, |
|
523 |
'g', 2 ); |
|
524 |
||
525 |
/* multi-line text broken in Qt 3 |
|
526 |
QString s = tr( "Game Over\n\nShots fired:\t%1\n Hit:\t%2\n Missed:\t%3\nHit ratio:\t%4 %\n\nPress N for a new game" ) |
|
527 |
.arg(view->shots()).arg(view->hits()) |
|
528 |
.arg(view->shots() - view->hits()) |
|
529 |
.arg(r); |
|
530 |
*/ |
|
531 |
||
532 |
view->showText( "Game Over. Press N for a new game.", Qt::yellow, FALSE ); |
|
533 |
} |
|
534 |
||
535 |
void KAstTopLevel::slotUpdateVitals() |
|
536 |
{ |
|
537 |
brakesLCD->display( view->brakeCount() ); |
|
538 |
shieldLCD->display( view->shieldCount() ); |
|
539 |
shootLCD->display( view->shootCount() ); |
|
540 |
// teleportsLCD->display( view->teleportCount() ); |
|
541 |
powerMeter->setValue( view->power() ); |
|
542 |
} |