summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 5633a8f..c1e4532 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -182,112 +182,109 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
offscreen = new QPixmap( sWidth, sHeight );
offscreen->fill( Qt::black );
// setUp();
crashLineLength = -1;
state = STATE_MENU;
prevState = STATE_MENU;
gameTimer = new QTimer( this, "game timer" );
connect( gameTimer, SIGNAL( timeout() ),
this, SLOT( run() ) );
}
SFCave :: ~SFCave()
{
}
void SFCave :: start()
{
gameTimer->start( 10 );
}
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 )
{
int val = (int)(Random( ) * range);
return val;
}
void SFCave :: setUp()
{
score = 0;
offset = 0;
nrFrames = 0;
dir = 1;
thrust = 0;
- int dist[] = { 100, 60, 40 };
if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
{
thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
- if ( currentCameDifficulty == DIFICULTY_EASY )
+ if ( currentGameDifficulty == DIFICULTY_EASY )
gateDistance = 100;
- else if ( currentCameDifficulty == DIFICULTY_EASY )
+ else if ( currentGameDifficulty == DIFICULTY_EASY )
gateDistance = 60;
else
gateDistance = 40;
-
- printf( "GD = %d\n", gateDistance );
}
else if ( CURRENT_GAME_TYPE == GATES_GAME )
{
thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
gateDistance = 75;
nextGate = nextInt( 50 ) + gateDistance;
}
else
{
thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
}
crashLineLength = 0;
lastGateBottomY = 0;
user.setRect( 50, sWidth/2, 4, 4 );
blockWidth = 20;
blockHeight = 70;
gapHeight = initialGateGaps[currentGameDifficulty];
for ( int i = 0 ; i < TRAILSIZE ; ++i )
{
trail[i].setX( -1 );
trail[i].setY( 0 );
}
if ( CURRENT_GAME_TYPE != FLY_GAME )
{
maxHeight = 50;
mapTop[0] = (int)(nextInt(50)) + 5;
mapBottom[0] = (int)(nextInt(50)) + 5;
for ( int i = 1 ; i < MAPSIZE ; ++i )
setPoint( i );
}
else
{
maxHeight = 100;
for ( int i = 0 ; i < MAPSIZE ; ++i )
mapBottom[i] = sHeight - 10;
@@ -746,142 +743,142 @@ void SFCave :: handleKeys()
trail[i].setY( user.y() );
done = true;
}
}
else
{
trail[i].setX( trail[i].x() - (2) );
}
}
if ( speed <= 3 )
{
if ( press )
thrust -= thrustUp;
else
thrust += noThrust;
if ( thrust > maxDownThrust )
thrust = maxDownThrust;
else if ( thrust < maxUpThrust )
thrust = maxUpThrust;
}
else
{
if ( press )
thrust -= 0.5;
else
thrust += 0.8;
if ( thrust > 5.0 )
thrust = 5.0;
else if ( thrust < -3.5 )
thrust = -3.5;
}
user.moveBy( 0, (int)thrust );
}
void SFCave :: keyPressEvent( QKeyEvent *e )
{
if ( state == STATE_MENU )
handleMenuKeys( e );
else
{
switch( e->key() )
{
case Qt::Key_Up:
case Qt::Key_F9:
case Qt::Key_Space:
- if ( !replay && !press )
+ if ( state == STATE_RUNNING && !replay && !press )
{
press = true;
replayList.append( new int( nrFrames ) );
}
+ else if ( state == STATE_CRASHED && e->key() == Key_Up )
+ state = STATE_NEWGAME;
break;
case Qt::Key_M:
case Qt::Key_Return:
case Qt::Key_Enter:
if ( state == STATE_CRASHED )
{
state = STATE_MENU;
currentMenuNr = 0;
currentMenuOption[currentMenuNr] = 0;
}
break;
case Qt::Key_Z:
showScoreZones = !showScoreZones;
break;
default:
e->ignore();
break;
}
}
}
void SFCave :: keyReleaseEvent( QKeyEvent *e )
{
if ( state == STATE_MENU )
{
}
else
{
switch( e->key() )
{
case Qt::Key_F9:
case Qt::Key_Space:
case Qt::Key_Up:
- if ( !replay && press )
- {
- press = false;
-
+ press = false;
+ if ( state == STATE_RUNNING && !replay && press )
replayList.append( new int( nrFrames ) );
- }
+
break;
case Qt::Key_R:
if ( state == STATE_CRASHED )
{
state = STATE_REPLAY;
}
break;
case Qt::Key_Down:
if ( state == STATE_CRASHED )
state = STATE_NEWGAME;
break;
case Qt::Key_S:
if ( state == STATE_CRASHED )
saveReplay();
break;
case Qt::Key_L:
if ( state == STATE_CRASHED )
loadReplay();
break;
default:
e->ignore();
break;
}
}
}
void SFCave :: saveScore()
{
#ifdef QWS
Config cfg( "sfcave" );
cfg.setGroup( "settings" );
QString key = "highScore_";
cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] );
key += CURRENT_GAME_TYPE;
cfg.writeEntry( key, highestScore[currentGameType] );
#endif
}
void SFCave :: saveReplay()
{
FILE *out;