Diffstat (limited to 'noncore/games/sfcave-sdl/gates_game.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/gates_game.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp index 1a9bc89..762801d 100644 --- a/noncore/games/sfcave-sdl/gates_game.cpp +++ b/noncore/games/sfcave-sdl/gates_game.cpp | |||
@@ -1,128 +1,141 @@ | |||
1 | #include "SDL_gfxPrimitives.h" | 1 | #include "SDL_gfxPrimitives.h" |
2 | 2 | ||
3 | #include "constants.h" | 3 | #include "constants.h" |
4 | #include "gates_game.h" | 4 | #include "gates_game.h" |
5 | #include "random.h" | 5 | #include "random.h" |
6 | 6 | ||
7 | GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) | 7 | GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) |
8 | : Game( p, w, h, diff ) | 8 | : Game( p, w, h, diff ) |
9 | { | 9 | { |
10 | gameName = "Gates"; | 10 | gameName = "Gates"; |
11 | difficulty = MENU_DIFFICULTY_EASY; | 11 | difficulty = MENU_DIFFICULTY_EASY; |
12 | blockUpdateRate = 200; | 12 | blockUpdateRate = 200; |
13 | 13 | ||
14 | terrain = new Terrain( w, h ); | 14 | terrain = new Terrain( w, h ); |
15 | player = new Player( w, h ); | 15 | player = new Player( w, h ); |
16 | highScore = 0; | 16 | highScore = 0; |
17 | } | 17 | } |
18 | 18 | ||
19 | GatesGame :: ~GatesGame() | 19 | GatesGame :: ~GatesGame() |
20 | { | 20 | { |
21 | // terrain and player get deleted by parent class | ||
21 | } | 22 | } |
22 | 23 | ||
23 | void GatesGame :: init() | 24 | void GatesGame :: init() |
24 | { | 25 | { |
25 | Game :: init(); | 26 | Game :: init(); |
26 | 27 | ||
27 | blockHeight = 80; | 28 | blockHeight = 80; |
28 | blockWidth = 20; | 29 | blockWidth = 20; |
29 | lastGateBottomY = 0; | 30 | lastGateBottomY = 0; |
30 | 31 | ||
31 | gateDistance = 75; | 32 | gateDistance = 75; |
32 | nextGate = nextInt( 50 ) + gateDistance; | 33 | nextGate = nextInt( 50 ) + gateDistance; |
33 | gapHeight = 75; | 34 | gapHeight = 75; |
34 | 35 | ||
35 | switch( difficulty ) | 36 | switch( difficulty ) |
36 | { | 37 | { |
37 | case MENU_DIFFICULTY_EASY: | 38 | case MENU_DIFFICULTY_EASY: |
38 | gapHeight = 75; | 39 | gapHeight = 75; |
39 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); | 40 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); |
40 | break; | 41 | break; |
41 | case MENU_DIFFICULTY_NORMAL: | 42 | case MENU_DIFFICULTY_NORMAL: |
42 | gapHeight = 50; | 43 | gapHeight = 50; |
43 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); | 44 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); |
44 | break; | 45 | break; |
45 | case MENU_DIFFICULTY_HARD: | 46 | case MENU_DIFFICULTY_HARD: |
46 | gapHeight = 25; | 47 | gapHeight = 25; |
47 | player->setMovementInfo( 0.6, 0.8, 6, 7 ); | 48 | player->setMovementInfo( 0.6, 0.8, 6, 7 ); |
48 | break; | 49 | break; |
50 | case MENU_DIFFICULTY_CUSTOM: | ||
51 | { | ||
52 | // Read custom difficulty settings for this game | ||
53 | gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); | ||
54 | |||
55 | double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); | ||
56 | double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); | ||
57 | double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); | ||
58 | double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); | ||
59 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
60 | |||
61 | break; | ||
62 | } | ||
49 | } | 63 | } |
50 | 64 | ||
51 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 65 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
52 | blocks[i].y( -1 ); | 66 | blocks[i].y( -1 ); |
53 | } | 67 | } |
54 | 68 | ||
55 | void GatesGame :: update( int state ) | 69 | void GatesGame :: update( int state ) |
56 | { | 70 | { |
57 | Game::update( state ); | 71 | Game::update( state ); |
58 | 72 | ||
59 | // Game logic goes here | 73 | // Game logic goes here |
60 | if ( state == STATE_PLAYING ) | 74 | if ( state == STATE_PLAYING ) |
61 | { | 75 | { |
62 | if ( nrFrames % 3 == 0 ) | 76 | if ( nrFrames % 3 == 0 ) |
63 | score ++; | 77 | score ++; |
64 | 78 | ||
65 | if ( nrFrames % 500 == 0 ) | 79 | if ( nrFrames % 500 == 0 ) |
66 | { | 80 | { |
67 | if ( gapHeight > 75 ) | 81 | if ( gapHeight > 75 ) |
68 | gapHeight -= 5; | 82 | gapHeight -= 5; |
69 | } | 83 | } |
70 | 84 | ||
71 | // Slightly random gap distance | 85 | // Slightly random gap distance |
72 | if ( nrFrames >= nextGate ) | 86 | if ( nrFrames >= nextGate ) |
73 | { | 87 | { |
74 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; | 88 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; |
75 | addGate(); | 89 | addGate(); |
76 | } | 90 | } |
77 | 91 | ||
78 | if ( checkCollisions() ) | 92 | if ( checkCollisions() ) |
79 | { | 93 | { |
80 | // printf( "Crashed!\n" ); | ||
81 | parent->changeState( STATE_CRASHING ); | 94 | parent->changeState( STATE_CRASHING ); |
82 | return; | 95 | return; |
83 | } | 96 | } |
84 | 97 | ||
85 | terrain->moveTerrain( 5 ); | 98 | terrain->moveTerrain( 5 ); |
86 | moveBlocks( 5 ); | 99 | moveBlocks( 5 ); |
87 | player->move( press ); | 100 | player->move( press ); |
88 | } | 101 | } |
89 | } | 102 | } |
90 | 103 | ||
91 | void GatesGame :: draw( SDL_Surface *screen ) | 104 | void GatesGame :: draw( SDL_Surface *screen ) |
92 | { | 105 | { |
93 | Game::preDraw( screen ); | 106 | Game::preDraw( screen ); |
94 | 107 | ||
95 | if ( parent->getState() == STATE_PLAYING ) | 108 | if ( parent->getState() == STATE_PLAYING ) |
96 | { | 109 | { |
97 | // Screen drawing goes here | 110 | // Screen drawing goes here |
98 | terrain->drawTerrain( screen ); | 111 | terrain->drawTerrain( screen ); |
99 | 112 | ||
100 | player->draw( screen ); | 113 | player->draw( screen ); |
101 | 114 | ||
102 | drawBlocks( screen ); | 115 | drawBlocks( screen ); |
103 | } | 116 | } |
104 | else | 117 | else |
105 | { | 118 | { |
106 | // Screen drawing goes here | 119 | // Screen drawing goes here |
107 | terrain->drawTerrain( screen ); | 120 | terrain->drawTerrain( screen ); |
108 | 121 | ||
109 | drawBlocks( screen ); | 122 | drawBlocks( screen ); |
110 | 123 | ||
111 | player->draw( screen ); | 124 | player->draw( screen ); |
112 | } | 125 | } |
113 | 126 | ||
114 | Game::draw( screen ); | 127 | Game::draw( screen ); |
115 | } | 128 | } |
116 | 129 | ||
117 | 130 | ||
118 | void GatesGame :: addGate() | 131 | void GatesGame :: addGate() |
119 | { | 132 | { |
120 | printf( "gapHeight = %d\n", gapHeight ); | 133 | printf( "gapHeight = %d\n", gapHeight ); |
121 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 134 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
122 | { | 135 | { |
123 | if ( blocks[i].y() == -1 ) | 136 | if ( blocks[i].y() == -1 ) |
124 | { | 137 | { |
125 | int x1 = sWidth; | 138 | int x1 = sWidth; |
126 | int y1 = terrain->getMapTop(50); | 139 | int y1 = terrain->getMapTop(50); |
127 | int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight); | 140 | int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight); |
128 | 141 | ||