- coverted badguy type into an object
[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 int frame;
29 std::vector<bouncy_distro_type> bouncy_distros;
30 std::vector<broken_brick_type> broken_bricks;
31 std::vector<bouncy_brick_type> bouncy_bricks;
32 std::vector<BadGuy> bad_guys;
33 std::vector<floating_score_type> floating_scores;
34 std::vector<upgrade_type> upgrades;
35 std::vector<bullet_type> bullets;
36 player_type tux;
37 texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
38 timer_type time_left;
39 double frame_ratio;
40
41 /* Initialize all 'dynamic' arrays */
42 void arrays_init(void)
43 {
44 }
45
46 /* Free memory of 'dynamic' arrays */
47 void arrays_free(void)
48 {
49 bad_guys.clear();
50 bouncy_distros.clear();
51 broken_bricks.clear();
52 bouncy_bricks.clear();
53 floating_scores.clear();
54 upgrades.clear();
55 bullets.clear();
56 }
57
58 void set_defaults(void)
59 {
60   /* Set defaults: */
61   
62   scroll_x = 0;
63
64   score_multiplier = 1;
65   timer_init(&super_bkgd_timer, true);
66
67   counting_distros = false;
68   distro_counter = 0;
69
70   endpos = 0;
71
72   /* set current song/music */
73   set_current_music(LEVEL_MUSIC);
74 }
75
76 /* Add score: */
77
78 void add_score(float x, float y, int s)
79 {
80  /* Add the score: */
81
82   score += s;
83
84   floating_score_type new_floating_score;
85   floating_score_init(&new_floating_score,x,y,s);
86   floating_scores.push_back(new_floating_score);
87 }
88
89 /* Add a bouncy distro: */
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
100 /* Add broken brick pieces: */
101
102 void add_broken_brick(float x, float y)
103 {
104   add_broken_brick_piece(x, y, -1, -4);
105   add_broken_brick_piece(x, y + 16, -1.5, -3);
106
107   add_broken_brick_piece(x + 16, y, 1, -4);
108   add_broken_brick_piece(x + 16, y + 16, 1.5, -3);
109 }
110
111
112 /* Add a broken brick piece: */
113
114 void add_broken_brick_piece(float x, float y, float xm, float ym)
115 {
116   broken_brick_type new_broken_brick;
117   broken_brick_init(&new_broken_brick,x,y,xm,ym);
118   broken_bricks.push_back(new_broken_brick);
119 }
120
121
122 /* Add a bouncy brick piece: */
123
124 void add_bouncy_brick(float x, float y)
125 {
126   bouncy_brick_type new_bouncy_brick;
127   bouncy_brick_init(&new_bouncy_brick,x,y);
128   bouncy_bricks.push_back(new_bouncy_brick);
129 }
130
131
132 /* Add a bad guy: */
133
134 void add_bad_guy(float x, float y, BadGuyKind kind)
135 {
136   BadGuy new_bad_guy;
137   new_bad_guy.init(x,y,kind);
138   bad_guys.push_back(new_bad_guy);
139 }
140
141 /* Add an upgrade: */
142
143 void add_upgrade(float x, float y, int dir, int kind)
144 {
145   upgrade_type new_upgrade;
146   upgrade_init(&new_upgrade,x,y,dir,kind);
147   upgrades.push_back(new_upgrade);
148 }
149
150 /* Add a bullet: */
151
152 void add_bullet(float x, float y, float xm, int dir)
153 {
154   bullet_type new_bullet;
155   bullet_init(&new_bullet,x,y,xm,dir);
156   bullets.push_back(new_bullet);
157   
158   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
159 }
160