Diffstat (limited to 'noncore/games/sfcave/sfcave.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index 788606f..b5bc736 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -3,2 +3,3 @@ | |||
3 | #include <math.h> | 3 | #include <math.h> |
4 | #include <time.h> | ||
4 | 5 | ||
@@ -28,2 +29,3 @@ | |||
28 | #define STATE_MENU 5 | 29 | #define STATE_MENU 5 |
30 | #define STATE_REPLAY 6 | ||
29 | 31 | ||
@@ -129,2 +131,3 @@ SFCave :: SFCave( int spd, QWidget *w, char *name ) | |||
129 | { | 131 | { |
132 | replayIt = 0; | ||
130 | #ifdef QWS | 133 | #ifdef QWS |
@@ -166,4 +169,6 @@ SFCave :: SFCave( int spd, QWidget *w, char *name ) | |||
166 | 169 | ||
167 | setUp(); | 170 | // setUp(); |
168 | crashLineLength = -1; | 171 | crashLineLength = -1; |
172 | state = STATE_MENU; | ||
173 | prevState = STATE_MENU; | ||
169 | 174 | ||
@@ -184,5 +189,17 @@ void SFCave :: start() | |||
184 | 189 | ||
190 | void SFCave :: setSeed( int seed ) | ||
191 | { | ||
192 | if ( seed == -1 ) | ||
193 | currentSeed = ((unsigned long) time((time_t *) NULL)); | ||
194 | else | ||
195 | currentSeed = seed; | ||
196 | PutSeed( currentSeed ); | ||
197 | } | ||
198 | |||
185 | int SFCave :: nextInt( int range ) | 199 | int SFCave :: nextInt( int range ) |
186 | { | 200 | { |
187 | return rand() % range; | 201 | int val = (int)(Random( ) * range); |
202 | |||
203 | return val; | ||
204 | |||
188 | } | 205 | } |
@@ -191,5 +208,2 @@ void SFCave :: setUp() | |||
191 | { | 208 | { |
192 | state = STATE_MENU; | ||
193 | prevState = STATE_MENU; | ||
194 | |||
195 | score = 0; | 209 | score = 0; |
@@ -223,2 +237,3 @@ void SFCave :: setUp() | |||
223 | crashLineLength = 0; | 237 | crashLineLength = 0; |
238 | lastGateBottomY = 0; | ||
224 | 239 | ||
@@ -256,2 +271,3 @@ void SFCave :: setUp() | |||
256 | blocks[i].setY( -1 ); | 271 | blocks[i].setY( -1 ); |
272 | |||
257 | } | 273 | } |
@@ -266,2 +282,3 @@ void SFCave :: run() | |||
266 | case STATE_NEWGAME: | 282 | case STATE_NEWGAME: |
283 | setSeed( -1 ); | ||
267 | setUp(); | 284 | setUp(); |
@@ -269,3 +286,14 @@ void SFCave :: run() | |||
269 | state = STATE_RUNNING; | 286 | state = STATE_RUNNING; |
287 | replay = false; | ||
288 | replayList.clear(); | ||
270 | break; | 289 | break; |
290 | case STATE_REPLAY: | ||
291 | setSeed( currentSeed ); | ||
292 | setUp(); | ||
293 | draw(); | ||
294 | state = STATE_RUNNING; | ||
295 | replay = true; | ||
296 | if ( replayIt ) | ||
297 | delete replayIt; | ||
298 | replayIt = new QListIterator<int>( replayList ); | ||
271 | case STATE_BOSS: | 299 | case STATE_BOSS: |
@@ -286,2 +314,12 @@ void SFCave :: run() | |||
286 | nrFrames ++; | 314 | nrFrames ++; |
315 | |||
316 | if ( replay ) | ||
317 | { | ||
318 | while( replayIt->current() && *(replayIt->current()) == nrFrames ) | ||
319 | { | ||
320 | press = !press; | ||
321 | ++(*replayIt); | ||
322 | } | ||
323 | } | ||
324 | |||
287 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 325 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
@@ -525,5 +563,5 @@ void SFCave :: addGate() | |||
525 | // See if height between last gate and this one is too big | 563 | // See if height between last gate and this one is too big |
526 | if ( b1Height - 200 > lastGateBottomY ) | 564 | if ( b1Height - 100 > lastGateBottomY ) |
527 | b1Height -= 25; | 565 | b1Height -= 25; |
528 | else if ( b1Height + 200 < lastGateBottomY ) | 566 | else if ( b1Height + 100 < lastGateBottomY ) |
529 | b1Height += 25; | 567 | b1Height += 25; |
@@ -531,2 +569,3 @@ void SFCave :: addGate() | |||
531 | 569 | ||
570 | |||
532 | int x2 = sWidth; | 571 | int x2 = sWidth; |
@@ -775,3 +814,7 @@ void SFCave :: keyPressEvent( QKeyEvent *e ) | |||
775 | case Qt::Key_Space: | 814 | case Qt::Key_Space: |
776 | press = true; | 815 | if ( !press ) |
816 | { | ||
817 | press = true; | ||
818 | replayList.append( new int( nrFrames ) ); | ||
819 | } | ||
777 | break; | 820 | break; |
@@ -806,18 +849,22 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e ) | |||
806 | case Qt::Key_Space: | 849 | case Qt::Key_Space: |
807 | press = false; | 850 | case Qt::Key_Up: |
851 | if ( press ) | ||
852 | { | ||
853 | press = false; | ||
854 | |||
855 | replayList.append( new int( nrFrames ) ); | ||
856 | } | ||
808 | break; | 857 | break; |
809 | 858 | ||
810 | case Qt::Key_Up: | ||
811 | press = false; | ||
812 | |||
813 | case Qt::Key_R: | 859 | case Qt::Key_R: |
814 | case Qt::Key_Down: | ||
815 | if ( state == STATE_CRASHED ) | 860 | if ( state == STATE_CRASHED ) |
816 | { | 861 | { |
817 | state = STATE_NEWGAME; | 862 | state = STATE_REPLAY; |
818 | } | 863 | } |
819 | else | ||
820 | movel = true; | ||
821 | break; | 864 | break; |
822 | 865 | ||
866 | case Qt::Key_Down: | ||
867 | if ( state == STATE_CRASHED ) | ||
868 | state = STATE_NEWGAME; | ||
869 | break; | ||
823 | default: | 870 | default: |