summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave/sfcave.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/sfcave/sfcave.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp75
1 files changed, 61 insertions, 14 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 @@
#include <math.h>
+#include <time.h>
@@ -28,2 +29,3 @@
#define STATE_MENU 5
+#define STATE_REPLAY 6
@@ -129,2 +131,3 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
{
+ replayIt = 0;
#ifdef QWS
@@ -166,4 +169,6 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
- setUp();
+// setUp();
crashLineLength = -1;
+ state = STATE_MENU;
+ prevState = STATE_MENU;
@@ -184,5 +189,17 @@ void SFCave :: start()
+void SFCave :: setSeed( int seed )
+{
+ if ( seed == -1 )
+ currentSeed = ((unsigned long) time((time_t *) NULL));
+ else
+ currentSeed = seed;
+ PutSeed( currentSeed );
+}
+
int SFCave :: nextInt( int range )
{
- return rand() % range;
+ int val = (int)(Random( ) * range);
+
+ return val;
+
}
@@ -191,5 +208,2 @@ void SFCave :: setUp()
{
- state = STATE_MENU;
- prevState = STATE_MENU;
-
score = 0;
@@ -223,2 +237,3 @@ void SFCave :: setUp()
crashLineLength = 0;
+ lastGateBottomY = 0;
@@ -256,2 +271,3 @@ void SFCave :: setUp()
blocks[i].setY( -1 );
+
}
@@ -266,2 +282,3 @@ void SFCave :: run()
case STATE_NEWGAME:
+ setSeed( -1 );
setUp();
@@ -269,3 +286,14 @@ void SFCave :: run()
state = STATE_RUNNING;
+ replay = false;
+ replayList.clear();
break;
+ case STATE_REPLAY:
+ setSeed( currentSeed );
+ setUp();
+ draw();
+ state = STATE_RUNNING;
+ replay = true;
+ if ( replayIt )
+ delete replayIt;
+ replayIt = new QListIterator<int>( replayList );
case STATE_BOSS:
@@ -286,2 +314,12 @@ void SFCave :: run()
nrFrames ++;
+
+ if ( replay )
+ {
+ while( replayIt->current() && *(replayIt->current()) == nrFrames )
+ {
+ press = !press;
+ ++(*replayIt);
+ }
+ }
+
if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
@@ -525,5 +563,5 @@ void SFCave :: addGate()
// See if height between last gate and this one is too big
- if ( b1Height - 200 > lastGateBottomY )
+ if ( b1Height - 100 > lastGateBottomY )
b1Height -= 25;
- else if ( b1Height + 200 < lastGateBottomY )
+ else if ( b1Height + 100 < lastGateBottomY )
b1Height += 25;
@@ -531,2 +569,3 @@ void SFCave :: addGate()
+
int x2 = sWidth;
@@ -775,3 +814,7 @@ void SFCave :: keyPressEvent( QKeyEvent *e )
case Qt::Key_Space:
+ if ( !press )
+ {
press = true;
+ replayList.append( new int( nrFrames ) );
+ }
break;
@@ -806,18 +849,22 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e )
case Qt::Key_Space:
- press = false;
- break;
-
case Qt::Key_Up:
+ if ( press )
+ {
press = false;
+ replayList.append( new int( nrFrames ) );
+ }
+ break;
+
case Qt::Key_R:
- case Qt::Key_Down:
if ( state == STATE_CRASHED )
{
- state = STATE_NEWGAME;
+ state = STATE_REPLAY;
}
- else
- movel = true;
break;
+ case Qt::Key_Down:
+ if ( state == STATE_CRASHED )
+ state = STATE_NEWGAME;
+ break;
default: