2 // C Implementation: scene
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
16 /* Initialize all 'dynamic' arrays */
17 void arrays_init(void)
20 num_bouncy_distros = 0;
21 num_broken_bricks = 0;
22 num_bouncy_bricks = 0;
23 num_floating_scores = 0;
27 bouncy_distros = NULL;
30 floating_scores = NULL;
35 /* Free memory of 'dynamic' arrays */
36 void arrays_free(void)
42 free(floating_scores);
47 void set_defaults(void)
53 for (i = 0; i < num_bouncy_distros; i++)
54 bouncy_distros[i].base.alive = NO;
56 for (i = 0; i < num_broken_bricks; i++)
57 broken_bricks[i].base.alive = NO;
59 for (i = 0; i < num_bouncy_bricks; i++)
60 bouncy_bricks[i].base.alive = NO;
62 for (i = 0; i < num_bad_guys; i++)
64 /*bad_guys[i].alive = NO;*/
65 badguy_init(&bad_guys[i]);
68 for (i = 0; i < num_floating_scores; i++)
69 floating_scores[i].base.alive = NO;
71 for (i = 0; i < num_upgrades; i++)
73 /*upgrades[i].alive = NO;*/
74 upgrade_init(&upgrades[i]);
77 for (i = 0; i < num_bullets; i++)
79 /*bullets[i].alive = NO;*/
80 bullet_init(&bullets[i]);
91 counting_distros = NO;
96 /* set current song/music */
97 current_music = LEVEL_MUSIC;
102 void add_score(int x, int y, int s)
112 /* Add a floating score thing to the game: */
116 for (i = 0; i < num_floating_scores && found == -1; i++)
118 if (!floating_scores[i].base.alive)
124 ++num_floating_scores;
125 floating_scores = realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
126 floating_score_init(&floating_scores[num_floating_scores-1],x,y,s);
132 floating_score_init(&floating_scores[found],x,y,s);
136 /* Add a bouncy distro: */
138 void add_bouncy_distro(float x, float y)
144 for (i = 0; i < num_bouncy_distros && found == -1; i++)
146 if (!bouncy_distros[i].base.alive)
152 ++num_bouncy_distros;
153 bouncy_distros = realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
154 found = num_bouncy_distros - 1;
159 bouncy_distros[found].base.alive = YES;
160 bouncy_distros[found].base.x = x;
161 bouncy_distros[found].base.y = y;
162 bouncy_distros[found].base.ym = -6;
167 /* Add broken brick pieces: */
169 void add_broken_brick(float x, float y)
171 add_broken_brick_piece(x, y, -4, -16);
172 add_broken_brick_piece(x, y + 16, -6, -12);
174 add_broken_brick_piece(x + 16, y, 4, -16);
175 add_broken_brick_piece(x + 16, y + 16, 6, -12);
179 /* Add a broken brick piece: */
181 void add_broken_brick_piece(float x, float y, float xm, float ym)
187 for (i = 0; i < num_broken_bricks && found == -1; i++)
189 if (!broken_bricks[i].base.alive)
196 broken_bricks = realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
197 found = num_broken_bricks - 1;
202 broken_bricks[found].base.alive = YES;
203 broken_bricks[found].base.x = x;
204 broken_bricks[found].base.y = y;
205 broken_bricks[found].base.xm = xm;
206 broken_bricks[found].base.ym = ym;
211 /* Add a bouncy brick piece: */
213 void add_bouncy_brick(float x, float y)
219 for (i = 0; i < num_bouncy_bricks && found == -1; i++)
221 if (!bouncy_bricks[i].base.alive)
228 bouncy_bricks = realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
229 found = num_bouncy_bricks - 1;
234 bouncy_bricks[found].base.alive = YES;
235 bouncy_bricks[found].base.x = x;
236 bouncy_bricks[found].base.y = y;
237 bouncy_bricks[found].offset = 0;
238 bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
239 bouncy_bricks[found].shape = shape(x, y);
246 void add_bad_guy(float x, float y, int kind)
252 for (i = 0; i < num_bad_guys && found == -1; i++)
254 if (!bad_guys[i].base.alive)
261 bad_guys = realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
262 badguy_init(&bad_guys[num_bad_guys-1]);
263 found = num_bad_guys - 1;
268 bad_guys[found].base.alive = YES;
269 bad_guys[found].mode = NORMAL;
270 bad_guys[found].dying = NO;
271 bad_guys[found].kind = kind;
272 bad_guys[found].base.x = x;
273 bad_guys[found].base.y = y;
274 bad_guys[found].base.xm = 1.3;
275 bad_guys[found].base.ym = 1.5;
276 bad_guys[found].dir = LEFT;
277 bad_guys[found].seen = NO;
278 timer_init(&bad_guys[found].timer);
282 /* Add an upgrade: */
284 void add_upgrade(float x, float y, int kind)
287 /* we use this pointer to check, if realloc() returned a new memory address */
288 upgrade_type * pointee = upgrades;
293 for (i = 0; i < num_upgrades && found == -1; i++)
295 if (!upgrades[i].base.alive)
302 upgrades = realloc(upgrades,num_upgrades*sizeof(upgrade_type));
303 if(upgrades != pointee)
305 upgrade_init(&upgrades[num_upgrades-1]);
306 found = num_upgrades - 1;
313 for (i = 0; i < num_upgrades && found == -1; i++)
315 upgrade_init(&upgrades[i]);
318 upgrade_init(&upgrades[found]);
319 upgrades[found].base.alive = YES;
320 upgrades[found].kind = kind;
321 upgrades[found].base.x = x;
322 upgrades[found].base.y = y;
323 upgrades[found].base.xm = 2;
324 upgrades[found].base.ym = -2;
325 upgrades[found].base.height = 0;
331 void add_bullet(float x, float y, float xm, int dir)
337 for (i = 0; i < num_bullets && found == -1; i++)
339 if (!bullets[i].base.alive)
346 bullets = realloc(bullets,num_bullets*sizeof(bullet_type));
347 bullet_init(&bullets[num_bullets-1]);
348 found = num_bullets - 1;
353 bullet_init(&bullets[found]);
354 bullets[found].base.alive = YES;
358 bullets[found].base.x = x + 32;
359 bullets[found].base.xm = BULLET_XM + xm;
363 bullets[found].base.x = x;
364 bullets[found].base.xm = -BULLET_XM + xm;
367 bullets[found].base.y = y;
368 bullets[found].base.ym = BULLET_STARTING_YM;
370 play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);