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, float x, float y, float xm, int dir)
30 pbullet->base.width = 4;
31 pbullet->base.height = 4;
32 pbullet->base.updated = SDL_GetTicks();
33 pbullet->base.alive = YES;
37 pbullet->base.x = x + 32;
38 pbullet->base.xm = BULLET_XM + xm;
43 pbullet->base.xm = -BULLET_XM + xm;
47 pbullet->base.ym = BULLET_STARTING_YM;
50 void bullet_action(bullet_type* pbullet)
53 double frame_ratio = get_frame_ratio(&pbullet->base);
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 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;
112 pupgrade->base.xm = 2;
113 pupgrade->base.ym = -2;
114 pupgrade->base.height = 0;
115 pupgrade->base.updated = SDL_GetTicks();
118 void upgrade_action(upgrade_type *pupgrade)
120 double frame_ratio = get_frame_ratio(&pupgrade->base);
122 if (pupgrade->base.alive)
124 if (pupgrade->base.height < 32)
128 pupgrade->base.height++;
134 if (pupgrade->kind == UPGRADE_MINTS ||
135 pupgrade->kind == UPGRADE_HERRING)
137 pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
138 pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
140 if (issolid(pupgrade->base.x, pupgrade->base.y + 31) ||
141 issolid(pupgrade->base.x + 31, pupgrade->base.y + 31))
143 if (pupgrade->base.ym > 0)
145 if (pupgrade->kind == UPGRADE_MINTS)
147 pupgrade->base.ym = 0;
149 else if (pupgrade->kind == UPGRADE_HERRING)
151 pupgrade->base.ym = -24;
154 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
158 pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
160 if (issolid(pupgrade->base.x, pupgrade->base.y))
162 pupgrade->base.xm = -pupgrade->base.xm;
167 /* Off the screen? Kill it! */
169 if (pupgrade->base.x < scroll_x)
170 pupgrade->base.alive = NO;
176 void upgrade_draw(upgrade_type* pupgrade)
178 if (pupgrade->base.alive)
180 if (pupgrade->base.height < 32)
184 dest.x = pupgrade->base.x - scroll_x;
185 dest.y = pupgrade->base.y + 32 - pupgrade->base.height;
187 dest.h = pupgrade->base.height;
192 src.h = pupgrade->base.height;
194 if (pupgrade->kind == UPGRADE_MINTS)
195 SDL_BlitSurface(img_mints.sdl_surface, &src, screen, &dest);
196 else if (pupgrade->kind == UPGRADE_COFFEE)
197 SDL_BlitSurface(img_coffee.sdl_surface, &src, screen, &dest);
198 else if (pupgrade->kind == UPGRADE_HERRING)
199 SDL_BlitSurface(img_golden_herring.sdl_surface, &src, screen, &dest);
203 if (pupgrade->kind == UPGRADE_MINTS)
205 texture_draw(&img_mints,
206 pupgrade->base.x - scroll_x, pupgrade->base.y,
209 else if (pupgrade->kind == UPGRADE_COFFEE)
211 texture_draw(&img_coffee,
212 pupgrade->base.x - scroll_x, pupgrade->base.y,
215 else if (pupgrade->kind == UPGRADE_HERRING)
217 texture_draw(&img_golden_herring,
218 pupgrade->base.x - scroll_x, pupgrade->base.y,
225 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
227 player_type* pplayer = NULL;
232 /* Remove the upgrade: */
234 /* p_c_object is CO_PLAYER, so assign it to pplayer */
235 pplayer = p_c_object;
237 pupgrade->base.alive = NO;
239 /* Affect the player: */
241 if (pupgrade->kind == UPGRADE_MINTS)
243 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
245 timer_start(&super_bkgd_timer, 350);
247 else if (pupgrade->kind == UPGRADE_COFFEE)
249 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
250 pplayer->got_coffee = YES;
251 timer_start(&super_bkgd_timer, 250);
253 else if (pupgrade->kind == UPGRADE_HERRING)
255 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
256 timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
257 timer_start(&super_bkgd_timer, 250);
258 /* play the herring song ^^ */
259 if (current_music != HURRYUP_MUSIC)
261 current_music = HERRING_MUSIC;