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 int score, distros, level, next_level, game_pause, quit, score_multiplier, endpos, counting_distros, distro_counter;
17 timer_type super_bkgd_timer;
20 bouncy_distro_type *bouncy_distros;
21 broken_brick_type *broken_bricks;
22 bouncy_brick_type *bouncy_bricks;
23 bad_guy_type *bad_guys;
24 floating_score_type *floating_scores;
25 upgrade_type *upgrades;
28 int num_bouncy_distros;
29 int num_broken_bricks;
30 int num_bouncy_bricks;
31 int num_floating_scores;
35 texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
39 /* Initialize all 'dynamic' arrays */
40 void arrays_init(void)
43 num_bouncy_distros = 0;
44 num_broken_bricks = 0;
45 num_bouncy_bricks = 0;
46 num_floating_scores = 0;
50 bouncy_distros = NULL;
53 floating_scores = NULL;
58 /* Free memory of 'dynamic' arrays */
59 void arrays_free(void)
65 free(floating_scores);
70 void set_defaults(void)
77 timer_init(&super_bkgd_timer, YES);
79 counting_distros = NO;
84 /* set current song/music */
85 set_current_music(LEVEL_MUSIC);
90 void add_score(float x, float y, int s)
100 /* Add a floating score thing to the game: */
104 for (i = 0; i < num_floating_scores && found == -1; i++)
106 if (!floating_scores[i].base.alive)
112 ++num_floating_scores;
113 floating_scores = (floating_score_type*) realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
114 floating_score_init(&floating_scores[num_floating_scores-1],x,y,s);
120 floating_score_init(&floating_scores[found],x,y,s);
124 /* Add a bouncy distro: */
126 void add_bouncy_distro(float x, float y)
132 for (i = 0; i < num_bouncy_distros && found == -1; i++)
134 if (!bouncy_distros[i].base.alive)
140 ++num_bouncy_distros;
141 bouncy_distros = (bouncy_distro_type*) realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
142 found = num_bouncy_distros - 1;
147 bouncy_distro_init(&bouncy_distros[found],x,y);
152 /* Add broken brick pieces: */
154 void add_broken_brick(float x, float y)
156 add_broken_brick_piece(x, y, -1, -4);
157 add_broken_brick_piece(x, y + 16, -1.5, -3);
159 add_broken_brick_piece(x + 16, y, 1, -4);
160 add_broken_brick_piece(x + 16, y + 16, 1.5, -3);
164 /* Add a broken brick piece: */
166 void add_broken_brick_piece(float x, float y, float xm, float ym)
172 for (i = 0; i < num_broken_bricks && found == -1; i++)
174 if (!broken_bricks[i].base.alive)
181 broken_bricks = (broken_brick_type*) realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
182 found = num_broken_bricks - 1;
187 broken_brick_init(&broken_bricks[found], x, y, xm, ym);
192 /* Add a bouncy brick piece: */
194 void add_bouncy_brick(float x, float y)
200 for (i = 0; i < num_bouncy_bricks && found == -1; i++)
202 if (!bouncy_bricks[i].base.alive)
209 bouncy_bricks = (bouncy_brick_type*) realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
210 found = num_bouncy_bricks - 1;
215 bouncy_brick_init(&bouncy_bricks[found],x,y);
222 void add_bad_guy(float x, float y, int kind)
228 for (i = 0; i < num_bad_guys && found == -1; i++)
230 if (!bad_guys[i].base.alive)
237 bad_guys = (bad_guy_type*) realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
238 found = num_bad_guys - 1;
243 badguy_init(&bad_guys[found], x, y, kind);
247 /* Add an upgrade: */
249 void add_upgrade(float x, float y, int dir, int kind)
255 for (i = 0; i < num_upgrades && found == -1; i++)
257 if (!upgrades[i].base.alive)
264 upgrades = (upgrade_type*) realloc(upgrades,num_upgrades*sizeof(upgrade_type));
265 found = num_upgrades - 1;
270 upgrade_init(&upgrades[found], x, y, dir, kind);
276 void add_bullet(float x, float y, float xm, int dir)
282 for (i = 0; i < num_bullets && found == -1; i++)
284 if (!bullets[i].base.alive)
291 bullets = (bullet_type*) realloc(bullets,num_bullets*sizeof(bullet_type));
292 found = num_bullets - 1;
297 bullet_init(&bullets[found], x, y, xm, dir);
299 play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);