comparison test/nds-test-progs/sprite/source/testsprite.c @ 2694:c1c7cb1b5a47 gsoc2008_nds

More sprite-work in the render driver, and some updates to the nds-test-progs.
author Darren Alton <dalton@stevens.edu>
date Sat, 16 Aug 2008 12:58:36 +0000
parents 71c56e900f8b
children e1da92da346c
comparison
equal deleted inserted replaced
2693:bae97b6ac32b 2694:c1c7cb1b5a47
5 #include <time.h> 5 #include <time.h>
6 #include <math.h> 6 #include <math.h>
7 #include <fat.h> 7 #include <fat.h>
8 #include <SDL/SDL.h> 8 #include <SDL/SDL.h>
9 9
10 #define NUM_SPRITES 100 10 #define NUM_SPRITES 10
11 #define MAX_SPEED 1 11 #define MAX_SPEED 1
12 12
13 SDL_Surface *sprite; 13 SDL_Surface *sprite;
14 int numsprites; 14 int numsprites;
15 SDL_Rect *sprite_rects; 15 SDL_Rect *sprite_rects;
160 Uint32 videoflags; 160 Uint32 videoflags;
161 Uint32 background; 161 Uint32 background;
162 int i, done; 162 int i, done;
163 SDL_Event event; 163 SDL_Event event;
164 Uint32 then, now, frames; 164 Uint32 then, now, frames;
165
166 consoleDemoInit(); puts("Hello world! Initializing FAT...");
165 fatInitDefault(); 167 fatInitDefault();
166 /* Initialize SDL */ 168 /* Initialize SDL */
167 if (SDL_Init(SDL_INIT_VIDEO) < 0) { 169 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
168 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); 170 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
169 return (1); 171 return (1);
170 } 172 }
173 puts("* initialized SDL");
171 174
172 numsprites = NUM_SPRITES; 175 numsprites = NUM_SPRITES;
173 videoflags = SDL_SWSURFACE | SDL_ANYFORMAT; 176 videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT*/;
174 width = 640; 177 width = 256;
175 height = 480; 178 height = 192;
176 video_bpp = 8; 179 video_bpp = 15;
177 debug_flip = 0; 180 debug_flip = 0;
178 while (argc > 1) { 181 while (argc > 1) {
179 --argc; 182 --argc;
180 if (strcmp(argv[argc - 1], "-width") == 0) { 183 if (strcmp(argv[argc - 1], "-width") == 0) {
181 width = atoi(argv[argc]); 184 width = atoi(argv[argc]);
212 if (!screen) { 215 if (!screen) {
213 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", 216 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
214 width, height, SDL_GetError()); 217 width, height, SDL_GetError());
215 quit(2); 218 quit(2);
216 } 219 }
220 screen->flags &= ~SDL_PREALLOC;
221 puts("* set video mode");
217 222
218 /* Load the sprite */ 223 /* Load the sprite */
219 if (LoadSprite("icon.bmp") < 0) { 224 if (LoadSprite("icon.bmp") < 0) {
220 quit(1); 225 quit(1);
221 } 226 }
227 puts("* loaded sprite");
222 228
223 /* Allocate memory for the sprite info */ 229 /* Allocate memory for the sprite info */
224 mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites); 230 mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
225 if (mem == NULL) { 231 if (mem == NULL) {
226 SDL_FreeSurface(sprite); 232 SDL_FreeSurface(sprite);
284 /* Loop, blitting sprites and waiting for a keystroke */ 290 /* Loop, blitting sprites and waiting for a keystroke */
285 frames = 0; 291 frames = 0;
286 then = SDL_GetTicks(); 292 then = SDL_GetTicks();
287 done = 0; 293 done = 0;
288 sprites_visible = 0; 294 sprites_visible = 0;
295 puts("hello!");
289 while (!done) { 296 while (!done) {
290 /* Check for events */ 297 /* Check for events */
291 ++frames; 298 ++frames;
292 while (SDL_PollEvent(&event)) { 299 printf(".");
293 switch (event.type) { 300 swiWaitForVBlank();
294 case SDL_MOUSEBUTTONDOWN:
295 SDL_WarpMouse(screen->w / 2, screen->h / 2);
296 break;
297 case SDL_KEYDOWN:
298 /* Any keypress quits the app... */
299 case SDL_QUIT:
300 done = 1;
301 break;
302 default:
303 break;
304 }
305 }
306 MoveSprites(screen, background); 301 MoveSprites(screen, background);
307 } 302 }
303 puts("goodbye!");
308 SDL_FreeSurface(sprite); 304 SDL_FreeSurface(sprite);
309 free(mem); 305 free(mem);
310 306
311 /* Print out some timing information */ 307 /* Print out some timing information */
312 now = SDL_GetTicks(); 308 now = SDL_GetTicks();