summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/starfield.cpp
authorandyq <andyq>2003-01-21 20:37:00 (UTC)
committer andyq <andyq>2003-01-21 20:37:00 (UTC)
commit0a6563fcc2f49857c581d9def24407a3a4ef526c (patch) (unidiff)
treef1b82a4bd7582ef2cb722cffb87eecff1e1f96e6 /noncore/games/sfcave-sdl/starfield.cpp
parent50b5915b48fc5cbacf23e4d2b75d7a266f141a4a (diff)
downloadopie-0a6563fcc2f49857c581d9def24407a3a4ef526c.zip
opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.gz
opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.bz2
Clean up of code - fixed memory leaks (most of them) and added new custom config menu
Diffstat (limited to 'noncore/games/sfcave-sdl/starfield.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/starfield.cpp74
1 files changed, 73 insertions, 1 deletions
diff --git a/noncore/games/sfcave-sdl/starfield.cpp b/noncore/games/sfcave-sdl/starfield.cpp
index c1f2d73..82edfc1 100644
--- a/noncore/games/sfcave-sdl/starfield.cpp
+++ b/noncore/games/sfcave-sdl/starfield.cpp
@@ -161,7 +161,7 @@ void StarField :: move( )
161 //Move Star 161 //Move Star
162 pos_x[i] += vel_x[i]; 162 pos_x[i] += vel_x[i];
163 pos_y[i] += vel_y[i]; 163 pos_y[i] += vel_y[i];
164 164
165 if (pos_x[i] < 0) 165 if (pos_x[i] < 0)
166 pos_x[i] = pos_x[i] + 240; 166 pos_x[i] = pos_x[i] + 240;
167 167
@@ -221,3 +221,75 @@ void StarField :: draw( SDL_Surface *screen, int w, int h )
221 SDL_UnlockSurface( screen ); 221 SDL_UnlockSurface( screen );
222 } 222 }
223} 223}
224
225
226
227// Test
228#ifdef DEBUG_STARS
229SDL_Surface *screen;
230StarField *stars;
231
232void go()
233{
234 /* Initialize SDL */
235 if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
236 {
237 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
238 exit(1);
239 }
240 atexit(SDL_Quit);
241
242 int videoflags = SDL_SWSURFACE ;
243
244 if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
245 {
246 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
247 exit(2);
248 }
249
250 stars = new StarField( false, 200 );
251
252 bool done = false;
253 while ( !done )
254 {
255 SDL_FillRect( screen, 0, 0 );
256 stars->draw( screen );
257 stars->move( );
258
259 SDL_Flip( screen );
260
261 SDL_Delay( 10 );
262
263 SDL_Event event;
264 while ( SDL_PollEvent(&event) )
265 {
266 switch (event.type)
267 {
268 case SDL_KEYDOWN:
269 // Escape keypress quits the app
270 if ( event.key.keysym.sym != SDLK_ESCAPE )
271 {
272 break;
273 }
274 case SDL_QUIT:
275 done = 1;
276 break;
277 default:
278 break;
279 }
280 }
281 }
282 }
283
284
285
286
287#ifdef __cplusplus
288extern "C"
289#endif
290int main( int argc, char *argv[] )
291{
292 go();
293}
294
295#endif