Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

fly_game.cpp

Go to the documentation of this file.
00001 #include <SDL/SDL_gfxPrimitives.h>
00002 
00003 #include "constants.h"
00004 #include "fly_game.h"
00005 #include "random.h"
00006 
00007 FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
00008         : Game( p, w, h, diff )
00009 {
00010         gameName = "Fly";
00011         difficulty = MENU_DIFFICULTY_EASY;
00012 
00013         terrain = new FlyTerrain( w, h );
00014         player = new Player( w, h );
00015         highScore = 0;
00016 }
00017 
00018 FlyGame :: ~FlyGame()
00019 {
00020         // terrain and player get deleted by parent class
00021 }
00022 
00023 void FlyGame :: init()
00024 {
00025         switch( difficulty )
00026         {
00027                 case MENU_DIFFICULTY_EASY:
00028                         player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
00029                         break;
00030                 case MENU_DIFFICULTY_NORMAL:
00031                         player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
00032                         break;
00033                 case MENU_DIFFICULTY_HARD:
00034                         player->setMovementInfo( 0.4, 0.6, 4, 5 );
00035                         break;
00036         case MENU_DIFFICULTY_CUSTOM:
00037         {
00038             double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 );
00039             double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 );
00040             double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 );
00041             double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 );
00042                         player->setMovementInfo( thrust, gravity, maxUp, maxDown );
00043             break;
00044         }
00045         }
00046 
00047         startScoring = false;
00048         Game :: init();
00049 }
00050 
00051 void FlyGame ::  update( int state )
00052 {
00053         Game::update( state );
00054 
00055         if ( state == STATE_PLAYING )
00056         {
00057 
00058                 if ( nrFrames % 3 == 0 )
00059                 {
00060                     int diff = terrain->getMapBottom( 10 ) - player->getY();
00061                         int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
00062 
00063                         if ( !startScoring )
00064                         {
00065                                 if ( tmpScore > 0 )
00066                                         startScoring = true;
00067                         }
00068 
00069                         if ( startScoring )
00070                         {
00071                                 // Update score
00072                                 // get distance between landscape and ship
00073 
00074                                 // the closer the difference is to 0 means more points
00075                                 score += tmpScore;
00076                         }
00077                 }
00078 
00079                 if ( checkCollisions() )
00080                 {
00081                         parent->changeState( STATE_CRASHING );
00082                         return;
00083                 }
00084 
00085                 // Game logic goes here
00086                 terrain->moveTerrain( 5 );
00087                 player->move( press );
00088         }
00089 }
00090 
00091 void FlyGame :: draw( SDL_Surface *screen )
00092 {
00093         Game::preDraw( screen );
00094 
00095         // Screen drawing goes here
00096         terrain->drawTerrain( screen );
00097 
00098         player->draw( screen );
00099 
00100         Game::draw( screen );
00101 }
00102 
00103 
00104 bool FlyGame :: checkCollisions()
00105 {
00106         bool ret = false;
00107 
00108         // Check collision with landscape
00109 
00110         return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
00111 }

Generated on Sat Nov 5 16:17:24 2005 for OPIE by  doxygen 1.4.2