summaryrefslogtreecommitdiff
authorandyq <andyq>2003-01-21 21:09:36 (UTC)
committer andyq <andyq>2003-01-21 21:09:36 (UTC)
commit6b3b53262213e4e4f73ffab2266ea3b4a7813fe4 (patch) (unidiff)
tree896759614d5601570f259525c000a8be4db4d68d
parent0a6563fcc2f49857c581d9def24407a3a4ef526c (diff)
downloadopie-6b3b53262213e4e4f73ffab2266ea3b4a7813fe4.zip
opie-6b3b53262213e4e4f73ffab2266ea3b4a7813fe4.tar.gz
opie-6b3b53262213e4e4f73ffab2266ea3b4a7813fe4.tar.bz2
Small bug fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/fly_game.cpp3
-rw-r--r--noncore/games/sfcave-sdl/gates_game.cpp4
-rw-r--r--noncore/games/sfcave-sdl/player.cpp2
-rw-r--r--noncore/games/sfcave-sdl/sfcave_game.cpp4
4 files changed, 6 insertions, 7 deletions
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp
index 7605c3f..8b05d8f 100644
--- a/noncore/games/sfcave-sdl/fly_game.cpp
+++ b/noncore/games/sfcave-sdl/fly_game.cpp
@@ -1,112 +1,111 @@
1#include "SDL_gfxPrimitives.h" 1#include "SDL_gfxPrimitives.h"
2 2
3#include "constants.h" 3#include "constants.h"
4#include "fly_game.h" 4#include "fly_game.h"
5#include "random.h" 5#include "random.h"
6 6
7FlyGame :: FlyGame( SFCave *p, int w, int h, int diff ) 7FlyGame :: FlyGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff ) 8 : Game( p, w, h, diff )
9{ 9{
10 gameName = "Fly"; 10 gameName = "Fly";
11 difficulty = MENU_DIFFICULTY_EASY; 11 difficulty = MENU_DIFFICULTY_EASY;
12 12
13 terrain = new FlyTerrain( w, h ); 13 terrain = new FlyTerrain( w, h );
14 player = new Player( w, h ); 14 player = new Player( w, h );
15 highScore = 0; 15 highScore = 0;
16} 16}
17 17
18FlyGame :: ~FlyGame() 18FlyGame :: ~FlyGame()
19{ 19{
20 // terrain and player get deleted by parent class 20 // terrain and player get deleted by parent class
21} 21}
22 22
23void FlyGame :: init() 23void FlyGame :: init()
24{ 24{
25 Game :: init();
26
27 switch( difficulty ) 25 switch( difficulty )
28 { 26 {
29 case MENU_DIFFICULTY_EASY: 27 case MENU_DIFFICULTY_EASY:
30 player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 ); 28 player->setMovementInfo( 0.3, 0.2, 1.5, 1.5 );
31 break; 29 break;
32 case MENU_DIFFICULTY_NORMAL: 30 case MENU_DIFFICULTY_NORMAL:
33 player->setMovementInfo( 0.35, 0.4, 2.5, 3 ); 31 player->setMovementInfo( 0.35, 0.4, 2.5, 3 );
34 break; 32 break;
35 case MENU_DIFFICULTY_HARD: 33 case MENU_DIFFICULTY_HARD:
36 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 34 player->setMovementInfo( 0.4, 0.6, 4, 5 );
37 break; 35 break;
38 case MENU_DIFFICULTY_CUSTOM: 36 case MENU_DIFFICULTY_CUSTOM:
39 { 37 {
40 double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 ); 38 double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 );
41 double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 ); 39 double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 );
42 double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 ); 40 double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 );
43 double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 ); 41 double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 );
44 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 42 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
45 break; 43 break;
46 } 44 }
47 } 45 }
48 46
49 startScoring = false; 47 startScoring = false;
48 Game :: init();
50} 49}
51 50
52void FlyGame :: update( int state ) 51void FlyGame :: update( int state )
53{ 52{
54 Game::update( state ); 53 Game::update( state );
55 54
56 if ( state == STATE_PLAYING ) 55 if ( state == STATE_PLAYING )
57 { 56 {
58 57
59 if ( nrFrames % 3 == 0 ) 58 if ( nrFrames % 3 == 0 )
60 { 59 {
61 int diff = terrain->getMapBottom( 10 ) - player->getY(); 60 int diff = terrain->getMapBottom( 10 ) - player->getY();
62 int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); 61 int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff );
63 62
64 if ( !startScoring ) 63 if ( !startScoring )
65 { 64 {
66 if ( tmpScore > 0 ) 65 if ( tmpScore > 0 )
67 startScoring = true; 66 startScoring = true;
68 } 67 }
69 68
70 if ( startScoring ) 69 if ( startScoring )
71 { 70 {
72 // Update score 71 // Update score
73 // get distance between landscape and ship 72 // get distance between landscape and ship
74 73
75 // the closer the difference is to 0 means more points 74 // the closer the difference is to 0 means more points
76 score += tmpScore; 75 score += tmpScore;
77 } 76 }
78 } 77 }
79 78
80 if ( checkCollisions() ) 79 if ( checkCollisions() )
81 { 80 {
82 parent->changeState( STATE_CRASHING ); 81 parent->changeState( STATE_CRASHING );
83 return; 82 return;
84 } 83 }
85 84
86 // Game logic goes here 85 // Game logic goes here
87 terrain->moveTerrain( 5 ); 86 terrain->moveTerrain( 5 );
88 player->move( press ); 87 player->move( press );
89 } 88 }
90} 89}
91 90
92void FlyGame :: draw( SDL_Surface *screen ) 91void FlyGame :: draw( SDL_Surface *screen )
93{ 92{
94 Game::preDraw( screen ); 93 Game::preDraw( screen );
95 94
96 // Screen drawing goes here 95 // Screen drawing goes here
97 terrain->drawTerrain( screen ); 96 terrain->drawTerrain( screen );
98 97
99 player->draw( screen ); 98 player->draw( screen );
100 99
101 Game::draw( screen ); 100 Game::draw( screen );
102} 101}
103 102
104 103
105bool FlyGame :: checkCollisions() 104bool FlyGame :: checkCollisions()
106{ 105{
107 bool ret = false; 106 bool ret = false;
108 107
109 // Check collision with landscape 108 // Check collision with landscape
110 109
111 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 110 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
112} 111}
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp
index 762801d..700a6ec 100644
--- a/noncore/games/sfcave-sdl/gates_game.cpp
+++ b/noncore/games/sfcave-sdl/gates_game.cpp
@@ -1,201 +1,201 @@
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
7GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) 7GatesGame :: 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
19GatesGame :: ~GatesGame() 19GatesGame :: ~GatesGame()
20{ 20{
21 // terrain and player get deleted by parent class 21 // terrain and player get deleted by parent class
22} 22}
23 23
24void GatesGame :: init() 24void GatesGame :: init()
25{ 25{
26 Game :: init();
27
28 blockHeight = 80; 26 blockHeight = 80;
29 blockWidth = 20; 27 blockWidth = 20;
30 lastGateBottomY = 0; 28 lastGateBottomY = 0;
31 29
32 gateDistance = 75; 30 gateDistance = 75;
33 nextGate = nextInt( 50 ) + gateDistance; 31 nextGate = nextInt( 50 ) + gateDistance;
34 gapHeight = 75; 32 gapHeight = 75;
35 33
36 switch( difficulty ) 34 switch( difficulty )
37 { 35 {
38 case MENU_DIFFICULTY_EASY: 36 case MENU_DIFFICULTY_EASY:
39 gapHeight = 75; 37 gapHeight = 75;
40 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 38 player->setMovementInfo( 0.4, 0.6, 4, 5 );
41 break; 39 break;
42 case MENU_DIFFICULTY_NORMAL: 40 case MENU_DIFFICULTY_NORMAL:
43 gapHeight = 50; 41 gapHeight = 50;
44 player->setMovementInfo( 0.4, 0.6, 4, 5 ); 42 player->setMovementInfo( 0.4, 0.6, 4, 5 );
45 break; 43 break;
46 case MENU_DIFFICULTY_HARD: 44 case MENU_DIFFICULTY_HARD:
47 gapHeight = 25; 45 gapHeight = 25;
48 player->setMovementInfo( 0.6, 0.8, 6, 7 ); 46 player->setMovementInfo( 0.6, 0.8, 6, 7 );
49 break; 47 break;
50 case MENU_DIFFICULTY_CUSTOM: 48 case MENU_DIFFICULTY_CUSTOM:
51 { 49 {
52 // Read custom difficulty settings for this game 50 // Read custom difficulty settings for this game
53 gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); 51 gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 );
54 52
55 double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); 53 double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 );
56 double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); 54 double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 );
57 double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); 55 double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 );
58 double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); 56 double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 );
59 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 57 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
60 58
61 break; 59 break;
62 } 60 }
63 } 61 }
64 62
65 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 63 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
66 blocks[i].y( -1 ); 64 blocks[i].y( -1 );
65
66 Game :: init();
67} 67}
68 68
69void GatesGame :: update( int state ) 69void GatesGame :: update( int state )
70{ 70{
71 Game::update( state ); 71 Game::update( state );
72 72
73 // Game logic goes here 73 // Game logic goes here
74 if ( state == STATE_PLAYING ) 74 if ( state == STATE_PLAYING )
75 { 75 {
76 if ( nrFrames % 3 == 0 ) 76 if ( nrFrames % 3 == 0 )
77 score ++; 77 score ++;
78 78
79 if ( nrFrames % 500 == 0 ) 79 if ( nrFrames % 500 == 0 )
80 { 80 {
81 if ( gapHeight > 75 ) 81 if ( gapHeight > 75 )
82 gapHeight -= 5; 82 gapHeight -= 5;
83 } 83 }
84 84
85 // Slightly random gap distance 85 // Slightly random gap distance
86 if ( nrFrames >= nextGate ) 86 if ( nrFrames >= nextGate )
87 { 87 {
88 nextGate = nrFrames + nextInt( 50 ) + gateDistance; 88 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
89 addGate(); 89 addGate();
90 } 90 }
91 91
92 if ( checkCollisions() ) 92 if ( checkCollisions() )
93 { 93 {
94 parent->changeState( STATE_CRASHING ); 94 parent->changeState( STATE_CRASHING );
95 return; 95 return;
96 } 96 }
97 97
98 terrain->moveTerrain( 5 ); 98 terrain->moveTerrain( 5 );
99 moveBlocks( 5 ); 99 moveBlocks( 5 );
100 player->move( press ); 100 player->move( press );
101 } 101 }
102} 102}
103 103
104void GatesGame :: draw( SDL_Surface *screen ) 104void GatesGame :: draw( SDL_Surface *screen )
105{ 105{
106 Game::preDraw( screen ); 106 Game::preDraw( screen );
107 107
108 if ( parent->getState() == STATE_PLAYING ) 108 if ( parent->getState() == STATE_PLAYING )
109 { 109 {
110 // Screen drawing goes here 110 // Screen drawing goes here
111 terrain->drawTerrain( screen ); 111 terrain->drawTerrain( screen );
112 112
113 player->draw( screen ); 113 player->draw( screen );
114 114
115 drawBlocks( screen ); 115 drawBlocks( screen );
116 } 116 }
117 else 117 else
118 { 118 {
119 // Screen drawing goes here 119 // Screen drawing goes here
120 terrain->drawTerrain( screen ); 120 terrain->drawTerrain( screen );
121 121
122 drawBlocks( screen ); 122 drawBlocks( screen );
123 123
124 player->draw( screen ); 124 player->draw( screen );
125 } 125 }
126 126
127 Game::draw( screen ); 127 Game::draw( screen );
128} 128}
129 129
130 130
131void GatesGame :: addGate() 131void GatesGame :: addGate()
132{ 132{
133 printf( "gapHeight = %d\n", gapHeight ); 133 printf( "gapHeight = %d\n", gapHeight );
134 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 134 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
135 { 135 {
136 if ( blocks[i].y() == -1 ) 136 if ( blocks[i].y() == -1 )
137 { 137 {
138 int x1 = sWidth; 138 int x1 = sWidth;
139 int y1 = terrain->getMapTop(50); 139 int y1 = terrain->getMapTop(50);
140 int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight); 140 int b1Height = nextInt(terrain->getMapBottom( 50 ) - terrain->getMapTop(50) - gapHeight);
141 141
142 // See if height between last gate and this one is too big 142 // See if height between last gate and this one is too big
143 if ( b1Height - 100 > lastGateBottomY ) 143 if ( b1Height - 100 > lastGateBottomY )
144 b1Height -= 25; 144 b1Height -= 25;
145 else if ( b1Height + 100 < lastGateBottomY ) 145 else if ( b1Height + 100 < lastGateBottomY )
146 b1Height += 25; 146 b1Height += 25;
147 lastGateBottomY = b1Height; 147 lastGateBottomY = b1Height;
148 148
149 149
150 int x2 = sWidth; 150 int x2 = sWidth;
151 int y2 = y1 + b1Height + gapHeight; 151 int y2 = y1 + b1Height + gapHeight;
152 int b2Height = terrain->getMapBottom( 50 ) - y2; 152 int b2Height = terrain->getMapBottom( 50 ) - y2;
153 153
154 154
155 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 155 blocks[i].setRect( x1, y1, blockWidth, b1Height );
156 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 156 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
157 157
158 break; 158 break;
159 } 159 }
160 } 160 }
161} 161}
162 162
163void GatesGame :: moveBlocks( int amountToMove ) 163void GatesGame :: moveBlocks( int amountToMove )
164{ 164{
165 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 165 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
166 { 166 {
167 if ( blocks[i].y() != -1 ) 167 if ( blocks[i].y() != -1 )
168 { 168 {
169 blocks[i].moveBy( -amountToMove, 0 ); 169 blocks[i].moveBy( -amountToMove, 0 );
170 if ( blocks[i].x() + blocks[i].y() < 0 ) 170 if ( blocks[i].x() + blocks[i].y() < 0 )
171 blocks[i].y( -1 ); 171 blocks[i].y( -1 );
172 } 172 }
173 } 173 }
174} 174}
175 175
176void GatesGame :: drawBlocks( SDL_Surface *screen ) 176void GatesGame :: drawBlocks( SDL_Surface *screen )
177{ 177{
178 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 178 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
179 { 179 {
180 if ( blocks[i].y() != -1 ) 180 if ( blocks[i].y() != -1 )
181 { 181 {
182 SDL_Rect r = blocks[i].getRect(); 182 SDL_Rect r = blocks[i].getRect();
183 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) ); 183 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
184 } 184 }
185 } 185 }
186} 186}
187 187
188bool GatesGame :: checkCollisions() 188bool GatesGame :: checkCollisions()
189{ 189{
190 // Check collisions with blocks 190 // Check collisions with blocks
191 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 191 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
192 { 192 {
193 if ( blocks[i].y() != -1 ) 193 if ( blocks[i].y() != -1 )
194 { 194 {
195 if ( blocks[i].intersects( player->getPos() ) ) 195 if ( blocks[i].intersects( player->getPos() ) )
196 return true; 196 return true;
197 } 197 }
198 } 198 }
199 // Check collision with landscape 199 // Check collision with landscape
200 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 200 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
201} 201}
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp
index 2d52ae2..f024d6b 100644
--- a/noncore/games/sfcave-sdl/player.cpp
+++ b/noncore/games/sfcave-sdl/player.cpp
@@ -1,284 +1,284 @@
1#include <SDL.h> 1#include <SDL.h>
2#include "SDL_gfxPrimitives.h" 2#include "SDL_gfxPrimitives.h"
3 3
4#include "constants.h" 4#include "constants.h"
5#include "player.h" 5#include "player.h"
6#include "random.h" 6#include "random.h"
7#include "animatedimage.h" 7#include "animatedimage.h"
8 8
9Player :: Player( int w, int h ) 9Player :: Player( int w, int h )
10{ 10{
11 sWidth = w; 11 sWidth = w;
12 sHeight = h; 12 sHeight = h;
13 13
14 thrust = 0.4; 14 thrust = 0.4;
15 gravity = 0.6; 15 gravity = 0.6;
16 maxUpSpeed = 4.0; 16 maxUpSpeed = 4.0;
17 maxDownSpeed = 5.0; 17 maxDownSpeed = 5.0;
18 18
19 explosion = new AnimatedImage( IMAGES_PATH "explosion.bmp", 15 ); 19 explosion = new AnimatedImage( IMAGES_PATH "explosion.bmp", 15 );
20 init(); 20 init();
21} 21}
22 22
23Player :: ~Player() 23Player :: ~Player()
24{ 24{
25 if ( explosion ) 25 if ( explosion )
26 delete explosion; 26 delete explosion;
27} 27}
28 28
29void Player :: init() 29void Player :: init()
30{ 30{
31 // Set player position 31 // Set player position
32 pos.x( 50 ); 32 pos.x( 50 );
33 pos.y( sWidth/2 ); 33 pos.y( sWidth/2 );
34 pos.h( 2 ); 34 pos.h( 2 );
35 pos.w( 4 ); 35 pos.w( 4 );
36 thrust = 0; 36 currentThrust = 0;
37 crashing = false; 37 crashing = false;
38 crashLineLength = 0; 38 crashLineLength = 0;
39 crashed = false; 39 crashed = false;
40 explosion->reset(); 40 explosion->reset();
41 allFaded = false; 41 allFaded = false;
42 expNextFrame = false; 42 expNextFrame = false;
43 43
44 // Reset Trail 44 // Reset Trail
45 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 45 for ( int i = 0 ; i < TRAILSIZE ; ++i )
46 { 46 {
47 trail[i].x( -1 ); 47 trail[i].x( -1 );
48 trail[i].y( 0 ); 48 trail[i].y( 0 );
49 trail[i].w( 2 ); 49 trail[i].w( 2 );
50 trail[i].h( 2 ); 50 trail[i].h( 2 );
51 } 51 }
52} 52}
53 53
54void Player :: draw( SDL_Surface *screen ) 54void Player :: draw( SDL_Surface *screen )
55{ 55{
56 if ( !crashing ) 56 if ( !crashing )
57 { 57 {
58 // Draw Player 58 // Draw Player
59 // ellipseRGBA( screen, pos.x(), pos.y(), pos.x()+ pos.width(), pos.y()+pos.height(), 0, 255, 255, 255 ); 59 // ellipseRGBA( screen, pos.x(), pos.y(), pos.x()+ pos.width(), pos.y()+pos.height(), 0, 255, 255, 255 );
60 filledEllipseRGBA( screen, pos.x() + pos.w(), pos.y(), pos.w(), pos.h(), 0, 255, 255, 255 ); 60 filledEllipseRGBA( screen, pos.x() + pos.w(), pos.y(), pos.w(), pos.h(), 0, 255, 255, 255 );
61 61
62 // Draw Trail 62 // Draw Trail
63 drawTrails( screen ); 63 drawTrails( screen );
64 } 64 }
65 else 65 else
66 { 66 {
67 drawTrails( screen ); 67 drawTrails( screen );
68 68
69 if ( !crashed ) 69 if ( !crashed )
70 explosion->draw( screen, pos.x(), pos.y() ); 70 explosion->draw( screen, pos.x(), pos.y() );
71 } 71 }
72} 72}
73 73
74void Player :: drawTrails( SDL_Surface *screen ) 74void Player :: drawTrails( SDL_Surface *screen )
75{ 75{
76 if ( allFaded && crashing ) 76 if ( allFaded && crashing )
77 return; 77 return;
78 78
79 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 79 for ( int i = 0 ; i < TRAILSIZE ; ++i )
80 { 80 {
81 if ( trail[i].x() >= 0 ) 81 if ( trail[i].x() >= 0 )
82 { 82 {
83 int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); 83 int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) ));
84 boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); 84 boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c );
85 } 85 }
86 } 86 }
87} 87}
88 88
89void Player :: move( bool up ) 89void Player :: move( bool up )
90{ 90{
91 // Find enpty trail and move others 91 // Find enpty trail and move others
92 moveTrails(); 92 moveTrails();
93 93
94 if ( up ) 94 if ( up )
95 currentThrust -= thrust; 95 currentThrust -= thrust;
96 else 96 else
97 currentThrust += gravity; 97 currentThrust += gravity;
98 98
99 if ( currentThrust > maxDownSpeed ) 99 if ( currentThrust > maxDownSpeed )
100 currentThrust = maxDownSpeed; 100 currentThrust = maxDownSpeed;
101 else if ( currentThrust < -maxUpSpeed ) 101 else if ( currentThrust < -maxUpSpeed )
102 currentThrust = -maxUpSpeed; 102 currentThrust = -maxUpSpeed;
103 103
104 pos.moveBy( 0, (int)(currentThrust) ); 104 pos.moveBy( 0, (int)(currentThrust) );
105} 105}
106 106
107void Player :: moveTrails() 107void Player :: moveTrails()
108{ 108{
109 bool done = false; 109 bool done = false;
110 bool stillVisible = false; 110 bool stillVisible = false;
111 111
112 // Dont do anything here if all faded when were crashing 112 // Dont do anything here if all faded when were crashing
113 if ( allFaded && crashing ) 113 if ( allFaded && crashing )
114 return; 114 return;
115 115
116 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 116 for ( int i = 0 ; i < TRAILSIZE ; ++i )
117 { 117 {
118 if ( trail[i].x() < 0 ) 118 if ( trail[i].x() < 0 )
119 { 119 {
120 stillVisible = true; 120 stillVisible = true;
121 if ( !crashing && !done ) 121 if ( !crashing && !done )
122 { 122 {
123 trail[i].x( pos.x() - 5 ); 123 trail[i].x( pos.x() - 5 );
124 trail[i].y( pos.y() ); 124 trail[i].y( pos.y() );
125 done = true; 125 done = true;
126 } 126 }
127 } 127 }
128 else 128 else
129 trail[i].x( trail[i].x() - 1 ); 129 trail[i].x( trail[i].x() - 1 );
130 } 130 }
131 131
132 if ( !stillVisible ) 132 if ( !stillVisible )
133 allFaded = true; 133 allFaded = true;
134} 134}
135 135
136bool Player :: updateCrashing() 136bool Player :: updateCrashing()
137{ 137{
138 crashing = true; 138 crashing = true;
139 139
140 moveTrails(); 140 moveTrails();
141 if ( expNextFrame ) 141 if ( expNextFrame )
142 { 142 {
143 expNextFrame = false; 143 expNextFrame = false;
144 crashed = !explosion->nextFrame(); 144 crashed = !explosion->nextFrame();
145 } 145 }
146 else 146 else
147 expNextFrame = true; 147 expNextFrame = true;
148 148
149 return crashed; 149 return crashed;
150} 150}
151 151
152void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown ) 152void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown )
153{ 153{
154 thrust = up; 154 thrust = up;
155 gravity = grav; 155 gravity = grav;
156 maxUpSpeed = maxUp; 156 maxUpSpeed = maxUp;
157 maxDownSpeed = maxDown; 157 maxDownSpeed = maxDown;
158} 158}
159 159
160 160
161void Player :: incValue( int valueType ) 161void Player :: incValue( int valueType )
162{ 162{
163 switch( valueType ) 163 switch( valueType )
164 { 164 {
165 case PLAYER_THRUST: 165 case PLAYER_THRUST:
166 thrust += 0.1; 166 thrust += 0.1;
167 break; 167 break;
168 case PLAYER_GRAVITY: 168 case PLAYER_GRAVITY:
169 gravity += 0.1; 169 gravity += 0.1;
170 break; 170 break;
171 case PLAYER_MAX_SPEED_UP: 171 case PLAYER_MAX_SPEED_UP:
172 maxUpSpeed += 0.1; 172 maxUpSpeed += 0.1;
173 break; 173 break;
174 case PLAYER_MAX_SPEED_DOWN: 174 case PLAYER_MAX_SPEED_DOWN:
175 maxDownSpeed += 0.1; 175 maxDownSpeed += 0.1;
176 break; 176 break;
177 } 177 }
178} 178}
179 179
180void Player :: decValue( int valueType ) 180void Player :: decValue( int valueType )
181{ 181{
182 switch( valueType ) 182 switch( valueType )
183 { 183 {
184 case PLAYER_THRUST: 184 case PLAYER_THRUST:
185 thrust -= 0.1; 185 thrust -= 0.1;
186 break; 186 break;
187 case PLAYER_GRAVITY: 187 case PLAYER_GRAVITY:
188 gravity -= 0.1; 188 gravity -= 0.1;
189 break; 189 break;
190 case PLAYER_MAX_SPEED_UP: 190 case PLAYER_MAX_SPEED_UP:
191 maxUpSpeed -= 0.1; 191 maxUpSpeed -= 0.1;
192 break; 192 break;
193 case PLAYER_MAX_SPEED_DOWN: 193 case PLAYER_MAX_SPEED_DOWN:
194 maxDownSpeed -= 0.1; 194 maxDownSpeed -= 0.1;
195 break; 195 break;
196 } 196 }
197} 197}
198 198
199void Player :: setValue( int valueType, double val ) 199void Player :: setValue( int valueType, double val )
200{ 200{
201 switch( valueType ) 201 switch( valueType )
202 { 202 {
203 case PLAYER_THRUST: 203 case PLAYER_THRUST:
204 thrust = val; 204 thrust = val;
205 break; 205 break;
206 case PLAYER_GRAVITY: 206 case PLAYER_GRAVITY:
207 gravity = val; 207 gravity = val;
208 break; 208 break;
209 case PLAYER_MAX_SPEED_UP: 209 case PLAYER_MAX_SPEED_UP:
210 maxUpSpeed = val; 210 maxUpSpeed = val;
211 break; 211 break;
212 case PLAYER_MAX_SPEED_DOWN: 212 case PLAYER_MAX_SPEED_DOWN:
213 maxDownSpeed = val; 213 maxDownSpeed = val;
214 break; 214 break;
215 } 215 }
216} 216}
217 217
218double Player :: getValue( int valueType ) 218double Player :: getValue( int valueType )
219{ 219{
220 double val; 220 double val;
221 switch( valueType ) 221 switch( valueType )
222 { 222 {
223 case PLAYER_THRUST: 223 case PLAYER_THRUST:
224 val = thrust; 224 val = thrust;
225 break; 225 break;
226 case PLAYER_GRAVITY: 226 case PLAYER_GRAVITY:
227 val = gravity; 227 val = gravity;
228 break; 228 break;
229 case PLAYER_MAX_SPEED_UP: 229 case PLAYER_MAX_SPEED_UP:
230 val = maxUpSpeed; 230 val = maxUpSpeed;
231 break; 231 break;
232 case PLAYER_MAX_SPEED_DOWN: 232 case PLAYER_MAX_SPEED_DOWN:
233 val = maxDownSpeed; 233 val = maxDownSpeed;
234 break; 234 break;
235 } 235 }
236 236
237 return val; 237 return val;
238} 238}
239 239
240string Player :: getValueTypeString( int valueType ) 240string Player :: getValueTypeString( int valueType )
241{ 241{
242 string val; 242 string val;
243 switch( valueType ) 243 switch( valueType )
244 { 244 {
245 case PLAYER_THRUST: 245 case PLAYER_THRUST:
246 val = "thrust"; 246 val = "thrust";
247 break; 247 break;
248 case PLAYER_GRAVITY: 248 case PLAYER_GRAVITY:
249 val = "gravity"; 249 val = "gravity";
250 break; 250 break;
251 case PLAYER_MAX_SPEED_UP: 251 case PLAYER_MAX_SPEED_UP:
252 val = "maxupspeed"; 252 val = "maxupspeed";
253 break; 253 break;
254 case PLAYER_MAX_SPEED_DOWN: 254 case PLAYER_MAX_SPEED_DOWN:
255 val = "maxdownspeed"; 255 val = "maxdownspeed";
256 break; 256 break;
257 } 257 }
258 258
259 return val; 259 return val;
260} 260}
261 261
262string Player :: getValueString( int valueType ) 262string Player :: getValueString( int valueType )
263{ 263{
264 char val[50]; 264 char val[50];
265 switch( valueType ) 265 switch( valueType )
266 { 266 {
267 case PLAYER_THRUST: 267 case PLAYER_THRUST:
268 sprintf( val, "Thrust - %lf", thrust ); 268 sprintf( val, "Thrust - %lf", thrust );
269 break; 269 break;
270 case PLAYER_GRAVITY: 270 case PLAYER_GRAVITY:
271 sprintf( val, "Gravity - %lf", gravity ); 271 sprintf( val, "Gravity - %lf", gravity );
272 break; 272 break;
273 case PLAYER_MAX_SPEED_UP: 273 case PLAYER_MAX_SPEED_UP:
274 sprintf( val, "Max Speed Up - %lf", maxUpSpeed ); 274 sprintf( val, "Max Speed Up - %lf", maxUpSpeed );
275 break; 275 break;
276 case PLAYER_MAX_SPEED_DOWN: 276 case PLAYER_MAX_SPEED_DOWN:
277 sprintf( val, "Max Speed Down - %lf", maxDownSpeed ); 277 sprintf( val, "Max Speed Down - %lf", maxDownSpeed );
278 break; 278 break;
279 } 279 }
280 280
281 string ret = val; 281 string ret = val;
282 return ret; 282 return ret;
283} 283}
284 284
diff --git a/noncore/games/sfcave-sdl/sfcave_game.cpp b/noncore/games/sfcave-sdl/sfcave_game.cpp
index 1b00e14..8fdbbe5 100644
--- a/noncore/games/sfcave-sdl/sfcave_game.cpp
+++ b/noncore/games/sfcave-sdl/sfcave_game.cpp
@@ -1,179 +1,179 @@
1#include "SDL_gfxPrimitives.h" 1#include "SDL_gfxPrimitives.h"
2 2
3#include "constants.h" 3#include "constants.h"
4#include "sfcave_game.h" 4#include "sfcave_game.h"
5#include "random.h" 5#include "random.h"
6 6
7SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff ) 7SFCaveGame :: SFCaveGame( SFCave *p, int w, int h, int diff )
8 : Game( p, w, h, diff ) 8 : Game( p, w, h, diff )
9{ 9{
10 gameName = "SFCave"; 10 gameName = "SFCave";
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
19SFCaveGame :: ~SFCaveGame() 19SFCaveGame :: ~SFCaveGame()
20{ 20{
21} 21}
22 22
23void SFCaveGame :: init() 23void SFCaveGame :: init()
24{ 24{
25 Game :: init();
26
27 blockDistance = 50; 25 blockDistance = 50;
28 blockHeight = 80; 26 blockHeight = 80;
29 blockWidth = 20; 27 blockWidth = 20;
30 28
31 switch( difficulty ) 29 switch( difficulty )
32 { 30 {
33 case MENU_DIFFICULTY_EASY: 31 case MENU_DIFFICULTY_EASY:
34 blockDistance = 50; 32 blockDistance = 50;
35 break; 33 break;
36 case MENU_DIFFICULTY_NORMAL: 34 case MENU_DIFFICULTY_NORMAL:
37 blockDistance = 40; 35 blockDistance = 40;
38 break; 36 break;
39 case MENU_DIFFICULTY_HARD: 37 case MENU_DIFFICULTY_HARD:
40 blockDistance = 30; 38 blockDistance = 30;
41 break; 39 break;
42 case MENU_DIFFICULTY_CUSTOM: 40 case MENU_DIFFICULTY_CUSTOM:
43 { 41 {
44 // Read custom difficulty settings for this game 42 // Read custom difficulty settings for this game
45 blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 ); 43 blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 );
46 44
47 double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 ); 45 double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 );
48 double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 ); 46 double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 );
49 double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 ); 47 double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 );
50 double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 ); 48 double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 );
51 player->setMovementInfo( thrust, gravity, maxUp, maxDown ); 49 player->setMovementInfo( thrust, gravity, maxUp, maxDown );
52 50
53 break; 51 break;
54 } 52 }
55 } 53 }
56 54
57 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 55 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
58 blocks[i].y( -1 ); 56 blocks[i].y( -1 );
57
58 Game :: init();
59} 59}
60 60
61void SFCaveGame :: update( int state ) 61void SFCaveGame :: update( int state )
62{ 62{
63 Game::update( state ); 63 Game::update( state );
64 64
65 if ( state == STATE_PLAYING ) 65 if ( state == STATE_PLAYING )
66 { 66 {
67 if ( nrFrames % 3 == 0 ) 67 if ( nrFrames % 3 == 0 )
68 score ++; 68 score ++;
69 69
70 if ( nrFrames % 200 == 0 ) 70 if ( nrFrames % 200 == 0 )
71 { 71 {
72 if ( terrain->getMaxHeight() < sHeight - 100 ) 72 if ( terrain->getMaxHeight() < sHeight - 100 )
73 { 73 {
74 terrain->increaseMaxHeight( 10 ); 74 terrain->increaseMaxHeight( 10 );
75 75
76 // Reduce block height 76 // Reduce block height
77 if ( terrain->getMaxHeight() > sHeight - 150 ) 77 if ( terrain->getMaxHeight() > sHeight - 150 )
78 blockHeight -= 5; 78 blockHeight -= 5;
79 } 79 }
80 } 80 }
81 81
82 if ( checkCollisions() ) 82 if ( checkCollisions() )
83 { 83 {
84 parent->changeState( STATE_CRASHING ); 84 parent->changeState( STATE_CRASHING );
85 return; 85 return;
86 } 86 }
87 87
88 if ( nrFrames % blockDistance == 0 ) 88 if ( nrFrames % blockDistance == 0 )
89 addBlock(); 89 addBlock();
90 90
91 // Game logic goes here 91 // Game logic goes here
92 terrain->moveTerrain( 5 ); 92 terrain->moveTerrain( 5 );
93 moveBlocks( 5 ); 93 moveBlocks( 5 );
94 player->move( press ); 94 player->move( press );
95 } 95 }
96} 96}
97 97
98void SFCaveGame :: draw( SDL_Surface *screen ) 98void SFCaveGame :: draw( SDL_Surface *screen )
99{ 99{
100 Game::preDraw( screen ); 100 Game::preDraw( screen );
101 101
102 if ( parent->getState() == STATE_PLAYING ) 102 if ( parent->getState() == STATE_PLAYING )
103 { 103 {
104 // Screen drawing goes here 104 // Screen drawing goes here
105 terrain->drawTerrain( screen ); 105 terrain->drawTerrain( screen );
106 106
107 player->draw( screen ); 107 player->draw( screen );
108 108
109 drawBlocks( screen ); 109 drawBlocks( screen );
110 } 110 }
111 else 111 else
112 { 112 {
113 // Screen drawing goes here 113 // Screen drawing goes here
114 terrain->drawTerrain( screen ); 114 terrain->drawTerrain( screen );
115 115
116 drawBlocks( screen ); 116 drawBlocks( screen );
117 117
118 player->draw( screen ); 118 player->draw( screen );
119 } 119 }
120 120
121 Game::draw( screen ); 121 Game::draw( screen );
122} 122}
123 123
124void SFCaveGame :: addBlock() 124void SFCaveGame :: addBlock()
125{ 125{
126 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 126 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
127 { 127 {
128 if ( blocks[i].y() == -1 ) 128 if ( blocks[i].y() == -1 )
129 { 129 {
130 int x = sWidth; 130 int x = sWidth;
131 131
132 int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight)); 132 int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight));
133 133
134 blocks[i].setRect( x, y, blockWidth, blockHeight ); 134 blocks[i].setRect( x, y, blockWidth, blockHeight );
135 135
136 break; 136 break;
137 } 137 }
138 } 138 }
139} 139}
140 140
141void SFCaveGame :: moveBlocks( int amountToMove ) 141void SFCaveGame :: moveBlocks( int amountToMove )
142{ 142{
143 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 143 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
144 { 144 {
145 if ( blocks[i].y() != -1 ) 145 if ( blocks[i].y() != -1 )
146 { 146 {
147 blocks[i].moveBy( -amountToMove, 0 ); 147 blocks[i].moveBy( -amountToMove, 0 );
148 if ( blocks[i].x() + blocks[i].y() < 0 ) 148 if ( blocks[i].x() + blocks[i].y() < 0 )
149 blocks[i].y( -1 ); 149 blocks[i].y( -1 );
150 } 150 }
151 } 151 }
152} 152}
153 153
154void SFCaveGame :: drawBlocks( SDL_Surface *screen ) 154void SFCaveGame :: drawBlocks( SDL_Surface *screen )
155{ 155{
156 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 156 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
157 { 157 {
158 if ( blocks[i].y() != -1 ) 158 if ( blocks[i].y() != -1 )
159 { 159 {
160 SDL_Rect r = blocks[i].getRect(); 160 SDL_Rect r = blocks[i].getRect();
161 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) ); 161 SDL_FillRect( screen, &r, SDL_MapRGB( screen->format, 100, 100, 255 ) );
162 } 162 }
163 } 163 }
164} 164}
165 165
166bool SFCaveGame :: checkCollisions() 166bool SFCaveGame :: checkCollisions()
167{ 167{
168 // Check collisions with blocks 168 // Check collisions with blocks
169 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 169 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
170 { 170 {
171 if ( blocks[i].y() != -1 ) 171 if ( blocks[i].y() != -1 )
172 { 172 {
173 if ( blocks[i].intersects( player->getPos() ) ) 173 if ( blocks[i].intersects( player->getPos() ) )
174 return true; 174 return true;
175 } 175 }
176 } 176 }
177 // Check collision with landscape 177 // Check collision with landscape
178 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() ); 178 return terrain->checkCollision( player->getX(), player->getY(), player->getHeight() );
179} 179}