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 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;
94 for(i = bullets.begin(); i != bullets.end(); ++i) {
95 if(& (*i) == pbullet) {
103 void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind)
105 pupgrade->base.width = 32;
106 pupgrade->base.height = 0;
107 pupgrade->kind = kind;
108 pupgrade->base.x = x;
109 pupgrade->base.y = y;
111 pupgrade->base.xm = -2;
113 pupgrade->base.xm = 2;
114 pupgrade->base.ym = -2;
115 pupgrade->base.height = 0;
116 pupgrade->old_base = pupgrade->base;
119 void upgrade_action(upgrade_type *pupgrade)
123 if (pupgrade->base.height < 32)
127 pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
128 if(pupgrade->base.height > 32)
129 pupgrade->base.height = 32;
135 if (pupgrade->kind == UPGRADE_MINTS ||
136 pupgrade->kind == UPGRADE_HERRING)
138 pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
139 pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
141 collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
143 /* Off the screen? Kill it! */
145 if (pupgrade->base.x < scroll_x - pupgrade->base.width)
146 upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
147 if (pupgrade->base.y > screen->h)
148 upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
150 if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
151 issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
153 if (pupgrade->base.ym > 0)
155 if (pupgrade->kind == UPGRADE_MINTS)
157 pupgrade->base.ym = 0;
159 else if (pupgrade->kind == UPGRADE_HERRING)
161 pupgrade->base.ym = -8;
164 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
168 pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
170 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
172 if(pupgrade->base.xm < 0)
173 pupgrade->base.xm = -pupgrade->base.xm;
175 else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
177 if(pupgrade->base.xm > 0)
178 pupgrade->base.xm = -pupgrade->base.xm;
185 void upgrade_draw(upgrade_type* pupgrade)
188 if (pupgrade->base.height < 32)
192 dest.x = (int)(pupgrade->base.x - scroll_x);
193 dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
195 dest.h = (int)pupgrade->base.height;
197 if (pupgrade->kind == UPGRADE_MINTS)
198 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h);
199 else if (pupgrade->kind == UPGRADE_COFFEE)
200 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h);
201 else if (pupgrade->kind == UPGRADE_HERRING)
202 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
206 if (pupgrade->kind == UPGRADE_MINTS)
208 texture_draw(&img_mints,
209 pupgrade->base.x - scroll_x, pupgrade->base.y);
211 else if (pupgrade->kind == UPGRADE_COFFEE)
213 texture_draw(&img_coffee,
214 pupgrade->base.x - scroll_x, pupgrade->base.y);
216 else if (pupgrade->kind == UPGRADE_HERRING)
218 texture_draw(&img_golden_herring,
219 pupgrade->base.x - scroll_x, pupgrade->base.y);
224 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
226 Player* pplayer = NULL;
231 /* Remove the upgrade: */
233 /* p_c_object is CO_PLAYER, so assign it to pplayer */
234 pplayer = (Player*) p_c_object;
236 upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
238 /* Affect the player: */
240 if (pupgrade->kind == UPGRADE_MINTS)
242 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
244 pplayer->base.height = 64;
245 pplayer->base.y -= 32;
246 if(collision_object_map(&pplayer->base))
248 pplayer->base.height = 32;
249 pplayer->base.y += 32;
250 pplayer->duck = true;
252 timer_start(&super_bkgd_timer, 350);
254 else if (pupgrade->kind == UPGRADE_COFFEE)
256 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
257 pplayer->got_coffee = true;
258 timer_start(&super_bkgd_timer, 250);
260 else if (pupgrade->kind == UPGRADE_HERRING)
262 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
263 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
264 timer_start(&super_bkgd_timer, 250);
265 /* play the herring song ^^ */
266 if (get_current_music() != HURRYUP_MUSIC)
268 set_current_music(HERRING_MUSIC);
269 play_current_music();