annotate test/nds-test-progs/sprite2/source/testsprite2.c @ 2695:c04a266c277a gsoc2008_nds

More sprite-driven texture work in the render/video drivers.
author Darren Alton <dalton@stevens.edu>
date Sun, 17 Aug 2008 09:50:28 +0000
parents c1c7cb1b5a47
children e1da92da346c
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
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
84 int LoadSprite2(const u8* ptr, int size) {
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
85 int i;
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
86 SDL_Rect r = {0,0,32,32};
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
87 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
88 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
89 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
90 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
91 if (!sprites[i]) {
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
92 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
93 return -1;
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
94 }
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
95 SDL_UpdateTexture(sprites[i], &r, ptr, r.w*2);
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
96 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
97 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
98 }
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
99 return 0;
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
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
102 void
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
103 MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
104 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
105 int i, n;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
106 int window_w, window_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
107 SDL_Rect area, *position, *velocity;
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 SDL_SelectRenderer(window);
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 /* Query the sizes */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
112 SDL_GetWindowSize(window, &window_w, &window_h);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
113
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
114 /* Cycle the color and alpha, if desired */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
115 if (cycle_color) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
116 current_color += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
117 if (current_color < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
118 current_color = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
119 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
120 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
121 if (current_color > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
122 current_color = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
123 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
124 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
125 SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
126 (Uint8) current_color);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
127 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
128 if (cycle_alpha) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
129 current_alpha += cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
130 if (current_alpha < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
131 current_alpha = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
132 cycle_direction = -cycle_direction;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
133 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
134 if (current_alpha > 255) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
135 current_alpha = 255;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
136 cycle_direction = -cycle_direction;
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 SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
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
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
141 /* 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
142 n = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
143 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
144 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
145 position = &positions[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
146 velocity = &velocities[i];
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
147 position->x += velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
148 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
149 velocity->x = -velocity->x;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
150 position->x += velocity->x;
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 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
153 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
154 velocity->y = -velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
155 position->y += velocity->y;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
156 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
157
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
158 /* Blit the sprite onto the screen */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
159 SDL_RenderCopy(sprite, NULL, position);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
160 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
161
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
162 /* Update the screen! */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
163 SDL_RenderPresent();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
164 }
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 int
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
167 main(int argc, char *argv[])
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
168 {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
169 int i, done;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
170 SDL_Event event;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
171 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
172
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
173 consoleDemoInit(); puts("Hello world! Initializing FAT...");
2692
cd8978f47849 Minor cleanups in renderer.
Darren Alton <dalton@stevens.edu>
parents: 2686
diff changeset
174 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
175
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
176 /* Initialize parameters */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
177 num_sprites = NUM_SPRITES;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
178
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
179 /* Initialize test framework */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
180 state = CommonCreateState(argv, SDL_INIT_VIDEO);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
181 if (!state) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
182 return 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
183 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
184 for (i = 1; i < argc;) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
185 int consumed;
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 consumed = CommonArg(state, i);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
188 if (consumed == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
189 consumed = -1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
190 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
191 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
192 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
193 blendMode = SDL_TEXTUREBLENDMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
194 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
195 } 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
196 blendMode = SDL_TEXTUREBLENDMODE_MASK;
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], "blend") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
199 blendMode = SDL_TEXTUREBLENDMODE_BLEND;
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], "add") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
202 blendMode = SDL_TEXTUREBLENDMODE_ADD;
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], "mod") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
205 blendMode = SDL_TEXTUREBLENDMODE_MOD;
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 }
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 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
210 if (argv[i + 1]) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
211 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
212 scaleMode = SDL_TEXTURESCALEMODE_NONE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
213 consumed = 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
214 } 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
215 scaleMode = SDL_TEXTURESCALEMODE_FAST;
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], "slow") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
218 scaleMode = SDL_TEXTURESCALEMODE_SLOW;
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], "best") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
221 scaleMode = SDL_TEXTURESCALEMODE_BEST;
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 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
224 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
225 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
226 cycle_color = SDL_TRUE;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
227 consumed = 1;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
228 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
229 cycle_alpha = 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_isdigit(*argv[i])) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
232 num_sprites = SDL_atoi(argv[i]);
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 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
235 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
236 if (consumed < 0) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
237 fprintf(stderr,
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
238 "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
239 argv[0], CommonUsage(state));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
240 quit(1);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
241 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
242 i += consumed;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
243 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
244 if (!CommonInit(state)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
245 quit(2);
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
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
248 /* 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
249 sprites =
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
250 (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
251 if (!sprites) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
252 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
253 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
254 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
255 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
256 SDL_SelectRenderer(state->windows[i]);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
257 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
258 }
2695
c04a266c277a More sprite-driven texture work in the render/video drivers.
Darren Alton <dalton@stevens.edu>
parents: 2694
diff changeset
259 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
260 printf("errored.\n");
2686
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
261 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
262 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
263
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
264 /* Allocate memory for the sprite info */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
265 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
266 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
267 if (!positions || !velocities) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
268 fprintf(stderr, "Out of memory!\n");
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
269 quit(2);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
270 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
271 srand(time(NULL));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
272 if (scaleMode != SDL_TEXTURESCALEMODE_NONE) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
273 sprite_w += sprite_w / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
274 sprite_h += sprite_h / 2;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
275 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
276 for (i = 0; i < num_sprites; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
277 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
278 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
279 positions[i].w = sprite_w;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
280 positions[i].h = sprite_h;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
281 velocities[i].x = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
282 velocities[i].y = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
283 while (!velocities[i].x && !velocities[i].y) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
284 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
285 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
286 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
287 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
288
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
289 /* Main render loop */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
290 frames = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
291 then = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
292 done = 0;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
293 while (!done) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
294 /* Check for events */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
295 ++frames;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
296 while (SDL_PollEvent(&event)) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
297 CommonEvent(state, &event, &done);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
298 switch (event.type) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
299 case SDL_WINDOWEVENT:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
300 switch (event.window.event) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
301 case SDL_WINDOWEVENT_EXPOSED:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
302 SDL_SelectRenderer(event.window.windowID);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
303 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
304 break;
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 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
307 default:
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
308 break;
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
309 }
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 for (i = 0; i < state->num_windows; ++i) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
312 MoveSprites(state->windows[i], sprites[i]);
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 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
315
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
316 /* Print out some timing information */
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
317 now = SDL_GetTicks();
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
318 if (now > then) {
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
319 printf("%2.2f frames per second\n",
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
320 ((double) frames * 1000) / (now - then));
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
321 }
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
322
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
323 quit(0);
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
324 return 0;
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
e9f27fe4f2a1 Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff changeset
327 /* vi: set ts=4 sw=4 expandtab: */