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;
53 void bullet_action(bullet_type* pbullet)
55 if (pbullet->base.alive)
57 pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
58 pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
60 if (issolid(pbullet->base.x, pbullet->base.y))
62 if (issolid(pbullet->base.x, pbullet->base.y - pbullet->base.ym))
63 pbullet->base.alive = NO;
66 if (pbullet->base.ym >= 0)
68 pbullet->base.y = (int)(pbullet->base.y / 32) * 32 - 8;
70 pbullet->base.ym = -pbullet->base.ym;
74 pbullet->base.ym = pbullet->base.ym + GRAVITY;
76 if (pbullet->base.x < scroll_x ||
77 pbullet->base.x > scroll_x + screen->w)
79 pbullet->base.alive = NO;
85 void bullet_draw(bullet_type* pbullet)
87 if (pbullet->base.alive &&
88 pbullet->base.x >= scroll_x - pbullet->base.width &&
89 pbullet->base.x <= scroll_x + screen->w)
91 texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
96 void bullet_collision(bullet_type* pbullet, int c_object)
99 if(c_object == CO_BADGUY)
100 pbullet->base.alive = NO;
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->base.alive = YES;
109 pupgrade->kind = kind;
110 pupgrade->base.x = x;
111 pupgrade->base.y = y;
113 pupgrade->base.xm = -2;
115 pupgrade->base.xm = 2;
116 pupgrade->base.ym = -2;
117 pupgrade->base.height = 0;
118 pupgrade->old_base = pupgrade->base;
121 void upgrade_action(upgrade_type *pupgrade)
124 if (pupgrade->base.alive)
126 if (pupgrade->base.height < 32)
130 pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
131 if(pupgrade->base.height > 32)
132 pupgrade->base.height = 32;
138 if (pupgrade->kind == UPGRADE_MINTS ||
139 pupgrade->kind == UPGRADE_HERRING)
141 pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
142 pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
144 collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
146 /* Off the screen? Kill it! */
148 if (pupgrade->base.x < scroll_x - pupgrade->base.width)
149 pupgrade->base.alive = NO;
150 if (pupgrade->base.y > screen->h)
151 pupgrade->base.alive = NO;
153 if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
154 issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
156 if (pupgrade->base.ym > 0)
158 if (pupgrade->kind == UPGRADE_MINTS)
160 pupgrade->base.ym = 0;
162 else if (pupgrade->kind == UPGRADE_HERRING)
164 pupgrade->base.ym = -8;
167 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
171 pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
173 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
175 if(pupgrade->base.xm < 0)
176 pupgrade->base.xm = -pupgrade->base.xm;
178 else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
180 if(pupgrade->base.xm > 0)
181 pupgrade->base.xm = -pupgrade->base.xm;
189 void upgrade_draw(upgrade_type* pupgrade)
192 if (pupgrade->base.alive)
194 if (pupgrade->base.height < 32)
198 dest.x = (int)(pupgrade->base.x - scroll_x);
199 dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
201 dest.h = (int)pupgrade->base.height;
203 if (pupgrade->kind == UPGRADE_MINTS)
204 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
205 else if (pupgrade->kind == UPGRADE_COFFEE)
206 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
207 else if (pupgrade->kind == UPGRADE_HERRING)
208 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
212 if (pupgrade->kind == UPGRADE_MINTS)
214 texture_draw(&img_mints,
215 pupgrade->base.x - scroll_x, pupgrade->base.y,
218 else if (pupgrade->kind == UPGRADE_COFFEE)
220 texture_draw(&img_coffee,
221 pupgrade->base.x - scroll_x, pupgrade->base.y,
224 else if (pupgrade->kind == UPGRADE_HERRING)
226 texture_draw(&img_golden_herring,
227 pupgrade->base.x - scroll_x, pupgrade->base.y,
234 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
236 player_type* pplayer = NULL;
241 /* Remove the upgrade: */
243 /* p_c_object is CO_PLAYER, so assign it to pplayer */
244 pplayer = (player_type*) p_c_object;
246 pupgrade->base.alive = NO;
248 /* Affect the player: */
250 if (pupgrade->kind == UPGRADE_MINTS)
252 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
254 pplayer->base.height = 64;
255 pplayer->base.y -= 32;
256 if(collision_object_map(&pplayer->base))
258 pplayer->base.height = 32;
259 pplayer->base.y += 32;
262 timer_start(&super_bkgd_timer, 350);
264 else if (pupgrade->kind == UPGRADE_COFFEE)
266 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
267 pplayer->got_coffee = YES;
268 timer_start(&super_bkgd_timer, 250);
270 else if (pupgrade->kind == UPGRADE_HERRING)
272 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
273 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
274 timer_start(&super_bkgd_timer, 250);
275 /* play the herring song ^^ */
276 if (get_current_music() != HURRYUP_MUSIC)
278 set_current_music(HERRING_MUSIC);
279 play_current_music();