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
22 #include "resources.h"
24 texture_type img_bullet;
25 texture_type img_golden_herring;
28 void create_special_bitmasks()
30 bm_bullet = bitmask_create_SDL(img_bullet.sdl_surface);
34 Bullet::init(float x, float y, float xm, int dir)
42 base.xm = BULLET_XM + xm;
47 base.xm = -BULLET_XM + xm;
51 base.ym = BULLET_STARTING_YM;
56 Bullet::action(double frame_ratio)
58 base.x = base.x + base.xm * frame_ratio;
59 base.y = base.y + base.ym * frame_ratio;
61 collision_swept_object_map(&old_base,&base);
63 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
66 base.y = (int)(base.y / 32) * 32;
69 base.ym = base.ym + GRAVITY;
71 if (base.x < scroll_x ||
72 base.x > scroll_x + screen->w ||
75 issolid(base.x + 4, base.y + 2) ||
76 issolid(base.x, base.y + 2))
78 World::current()->bullets.erase(static_cast<std::vector<Bullet>::iterator>(this));
86 if (base.x >= scroll_x - base.width &&
87 base.x <= scroll_x + screen->w)
89 texture_draw(&img_bullet, base.x - scroll_x, base.y, 255,
95 Bullet::collision(int c_object)
97 if(c_object == CO_BADGUY) {
98 std::vector<Bullet>::iterator i;
100 for(i = World::current()->bullets.begin(); i != World::current()->bullets.end(); ++i)
104 World::current()->bullets.erase(i);
112 Upgrade::init(float x_, float y_, int dir_, int kind_)
131 Upgrade::action(double frame_ratio)
133 if (base.height < 32)
137 base.height = base.height + 0.7 * frame_ratio;
145 if (kind == UPGRADE_MINTS ||
146 kind == UPGRADE_HERRING)
148 base.x = base.x + base.xm * frame_ratio;
149 base.y = base.y + base.ym * frame_ratio;
151 collision_swept_object_map(&old_base,&base);
153 /* Off the screen? Kill it! */
155 if (base.x < scroll_x - base.width)
156 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
157 if (base.y > screen->h)
158 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
160 if (issolid(base.x + 1, base.y + 32.) ||
161 issolid(base.x + 31., base.y + 32.))
165 if (kind == UPGRADE_MINTS)
169 else if (kind == UPGRADE_HERRING)
174 base.y = (int)(base.y / 32) * 32;
178 base.ym = base.ym + GRAVITY * frame_ratio;
180 if (issolid(base.x - 1, (int) base.y))
185 else if (issolid(base.x + base.width, (int) base.y))
199 if (base.height < 32)
203 dest.x = (int)(base.x - scroll_x);
204 dest.y = (int)(base.y + 32 - base.height);
206 dest.h = (int)base.height;
208 if (kind == UPGRADE_MINTS)
209 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h);
210 else if (kind == UPGRADE_COFFEE)
211 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h);
212 else if (kind == UPGRADE_HERRING)
213 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
217 if (kind == UPGRADE_MINTS)
219 texture_draw(&img_mints,
220 base.x - scroll_x, base.y);
222 else if (kind == UPGRADE_COFFEE)
224 texture_draw(&img_coffee,
225 base.x - scroll_x, base.y);
227 else if (kind == UPGRADE_HERRING)
229 texture_draw(&img_golden_herring,
230 base.x - scroll_x, base.y);
236 Upgrade::collision(void* p_c_object, int c_object)
238 Player* pplayer = NULL;
243 /* Remove the upgrade: */
245 /* p_c_object is CO_PLAYER, so assign it to pplayer */
246 pplayer = (Player*) p_c_object;
248 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
250 /* Affect the player: */
252 if (kind == UPGRADE_MINTS)
254 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
256 pplayer->base.height = 64;
257 pplayer->base.y -= 32;
258 if(collision_object_map(&pplayer->base))
260 pplayer->base.height = 32;
261 pplayer->base.y += 32;
262 pplayer->duck = true;
265 else if (kind == UPGRADE_COFFEE)
267 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
268 pplayer->got_coffee = true;
270 else if (kind == UPGRADE_HERRING)
272 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
273 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
274 /* play the herring song ^^ */
275 if (get_current_music() != HURRYUP_MUSIC)
277 set_current_music(HERRING_MUSIC);
278 play_current_music();