summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave/sfcave.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/sfcave/sfcave.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp79
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
@@ -2,4 +2,5 @@
#include <stdlib.h>
#include <math.h>
+#include <time.h>
#ifdef QWS
@@ -27,4 +28,5 @@
#define STATE_NEWGAME 4
#define STATE_MENU 5
+#define STATE_REPLAY 6
// Menus
@@ -128,4 +130,5 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
{
+ replayIt = 0;
#ifdef QWS
showMaximized();
@@ -165,6 +168,8 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
offscreen->fill( Qt::black );
- setUp();
+// setUp();
crashLineLength = -1;
+ state = STATE_MENU;
+ prevState = STATE_MENU;
gameTimer = new QTimer( this, "game timer" );
@@ -183,14 +188,23 @@ 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;
+
}
void SFCave :: setUp()
{
- state = STATE_MENU;
- prevState = STATE_MENU;
-
score = 0;
offset = 0;
@@ -222,4 +236,5 @@ void SFCave :: setUp()
crashLineLength = 0;
+ lastGateBottomY = 0;
user.setRect( 50, sWidth/2, 4, 4 );
@@ -255,4 +270,5 @@ void SFCave :: setUp()
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
blocks[i].setY( -1 );
+
}
@@ -265,8 +281,20 @@ void SFCave :: run()
break;
case STATE_NEWGAME:
+ setSeed( -1 );
setUp();
draw();
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:
drawBoss();
@@ -285,4 +313,14 @@ void SFCave :: run()
// Apply Game rules
nrFrames ++;
+
+ if ( replay )
+ {
+ while( replayIt->current() && *(replayIt->current()) == nrFrames )
+ {
+ press = !press;
+ ++(*replayIt);
+ }
+ }
+
if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
handleGameSFCave();
@@ -524,10 +562,11 @@ 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;
lastGateBottomY = b1Height;
+
int x2 = sWidth;
int y2 = y1 + b1Height + gapHeight;
@@ -774,5 +813,9 @@ void SFCave :: keyPressEvent( QKeyEvent *e )
case Qt::Key_F9:
case Qt::Key_Space:
- press = true;
+ if ( !press )
+ {
+ press = true;
+ replayList.append( new int( nrFrames ) );
+ }
break;
case Qt::Key_M:
@@ -805,20 +848,24 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e )
case Qt::Key_F9:
case Qt::Key_Space:
- press = false;
+ case Qt::Key_Up:
+ if ( press )
+ {
+ press = false;
+
+ replayList.append( new int( nrFrames ) );
+ }
break;
- case Qt::Key_Up:
- press = false;
-
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:
e->ignore();