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);
32 void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
34 pbullet->base.width = 4;
35 pbullet->base.height = 4;
39 pbullet->base.x = x + 32;
40 pbullet->base.xm = BULLET_XM + xm;
45 pbullet->base.xm = -BULLET_XM + xm;
49 pbullet->base.ym = BULLET_STARTING_YM;
50 pbullet->old_base = pbullet->base;
53 void bullet_action(bullet_type* pbullet)
55 pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
56 pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
58 collision_swept_object_map(&pbullet->old_base,&pbullet->base);
60 if (issolid(pbullet->base.x, pbullet->base.y + 4) || issolid(pbullet->base.x, pbullet->base.y))
62 pbullet->base.ym = -pbullet->base.ym;
63 pbullet->base.y = (int)(pbullet->base.y / 32) * 32;
66 pbullet->base.ym = pbullet->base.ym + GRAVITY;
68 if (pbullet->base.x < scroll_x ||
69 pbullet->base.x > scroll_x + screen->w ||
70 pbullet->base.y < 0 ||
71 pbullet->base.y > screen->h ||
72 issolid(pbullet->base.x + 4, pbullet->base.y + 2) ||
73 issolid(pbullet->base.x, pbullet->base.y + 2))
75 World::current()->bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
80 void bullet_draw(bullet_type* pbullet)
82 if (pbullet->base.x >= scroll_x - pbullet->base.width &&
83 pbullet->base.x <= scroll_x + screen->w)
85 texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y, 255,
90 void bullet_collision(bullet_type* pbullet, int c_object)
92 if(c_object == CO_BADGUY) {
93 std::vector<bullet_type>::iterator i;
95 for(i = World::current()->bullets.begin(); i != World::current()->bullets.end(); ++i) {
96 if(& (*i) == pbullet) {
97 World::current()->bullets.erase(i);
104 void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind)
106 pupgrade->base.width = 32;
107 pupgrade->base.height = 0;
108 pupgrade->kind = kind;
109 pupgrade->base.x = x;
110 pupgrade->base.y = y;
112 pupgrade->base.xm = -2;
114 pupgrade->base.xm = 2;
115 pupgrade->base.ym = -2;
116 pupgrade->base.height = 0;
117 pupgrade->old_base = pupgrade->base;
120 void upgrade_action(upgrade_type *pupgrade)
124 if (pupgrade->base.height < 32)
128 pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
129 if(pupgrade->base.height > 32)
130 pupgrade->base.height = 32;
136 if (pupgrade->kind == UPGRADE_MINTS ||
137 pupgrade->kind == UPGRADE_HERRING)
139 pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
140 pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
142 collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
144 /* Off the screen? Kill it! */
146 if (pupgrade->base.x < scroll_x - pupgrade->base.width)
147 World::current()->upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
148 if (pupgrade->base.y > screen->h)
149 World::current()->upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
151 if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
152 issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
154 if (pupgrade->base.ym > 0)
156 if (pupgrade->kind == UPGRADE_MINTS)
158 pupgrade->base.ym = 0;
160 else if (pupgrade->kind == UPGRADE_HERRING)
162 pupgrade->base.ym = -8;
165 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
169 pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
171 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
173 if(pupgrade->base.xm < 0)
174 pupgrade->base.xm = -pupgrade->base.xm;
176 else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
178 if(pupgrade->base.xm > 0)
179 pupgrade->base.xm = -pupgrade->base.xm;
186 void upgrade_draw(upgrade_type* pupgrade)
189 if (pupgrade->base.height < 32)
193 dest.x = (int)(pupgrade->base.x - scroll_x);
194 dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
196 dest.h = (int)pupgrade->base.height;
198 if (pupgrade->kind == UPGRADE_MINTS)
199 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h);
200 else if (pupgrade->kind == UPGRADE_COFFEE)
201 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h);
202 else if (pupgrade->kind == UPGRADE_HERRING)
203 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
207 if (pupgrade->kind == UPGRADE_MINTS)
209 texture_draw(&img_mints,
210 pupgrade->base.x - scroll_x, pupgrade->base.y);
212 else if (pupgrade->kind == UPGRADE_COFFEE)
214 texture_draw(&img_coffee,
215 pupgrade->base.x - scroll_x, pupgrade->base.y);
217 else if (pupgrade->kind == UPGRADE_HERRING)
219 texture_draw(&img_golden_herring,
220 pupgrade->base.x - scroll_x, pupgrade->base.y);
225 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
227 Player* pplayer = NULL;
232 /* Remove the upgrade: */
234 /* p_c_object is CO_PLAYER, so assign it to pplayer */
235 pplayer = (Player*) p_c_object;
237 World::current()->upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
239 /* Affect the player: */
241 if (pupgrade->kind == UPGRADE_MINTS)
243 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
245 pplayer->base.height = 64;
246 pplayer->base.y -= 32;
247 if(collision_object_map(&pplayer->base))
249 pplayer->base.height = 32;
250 pplayer->base.y += 32;
251 pplayer->duck = true;
253 timer_start(&super_bkgd_timer, 350);
255 else if (pupgrade->kind == UPGRADE_COFFEE)
257 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
258 pplayer->got_coffee = true;
259 timer_start(&super_bkgd_timer, 250);
261 else if (pupgrade->kind == UPGRADE_HERRING)
263 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
264 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
265 timer_start(&super_bkgd_timer, 250);
266 /* play the herring song ^^ */
267 if (get_current_music() != HURRYUP_MUSIC)
269 set_current_music(HERRING_MUSIC);
270 play_current_music();