summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-03 13:01:51 (UTC)
committer sandman <sandman>2002-10-03 13:01:51 (UTC)
commitee864e9e055fd23778a8e5dd3c35e3a29cded368 (patch) (unidiff)
tree4362efd44484c1f9f56104b46fab06e1e51af125
parentf254ef08b354327d70d80690eff84dda15e592fc (diff)
downloadopie-ee864e9e055fd23778a8e5dd3c35e3a29cded368.zip
opie-ee864e9e055fd23778a8e5dd3c35e3a29cded368.tar.gz
opie-ee864e9e055fd23778a8e5dd3c35e3a29cded368.tar.bz2
TT fixed a bug in QCanvasPixmapArray in 2.3.4 and qasteroids relied on the
buggy behaviour
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/qasteroids/view.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp
index ef08343..448a54a 100644
--- a/noncore/games/qasteroids/view.cpp
+++ b/noncore/games/qasteroids/view.cpp
@@ -1,272 +1,272 @@
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 <qpe/resource.h>
28 28
29#include <qapplication.h> 29#include <qapplication.h>
30#include <qkeycode.h> 30#include <qkeycode.h>
31#include <qaccel.h> 31#include <qaccel.h>
32 32
33#include <stdlib.h> 33#include <stdlib.h>
34#include <math.h> 34#include <math.h>
35 35
36#define IMG_BACKGROUND "qasteroids/bg.png" 36#define IMG_BACKGROUND "qasteroids/bg.png"
37 37
38#define REFRESH_DELAY 33 38#define REFRESH_DELAY 33
39#define SHIP_SPEED 0.3 39#define SHIP_SPEED 0.3
40#define MISSILE_SPEED 10.0 40#define MISSILE_SPEED 10.0
41#define SHIP_STEPS 64 41#define SHIP_STEPS 64
42#define ROTATE_RATE 2 42#define ROTATE_RATE 2
43#define SHIELD_ON_COST 1 43#define SHIELD_ON_COST 1
44#define SHIELD_HIT_COST 30 44#define SHIELD_HIT_COST 30
45#define BRAKE_ON_COST 4 45#define BRAKE_ON_COST 4
46 46
47#define MAX_ROCK_SPEED 2.5 47#define MAX_ROCK_SPEED 2.5
48#define MAX_POWERUP_SPEED 1.5 48#define MAX_POWERUP_SPEED 1.5
49 #define MAX_SHIP_SPEED 8 49 #define MAX_SHIP_SPEED 8
50#define MAX_BRAKES 5 50#define MAX_BRAKES 5
51#define MAX_SHIELDS 5 51#define MAX_SHIELDS 5
52 #define MAX_FIREPOWER 5 52 #define MAX_FIREPOWER 5
53 53
54#define TEXT_SPEED 4 54#define TEXT_SPEED 4
55 55
56#define PI_X_2 6.283185307 56#define PI_X_2 6.283185307
57#ifndef M_PI 57#ifndef M_PI
58#define M_PI 3.141592654 58#define M_PI 3.141592654
59#endif 59#endif
60 60
61struct 61struct
62{ 62{
63 int id; 63 int id;
64 const char *path; 64 const char *path;
65 int frames; 65 int frames;
66} 66}
67kas_animations [] = 67kas_animations [] =
68{ 68{
69// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 }, 69// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 },
70 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 }, 70 { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 },
71 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 }, 71 { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 },
72 { ID_SHIP, "ship/ship\%1.png", 32 }, 72 { ID_SHIP, "ship/ship\%1.png", 32 },
73 { ID_MISSILE, "missile/missile.png", 1 }, 73 { ID_MISSILE, "missile/missile.png", 0 },
74 { ID_BIT, "bits/bits\%1.png", 16 }, 74 { ID_BIT, "bits/bits\%1.png", 16 },
75 { ID_EXHAUST, "exhaust/exhaust.png", 1 }, 75 { ID_EXHAUST, "exhaust/exhaust.png", 0 },
76 { ID_ENERGY_POWERUP, "powerups/energy.png", 1 }, 76 { ID_ENERGY_POWERUP, "powerups/energy.png", 0 },
77// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, 77// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
78 { ID_BRAKE_POWERUP, "powerups/brake.png", 1 }, 78 { ID_BRAKE_POWERUP, "powerups/brake.png", 0 },
79 { ID_SHIELD_POWERUP, "powerups/shield.png", 1 }, 79 { ID_SHIELD_POWERUP, "powerups/shield.png", 0 },
80 { ID_SHOOT_POWERUP, "powerups/shoot.png", 1 }, 80 { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 },
81 { ID_SHIELD, "shield/shield\%1.png", 6 }, 81 { ID_SHIELD, "shield/shield\%1.png", 6 },
82 { 0, 0, 0 } 82 { 0, 0, 0 }
83}; 83};
84 84
85 85
86 86
87KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) 87KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
88 : QWidget( parent, name ), 88 : QWidget( parent, name ),
89 field(200, 200), 89 field(200, 200),
90 view(&field,this) 90 view(&field,this)
91{ 91{
92 view.setVScrollBarMode( QScrollView::AlwaysOff ); 92 view.setVScrollBarMode( QScrollView::AlwaysOff );
93 view.setHScrollBarMode( QScrollView::AlwaysOff ); 93 view.setHScrollBarMode( QScrollView::AlwaysOff );
94 rocks.setAutoDelete( TRUE ); 94 rocks.setAutoDelete( TRUE );
95 missiles.setAutoDelete( TRUE ); 95 missiles.setAutoDelete( TRUE );
96 bits.setAutoDelete( TRUE ); 96 bits.setAutoDelete( TRUE );
97 powerups.setAutoDelete( TRUE ); 97 powerups.setAutoDelete( TRUE );
98 exhaust.setAutoDelete( TRUE ); 98 exhaust.setAutoDelete( TRUE );
99 99
100 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) ); 100 QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) );
101 field.setBackgroundPixmap( pm ); 101 field.setBackgroundPixmap( pm );
102 102
103 textSprite = new QCanvasText( &field ); 103 textSprite = new QCanvasText( &field );
104 QFont font( "helvetica", 14 ); 104 QFont font( "helvetica", 14 );
105 textSprite->setFont( font ); 105 textSprite->setFont( font );
106 106
107 shield = 0; 107 shield = 0;
108 shieldOn = FALSE; 108 shieldOn = FALSE;
109 refreshRate = REFRESH_DELAY; 109 refreshRate = REFRESH_DELAY;
110 110
111 readSprites(); 111 readSprites();
112 112
113 shieldTimer = new QTimer( this ); 113 shieldTimer = new QTimer( this );
114 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); 114 connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
115 mTimerId = -1; 115 mTimerId = -1;
116 116
117 shipPower = MAX_POWER_LEVEL; 117 shipPower = MAX_POWER_LEVEL;
118 vitalsChanged = TRUE; 118 vitalsChanged = TRUE;
119 can_destroy_powerups = FALSE; 119 can_destroy_powerups = FALSE;
120 120
121 mPaused = TRUE; 121 mPaused = TRUE;
122} 122}
123 123
124// - - - 124// - - -
125 125
126KAsteroidsView::~KAsteroidsView() 126KAsteroidsView::~KAsteroidsView()
127{ 127{
128} 128}
129 129
130// - - - 130// - - -
131 131
132void KAsteroidsView::reset() 132void KAsteroidsView::reset()
133{ 133{
134 rocks.clear(); 134 rocks.clear();
135 missiles.clear(); 135 missiles.clear();
136 bits.clear(); 136 bits.clear();
137 powerups.clear(); 137 powerups.clear();
138 exhaust.clear(); 138 exhaust.clear();
139 139
140 shotsFired = 0; 140 shotsFired = 0;
141 shotsHit = 0; 141 shotsHit = 0;
142 142
143 rockSpeed = 1.0; 143 rockSpeed = 1.0;
144 powerupSpeed = 1.0; 144 powerupSpeed = 1.0;
145 mFrameNum = 0; 145 mFrameNum = 0;
146 mPaused = FALSE; 146 mPaused = FALSE;
147 147
148 ship->hide(); 148 ship->hide();
149 shield->hide(); 149 shield->hide();
150/* 150/*
151 if ( mTimerId >= 0 ) { 151 if ( mTimerId >= 0 ) {
152 killTimer( mTimerId ); 152 killTimer( mTimerId );
153 mTimerId = -1; 153 mTimerId = -1;
154 } 154 }
155*/ 155*/
156} 156}
157 157
158// - -- 158// - --
159 159
160void KAsteroidsView::newGame() 160void KAsteroidsView::newGame()
161{ 161{
162 if ( shieldOn ) 162 if ( shieldOn )
163 { 163 {
164 shield->hide(); 164 shield->hide();
165 shieldOn = FALSE; 165 shieldOn = FALSE;
166 } 166 }
167 reset(); 167 reset();
168 if ( mTimerId < 0 ) 168 if ( mTimerId < 0 )
169 mTimerId = startTimer( REFRESH_DELAY ); 169 mTimerId = startTimer( REFRESH_DELAY );
170 emit updateVitals(); 170 emit updateVitals();
171} 171}
172 172
173// - - - 173// - - -
174 174
175void KAsteroidsView::endGame() 175void KAsteroidsView::endGame()
176{ 176{
177} 177}
178 178
179void KAsteroidsView::pause( bool p ) 179void KAsteroidsView::pause( bool p )
180{ 180{
181 if ( !mPaused && p ) { 181 if ( !mPaused && p ) {
182 if ( mTimerId >= 0 ) { 182 if ( mTimerId >= 0 ) {
183 killTimer( mTimerId ); 183 killTimer( mTimerId );
184 mTimerId = -1; 184 mTimerId = -1;
185 } 185 }
186 } else if ( mPaused && !p ) 186 } else if ( mPaused && !p )
187 mTimerId = startTimer( REFRESH_DELAY ); 187 mTimerId = startTimer( REFRESH_DELAY );
188 mPaused = p; 188 mPaused = p;
189} 189}
190 190
191// - - - 191// - - -
192 192
193void KAsteroidsView::newShip() 193void KAsteroidsView::newShip()
194{ 194{
195 ship->move( field.width()/2, field.height()/2, 0 ); 195 ship->move( field.width()/2, field.height()/2, 0 );
196 shield->move( field.width()/2, field.height()/2, 0 ); 196 shield->move( field.width()/2, field.height()/2, 0 );
197 ship->setVelocity( 0.0, 0.0 ); 197 ship->setVelocity( 0.0, 0.0 );
198 shipDx = 0; 198 shipDx = 0;
199 shipDy = 0; 199 shipDy = 0;
200 shipAngle = 0; 200 shipAngle = 0;
201 rotateL = FALSE; 201 rotateL = FALSE;
202 rotateR = FALSE; 202 rotateR = FALSE;
203 thrustShip = FALSE; 203 thrustShip = FALSE;
204 shootShip = FALSE; 204 shootShip = FALSE;
205 brakeShip = FALSE; 205 brakeShip = FALSE;
206 teleportShip = FALSE; 206 teleportShip = FALSE;
207 shieldOn = TRUE; 207 shieldOn = TRUE;
208 shootDelay = 0; 208 shootDelay = 0;
209 shipPower = MAX_POWER_LEVEL; 209 shipPower = MAX_POWER_LEVEL;
210 rotateRate = ROTATE_RATE; 210 rotateRate = ROTATE_RATE;
211 rotateSlow = 0; 211 rotateSlow = 0;
212 212
213 mBrakeCount = 0; 213 mBrakeCount = 0;
214 mTeleportCount = 0; 214 mTeleportCount = 0;
215 mShootCount = 0; 215 mShootCount = 0;
216 216
217 ship->show(); 217 ship->show();
218 shield->show(); 218 shield->show();
219 mShieldCount = 1; // just in case the ship appears on a rock. 219 mShieldCount = 1; // just in case the ship appears on a rock.
220 shieldTimer->start( 1000, TRUE ); 220 shieldTimer->start( 1000, TRUE );
221} 221}
222 222
223void KAsteroidsView::setShield( bool s ) 223void KAsteroidsView::setShield( bool s )
224{ 224{
225 if ( shieldTimer->isActive() && !s ) { 225 if ( shieldTimer->isActive() && !s ) {
226 shieldTimer->stop(); 226 shieldTimer->stop();
227 hideShield(); 227 hideShield();
228 } else { 228 } else {
229 shieldOn = s && mShieldCount; 229 shieldOn = s && mShieldCount;
230 } 230 }
231} 231}
232 232
233void KAsteroidsView::brake( bool b ) 233void KAsteroidsView::brake( bool b )
234{ 234{
235 if ( mBrakeCount ) 235 if ( mBrakeCount )
236 { 236 {
237 if ( brakeShip && !b ) 237 if ( brakeShip && !b )
238 { 238 {
239 rotateL = FALSE; 239 rotateL = FALSE;
240 rotateR = FALSE; 240 rotateR = FALSE;
241 thrustShip = FALSE; 241 thrustShip = FALSE;
242 rotateRate = ROTATE_RATE; 242 rotateRate = ROTATE_RATE;
243 } 243 }
244 244
245 brakeShip = b; 245 brakeShip = b;
246 } 246 }
247} 247}
248 248
249// - - - 249// - - -
250 250
251void KAsteroidsView::readSprites() 251void KAsteroidsView::readSprites()
252{ 252{
253 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND ); 253 QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND );
254 int sep = sprites_prefix.findRev( "/" ); 254 int sep = sprites_prefix.findRev( "/" );
255 255
256 sprites_prefix.truncate( sep ); 256 sprites_prefix.truncate( sep );
257 257
258 int i = 0; 258 int i = 0;
259 while ( kas_animations[i].id ) 259 while ( kas_animations[i].id )
260 { 260 {
261 animation.insert( kas_animations[i].id, 261 animation.insert( kas_animations[i].id,
262 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path, 262 new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path,
263 kas_animations[i].frames ) ); 263 kas_animations[i].frames ) );
264 i++; 264 i++;
265 } 265 }
266 266
267 ship = new QCanvasSprite( animation[ID_SHIP], &field ); 267 ship = new QCanvasSprite( animation[ID_SHIP], &field );
268 ship->hide(); 268 ship->hide();
269 269
270 shield = new KShield( animation[ID_SHIELD], &field ); 270 shield = new KShield( animation[ID_SHIELD], &field );
271 shield->hide(); 271 shield->hide();
272} 272}