-rw-r--r-- | noncore/games/qasteroids/toplevel.cpp | 9 | ||||
-rw-r--r-- | noncore/games/qasteroids/view.cpp | 14 |
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,533 +1,534 @@ | |||
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 | ||
43 | struct SLevel | 44 | struct 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 | ||
51 | SLevel levels[MAX_LEVELS] = | 52 | SLevel 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 | ||
70 | const char *soundEvents[] = | 71 | const char *soundEvents[] = |
71 | { | 72 | { |
72 | "ShipDestroyed", | 73 | "ShipDestroyed", |
73 | "RockDestroyed", | 74 | "RockDestroyed", |
74 | 0 | 75 | 0 |
75 | }; | 76 | }; |
76 | 77 | ||
77 | const char *soundDefaults[] = | 78 | const 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 | ||
85 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *_name, WFlags fl ) | 86 | KAstTopLevel::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 | ||
291 | KAstTopLevel::~KAstTopLevel() | 292 | KAstTopLevel::~KAstTopLevel() |
292 | { | 293 | { |
293 | } | 294 | } |
294 | 295 | ||
295 | void KAstTopLevel::playSound( const char * ) | 296 | void KAstTopLevel::playSound( const char * ) |
296 | { | 297 | { |
297 | } | 298 | } |
298 | 299 | ||
299 | void KAstTopLevel::keyPressEvent( QKeyEvent *event ) | 300 | void 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 | ||
346 | void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) | 347 | void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) |
347 | { | 348 | { |
348 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) | 349 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
349 | { | 350 | { |
350 | event->ignore(); | 351 | event->ignore(); |
351 | return; | 352 | return; |
352 | } | 353 | } |
353 | 354 | ||
354 | Action a = actions[ event->key() ]; | 355 | Action a = actions[ event->key() ]; |
355 | 356 | ||
356 | switch ( a ) | 357 | switch ( a ) |
357 | { | 358 | { |
358 | case RotateLeft: | 359 | case RotateLeft: |
359 | view->rotateLeft( FALSE ); | 360 | view->rotateLeft( FALSE ); |
360 | break; | 361 | break; |
361 | 362 | ||
362 | case RotateRight: | 363 | case RotateRight: |
363 | view->rotateRight( FALSE ); | 364 | view->rotateRight( FALSE ); |
364 | break; | 365 | break; |
365 | 366 | ||
366 | case Thrust: | 367 | case Thrust: |
367 | view->thrust( FALSE ); | 368 | view->thrust( FALSE ); |
368 | break; | 369 | break; |
369 | 370 | ||
370 | case Shoot: | 371 | case Shoot: |
371 | view->shoot( FALSE ); | 372 | view->shoot( FALSE ); |
372 | break; | 373 | break; |
373 | 374 | ||
374 | case Brake: | 375 | case Brake: |
375 | view->brake( FALSE ); | 376 | view->brake( FALSE ); |
376 | break; | 377 | break; |
377 | 378 | ||
378 | case Shield: | 379 | case Shield: |
379 | view->setShield( FALSE ); | 380 | view->setShield( FALSE ); |
380 | break; | 381 | break; |
381 | 382 | ||
382 | case Teleport: | 383 | case Teleport: |
383 | view->teleport( FALSE ); | 384 | view->teleport( FALSE ); |
384 | break; | 385 | break; |
385 | 386 | ||
386 | case Launch: | 387 | case Launch: |
387 | if ( waitShip ) | 388 | if ( waitShip ) |
388 | { | 389 | { |
389 | view->newShip(); | 390 | view->newShip(); |
390 | waitShip = FALSE; | 391 | waitShip = FALSE; |
391 | view->hideText(); | 392 | view->hideText(); |
392 | } | 393 | } |
393 | else | 394 | else |
394 | { | 395 | { |
395 | event->ignore(); | 396 | event->ignore(); |
396 | return; | 397 | return; |
397 | } | 398 | } |
398 | break; | 399 | break; |
399 | 400 | ||
400 | case NewGame: | 401 | case NewGame: |
401 | slotNewGame(); | 402 | slotNewGame(); |
402 | break; | 403 | break; |
403 | /* | 404 | /* |
404 | case Pause: | 405 | case Pause: |
405 | { | 406 | { |
406 | view->pause( TRUE ); | 407 | view->pause( TRUE ); |
407 | QMessageBox::information( this, | 408 | QMessageBox::information( this, |
408 | tr("KAsteroids is paused"), | 409 | tr("KAsteroids is paused"), |
409 | tr("Paused") ); | 410 | tr("Paused") ); |
410 | view->pause( FALSE ); | 411 | view->pause( FALSE ); |
411 | } | 412 | } |
412 | break; | 413 | break; |
413 | */ | 414 | */ |
414 | default: | 415 | default: |
415 | event->ignore(); | 416 | event->ignore(); |
416 | return; | 417 | return; |
417 | } | 418 | } |
418 | 419 | ||
419 | event->accept(); | 420 | event->accept(); |
420 | } | 421 | } |
421 | 422 | ||
422 | void KAstTopLevel::showEvent( QShowEvent *e ) | 423 | void KAstTopLevel::showEvent( QShowEvent *e ) |
423 | { | 424 | { |
424 | QMainWindow::showEvent( e ); | 425 | QMainWindow::showEvent( e ); |
425 | view->pause( FALSE ); | 426 | view->pause( FALSE ); |
426 | setFocus(); | 427 | setFocus(); |
427 | } | 428 | } |
428 | 429 | ||
429 | void KAstTopLevel::hideEvent( QHideEvent *e ) | 430 | void KAstTopLevel::hideEvent( QHideEvent *e ) |
430 | { | 431 | { |
431 | QMainWindow::hideEvent( e ); | 432 | QMainWindow::hideEvent( e ); |
432 | view->pause( TRUE ); | 433 | view->pause( TRUE ); |
433 | } | 434 | } |
434 | 435 | ||
435 | void KAstTopLevel::focusInEvent( QFocusEvent * ) | 436 | void KAstTopLevel::focusInEvent( QFocusEvent * ) |
436 | { | 437 | { |
437 | view->pause( FALSE ); | 438 | view->pause( FALSE ); |
438 | setFocus(); | 439 | setFocus(); |
439 | } | 440 | } |
440 | 441 | ||
441 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) | 442 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) |
442 | { | 443 | { |
443 | view->pause( TRUE ); | 444 | view->pause( TRUE ); |
444 | } | 445 | } |
445 | 446 | ||
446 | void KAstTopLevel::slotNewGame() | 447 | void KAstTopLevel::slotNewGame() |
447 | { | 448 | { |
448 | shipsRemain = 3; | 449 | shipsRemain = 3; |
449 | score = 0; | 450 | score = 0; |
450 | scoreLCD->display( 0 ); | 451 | scoreLCD->display( 0 ); |
451 | level = 0; | 452 | level = 0; |
452 | levelLCD->display( level+1 ); | 453 | levelLCD->display( level+1 ); |
453 | shipsLCD->display( shipsRemain-1 ); | 454 | shipsLCD->display( shipsRemain-1 ); |
454 | view->newGame(); | 455 | view->newGame(); |
455 | view->setRockSpeed( levels[0].rockSpeed ); | 456 | view->setRockSpeed( levels[0].rockSpeed ); |
456 | view->addRocks( levels[0].nrocks ); | 457 | view->addRocks( levels[0].nrocks ); |
457 | view->newShip(); | 458 | view->newShip(); |
458 | waitShip = FALSE; | 459 | waitShip = FALSE; |
459 | view->hideText(); | 460 | view->hideText(); |
460 | isPaused = FALSE; | 461 | isPaused = FALSE; |
461 | } | 462 | } |
462 | 463 | ||
463 | void KAstTopLevel::slotShipKilled() | 464 | void KAstTopLevel::slotShipKilled() |
464 | { | 465 | { |
465 | shipsRemain--; | 466 | shipsRemain--; |
466 | shipsLCD->display( shipsRemain-1 ); | 467 | shipsLCD->display( shipsRemain-1 ); |
467 | 468 | ||
468 | playSound( "ShipDestroyed" ); | 469 | playSound( "ShipDestroyed" ); |
469 | 470 | ||
470 | if ( shipsRemain > 0 ) | 471 | if ( shipsRemain > 0 ) |
471 | { | 472 | { |
472 | waitShip = TRUE; | 473 | waitShip = TRUE; |
473 | view->showText( tr( "Ship Destroyed.\nPress Contacts/Home key."), yellow ); | 474 | view->showText( tr( "Ship Destroyed.\nPress Contacts/Home key."), yellow ); |
474 | } | 475 | } |
475 | else | 476 | else |
476 | { | 477 | { |
477 | view->endGame(); | 478 | view->endGame(); |
478 | doStats(); | 479 | doStats(); |
479 | } | 480 | } |
480 | } | 481 | } |
481 | 482 | ||
482 | void KAstTopLevel::slotRockHit( int size ) | 483 | void KAstTopLevel::slotRockHit( int size ) |
483 | { | 484 | { |
484 | switch ( size ) | 485 | switch ( size ) |
485 | { | 486 | { |
486 | case 0: | 487 | case 0: |
487 | score += 10; | 488 | score += 10; |
488 | break; | 489 | break; |
489 | 490 | ||
490 | case 1: | 491 | case 1: |
491 | score += 20; | 492 | score += 20; |
492 | break; | 493 | break; |
493 | 494 | ||
494 | default: | 495 | default: |
495 | score += 40; | 496 | score += 40; |
496 | } | 497 | } |
497 | 498 | ||
498 | playSound( "RockDestroyed" ); | 499 | playSound( "RockDestroyed" ); |
499 | 500 | ||
500 | scoreLCD->display( score ); | 501 | scoreLCD->display( score ); |
501 | } | 502 | } |
502 | 503 | ||
503 | void KAstTopLevel::slotRocksRemoved() | 504 | void KAstTopLevel::slotRocksRemoved() |
504 | { | 505 | { |
505 | level++; | 506 | level++; |
506 | 507 | ||
507 | if ( level >= MAX_LEVELS ) | 508 | if ( level >= MAX_LEVELS ) |
508 | level = MAX_LEVELS - 1; | 509 | level = MAX_LEVELS - 1; |
509 | 510 | ||
510 | view->setRockSpeed( levels[level-1].rockSpeed ); | 511 | view->setRockSpeed( levels[level-1].rockSpeed ); |
511 | view->addRocks( levels[level-1].nrocks ); | 512 | view->addRocks( levels[level-1].nrocks ); |
512 | 513 | ||
513 | levelLCD->display( level+1 ); | 514 | levelLCD->display( level+1 ); |
514 | } | 515 | } |
515 | 516 | ||
516 | void KAstTopLevel::doStats() | 517 | void KAstTopLevel::doStats() |
517 | { | 518 | { |
518 | QString r( "0.00" ); | 519 | QString r( "0.00" ); |
519 | if ( view->shots() ) | 520 | if ( view->shots() ) |
520 | r = QString::number( (double)view->hits() / view->shots() * 100.0, | 521 | r = QString::number( (double)view->hits() / view->shots() * 100.0, |
521 | 'g', 2 ); | 522 | 'g', 2 ); |
522 | 523 | ||
523 | view->showText( tr( "Game Over.\nPress Calendar for a new game." ), yellow, FALSE ); | 524 | view->showText( tr( "Game Over.\nPress Calendar for a new game." ), yellow, FALSE ); |
524 | } | 525 | } |
525 | 526 | ||
526 | void KAstTopLevel::slotUpdateVitals() | 527 | void KAstTopLevel::slotUpdateVitals() |
527 | { | 528 | { |
528 | brakesLCD->display( view->brakeCount() ); | 529 | brakesLCD->display( view->brakeCount() ); |
529 | shieldLCD->display( view->shieldCount() ); | 530 | shieldLCD->display( view->shieldCount() ); |
530 | shootLCD->display( view->shootCount() ); | 531 | shootLCD->display( view->shootCount() ); |
531 | // teleportsLCD->display( view->teleportCount() ); | 532 | // teleportsLCD->display( view->teleportCount() ); |
532 | powerMeter->setValue( view->power() ); | 533 | powerMeter->setValue( view->power() ); |
533 | } | 534 | } |
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,882 +1,878 @@ | |||
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 | ||
58 | struct kas_animations_t | 58 | struct 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 | ||
65 | static const kas_animations_t kas_animations [] = | 65 | static 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 | ||
85 | KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) | 85 | KAsteroidsView::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 | ||
124 | KAsteroidsView::~KAsteroidsView() | 123 | KAsteroidsView::~KAsteroidsView() |
125 | { | 124 | { |
126 | } | 125 | } |
127 | 126 | ||
128 | // - - - | 127 | // - - - |
129 | 128 | ||
130 | void KAsteroidsView::reset() | 129 | void 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 | ||
158 | void KAsteroidsView::newGame() | 157 | void 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 | ||
173 | void KAsteroidsView::endGame() | 172 | void KAsteroidsView::endGame() |
174 | { | 173 | { |
175 | } | 174 | } |
176 | 175 | ||
177 | void KAsteroidsView::pause( bool p ) | 176 | void 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 | ||
191 | void KAsteroidsView::newShip() | 190 | void 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 | ||
221 | void KAsteroidsView::setShield( bool s ) | 220 | void 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 | ||
231 | void KAsteroidsView::brake( bool b ) | 230 | void 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 | ||
249 | void KAsteroidsView::readSprites() | 248 | void 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 | ||
274 | void KAsteroidsView::addRocks( int num ) | 270 | void 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 | ||
305 | void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) | 301 | void 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 | ||
325 | void KAsteroidsView::hideText() | 321 | void KAsteroidsView::hideText() |
326 | { | 322 | { |
327 | textDy = -TEXT_SPEED; | 323 | textDy = -TEXT_SPEED; |
328 | } | 324 | } |
329 | 325 | ||
330 | // - - - | 326 | // - - - |
331 | 327 | ||
332 | void KAsteroidsView::resizeEvent(QResizeEvent* event) | 328 | void 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 | ||
341 | void KAsteroidsView::timerEvent( QTimerEvent * ) | 337 | void 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() ) |
383 | { | 379 | { |
384 | if ( textDy < 0 && | 380 | if ( textDy < 0 && |
385 | textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { | 381 | textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { |
386 | textSprite->hide(); | 382 | textSprite->hide(); |
387 | } else { | 383 | } else { |
388 | textSprite->moveBy( 0, textDy ); | 384 | textSprite->moveBy( 0, textDy ); |
389 | } | 385 | } |
390 | if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) | 386 | if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) |
391 | textDy = 0; | 387 | textDy = 0; |
392 | } | 388 | } |
393 | 389 | ||
394 | if ( vitalsChanged && !(mFrameNum % 10) ) { | 390 | if ( vitalsChanged && !(mFrameNum % 10) ) { |
395 | emit updateVitals(); | 391 | emit updateVitals(); |
396 | vitalsChanged = FALSE; | 392 | vitalsChanged = FALSE; |
397 | } | 393 | } |
398 | 394 | ||
399 | mFrameNum++; | 395 | mFrameNum++; |
400 | } | 396 | } |
401 | 397 | ||
402 | void KAsteroidsView::wrapSprite( QCanvasItem *s ) | 398 | void KAsteroidsView::wrapSprite( QCanvasItem *s ) |
403 | { | 399 | { |
404 | int x = int(s->x() + s->boundingRect().width() / 2); | 400 | int x = int(s->x() + s->boundingRect().width() / 2); |
405 | int y = int(s->y() + s->boundingRect().height() / 2); | 401 | int y = int(s->y() + s->boundingRect().height() / 2); |
406 | 402 | ||
407 | if ( x > field.width() ) | 403 | if ( x > field.width() ) |
408 | s->move( s->x() - field.width(), s->y() ); | 404 | s->move( s->x() - field.width(), s->y() ); |
409 | else if ( x < 0 ) | 405 | else if ( x < 0 ) |
410 | s->move( field.width() + s->x(), s->y() ); | 406 | s->move( field.width() + s->x(), s->y() ); |
411 | 407 | ||
412 | if ( y > field.height() ) | 408 | if ( y > field.height() ) |
413 | s->move( s->x(), s->y() - field.height() ); | 409 | s->move( s->x(), s->y() - field.height() ); |
414 | else if ( y < 0 ) | 410 | else if ( y < 0 ) |
415 | s->move( s->x(), field.height() + s->y() ); | 411 | s->move( s->x(), field.height() + s->y() ); |
416 | } | 412 | } |
417 | 413 | ||
418 | // - - - | 414 | // - - - |
419 | 415 | ||
420 | void KAsteroidsView::rockHit( QCanvasItem *hit ) | 416 | void KAsteroidsView::rockHit( QCanvasItem *hit ) |
421 | { | 417 | { |
422 | KPowerup *nPup = 0; | 418 | KPowerup *nPup = 0; |
423 | int rnd = static_cast<int>(randDouble()*30.0) % 30; | 419 | int rnd = static_cast<int>(randDouble()*30.0) % 30; |
424 | switch( rnd ) | 420 | switch( rnd ) |
425 | { | 421 | { |
426 | case 4: | 422 | case 4: |
427 | case 5: | 423 | case 5: |
428 | nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, | 424 | nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, |
429 | ID_ENERGY_POWERUP ); | 425 | ID_ENERGY_POWERUP ); |
430 | break; | 426 | break; |
431 | case 10: | 427 | case 10: |
432 | // nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, | 428 | // nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, |
433 | // ID_TELEPORT_POWERUP ); | 429 | // ID_TELEPORT_POWERUP ); |
434 | break; | 430 | break; |
435 | case 15: | 431 | case 15: |
436 | nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, | 432 | nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, |
437 | ID_BRAKE_POWERUP ); | 433 | ID_BRAKE_POWERUP ); |
438 | break; | 434 | break; |
439 | case 20: | 435 | case 20: |
440 | nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, | 436 | nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, |
441 | ID_SHIELD_POWERUP ); | 437 | ID_SHIELD_POWERUP ); |
442 | break; | 438 | break; |
443 | case 24: | 439 | case 24: |
444 | case 25: | 440 | case 25: |
445 | nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, | 441 | nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, |
446 | ID_SHOOT_POWERUP ); | 442 | ID_SHOOT_POWERUP ); |
447 | break; | 443 | break; |
448 | } | 444 | } |
449 | if ( nPup ) | 445 | if ( nPup ) |
450 | { | 446 | { |
451 | double r = 0.5 - randDouble(); | 447 | double r = 0.5 - randDouble(); |
452 | nPup->move( hit->x(), hit->y(), 0 ); | 448 | nPup->move( hit->x(), hit->y(), 0 ); |
453 | nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); | 449 | nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); |
454 | nPup->show( ); | 450 | nPup->show( ); |
455 | powerups.append( nPup ); | 451 | powerups.append( nPup ); |
456 | } | 452 | } |
457 | 453 | ||
458 | if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) | 454 | if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) |
459 | { | 455 | { |
460 | // break into smaller rocks | 456 | // break into smaller rocks |
461 | double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; | 457 | double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; |
462 | double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; | 458 | double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; |
463 | 459 | ||
464 | double dx = hit->xVelocity(); | 460 | double dx = hit->xVelocity(); |
465 | double dy = hit->yVelocity(); | 461 | double dy = hit->yVelocity(); |
466 | 462 | ||
467 | double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; | 463 | double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; |
468 | if ( dx > maxRockSpeed ) | 464 | if ( dx > maxRockSpeed ) |
469 | dx = maxRockSpeed; | 465 | dx = maxRockSpeed; |
470 | else if ( dx < -maxRockSpeed ) | 466 | else if ( dx < -maxRockSpeed ) |
471 | dx = -maxRockSpeed; | 467 | dx = -maxRockSpeed; |
472 | if ( dy > maxRockSpeed ) | 468 | if ( dy > maxRockSpeed ) |
473 | dy = maxRockSpeed; | 469 | dy = maxRockSpeed; |
474 | else if ( dy < -maxRockSpeed ) | 470 | else if ( dy < -maxRockSpeed ) |
475 | dy = -maxRockSpeed; | 471 | dy = -maxRockSpeed; |
476 | 472 | ||
477 | QCanvasSprite *nrock; | 473 | QCanvasSprite *nrock; |
478 | 474 | ||
479 | for ( int i = 0; i < 4; i++ ) | 475 | for ( int i = 0; i < 4; i++ ) |
480 | { | 476 | { |
481 | double r = rockSpeed/2 - randDouble()*rockSpeed; | 477 | double r = rockSpeed/2 - randDouble()*rockSpeed; |
482 | if ( hit->rtti() == ID_ROCK_LARGE ) | 478 | if ( hit->rtti() == ID_ROCK_LARGE ) |
483 | { | 479 | { |
484 | nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, | 480 | nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, |
485 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); | 481 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); |
486 | emit rockHit( 0 ); | 482 | emit rockHit( 0 ); |
487 | } | 483 | } |
488 | else | 484 | else |
489 | { | 485 | { |
490 | nrock = new KRock( animation[ID_ROCK_SMALL], &field, | 486 | nrock = new KRock( animation[ID_ROCK_SMALL], &field, |
491 | ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); | 487 | ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); |
492 | emit rockHit( 1 ); | 488 | emit rockHit( 1 ); |
493 | } | 489 | } |
494 | 490 | ||
495 | nrock->move( hit->x(), hit->y(), 0 ); | 491 | nrock->move( hit->x(), hit->y(), 0 ); |
496 | nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); | 492 | nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); |
497 | nrock->setFrame( randInt( nrock->frameCount() ) ); | 493 | nrock->setFrame( randInt( nrock->frameCount() ) ); |
498 | nrock->show( ); | 494 | nrock->show( ); |
499 | rocks.append( nrock ); | 495 | rocks.append( nrock ); |
500 | } | 496 | } |
501 | } | 497 | } |
502 | else if ( hit->rtti() == ID_ROCK_SMALL ) | 498 | else if ( hit->rtti() == ID_ROCK_SMALL ) |
503 | emit rockHit( 2 ); | 499 | emit rockHit( 2 ); |
504 | rocks.removeRef( (QCanvasSprite *)hit ); | 500 | rocks.removeRef( (QCanvasSprite *)hit ); |
505 | if ( rocks.count() == 0 ) | 501 | if ( rocks.count() == 0 ) |
506 | emit rocksRemoved(); | 502 | emit rocksRemoved(); |
507 | } | 503 | } |
508 | 504 | ||
509 | void KAsteroidsView::reducePower( int val ) | 505 | void KAsteroidsView::reducePower( int val ) |
510 | { | 506 | { |
511 | shipPower -= val; | 507 | shipPower -= val; |
512 | if ( shipPower <= 0 ) | 508 | if ( shipPower <= 0 ) |
513 | { | 509 | { |
514 | shipPower = 0; | 510 | shipPower = 0; |
515 | thrustShip = FALSE; | 511 | thrustShip = FALSE; |
516 | if ( shieldOn ) | 512 | if ( shieldOn ) |
517 | { | 513 | { |
518 | shieldOn = FALSE; | 514 | shieldOn = FALSE; |
519 | shield->hide(); | 515 | shield->hide(); |
520 | } | 516 | } |
521 | } | 517 | } |
522 | vitalsChanged = TRUE; | 518 | vitalsChanged = TRUE; |
523 | } | 519 | } |
524 | 520 | ||
525 | void KAsteroidsView::addExhaust( double x, double y, double dx, | 521 | void KAsteroidsView::addExhaust( double x, double y, double dx, |
526 | double dy, int count ) | 522 | double dy, int count ) |
527 | { | 523 | { |
528 | for ( int i = 0; i < count; i++ ) | 524 | for ( int i = 0; i < count; i++ ) |
529 | { | 525 | { |
530 | KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); | 526 | KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); |
531 | e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); | 527 | e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); |
532 | e->setVelocity( dx, dy ); | 528 | e->setVelocity( dx, dy ); |
533 | e->show( ); | 529 | e->show( ); |
534 | exhaust.append( e ); | 530 | exhaust.append( e ); |
535 | } | 531 | } |
536 | } | 532 | } |
537 | 533 | ||
538 | void KAsteroidsView::processMissiles() | 534 | void KAsteroidsView::processMissiles() |
539 | { | 535 | { |
540 | KMissile *missile; | 536 | KMissile *missile; |
541 | 537 | ||
542 | // if a missile has hit a rock, remove missile and break rock into smaller | 538 | // if a missile has hit a rock, remove missile and break rock into smaller |
543 | // rocks or remove completely. | 539 | // rocks or remove completely. |
544 | QPtrListIterator<KMissile> it(missiles); | 540 | QPtrListIterator<KMissile> it(missiles); |
545 | 541 | ||
546 | for ( ; it.current(); ++it ) | 542 | for ( ; it.current(); ++it ) |
547 | { | 543 | { |
548 | missile = it.current(); | 544 | missile = it.current(); |
549 | missile->growOlder(); | 545 | missile->growOlder(); |
550 | 546 | ||
551 | if ( missile->expired() ) | 547 | if ( missile->expired() ) |
552 | { | 548 | { |
553 | missiles.removeRef( missile ); | 549 | missiles.removeRef( missile ); |
554 | continue; | 550 | continue; |
555 | } | 551 | } |
556 | 552 | ||
557 | wrapSprite( missile ); | 553 | wrapSprite( missile ); |
558 | 554 | ||
559 | QCanvasItemList hits = missile->collisions( TRUE ); | 555 | QCanvasItemList hits = missile->collisions( TRUE ); |
560 | QCanvasItemList::Iterator hit; | 556 | QCanvasItemList::Iterator hit; |
561 | for ( hit = hits.begin(); hit != hits.end(); ++hit ) | 557 | for ( hit = hits.begin(); hit != hits.end(); ++hit ) |
562 | { | 558 | { |
563 | if ( (*hit)->rtti() >= ID_ROCK_LARGE && | 559 | if ( (*hit)->rtti() >= ID_ROCK_LARGE && |
564 | (*hit)->rtti() <= ID_ROCK_SMALL ) | 560 | (*hit)->rtti() <= ID_ROCK_SMALL ) |
565 | { | 561 | { |
566 | shotsHit++; | 562 | shotsHit++; |
567 | rockHit( *hit ); | 563 | rockHit( *hit ); |
568 | missiles.removeRef( missile ); | 564 | missiles.removeRef( missile ); |
569 | break; | 565 | break; |
570 | } | 566 | } |
571 | } | 567 | } |
572 | } | 568 | } |
573 | } | 569 | } |
574 | 570 | ||
575 | // - - - | 571 | // - - - |
576 | 572 | ||
577 | void KAsteroidsView::processShip() | 573 | void KAsteroidsView::processShip() |
578 | { | 574 | { |
579 | if ( ship->visible() ) | 575 | if ( ship->visible() ) |
580 | { | 576 | { |
581 | if ( shieldOn ) | 577 | if ( shieldOn ) |
582 | { | 578 | { |
583 | shield->show(); | 579 | shield->show(); |
584 | reducePower( SHIELD_ON_COST ); | 580 | reducePower( SHIELD_ON_COST ); |
585 | static int sf = 0; | 581 | static int sf = 0; |
586 | sf++; | 582 | sf++; |
587 | 583 | ||
588 | if ( sf % 2 ) | 584 | if ( sf % 2 ) |
589 | shield->setFrame( (shield->frame()+1) % shield->frameCount() ); | 585 | shield->setFrame( (shield->frame()+1) % shield->frameCount() ); |
590 | shield->move( ship->x() - 5, ship->y() - 5 ); | 586 | shield->move( ship->x() - 5, ship->y() - 5 ); |
591 | 587 | ||
592 | QCanvasItemList hits = shield->collisions( TRUE ); | 588 | QCanvasItemList hits = shield->collisions( TRUE ); |
593 | QCanvasItemList::Iterator it; | 589 | QCanvasItemList::Iterator it; |
594 | for ( it = hits.begin(); it != hits.end(); ++it ) | 590 | for ( it = hits.begin(); it != hits.end(); ++it ) |
595 | { | 591 | { |
596 | if ( (*it)->rtti() >= ID_ROCK_LARGE && | 592 | if ( (*it)->rtti() >= ID_ROCK_LARGE && |
597 | (*it)->rtti() <= ID_ROCK_SMALL ) | 593 | (*it)->rtti() <= ID_ROCK_SMALL ) |
598 | { | 594 | { |
599 | int factor; | 595 | int factor; |
600 | switch ( (*it)->rtti() ) | 596 | switch ( (*it)->rtti() ) |
601 | { | 597 | { |
602 | case ID_ROCK_LARGE: | 598 | case ID_ROCK_LARGE: |
603 | factor = 3; | 599 | factor = 3; |
604 | break; | 600 | break; |
605 | 601 | ||
606 | case ID_ROCK_MEDIUM: | 602 | case ID_ROCK_MEDIUM: |
607 | factor = 2; | 603 | factor = 2; |
608 | break; | 604 | break; |
609 | 605 | ||
610 | default: | 606 | default: |
611 | factor = 1; | 607 | factor = 1; |
612 | } | 608 | } |
613 | 609 | ||
614 | if ( factor > mShieldCount ) | 610 | if ( factor > mShieldCount ) |
615 | { | 611 | { |
616 | // shield not strong enough | 612 | // shield not strong enough |
617 | shieldOn = FALSE; | 613 | shieldOn = FALSE; |
618 | break; | 614 | break; |
619 | } | 615 | } |
620 | rockHit( *it ); | 616 | rockHit( *it ); |
621 | // the more shields we have the less costly | 617 | // the more shields we have the less costly |
622 | reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) ); | 618 | reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) ); |
623 | } | 619 | } |
624 | } | 620 | } |
625 | } | 621 | } |
626 | 622 | ||
627 | if ( !shieldOn ) | 623 | if ( !shieldOn ) |
628 | { | 624 | { |
629 | shield->hide(); | 625 | shield->hide(); |
630 | QCanvasItemList hits = ship->collisions( TRUE ); | 626 | QCanvasItemList hits = ship->collisions( TRUE ); |
631 | QCanvasItemList::Iterator it; | 627 | QCanvasItemList::Iterator it; |
632 | for ( it = hits.begin(); it != hits.end(); ++it ) | 628 | for ( it = hits.begin(); it != hits.end(); ++it ) |
633 | { | 629 | { |
634 | if ( (*it)->rtti() >= ID_ROCK_LARGE && | 630 | if ( (*it)->rtti() >= ID_ROCK_LARGE && |
635 | (*it)->rtti() <= ID_ROCK_SMALL ) | 631 | (*it)->rtti() <= ID_ROCK_SMALL ) |
636 | { | 632 | { |
637 | KBit *bit; | 633 | KBit *bit; |
638 | for ( int i = 0; i < 8; i++ ) | 634 | for ( int i = 0; i < 8; i++ ) |
639 | { | 635 | { |
640 | bit = new KBit( animation[ID_BIT], &field ); | 636 | bit = new KBit( animation[ID_BIT], &field ); |
641 | bit->move( ship->x() + 5 - randDouble() * 10, | 637 | bit->move( ship->x() + 5 - randDouble() * 10, |
642 | ship->y() + 5 - randDouble() * 10, | 638 | ship->y() + 5 - randDouble() * 10, |
643 | randInt(bit->frameCount()) ); | 639 | randInt(bit->frameCount()) ); |
644 | bit->setVelocity( 1-randDouble()*2, | 640 | bit->setVelocity( 1-randDouble()*2, |
645 | 1-randDouble()*2 ); | 641 | 1-randDouble()*2 ); |
646 | bit->setDeath( 60 + randInt(60) ); | 642 | bit->setDeath( 60 + randInt(60) ); |
647 | bit->show( ); | 643 | bit->show( ); |
648 | bits.append( bit ); | 644 | bits.append( bit ); |
649 | } | 645 | } |
650 | ship->hide(); | 646 | ship->hide(); |
651 | shield->hide(); | 647 | shield->hide(); |
652 | emit shipKilled(); | 648 | emit shipKilled(); |
653 | break; | 649 | break; |
654 | } | 650 | } |
655 | } | 651 | } |
656 | } | 652 | } |
657 | 653 | ||
658 | 654 | ||
659 | if ( rotateSlow ) | 655 | if ( rotateSlow ) |
660 | rotateSlow--; | 656 | rotateSlow--; |
661 | 657 | ||
662 | if ( rotateL ) | 658 | if ( rotateL ) |
663 | { | 659 | { |
664 | shipAngle -= rotateSlow ? 1 : rotateRate; | 660 | shipAngle -= rotateSlow ? 1 : rotateRate; |
665 | if ( shipAngle < 0 ) | 661 | if ( shipAngle < 0 ) |
666 | shipAngle += SHIP_STEPS; | 662 | shipAngle += SHIP_STEPS; |
667 | } | 663 | } |
668 | 664 | ||
669 | if ( rotateR ) | 665 | if ( rotateR ) |
670 | { | 666 | { |
671 | shipAngle += rotateSlow ? 1 : rotateRate; | 667 | shipAngle += rotateSlow ? 1 : rotateRate; |
672 | if ( shipAngle >= SHIP_STEPS ) | 668 | if ( shipAngle >= SHIP_STEPS ) |
673 | shipAngle -= SHIP_STEPS; | 669 | shipAngle -= SHIP_STEPS; |
674 | } | 670 | } |
675 | 671 | ||
676 | double angle = shipAngle * PI_X_2 / SHIP_STEPS; | 672 | double angle = shipAngle * PI_X_2 / SHIP_STEPS; |
677 | double cosangle = cos( angle ); | 673 | double cosangle = cos( angle ); |
678 | double sinangle = sin( angle ); | 674 | double sinangle = sin( angle ); |
679 | 675 | ||
680 | if ( brakeShip ) | 676 | if ( brakeShip ) |
681 | { | 677 | { |
682 | thrustShip = FALSE; | 678 | thrustShip = FALSE; |
683 | rotateL = FALSE; | 679 | rotateL = FALSE; |
684 | rotateR = FALSE; | 680 | rotateR = FALSE; |
685 | rotateRate = ROTATE_RATE; | 681 | rotateRate = ROTATE_RATE; |
686 | if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 ) | 682 | if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 ) |
687 | { | 683 | { |
688 | shipDx = 0.0; | 684 | shipDx = 0.0; |
689 | shipDy = 0.0; | 685 | shipDy = 0.0; |
690 | ship->setVelocity( shipDx, shipDy ); | 686 | ship->setVelocity( shipDx, shipDy ); |
691 | brakeShip = FALSE; | 687 | brakeShip = FALSE; |
692 | } | 688 | } |
693 | else | 689 | else |
694 | { | 690 | { |
695 | double motionAngle = atan2( -shipDy, -shipDx ); | 691 | double motionAngle = atan2( -shipDy, -shipDx ); |
696 | if ( angle > M_PI ) | 692 | if ( angle > M_PI ) |
697 | angle -= PI_X_2; | 693 | angle -= PI_X_2; |
698 | double angleDiff = angle - motionAngle; | 694 | double angleDiff = angle - motionAngle; |
699 | if ( angleDiff > M_PI ) | 695 | if ( angleDiff > M_PI ) |
700 | angleDiff = PI_X_2 - angleDiff; | 696 | angleDiff = PI_X_2 - angleDiff; |
701 | else if ( angleDiff < -M_PI ) | 697 | else if ( angleDiff < -M_PI ) |
702 | angleDiff = PI_X_2 + angleDiff; | 698 | angleDiff = PI_X_2 + angleDiff; |
703 | double fdiff = fabs( angleDiff ); | 699 | double fdiff = fabs( angleDiff ); |
704 | if ( fdiff > 0.08 ) | 700 | if ( fdiff > 0.08 ) |
705 | { | 701 | { |
706 | if ( angleDiff > 0 ) | 702 | if ( angleDiff > 0 ) |
707 | rotateL = TRUE; | 703 | rotateL = TRUE; |
708 | else if ( angleDiff < 0 ) | 704 | else if ( angleDiff < 0 ) |
709 | rotateR = TRUE; | 705 | rotateR = TRUE; |
710 | if ( fdiff > 0.6 ) | 706 | if ( fdiff > 0.6 ) |
711 | rotateRate = mBrakeCount + 1; | 707 | rotateRate = mBrakeCount + 1; |
712 | else if ( fdiff > 0.4 ) | 708 | else if ( fdiff > 0.4 ) |
713 | rotateRate = 2; | 709 | rotateRate = 2; |
714 | else | 710 | else |
715 | rotateRate = 1; | 711 | rotateRate = 1; |
716 | 712 | ||
717 | if ( rotateRate > 5 ) | 713 | if ( rotateRate > 5 ) |
718 | rotateRate = 5; | 714 | rotateRate = 5; |
719 | } | 715 | } |
720 | else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 ) | 716 | else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 ) |
721 | { | 717 | { |
722 | thrustShip = TRUE; | 718 | thrustShip = TRUE; |
723 | // we'll make braking a bit faster | 719 | // we'll make braking a bit faster |
724 | shipDx += cosangle/6 * (mBrakeCount - 1); | 720 | shipDx += cosangle/6 * (mBrakeCount - 1); |
725 | shipDy += sinangle/6 * (mBrakeCount - 1); | 721 | shipDy += sinangle/6 * (mBrakeCount - 1); |
726 | reducePower( BRAKE_ON_COST ); | 722 | reducePower( BRAKE_ON_COST ); |
727 | addExhaust( ship->x() + 10 - cosangle*11, | 723 | addExhaust( ship->x() + 10 - cosangle*11, |
728 | ship->y() + 10 - sinangle*11, | 724 | ship->y() + 10 - sinangle*11, |
729 | shipDx-cosangle, shipDy-sinangle, | 725 | shipDx-cosangle, shipDy-sinangle, |
730 | mBrakeCount+1 ); | 726 | mBrakeCount+1 ); |
731 | } | 727 | } |
732 | } | 728 | } |
733 | } | 729 | } |
734 | 730 | ||
735 | if ( thrustShip ) | 731 | if ( thrustShip ) |
736 | { | 732 | { |
737 | // The ship has a terminal velocity, but trying to go faster | 733 | // The ship has a terminal velocity, but trying to go faster |
738 | // still uses fuel (can go faster diagonally - don't care). | 734 | // still uses fuel (can go faster diagonally - don't care). |
739 | double thrustx = cosangle/8; | 735 | double thrustx = cosangle/8; |
740 | double thrusty = sinangle/8; | 736 | double thrusty = sinangle/8; |
741 | if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED ) | 737 | if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED ) |
742 | shipDx += thrustx; | 738 | shipDx += thrustx; |
743 | if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED ) | 739 | if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED ) |
744 | shipDy += thrusty; | 740 | shipDy += thrusty; |
745 | ship->setVelocity( shipDx, shipDy ); | 741 | ship->setVelocity( shipDx, shipDy ); |
746 | reducePower( 1 ); | 742 | reducePower( 1 ); |
747 | addExhaust( ship->x() + 10 - cosangle*10, | 743 | addExhaust( ship->x() + 10 - cosangle*10, |
748 | ship->y() + 10 - sinangle*10, | 744 | ship->y() + 10 - sinangle*10, |
749 | shipDx-cosangle, shipDy-sinangle, 3 ); | 745 | shipDx-cosangle, shipDy-sinangle, 3 ); |
750 | } | 746 | } |
751 | 747 | ||
752 | ship->setFrame( shipAngle >> 1 ); | 748 | ship->setFrame( shipAngle >> 1 ); |
753 | 749 | ||
754 | if ( shootShip ) | 750 | if ( shootShip ) |
755 | { | 751 | { |
756 | if ( !shootDelay && (int)missiles.count() < mShootCount + 2 ) | 752 | if ( !shootDelay && (int)missiles.count() < mShootCount + 2 ) |
757 | { | 753 | { |
758 | KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); | 754 | KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); |
759 | missile->move( 11+ship->x()+cosangle*11, | 755 | missile->move( 11+ship->x()+cosangle*11, |
760 | 11+ship->y()+sinangle*11, 0 ); | 756 | 11+ship->y()+sinangle*11, 0 ); |
761 | missile->setVelocity( shipDx + cosangle*MISSILE_SPEED, | 757 | missile->setVelocity( shipDx + cosangle*MISSILE_SPEED, |
762 | shipDy + sinangle*MISSILE_SPEED ); | 758 | shipDy + sinangle*MISSILE_SPEED ); |
763 | missile->show( ); | 759 | missile->show( ); |
764 | missiles.append( missile ); | 760 | missiles.append( missile ); |
765 | shotsFired++; | 761 | shotsFired++; |
766 | reducePower( 1 ); | 762 | reducePower( 1 ); |
767 | 763 | ||
768 | shootDelay = 5; | 764 | shootDelay = 5; |
769 | } | 765 | } |
770 | 766 | ||
771 | if ( shootDelay ) | 767 | if ( shootDelay ) |
772 | shootDelay--; | 768 | shootDelay--; |
773 | } | 769 | } |
774 | 770 | ||
775 | if ( teleportShip ) | 771 | if ( teleportShip ) |
776 | { | 772 | { |
777 | int ra = rand() % 10; | 773 | int ra = rand() % 10; |
778 | if( ra == 0 ) | 774 | if( ra == 0 ) |
779 | ra += rand() % 20; | 775 | ra += rand() % 20; |
780 | int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) ); | 776 | int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) ); |
781 | int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) ); | 777 | int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) ); |
782 | ship->move( xra, yra ); | 778 | ship->move( xra, yra ); |
783 | } | 779 | } |
784 | 780 | ||
785 | vitalsChanged = TRUE; | 781 | vitalsChanged = TRUE; |
786 | } | 782 | } |
787 | } | 783 | } |
788 | 784 | ||
789 | // - - - | 785 | // - - - |
790 | 786 | ||
791 | void KAsteroidsView::processPowerups() | 787 | void KAsteroidsView::processPowerups() |
792 | { | 788 | { |
793 | if ( !powerups.isEmpty() ) | 789 | if ( !powerups.isEmpty() ) |
794 | { | 790 | { |
795 | // if player gets the powerup remove it from the screen, if option | 791 | // if player gets the powerup remove it from the screen, if option |
796 | // "Can destroy powerups" is enabled and a missile hits the powerup | 792 | // "Can destroy powerups" is enabled and a missile hits the powerup |
797 | // destroy it | 793 | // destroy it |
798 | 794 | ||
799 | KPowerup *pup; | 795 | KPowerup *pup; |
800 | QPtrListIterator<KPowerup> it( powerups ); | 796 | QPtrListIterator<KPowerup> it( powerups ); |
801 | 797 | ||
802 | for( ; it.current(); ++it ) | 798 | for( ; it.current(); ++it ) |
803 | { | 799 | { |
804 | pup = it.current(); | 800 | pup = it.current(); |
805 | pup->growOlder(); | 801 | pup->growOlder(); |
806 | 802 | ||
807 | if( pup->expired() ) | 803 | if( pup->expired() ) |
808 | { | 804 | { |
809 | powerups.removeRef( pup ); | 805 | powerups.removeRef( pup ); |
810 | continue; | 806 | continue; |
811 | } | 807 | } |
812 | 808 | ||
813 | wrapSprite( pup ); | 809 | wrapSprite( pup ); |
814 | 810 | ||
815 | QCanvasItemList hits = pup->collisions( TRUE ); | 811 | QCanvasItemList hits = pup->collisions( TRUE ); |
816 | QCanvasItemList::Iterator it; | 812 | QCanvasItemList::Iterator it; |
817 | for ( it = hits.begin(); it != hits.end(); ++it ) | 813 | for ( it = hits.begin(); it != hits.end(); ++it ) |
818 | { | 814 | { |
819 | if ( (*it) == ship ) | 815 | if ( (*it) == ship ) |
820 | { | 816 | { |
821 | switch( pup->rtti() ) | 817 | switch( pup->rtti() ) |
822 | { | 818 | { |
823 | case ID_ENERGY_POWERUP: | 819 | case ID_ENERGY_POWERUP: |
824 | shipPower += 150; | 820 | shipPower += 150; |
825 | if ( shipPower > MAX_POWER_LEVEL ) | 821 | if ( shipPower > MAX_POWER_LEVEL ) |
826 | shipPower = MAX_POWER_LEVEL; | 822 | shipPower = MAX_POWER_LEVEL; |
827 | break; | 823 | break; |
828 | case ID_TELEPORT_POWERUP: | 824 | case ID_TELEPORT_POWERUP: |
829 | mTeleportCount++; | 825 | mTeleportCount++; |
830 | break; | 826 | break; |
831 | case ID_BRAKE_POWERUP: | 827 | case ID_BRAKE_POWERUP: |
832 | if ( mBrakeCount < MAX_BRAKES ) | 828 | if ( mBrakeCount < MAX_BRAKES ) |
833 | mBrakeCount++; | 829 | mBrakeCount++; |
834 | break; | 830 | break; |
835 | case ID_SHIELD_POWERUP: | 831 | case ID_SHIELD_POWERUP: |
836 | if ( mShieldCount < MAX_SHIELDS ) | 832 | if ( mShieldCount < MAX_SHIELDS ) |
837 | mShieldCount++; | 833 | mShieldCount++; |
838 | break; | 834 | break; |
839 | case ID_SHOOT_POWERUP: | 835 | case ID_SHOOT_POWERUP: |
840 | if ( mShootCount < MAX_FIREPOWER ) | 836 | if ( mShootCount < MAX_FIREPOWER ) |
841 | mShootCount++; | 837 | mShootCount++; |
842 | break; | 838 | break; |
843 | } | 839 | } |
844 | 840 | ||
845 | powerups.removeRef( pup ); | 841 | powerups.removeRef( pup ); |
846 | vitalsChanged = TRUE; | 842 | vitalsChanged = TRUE; |
847 | } | 843 | } |
848 | else if ( (*it) == shield ) | 844 | else if ( (*it) == shield ) |
849 | { | 845 | { |
850 | powerups.removeRef( pup ); | 846 | powerups.removeRef( pup ); |
851 | } | 847 | } |
852 | else if ( (*it)->rtti() == ID_MISSILE ) | 848 | else if ( (*it)->rtti() == ID_MISSILE ) |
853 | { | 849 | { |
854 | if ( can_destroy_powerups ) | 850 | if ( can_destroy_powerups ) |
855 | { | 851 | { |
856 | powerups.removeRef( pup ); | 852 | powerups.removeRef( pup ); |
857 | } | 853 | } |
858 | } | 854 | } |
859 | } | 855 | } |
860 | } | 856 | } |
861 | } // -- if( powerups.isEmpty() ) | 857 | } // -- if( powerups.isEmpty() ) |
862 | } | 858 | } |
863 | 859 | ||
864 | // - - - | 860 | // - - - |
865 | 861 | ||
866 | void KAsteroidsView::hideShield() | 862 | void KAsteroidsView::hideShield() |
867 | { | 863 | { |
868 | shield->hide(); | 864 | shield->hide(); |
869 | mShieldCount = 0; | 865 | mShieldCount = 0; |
870 | shieldOn = FALSE; | 866 | shieldOn = FALSE; |
871 | } | 867 | } |
872 | 868 | ||
873 | double KAsteroidsView::randDouble() | 869 | double KAsteroidsView::randDouble() |
874 | { | 870 | { |
875 | int v = rand(); | 871 | int v = rand(); |
876 | return (double)v / (double)RAND_MAX; | 872 | return (double)v / (double)RAND_MAX; |
877 | } | 873 | } |
878 | 874 | ||
879 | int KAsteroidsView::randInt( int range ) | 875 | int KAsteroidsView::randInt( int range ) |
880 | { | 876 | { |
881 | return rand() % range; | 877 | return rand() % range; |
882 | } | 878 | } |