2 // C Implementation: badguy
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
19 void badguy_create_bitmasks()
21 /*bm_bsod = img_bsod_left[0];*/
24 void badguy_init(bad_guy_type* pbad)
26 pbad->base.updated = SDL_GetTicks();
27 pbad->base.alive = NO;
28 pbad->base.width = 32;
29 pbad->base.height = 32;
33 void badguy_action(bad_guy_type* pbad)
36 double frame_ratio = get_frame_ratio(&pbad->base);
42 if (pbad->kind == BAD_BSOD)
44 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
46 /* Move left/right: */
48 if (pbad->dying == NO ||
49 pbad->dying == FALLING)
51 if (pbad->dir == RIGHT)
52 pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
53 else if (pbad->dir == LEFT)
54 pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
58 /* Move vertically: */
60 pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
63 /* Bump into things horizontally: */
67 if (issolid(pbad->base.x, pbad->base.y))
68 pbad->dir = !pbad->dir;
71 /* Fall if we get off the ground: */
73 if (pbad->dying != FALLING)
75 if (!issolid(pbad->base.x, pbad->base.y + 32) &&
76 pbad->base.ym < MAX_YM)
78 pbad->base.ym = pbad->base.ym + GRAVITY;
84 if (pbad->base.ym > 0)
86 pbad->base.y = (int)(pbad->base.y / 32) * 32;
92 pbad->base.ym = pbad->base.ym + GRAVITY;
94 if (pbad->base.y > screen->h)
95 pbad->base.alive = NO;
97 else if (pbad->kind == BAD_LAPTOP)
99 /* --- LAPTOP MONSTER: --- */
101 /* Move left/right: */
103 if (pbad->mode != KICK && pbad->mode != HELD)
105 if (pbad->dying == NO ||
106 pbad->dying == FALLING)
108 if (pbad->dir == RIGHT)
109 pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
110 else if (pbad->dir == LEFT)
111 pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
114 else if (pbad->mode == KICK)
117 if (pbad->dir == RIGHT)
118 pbad->base.x = pbad->base.x + 16;
119 else if (pbad->dir == LEFT)
120 pbad->base.x = pbad->base.x - 16;*/
122 else if (pbad->mode == HELD)
123 { /* FIXME: The pbad object shouldn't know about pplayer objects. */
124 /* If we're holding the laptop */
127 pbad->base.x = tux.base.x - 16;
128 pbad->base.y = tux.base.y - 8 - (tux.size*16);
130 else /* facing left */
132 pbad->base.x = tux.base.x - 16;
133 pbad->base.y = tux.base.y - 8 - (tux.size*16);
136 if(tux.input.fire != DOWN) /* SHOOT! */
141 play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
146 /* Move vertically: */
148 if(pbad->mode != HELD)
149 pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
151 /* Bump into things horizontally: */
155 if (issolid(pbad->base.x, pbad->base.y))
157 pbad->dir = !pbad->dir;
159 if (pbad->mode == KICK)
161 /* handle stereo sound */
162 /* FIXME: In theory a badguy object doesn't know anything about player objects */
163 if (tux.base.x > pbad->base.x)
164 play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
165 else if (tux.base.x < pbad->base.x)
166 play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
168 play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
174 /* Fall if we get off the ground: */
176 if (pbad->dying != FALLING)
178 if (!issolid(pbad->base.x, pbad->base.y + 32) &&
179 pbad->base.ym < MAX_YM)
181 if(pbad->mode != HELD)
182 pbad->base.ym = pbad->base.ym + GRAVITY;
188 if (pbad->base.ym > 0)
190 pbad->base.y = (int)(pbad->base.y / 32) * 32;
196 pbad->base.ym = pbad->base.ym + GRAVITY;
198 if (pbad->base.y > screen->h)
199 pbad->base.alive = NO;
201 else if (pbad->kind == BAD_MONEY)
203 /* --- MONEY BAGS: --- */
206 /* Move vertically: */
208 pbad->base.y = pbad->base.y + pbad->base.ym *frame_ratio;
211 /* Fall if we get off the ground: */
213 if (pbad->dying != FALLING)
215 if (!issolid(pbad->base.x, pbad->base.y + 32))
217 if (pbad->base.ym < MAX_YM)
219 pbad->base.ym = pbad->base.ym + GRAVITY;
226 if (pbad->base.ym > 0)
228 pbad->base.y = (int)(pbad->base.y / 32) * 32;
229 pbad->base.ym = -MAX_YM;
234 pbad->base.ym = pbad->base.ym + GRAVITY;
236 if (pbad->base.y > screen->h)
237 pbad->base.alive = NO;
239 else if (pbad->kind == -1)
243 else if (pbad->kind == -1)
249 /* Handle mode timer: */
251 if (pbad->mode == FLAT /* && bad_guys[1].mode != HELD*/)
253 if(!timer_check(&pbad->timer))
256 /* else if (pbad->mode == KICK)
263 /* Handle dying timer: */
265 if (pbad->dying == SQUISHED)
267 /* Remove it if time's up: */
268 if(!timer_check(&pbad->timer))
269 pbad->base.alive = NO;
273 /* Remove if it's far off the screen: */
275 if (pbad->base.x < scroll_x - OFFSCREEN_DISTANCE)
276 pbad->base.alive = NO;
279 /* Once it's on screen, it's activated! */
281 if (pbad->base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
287 void badguy_draw(bad_guy_type* pbad)
289 if (pbad->base.alive &&
290 pbad->base.x > scroll_x - 32 &&
291 pbad->base.x < scroll_x + screen->w)
293 if (pbad->kind == BAD_BSOD)
295 /* --- BLUE SCREEN OF DEATH MONSTER: --- */
297 if (pbad->dying == NO)
301 if (pbad->dir == LEFT)
303 texture_draw(&img_bsod_left[(frame / 5) % 4],
304 pbad->base.x - scroll_x,
310 texture_draw(&img_bsod_right[(frame / 5) % 4],
311 pbad->base.x - scroll_x,
316 else if (pbad->dying == FALLING)
320 if (pbad->dir == LEFT)
322 texture_draw(&img_bsod_falling_left,
323 pbad->base.x - scroll_x,
329 texture_draw(&img_bsod_falling_right,
330 pbad->base.x - scroll_x,
335 else if (pbad->dying == SQUISHED)
337 /* Dying - Squished: */
339 if (pbad->dir == LEFT)
341 texture_draw(&img_bsod_squished_left,
342 pbad->base.x - scroll_x,
348 texture_draw(&img_bsod_squished_right,
349 pbad->base.x - scroll_x,
355 else if (pbad->kind == BAD_LAPTOP)
357 /* --- LAPTOP MONSTER: --- */
359 if (pbad->dying == NO)
363 if (pbad->mode == NORMAL)
367 if (pbad->dir == LEFT)
369 texture_draw(&img_laptop_left[(frame / 5) % 3],
370 pbad->base.x - scroll_x,
376 texture_draw(&img_laptop_right[(frame / 5) % 3],
377 pbad->base.x - scroll_x,
386 if (pbad->dir == LEFT)
388 texture_draw(&img_laptop_flat_left,
389 pbad->base.x - scroll_x,
395 texture_draw(&img_laptop_flat_right,
396 pbad->base.x - scroll_x,
402 else if (pbad->dying == FALLING)
406 if (pbad->dir == LEFT)
408 texture_draw(&img_laptop_falling_left,
409 pbad->base.x - scroll_x,
415 texture_draw(&img_laptop_falling_right,
416 pbad->base.x - scroll_x,
422 else if (pbad->kind == BAD_MONEY)
424 if (pbad->base.ym > -16)
426 if (pbad->dir == LEFT)
428 texture_draw(&img_money_left[0],
429 pbad->base.x - scroll_x,
435 texture_draw(&img_money_right[0],
436 pbad->base.x - scroll_x,
443 if (pbad->dir == LEFT)
445 texture_draw(&img_money_left[1],
446 pbad->base.x - scroll_x,
452 texture_draw(&img_money_right[1],
453 pbad->base.x - scroll_x,
459 else if (pbad->kind == -1)
464 void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
466 bad_guy_type* pbad_c = NULL;
467 player_type* pplayer_c = NULL;
472 pbad->dying = FALLING;
475 /* Gain some points: */
477 if (pbad->kind == BAD_BSOD)
478 add_score(pbad->base.x - scroll_x, pbad->base.y,
479 50 * score_multiplier);
480 else if (pbad->kind == BAD_LAPTOP)
481 add_score(pbad->base.x - scroll_x, pbad->base.y,
482 25 * score_multiplier);
484 /* Play death sound: */
485 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
489 if (pbad->mode != KICK)
490 pbad->dir = !pbad->dir;
493 /* We're in kick mode, kill the other guy: */
495 pbad_c->dying = FALLING;
496 pbad_c->base.ym = -8;
497 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
499 add_score(pbad->base.x - scroll_x,
502 pbad->dir = !pbad->dir;
505 pplayer_c = p_c_object;
506 if (pbad->kind == BAD_BSOD)
508 pbad->dying = SQUISHED;
509 timer_start(&pbad->timer,4000);
510 pplayer_c->base.ym = -KILL_BOUNCE_YM;
512 add_score(pbad->base.x - scroll_x, pbad->base.y,
513 50 * score_multiplier);
515 play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
517 else if (pbad->kind == BAD_LAPTOP)
519 if (pbad->mode != FLAT)
523 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
527 timer_start(&pbad->timer,10000);
529 pplayer_c->base.y = pplayer_c->base.y - 32;
536 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
538 if (pplayer_c->base.x <= pbad->base.x)
543 timer_start(&pbad->timer,5000);
546 pplayer_c->base.ym = -KILL_BOUNCE_YM;
548 add_score(pbad->base.x - scroll_x,
550 25 * score_multiplier);
552 /* play_sound(sounds[SND_SQUISH]); */