2 // C Implementation: player/tux
7 // Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
20 texture_type tux_life,
21 tux_right[3], tux_left[3],
22 bigtux_right[3], bigtux_left[3],
23 bigtux_right_jump, bigtux_left_jump,
24 ducktux_right, ducktux_left,
25 skidtux_right, skidtux_left,
26 firetux_right[3], firetux_left[3],
27 bigfiretux_right[3], bigfiretux_left[3],
28 bigfiretux_right_jump, bigfiretux_left_jump,
29 duckfiretux_right, duckfiretux_left,
30 skidfiretux_right, skidfiretux_left,
31 cape_right[2], cape_left[2],
32 bigcape_right[2], bigcape_left[2];
34 void player_init(player_type* pplayer)
36 pplayer->base.width = 32;
37 pplayer->base.height = 32;
39 pplayer->size = SMALL;
40 pplayer->got_coffee = NO;
43 pplayer->base.y = 240;
50 pplayer->jumping = NO;
52 pplayer->frame_main = 0;
56 pplayer->input.down = UP;
57 pplayer->input.fire = UP;
58 pplayer->input.left = UP;
59 pplayer->input.old_fire = UP;
60 pplayer->input.right = UP;
61 pplayer->input.up = UP;
63 pplayer->keymap.jump = SDLK_UP;
64 pplayer->keymap.duck = SDLK_DOWN;
65 pplayer->keymap.left = SDLK_LEFT;
66 pplayer->keymap.right = SDLK_RIGHT;
67 pplayer->keymap.fire = SDLK_LCTRL;
69 timer_init(&pplayer->invincible_timer);
70 timer_init(&pplayer->skidding_timer);
71 timer_init(&pplayer->safe_timer);
74 int player_keydown_event(player_type* pplayer, SDLKey key)
76 if(key == pplayer->keymap.right)
78 pplayer->input.right = DOWN;
81 else if( key == pplayer->keymap.left)
83 pplayer->input.left = DOWN;
86 else if(key == pplayer->keymap.jump)
88 pplayer->input.up = DOWN;
91 else if(key == pplayer->keymap.duck)
93 pplayer->input.down = DOWN;
96 else if(key == pplayer->keymap.fire)
98 pplayer->input.fire = DOWN;
105 int player_keyup_event(player_type* pplayer, SDLKey key)
107 if(key == pplayer->keymap.right)
109 pplayer->input.right = UP;
112 else if( key == pplayer->keymap.left)
114 pplayer->input.left = UP;
117 else if(key == pplayer->keymap.jump)
119 pplayer->input.up = UP;
122 else if(key == pplayer->keymap.duck)
124 pplayer->input.down = UP;
127 else if(key == pplayer->keymap.fire)
129 pplayer->input.fire = UP;
136 void player_level_begin(player_type* pplayer)
139 pplayer->base.y = 240;
140 pplayer->base.xm = 0;
141 pplayer->base.ym = 0;
143 pplayer->input.down = UP;
144 pplayer->input.fire = UP;
145 pplayer->input.left = UP;
146 pplayer->input.old_fire = UP;
147 pplayer->input.right = UP;
148 pplayer->input.up = UP;
150 timer_init(&pplayer->invincible_timer);
151 timer_init(&pplayer->skidding_timer);
152 timer_init(&pplayer->safe_timer);
155 void player_action(player_type* pplayer)
157 /* --- HANDLE TUX! --- */
159 player_input(pplayer);
163 pplayer->base.x= pplayer->base.x+ pplayer->base.xm * frame_ratio;
164 pplayer->base.y = pplayer->base.y + pplayer->base.ym * frame_ratio;
166 player_keep_in_bounds(pplayer);
172 /* FIXME: this code is COMPLETLY broken!!! */
173 /* if (issolid(pplayer->base.x, pplayer->base.y + 31) &&
174 !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31))
176 while (issolid(pplayer->base.x, pplayer->base.y + 31))
178 if (pplayer->base.xm < 0)
180 else if (pplayer->base.xm > 0)
184 pplayer->base.xm = 0;
187 /*if (issolid(pplayer->base.x, pplayer->base.y) &&
188 !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y))
190 while (issolid(pplayer->base.x, (pplayer->base.y)))
192 if (pplayer->base.xm < 0)
194 else if (pplayer->base.xm > 0)
198 pplayer->base.xm = 0;
201 if (issolid(pplayer->base.x, pplayer->base.y + 31))
203 /* Set down properly: */
206 while (issolid(pplayer->base.x, pplayer->base.y + 31))
211 DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!");
212 /*the circumstances are:
213 issolid() is true and base.ym == 0
214 use of floating point varibles for base stuff*/
217 if (pplayer->base.ym < 0)
219 else if (pplayer->base.ym > 0)
224 /* Reset score multiplier (for multi-hits): */
226 if (pplayer->base.ym > 0)
227 score_multiplier = 1;
232 pplayer->base.ym = 0;
233 pplayer->jumping = NO;
234 pplayer->input.up = UP;
236 /* FIXME: this code is COMPLETLY broken!!! */
237 /*if (issolid(pplayer->base.x, pplayer->base.y) ||
238 (pplayer->size == BIG && !pplayer->duck &&
239 (issolid(pplayer->base.x, pplayer->base.y - 32))))
241 /*if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) &&
242 (pplayer->size == SMALL || pplayer->duck ||
243 !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))*/
245 if (((!issolid(pplayer->base.x, pplayer->base.y- pplayer->base.ym * frame_ratio) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x, pplayer->base.y+31))))
246 ||((!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)))))
247 /*(pplayer->size == SMALL || pplayer->duck ||
248 !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/
250 pplayer->base.y = pplayer->base.y- pplayer->base.ym * frame_ratio;
251 pplayer->base.ym = 0;
254 if (((issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)) && (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y))
255 /*(pplayer->size == SMALL || pplayer->duck ||
256 !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/) ||
257 (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height))))
259 pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio;
260 pplayer->base.xm = 0;
263 if (pplayer->base.ym <= 0)
265 if (isbrick(pplayer->base.x, pplayer->base.y) ||
266 isfullbox(pplayer->base.x, pplayer->base.y))
268 trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
269 trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
270 bumpbrick(pplayer->base.x, pplayer->base.y);
271 tryemptybox(pplayer->base.x, pplayer->base.y);
274 if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
275 isfullbox(pplayer->base.x+ 31, pplayer->base.y))
277 trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
278 trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
279 bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
280 tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
282 /* Get a distro from a brick? */
284 if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
285 shape(pplayer->base.x, pplayer->base.y) == 'y')
287 add_bouncy_distro(((pplayer->base.x+ 1)
289 (int)(pplayer->base.y / 32) * 32);
291 if (counting_distros == NO)
293 counting_distros = YES;
294 distro_counter = 100;
297 if (distro_counter <= 0)
298 level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a');
300 play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
301 score = score + SCORE_DISTRO;
304 else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
305 shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
307 add_bouncy_distro(((pplayer->base.x+ 1 + 31)
309 (int)(pplayer->base.y / 32) * 32);
311 if (counting_distros == NO)
313 counting_distros = YES;
314 distro_counter = 100;
317 if (distro_counter <= 0)
318 level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
320 play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
321 score = score + SCORE_DISTRO;
328 pplayer->base.ym = 0;
329 pplayer->jumping = NO;
330 timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
333 /* Bump into things: * /
335 if (issolid(pplayer->base.x, pplayer->base.y) ||
336 (pplayer->size == BIG && !pplayer->duck &&
337 (issolid(pplayer->base.x, pplayer->base.y - 32))))
340 if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) &&
341 (pplayer->size == SMALL || pplayer->duck ||
342 !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym)))
344 if (pplayer->base.ym <= 0)
347 /* FIXME: this code is COMPLETLY broken!!! */
348 if (pplayer->size == BIG)
350 /* Break bricks and empty boxes: * /
354 if (isbrick(pplayer->base.x, pplayer->base.y - 32) ||
355 isfullbox(pplayer->base.x, pplayer->base.y - 32))
357 trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE);
358 trybumpbadguy(pplayer->base.x, pplayer->base.y - 96);
360 if (isfullbox(pplayer->base.x, pplayer->base.y - 32))
362 bumpbrick(pplayer->base.x, pplayer->base.y - 32);
365 trybreakbrick(pplayer->base.x, pplayer->base.y - 32);
366 tryemptybox(pplayer->base.x, pplayer->base.y - 32);
369 if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) ||
370 isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
372 trygrabdistro(pplayer->base.x+ 31,
373 pplayer->base.y - 64,
375 trybumpbadguy(pplayer->base.x+ 31,
376 pplayer->base.y - 96);
378 if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
380 bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32);
383 trybreakbrick(pplayer->base.x+ 31,
384 pplayer->base.y - 32);
385 tryemptybox(pplayer->base.x+ 31,
386 pplayer->base.y - 32);
391 if (isbrick(pplayer->base.x, pplayer->base.y) ||
392 isfullbox(pplayer->base.x, pplayer->base.y))
394 trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
395 trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
396 if (isfullbox(pplayer->base.x, pplayer->base.y))
397 bumpbrick(pplayer->base.x, pplayer->base.y);
398 trybreakbrick(pplayer->base.x, pplayer->base.y);
399 tryemptybox(pplayer->base.x, pplayer->base.y);
402 if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
403 isfullbox(pplayer->base.x+ 31, pplayer->base.y))
405 trygrabdistro(pplayer->base.x+ 31,
406 pplayer->base.y - 32,
408 trybumpbadguy(pplayer->base.x+ 31,
409 pplayer->base.y - 64);
410 if (isfullbox(pplayer->base.x+ 31, pplayer->base.y))
411 bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
412 trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
413 tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
419 /* It's a brick and we're small, make the brick
420 bounce, and grab any distros above it: * /
422 if (isbrick(pplayer->base.x, pplayer->base.y) ||
423 isfullbox(pplayer->base.x, pplayer->base.y))
425 trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
426 trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
427 bumpbrick(pplayer->base.x, pplayer->base.y);
428 tryemptybox(pplayer->base.x, pplayer->base.y);
431 if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
432 isfullbox(pplayer->base.x+ 31, pplayer->base.y))
434 trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
435 trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
436 bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
437 tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
441 /* Get a distro from a brick? * /
443 if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
444 shape(pplayer->base.x, pplayer->base.y) == 'y')
446 add_bouncy_distro(((pplayer->base.x+ 1)
448 (int)(pplayer->base.y / 32) * 32);
450 if (counting_distros == NO)
452 counting_distros = YES;
453 distro_counter = 100;
456 if (distro_counter <= 0)
457 level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a');
459 play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
460 score = score + SCORE_DISTRO;
463 else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
464 shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
466 add_bouncy_distro(((pplayer->base.x+ 1 + 31)
468 (int)(pplayer->base.y / 32) * 32);
470 if (counting_distros == NO)
472 counting_distros = YES;
473 distro_counter = 100;
476 if (distro_counter <= 0)
477 level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
479 play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
480 score = score + SCORE_DISTRO;
488 pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30;
494 pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32;
497 pplayer->base.ym = 0;
498 pplayer->jumping = NO;
499 timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
506 player_grabdistros(pplayer);
509 /* Slow down horizontally: */
513 if (pplayer->input.right == UP && pplayer->input.left == UP)
515 if (isice(pplayer->base.x, pplayer->base.y + 32) ||
516 !issolid(pplayer->base.x, pplayer->base.y + 32))
518 /* Slowly on ice or in air: */
520 if (pplayer->base.xm > 0)
522 else if (pplayer->base.xm < 0)
527 /* Quickly, otherwise: */
529 pplayer->base.xm = pplayer->base.xm / 2;
534 /* Drop vertically: */
536 if (!issolid(pplayer->base.x, pplayer->base.y + 32))
538 pplayer->base.ym = pplayer->base.ym + GRAVITY;
540 if (pplayer->base.ym > MAX_YM)
541 pplayer->base.ym = MAX_YM;
547 timer_check(&pplayer->safe_timer);
550 /* ---- DONE HANDLING TUX! --- */
552 /* Handle invincibility timer: */
555 if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
558 no, we are no more invincible
559 or we were not in invincible mode
560 but are we in hurry ?
564 if (timer_get_left(&time_left) < TIME_WARNING)
566 /* yes, we are in hurry
567 stop the herring_song, prepare to play the correct
570 current_music = HURRYUP_MUSIC;
574 current_music = LEVEL_MUSIC;
577 /* stop the old music if it's being played */
582 /* Handle skidding: */
584 timer_check(&pplayer->skidding_timer);
588 if (pplayer->base.x - scroll_x >= endpos && endpos != 0)
595 void player_handle_horizontal_input(player_type *pplayer, int dir)
597 if (pplayer->jumping == NO)
599 if ((dir ? (pplayer->base.xm < -SKID_XM) : (pplayer->base.xm > SKID_XM)) && !timer_started(&pplayer->skidding_timer) &&
600 pplayer->dir == !dir)
602 timer_start(&pplayer->skidding_timer, SKID_TIME);
604 play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
610 if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + 32) &&
611 !timer_started(&pplayer->skidding_timer))
613 pplayer->base.xm = 0;
618 if (pplayer->dir == dir)
620 /* Facing the direction we're jumping? Go full-speed: */
622 if (pplayer->input.fire == UP)
624 pplayer->base.xm = pplayer->base.xm + ( dir ? WALK_SPEED : -WALK_SPEED) * frame_ratio;
628 if (pplayer->base.xm > MAX_WALK_XM)
629 pplayer->base.xm = MAX_WALK_XM;
633 if (pplayer->base.xm < -MAX_WALK_XM)
634 pplayer->base.xm = -MAX_WALK_XM;
637 else if ( pplayer->input.fire == DOWN)
639 pplayer->base.xm = pplayer->base.xm + ( dir ? RUN_SPEED : -RUN_SPEED) * frame_ratio;
643 if (pplayer->base.xm > MAX_RUN_XM)
644 pplayer->base.xm = MAX_RUN_XM;
648 if (pplayer->base.xm < -MAX_RUN_XM)
649 pplayer->base.xm = -MAX_RUN_XM;
654 /* Not facing the direction we're jumping?
657 pplayer->base.xm = pplayer->base.xm + ( dir ? (WALK_SPEED / 2) : -(WALK_SPEED / 2)) * frame_ratio;
661 if (pplayer->base.xm > MAX_WALK_XM / 2)
662 pplayer->base.xm = MAX_WALK_XM / 2;
666 if (pplayer->base.xm < -MAX_WALK_XM / 2)
667 pplayer->base.xm = -MAX_WALK_XM / 2;
675 void player_handle_vertical_input(player_type *pplayer)
677 if(!timer_started(&pplayer->jump_timer))
679 timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
684 if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
685 pplayer->base.ym != 0)
687 /* If they're not on the ground, or are currently moving
688 vertically, don't jump! */
690 pplayer->jumping = NO;
691 timer_stop(&pplayer->jump_timer);
695 /* Make sure we're not standing back up into a solid! */
697 if (pplayer->size == SMALL || pplayer->duck == NO ||
698 !issolid(pplayer->base.x, pplayer->base.y))
700 pplayer->jumping = YES;
702 if (pplayer->size == SMALL)
703 play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
705 play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
710 /* Keep jumping for a while: */
712 if (timer_check(&pplayer->jump_timer))
714 pplayer->base.ym = pplayer->base.ym - JUMP_SPEED * frame_ratio;
715 if (pplayer->base.ym < -YM_FOR_JUMP)
716 pplayer->base.ym = -YM_FOR_JUMP;
720 void player_input(player_type *pplayer)
722 /* Handle key and joystick state: */
725 if (pplayer->input.right == DOWN && pplayer->input.left == UP)
727 player_handle_horizontal_input(pplayer,RIGHT);
729 else if (pplayer->input.left == DOWN && pplayer->input.right == UP)
731 player_handle_horizontal_input(pplayer,LEFT);
736 if ( pplayer->input.up == DOWN)
738 player_handle_vertical_input(pplayer);
741 timer_stop(&pplayer->jump_timer);
745 if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee)
747 add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir);
753 if (pplayer->input.down == DOWN)
755 if (pplayer->size == BIG)
760 if (pplayer->size == BIG && pplayer->duck == YES)
762 /* Make sure we're not standing back up into a solid! */
764 if (!issolid(pplayer->base.x, pplayer->base.y - 32))
773 if (pplayer->input.right == UP && pplayer->input.left == UP)
775 pplayer->frame_main = 1;
780 if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
782 pplayer->frame_main = (pplayer->frame_main + 1) % 4;
784 pplayer->frame = pplayer->frame_main;
786 if (pplayer->frame == 3)
792 void player_grabdistros(player_type *pplayer)
797 trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE);
798 trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE);
800 if (pplayer->size == BIG && !pplayer->duck)
802 trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
803 trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
808 /* Enough distros for a One-up? */
810 if (distros >= DISTROS_LIFEUP)
812 distros = distros - DISTROS_LIFEUP;
813 if(pplayer->lives < MAX_LIVES)
815 /*We want to hear the sound even, if MAX_LIVES is reached*/
816 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
820 void player_draw(player_type* pplayer)
822 if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0)
824 if (pplayer->size == SMALL)
826 if (timer_started(&pplayer->invincible_timer))
830 if (pplayer->dir == RIGHT)
832 texture_draw(&cape_right[frame % 2],
833 pplayer->base.x- scroll_x, pplayer->base.y,
838 texture_draw(&cape_left[frame % 2],
839 pplayer->base.x- scroll_x, pplayer->base.y,
845 if (!pplayer->got_coffee)
847 if (pplayer->dir == RIGHT)
849 texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
853 texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
858 /* Tux got coffee! */
860 if (pplayer->dir == RIGHT)
862 texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
866 texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
872 if (timer_started(&pplayer->invincible_timer))
876 if (pplayer->dir == RIGHT)
878 texture_draw(&bigcape_right[frame % 2],
879 pplayer->base.x- scroll_x, pplayer->base.y,
884 texture_draw(&bigcape_left[frame % 2],
885 pplayer->base.x-scroll_x, pplayer->base.y,
890 if (!pplayer->got_coffee)
894 if (!timer_started(&pplayer->skidding_timer))
896 if (!pplayer->jumping || pplayer->base.ym > 0)
898 if (pplayer->dir == RIGHT)
900 texture_draw(&bigtux_right[pplayer->frame],
901 pplayer->base.x- scroll_x, pplayer->base.y,
906 texture_draw(&bigtux_left[pplayer->frame],
907 pplayer->base.x- scroll_x, pplayer->base.y,
913 if (pplayer->dir == RIGHT)
915 texture_draw(&bigtux_right_jump,
916 pplayer->base.x- scroll_x, pplayer->base.y,
921 texture_draw(&bigtux_left_jump,
922 pplayer->base.x- scroll_x, pplayer->base.y,
929 if (pplayer->dir == RIGHT)
931 texture_draw(&skidtux_right,
932 pplayer->base.x- scroll_x, pplayer->base.y,
937 texture_draw(&skidtux_left,
938 pplayer->base.x- scroll_x, pplayer->base.y,
945 if (pplayer->dir == RIGHT)
947 texture_draw(&ducktux_right, pplayer->base.x- scroll_x, pplayer->base.y,
952 texture_draw(&ducktux_left, pplayer->base.x- scroll_x, pplayer->base.y,
959 /* Tux has coffee! */
963 if (!timer_started(&pplayer->skidding_timer))
965 if (!pplayer->jumping || pplayer->base.ym > 0)
967 if (pplayer->dir == RIGHT)
969 texture_draw(&bigfiretux_right[pplayer->frame],
970 pplayer->base.x- scroll_x, pplayer->base.y,
975 texture_draw(&bigfiretux_left[pplayer->frame],
976 pplayer->base.x- scroll_x, pplayer->base.y,
982 if (pplayer->dir == RIGHT)
984 texture_draw(&bigfiretux_right_jump,
985 pplayer->base.x- scroll_x, pplayer->base.y,
990 texture_draw(&bigfiretux_left_jump,
991 pplayer->base.x- scroll_x, pplayer->base.y,
998 if (pplayer->dir == RIGHT)
1000 texture_draw(&skidfiretux_right,
1001 pplayer->base.x- scroll_x, pplayer->base.y,
1006 texture_draw(&skidfiretux_left,
1007 pplayer->base.x- scroll_x, pplayer->base.y,
1014 if (pplayer->dir == RIGHT)
1016 texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x, pplayer->base.y,
1021 texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x, pplayer->base.y,
1030 void player_collision(player_type* pplayer, void* p_c_object, int c_object)
1032 bad_guy_type* pbad_c = NULL;
1037 pbad_c = (bad_guy_type*) p_c_object;
1038 /* Hurt the player if he just touched it: */
1040 if (!pbad_c->dying && !pplayer->dying &&
1041 !timer_started(&pplayer->safe_timer) &&
1042 pbad_c->mode != HELD)
1044 if (pbad_c->mode == FLAT && pplayer->input.fire != DOWN)
1048 pbad_c->mode = KICK;
1049 play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
1051 if (pplayer->base.x<= pbad_c->base.x)
1053 pbad_c->dir = RIGHT;
1054 pbad_c->base.x = pbad_c->base.x + 16;
1059 pbad_c->base.x = pbad_c->base.x - 16;
1062 timer_start(&pbad_c->timer,5000);
1064 else if (pbad_c->mode == FLAT && pplayer->input.fire == DOWN)
1066 pbad_c->mode = HELD;
1069 else if (pbad_c->mode == KICK)
1071 if (pplayer->base.y < pbad_c->base.y - 16 &&
1072 timer_started(&pbad_c->timer))
1074 /* Step on (stop being kicked) */
1076 pbad_c->mode = FLAT;
1077 play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
1078 timer_start(&pbad_c->timer, 10000);
1082 /* Hurt if you get hit by kicked laptop: */
1084 if (timer_started(&pbad_c->timer))
1086 if (!timer_started(&pplayer->invincible_timer))
1088 player_kill(pplayer,SHRINK);
1092 pbad_c->dying = FALLING;
1093 pbad_c->base.ym = -8;
1094 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
1101 if (!timer_started(&pplayer->invincible_timer ))
1103 player_kill(pplayer,SHRINK);
1107 pbad_c->dying = FALLING;
1108 pbad_c->base.ym = -8;
1109 play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
1123 void player_kill(player_type* pplayer, int mode)
1125 pplayer->base.ym = -5;
1127 play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
1129 if (pplayer->dir == RIGHT)
1130 pplayer->base.xm = -8;
1131 else if (pplayer->dir == LEFT)
1132 pplayer->base.xm = 8;
1134 if (mode == SHRINK && pplayer->size == BIG)
1136 if (pplayer->got_coffee)
1137 pplayer->got_coffee = NO;
1139 pplayer->size = SMALL;
1140 pplayer->base.height = 32;
1142 timer_start(&pplayer->safe_timer,TUX_SAFE_TIME);
1150 void player_dying(player_type *pplayer)
1152 pplayer->base.ym = pplayer->base.ym + GRAVITY;
1157 player_remove_powerups(pplayer);
1158 pplayer->dying = NO;
1160 player_level_begin(pplayer);
1164 /* Remove Tux's power ups */
1165 void player_remove_powerups(player_type* pplayer)
1167 pplayer->got_coffee = NO;
1168 pplayer->size = SMALL;
1169 pplayer->base.height = 32;
1172 void player_keep_in_bounds(player_type* pplayer)
1174 /* Keep tux in bounds: */
1175 if (pplayer->base.x< 0)
1177 else if(pplayer->base.x< scroll_x)
1178 pplayer->base.x= scroll_x;
1179 else if (pplayer->base.x< 160 + scroll_x && scroll_x > 0 && debug_mode == YES)
1181 scroll_x = pplayer->base.x- 160;
1182 /*pplayer->base.x+= 160;*/
1188 else if (pplayer->base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
1190 /* Scroll the screen in past center: */
1192 scroll_x = pplayer->base.x- screen->w / 2;
1193 /*pplayer->base.x= 320 + scroll_x;*/
1195 if (scroll_x > ((current_level.width * 32) - screen->w))
1196 scroll_x = ((current_level.width * 32) - screen->w);
1198 else if (pplayer->base.x> 608 + scroll_x)
1200 /* ... unless there's no more to scroll! */
1202 /*pplayer->base.x= 608 + scroll_x;*/
1205 /* Keep in-bounds, vertically: */
1207 if (pplayer->base.y < 0)
1208 pplayer->base.y = 0;
1209 else if (pplayer->base.y > screen->h)
1211 player_kill(&tux,KILL);