summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/starfield.cpp
Unidiff
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