c39fcfa58b3862ad91bfc84c1c5aa6172d6c36da
[supertux.git] / src / scene.cpp
1 //
2 // C Implementation: scene
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include <stdlib.h>
14 #include "scene.h"
15
16 int score;
17 int distros;
18 int level;
19 int next_level;
20 int game_pause;
21 bool quit;
22 int score_multiplier;
23 int endpos;
24 bool counting_distros;
25 int distro_counter;
26 timer_type  super_bkgd_timer;
27 float scroll_x;
28 unsigned int global_frame_counter;
29
30 std::vector<bouncy_distro_type> bouncy_distros;
31 std::vector<broken_brick_type> broken_bricks;
32 std::vector<bouncy_brick_type> bouncy_bricks;
33 std::vector<BadGuy> bad_guys;
34 std::vector<floating_score_type> floating_scores;
35 std::vector<upgrade_type> upgrades;
36 std::vector<bullet_type> bullets;
37 std::vector<ParticleSystem*> particle_systems;
38 Player tux;
39 texture_type img_box_full;
40 texture_type img_box_empty;
41 texture_type img_mints;
42 texture_type img_coffee;
43 texture_type img_super_bkgd;
44 texture_type img_red_glow;
45 timer_type time_left;
46 double frame_ratio;
47
48 void arrays_free(void)
49 {
50 bad_guys.clear();
51 bouncy_distros.clear();
52 broken_bricks.clear();
53 bouncy_bricks.clear();
54 floating_scores.clear();
55 upgrades.clear();
56 bullets.clear();
57 std::vector<ParticleSystem*>::iterator i;
58 for(i = particle_systems.begin(); i != particle_systems.end(); ++i) {
59   delete *i;
60 }
61 particle_systems.clear();
62 }
63
64 void set_defaults(void)
65 {
66   /* Set defaults: */
67   
68   scroll_x = 0;
69
70   score_multiplier = 1;
71   timer_init(&super_bkgd_timer, true);
72
73   counting_distros = false;
74   distro_counter = 0;
75
76   endpos = 0;
77
78   /* set current song/music */
79   set_current_music(LEVEL_MUSIC);
80 }
81
82 void add_score(float x, float y, int s)
83 {
84   score += s;
85
86   floating_score_type new_floating_score;
87   floating_score_init(&new_floating_score,x,y,s);
88   floating_scores.push_back(new_floating_score);
89 }
90
91 void add_bouncy_distro(float x, float y)
92 {
93
94   bouncy_distro_type new_bouncy_distro;
95   bouncy_distro_init(&new_bouncy_distro,x,y);
96   bouncy_distros.push_back(new_bouncy_distro);
97 }
98
99 void add_broken_brick(float x, float y)
100 {
101   add_broken_brick_piece(x, y, -1, -4);
102   add_broken_brick_piece(x, y + 16, -1.5, -3);
103
104   add_broken_brick_piece(x + 16, y, 1, -4);
105   add_broken_brick_piece(x + 16, y + 16, 1.5, -3);
106 }
107
108 void add_broken_brick_piece(float x, float y, float xm, float ym)
109 {
110   broken_brick_type new_broken_brick;
111   broken_brick_init(&new_broken_brick,x,y,xm,ym);
112   broken_bricks.push_back(new_broken_brick);
113 }
114
115 void add_bouncy_brick(float x, float y)
116 {
117   bouncy_brick_type new_bouncy_brick;
118   bouncy_brick_init(&new_bouncy_brick,x,y);
119   bouncy_bricks.push_back(new_bouncy_brick);
120 }
121
122 void add_bad_guy(float x, float y, BadGuyKind kind)
123 {
124   bad_guys.push_back(BadGuy());
125   BadGuy& new_bad_guy = bad_guys.back();
126   
127   new_bad_guy.init(x,y,kind);
128 }
129
130 void add_upgrade(float x, float y, int dir, int kind)
131 {
132   upgrade_type new_upgrade;
133   upgrade_init(&new_upgrade,x,y,dir,kind);
134   upgrades.push_back(new_upgrade);
135 }
136
137 void add_bullet(float x, float y, float xm, int dir)
138 {
139   bullet_type new_bullet;
140   bullet_init(&new_bullet,x,y,xm,dir);
141   bullets.push_back(new_bullet);
142   
143   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
144 }
145
146 // EOF //
147