summaryrefslogtreecommitdiff
authorandyq <andyq>2002-12-20 22:57:16 (UTC)
committer andyq <andyq>2002-12-20 22:57:16 (UTC)
commit12a964a2f8837ee981284f3ee902baae0c7b1f77 (patch) (side-by-side diff)
treec89f1e29e40f8aa1d0b1f2940b7227ce6c75bf01
parent48efd0d81aad0c3d0a64baabbc46fde593eb086c (diff)
downloadopie-12a964a2f8837ee981284f3ee902baae0c7b1f77.zip
opie-12a964a2f8837ee981284f3ee902baae0c7b1f77.tar.gz
opie-12a964a2f8837ee981284f3ee902baae0c7b1f77.tar.bz2
Fixed small bugette with cursor keys
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp17
1 files changed, 7 insertions, 10 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
@@ -166,144 +166,141 @@ SFCave :: SFCave( int spd, QWidget *w, char *name )
Config cfg( "sfcave" );
cfg.setGroup( "settings" );
QString key = "highScore_";
for ( int i = 0 ; i < 3 ; ++i )
{
for ( int j = 0 ; j < 3 ; ++j )
highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 );
}
currentGameType = cfg.readNumEntry( "gameType", 0 );
currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 );
#endif
speed = spd; // Change to 2 for PC
press = false;
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;
}
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
blocks[i].setY( -1 );
}
void SFCave :: run()
{
switch ( state )
{
case STATE_MENU:
displayMenu();
break;
case STATE_NEWGAME:
setSeed( -1 );
setUp();
@@ -730,174 +727,174 @@ void SFCave :: draw()
p.end();
bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
//printf( "endpaint\n" );
}
void SFCave :: handleKeys()
{
// Find enpty trail and move others
bool done = false;
for ( int i = 0 ; i < TRAILSIZE ; ++i )
{
if ( trail[i].x() < 0 )
{
if ( !done )
{
trail[i].setX( user.x() - 5 );
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;
-
+ 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;
out = fopen( (const char *)replayFile, "w" );
if ( !out )
{
printf( "Couldn't write to /home/root/sfcave.replay\n" );
return;
}
// Build up string of values
// Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>.......
QString val;
val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty );
QListIterator<int> it( replayList );
while( it.current() )
{
QString tmp;