-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 105 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.h | 8 |
2 files changed, 93 insertions, 20 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index c1e4532..d6d28b2 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp @@ -1,41 +1,41 @@ #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.12 by AndyQ" +#define CAPTION "SFCave 1.13 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 @@ -83,48 +83,69 @@ QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Rep int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; #define UP_THRUST 0.6 #define NO_THRUST 0.8 #define MAX_DOWN_THRUST 4.0 #define MAX_UP_THRUST -3.5 double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave { 0.6, 0.6, 0.8 }, // Gates { 0.4, 0.7, 1.0 } }; // Fly double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave { 0.8, 0.8, 1.0 }, // Gates { 0.4, 0.7, 1.0 } }; // Fly 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 }; 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] ); } } @@ -157,126 +178,136 @@ SFCave :: SFCave( int spd, QWidget *w, char *name ) currentMenuNr = 0; currentGameType = 0; currentGameDifficulty = 0; setCaption( CAPTION ); showScoreZones = false; #ifdef QWS 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; + showEyeCandy = 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; + startScoring = false; + press = false; 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_EASY ) + 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; + else if ( currentGameDifficulty == DIFICULTY_NORMAL ) + flyScores = flyNormalScores; + else + flyScores = 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 ) @@ -297,54 +328,56 @@ void SFCave :: setUp() 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; replay = true; if ( replayIt ) delete replayIt; replayIt = new QListIterator<int>( replayList ); + break; case STATE_BOSS: drawBoss(); break; case STATE_CRASHING: case STATE_CRASHED: + press = false; draw(); break; 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(); @@ -411,63 +444,73 @@ void SFCave :: handleGameGates() 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 { 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 - int diff = mapBottom[10] - user.y(); // the closer the difference is to 0 means more points - if ( diff < 10 ) - score += 5; - else if ( diff < 20 ) - score += 3; - else if ( diff < 30 ) - score += 2; - else if ( diff < 40 ) - score += 1; + for ( int i = 0 ; i < 10 && flyScores[i][0] != -1 ; ++i ) + { + if ( flyScores[i][0] <= diff && flyScores[i][1] > diff ) + { + 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; } @@ -629,70 +672,79 @@ 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 ) + { + if ( flyScores[j][2] < 0 ) p.setPen( Qt::red ); - p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 ); - p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 ); - p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 ); - p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 ); + + 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] ); } // draw score QString s; s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); p.drawText( 5, 10, s ); if ( state == STATE_CRASHING || state == STATE_CRASHED ) { // add next crash line if ( crashLineLength != -1 ) { for ( int i = 0 ; i < 36 ; ++i ) { int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); @@ -767,101 +819,114 @@ void SFCave :: handleKeys() 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 ( state == STATE_RUNNING && !replay && !press ) + if ( state == STATE_RUNNING ) + { + if ( !replay && !press ) { press = true; replayList.append( new int( nrFrames ) ); } - else if ( state == STATE_CRASHED && e->key() == Key_Up ) + } + else if ( state == STATE_CRASHED ) + { + if ( 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 ( state == STATE_RUNNING ) + { + if ( !replay && press ) + { press = false; - if ( state == STATE_RUNNING && !replay && press ) replayList.append( new int( nrFrames ) ); + } + } + break; + case Qt::Key_E: + showEyeCandy = !showEyeCandy; 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; } } } diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h index 65e5ae4..f95558d 100644 --- a/noncore/games/sfcave/sfcave.h +++ b/noncore/games/sfcave/sfcave.h @@ -17,55 +17,63 @@ class SFCave : public QMainWindow { 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]; + + 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]; |