summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp19
-rw-r--r--noncore/games/sfcave/sfcave.h2
2 files changed, 11 insertions, 10 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index d6d28b2..9b30fe6 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -99,64 +99,65 @@ double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // S
double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave
{ -3.5, -4.0, -5.0 }, // Gates
{ -3.5, -4.0, -5.0 } }; // Fly
double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave
{ 4.0, 5.0, 5.5 }, // Gates
{ 3.5, 4.0, 5.0 } }; // Fly
int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 },
{ 10, 20, 3 },
{ 20, 30, 2 },
{ 30, 40, 1 },
{ 50, 70, -2 },
{ 70, 300, -5 },
{ -1, -1, -1 } };
int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 },
{ 10, 20, 3 },
{ 20, 30, 2 },
{ 30, 40, 1 },
{ 50, 70, -2 },
{ 70, 300, -5 },
{ -1, -1, -1 } };
int SFCave::flyHardScores[7][3] = { { 0, 20, 5 },
{ 20, 40, 3 },
{ 40, 100, 1 },
{ 100, 150, -2 },
{ 150, 300, -5 },
{ -1, -1, -1 } };
int SFCave::initialGateGaps[] = { 75, 50, 25 };
+#define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y))
bool movel;
int main( int argc, char *argv[] )
{
movel = true;
#ifdef QWS
QPEApplication a( argc, argv );
#else
QApplication a( argc, argv );
#endif
int speed = 3;
for ( int i = 0 ; i < argc ; ++i )
{
if ( strcmp( argv[i], "-s" ) == 0 )
{
if ( i+1 < argc )
speed = atoi( argv[i+1] );
}
}
SFCave app( speed );
a.setMainWidget( &app );
app.show();
app.start();
a.exec();
}
SFCave :: SFCave( int spd, QWidget *w, char *name )
: QMainWindow( w, name )
@@ -253,69 +254,69 @@ void SFCave :: setUp()
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 ( currentGameDifficulty == DIFICULTY_EASY )
gateDistance = 100;
else if ( currentGameDifficulty == DIFICULTY_NORMAL )
gateDistance = 60;
else
gateDistance = 40;
}
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];
if ( currentGameDifficulty == DIFICULTY_EASY )
- flyScores = flyEasyScores;
+ flyScores = (int*)flyEasyScores;
else if ( currentGameDifficulty == DIFICULTY_NORMAL )
- flyScores = flyNormalScores;
+ flyScores = (int*)flyNormalScores;
else
- flyScores = flyHardScores;
+ flyScores = (int*)flyHardScores;
}
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;
@@ -452,69 +453,69 @@ void SFCave :: handleGameGates()
if ( score > highestScore[currentGameType][currentGameDifficulty] )
{
highestScore[currentGameType][currentGameDifficulty] = score;
saveScore();
}
state = STATE_CRASHING;
}
else
{
moveLandscape();
}
}
void SFCave :: handleGameFly()
{
int diff = mapBottom[10] - user.y();
if ( nrFrames % 4 == 0 )
{
if ( !startScoring )
{
if ( diff < 40 )
startScoring = true;
}
if ( startScoring )
{
// Update score
// get distance between landscape and ship
// the closer the difference is to 0 means more points
- for ( int i = 0 ; i < 10 && flyScores[i][0] != -1 ; ++i )
+ for ( int i = 0 ; i < 10 && FLYSCORES( i, 0 ) != -1 ; ++i )
{
- if ( flyScores[i][0] <= diff && flyScores[i][1] > diff )
+ if ( FLYSCORES( i, 0 ) <= diff && FLYSCORES(i, 1 ) > diff )
{
- score += flyScores[i][2];
+ score += FLYSCORES( i, 2 );
break;
}
}
}
}
if ( checkFlyGameCollision() )
{
if ( score > highestScore[currentGameType][currentGameDifficulty] )
{
highestScore[currentGameType][currentGameDifficulty] = score;
saveScore();
}
state = STATE_CRASHING;
}
else
{
moveFlyGameLandscape();
}
}
bool SFCave :: checkFlyGameCollision()
{
if ( (user.y() + user.width()) >= mapBottom[11] )
return true;
return false;
}
void SFCave :: moveFlyGameLandscape()
{
offset++;
@@ -665,70 +666,70 @@ void SFCave :: setPoint( int point )
// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
}
void SFCave :: drawBoss()
{
offscreen->fill( Qt::black );
bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
}
void SFCave :: draw()
{
//printf( "Paint\n" );
offscreen->fill( Qt::black );
QPainter p( offscreen );
QFontMetrics fm = p.fontMetrics();
p.setPen( Qt::white );
for ( int i = 0 ; i < MAPSIZE -3; ++i )
{
// Only display top landscape if not running FLY_GAME
if ( CURRENT_GAME_TYPE != FLY_GAME )
p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] );
p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] );
if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones )
{
p.setPen( Qt::blue );
- for ( int j = 1 ; j < 10 && flyScores[j][0] != -1 ; ++j )
+ for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j )
{
- if ( flyScores[j][2] < 0 )
+ if ( FLYSCORES( j, 2 ) < 0 )
p.setPen( Qt::red );
- p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-flyScores[j][0], ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-flyScores[j][0] );
+ p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) );
}
p.setPen( Qt::white );
}
}
// Uncomment this to show user segment (usful for checking collision boundary with landscape
// p.setPen( Qt::red );
// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight );
// p.setPen( Qt::white );
// Draw user
p.drawRect( user );
// Draw trails
for ( int i = 0 ; i < TRAILSIZE ; ++i )
if ( trail[i].x() >= 0 )
{
if ( showEyeCandy )
p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) );
p.drawRect( trail[i].x(), trail[i].y(), 2, 2 );
}
p.setPen( Qt::white );
// Draw blocks
for ( int i = 0 ; i < BLOCKSIZE ; ++i )
if ( blocks[i].y() != -1 )
{
p.fillRect( blocks[i], Qt::black );
p.drawRect( blocks[i] );
}
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h
index f95558d..b1fe819 100644
--- a/noncore/games/sfcave/sfcave.h
+++ b/noncore/games/sfcave/sfcave.h
@@ -21,65 +21,65 @@ Q_OBJECT
public:
int sWidth;
int sHeight;
int segSize;
int currentSeed;
QList<int> replayList;
QListIterator<int> *replayIt;
bool replay;
QString replayFile;
int blockWidth;
int blockHeight;
int gapHeight;
int state;
int prevState;
int speed;
int crashLineLength;
bool startScoring;
bool showEyeCandy;
static double UpThrustVals[3][3];
static double DownThrustVals[3][3];
static double MaxUpThrustVals[3][3];
static double MaxDownThrustVals[3][3];
static int initialGateGaps[];
static int flyEasyScores[7][3];
static int flyNormalScores[7][3];
static int flyHardScores[7][3];
- int flyScores[7][3];
+ int *flyScores;
double thrustUp;
double noThrust;
double maxUpThrust;
double maxDownThrust;
int gateDistance;
int nextGate;
int lastGateBottomY;
static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS];
int currentMenuNr;
static int nrMenuOptions[NR_MENUS];
static int currentMenuOption[NR_MENUS];
static QString dificultyOption[3];
static QString gameTypes[3];
int currentGameType;
int currentGameDifficulty;
QPixmap *offscreen;
QTimer *gameTimer;
int score;
int highestScore[3][3];
int mapTop[MAPSIZE];
int mapBottom[MAPSIZE];
QRect blocks[BLOCKSIZE];
QRect user;
QPoint trail[TRAILSIZE];