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 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;
117 void upgrade_action(upgrade_type *pupgrade)
120 if (pupgrade->base.alive)
122 if (pupgrade->base.height < 32)
126 pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
127 if(pupgrade->base.height > 32)
128 pupgrade->base.height = 32;
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 = -8;
154 pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
158 pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
160 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
162 if(pupgrade->base.xm < 0)
163 pupgrade->base.xm = -pupgrade->base.xm;
165 else if (issolid(pupgrade->base.x + pupgrade->base.width-1, (int) pupgrade->base.y))
167 if(pupgrade->base.xm > 0)
168 pupgrade->base.xm = -pupgrade->base.xm;
173 /* Off the screen? Kill it! */
175 if (pupgrade->base.x < scroll_x - pupgrade->base.width)
176 pupgrade->base.alive = NO;
182 void upgrade_draw(upgrade_type* pupgrade)
185 if (pupgrade->base.alive)
187 if (pupgrade->base.height < 32)
191 dest.x = (int)(pupgrade->base.x - scroll_x);
192 dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
194 dest.h = (int)pupgrade->base.height;
196 if (pupgrade->kind == UPGRADE_MINTS)
197 texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
198 else if (pupgrade->kind == UPGRADE_COFFEE)
199 texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
200 else if (pupgrade->kind == UPGRADE_HERRING)
201 texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
205 if (pupgrade->kind == UPGRADE_MINTS)
207 texture_draw(&img_mints,
208 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,
217 else if (pupgrade->kind == UPGRADE_HERRING)
219 texture_draw(&img_golden_herring,
220 pupgrade->base.x - scroll_x, pupgrade->base.y,
227 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
229 player_type* pplayer = NULL;
234 /* Remove the upgrade: */
236 /* p_c_object is CO_PLAYER, so assign it to pplayer */
237 pplayer = (player_type*) p_c_object;
239 pupgrade->base.alive = NO;
241 /* Affect the player: */
243 if (pupgrade->kind == UPGRADE_MINTS)
245 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
247 pplayer->base.height = 64;
248 timer_start(&super_bkgd_timer, 350);
250 else if (pupgrade->kind == UPGRADE_COFFEE)
252 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
253 pplayer->got_coffee = YES;
254 timer_start(&super_bkgd_timer, 250);
256 else if (pupgrade->kind == UPGRADE_HERRING)
258 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
259 timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
260 timer_start(&super_bkgd_timer, 250);
261 /* play the herring song ^^ */
262 if (current_music != HURRYUP_MUSIC)
264 current_music = HERRING_MUSIC;