Diffstat (limited to 'noncore/games/sfcave-sdl/starfield.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/starfield.cpp | 72 |
1 files changed, 72 insertions, 0 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 | |||
@@ -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 | ||
229 | SDL_Surface *screen; | ||
230 | StarField *stars; | ||
231 | |||
232 | void 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 | ||
288 | extern "C" | ||
289 | #endif | ||
290 | int main( int argc, char *argv[] ) | ||
291 | { | ||
292 | go(); | ||
293 | } | ||
294 | |||
295 | #endif | ||