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;
36 pbullet->base.alive = YES;
40 pbullet->base.x = x + 32;
41 pbullet->base.xm = BULLET_XM + xm;
46 pbullet->base.xm = -BULLET_XM + xm;
50 pbullet->base.ym = BULLET_STARTING_YM;
51 pbullet->old_base = pbullet->base;
54 void bullet_action(bullet_type* pbullet)
56 if (pbullet->base.alive)
58 pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
59 pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
61 collision_swept_object_map(&pbullet->old_base,&pbullet->base);
63 if (issolid(pbullet->base.x, pbullet->base.y + 4) || issolid(pbullet->base.x, pbullet->base.y))
65 pbullet->base.ym = -pbullet->base.ym;
66 pbullet->base.y = (int)(pbullet->base.y / 32) * 32;
69 pbullet->base.ym = pbullet->base.ym + GRAVITY;
71 if (pbullet->base.x < scroll_x ||
72 pbullet->base.x > scroll_x + screen->w ||
73 pbullet->base.y < 0 ||
74 pbullet->base.y > screen->h ||
75 issolid(pbullet->base.x + 4, pbullet->base.y + 2) ||
76 issolid(pbullet->base.x, pbullet->base.y + 2))
78 pbullet->base.alive = NO;
84 void bullet_draw(bullet_type* pbullet)
86 if (pbullet->base.alive &&
87 pbullet->base.x >= scroll_x - pbullet->base.width &&
88 pbullet->base.x <= scroll_x + screen->w)
90 texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
95 void bullet_collision(bullet_type* pbullet, int c_object)
98 if(c_object == CO_BADGUY)
99 pbullet->base.alive = NO;
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->base.alive = YES;
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)
123 if (pupgrade->base.alive)
125 if (pupgrade->base.height < 32)
129 pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
130 if(pupgrade->base.height > 32)
131 pupgrade->base.height = 32;
137 if (pupgrade->kind == UPGRADE_MINTS ||
138 pupgrade->kind == UPGRADE_HERRING)
140 pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
141 pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
143 collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
145 /* Off the screen? Kill it! */
147 if (pupgrade->base.x < scroll_x - pupgrade->base.width)
148 pupgrade->base.alive = NO;
149 if (pupgrade->base.y > screen->h)
150 pupgrade->base.alive = NO;
152 if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
153 issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
155 if (pupgrade->base.ym > 0)
157 if (pupgrade->kind == UPGRADE_MINTS)
159 pupgrade->base.ym = 0;
161 else if (pupgrade->kind == UPGRADE_HERRING)
163 pupgrade->base.ym = -8;
166 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
170 pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
172 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
174 if(pupgrade->base.xm < 0)
175 pupgrade->base.xm = -pupgrade->base.xm;
177 else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
179 if(pupgrade->base.xm > 0)
180 pupgrade->base.xm = -pupgrade->base.xm;
188 void upgrade_draw(upgrade_type* pupgrade)
191 if (pupgrade->base.alive)
193 if (pupgrade->base.height < 32)
197 dest.x = (int)(pupgrade->base.x - scroll_x);
198 dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
200 dest.h = (int)pupgrade->base.height;
202 if (pupgrade->kind == UPGRADE_MINTS)
203 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
204 else if (pupgrade->kind == UPGRADE_COFFEE)
205 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
206 else if (pupgrade->kind == UPGRADE_HERRING)
207 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
211 if (pupgrade->kind == UPGRADE_MINTS)
213 texture_draw(&img_mints,
214 pupgrade->base.x - scroll_x, pupgrade->base.y,
217 else if (pupgrade->kind == UPGRADE_COFFEE)
219 texture_draw(&img_coffee,
220 pupgrade->base.x - scroll_x, pupgrade->base.y,
223 else if (pupgrade->kind == UPGRADE_HERRING)
225 texture_draw(&img_golden_herring,
226 pupgrade->base.x - scroll_x, pupgrade->base.y,
233 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
235 player_type* pplayer = NULL;
240 /* Remove the upgrade: */
242 /* p_c_object is CO_PLAYER, so assign it to pplayer */
243 pplayer = (player_type*) p_c_object;
245 pupgrade->base.alive = NO;
247 /* Affect the player: */
249 if (pupgrade->kind == UPGRADE_MINTS)
251 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
253 pplayer->base.height = 64;
254 pplayer->base.y -= 32;
255 if(collision_object_map(&pplayer->base))
257 pplayer->base.height = 32;
258 pplayer->base.y += 32;
261 timer_start(&super_bkgd_timer, 350);
263 else if (pupgrade->kind == UPGRADE_COFFEE)
265 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
266 pplayer->got_coffee = YES;
267 timer_start(&super_bkgd_timer, 250);
269 else if (pupgrade->kind == UPGRADE_HERRING)
271 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
272 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
273 timer_start(&super_bkgd_timer, 250);
274 /* play the herring song ^^ */
275 if (get_current_music() != HURRYUP_MUSIC)
277 set_current_music(HERRING_MUSIC);
278 play_current_music();