- renamed input/input_
[supertux.git] / src / player.cpp
1 //
2 // C Implementation: player/tux
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include "gameloop.h"
14 #include "globals.h"
15 #include "player.h"
16 #include "defines.h"
17 #include "scene.h"
18 #include "screen.h"
19
20 texture_type tux_life;
21 texture_type tux_right[3];
22 texture_type tux_left[3];
23 texture_type bigtux_right[3];
24 texture_type bigtux_left[3];
25 texture_type bigtux_right_jump;
26 texture_type bigtux_left_jump;
27 texture_type ducktux_right;
28 texture_type ducktux_left;
29 texture_type skidtux_right;
30 texture_type skidtux_left;
31 texture_type firetux_right[3];
32 texture_type firetux_left[3];
33 texture_type bigfiretux_right[3];
34 texture_type bigfiretux_left[3];
35 texture_type bigfiretux_right_jump;
36 texture_type bigfiretux_left_jump;
37 texture_type duckfiretux_right;
38 texture_type duckfiretux_left;
39 texture_type skidfiretux_right;
40 texture_type skidfiretux_left;
41 texture_type cape_right[2];
42 texture_type cape_left[2];
43 texture_type bigcape_right[2];
44 texture_type bigcape_left[2];
45
46 void player_input_init(player_input_type* pplayer_input)
47 {
48   pplayer_input->down = UP;
49   pplayer_input->fire = UP;
50   pplayer_input->left = UP;
51   pplayer_input->old_fire = UP;
52   pplayer_input->right = UP;
53   pplayer_input->up = UP;
54 }
55
56 void
57 Player::init()
58 {
59   base.width = 32;
60   base.height = 32;
61
62   size = SMALL;
63   got_coffee = false;
64
65   base.x = 0;
66   base.y = 240;
67   base.xm = 0;
68   base.ym = 0;
69   old_base = base;
70   dir = RIGHT;
71   duck = false;
72
73   dying   = DYING_NOT;
74   jumping = false;
75
76   frame_main = 0;
77   frame_ = 0;
78   lives = 3;
79   score = 0;
80   distros = 0;
81
82   player_input_init(&input);
83
84   keymap.jump  = SDLK_UP;
85   keymap.duck  = SDLK_DOWN;
86   keymap.left  = SDLK_LEFT;
87   keymap.right = SDLK_RIGHT;
88   keymap.fire  = SDLK_LCTRL;
89
90   timer_init(&invincible_timer,true);
91   timer_init(&skidding_timer,true);
92   timer_init(&safe_timer,true);
93   timer_init(&frame_timer,true);
94   physic_init(&hphysic);
95   physic_init(&vphysic);
96 }
97
98 int
99 Player::key_event(SDLKey key, int state)
100 {
101   if(key == keymap.right)
102     {
103       input.right = state;
104       return true;
105     }
106   else if(key == keymap.left)
107     {
108       input.left = state;
109       return true;
110     }
111   else if(key == keymap.jump)
112     {
113       input.up = state;
114       return true;
115     }
116   else if(key == keymap.duck)
117     {
118       input.down = state;
119       return true;
120     }
121   else if(key == keymap.fire)
122     {
123       input.fire = state;
124       return true;
125     }
126   else
127     return false;
128 }
129
130 void
131 Player::level_begin()
132 {
133   base.x = 0;
134   base.y = 240;
135   base.xm = 0;
136   base.ym = 0;
137   old_base = base;
138
139   player_input_init(&input);
140
141   timer_init(&invincible_timer,true);
142   timer_init(&skidding_timer,true);
143   timer_init(&safe_timer,true);
144   timer_init(&frame_timer,true);
145   physic_init(&hphysic);
146   physic_init(&vphysic);
147 }
148
149 void
150 Player::action()
151 {
152   bool jumped_in_solid = false;
153
154   /* --- HANDLE TUX! --- */
155
156   handle_input();
157
158   /* Move tux: */
159
160   previous_base = base;
161
162   base.x += base.xm * frame_ratio;
163   base.y += base.ym * frame_ratio;
164
165   collision_swept_object_map(&old_base,&base);
166
167   keep_in_bounds();
168
169   /* Land: */
170
171   if (!dying)
172     {
173
174
175       if( !on_ground())
176         {
177           if(under_solid())
178             {
179               physic_set_state(&vphysic,PH_VT);
180               physic_set_start_vy(&vphysic,0);
181               jumped_in_solid = true;
182             }
183           else
184             {
185               if(!physic_is_set(&vphysic))
186                 {
187                   physic_set_state(&vphysic,PH_VT);
188                   physic_set_start_vy(&vphysic,0);
189                 }
190             }
191           base.ym = physic_get_velocity(&vphysic);
192
193         }
194       else
195         {
196
197           /* Land: */
198
199           if (base.ym > 0)
200             {
201               base.y = (int)(((int)base.y / 32) * 32);
202               base.ym = 0;
203             }
204
205           physic_init(&vphysic);
206
207           /* Reset score multiplier (for multi-hits): */
208
209           score_multiplier = 1;
210         }
211
212       if(jumped_in_solid)
213         {
214           if (isbrick(base.x, base.y) ||
215               isfullbox(base.x, base.y))
216             {
217               trygrabdistro(base.x, base.y - 32,BOUNCE);
218               trybumpbadguy(base.x, base.y - 64);
219
220               if(size == BIG)
221                 trybreakbrick(base.x, base.y);
222
223               bumpbrick(base.x, base.y);
224               tryemptybox(base.x, base.y, RIGHT);
225             }
226
227           if (isbrick(base.x+ 31, base.y) ||
228               isfullbox(base.x+ 31, base.y))
229             {
230               trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
231               trybumpbadguy(base.x+ 31, base.y - 64);
232
233               if(size == BIG)
234                 trybreakbrick(base.x+ 31, base.y);
235
236               bumpbrick(base.x+ 31, base.y);
237               tryemptybox(base.x+ 31, base.y, LEFT);
238             }
239
240
241           if(size == SMALL)
242             {
243               /* Get a distro from a brick? */
244
245               if (shape(base.x, base.y) == 'x' ||
246                   shape(base.x, base.y) == 'y')
247                 {
248                   add_bouncy_distro((((int)base.x)
249                                      / 32) * 32,
250                                     ((int)base.y / 32) * 32);
251                   if (counting_distros == false)
252                     {
253                       counting_distros = true;
254                       distro_counter = 100;
255                     }
256
257                   if (distro_counter <= 0)
258                     level_change(&current_level,base.x,base.y - 1, 'a');
259
260                   play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
261                   score = score + SCORE_DISTRO;
262                   distros++;
263                 }
264               else if (shape(base.x+ 31, base.y) == 'x' ||
265                        shape(base.x+ 31, base.y) == 'y')
266                 {
267                   add_bouncy_distro((((int)base.x + 31)
268                                      / 32) * 32,
269                                     ((int)base.y / 32) * 32);
270                   if (counting_distros == false)
271                     {
272                       counting_distros = true;
273                       distro_counter = 100;
274                     }
275
276                   if (distro_counter <= 0)
277                     level_change(&current_level,base.x+ 31, base.y, 'a');
278
279                   play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
280                   score = score + SCORE_DISTRO;
281                   distros++;
282                 }
283             }
284         }
285
286       grabdistros();
287
288       if (jumped_in_solid)
289         {
290           ++base.y;
291           ++old_base.y;
292           if(on_ground())
293             {
294               /* Make sure jumping is off. */
295               jumping = false;
296             }
297         }
298
299     }
300
301   timer_check(&safe_timer);
302
303
304   /* ---- DONE HANDLING TUX! --- */
305
306   /* Handle invincibility timer: */
307
308
309   if (get_current_music() == HERRING_MUSIC && !timer_check(&invincible_timer))
310     {
311       /*
312          no, we are no more invincible
313          or we were not in invincible mode
314          but are we in hurry ?
315        */
316
317
318       if (timer_get_left(&time_left) < TIME_WARNING)
319         {
320           /* yes, we are in hurry
321              stop the herring_song, prepare to play the correct
322              fast level_song !
323            */
324           set_current_music(HURRYUP_MUSIC);
325         }
326       else
327         {
328           set_current_music(LEVEL_MUSIC);
329         }
330
331       /* start playing it */
332       play_current_music();
333     }
334
335   /* Handle skidding: */
336
337   timer_check(&skidding_timer);
338
339   /* End of level? */
340
341   if (base.x >= endpos && endpos != 0)
342     {
343       next_level = 1;
344     }
345
346 }
347
348 bool
349 Player::on_ground()
350 {
351   return ( issolid(base.x + base.width / 2, base.y + base.height) ||
352            issolid(base.x + 1, base.y + base.height) ||
353            issolid(base.x + base.width - 1, base.y + base.height)  );
354 }
355
356 bool
357 Player::under_solid()
358 {
359   return ( issolid(base.x + base.width / 2, base.y) ||
360            issolid(base.x + 1, base.y) ||
361            issolid(base.x + base.width - 1, base.y)  );
362 }
363
364 void
365 Player::handle_horizontal_input(int newdir)
366 {
367   if ((newdir ? (base.xm < -SKID_XM) : (base.xm > SKID_XM)) && !timer_started(&skidding_timer) &&
368       dir == !newdir && on_ground())
369     {
370       timer_start(&skidding_timer, SKID_TIME);
371
372       play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
373
374     }
375   dir = newdir;
376
377
378   if ((newdir ? (base.xm < 0) : (base.xm > 0)) && !isice(base.x, base.y + base.height) &&
379       !timer_started(&skidding_timer))
380     {
381       base.xm = 0;
382     }
383
384   if (!duck)
385     {
386       if (dir == newdir)
387         {
388           /* Facing the direction we're jumping?  Go full-speed: */
389
390           if (input.fire == UP)
391             {
392               base.xm = base.xm + ( newdir ? WALK_SPEED : -WALK_SPEED) * frame_ratio;
393
394               if(newdir)
395                 {
396                   if (base.xm > MAX_WALK_XM)
397                     base.xm = MAX_WALK_XM;
398                 }
399               else
400                 {
401                   if (base.xm < -MAX_WALK_XM)
402                     base.xm = -MAX_WALK_XM;
403                 }
404             }
405           else if ( input.fire == DOWN)
406             {
407               base.xm = base.xm + ( newdir ? RUN_SPEED : -RUN_SPEED) * frame_ratio;
408
409               if(newdir)
410                 {
411                   if (base.xm > MAX_RUN_XM)
412                     base.xm = MAX_RUN_XM;
413                 }
414               else
415                 {
416                   if (base.xm < -MAX_RUN_XM)
417                     base.xm = -MAX_RUN_XM;
418                 }
419             }
420           else
421             {
422               /* Not facing the direction we're jumping?
423                  Go half-speed: */
424
425               base.xm = base.xm + ( newdir ? (WALK_SPEED / 2) : -(WALK_SPEED / 2)) * frame_ratio;
426
427               if(newdir)
428                 {
429                   if (base.xm > MAX_WALK_XM / 2)
430                     base.xm = MAX_WALK_XM / 2;
431                 }
432               else
433                 {
434                   if (base.xm < -MAX_WALK_XM / 2)
435                     base.xm = -MAX_WALK_XM / 2;
436                 }
437             }
438         }
439
440     }
441 }
442
443 void
444 Player::handle_vertical_input()
445 {
446   if(input.up == DOWN)
447     {
448       if (on_ground())
449         {
450           if(!physic_is_set(&vphysic))
451             {
452               physic_set_state(&vphysic,PH_VT);
453               physic_set_start_vy(&vphysic,5.5);
454               --base.y;
455               jumping = true;
456               if (size == SMALL)
457                 play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
458               else
459                 play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
460             }
461         }
462     }
463   else if(input.up == UP && jumping)
464     {
465       if (on_ground())
466         {
467           physic_init(&vphysic);
468           jumping = false;
469         }
470       else
471         {
472           jumping = false;
473           if(physic_is_set(&vphysic))
474             {
475               if(physic_get_velocity(&vphysic) < 0.)
476                 {
477                   physic_set_state(&vphysic,PH_VT);
478                   physic_set_start_vy(&vphysic,0);
479                 }
480             }
481           else
482             {
483               if(!physic_is_set(&vphysic))
484                 {
485                   physic_set_state(&vphysic,PH_VT);
486                 }
487             }
488         }
489     }
490 }
491
492 void
493 Player::handle_input()
494 {
495   /* Handle key and joystick state: */
496   if(duck == false)
497     {
498       if (input.right == DOWN && input.left == UP)
499         {
500           handle_horizontal_input(RIGHT);
501         }
502       else if (input.left == DOWN && input.right == UP)
503         {
504           handle_horizontal_input(LEFT);
505         }
506       else
507         {
508           if(base.xm > 0)
509             {
510               base.xm = (int)(base.xm - frame_ratio);
511               if(base.xm < 0)
512                 base.xm = 0;
513             }
514           else if(base.xm < 0)
515             {
516               base.xm = (int)(base.xm + frame_ratio);
517               if(base.xm > 0)
518                 base.xm = 0;
519             }
520         }
521     }
522
523   /* Jump/jumping? */
524
525   if ( input.up == DOWN || (input.up == UP && jumping))
526     {
527       handle_vertical_input();
528     }
529
530   /* Shoot! */
531
532   if (input.fire == DOWN && input.old_fire == UP && got_coffee)
533     {
534       add_bullet(base.x, base.y, base.xm, dir);
535     }
536
537
538   /* Duck! */
539
540   if (input.down == DOWN)
541     {
542       if (size == BIG && duck != true)
543         {
544           duck = true;
545           base.height = 32;
546           base.y += 32;
547         }
548     }
549   else
550     {
551       if (size == BIG && duck)
552         {
553           /* Make sure we're not standing back up into a solid! */
554           base.height = 64;
555           base.y -= 32;
556
557           if (!collision_object_map(&base) /*issolid(base.x + 16, base.y - 16)*/)
558             {
559               duck = false;
560               base.height = 64;
561               old_base.y -= 32;
562               old_base.height = 64;
563             }
564           else
565             {
566               base.height = 32;
567               base.y += 32;
568             }
569         }
570       else
571         {
572           duck = false;
573         }
574     }
575
576   /* (Tux): */
577
578   if(!timer_check(&frame_timer))
579     {
580       timer_start(&frame_timer,25);
581       if (input.right == UP && input.left == UP)
582         {
583           frame_main = 1;
584           frame_ = 1;
585         }
586       else
587         {
588           if ((input.fire == DOWN && (global_frame_counter % 2) == 0) ||
589               (global_frame_counter % 4) == 0)
590             frame_main = (frame_main + 1) % 4;
591
592           frame_ = frame_main;
593
594           if (frame_ == 3)
595             frame_ = 1;
596         }
597     }
598
599 }
600
601 void
602 Player::grabdistros()
603 {
604   /* Grab distros: */
605   if (!dying)
606     {
607       trygrabdistro(base.x, base.y, NO_BOUNCE);
608       trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
609
610       trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
611       trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
612
613       if(size == BIG)
614         {
615           trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
616           trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
617         }
618
619     }
620
621   /* Enough distros for a One-up? */
622   if (distros >= DISTROS_LIFEUP)
623     {
624       distros = distros - DISTROS_LIFEUP;
625       if(lives < MAX_LIVES)
626         lives++;
627       /*We want to hear the sound even, if MAX_LIVES is reached*/
628       play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
629     }
630 }
631
632 void
633 Player::draw()
634 {
635   if (!timer_started(&safe_timer) || (global_frame_counter % 2) == 0)
636     {
637       if (size == SMALL)
638         {
639           if (timer_started(&invincible_timer))
640             {
641               /* Draw cape: */
642
643               if (dir == RIGHT)
644                 {
645                   texture_draw(&cape_right[global_frame_counter % 2],
646                                base.x- scroll_x, base.y);
647                 }
648               else
649                 {
650                   texture_draw(&cape_left[global_frame_counter % 2],
651                                base.x- scroll_x, base.y);
652                 }
653             }
654
655
656           if (!got_coffee)
657             {
658               if (dir == RIGHT)
659                 {
660                   texture_draw(&tux_right[frame_], base.x- scroll_x, base.y);
661                 }
662               else
663                 {
664                   texture_draw(&tux_left[frame_], base.x- scroll_x, base.y);
665                 }
666             }
667           else
668             {
669               /* Tux got coffee! */
670
671               if (dir == RIGHT)
672                 {
673                   texture_draw(&firetux_right[frame_], base.x- scroll_x, base.y);
674                 }
675               else
676                 {
677                   texture_draw(&firetux_left[frame_], base.x- scroll_x, base.y);
678                 }
679             }
680         }
681       else
682         {
683           if (timer_started(&invincible_timer))
684             {
685               /* Draw cape: */
686               if (dir == RIGHT)
687                 {
688                   texture_draw(&bigcape_right[global_frame_counter % 2],
689                                base.x- scroll_x - 8, base.y);
690                 }
691               else
692                 {
693                   texture_draw(&bigcape_left[global_frame_counter % 2],
694                                base.x-scroll_x - 8, base.y);
695                 }
696             }
697
698           if (!got_coffee)
699             {
700               if (!duck)
701                 {
702                   if (!timer_started(&skidding_timer))
703                     {
704                       if (!jumping || base.ym > 0)
705                         {
706                           if (dir == RIGHT)
707                             {
708                               texture_draw(&bigtux_right[frame_],
709                                            base.x- scroll_x - 8, base.y);
710                             }
711                           else
712                             {
713                               texture_draw(&bigtux_left[frame_],
714                                            base.x- scroll_x - 8, base.y);
715                             }
716                         }
717                       else
718                         {
719                           if (dir == RIGHT)
720                             {
721                               texture_draw(&bigtux_right_jump,
722                                            base.x- scroll_x - 8, base.y);
723                             }
724                           else
725                             {
726                               texture_draw(&bigtux_left_jump,
727                                            base.x- scroll_x - 8, base.y);
728                             }
729                         }
730                     }
731                   else
732                     {
733                       if (dir == RIGHT)
734                         {
735                           texture_draw(&skidtux_right,
736                                        base.x- scroll_x - 8, base.y);
737                         }
738                       else
739                         {
740                           texture_draw(&skidtux_left,
741                                        base.x- scroll_x - 8, base.y);
742                         }
743                     }
744                 }
745               else
746                 {
747                   if (dir == RIGHT)
748                     {
749                       texture_draw(&ducktux_right, base.x- scroll_x - 8, base.y - 16);
750                     }
751                   else
752                     {
753                       texture_draw(&ducktux_left, base.x- scroll_x - 8, base.y - 16);
754                     }
755                 }
756             }
757           else
758             {
759               /* Tux has coffee! */
760
761               if (!duck)
762                 {
763                   if (!timer_started(&skidding_timer))
764                     {
765                       if (!jumping || base.ym > 0)
766                         {
767                           if (dir == RIGHT)
768                             {
769                               texture_draw(&bigfiretux_right[frame_],
770                                            base.x- scroll_x - 8, base.y);
771                             }
772                           else
773                             {
774                               texture_draw(&bigfiretux_left[frame_],
775                                            base.x- scroll_x - 8, base.y);
776                             }
777                         }
778                       else
779                         {
780                           if (dir == RIGHT)
781                             {
782                               texture_draw(&bigfiretux_right_jump,
783                                            base.x- scroll_x - 8, base.y);
784                             }
785                           else
786                             {
787                               texture_draw(&bigfiretux_left_jump,
788                                            base.x- scroll_x - 8, base.y);
789                             }
790                         }
791                     }
792                   else
793                     {
794                       if (dir == RIGHT)
795                         {
796                           texture_draw(&skidfiretux_right,
797                                        base.x- scroll_x - 8, base.y);
798                         }
799                       else
800                         {
801                           texture_draw(&skidfiretux_left,
802                                        base.x- scroll_x - 8, base.y);
803                         }
804                     }
805                 }
806               else
807                 {
808                   if (dir == RIGHT)
809                     {
810                       texture_draw(&duckfiretux_right, base.x- scroll_x - 8, base.y - 16);
811                     }
812                   else
813                     {
814                       texture_draw(&duckfiretux_left, base.x- scroll_x - 8, base.y - 16);
815                     }
816                 }
817             }
818         }
819     }
820 }
821
822 void
823 Player::collision(void* p_c_object, int c_object)
824 {
825   BadGuy* pbad_c = NULL;
826
827   switch (c_object)
828     {
829     case CO_BADGUY:
830       pbad_c = (BadGuy*) p_c_object;
831       /* Hurt the player if he just touched it: */
832
833       if (!pbad_c->dying && !dying &&
834           !timer_started(&safe_timer) &&
835           pbad_c->mode != HELD)
836         {
837           if (pbad_c->mode == FLAT  && input.fire != DOWN)
838             {
839               /* Kick: */
840
841               pbad_c->mode = KICK;
842               play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
843
844               if (base.x < pbad_c->base.x + (pbad_c->base.width/2))
845                 {
846                   pbad_c->dir = RIGHT;
847                   pbad_c->base.x = pbad_c->base.x + 16;
848                 }
849               else
850                 {
851                   pbad_c->dir = LEFT;
852                   pbad_c->base.x = pbad_c->base.x - 32;
853                 }
854
855               timer_start(&pbad_c->timer,5000);
856             }
857           else if (pbad_c->mode == FLAT && input.fire == DOWN)
858             {
859               pbad_c->mode = HELD;
860               pbad_c->base.y-=8;
861             }
862           else if (pbad_c->mode == KICK)
863             {
864               if (base.y < pbad_c->base.y - 16 &&
865                   timer_started(&pbad_c->timer))
866                 {
867                   /* Step on (stop being kicked) */
868
869                   pbad_c->mode = FLAT;
870                   play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
871                   timer_start(&pbad_c->timer, 10000);
872                 }
873               else
874                 {
875                   /* Hurt if you get hit by kicked laptop: */
876
877                   if (timer_started(&pbad_c->timer))
878                     {
879                       if (!timer_started(&invincible_timer))
880                         {
881                           kill(SHRINK);
882                         }
883                       else
884                         {
885                           pbad_c->dying = DYING_FALLING;
886                           play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
887                           add_score(pbad_c->base.x - scroll_x,
888                                     pbad_c->base.y,
889                                     25 * score_multiplier);
890                         }
891                     }
892                 }
893             }
894           else
895             {
896               if (!timer_started(&invincible_timer ))
897                 {
898                   kill(SHRINK);
899                 }
900               else
901                 {
902                   pbad_c->dying = DYING_FALLING;
903                   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
904                   add_score(pbad_c->base.x - scroll_x,
905                             pbad_c->base.y,
906                             25 * score_multiplier);
907                 }
908             }
909           score_multiplier++;
910         }
911       break;
912     default:
913       break;
914     }
915
916 }
917
918 /* Kill Player! */
919
920 void
921 Player::kill(int mode)
922 {
923   base.ym = -5;
924
925   play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
926
927   if (dir == RIGHT)
928     base.xm = -8;
929   else if (dir == LEFT)
930     base.xm = 8;
931
932   if (mode == SHRINK && size == BIG)
933     {
934       if (got_coffee)
935         got_coffee = false;
936
937       size = SMALL;
938       base.height = 32;
939
940       timer_start(&safe_timer,TUX_SAFE_TIME);
941     }
942   else
943     {
944       dying = DYING_SQUISHED;
945     }
946 }
947
948 void
949 Player::is_dying()
950 {
951   base.ym = base.ym + gravity;
952
953   /* He died :^( */
954
955   --lives;
956   remove_powerups();
957   dying = DYING_NOT;
958   
959   level_begin();
960
961 }
962
963 /* Remove Tux's power ups */
964 void
965 Player::remove_powerups()
966 {
967   got_coffee = false;
968   size = SMALL;
969   base.height = 32;
970 }
971
972 void
973 Player::keep_in_bounds()
974 {
975   /* Keep tux in bounds: */
976   if (base.x< 0)
977     base.x= 0;
978   else if(base.x< scroll_x)
979     base.x= scroll_x;
980   else if (base.x< 160 + scroll_x && scroll_x > 0 && debug_mode)
981     {
982       scroll_x = base.x- 160;
983       /*base.x+= 160;*/
984
985       if(scroll_x < 0)
986         scroll_x = 0;
987
988     }
989   else if (base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
990     {
991       /* Scroll the screen in past center: */
992
993       scroll_x = base.x- screen->w / 2;
994       /*base.x= 320 + scroll_x;*/
995
996       if (scroll_x > ((current_level.width * 32) - screen->w))
997         scroll_x = ((current_level.width * 32) - screen->w);
998     }
999   else if (base.x> 608 + scroll_x)
1000     {
1001       /* ... unless there's no more to scroll! */
1002
1003       /*base.x= 608 + scroll_x;*/
1004     }
1005
1006   /* Keep in-bounds, vertically: */
1007
1008   if (base.y > screen->h)
1009     {
1010       kill(KILL);
1011     }
1012 }