2 // C Implementation: special
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
23 void create_special_bitmasks()
25 bm_bullet = bitmask_create_SDL(img_bullet.sdl_surface);
28 void bullet_init(bullet_type* pbullet)
30 pbullet->it.alive = &pbullet->alive;
31 pbullet->it.x = &pbullet->x;
32 pbullet->it.y = &pbullet->y;
33 pbullet->it.width = &pbullet->width;
34 pbullet->it.height = &pbullet->height;
35 pbullet->it.updated = &pbullet->updated;
39 pbullet->updated = SDL_GetTicks();
43 void bullet_action(bullet_type* pbullet)
46 double frame_ratio = get_frame_ratio(&pbullet->it);
50 pbullet->x = pbullet->x + pbullet->xm * frame_ratio;
51 pbullet->y = pbullet->y + pbullet->ym * frame_ratio;
53 if (issolid(pbullet->x, pbullet->y))
55 if (issolid(pbullet->x, pbullet->y - pbullet->ym))
61 pbullet->y = (int)(pbullet->y / 32) * 32 - 8;
63 pbullet->ym = -pbullet->ym;
67 pbullet->ym = pbullet->ym + GRAVITY;
69 if (pbullet->x < scroll_x ||
70 pbullet->x > scroll_x + screen->w)
78 void bullet_draw(bullet_type* pbullet)
81 pbullet->x >= scroll_x - pbullet->width &&
82 pbullet->x <= scroll_x + screen->w)
84 texture_draw(&img_bullet, pbullet->x - scroll_x, pbullet->y,
89 void bullet_collision(bullet_type* pbullet, int c_object)
92 if(c_object == CO_BADGUY)
97 void upgrade_init(upgrade_type *pupgrade)
99 pupgrade->it.alive = &pupgrade->alive;
100 pupgrade->it.x = &pupgrade->x;
101 pupgrade->it.y = &pupgrade->y;
102 pupgrade->it.width = &pupgrade->width;
103 pupgrade->it.height = &pupgrade->height;
104 pupgrade->it.updated = &pupgrade->updated;
106 pupgrade->width = 32;
107 pupgrade->height = 0;
108 pupgrade->updated = SDL_GetTicks();
109 pupgrade->alive = NO;
112 void upgrade_action(upgrade_type *pupgrade)
114 double frame_ratio = get_frame_ratio(&pupgrade->it);
118 if (pupgrade->height < 32)
128 if (pupgrade->kind == UPGRADE_MINTS ||
129 pupgrade->kind == UPGRADE_HERRING)
131 pupgrade->x = pupgrade->x + pupgrade->xm * frame_ratio;
132 pupgrade->y = pupgrade->y + pupgrade->ym * frame_ratio;
134 if (issolid(pupgrade->x, pupgrade->y + 31) ||
135 issolid(pupgrade->x + 31, pupgrade->y + 31))
137 if (pupgrade->ym > 0)
139 if (pupgrade->kind == UPGRADE_MINTS)
143 else if (pupgrade->kind == UPGRADE_HERRING)
148 pupgrade->y = (int)(pupgrade->y / 32) * 32;
152 pupgrade->ym = pupgrade->ym + GRAVITY;
154 if (issolid(pupgrade->x, pupgrade->y))
156 pupgrade->xm = -pupgrade->xm;
161 /* Off the screen? Kill it! */
163 if (pupgrade->x < scroll_x)
164 pupgrade->alive = NO;
170 void upgrade_draw(upgrade_type* pupgrade)
174 if (pupgrade->height < 32)
178 dest.x = pupgrade->x - scroll_x;
179 dest.y = pupgrade->y + 32 - pupgrade->height;
181 dest.h = pupgrade->height;
186 src.h = pupgrade->height;
188 if (pupgrade->kind == UPGRADE_MINTS)
189 SDL_BlitSurface(img_mints.sdl_surface, &src, screen, &dest);
190 else if (pupgrade->kind == UPGRADE_COFFEE)
191 SDL_BlitSurface(img_coffee.sdl_surface, &src, screen, &dest);
192 else if (pupgrade->kind == UPGRADE_HERRING)
193 SDL_BlitSurface(img_golden_herring.sdl_surface, &src, screen, &dest);
197 if (pupgrade->kind == UPGRADE_MINTS)
199 texture_draw(&img_mints,
200 pupgrade->x - scroll_x, pupgrade->y,
203 else if (pupgrade->kind == UPGRADE_COFFEE)
205 texture_draw(&img_coffee,
206 pupgrade->x - scroll_x, pupgrade->y,
209 else if (pupgrade->kind == UPGRADE_HERRING)
211 texture_draw(&img_golden_herring,
212 pupgrade->x - scroll_x, pupgrade->y,
219 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
221 player_type* pplayer = NULL;
226 /* Remove the upgrade: */
228 /* p_c_object is CO_PLAYER, so assign it to pplayer */
229 pplayer = p_c_object;
231 pupgrade->alive = NO;
233 /* Affect the player: */
235 if (pupgrade->kind == UPGRADE_MINTS)
237 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
241 else if (pupgrade->kind == UPGRADE_COFFEE)
243 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
244 pplayer->got_coffee = YES;
247 else if (pupgrade->kind == UPGRADE_HERRING)
249 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
250 timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
252 /* play the herring song ^^ */
253 if (current_music != HURRYUP_MUSIC)
255 current_music = HERRING_MUSIC;