1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include <SDL/SDL_gfxPrimitives.h>
#include "constants.h"
#include "fly_game.h"
#include "random.h"
FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
: Game( p, w, h, diff )
{
gameName = "Fly";
difficulty = MENU_DIFFICULTY_EASY;
terrain = new FlyTerrain( w, h );
player = new Player( w, h );
highScore = 0;
}
FlyGame :: ~FlyGame()
{
// terrain and player get deleted by parent class
}
void FlyGame :: init()
{
switch( difficulty )
{
case MENU_DIFFICULTY_EASY:
player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
break;
case MENU_DIFFICULTY_NORMAL:
player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
break;
case MENU_DIFFICULTY_HARD:
player->setMovementInfo( 0.4, 0.6, 4, 5 );
break;
case MENU_DIFFICULTY_CUSTOM:
{
double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 );
double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 );
double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 );
double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 );
player->setMovementInfo( thrust, gravity, maxUp, maxDown );
break;
}
}
startScoring = false;
Game :: init();
}
void FlyGame :: update( int state )
{
Game::update( state );
if ( state == STATE_PLAYING )
{
if ( nrFrames % 3 == 0 )
{
int diff = terrain->getMapBottom( 10 ) - player->getY();
int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
if ( !startScoring )
{
if ( tmpScore > 0 )
startScoring = true;
}
if ( startScoring )
{
// Update score
// get distance between landscape and ship
// the closer the difference is to 0 means more points
score += tmpScore;
}
}
if ( checkCollisions() )
{
parent->changeState( STATE_CRASHING );
return;
}
// Game logic goes here
terrain->moveTerrain( 5 );
player->move( press );
}
}
void FlyGame :: draw( SDL_Surface *screen )
{
Game::preDraw( screen );
// Screen drawing goes here
terrain->drawTerrain( screen );
player->draw( screen );
Game::draw( screen );
}
bool FlyGame :: checkCollisions()
{
bool ret = false;
// Check collision with landscape
return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
}
|