summaryrefslogtreecommitdiff
authordrw <drw>2005-05-18 14:28:05 (UTC)
committer drw <drw>2005-05-18 14:28:05 (UTC)
commitcb243f00d12c5fc40de02e7f9f20009b52303a66 (patch) (unidiff)
treef85e840af4db55a67a2a057d6a7f4ef59bfb4385
parent600f14a61969ec2edd6d89efecaac997b1c6464f (diff)
downloadopie-cb243f00d12c5fc40de02e7f9f20009b52303a66.zip
opie-cb243f00d12c5fc40de02e7f9f20009b52303a66.tar.gz
opie-cb243f00d12c5fc40de02e7f9f20009b52303a66.tar.bz2
Resource -> OResource
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/qasteroids/toplevel.cpp9
-rw-r--r--noncore/games/qasteroids/view.cpp14
2 files changed, 10 insertions, 13 deletions
diff --git a/noncore/games/qasteroids/toplevel.cpp b/noncore/games/qasteroids/toplevel.cpp
index 9053d3d..d1e1fac 100644
--- a/noncore/games/qasteroids/toplevel.cpp
+++ b/noncore/games/qasteroids/toplevel.cpp
@@ -1,346 +1,347 @@
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 <opie2/oresource.h>
30
29#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
30#include <qpe/resource.h>
31 32
32#include <qlabel.h> 33#include <qlabel.h>
33#include <qlayout.h> 34#include <qlayout.h>
34#include <qlcdnumber.h> 35#include <qlcdnumber.h>
35 36
36#include <sys/utsname.h> 37#include <sys/utsname.h>
37 38
38 39
39 #define SB_SCORE1 40 #define SB_SCORE1
40 #define SB_LEVEL2 41 #define SB_LEVEL2
41 #define SB_SHIPS3 42 #define SB_SHIPS3
42 43
43struct SLevel 44struct SLevel
44{ 45{
45 int nrocks; 46 int nrocks;
46 double rockSpeed; 47 double rockSpeed;
47}; 48};
48 49
49 #define MAX_LEVELS16 50 #define MAX_LEVELS16
50 51
51SLevel levels[MAX_LEVELS] = 52SLevel levels[MAX_LEVELS] =
52{ 53{
53 { 1, 0.4 }, 54 { 1, 0.4 },
54 { 1, 0.6 }, 55 { 1, 0.6 },
55 { 2, 0.5 }, 56 { 2, 0.5 },
56 { 2, 0.7 }, 57 { 2, 0.7 },
57 { 2, 0.8 }, 58 { 2, 0.8 },
58 { 3, 0.6 }, 59 { 3, 0.6 },
59 { 3, 0.7 }, 60 { 3, 0.7 },
60 { 3, 0.8 }, 61 { 3, 0.8 },
61 { 4, 0.6 }, 62 { 4, 0.6 },
62 { 4, 0.7 }, 63 { 4, 0.7 },
63 { 4, 0.8 }, 64 { 4, 0.8 },
64 { 5, 0.7 }, 65 { 5, 0.7 },
65 { 5, 0.8 }, 66 { 5, 0.8 },
66 { 5, 0.9 }, 67 { 5, 0.9 },
67 { 5, 1.0 } 68 { 5, 1.0 }
68}; 69};
69 70
70const char *soundEvents[] = 71const char *soundEvents[] =
71{ 72{
72 "ShipDestroyed", 73 "ShipDestroyed",
73 "RockDestroyed", 74 "RockDestroyed",
74 0 75 0
75}; 76};
76 77
77const char *soundDefaults[] = 78const char *soundDefaults[] =
78{ 79{
79 "Explosion.wav", 80 "Explosion.wav",
80 "ploop.wav", 81 "ploop.wav",
81 0 82 0
82}; 83};
83 84
84 85
85KAstTopLevel::KAstTopLevel( QWidget *parent, const char *_name, WFlags fl ) 86KAstTopLevel::KAstTopLevel( QWidget *parent, const char *_name, WFlags fl )
86 : QMainWindow( parent, _name, fl ) 87 : QMainWindow( parent, _name, fl )
87{ 88{
88 setCaption( tr("Asteroids") ); 89 setCaption( tr("Asteroids") );
89 90
90 QPEApplication::grabKeyboard(); 91 QPEApplication::grabKeyboard();
91 92
92 QWidget *border = new QWidget( this ); 93 QWidget *border = new QWidget( this );
93 border->setBackgroundColor( black ); 94 border->setBackgroundColor( black );
94 setCentralWidget( border ); 95 setCentralWidget( border );
95 96
96 QVBoxLayout *borderLayout = new QVBoxLayout( border ); 97 QVBoxLayout *borderLayout = new QVBoxLayout( border );
97 98
98 QWidget *mainWin = new QWidget( border ); 99 QWidget *mainWin = new QWidget( border );
99 borderLayout->addWidget( mainWin, 2, AlignHCenter ); 100 borderLayout->addWidget( mainWin, 2, AlignHCenter );
100 101
101 view = new KAsteroidsView( mainWin ); 102 view = new KAsteroidsView( mainWin );
102 connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) ); 103 connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) );
103 connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) ); 104 connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) );
104 connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) ); 105 connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) );
105 connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) ); 106 connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) );
106 107
107 QVBoxLayout *vb = new QVBoxLayout( mainWin ); 108 QVBoxLayout *vb = new QVBoxLayout( mainWin );
108 QHBoxLayout *hb = new QHBoxLayout; 109 QHBoxLayout *hb = new QHBoxLayout;
109 QHBoxLayout *hbd = new QHBoxLayout; 110 QHBoxLayout *hbd = new QHBoxLayout;
110 vb->addLayout( hb ); 111 vb->addLayout( hb );
111 112
112 QFont labelFont( "helvetica", 12 ); 113 QFont labelFont( "helvetica", 12 );
113 QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ), 114 QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ),
114 QColor( 64, 64, 64 ), black, darkGreen, black ); 115 QColor( 64, 64, 64 ), black, darkGreen, black );
115 QPalette pal( grp, grp, grp ); 116 QPalette pal( grp, grp, grp );
116 117
117 mainWin->setPalette( pal ); 118 mainWin->setPalette( pal );
118 119
119 QLabel *label; 120 QLabel *label;
120 label = new QLabel( tr("Score"), mainWin ); 121 label = new QLabel( tr("Score"), mainWin );
121 label->setFont( labelFont ); 122 label->setFont( labelFont );
122 label->setPalette( pal ); 123 label->setPalette( pal );
123// label->setFixedWidth( label->sizeHint().width() ); 124// label->setFixedWidth( label->sizeHint().width() );
124 hb->addWidget( label ); 125 hb->addWidget( label );
125 126
126 scoreLCD = new QLCDNumber( 5, mainWin ); 127 scoreLCD = new QLCDNumber( 5, mainWin );
127 scoreLCD->setFrameStyle( QFrame::NoFrame ); 128 scoreLCD->setFrameStyle( QFrame::NoFrame );
128 scoreLCD->setSegmentStyle( QLCDNumber::Flat ); 129 scoreLCD->setSegmentStyle( QLCDNumber::Flat );
129 scoreLCD->setFixedHeight( 16 ); 130 scoreLCD->setFixedHeight( 16 );
130 scoreLCD->setPalette( pal ); 131 scoreLCD->setPalette( pal );
131 hb->addWidget( scoreLCD ); 132 hb->addWidget( scoreLCD );
132 hb->addStretch( 1 ); 133 hb->addStretch( 1 );
133 134
134 label = new QLabel( tr("Level"), mainWin ); 135 label = new QLabel( tr("Level"), mainWin );
135 label->setFont( labelFont ); 136 label->setFont( labelFont );
136 label->setPalette( pal ); 137 label->setPalette( pal );
137// label->setFixedWidth( label->sizeHint().width() ); 138// label->setFixedWidth( label->sizeHint().width() );
138 hb->addWidget( label ); 139 hb->addWidget( label );
139 140
140 levelLCD = new QLCDNumber( 2, mainWin ); 141 levelLCD = new QLCDNumber( 2, mainWin );
141 levelLCD->setFrameStyle( QFrame::NoFrame ); 142 levelLCD->setFrameStyle( QFrame::NoFrame );
142 levelLCD->setSegmentStyle( QLCDNumber::Flat ); 143 levelLCD->setSegmentStyle( QLCDNumber::Flat );
143 levelLCD->setFixedHeight( 16 ); 144 levelLCD->setFixedHeight( 16 );
144 levelLCD->setPalette( pal ); 145 levelLCD->setPalette( pal );
145 hb->addWidget( levelLCD ); 146 hb->addWidget( levelLCD );
146 hb->addStretch( 1 ); 147 hb->addStretch( 1 );
147 148
148 label = new QLabel( tr("Ships"), mainWin ); 149 label = new QLabel( tr("Ships"), mainWin );
149 label->setFont( labelFont ); 150 label->setFont( labelFont );
150// label->setFixedWidth( label->sizeHint().width() ); 151// label->setFixedWidth( label->sizeHint().width() );
151 label->setPalette( pal ); 152 label->setPalette( pal );
152 hb->addWidget( label ); 153 hb->addWidget( label );
153 154
154 shipsLCD = new QLCDNumber( 1, mainWin ); 155 shipsLCD = new QLCDNumber( 1, mainWin );
155 shipsLCD->setFrameStyle( QFrame::NoFrame ); 156 shipsLCD->setFrameStyle( QFrame::NoFrame );
156 shipsLCD->setSegmentStyle( QLCDNumber::Flat ); 157 shipsLCD->setSegmentStyle( QLCDNumber::Flat );
157 shipsLCD->setFixedHeight( 16 ); 158 shipsLCD->setFixedHeight( 16 );
158 shipsLCD->setPalette( pal ); 159 shipsLCD->setPalette( pal );
159 hb->addWidget( shipsLCD ); 160 hb->addWidget( shipsLCD );
160 161
161// hb->addStrut( 14 ); 162// hb->addStrut( 14 );
162 163
163 vb->addWidget( view, 10 ); 164 vb->addWidget( view, 10 );
164 165
165// -- bottom layout: 166// -- bottom layout:
166 vb->addLayout( hbd ); 167 vb->addLayout( hbd );
167 168
168 QFont smallFont( "helvetica", 12 ); 169 QFont smallFont( "helvetica", 12 );
169 hbd->addSpacing( 5 ); 170 hbd->addSpacing( 5 );
170 171
171/* 172/*
172 label = new QLabel( tr( "T" ), mainWin ); 173 label = new QLabel( tr( "T" ), mainWin );
173 label->setFont( smallFont ); 174 label->setFont( smallFont );
174 label->setFixedWidth( label->sizeHint().width() ); 175 label->setFixedWidth( label->sizeHint().width() );
175 label->setPalette( pal ); 176 label->setPalette( pal );
176 hbd->addWidget( label ); 177 hbd->addWidget( label );
177 178
178 teleportsLCD = new QLCDNumber( 1, mainWin ); 179 teleportsLCD = new QLCDNumber( 1, mainWin );
179 teleportsLCD->setFrameStyle( QFrame::NoFrame ); 180 teleportsLCD->setFrameStyle( QFrame::NoFrame );
180 teleportsLCD->setSegmentStyle( QLCDNumber::Flat ); 181 teleportsLCD->setSegmentStyle( QLCDNumber::Flat );
181 teleportsLCD->setPalette( pal ); 182 teleportsLCD->setPalette( pal );
182 teleportsLCD->setFixedHeight( 18 ); 183 teleportsLCD->setFixedHeight( 18 );
183 hbd->addWidget( teleportsLCD ); 184 hbd->addWidget( teleportsLCD );
184 185
185 hbd->addSpacing( 10 ); 186 hbd->addSpacing( 10 );
186*/ 187*/
187 label = new QLabel( mainWin ); 188 label = new QLabel( mainWin );
188 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/brake.png") ); 189 label->setPixmap( Opie::Core::OResource::loadPixmap("qasteroids/powerups/brake.png") );
189 label->setFixedWidth( 16 ); 190 label->setFixedWidth( 16 );
190 label->setPalette( pal ); 191 label->setPalette( pal );
191 hbd->addWidget( label ); 192 hbd->addWidget( label );
192 193
193 brakesLCD = new QLCDNumber( 1, mainWin ); 194 brakesLCD = new QLCDNumber( 1, mainWin );
194 brakesLCD->setFrameStyle( QFrame::NoFrame ); 195 brakesLCD->setFrameStyle( QFrame::NoFrame );
195 brakesLCD->setSegmentStyle( QLCDNumber::Flat ); 196 brakesLCD->setSegmentStyle( QLCDNumber::Flat );
196 brakesLCD->setPalette( pal ); 197 brakesLCD->setPalette( pal );
197 brakesLCD->setFixedHeight( 16 ); 198 brakesLCD->setFixedHeight( 16 );
198 hbd->addWidget( brakesLCD ); 199 hbd->addWidget( brakesLCD );
199 200
200 hbd->addSpacing( 5 ); 201 hbd->addSpacing( 5 );
201 202
202 label = new QLabel( mainWin ); 203 label = new QLabel( mainWin );
203 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shield.png") ); 204 label->setPixmap( Opie::Core::OResource::loadPixmap("qasteroids/powerups/shield.png") );
204 label->setFixedWidth( 16 ); 205 label->setFixedWidth( 16 );
205 label->setPalette( pal ); 206 label->setPalette( pal );
206 hbd->addWidget( label ); 207 hbd->addWidget( label );
207 208
208 shieldLCD = new QLCDNumber( 1, mainWin ); 209 shieldLCD = new QLCDNumber( 1, mainWin );
209 shieldLCD->setFrameStyle( QFrame::NoFrame ); 210 shieldLCD->setFrameStyle( QFrame::NoFrame );
210 shieldLCD->setSegmentStyle( QLCDNumber::Flat ); 211 shieldLCD->setSegmentStyle( QLCDNumber::Flat );
211 shieldLCD->setPalette( pal ); 212 shieldLCD->setPalette( pal );
212 shieldLCD->setFixedHeight( 16 ); 213 shieldLCD->setFixedHeight( 16 );
213 hbd->addWidget( shieldLCD ); 214 hbd->addWidget( shieldLCD );
214 215
215 hbd->addSpacing( 5 ); 216 hbd->addSpacing( 5 );
216 217
217 label = new QLabel( mainWin ); 218 label = new QLabel( mainWin );
218 label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") ); 219 label->setPixmap( Opie::Core::OResource::loadPixmap("qasteroids/powerups/shoot.png") );
219 label->setFixedWidth( 16 ); 220 label->setFixedWidth( 16 );
220 label->setPalette( pal ); 221 label->setPalette( pal );
221 hbd->addWidget( label ); 222 hbd->addWidget( label );
222 223
223 shootLCD = new QLCDNumber( 1, mainWin ); 224 shootLCD = new QLCDNumber( 1, mainWin );
224 shootLCD->setFrameStyle( QFrame::NoFrame ); 225 shootLCD->setFrameStyle( QFrame::NoFrame );
225 shootLCD->setSegmentStyle( QLCDNumber::Flat ); 226 shootLCD->setSegmentStyle( QLCDNumber::Flat );
226 shootLCD->setPalette( pal ); 227 shootLCD->setPalette( pal );
227 shootLCD->setFixedHeight( 16 ); 228 shootLCD->setFixedHeight( 16 );
228 hbd->addWidget( shootLCD ); 229 hbd->addWidget( shootLCD );
229 230
230 hbd->addStretch( 1 ); 231 hbd->addStretch( 1 );
231 232
232 label = new QLabel( tr( "Fuel" ), mainWin ); 233 label = new QLabel( tr( "Fuel" ), mainWin );
233 label->setFont( smallFont ); 234 label->setFont( smallFont );
234 label->setFixedWidth( label->sizeHint().width() + 5 ); 235 label->setFixedWidth( label->sizeHint().width() + 5 );
235 label->setPalette( pal ); 236 label->setPalette( pal );
236 hbd->addWidget( label ); 237 hbd->addWidget( label );
237 238
238 powerMeter = new KALedMeter( mainWin ); 239 powerMeter = new KALedMeter( mainWin );
239 powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); 240 powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain );
240 powerMeter->setRange( MAX_POWER_LEVEL ); 241 powerMeter->setRange( MAX_POWER_LEVEL );
241 powerMeter->addColorRange( 10, darkRed ); 242 powerMeter->addColorRange( 10, darkRed );
242 powerMeter->addColorRange( 20, QColor(160, 96, 0) ); 243 powerMeter->addColorRange( 20, QColor(160, 96, 0) );
243 powerMeter->addColorRange( 70, darkGreen ); 244 powerMeter->addColorRange( 70, darkGreen );
244 powerMeter->setCount( 15 ); 245 powerMeter->setCount( 15 );
245 powerMeter->setPalette( pal ); 246 powerMeter->setPalette( pal );
246 powerMeter->setFixedSize( 60, 12 ); 247 powerMeter->setFixedSize( 60, 12 );
247 hbd->addWidget( powerMeter ); 248 hbd->addWidget( powerMeter );
248 249
249 shipsRemain = 3; 250 shipsRemain = 3;
250 showHiscores = FALSE; 251 showHiscores = FALSE;
251 252
252 actions.insert( Qt::Key_Up, Thrust ); 253 actions.insert( Qt::Key_Up, Thrust );
253 actions.insert( Qt::Key_Left, RotateLeft ); 254 actions.insert( Qt::Key_Left, RotateLeft );
254 actions.insert( Qt::Key_Right, RotateRight ); 255 actions.insert( Qt::Key_Right, RotateRight );
255 actions.insert( Qt::Key_Enter, Shoot ); 256 actions.insert( Qt::Key_Enter, Shoot );
256 actions.insert( Qt::Key_Z, Teleport ); 257 actions.insert( Qt::Key_Z, Teleport );
257 actions.insert( Qt::Key_Down, Brake ); 258 actions.insert( Qt::Key_Down, Brake );
258 actions.insert( Qt::Key_P, Pause ); 259 actions.insert( Qt::Key_P, Pause );
259 260
260 261
261 struct utsname name; /* check for embedix kernel running on the zaurus, if 262 struct utsname name; /* check for embedix kernel running on the zaurus, if
262 lineo change string, this break 263 lineo change string, this break
263 */ 264 */
264 if (uname(&name) != -1) { 265 if (uname(&name) != -1) {
265 QString release=name.release; 266 QString release=name.release;
266 if(release.find("embedix",0,TRUE) !=-1) { 267 if(release.find("embedix",0,TRUE) !=-1) {
267 actions.insert( Key_F12, Launch ); 268 actions.insert( Key_F12, Launch );
268 actions.insert( Key_F11, Shield ); 269 actions.insert( Key_F11, Shield );
269 actions.insert( Key_F9, NewGame ); 270 actions.insert( Key_F9, NewGame );
270 } else { 271 } else {
271 // ipaq 272 // ipaq
272 actions.insert( Key_F12, Shoot ); 273 actions.insert( Key_F12, Shoot );
273 actions.insert( Key_F11, Shield ); 274 actions.insert( Key_F11, Shield );
274 actions.insert( Key_F10, Launch ); 275 actions.insert( Key_F10, Launch );
275 actions.insert( Key_F9, NewGame ); 276 actions.insert( Key_F9, NewGame );
276 } 277 }
277 } 278 }
278 279
279// actions.insert( Qt::Key_S, Shield ); 280// actions.insert( Qt::Key_S, Shield );
280// actions.insert( Qt::Key_X, Brake ); 281// actions.insert( Qt::Key_X, Brake );
281// actions.insert( Qt::Key_L, Launch ); 282// actions.insert( Qt::Key_L, Launch );
282 actions.insert( Qt::Key_Space, Shoot ); 283 actions.insert( Qt::Key_Space, Shoot );
283 284
284 view->showText( tr( "Press Calendar to start playing" ), yellow ); 285 view->showText( tr( "Press Calendar to start playing" ), yellow );
285 286
286 setFocusPolicy( StrongFocus ); 287 setFocusPolicy( StrongFocus );
287 288
288 slotNewGame(); 289 slotNewGame();
289} 290}
290 291
291KAstTopLevel::~KAstTopLevel() 292KAstTopLevel::~KAstTopLevel()
292{ 293{
293} 294}
294 295
295void KAstTopLevel::playSound( const char * ) 296void KAstTopLevel::playSound( const char * )
296{ 297{
297} 298}
298 299
299void KAstTopLevel::keyPressEvent( QKeyEvent *event ) 300void KAstTopLevel::keyPressEvent( QKeyEvent *event )
300{ 301{
301 if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) 302 if ( event->isAutoRepeat() || !actions.contains( event->key() ) )
302 { 303 {
303 event->ignore(); 304 event->ignore();
304 return; 305 return;
305 } 306 }
306 307
307 Action a = actions[ event->key() ]; 308 Action a = actions[ event->key() ];
308 309
309 switch ( a ) 310 switch ( a )
310 { 311 {
311 case RotateLeft: 312 case RotateLeft:
312 view->rotateLeft( TRUE ); 313 view->rotateLeft( TRUE );
313 break; 314 break;
314 315
315 case RotateRight: 316 case RotateRight:
316 view->rotateRight( TRUE ); 317 view->rotateRight( TRUE );
317 break; 318 break;
318 319
319 case Thrust: 320 case Thrust:
320 view->thrust( TRUE ); 321 view->thrust( TRUE );
321 break; 322 break;
322 323
323 case Shoot: 324 case Shoot:
324 view->shoot( TRUE ); 325 view->shoot( TRUE );
325 break; 326 break;
326 327
327 case Shield: 328 case Shield:
328 view->setShield( TRUE ); 329 view->setShield( TRUE );
329 break; 330 break;
330 331
331 case Teleport: 332 case Teleport:
332 view->teleport( TRUE ); 333 view->teleport( TRUE );
333 break; 334 break;
334 335
335 case Brake: 336 case Brake:
336 view->brake( TRUE ); 337 view->brake( TRUE );
337 break; 338 break;
338 339
339 default: 340 default:
340 event->ignore(); 341 event->ignore();
341 return; 342 return;
342 } 343 }
343 event->accept(); 344 event->accept();
344} 345}
345 346
346void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) 347void KAstTopLevel::keyReleaseEvent( QKeyEvent *event )
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp
index 3a4d410..6cab700 100644
--- a/noncore/games/qasteroids/view.cpp
+++ b/noncore/games/qasteroids/view.cpp
@@ -1,382 +1,378 @@
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 24
25#include "view.h" 25#include "view.h"
26 26
27#include <qpe/resource.h> 27#include <opie2/oresource.h>
28 28#include <qpe/qpeapplication.h>
29 29
30#include <stdlib.h> 30#include <stdlib.h>
31#include <math.h> 31#include <math.h>
32 32
33#define IMG_BACKGROUND "qasteroids/bg.png" 33#define IMG_BACKGROUND "qasteroids/bg"
34 34
35#define REFRESH_DELAY 33 35#define REFRESH_DELAY 33
36#define SHIP_SPEED 0.3 36#define SHIP_SPEED 0.3
37#define MISSILE_SPEED 10.0 37#define MISSILE_SPEED 10.0
38#define SHIP_STEPS 64 38#define SHIP_STEPS 64
39#define ROTATE_RATE 2 39#define ROTATE_RATE 2
40#define SHIELD_ON_COST 1 40#define SHIELD_ON_COST 1
41#define SHIELD_HIT_COST 30 41#define SHIELD_HIT_COST 30
42#define BRAKE_ON_COST 4 42#define BRAKE_ON_COST 4
43 43
44#define MAX_ROCK_SPEED 2.5 44#define MAX_ROCK_SPEED 2.5
45#define MAX_POWERUP_SPEED 1.5 45#define MAX_POWERUP_SPEED 1.5
46 #define MAX_SHIP_SPEED 8 46 #define MAX_SHIP_SPEED 8
47#define MAX_BRAKES 5 47#define MAX_BRAKES 5
48#define MAX_SHIELDS 5 48#define MAX_SHIELDS 5
49 #define MAX_FIREPOWER 5 49 #define MAX_FIREPOWER 5
50 50
51#define TEXT_SPEED 4 51#define TEXT_SPEED 4
52 52
53#define PI_X_2 6.283185307 53#define PI_X_2 6.283185307
54#ifndef M_PI 54#ifndef M_PI
55#define M_PI 3.141592654 55#define M_PI 3.141592654
56#endif 56#endif
57 57
58struct kas_animations_t 58struct kas_animations_t
59{ 59{
60 int id; 60 int id;
61 const char *path; 61 const char *path;
62 int frames; 62 int frames;
63}; 63};
64 64
65static const kas_animations_t kas_animations [] = 65static const kas_animations_t kas_animations [] =
66{ 66{
67// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 }, 67// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 },
68 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 }, 68 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 },
69 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 }, 69 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 },
70 { ID_SHIP, "ship/ship\%1.png", 32 }, 70 { ID_SHIP, "ship/ship\%1.png", 32 },
71 { ID_MISSILE, "missile/missile.png", 0 }, 71 { ID_MISSILE, "missile/missile.png", 0 },
72 { ID_BIT, "bits/bits\%1.png", 16 }, 72 { ID_BIT, "bits/bits\%1.png", 16 },
73 { ID_EXHAUST, "exhaust/exhaust.png", 0 }, 73 { ID_EXHAUST, "exhaust/exhaust.png", 0 },
74 { ID_ENERGY_POWERUP, "powerups/energy.png", 0 }, 74 { ID_ENERGY_POWERUP, "powerups/energy.png", 0 },
75// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, 75// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
76 { ID_BRAKE_POWERUP, "powerups/brake.png", 0 }, 76 { ID_BRAKE_POWERUP, "powerups/brake.png", 0 },
77 { ID_SHIELD_POWERUP, "powerups/shield.png", 0 }, 77 { ID_SHIELD_POWERUP, "powerups/shield.png", 0 },
78 { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 }, 78 { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 },
79 { ID_SHIELD, "shield/shield\%1.png", 6 }, 79 { ID_SHIELD, "shield/shield\%1.png", 6 },
80 { 0, 0, 0 } 80 { 0, 0, 0 }
81}; 81};
82 82
83 83
84 84
85KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) 85KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
86 : QWidget( parent, name ), 86 : QWidget( parent, name ),
87 field(200, 200), 87 field(200, 200),
88 view(&field,this) 88 view(&field,this)
89{ 89{
90 view.setVScrollBarMode( QScrollView::AlwaysOff ); 90 view.setVScrollBarMode( QScrollView::AlwaysOff );
91 view.setHScrollBarMode( QScrollView::AlwaysOff ); 91 view.setHScrollBarMode( QScrollView::AlwaysOff );
92 rocks.setAutoDelete( TRUE ); 92 rocks.setAutoDelete( TRUE );
93 missiles.setAutoDelete( TRUE ); 93 missiles.setAutoDelete( TRUE );
94 bits.setAutoDelete( TRUE ); 94 bits.setAutoDelete( TRUE );
95 powerups.setAutoDelete( TRUE ); 95 powerups.setAutoDelete( TRUE );
96 exhaust.setAutoDelete( TRUE ); 96 exhaust.setAutoDelete( TRUE );
97 97
98 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) ); 98 field.setBackgroundPixmap( Opie::Core::OResource::loadPixmap(IMG_BACKGROUND) );
99 field.setBackgroundPixmap( pm );
100 99
101 textSprite = new QCanvasText( &field ); 100 textSprite = new QCanvasText( &field );
102 QFont font( "helvetica", 14 ); 101 QFont font( "helvetica", 14 );
103 textSprite->setFont( font ); 102 textSprite->setFont( font );
104 103
105 shield = 0; 104 shield = 0;
106 shieldOn = FALSE; 105 shieldOn = FALSE;
107 refreshRate = REFRESH_DELAY; 106 refreshRate = REFRESH_DELAY;
108 107
109 readSprites(); 108 readSprites();
110 109
111 shieldTimer = new QTimer( this ); 110 shieldTimer = new QTimer( this );
112 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); 111 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
113 mTimerId = -1; 112 mTimerId = -1;
114 113
115 shipPower = MAX_POWER_LEVEL; 114 shipPower = MAX_POWER_LEVEL;
116 vitalsChanged = TRUE; 115 vitalsChanged = TRUE;
117 can_destroy_powerups = FALSE; 116 can_destroy_powerups = FALSE;
118 117
119 mPaused = TRUE; 118 mPaused = TRUE;
120} 119}
121 120
122// - - - 121// - - -
123 122
124KAsteroidsView::~KAsteroidsView() 123KAsteroidsView::~KAsteroidsView()
125{ 124{
126} 125}
127 126
128// - - - 127// - - -
129 128
130void KAsteroidsView::reset() 129void KAsteroidsView::reset()
131{ 130{
132 rocks.clear(); 131 rocks.clear();
133 missiles.clear(); 132 missiles.clear();
134 bits.clear(); 133 bits.clear();
135 powerups.clear(); 134 powerups.clear();
136 exhaust.clear(); 135 exhaust.clear();
137 136
138 shotsFired = 0; 137 shotsFired = 0;
139 shotsHit = 0; 138 shotsHit = 0;
140 139
141 rockSpeed = 1.0; 140 rockSpeed = 1.0;
142 powerupSpeed = 1.0; 141 powerupSpeed = 1.0;
143 mFrameNum = 0; 142 mFrameNum = 0;
144 mPaused = FALSE; 143 mPaused = FALSE;
145 144
146 ship->hide(); 145 ship->hide();
147 shield->hide(); 146 shield->hide();
148/* 147/*
149 if ( mTimerId >= 0 ) { 148 if ( mTimerId >= 0 ) {
150 killTimer( mTimerId ); 149 killTimer( mTimerId );
151 mTimerId = -1; 150 mTimerId = -1;
152 } 151 }
153*/ 152*/
154} 153}
155 154
156// - -- 155// - --
157 156
158void KAsteroidsView::newGame() 157void KAsteroidsView::newGame()
159{ 158{
160 if ( shieldOn ) 159 if ( shieldOn )
161 { 160 {
162 shield->hide(); 161 shield->hide();
163 shieldOn = FALSE; 162 shieldOn = FALSE;
164 } 163 }
165 reset(); 164 reset();
166 if ( mTimerId < 0 ) 165 if ( mTimerId < 0 )
167 mTimerId = startTimer( REFRESH_DELAY ); 166 mTimerId = startTimer( REFRESH_DELAY );
168 emit updateVitals(); 167 emit updateVitals();
169} 168}
170 169
171// - - - 170// - - -
172 171
173void KAsteroidsView::endGame() 172void KAsteroidsView::endGame()
174{ 173{
175} 174}
176 175
177void KAsteroidsView::pause( bool p ) 176void KAsteroidsView::pause( bool p )
178{ 177{
179 if ( !mPaused && p ) { 178 if ( !mPaused && p ) {
180 if ( mTimerId >= 0 ) { 179 if ( mTimerId >= 0 ) {
181 killTimer( mTimerId ); 180 killTimer( mTimerId );
182 mTimerId = -1; 181 mTimerId = -1;
183 } 182 }
184 } else if ( mPaused && !p ) 183 } else if ( mPaused && !p )
185 mTimerId = startTimer( REFRESH_DELAY ); 184 mTimerId = startTimer( REFRESH_DELAY );
186 mPaused = p; 185 mPaused = p;
187} 186}
188 187
189// - - - 188// - - -
190 189
191void KAsteroidsView::newShip() 190void KAsteroidsView::newShip()
192{ 191{
193 ship->move( field.width()/2, field.height()/2, 0 ); 192 ship->move( field.width()/2, field.height()/2, 0 );
194 shield->move( field.width()/2, field.height()/2, 0 ); 193 shield->move( field.width()/2, field.height()/2, 0 );
195 ship->setVelocity( 0.0, 0.0 ); 194 ship->setVelocity( 0.0, 0.0 );
196 shipDx = 0; 195 shipDx = 0;
197 shipDy = 0; 196 shipDy = 0;
198 shipAngle = 0; 197 shipAngle = 0;
199 rotateL = FALSE; 198 rotateL = FALSE;
200 rotateR = FALSE; 199 rotateR = FALSE;
201 thrustShip = FALSE; 200 thrustShip = FALSE;
202 shootShip = FALSE; 201 shootShip = FALSE;
203 brakeShip = FALSE; 202 brakeShip = FALSE;
204 teleportShip = FALSE; 203 teleportShip = FALSE;
205 shieldOn = TRUE; 204 shieldOn = TRUE;
206 shootDelay = 0; 205 shootDelay = 0;
207 shipPower = MAX_POWER_LEVEL; 206 shipPower = MAX_POWER_LEVEL;
208 rotateRate = ROTATE_RATE; 207 rotateRate = ROTATE_RATE;
209 rotateSlow = 0; 208 rotateSlow = 0;
210 209
211 mBrakeCount = 0; 210 mBrakeCount = 0;
212 mTeleportCount = 0; 211 mTeleportCount = 0;
213 mShootCount = 0; 212 mShootCount = 0;
214 213
215 ship->show(); 214 ship->show();
216 shield->show(); 215 shield->show();
217 mShieldCount = 1; // just in case the ship appears on a rock. 216 mShieldCount = 1; // just in case the ship appears on a rock.
218 shieldTimer->start( 1000, TRUE ); 217 shieldTimer->start( 1000, TRUE );
219} 218}
220 219
221void KAsteroidsView::setShield( bool s ) 220void KAsteroidsView::setShield( bool s )
222{ 221{
223 if ( shieldTimer->isActive() && !s ) { 222 if ( shieldTimer->isActive() && !s ) {
224 shieldTimer->stop(); 223 shieldTimer->stop();
225 hideShield(); 224 hideShield();
226 } else { 225 } else {
227 shieldOn = s && mShieldCount; 226 shieldOn = s && mShieldCount;
228 } 227 }
229} 228}
230 229
231void KAsteroidsView::brake( bool b ) 230void KAsteroidsView::brake( bool b )
232{ 231{
233 if ( mBrakeCount ) 232 if ( mBrakeCount )
234 { 233 {
235 if ( brakeShip && !b ) 234 if ( brakeShip && !b )
236 { 235 {
237 rotateL = FALSE; 236 rotateL = FALSE;
238 rotateR = FALSE; 237 rotateR = FALSE;
239 thrustShip = FALSE; 238 thrustShip = FALSE;
240 rotateRate = ROTATE_RATE; 239 rotateRate = ROTATE_RATE;
241 } 240 }
242 241
243 brakeShip = b; 242 brakeShip = b;
244 } 243 }
245} 244}
246 245
247// - - - 246// - - -
248 247
249void KAsteroidsView::readSprites() 248void KAsteroidsView::readSprites()
250{ 249{
251 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND ); 250 QString sprites_prefix = QPEApplication::qpeDir() + "pics/qasteroids";
252 int sep = sprites_prefix.findRev( "/" );
253
254 sprites_prefix.truncate( sep );
255 251
256 int i = 0; 252 int i = 0;
257 while ( kas_animations[i].id ) 253 while ( kas_animations[i].id )
258 { 254 {
259 animation.insert( kas_animations[i].id, 255 animation.insert( kas_animations[i].id,
260 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path, 256 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path,
261 kas_animations[i].frames ) ); 257 kas_animations[i].frames ) );
262 i++; 258 i++;
263 } 259 }
264 260
265 ship = new QCanvasSprite( animation[ID_SHIP], &field ); 261 ship = new QCanvasSprite( animation[ID_SHIP], &field );
266 ship->hide(); 262 ship->hide();
267 263
268 shield = new KShield( animation[ID_SHIELD], &field ); 264 shield = new KShield( animation[ID_SHIELD], &field );
269 shield->hide(); 265 shield->hide();
270} 266}
271 267
272// - - - 268// - - -
273 269
274void KAsteroidsView::addRocks( int num ) 270void KAsteroidsView::addRocks( int num )
275{ 271{
276 for ( int i = 0; i < num; i++ ) 272 for ( int i = 0; i < num; i++ )
277 { 273 {
278 KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field, 274 KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field,
279 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); 275 ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
280 double dx = (2.0 - randDouble()*4.0) * rockSpeed; 276 double dx = (2.0 - randDouble()*4.0) * rockSpeed;
281 double dy = (2.0 - randDouble()*4.0) * rockSpeed; 277 double dy = (2.0 - randDouble()*4.0) * rockSpeed;
282 rock->setVelocity( dx, dy ); 278 rock->setVelocity( dx, dy );
283 rock->setFrame( randInt( rock->frameCount() ) ); 279 rock->setFrame( randInt( rock->frameCount() ) );
284 if ( dx > 0 ) 280 if ( dx > 0 )
285 { 281 {
286 if ( dy > 0 ) 282 if ( dy > 0 )
287 rock->move( 5, 5, 0 ); 283 rock->move( 5, 5, 0 );
288 else 284 else
289 rock->move( 5, field.height() - 25, 0 ); 285 rock->move( 5, field.height() - 25, 0 );
290 } 286 }
291 else 287 else
292 { 288 {
293 if ( dy > 0 ) 289 if ( dy > 0 )
294 rock->move( field.width() - 25, 5, 0 ); 290 rock->move( field.width() - 25, 5, 0 );
295 else 291 else
296 rock->move( field.width() - 25, field.height() - 25, 0 ); 292 rock->move( field.width() - 25, field.height() - 25, 0 );
297 } 293 }
298 rock->show( ); 294 rock->show( );
299 rocks.append( rock ); 295 rocks.append( rock );
300 } 296 }
301} 297}
302 298
303// - - - 299// - - -
304 300
305void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) 301void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll )
306{ 302{
307 textSprite->setTextFlags( AlignLeft | AlignVCenter ); 303 textSprite->setTextFlags( AlignLeft | AlignVCenter );
308 textSprite->setText( text ); 304 textSprite->setText( text );
309 textSprite->setColor( color ); 305 textSprite->setColor( color );
310 306
311 if ( scroll ) { 307 if ( scroll ) {
312 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, 308 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
313 -textSprite->boundingRect().height() ); 309 -textSprite->boundingRect().height() );
314 textDy = TEXT_SPEED; 310 textDy = TEXT_SPEED;
315 } else { 311 } else {
316 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, 312 textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
317 (field.height()-textSprite->boundingRect().height()) / 2 ); 313 (field.height()-textSprite->boundingRect().height()) / 2 );
318 textDy = 0; 314 textDy = 0;
319 } 315 }
320 textSprite->show(); 316 textSprite->show();
321} 317}
322 318
323// - - - 319// - - -
324 320
325void KAsteroidsView::hideText() 321void KAsteroidsView::hideText()
326{ 322{
327 textDy = -TEXT_SPEED; 323 textDy = -TEXT_SPEED;
328} 324}
329 325
330// - - - 326// - - -
331 327
332void KAsteroidsView::resizeEvent(QResizeEvent* event) 328void KAsteroidsView::resizeEvent(QResizeEvent* event)
333{ 329{
334 QWidget::resizeEvent(event); 330 QWidget::resizeEvent(event);
335 field.resize(width()-4, height()-4); 331 field.resize(width()-4, height()-4);
336 view.resize(width(),height()); 332 view.resize(width(),height());
337} 333}
338 334
339// - - - 335// - - -
340 336
341void KAsteroidsView::timerEvent( QTimerEvent * ) 337void KAsteroidsView::timerEvent( QTimerEvent * )
342{ 338{
343 field.advance(); 339 field.advance();
344 340
345 QCanvasSprite *rock; 341 QCanvasSprite *rock;
346 342
347 // move rocks forward 343 // move rocks forward
348 for ( rock = rocks.first(); rock; rock = rocks.next() ) { 344 for ( rock = rocks.first(); rock; rock = rocks.next() ) {
349 ((KRock *)rock)->nextFrame(); 345 ((KRock *)rock)->nextFrame();
350 wrapSprite( rock ); 346 wrapSprite( rock );
351 } 347 }
352 348
353 wrapSprite( ship ); 349 wrapSprite( ship );
354 350
355 // check for missile collision with rocks. 351 // check for missile collision with rocks.
356 processMissiles(); 352 processMissiles();
357 353
358 // these are generated when a ship explodes 354 // these are generated when a ship explodes
359 for ( KBit *bit = bits.first(); bit; bit = bits.next() ) 355 for ( KBit *bit = bits.first(); bit; bit = bits.next() )
360 { 356 {
361 if ( bit->expired() ) 357 if ( bit->expired() )
362 { 358 {
363 bits.removeRef( bit ); 359 bits.removeRef( bit );
364 } 360 }
365 else 361 else
366 { 362 {
367 bit->growOlder(); 363 bit->growOlder();
368 bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); 364 bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() );
369 } 365 }
370 } 366 }
371 367
372 for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) 368 for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() )
373 exhaust.removeRef( e ); 369 exhaust.removeRef( e );
374 370
375 // move / rotate ship. 371 // move / rotate ship.
376 // check for collision with a rock. 372 // check for collision with a rock.
377 processShip(); 373 processShip();
378 374
379 // move powerups and check for collision with player and missiles 375 // move powerups and check for collision with player and missiles
380 processPowerups(); 376 processPowerups();
381 377
382 if ( textSprite->visible() ) 378 if ( textSprite->visible() )