summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 929dc41..5633a8f 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -1,65 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef QWS
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#else
#include <qapplication.h>
#endif
#include <qdir.h>
#include "helpwindow.h"
#include "sfcave.h"
-#define CAPTION "SFCave 1.11 by AndyQ"
+#define CAPTION "SFCave 1.12 by AndyQ"
#define UP_THRUST 0.6
#define NO_THRUST 0.8
#define MAX_DOWN_THRUST 4.0
#define MAX_UP_THRUST -3.5
// States
#define STATE_BOSS 0
#define STATE_RUNNING 1
#define STATE_CRASHING 2
#define STATE_CRASHED 3
#define STATE_NEWGAME 4
#define STATE_MENU 5
#define STATE_REPLAY 6
// Menus
#define MENU_MAIN_MENU 0
#define MENU_OPTIONS_MENU 1
#define MENU_REPLAY_MENU 2
// Main Menu Options
#define MENU_START_GAME 0
#define MENU_REPLAY 1
#define MENU_OPTIONS 2
#define MENU_HELP 3
#define MENU_QUIT 4
// Option Menu Options
#define MENU_GAME_TYPE 0
#define MENU_GAME_DIFFICULTY 1
#define MENU_CLEAR_HIGHSCORES 2
#define MENU_BACK 3
// Replay Menu Options
#define MENU_REPLAY_START 0
#define MENU_REPLAY_LOAD 1
#define MENU_REPLAY_SAVE 2
#define MENU_REPLAY_BACK 3
#define NR_GAME_DIFFICULTIES 3
#define NR_GAME_TYPES 3
#define DIFICULTY_EASY 0
#define DIFICULTY_NORMAL 1
#define DIFICULTY_HARD 2
#define EASY "Easy"
#define NORMAL "Normal"
@@ -182,128 +182,138 @@ 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 )
+ gateDistance = 100;
+ else if ( currentCameDifficulty == 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];
- gateDistance = 75;
- nextGate = nextInt( 50 ) + gateDistance;
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();
draw();
state = STATE_RUNNING;
replay = false;
replayList.clear();
break;
case STATE_REPLAY:
setSeed( currentSeed );
setUp();
draw();
state = STATE_RUNNING;
@@ -323,97 +333,97 @@ void SFCave :: run()
case STATE_RUNNING:
{
if ( nrFrames % 2 == 0 )
handleKeys();
// Apply Game rules
nrFrames ++;
if ( replay )
{
while( replayIt->current() && *(replayIt->current()) == nrFrames )
{
press = !press;
++(*replayIt);
}
}
if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
handleGameSFCave();
else if ( CURRENT_GAME_TYPE == GATES_GAME )
handleGameGates();
else if ( CURRENT_GAME_TYPE == FLY_GAME )
handleGameFly();
draw();
break;
}
}
}
void SFCave :: handleGameSFCave()
{
// Update score
if ( nrFrames % 5 == 0 )
score ++;
if ( nrFrames % 500 == 0 )
{
if ( maxHeight < sHeight - 100 )
{
maxHeight += 10;
// Reduce block height
if ( maxHeight > sHeight - 150 )
blockHeight -= 5;
}
}
- if ( nrFrames % 100 == 0 )
+ if ( nrFrames % gateDistance == 0 )
addBlock();
if ( checkCollision() )
{
if ( score > highestScore[currentGameType][currentGameDifficulty] )
{
highestScore[currentGameType][currentGameDifficulty] = score;
saveScore();
}
state = STATE_CRASHING;
}
else
{
moveLandscape();
}
}
void SFCave :: handleGameGates()
{
// Update score
if ( nrFrames % 5 == 0 )
score ++;
// Slightly random gap distance
if ( nrFrames >= nextGate )
{
nextGate = nrFrames + nextInt( 50 ) + gateDistance;
addGate();
}
if ( nrFrames % 500 == 0 )
{
if ( gapHeight > 75 )
gapHeight -= 5;
}
if ( checkCollision() )
{
if ( score > highestScore[currentGameType][currentGameDifficulty] )
{
highestScore[currentGameType][currentGameDifficulty] = score;
saveScore();
}
state = STATE_CRASHING;
}
else