author | andyq <andyq> | 2003-01-20 23:11:56 (UTC) |
---|---|---|
committer | andyq <andyq> | 2003-01-20 23:11:56 (UTC) |
commit | 92419b025aa5d82bb7592281af5505ff931c2e58 (patch) (unidiff) | |
tree | 374ee9ca86ef716ce388c8a28e38261f6a04ce7a /noncore/games/sfcave-sdl/fly_game.cpp | |
parent | 02090d2e63ad8398c0a8a9f1fb895a9c6e42514b (diff) | |
download | opie-92419b025aa5d82bb7592281af5505ff931c2e58.zip opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.gz opie-92419b025aa5d82bb7592281af5505ff931c2e58.tar.bz2 |
Initial Revision
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.cpp | 103 |
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 | |||
7 | FlyGame :: 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 | |||
18 | FlyGame :: ~FlyGame() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | void 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 | |||
42 | void 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 | |||
83 | void 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 | |||
96 | bool 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 | } | ||