Mercurial > sdl-ios-xcode
annotate test/nds-test-progs/sprite/source/testsprite.c @ 2686:e9f27fe4f2a1 gsoc2008_nds
Existing testsprite programs made into NDS projects
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Wed, 13 Aug 2008 00:49:03 +0000 |
parents | |
children | 71c56e900f8b |
rev | line source |
---|---|
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
1 /* Simple program: Move N sprites around on the screen as fast as possible */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
2 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
3 #include <stdlib.h> |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
4 #include <stdio.h> |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
5 #include <time.h> |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
6 #include <math.h> |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
7 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
8 #include "SDL.h" |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
9 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
10 #define NUM_SPRITES 100 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
11 #define MAX_SPEED 1 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
12 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
13 SDL_Surface *sprite; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
14 int numsprites; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
15 SDL_Rect *sprite_rects; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
16 SDL_Rect *positions; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
17 SDL_Rect *velocities; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
18 int sprites_visible; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
19 int debug_flip; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
20 Uint16 sprite_w, sprite_h; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
21 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
22 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
23 static void |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
24 quit(int rc) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
25 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
26 SDL_Quit(); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
27 exit(rc); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
28 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
29 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
30 int |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
31 LoadSprite(char *file) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
32 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
33 SDL_Surface *temp; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
34 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
35 /* Load the sprite image */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
36 sprite = SDL_LoadBMP(file); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
37 if (sprite == NULL) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
38 fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
39 return (-1); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
40 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
41 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
42 /* Set transparent pixel as the pixel at (0,0) */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
43 if (sprite->format->palette) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
44 SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL), |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
45 *(Uint8 *) sprite->pixels); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
46 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
47 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
48 /* Convert sprite to video format */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
49 temp = SDL_DisplayFormat(sprite); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
50 SDL_FreeSurface(sprite); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
51 if (temp == NULL) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
52 fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
53 return (-1); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
54 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
55 sprite = temp; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
56 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
57 /* We're ready to roll. :) */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
58 return (0); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
59 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
60 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
61 void |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
62 MoveSprites(SDL_Surface * screen, Uint32 background) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
63 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
64 int i, nupdates; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
65 SDL_Rect area, *position, *velocity; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
66 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
67 nupdates = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
68 /* Erase all the sprites if necessary */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
69 if (sprites_visible) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
70 SDL_FillRect(screen, NULL, background); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
71 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
72 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
73 /* Move the sprite, bounce at the wall, and draw */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
74 for (i = 0; i < numsprites; ++i) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
75 position = &positions[i]; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
76 velocity = &velocities[i]; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
77 position->x += velocity->x; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
78 if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
79 velocity->x = -velocity->x; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
80 position->x += velocity->x; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
81 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
82 position->y += velocity->y; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
83 if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
84 velocity->y = -velocity->y; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
85 position->y += velocity->y; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
86 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
87 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
88 /* Blit the sprite onto the screen */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
89 area = *position; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
90 SDL_BlitSurface(sprite, NULL, screen, &area); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
91 sprite_rects[nupdates++] = area; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
92 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
93 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
94 if (debug_flip) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
95 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
96 static int t = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
97 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
98 Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
99 SDL_Rect r; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
100 r.x = |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
101 (sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
102 r.y = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
103 r.w = 20; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
104 r.h = screen->h; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
105 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
106 SDL_FillRect(screen, &r, color); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
107 t += 2; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
108 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
109 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
110 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
111 /* Update the screen! */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
112 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
113 SDL_Flip(screen); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
114 } else { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
115 SDL_UpdateRects(screen, nupdates, sprite_rects); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
116 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
117 sprites_visible = 1; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
118 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
119 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
120 /* This is a way of telling whether or not to use hardware surfaces */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
121 Uint32 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
122 FastestFlags(Uint32 flags, int width, int height, int bpp) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
123 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
124 const SDL_VideoInfo *info; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
125 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
126 /* Hardware acceleration is only used in fullscreen mode */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
127 flags |= SDL_FULLSCREEN; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
128 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
129 /* Check for various video capabilities */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
130 info = SDL_GetVideoInfo(); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
131 if (info->blit_hw_CC && info->blit_fill) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
132 /* We use accelerated colorkeying and color filling */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
133 flags |= SDL_HWSURFACE; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
134 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
135 /* If we have enough video memory, and will use accelerated |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
136 blits directly to it, then use page flipping. |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
137 */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
138 if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
139 /* Direct hardware blitting without double-buffering |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
140 causes really bad flickering. |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
141 */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
142 if (info->video_mem * 1024 > (height * width * bpp / 8)) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
143 flags |= SDL_DOUBLEBUF; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
144 } else { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
145 flags &= ~SDL_HWSURFACE; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
146 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
147 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
148 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
149 /* Return the flags */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
150 return (flags); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
151 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
152 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
153 int |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
154 main(int argc, char *argv[]) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
155 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
156 SDL_Surface *screen; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
157 Uint8 *mem; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
158 int width, height; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
159 Uint8 video_bpp; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
160 Uint32 videoflags; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
161 Uint32 background; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
162 int i, done; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
163 SDL_Event event; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
164 Uint32 then, now, frames; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
165 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
166 /* Initialize SDL */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
167 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
168 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
169 return (1); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
170 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
171 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
172 numsprites = NUM_SPRITES; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
173 videoflags = SDL_SWSURFACE | SDL_ANYFORMAT; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
174 width = 640; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
175 height = 480; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
176 video_bpp = 8; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
177 debug_flip = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
178 while (argc > 1) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
179 --argc; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
180 if (strcmp(argv[argc - 1], "-width") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
181 width = atoi(argv[argc]); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
182 --argc; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
183 } else if (strcmp(argv[argc - 1], "-height") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
184 height = atoi(argv[argc]); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
185 --argc; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
186 } else if (strcmp(argv[argc - 1], "-bpp") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
187 video_bpp = atoi(argv[argc]); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
188 videoflags &= ~SDL_ANYFORMAT; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
189 --argc; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
190 } else if (strcmp(argv[argc], "-fast") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
191 videoflags = FastestFlags(videoflags, width, height, video_bpp); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
192 } else if (strcmp(argv[argc], "-hw") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
193 videoflags ^= SDL_HWSURFACE; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
194 } else if (strcmp(argv[argc], "-flip") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
195 videoflags ^= SDL_DOUBLEBUF; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
196 } else if (strcmp(argv[argc], "-debugflip") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
197 debug_flip ^= 1; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
198 } else if (strcmp(argv[argc], "-fullscreen") == 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
199 videoflags ^= SDL_FULLSCREEN; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
200 } else if (isdigit(argv[argc][0])) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
201 numsprites = atoi(argv[argc]); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
202 } else { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
203 fprintf(stderr, |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
204 "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n", |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
205 argv[0]); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
206 quit(1); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
207 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
208 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
209 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
210 /* Set video mode */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
211 screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
212 if (!screen) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
213 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
214 width, height, SDL_GetError()); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
215 quit(2); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
216 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
217 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
218 /* Load the sprite */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
219 if (LoadSprite("icon.bmp") < 0) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
220 quit(1); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
221 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
222 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
223 /* Allocate memory for the sprite info */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
224 mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
225 if (mem == NULL) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
226 SDL_FreeSurface(sprite); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
227 fprintf(stderr, "Out of memory!\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
228 quit(2); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
229 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
230 sprite_rects = (SDL_Rect *) mem; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
231 positions = sprite_rects; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
232 sprite_rects += numsprites; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
233 velocities = sprite_rects; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
234 sprite_rects += numsprites; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
235 sprite_w = sprite->w; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
236 sprite_h = sprite->h; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
237 srand(time(NULL)); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
238 for (i = 0; i < numsprites; ++i) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
239 positions[i].x = rand() % (screen->w - sprite_w); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
240 positions[i].y = rand() % (screen->h - sprite_h); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
241 positions[i].w = sprite->w; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
242 positions[i].h = sprite->h; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
243 velocities[i].x = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
244 velocities[i].y = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
245 while (!velocities[i].x && !velocities[i].y) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
246 velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
247 velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
248 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
249 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
250 background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
251 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
252 /* Print out information about our surfaces */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
253 printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
254 if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
255 printf("Screen is in video memory\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
256 } else { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
257 printf("Screen is in system memory\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
258 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
259 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
260 printf("Screen has double-buffering enabled\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
261 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
262 if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
263 printf("Sprite is in video memory\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
264 } else { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
265 printf("Sprite is in system memory\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
266 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
267 /* Run a sample blit to trigger blit acceleration */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
268 { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
269 SDL_Rect dst; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
270 dst.x = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
271 dst.y = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
272 dst.w = sprite->w; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
273 dst.h = sprite->h; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
274 SDL_BlitSurface(sprite, NULL, screen, &dst); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
275 SDL_FillRect(screen, &dst, background); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
276 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
277 if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
278 printf("Sprite blit uses hardware acceleration\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
279 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
280 if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
281 printf("Sprite blit uses RLE acceleration\n"); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
282 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
283 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
284 /* Loop, blitting sprites and waiting for a keystroke */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
285 frames = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
286 then = SDL_GetTicks(); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
287 done = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
288 sprites_visible = 0; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
289 while (!done) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
290 /* Check for events */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
291 ++frames; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
292 while (SDL_PollEvent(&event)) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
293 switch (event.type) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
294 case SDL_MOUSEBUTTONDOWN: |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
295 SDL_WarpMouse(screen->w / 2, screen->h / 2); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
296 break; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
297 case SDL_KEYDOWN: |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
298 /* Any keypress quits the app... */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
299 case SDL_QUIT: |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
300 done = 1; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
301 break; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
302 default: |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
303 break; |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
304 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
305 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
306 MoveSprites(screen, background); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
307 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
308 SDL_FreeSurface(sprite); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
309 free(mem); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
310 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
311 /* Print out some timing information */ |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
312 now = SDL_GetTicks(); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
313 if (now > then) { |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
314 printf("%2.2f frames per second\n", |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
315 ((double) frames * 1000) / (now - then)); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
316 } |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
317 SDL_Quit(); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
318 return (0); |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
319 } |