summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/fly_game.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/fly_game.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/fly_game.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp
new file mode 100644
index 0000000..f5ab401
--- a/dev/null
+++ b/noncore/games/sfcave-sdl/fly_game.cpp
@@ -0,0 +1,103 @@
1#include "SDL_gfxPrimitives.h"
2
3#include "constants.h"
4#include "fly_game.h"
5#include "random.h"
6
7FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff )
9{
10 gameName = "Fly";
11 difficulty = MENU_DIFFICULTY_EASY;
12
13 terrain = new FlyTerrain( w, h );
14 player = new Player( w, h );
15 highScore = 0;
16}
17
18FlyGame :: ~FlyGame()
19{
20}
21
22void FlyGame :: init()
23{
24 Game :: init();
25
26 switch( difficulty )
27 {
28 case MENU_DIFFICULTY_EASY:
29 player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
30 break;
31 case MENU_DIFFICULTY_NORMAL:
32 player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
33 break;
34 case MENU_DIFFICULTY_HARD:
35 player->setMovementInfo( 0.4, 0.6, 4, 5 );
36 break;
37 }
38
39 startScoring = false;
40}
41
42void FlyGame :: update( int state )
43{
44 Game::update( state );
45
46 if ( state == STATE_PLAYING )
47 {
48
49 if ( nrFrames % 3 == 0 )
50 {
51 int diff = terrain->getMapBottom( 10 ) - player->getY();
52 int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
53 // printf( "diff - %d score - %d\n", diff, tmpScore );
54 if ( !startScoring )
55 {
56 if ( tmpScore > 0 )
57 startScoring = true;
58 }
59
60 if ( startScoring )
61 {
62 // Update score
63 // get distance between landscape and ship
64
65 // the closer the difference is to 0 means more points
66 score += tmpScore;
67 }
68 }
69
70 if ( checkCollisions() )
71 {
72 // printf( "Crashed!\n" );
73 parent->changeState( STATE_CRASHING );
74 return;
75 }
76
77 // Game logic goes here
78 terrain->moveTerrain( 5 );
79 player->move( press );
80 }
81}
82
83void FlyGame :: draw( SDL_Surface *screen )
84{
85 Game::preDraw( screen );
86
87 // Screen drawing goes here
88 terrain->drawTerrain( screen );
89
90 player->draw( screen );
91
92 Game::draw( screen );
93}
94
95
96bool FlyGame :: checkCollisions()
97{
98 bool ret = false;
99
100 // Check collision with landscape
101
102 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
103}