annotate test/nds-test-progs/sprite2/source/testsprite2.c @ 2698:e1da92da346c gsoc2008_nds

Clean up.
author Darren Alton <dalton@stevens.edu>
date Wed, 27 Aug 2008 04:23:38 +0000
parents c04a266c277a
children
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 <nds.h>
2692
cd8978f47849 Minor cleanups in renderer.
Darren Alton <dalton@stevens.edu>
parents: 2686
diff changeset
7 #include <fat.h>
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
8 #include "common.h"
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
9
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
10 #include "icon_bmp_bin.h"
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
11
2694
c1c7cb1b5a47 More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents: 2692
diff changeset
12 #define NUM_SPRITES 10
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
13 #define MAX_SPEED 1
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
14
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
15 static CommonState *state;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
16 static int num_sprites;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
17 static SDL_TextureID *sprites;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
18 static SDL_bool cycle_color;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
19 static SDL_bool cycle_alpha;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
20 static int cycle_direction = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
21 static int current_alpha = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
22 static int current_color = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
23 static SDL_Rect *positions;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
24 static SDL_Rect *velocities;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
25 static int sprite_w, sprite_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
26 static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
27 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
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 /* 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
30 static void
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
31 quit(int rc)
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 if (sprites) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
34 SDL_free(sprites);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
35 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
36 if (positions) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
37 SDL_free(positions);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
38 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
39 if (velocities) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
40 SDL_free(velocities);
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 CommonQuit(state);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
43 exit(rc);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
44 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
45
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
46 int
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
47 LoadSprite(char *file)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
48 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
49 int i;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
50 SDL_Surface *temp;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
51
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
52 /* Load the sprite image */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
53 temp = SDL_LoadBMP(file);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
54 if (temp == NULL) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
55 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
56 return (-1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
57 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
58 sprite_w = temp->w;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
59 sprite_h = temp->h;
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 /* 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
62 if (temp->format->palette) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
63 SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *) temp->pixels);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
64 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
65
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
66 /* Create textures from the image */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
67 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
68 SDL_SelectRenderer(state->windows[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
69 sprites[i] = SDL_CreateTextureFromSurface(0, temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
70 if (!sprites[i]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
71 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
72 SDL_FreeSurface(temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
73 return (-1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
74 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
75 SDL_SetTextureBlendMode(sprites[i], blendMode);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
76 SDL_SetTextureScaleMode(sprites[i], scaleMode);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
77 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
78 SDL_FreeSurface(temp);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
79
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
80 /* We're ready to roll. :) */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
81 return (0);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
82 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
83
2698
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
84 int
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
85 LoadSprite2(const u8 * ptr, int size)
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
86 {
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
87 int i;
2698
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
88 SDL_Rect r = { 0, 0, 32, 32 };
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
89 for (i = 0; i < state->num_windows; ++i) {
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
90 SDL_SelectRenderer(state->windows[i]);
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
91 sprites[i] = SDL_CreateTexture(SDL_PIXELFORMAT_ABGR1555,
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
92 SDL_TEXTUREACCESS_STATIC, r.w, r.h);
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
93 if (!sprites[i]) {
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
94 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
95 return -1;
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
96 }
2698
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
97 SDL_UpdateTexture(sprites[i], &r, ptr, r.w * 2);
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
98 SDL_SetTextureBlendMode(sprites[i], blendMode);
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
99 SDL_SetTextureScaleMode(sprites[i], scaleMode);
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
100 }
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
101 return 0;
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
102 }
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
103
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
104 void
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
105 MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
106 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
107 int i, n;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
108 int window_w, window_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
109 SDL_Rect area, *position, *velocity;
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 SDL_SelectRenderer(window);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
112
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
113 /* Query the sizes */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
114 SDL_GetWindowSize(window, &window_w, &window_h);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
115
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
116 /* Cycle the color and alpha, if desired */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
117 if (cycle_color) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
118 current_color += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
119 if (current_color < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
120 current_color = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
121 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
122 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
123 if (current_color > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
124 current_color = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
125 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
126 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
127 SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
128 (Uint8) current_color);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
129 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
130 if (cycle_alpha) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
131 current_alpha += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
132 if (current_alpha < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
133 current_alpha = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
134 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
135 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
136 if (current_alpha > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
137 current_alpha = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
138 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
139 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
140 SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
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
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
143 /* 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
144 n = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
145 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
146 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
147 position = &positions[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
148 velocity = &velocities[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
149 position->x += velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
150 if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
151 velocity->x = -velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
152 position->x += velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
153 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
154 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
155 if ((position->y < 0) || (position->y >= (window_h - sprite_w))) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
156 velocity->y = -velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
157 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
158 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
159
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
160 /* Blit the sprite onto the screen */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
161 SDL_RenderCopy(sprite, NULL, position);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
162 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
163
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
164 /* Update the screen! */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
165 SDL_RenderPresent();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
166 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
167
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
168 int
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
169 main(int argc, char *argv[])
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 int i, done;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
172 SDL_Event event;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
173 Uint32 then, now, frames;
2694
c1c7cb1b5a47 More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents: 2692
diff changeset
174
2698
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
175 consoleDemoInit();
e1da92da346c Clean up.
Darren Alton <dalton@stevens.edu>
parents: 2695
diff changeset
176 puts("Hello world! Initializing FAT...");
2692
cd8978f47849 Minor cleanups in renderer.
Darren Alton <dalton@stevens.edu>
parents: 2686
diff changeset
177 fatInitDefault();
2694
c1c7cb1b5a47 More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents: 2692
diff changeset
178
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
179 /* Initialize parameters */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
180 num_sprites = NUM_SPRITES;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
181
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
182 /* Initialize test framework */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
183 state = CommonCreateState(argv, SDL_INIT_VIDEO);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
184 if (!state) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
185 return 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
186 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
187 for (i = 1; i < argc;) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
188 int consumed;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
189
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
190 consumed = CommonArg(state, i);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
191 if (consumed == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
192 consumed = -1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
193 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
194 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
195 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
196 blendMode = SDL_TEXTUREBLENDMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
197 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
198 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
199 blendMode = SDL_TEXTUREBLENDMODE_MASK;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
200 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
201 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
202 blendMode = SDL_TEXTUREBLENDMODE_BLEND;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
203 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
204 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
205 blendMode = SDL_TEXTUREBLENDMODE_ADD;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
206 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
207 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
208 blendMode = SDL_TEXTUREBLENDMODE_MOD;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
209 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
210 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
211 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
212 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
213 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
214 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
215 scaleMode = SDL_TEXTURESCALEMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
216 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
217 } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
218 scaleMode = SDL_TEXTURESCALEMODE_FAST;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
219 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
220 } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
221 scaleMode = SDL_TEXTURESCALEMODE_SLOW;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
222 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
223 } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
224 scaleMode = SDL_TEXTURESCALEMODE_BEST;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
225 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
226 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
227 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
228 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
229 cycle_color = SDL_TRUE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
230 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
231 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
232 cycle_alpha = SDL_TRUE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
233 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
234 } else if (SDL_isdigit(*argv[i])) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
235 num_sprites = SDL_atoi(argv[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
236 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
237 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
238 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
239 if (consumed < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
240 fprintf(stderr,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
241 "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n",
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
242 argv[0], CommonUsage(state));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
243 quit(1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
244 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
245 i += consumed;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
246 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
247 if (!CommonInit(state)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
248 quit(2);
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
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
251 /* Create the windows, initialize the renderers, and load the textures */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
252 sprites =
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
253 (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
254 if (!sprites) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
255 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
256 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
257 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
258 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
259 SDL_SelectRenderer(state->windows[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
260 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
261 }
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
262 if (LoadSprite2(icon_bmp_bin, icon_bmp_bin_size) < 0) {
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
263 printf("errored.\n");
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
264 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
265 }
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 /* Allocate memory for the sprite info */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
268 positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
269 velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
270 if (!positions || !velocities) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
271 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
272 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
273 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
274 srand(time(NULL));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
275 if (scaleMode != SDL_TEXTURESCALEMODE_NONE) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
276 sprite_w += sprite_w / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
277 sprite_h += sprite_h / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
278 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
279 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
280 positions[i].x = rand() % (state->window_w - sprite_w);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
281 positions[i].y = rand() % (state->window_h - sprite_h);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
282 positions[i].w = sprite_w;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
283 positions[i].h = sprite_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
284 velocities[i].x = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
285 velocities[i].y = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
286 while (!velocities[i].x && !velocities[i].y) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
287 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
288 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
289 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
290 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
291
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
292 /* Main render loop */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
293 frames = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
294 then = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
295 done = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
296 while (!done) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
297 /* Check for events */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
298 ++frames;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
299 while (SDL_PollEvent(&event)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
300 CommonEvent(state, &event, &done);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
301 switch (event.type) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
302 case SDL_WINDOWEVENT:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
303 switch (event.window.event) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
304 case SDL_WINDOWEVENT_EXPOSED:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
305 SDL_SelectRenderer(event.window.windowID);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
306 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
307 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
308 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
309 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
310 default:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
311 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
312 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
313 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
314 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
315 MoveSprites(state->windows[i], sprites[i]);
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 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
318
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
319 /* Print out some timing information */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
320 now = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
321 if (now > then) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
322 printf("%2.2f frames per second\n",
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
323 ((double) frames * 1000) / (now - then));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
324 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
325
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
326 quit(0);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
327 return 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
328 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
329
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
330 /* vi: set ts=4 sw=4 expandtab: */