author | zecke <zecke> | 2004-11-15 14:28:50 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-11-15 14:28:50 (UTC) |
commit | c9543dc4edd3ea586c04e8114e133296ad9529d9 (patch) (unidiff) | |
tree | a5031c6fed1808b69c174480430944f8377b88a2 | |
parent | f0c8746173f4cea9680b120bf823e77e7c8729b3 (diff) | |
download | opie-c9543dc4edd3ea586c04e8114e133296ad9529d9.zip opie-c9543dc4edd3ea586c04e8114e133296ad9529d9.tar.gz opie-c9543dc4edd3ea586c04e8114e133296ad9529d9.tar.bz2 |
Make SFCave quick launchable
-rw-r--r-- | noncore/games/sfcave/opie-sfcave.control | 2 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 48 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.h | 8 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.pro | 5 |
4 files changed, 21 insertions, 42 deletions
diff --git a/noncore/games/sfcave/opie-sfcave.control b/noncore/games/sfcave/opie-sfcave.control index 0ff3e2c..1d98a19 100644 --- a/noncore/games/sfcave/opie-sfcave.control +++ b/noncore/games/sfcave/opie-sfcave.control | |||
@@ -1,9 +1,9 @@ | |||
1 | Package: opie-sfcave | 1 | Package: opie-sfcave |
2 | Files: bin/sfcave apps/Games/sfcave.desktop pics/sfcave | 2 | Files: plugins/applications/libsfcave.so* bin/sfcave apps/Games/sfcave.desktop pics/sfcave |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/games | 4 | Section: opie/games |
5 | Maintainer: Andy Qua <andy.qua@blueyonder.co.uk> | 5 | Maintainer: Andy Qua <andy.qua@blueyonder.co.uk> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Depends: task-opie-minimal | 7 | Depends: task-opie-minimal |
8 | Description: SFCave for the Zaurus. Fly the dot though the cave avoiding the walls. | 8 | Description: SFCave for the Zaurus. Fly the dot though the cave avoiding the walls. |
9 | Version: $QPE_VERSION$EXTRAVERSION | 9 | Version: $QPE_VERSION$EXTRAVERSION |
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index 9b30fe6..5dca427 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -1,471 +1,447 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <math.h> | 3 | #include <math.h> |
4 | #include <time.h> | 4 | #include <time.h> |
5 | 5 | ||
6 | #ifdef QWS | 6 | #include <opie2/oapplicationfactory.h> |
7 | #include <qpe/qpeapplication.h> | ||
8 | #include <qpe/config.h> | 7 | #include <qpe/config.h> |
9 | #else | 8 | |
10 | #include <qapplication.h> | 9 | #include <qapplication.h> |
11 | #endif | ||
12 | #include <qdir.h> | 10 | #include <qdir.h> |
13 | 11 | ||
14 | #include "helpwindow.h" | 12 | #include "helpwindow.h" |
15 | #include "sfcave.h" | 13 | #include "sfcave.h" |
16 | 14 | ||
17 | #define CAPTION "SFCave 1.13 by AndyQ" | 15 | #define CAPTION "SFCave 1.13 by AndyQ" |
18 | 16 | ||
19 | #define UP_THRUST 0.6 | 17 | #define UP_THRUST 0.6 |
20 | #define NO_THRUST 0.8 | 18 | #define NO_THRUST 0.8 |
21 | #define MAX_DOWN_THRUST 4.0 | 19 | #define MAX_DOWN_THRUST 4.0 |
22 | #define MAX_UP_THRUST -3.5 | 20 | #define MAX_UP_THRUST -3.5 |
23 | 21 | ||
24 | // States | 22 | // States |
25 | #define STATE_BOSS 0 | 23 | #define STATE_BOSS 0 |
26 | #define STATE_RUNNING 1 | 24 | #define STATE_RUNNING 1 |
27 | #define STATE_CRASHING 2 | 25 | #define STATE_CRASHING 2 |
28 | #define STATE_CRASHED 3 | 26 | #define STATE_CRASHED 3 |
29 | #define STATE_NEWGAME 4 | 27 | #define STATE_NEWGAME 4 |
30 | #define STATE_MENU 5 | 28 | #define STATE_MENU 5 |
31 | #define STATE_REPLAY 6 | 29 | #define STATE_REPLAY 6 |
32 | 30 | ||
33 | // Menus | 31 | // Menus |
34 | #define MENU_MAIN_MENU 0 | 32 | #define MENU_MAIN_MENU 0 |
35 | #define MENU_OPTIONS_MENU 1 | 33 | #define MENU_OPTIONS_MENU 1 |
36 | #define MENU_REPLAY_MENU 2 | 34 | #define MENU_REPLAY_MENU 2 |
37 | 35 | ||
38 | // Main Menu Options | 36 | // Main Menu Options |
39 | #define MENU_START_GAME 0 | 37 | #define MENU_START_GAME 0 |
40 | #define MENU_REPLAY 1 | 38 | #define MENU_REPLAY 1 |
41 | #define MENU_OPTIONS 2 | 39 | #define MENU_OPTIONS 2 |
42 | #define MENU_HELP 3 | 40 | #define MENU_HELP 3 |
43 | #define MENU_QUIT 4 | 41 | #define MENU_QUIT 4 |
44 | 42 | ||
45 | // Option Menu Options | 43 | // Option Menu Options |
46 | #define MENU_GAME_TYPE 0 | 44 | #define MENU_GAME_TYPE 0 |
47 | #define MENU_GAME_DIFFICULTY 1 | 45 | #define MENU_GAME_DIFFICULTY 1 |
48 | #define MENU_CLEAR_HIGHSCORES 2 | 46 | #define MENU_CLEAR_HIGHSCORES 2 |
49 | #define MENU_BACK 3 | 47 | #define MENU_BACK 3 |
50 | 48 | ||
51 | // Replay Menu Options | 49 | // Replay Menu Options |
52 | #define MENU_REPLAY_START 0 | 50 | #define MENU_REPLAY_START 0 |
53 | #define MENU_REPLAY_LOAD 1 | 51 | #define MENU_REPLAY_LOAD 1 |
54 | #define MENU_REPLAY_SAVE 2 | 52 | #define MENU_REPLAY_SAVE 2 |
55 | #define MENU_REPLAY_BACK 3 | 53 | #define MENU_REPLAY_BACK 3 |
56 | 54 | ||
57 | 55 | ||
58 | #define NR_GAME_DIFFICULTIES 3 | 56 | #define NR_GAME_DIFFICULTIES 3 |
59 | #define NR_GAME_TYPES 3 | 57 | #define NR_GAME_TYPES 3 |
60 | 58 | ||
61 | #define DIFICULTY_EASY 0 | 59 | #define DIFICULTY_EASY 0 |
62 | #define DIFICULTY_NORMAL 1 | 60 | #define DIFICULTY_NORMAL 1 |
63 | #define DIFICULTY_HARD 2 | 61 | #define DIFICULTY_HARD 2 |
64 | #define EASY "Easy" | 62 | #define EASY "Easy" |
65 | #define NORMAL "Normal" | 63 | #define NORMAL "Normal" |
66 | #define HARD "Hard" | 64 | #define HARD "Hard" |
67 | 65 | ||
68 | #define SFCAVE_GAME_TYPE 0 | 66 | #define SFCAVE_GAME_TYPE 0 |
69 | #define GATES_GAME_TYPE 1 | 67 | #define GATES_GAME_TYPE 1 |
70 | #define FLY_GAME_TYPE 2 | 68 | #define FLY_GAME_TYPE 2 |
71 | #define SFCAVE_GAME "SFCave" | 69 | #define SFCAVE_GAME "SFCave" |
72 | #define GATES_GAME "Gates" | 70 | #define GATES_GAME "Gates" |
73 | #define FLY_GAME "Fly" | 71 | #define FLY_GAME "Fly" |
74 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] | 72 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] |
75 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; | 73 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; |
76 | 74 | ||
77 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; | 75 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; |
78 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; | 76 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; |
79 | 77 | ||
80 | QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" }, | 78 | QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" }, |
81 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" }, | 79 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" }, |
82 | { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } }; | 80 | { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } }; |
83 | 81 | ||
84 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; | 82 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; |
85 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; | 83 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; |
86 | 84 | ||
87 | #define UP_THRUST 0.6 | 85 | #define UP_THRUST 0.6 |
88 | #define NO_THRUST 0.8 | 86 | #define NO_THRUST 0.8 |
89 | #define MAX_DOWN_THRUST 4.0 | 87 | #define MAX_DOWN_THRUST 4.0 |
90 | #define MAX_UP_THRUST -3.5 | 88 | #define MAX_UP_THRUST -3.5 |
91 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave | 89 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave |
92 | { 0.6, 0.6, 0.8 }, // Gates | 90 | { 0.6, 0.6, 0.8 }, // Gates |
93 | { 0.4, 0.7, 1.0 } }; // Fly | 91 | { 0.4, 0.7, 1.0 } }; // Fly |
94 | 92 | ||
95 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave | 93 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave |
96 | { 0.8, 0.8, 1.0 }, // Gates | 94 | { 0.8, 0.8, 1.0 }, // Gates |
97 | { 0.4, 0.7, 1.0 } }; // Fly | 95 | { 0.4, 0.7, 1.0 } }; // Fly |
98 | 96 | ||
99 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave | 97 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave |
100 | { -3.5, -4.0, -5.0 }, // Gates | 98 | { -3.5, -4.0, -5.0 }, // Gates |
101 | { -3.5, -4.0, -5.0 } }; // Fly | 99 | { -3.5, -4.0, -5.0 } }; // Fly |
102 | 100 | ||
103 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave | 101 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave |
104 | { 4.0, 5.0, 5.5 }, // Gates | 102 | { 4.0, 5.0, 5.5 }, // Gates |
105 | { 3.5, 4.0, 5.0 } }; // Fly | 103 | { 3.5, 4.0, 5.0 } }; // Fly |
106 | 104 | ||
107 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, | 105 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, |
108 | { 10, 20, 3 }, | 106 | { 10, 20, 3 }, |
109 | { 20, 30, 2 }, | 107 | { 20, 30, 2 }, |
110 | { 30, 40, 1 }, | 108 | { 30, 40, 1 }, |
111 | { 50, 70, -2 }, | 109 | { 50, 70, -2 }, |
112 | { 70, 300, -5 }, | 110 | { 70, 300, -5 }, |
113 | { -1, -1, -1 } }; | 111 | { -1, -1, -1 } }; |
114 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, | 112 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, |
115 | { 10, 20, 3 }, | 113 | { 10, 20, 3 }, |
116 | { 20, 30, 2 }, | 114 | { 20, 30, 2 }, |
117 | { 30, 40, 1 }, | 115 | { 30, 40, 1 }, |
118 | { 50, 70, -2 }, | 116 | { 50, 70, -2 }, |
119 | { 70, 300, -5 }, | 117 | { 70, 300, -5 }, |
120 | { -1, -1, -1 } }; | 118 | { -1, -1, -1 } }; |
121 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, | 119 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, |
122 | { 20, 40, 3 }, | 120 | { 20, 40, 3 }, |
123 | { 40, 100, 1 }, | 121 | { 40, 100, 1 }, |
124 | { 100, 150, -2 }, | 122 | { 100, 150, -2 }, |
125 | { 150, 300, -5 }, | 123 | { 150, 300, -5 }, |
126 | { -1, -1, -1 } }; | 124 | { -1, -1, -1 } }; |
127 | 125 | ||
128 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; | 126 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; |
129 | 127 | ||
130 | 128 | ||
131 | #define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y)) | 129 | #define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y)) |
132 | bool movel; | 130 | bool movel; |
133 | 131 | ||
134 | 132 | ||
135 | int main( int argc, char *argv[] ) | 133 | OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<SFCave> ) |
136 | { | ||
137 | movel = true; | ||
138 | #ifdef QWS | ||
139 | QPEApplication a( argc, argv ); | ||
140 | #else | ||
141 | QApplication a( argc, argv ); | ||
142 | #endif | ||
143 | 134 | ||
144 | int speed = 3; | 135 | SFCave :: SFCave( QWidget *w, const char *name, WFlags fl ) |
145 | for ( int i = 0 ; i < argc ; ++i ) | 136 | : QMainWindow( w, name, fl ) |
146 | { | ||
147 | if ( strcmp( argv[i], "-s" ) == 0 ) | ||
148 | { | ||
149 | if ( i+1 < argc ) | ||
150 | speed = atoi( argv[i+1] ); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | SFCave app( speed ); | ||
155 | a.setMainWidget( &app ); | ||
156 | app.show(); | ||
157 | app.start(); | ||
158 | a.exec(); | ||
159 | } | ||
160 | |||
161 | SFCave :: SFCave( int spd, QWidget *w, char *name ) | ||
162 | : QMainWindow( w, name ) | ||
163 | 137 | ||
164 | { | 138 | { |
165 | replayIt = 0; | ||
166 | #ifdef QWS | ||
167 | showMaximized(); | 139 | showMaximized(); |
168 | #else | 140 | movel = true; |
169 | resize( 240, 284 ); | 141 | int spd = 3; |
170 | #endif | 142 | |
143 | |||
144 | replayIt = 0; | ||
171 | 145 | ||
172 | replayFile = QDir::home().path(); | 146 | replayFile = QDir::home().path(); |
173 | replayFile += "/sfcave.replay"; | 147 | replayFile += "/sfcave.replay"; |
174 | printf( "%s\n", (const char *)replayFile ); | 148 | printf( "%s\n", (const char *)replayFile ); |
175 | 149 | ||
176 | sWidth = width(); | 150 | sWidth = width(); |
177 | sHeight = height(); | 151 | sHeight = height(); |
178 | segSize = sWidth/(MAPSIZE-1)+1; | 152 | segSize = sWidth/(MAPSIZE-1)+1; |
179 | 153 | ||
180 | currentMenuNr = 0; | 154 | currentMenuNr = 0; |
181 | currentGameType = 0; | 155 | currentGameType = 0; |
182 | currentGameDifficulty = 0; | 156 | currentGameDifficulty = 0; |
183 | 157 | ||
184 | setCaption( CAPTION ); | 158 | setCaption( CAPTION ); |
185 | showScoreZones = false; | 159 | showScoreZones = false; |
186 | 160 | ||
187 | #ifdef QWS | 161 | #ifdef QWS |
188 | Config cfg( "sfcave" ); | 162 | Config cfg( "sfcave" ); |
189 | cfg.setGroup( "settings" ); | 163 | cfg.setGroup( "settings" ); |
190 | QString key = "highScore_"; | 164 | QString key = "highScore_"; |
191 | 165 | ||
192 | for ( int i = 0 ; i < 3 ; ++i ) | 166 | for ( int i = 0 ; i < 3 ; ++i ) |
193 | { | 167 | { |
194 | for ( int j = 0 ; j < 3 ; ++j ) | 168 | for ( int j = 0 ; j < 3 ; ++j ) |
195 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); | 169 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); |
196 | } | 170 | } |
197 | 171 | ||
198 | currentGameType = cfg.readNumEntry( "gameType", 0 ); | 172 | currentGameType = cfg.readNumEntry( "gameType", 0 ); |
199 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); | 173 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); |
200 | #endif | 174 | #endif |
201 | speed = spd; // Change to 2 for PC | 175 | speed = spd; // Change to 2 for PC |
202 | press = false; | 176 | press = false; |
203 | showEyeCandy = false; | 177 | showEyeCandy = false; |
204 | 178 | ||
205 | offscreen = new QPixmap( sWidth, sHeight ); | 179 | offscreen = new QPixmap( sWidth, sHeight ); |
206 | offscreen->fill( Qt::black ); | 180 | offscreen->fill( Qt::black ); |
207 | 181 | ||
208 | // setUp(); | 182 | // setUp(); |
209 | crashLineLength = -1; | 183 | crashLineLength = -1; |
210 | state = STATE_MENU; | 184 | state = STATE_MENU; |
211 | prevState = STATE_MENU; | 185 | prevState = STATE_MENU; |
212 | 186 | ||
213 | gameTimer = new QTimer( this, "game timer" ); | 187 | gameTimer = new QTimer( this, "game timer" ); |
214 | connect( gameTimer, SIGNAL( timeout() ), | 188 | connect( gameTimer, SIGNAL( timeout() ), |
215 | this, SLOT( run() ) ); | 189 | this, SLOT( run() ) ); |
190 | |||
191 | QTimer::singleShot(0, this, SLOT(start())); | ||
216 | } | 192 | } |
217 | 193 | ||
218 | SFCave :: ~SFCave() | 194 | SFCave :: ~SFCave() |
219 | { | 195 | { |
220 | } | 196 | } |
221 | 197 | ||
222 | void SFCave :: start() | 198 | void SFCave :: start() |
223 | { | 199 | { |
224 | gameTimer->start( 10 ); | 200 | gameTimer->start( 10 ); |
225 | 201 | ||
226 | } | 202 | } |
227 | 203 | ||
228 | void SFCave :: setSeed( int seed ) | 204 | void SFCave :: setSeed( int seed ) |
229 | { | 205 | { |
230 | if ( seed == -1 ) | 206 | if ( seed == -1 ) |
231 | currentSeed = ((unsigned long) time((time_t *) NULL)); | 207 | currentSeed = ((unsigned long) time((time_t *) NULL)); |
232 | else | 208 | else |
233 | currentSeed = seed; | 209 | currentSeed = seed; |
234 | PutSeed( currentSeed ); | 210 | PutSeed( currentSeed ); |
235 | } | 211 | } |
236 | 212 | ||
237 | int SFCave :: nextInt( int range ) | 213 | int SFCave :: nextInt( int range ) |
238 | { | 214 | { |
239 | int val = (int)(Random( ) * range); | 215 | int val = (int)(Random( ) * range); |
240 | 216 | ||
241 | return val; | 217 | return val; |
242 | 218 | ||
243 | } | 219 | } |
244 | 220 | ||
245 | void SFCave :: setUp() | 221 | void SFCave :: setUp() |
246 | { | 222 | { |
247 | score = 0; | 223 | score = 0; |
248 | offset = 0; | 224 | offset = 0; |
249 | nrFrames = 0; | 225 | nrFrames = 0; |
250 | dir = 1; | 226 | dir = 1; |
251 | thrust = 0; | 227 | thrust = 0; |
252 | startScoring = false; | 228 | startScoring = false; |
253 | press = false; | 229 | press = false; |
254 | 230 | ||
255 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 231 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
256 | { | 232 | { |
257 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 233 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
258 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 234 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
259 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 235 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
260 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 236 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
261 | 237 | ||
262 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 238 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
263 | gateDistance = 100; | 239 | gateDistance = 100; |
264 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 240 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
265 | gateDistance = 60; | 241 | gateDistance = 60; |
266 | else | 242 | else |
267 | gateDistance = 40; | 243 | gateDistance = 40; |
268 | } | 244 | } |
269 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 245 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
270 | { | 246 | { |
271 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 247 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
272 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 248 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
273 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 249 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
274 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 250 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
275 | gateDistance = 75; | 251 | gateDistance = 75; |
276 | nextGate = nextInt( 50 ) + gateDistance; | 252 | nextGate = nextInt( 50 ) + gateDistance; |
277 | } | 253 | } |
278 | else | 254 | else |
279 | { | 255 | { |
280 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 256 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
281 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 257 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
282 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 258 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
283 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 259 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
284 | 260 | ||
285 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 261 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
286 | flyScores = (int*)flyEasyScores; | 262 | flyScores = (int*)flyEasyScores; |
287 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 263 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
288 | flyScores = (int*)flyNormalScores; | 264 | flyScores = (int*)flyNormalScores; |
289 | else | 265 | else |
290 | flyScores = (int*)flyHardScores; | 266 | flyScores = (int*)flyHardScores; |
291 | } | 267 | } |
292 | 268 | ||
293 | crashLineLength = 0; | 269 | crashLineLength = 0; |
294 | lastGateBottomY = 0; | 270 | lastGateBottomY = 0; |
295 | 271 | ||
296 | user.setRect( 50, sWidth/2, 4, 4 ); | 272 | user.setRect( 50, sWidth/2, 4, 4 ); |
297 | 273 | ||
298 | blockWidth = 20; | 274 | blockWidth = 20; |
299 | blockHeight = 70; | 275 | blockHeight = 70; |
300 | gapHeight = initialGateGaps[currentGameDifficulty]; | 276 | gapHeight = initialGateGaps[currentGameDifficulty]; |
301 | 277 | ||
302 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 278 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
303 | { | 279 | { |
304 | trail[i].setX( -1 ); | 280 | trail[i].setX( -1 ); |
305 | trail[i].setY( 0 ); | 281 | trail[i].setY( 0 ); |
306 | } | 282 | } |
307 | 283 | ||
308 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 284 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
309 | { | 285 | { |
310 | maxHeight = 50; | 286 | maxHeight = 50; |
311 | 287 | ||
312 | mapTop[0] = (int)(nextInt(50)) + 5; | 288 | mapTop[0] = (int)(nextInt(50)) + 5; |
313 | mapBottom[0] = (int)(nextInt(50)) + 5; | 289 | mapBottom[0] = (int)(nextInt(50)) + 5; |
314 | for ( int i = 1 ; i < MAPSIZE ; ++i ) | 290 | for ( int i = 1 ; i < MAPSIZE ; ++i ) |
315 | setPoint( i ); | 291 | setPoint( i ); |
316 | } | 292 | } |
317 | else | 293 | else |
318 | { | 294 | { |
319 | maxHeight = 100; | 295 | maxHeight = 100; |
320 | 296 | ||
321 | for ( int i = 0 ; i < MAPSIZE ; ++i ) | 297 | for ( int i = 0 ; i < MAPSIZE ; ++i ) |
322 | mapBottom[i] = sHeight - 10; | 298 | mapBottom[i] = sHeight - 10; |
323 | } | 299 | } |
324 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 300 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
325 | blocks[i].setY( -1 ); | 301 | blocks[i].setY( -1 ); |
326 | 302 | ||
327 | } | 303 | } |
328 | 304 | ||
329 | void SFCave :: run() | 305 | void SFCave :: run() |
330 | { | 306 | { |
331 | switch ( state ) | 307 | switch ( state ) |
332 | { | 308 | { |
333 | case STATE_MENU: | 309 | case STATE_MENU: |
334 | displayMenu(); | 310 | displayMenu(); |
335 | break; | 311 | break; |
336 | case STATE_NEWGAME: | 312 | case STATE_NEWGAME: |
337 | setSeed( -1 ); | 313 | setSeed( -1 ); |
338 | setUp(); | 314 | setUp(); |
339 | draw(); | 315 | draw(); |
340 | state = STATE_RUNNING; | 316 | state = STATE_RUNNING; |
341 | replay = false; | 317 | replay = false; |
342 | replayList.clear(); | 318 | replayList.clear(); |
343 | break; | 319 | break; |
344 | case STATE_REPLAY: | 320 | case STATE_REPLAY: |
345 | setSeed( currentSeed ); | 321 | setSeed( currentSeed ); |
346 | setUp(); | 322 | setUp(); |
347 | draw(); | 323 | draw(); |
348 | state = STATE_RUNNING; | 324 | state = STATE_RUNNING; |
349 | replay = true; | 325 | replay = true; |
350 | if ( replayIt ) | 326 | if ( replayIt ) |
351 | delete replayIt; | 327 | delete replayIt; |
352 | replayIt = new QListIterator<int>( replayList ); | 328 | replayIt = new QListIterator<int>( replayList ); |
353 | break; | 329 | break; |
354 | case STATE_BOSS: | 330 | case STATE_BOSS: |
355 | drawBoss(); | 331 | drawBoss(); |
356 | break; | 332 | break; |
357 | 333 | ||
358 | case STATE_CRASHING: | 334 | case STATE_CRASHING: |
359 | case STATE_CRASHED: | 335 | case STATE_CRASHED: |
360 | press = false; | 336 | press = false; |
361 | draw(); | 337 | draw(); |
362 | break; | 338 | break; |
363 | 339 | ||
364 | case STATE_RUNNING: | 340 | case STATE_RUNNING: |
365 | { | 341 | { |
366 | if ( nrFrames % 2 == 0 ) | 342 | if ( nrFrames % 2 == 0 ) |
367 | handleKeys(); | 343 | handleKeys(); |
368 | 344 | ||
369 | // Apply Game rules | 345 | // Apply Game rules |
370 | nrFrames ++; | 346 | nrFrames ++; |
371 | 347 | ||
372 | if ( replay ) | 348 | if ( replay ) |
373 | { | 349 | { |
374 | while( replayIt->current() && *(replayIt->current()) == nrFrames ) | 350 | while( replayIt->current() && *(replayIt->current()) == nrFrames ) |
375 | { | 351 | { |
376 | press = !press; | 352 | press = !press; |
377 | ++(*replayIt); | 353 | ++(*replayIt); |
378 | } | 354 | } |
379 | } | 355 | } |
380 | 356 | ||
381 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 357 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
382 | handleGameSFCave(); | 358 | handleGameSFCave(); |
383 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 359 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
384 | handleGameGates(); | 360 | handleGameGates(); |
385 | else if ( CURRENT_GAME_TYPE == FLY_GAME ) | 361 | else if ( CURRENT_GAME_TYPE == FLY_GAME ) |
386 | handleGameFly(); | 362 | handleGameFly(); |
387 | 363 | ||
388 | draw(); | 364 | draw(); |
389 | break; | 365 | break; |
390 | } | 366 | } |
391 | } | 367 | } |
392 | } | 368 | } |
393 | 369 | ||
394 | void SFCave :: handleGameSFCave() | 370 | void SFCave :: handleGameSFCave() |
395 | { | 371 | { |
396 | // Update score | 372 | // Update score |
397 | if ( nrFrames % 5 == 0 ) | 373 | if ( nrFrames % 5 == 0 ) |
398 | score ++; | 374 | score ++; |
399 | 375 | ||
400 | if ( nrFrames % 500 == 0 ) | 376 | if ( nrFrames % 500 == 0 ) |
401 | { | 377 | { |
402 | if ( maxHeight < sHeight - 100 ) | 378 | if ( maxHeight < sHeight - 100 ) |
403 | { | 379 | { |
404 | maxHeight += 10; | 380 | maxHeight += 10; |
405 | 381 | ||
406 | // Reduce block height | 382 | // Reduce block height |
407 | if ( maxHeight > sHeight - 150 ) | 383 | if ( maxHeight > sHeight - 150 ) |
408 | blockHeight -= 5; | 384 | blockHeight -= 5; |
409 | } | 385 | } |
410 | } | 386 | } |
411 | 387 | ||
412 | if ( nrFrames % gateDistance == 0 ) | 388 | if ( nrFrames % gateDistance == 0 ) |
413 | addBlock(); | 389 | addBlock(); |
414 | 390 | ||
415 | if ( checkCollision() ) | 391 | if ( checkCollision() ) |
416 | { | 392 | { |
417 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 393 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
418 | { | 394 | { |
419 | highestScore[currentGameType][currentGameDifficulty] = score; | 395 | highestScore[currentGameType][currentGameDifficulty] = score; |
420 | saveScore(); | 396 | saveScore(); |
421 | } | 397 | } |
422 | state = STATE_CRASHING; | 398 | state = STATE_CRASHING; |
423 | } | 399 | } |
424 | else | 400 | else |
425 | { | 401 | { |
426 | moveLandscape(); | 402 | moveLandscape(); |
427 | } | 403 | } |
428 | 404 | ||
429 | } | 405 | } |
430 | 406 | ||
431 | 407 | ||
432 | void SFCave :: handleGameGates() | 408 | void SFCave :: handleGameGates() |
433 | { | 409 | { |
434 | // Update score | 410 | // Update score |
435 | if ( nrFrames % 5 == 0 ) | 411 | if ( nrFrames % 5 == 0 ) |
436 | score ++; | 412 | score ++; |
437 | 413 | ||
438 | // Slightly random gap distance | 414 | // Slightly random gap distance |
439 | if ( nrFrames >= nextGate ) | 415 | if ( nrFrames >= nextGate ) |
440 | { | 416 | { |
441 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; | 417 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; |
442 | addGate(); | 418 | addGate(); |
443 | } | 419 | } |
444 | 420 | ||
445 | if ( nrFrames % 500 == 0 ) | 421 | if ( nrFrames % 500 == 0 ) |
446 | { | 422 | { |
447 | if ( gapHeight > 75 ) | 423 | if ( gapHeight > 75 ) |
448 | gapHeight -= 5; | 424 | gapHeight -= 5; |
449 | } | 425 | } |
450 | 426 | ||
451 | if ( checkCollision() ) | 427 | if ( checkCollision() ) |
452 | { | 428 | { |
453 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 429 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
454 | { | 430 | { |
455 | highestScore[currentGameType][currentGameDifficulty] = score; | 431 | highestScore[currentGameType][currentGameDifficulty] = score; |
456 | saveScore(); | 432 | saveScore(); |
457 | } | 433 | } |
458 | state = STATE_CRASHING; | 434 | state = STATE_CRASHING; |
459 | } | 435 | } |
460 | else | 436 | else |
461 | { | 437 | { |
462 | moveLandscape(); | 438 | moveLandscape(); |
463 | } | 439 | } |
464 | 440 | ||
465 | } | 441 | } |
466 | 442 | ||
467 | void SFCave :: handleGameFly() | 443 | void SFCave :: handleGameFly() |
468 | { | 444 | { |
469 | int diff = mapBottom[10] - user.y(); | 445 | int diff = mapBottom[10] - user.y(); |
470 | 446 | ||
471 | if ( nrFrames % 4 == 0 ) | 447 | if ( nrFrames % 4 == 0 ) |
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h index b1fe819..7bdf881 100644 --- a/noncore/games/sfcave/sfcave.h +++ b/noncore/games/sfcave/sfcave.h | |||
@@ -1,131 +1,137 @@ | |||
1 | #include <qmainwindow.h> | 1 | #include <qmainwindow.h> |
2 | #include <qpainter.h> | 2 | #include <qpainter.h> |
3 | #include <qpixmap.h> | 3 | #include <qpixmap.h> |
4 | #include <qpoint.h> | 4 | #include <qpoint.h> |
5 | #include <qrect.h> | 5 | #include <qrect.h> |
6 | #include <qtimer.h> | 6 | #include <qtimer.h> |
7 | #include <qlist.h> | 7 | #include <qlist.h> |
8 | 8 | ||
9 | #include "random.h" | 9 | #include "random.h" |
10 | 10 | ||
11 | #define MAPSIZE 52 | 11 | #define MAPSIZE 52 |
12 | #define BLOCKSIZE 6 | 12 | #define BLOCKSIZE 6 |
13 | #define TRAILSIZE 30 | 13 | #define TRAILSIZE 30 |
14 | 14 | ||
15 | #define NR_MENUS 3 | 15 | #define NR_MENUS 3 |
16 | #define MAX_MENU_OPTIONS 8 | 16 | #define MAX_MENU_OPTIONS 8 |
17 | 17 | ||
18 | class SFCave : public QMainWindow | 18 | class SFCave : public QMainWindow |
19 | { | 19 | { |
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | 21 | ||
22 | public: | 22 | public: |
23 | int sWidth; | 23 | int sWidth; |
24 | int sHeight; | 24 | int sHeight; |
25 | int segSize; | 25 | int segSize; |
26 | 26 | ||
27 | int currentSeed; | 27 | int currentSeed; |
28 | 28 | ||
29 | QList<int> replayList; | 29 | QList<int> replayList; |
30 | QListIterator<int> *replayIt; | 30 | QListIterator<int> *replayIt; |
31 | bool replay; | 31 | bool replay; |
32 | QString replayFile; | 32 | QString replayFile; |
33 | 33 | ||
34 | int blockWidth; | 34 | int blockWidth; |
35 | int blockHeight; | 35 | int blockHeight; |
36 | int gapHeight; | 36 | int gapHeight; |
37 | int state; | 37 | int state; |
38 | int prevState; | 38 | int prevState; |
39 | int speed; | 39 | int speed; |
40 | int crashLineLength; | 40 | int crashLineLength; |
41 | bool startScoring; | 41 | bool startScoring; |
42 | bool showEyeCandy; | 42 | bool showEyeCandy; |
43 | 43 | ||
44 | static double UpThrustVals[3][3]; | 44 | static double UpThrustVals[3][3]; |
45 | static double DownThrustVals[3][3]; | 45 | static double DownThrustVals[3][3]; |
46 | static double MaxUpThrustVals[3][3]; | 46 | static double MaxUpThrustVals[3][3]; |
47 | static double MaxDownThrustVals[3][3]; | 47 | static double MaxDownThrustVals[3][3]; |
48 | static int initialGateGaps[]; | 48 | static int initialGateGaps[]; |
49 | 49 | ||
50 | static int flyEasyScores[7][3]; | 50 | static int flyEasyScores[7][3]; |
51 | static int flyNormalScores[7][3]; | 51 | static int flyNormalScores[7][3]; |
52 | static int flyHardScores[7][3]; | 52 | static int flyHardScores[7][3]; |
53 | int *flyScores; | 53 | int *flyScores; |
54 | 54 | ||
55 | 55 | ||
56 | double thrustUp; | 56 | double thrustUp; |
57 | double noThrust; | 57 | double noThrust; |
58 | double maxUpThrust; | 58 | double maxUpThrust; |
59 | double maxDownThrust; | 59 | double maxDownThrust; |
60 | 60 | ||
61 | int gateDistance; | 61 | int gateDistance; |
62 | int nextGate; | 62 | int nextGate; |
63 | int lastGateBottomY; | 63 | int lastGateBottomY; |
64 | 64 | ||
65 | static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS]; | 65 | static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS]; |
66 | int currentMenuNr; | 66 | int currentMenuNr; |
67 | static int nrMenuOptions[NR_MENUS]; | 67 | static int nrMenuOptions[NR_MENUS]; |
68 | static int currentMenuOption[NR_MENUS]; | 68 | static int currentMenuOption[NR_MENUS]; |
69 | 69 | ||
70 | static QString dificultyOption[3]; | 70 | static QString dificultyOption[3]; |
71 | static QString gameTypes[3]; | 71 | static QString gameTypes[3]; |
72 | int currentGameType; | 72 | int currentGameType; |
73 | int currentGameDifficulty; | 73 | int currentGameDifficulty; |
74 | 74 | ||
75 | QPixmap *offscreen; | 75 | QPixmap *offscreen; |
76 | QTimer *gameTimer; | 76 | QTimer *gameTimer; |
77 | 77 | ||
78 | int score; | 78 | int score; |
79 | int highestScore[3][3]; | 79 | int highestScore[3][3]; |
80 | 80 | ||
81 | int mapTop[MAPSIZE]; | 81 | int mapTop[MAPSIZE]; |
82 | int mapBottom[MAPSIZE]; | 82 | int mapBottom[MAPSIZE]; |
83 | QRect blocks[BLOCKSIZE]; | 83 | QRect blocks[BLOCKSIZE]; |
84 | QRect user; | 84 | QRect user; |
85 | QPoint trail[TRAILSIZE]; | 85 | QPoint trail[TRAILSIZE]; |
86 | 86 | ||
87 | int offset; | 87 | int offset; |
88 | int maxHeight; | 88 | int maxHeight; |
89 | int nrFrames; | 89 | int nrFrames; |
90 | int dir; | 90 | int dir; |
91 | 91 | ||
92 | bool showScoreZones; | 92 | bool showScoreZones; |
93 | 93 | ||
94 | bool press; | 94 | bool press; |
95 | double thrust; | 95 | double thrust; |
96 | bool running; | 96 | bool running; |
97 | 97 | ||
98 | SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); | 98 | SFCave( QWidget *p = 0, const char *name = 0, WFlags fl = 0 ); |
99 | ~SFCave(); | 99 | ~SFCave(); |
100 | |||
101 | static QString appName() { return QString::fromLatin1( QUICKAPP_NAME ); } | ||
102 | |||
103 | public slots: | ||
100 | void start(); | 104 | void start(); |
105 | public: | ||
106 | |||
101 | void setSeed( int seed ); | 107 | void setSeed( int seed ); |
102 | int nextInt( int range ); | 108 | int nextInt( int range ); |
103 | void setUp(); | 109 | void setUp(); |
104 | void handleGameSFCave(); | 110 | void handleGameSFCave(); |
105 | void handleGameGates(); | 111 | void handleGameGates(); |
106 | void handleGameFly(); | 112 | void handleGameFly(); |
107 | bool checkFlyGameCollision(); | 113 | bool checkFlyGameCollision(); |
108 | void moveFlyGameLandscape(); | 114 | void moveFlyGameLandscape(); |
109 | void setFlyPoint( int point ); | 115 | void setFlyPoint( int point ); |
110 | bool checkCollision(); | 116 | bool checkCollision(); |
111 | void moveLandscape(); | 117 | void moveLandscape(); |
112 | void addBlock(); | 118 | void addBlock(); |
113 | void addGate(); | 119 | void addGate(); |
114 | void setPoint( int point ); | 120 | void setPoint( int point ); |
115 | void drawBoss(); | 121 | void drawBoss(); |
116 | void draw(); | 122 | void draw(); |
117 | void handleKeys(); | 123 | void handleKeys(); |
118 | 124 | ||
119 | void handleMenuKeys( QKeyEvent * e ); | 125 | void handleMenuKeys( QKeyEvent * e ); |
120 | void displayMenu(); | 126 | void displayMenu(); |
121 | void dealWithMenuSelection(); | 127 | void dealWithMenuSelection(); |
122 | 128 | ||
123 | void keyPressEvent( QKeyEvent *e ); | 129 | void keyPressEvent( QKeyEvent *e ); |
124 | void keyReleaseEvent( QKeyEvent *e ); | 130 | void keyReleaseEvent( QKeyEvent *e ); |
125 | void saveScore(); | 131 | void saveScore(); |
126 | void saveReplay(); | 132 | void saveReplay(); |
127 | void loadReplay(); | 133 | void loadReplay(); |
128 | 134 | ||
129 | private slots: | 135 | private slots: |
130 | void run(); | 136 | void run(); |
131 | }; | 137 | }; |
diff --git a/noncore/games/sfcave/sfcave.pro b/noncore/games/sfcave/sfcave.pro index a0df828..3a26a79 100644 --- a/noncore/games/sfcave/sfcave.pro +++ b/noncore/games/sfcave/sfcave.pro | |||
@@ -1,13 +1,10 @@ | |||
1 | TEMPLATE= app | 1 | CONFIG += qt quick-app |
2 | CONFIG += qt warn_on | ||
3 | DESTDIR = $(OPIEDIR)/bin | ||
4 | SOURCES = sfcave.cpp helpwindow.cpp random.cpp | 2 | SOURCES = sfcave.cpp helpwindow.cpp random.cpp |
5 | HEADERS = sfcave.h helpwindow.h random.h | 3 | HEADERS = sfcave.h helpwindow.h random.h |
6 | TARGET = sfcave | 4 | TARGET = sfcave |
7 | INCLUDEPATH += $(OPIEDIR)/include | 5 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH+= $(OPIEDIR)/include | 6 | DEPENDPATH+= $(OPIEDIR)/include |
9 | LIBS += -lqpe | 7 | LIBS += -lqpe |
10 | 8 | ||
11 | 9 | ||
12 | |||
13 | include ( $(OPIEDIR)/include.pro ) | 10 | include ( $(OPIEDIR)/include.pro ) |