2 // C Implementation: special
7 // Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
23 #include "sprite_manager.h"
24 #include "resources.h"
30 Sprite* img_iceflower;
33 #define GROWUP_SPEED 1.0f
36 Bullet::init(float x, float y, float xm, int dir)
44 base.xm = BULLET_XM + xm;
49 base.xm = -BULLET_XM + xm;
53 base.ym = BULLET_STARTING_YM;
60 std::vector<Bullet>& bullets = World::current()->bullets;
61 for(std::vector<Bullet>::iterator i = bullets.begin();
62 i != bullets.end(); ++i) {
73 Bullet::action(double frame_ratio)
75 base.x = base.x + base.xm * frame_ratio;
76 base.y = base.y + base.ym * frame_ratio;
78 collision_swept_object_map(&old_base,&base);
80 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
83 base.y = (int)(base.y / 32) * 32;
86 base.ym = base.ym + GRAVITY;
88 if (base.x < scroll_x ||
89 base.x > scroll_x + screen->w ||
92 issolid(base.x + 4, base.y + 2) ||
93 issolid(base.x, base.y + 2))
103 if (base.x >= scroll_x - base.width &&
104 base.x <= scroll_x + screen->w)
106 img_bullet->draw( base.x - scroll_x, base.y, 255,
112 Bullet::collision(int c_object)
114 if(c_object == CO_BADGUY) {
120 Upgrade::init(float x_, float y_, int dir_, UpgradeKind kind_)
132 physic.enable_gravity(false);
134 if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
135 physic.set_velocity(dir == LEFT ? -1 : 1, 4);
136 physic.enable_gravity(true);
138 } else if (kind == UPGRADE_ICEFLOWER) {
140 } else if (kind == UPGRADE_GROWUP) {
141 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
143 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
150 std::vector<Upgrade>& upgrades = World::current()->upgrades;
151 for(std::vector<Upgrade>::iterator i = upgrades.begin();
152 i != upgrades.end(); ++i) {
153 if( & (*i) == this) {
163 Upgrade::action(double frame_ratio)
165 if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
166 if (base.height < 32) {
168 base.height = base.height + 0.7 * frame_ratio;
176 /* Off screen? Kill it! */
177 if(base.x < scroll_x - base.width || base.y > screen->h) {
183 physic.apply(frame_ratio, base.x, base.y);
184 if(kind == UPGRADE_GROWUP) {
185 collision_swept_object_map(&old_base, &base);
189 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
191 if(physic.get_velocity_y() != 0) {
192 if(issolid(base.x, base.y + base.height)) {
193 base.y = int(base.y / 32) * 32;
195 if(kind == UPGRADE_GROWUP) {
196 physic.enable_gravity(false);
197 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
198 } else if(kind == UPGRADE_HERRING) {
199 physic.set_velocity(dir == LEFT ? -2 : 2, 3);
203 if((physic.get_velocity_x() < 0
204 && !issolid(base.x+base.width, base.y + base.height))
205 || (physic.get_velocity_x() > 0
206 && !issolid(base.x, base.y + base.height))) {
207 physic.enable_gravity(true);
212 // horizontal bounce?
213 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
214 if ( (physic.get_velocity_x() < 0
215 && issolid(base.x, (int) base.y + base.height/2))
216 || (physic.get_velocity_x() > 0
217 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
218 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
219 dir = dir == LEFT ? RIGHT : LEFT;
228 if (base.height < 32)
232 dest.x = (int)(base.x - scroll_x);
233 dest.y = (int)(base.y + 32 - base.height);
235 dest.h = (int)base.height;
237 if (kind == UPGRADE_GROWUP)
238 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
239 else if (kind == UPGRADE_ICEFLOWER)
240 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
241 else if (kind == UPGRADE_HERRING)
242 img_star->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
243 else if (kind == UPGRADE_1UP)
244 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
248 if (kind == UPGRADE_GROWUP)
251 base.x - scroll_x, base.y);
253 else if (kind == UPGRADE_ICEFLOWER)
256 base.x - scroll_x, base.y);
258 else if (kind == UPGRADE_HERRING)
261 base.x - scroll_x, base.y);
263 else if (kind == UPGRADE_1UP)
265 img_1up->draw( base.x - scroll_x, base.y);
271 Upgrade::collision(void* p_c_object, int c_object)
273 Player* pplayer = NULL;
278 /* Remove the upgrade: */
280 /* p_c_object is CO_PLAYER, so assign it to pplayer */
281 pplayer = (Player*) p_c_object;
283 /* Affect the player: */
285 if (kind == UPGRADE_GROWUP)
287 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
289 pplayer->base.height = 64;
290 pplayer->base.y -= 32;
291 if(collision_object_map(&pplayer->base))
293 pplayer->base.height = 32;
294 pplayer->base.y += 32;
295 pplayer->duck = true;
298 else if (kind == UPGRADE_ICEFLOWER)
300 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
301 pplayer->got_coffee = true;
303 else if (kind == UPGRADE_HERRING)
305 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
306 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
307 /* play the herring song ^^ */
308 if (get_current_music() != HURRYUP_MUSIC)
310 set_current_music(HERRING_MUSIC);
311 play_current_music();
314 else if (kind == UPGRADE_1UP)
316 if(player_status.lives < MAX_LIVES) {
317 player_status.lives++;
318 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
327 void load_special_gfx()
329 img_growup = sprite_manager->load("egg");
330 img_iceflower = sprite_manager->load("iceflower");
331 img_star = sprite_manager->load("star");
332 img_1up = sprite_manager->load("1up");
334 img_bullet = new Surface(datadir + "/images/shared/bullet.png",
338 void free_special_gfx()