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 texture_type img_bullet;
24 texture_type img_golden_herring;
27 void create_special_bitmasks()
29 bm_bullet = bitmask_create_SDL(img_bullet.sdl_surface);
33 Bullet::init(float x, float y, float xm, int dir)
41 base.xm = BULLET_XM + xm;
46 base.xm = -BULLET_XM + xm;
50 base.ym = BULLET_STARTING_YM;
57 base.x = base.x + base.xm * frame_ratio;
58 base.y = base.y + base.ym * frame_ratio;
60 collision_swept_object_map(&old_base,&base);
62 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
65 base.y = (int)(base.y / 32) * 32;
68 base.ym = base.ym + GRAVITY;
70 if (base.x < scroll_x ||
71 base.x > scroll_x + screen->w ||
74 issolid(base.x + 4, base.y + 2) ||
75 issolid(base.x, base.y + 2))
77 World::current()->bullets.erase(static_cast<std::vector<Bullet>::iterator>(this));
85 if (base.x >= scroll_x - base.width &&
86 base.x <= scroll_x + screen->w)
88 texture_draw(&img_bullet, base.x - scroll_x, base.y, 255,
94 Bullet::collision(int c_object)
96 if(c_object == CO_BADGUY) {
97 std::vector<Bullet>::iterator i;
99 for(i = World::current()->bullets.begin(); i != World::current()->bullets.end(); ++i)
103 World::current()->bullets.erase(i);
111 Upgrade::init(float x_, float y_, int dir_, int kind_)
132 if (base.height < 32)
136 base.height = base.height + 0.7 * frame_ratio;
144 if (kind == UPGRADE_MINTS ||
145 kind == UPGRADE_HERRING)
147 base.x = base.x + base.xm * frame_ratio;
148 base.y = base.y + base.ym * frame_ratio;
150 collision_swept_object_map(&old_base,&base);
152 /* Off the screen? Kill it! */
154 if (base.x < scroll_x - base.width)
155 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
156 if (base.y > screen->h)
157 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
159 if (issolid(base.x + 1, base.y + 32.) ||
160 issolid(base.x + 31., base.y + 32.))
164 if (kind == UPGRADE_MINTS)
168 else if (kind == UPGRADE_HERRING)
173 base.y = (int)(base.y / 32) * 32;
177 base.ym = base.ym + GRAVITY * frame_ratio;
179 if (issolid(base.x - 1, (int) base.y))
184 else if (issolid(base.x + base.width, (int) base.y))
198 if (base.height < 32)
202 dest.x = (int)(base.x - scroll_x);
203 dest.y = (int)(base.y + 32 - base.height);
205 dest.h = (int)base.height;
207 if (kind == UPGRADE_MINTS)
208 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h);
209 else if (kind == UPGRADE_COFFEE)
210 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h);
211 else if (kind == UPGRADE_HERRING)
212 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
216 if (kind == UPGRADE_MINTS)
218 texture_draw(&img_mints,
219 base.x - scroll_x, base.y);
221 else if (kind == UPGRADE_COFFEE)
223 texture_draw(&img_coffee,
224 base.x - scroll_x, base.y);
226 else if (kind == UPGRADE_HERRING)
228 texture_draw(&img_golden_herring,
229 base.x - scroll_x, base.y);
235 Upgrade::collision(void* p_c_object, int c_object)
237 Player* pplayer = NULL;
242 /* Remove the upgrade: */
244 /* p_c_object is CO_PLAYER, so assign it to pplayer */
245 pplayer = (Player*) p_c_object;
247 World::current()->upgrades.erase(static_cast<std::vector<Upgrade>::iterator>(this));
249 /* Affect the player: */
251 if (kind == UPGRADE_MINTS)
253 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
255 pplayer->base.height = 64;
256 pplayer->base.y -= 32;
257 if(collision_object_map(&pplayer->base))
259 pplayer->base.height = 32;
260 pplayer->base.y += 32;
261 pplayer->duck = true;
263 timer_start(&super_bkgd_timer, 350);
265 else if (kind == UPGRADE_COFFEE)
267 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
268 pplayer->got_coffee = true;
269 timer_start(&super_bkgd_timer, 250);
271 else if (kind == UPGRADE_HERRING)
273 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
274 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
275 timer_start(&super_bkgd_timer, 250);
276 /* play the herring song ^^ */
277 if (get_current_music() != HURRYUP_MUSIC)
279 set_current_music(HERRING_MUSIC);
280 play_current_music();