summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/player.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/player.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/player.cpp152
1 files changed, 137 insertions, 15 deletions
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp
index 830ee78..2d52ae2 100644
--- a/noncore/games/sfcave-sdl/player.cpp
+++ b/noncore/games/sfcave-sdl/player.cpp
@@ -11,8 +11,8 @@ Player :: Player( int w, int h )
11 sWidth = w; 11 sWidth = w;
12 sHeight = h; 12 sHeight = h;
13 13
14 thrustUp = 0.4; 14 thrust = 0.4;
15 thrustDown = 0.6; 15 gravity = 0.6;
16 maxUpSpeed = 4.0; 16 maxUpSpeed = 4.0;
17 maxDownSpeed = 5.0; 17 maxDownSpeed = 5.0;
18 18
@@ -80,10 +80,7 @@ void Player :: drawTrails( SDL_Surface *screen )
80 { 80 {
81 if ( trail[i].x() >= 0 ) 81 if ( trail[i].x() >= 0 )
82 { 82 {
83 // int r = (int) ((255.0/pos.x()) * (trail[i].x));
84 // int g = (int) ((150.0/pos.x()) * (trail[i].x));
85 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() ) ));
86 // SDL_FillRect( screen, &trail[i], SDL_MapRGBA( screen->format, r, g, 0, 0 ) ); //(int)(1.5*c), 0, 255 ) );
87 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 );
88 } 85 }
89 } 86 }
@@ -95,16 +92,16 @@ void Player :: move( bool up )
95 moveTrails(); 92 moveTrails();
96 93
97 if ( up ) 94 if ( up )
98 thrust -= thrustUp; 95 currentThrust -= thrust;
99 else 96 else
100 thrust += thrustDown; 97 currentThrust += gravity;
101 98
102 if ( thrust > maxDownSpeed ) 99 if ( currentThrust > maxDownSpeed )
103 thrust = maxDownSpeed; 100 currentThrust = maxDownSpeed;
104 else if ( thrust < -maxUpSpeed ) 101 else if ( currentThrust < -maxUpSpeed )
105 thrust = -maxUpSpeed; 102 currentThrust = -maxUpSpeed;
106 103
107 pos.moveBy( 0, (int)(thrust) ); 104 pos.moveBy( 0, (int)(currentThrust) );
108} 105}
109 106
110void Player :: moveTrails() 107void Player :: moveTrails()
@@ -152,11 +149,136 @@ bool Player :: updateCrashing()
152 return crashed; 149 return crashed;
153} 150}
154 151
155void Player :: setMovementInfo( double up, double down, double maxUp, double maxDown ) 152void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown )
156{ 153{
157 thrustUp = up; 154 thrust = up;
158 thrustDown = down; 155 gravity = grav;
159 maxUpSpeed = maxUp; 156 maxUpSpeed = maxUp;
160 maxDownSpeed = maxDown; 157 maxDownSpeed = maxDown;
161} 158}
162 159
160
161void Player :: incValue( int valueType )
162{
163 switch( valueType )
164 {
165 case PLAYER_THRUST:
166 thrust += 0.1;
167 break;
168 case PLAYER_GRAVITY:
169 gravity += 0.1;
170 break;
171 case PLAYER_MAX_SPEED_UP:
172 maxUpSpeed += 0.1;
173 break;
174 case PLAYER_MAX_SPEED_DOWN:
175 maxDownSpeed += 0.1;
176 break;
177 }
178}
179
180void Player :: decValue( int valueType )
181{
182 switch( valueType )
183 {
184 case PLAYER_THRUST:
185 thrust -= 0.1;
186 break;
187 case PLAYER_GRAVITY:
188 gravity -= 0.1;
189 break;
190 case PLAYER_MAX_SPEED_UP:
191 maxUpSpeed -= 0.1;
192 break;
193 case PLAYER_MAX_SPEED_DOWN:
194 maxDownSpeed -= 0.1;
195 break;
196 }
197}
198
199void Player :: setValue( int valueType, double val )
200{
201 switch( valueType )
202 {
203 case PLAYER_THRUST:
204 thrust = val;
205 break;
206 case PLAYER_GRAVITY:
207 gravity = val;
208 break;
209 case PLAYER_MAX_SPEED_UP:
210 maxUpSpeed = val;
211 break;
212 case PLAYER_MAX_SPEED_DOWN:
213 maxDownSpeed = val;
214 break;
215 }
216}
217
218double Player :: getValue( int valueType )
219{
220 double val;
221 switch( valueType )
222 {
223 case PLAYER_THRUST:
224 val = thrust;
225 break;
226 case PLAYER_GRAVITY:
227 val = gravity;
228 break;
229 case PLAYER_MAX_SPEED_UP:
230 val = maxUpSpeed;
231 break;
232 case PLAYER_MAX_SPEED_DOWN:
233 val = maxDownSpeed;
234 break;
235 }
236
237 return val;
238}
239
240string Player :: getValueTypeString( int valueType )
241{
242 string val;
243 switch( valueType )
244 {
245 case PLAYER_THRUST:
246 val = "thrust";
247 break;
248 case PLAYER_GRAVITY:
249 val = "gravity";
250 break;
251 case PLAYER_MAX_SPEED_UP:
252 val = "maxupspeed";
253 break;
254 case PLAYER_MAX_SPEED_DOWN:
255 val = "maxdownspeed";
256 break;
257 }
258
259 return val;
260}
261
262string Player :: getValueString( int valueType )
263{
264 char val[50];
265 switch( valueType )
266 {
267 case PLAYER_THRUST:
268 sprintf( val, "Thrust - %lf", thrust );
269 break;
270 case PLAYER_GRAVITY:
271 sprintf( val, "Gravity - %lf", gravity );
272 break;
273 case PLAYER_MAX_SPEED_UP:
274 sprintf( val, "Max Speed Up - %lf", maxUpSpeed );
275 break;
276 case PLAYER_MAX_SPEED_DOWN:
277 sprintf( val, "Max Speed Down - %lf", maxDownSpeed );
278 break;
279 }
280
281 string ret = val;
282 return ret;
283}
284