- removed a few redundant "== true"'s
[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   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::input()
494 {
495   /* Handle key and joystick state: */
496
497   if(duck == false)
498     {
499       if (input_.right == DOWN && input_.left == UP)
500         {
501           handle_horizontal_input(RIGHT);
502         }
503       else if (input_.left == DOWN && input_.right == UP)
504         {
505           handle_horizontal_input(LEFT);
506         }
507       else
508         {
509           if(base.xm > 0)
510             {
511               base.xm = (int)(base.xm - frame_ratio);
512               if(base.xm < 0)
513                 base.xm = 0;
514             }
515           else if(base.xm < 0)
516             {
517               base.xm = (int)(base.xm + frame_ratio);
518               if(base.xm > 0)
519                 base.xm = 0;
520             }
521         }
522     }
523
524   /* Jump/jumping? */
525
526   if ( input_.up == DOWN || (input_.up == UP && jumping))
527     {
528       handle_vertical_input();
529     }
530
531   /* Shoot! */
532
533   if (input_.fire == DOWN && input_.old_fire == UP && got_coffee)
534     {
535       add_bullet(base.x, base.y, base.xm, dir);
536     }
537
538
539   /* Duck! */
540
541   if (input_.down == DOWN)
542     {
543       if (size == BIG && duck != true)
544         {
545           duck = true;
546           base.height = 32;
547           base.y += 32;
548         }
549     }
550   else
551     {
552       if (size == BIG && duck)
553         {
554           /* Make sure we're not standing back up into a solid! */
555           base.height = 64;
556           base.y -= 32;
557
558           if (!collision_object_map(&base) /*issolid(base.x + 16, base.y - 16)*/)
559             {
560               duck = false;
561               base.height = 64;
562               old_base.y -= 32;
563               old_base.height = 64;
564             }
565           else
566             {
567               base.height = 32;
568               base.y += 32;
569             }
570         }
571       else
572         {
573           duck = false;
574         }
575     }
576
577   /* (Tux): */
578
579   if(!timer_check(&frame_timer))
580     {
581       timer_start(&frame_timer,25);
582       if (input_.right == UP && input_.left == UP)
583         {
584           frame_main = 1;
585           frame_ = 1;
586         }
587       else
588         {
589           if ((input_.fire == DOWN && (global_frame_counter % 2) == 0) ||
590               (global_frame_counter % 4) == 0)
591             frame_main = (frame_main + 1) % 4;
592
593           frame_ = frame_main;
594
595           if (frame_ == 3)
596             frame_ = 1;
597         }
598     }
599
600 }
601
602 void
603 Player::grabdistros()
604 {
605   /* Grab distros: */
606   if (!dying)
607     {
608       trygrabdistro(base.x, base.y, NO_BOUNCE);
609       trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
610
611       trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
612       trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
613
614       if(size == BIG)
615         {
616           trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
617           trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
618         }
619
620     }
621
622   /* Enough distros for a One-up? */
623   if (distros >= DISTROS_LIFEUP)
624     {
625       distros = distros - DISTROS_LIFEUP;
626       if(lives < MAX_LIVES)
627         lives++;
628       /*We want to hear the sound even, if MAX_LIVES is reached*/
629       play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
630     }
631 }
632
633 void
634 Player::draw()
635 {
636   if (!timer_started(&safe_timer) || (global_frame_counter % 2) == 0)
637     {
638       if (size == SMALL)
639         {
640           if (timer_started(&invincible_timer))
641             {
642               /* Draw cape: */
643
644               if (dir == RIGHT)
645                 {
646                   texture_draw(&cape_right[global_frame_counter % 2],
647                                base.x- scroll_x, base.y);
648                 }
649               else
650                 {
651                   texture_draw(&cape_left[global_frame_counter % 2],
652                                base.x- scroll_x, base.y);
653                 }
654             }
655
656
657           if (!got_coffee)
658             {
659               if (dir == RIGHT)
660                 {
661                   texture_draw(&tux_right[frame_], base.x- scroll_x, base.y);
662                 }
663               else
664                 {
665                   texture_draw(&tux_left[frame_], base.x- scroll_x, base.y);
666                 }
667             }
668           else
669             {
670               /* Tux got coffee! */
671
672               if (dir == RIGHT)
673                 {
674                   texture_draw(&firetux_right[frame_], base.x- scroll_x, base.y);
675                 }
676               else
677                 {
678                   texture_draw(&firetux_left[frame_], base.x- scroll_x, base.y);
679                 }
680             }
681         }
682       else
683         {
684           if (timer_started(&invincible_timer))
685             {
686               /* Draw cape: */
687               if (dir == RIGHT)
688                 {
689                   texture_draw(&bigcape_right[global_frame_counter % 2],
690                                base.x- scroll_x - 8, base.y);
691                 }
692               else
693                 {
694                   texture_draw(&bigcape_left[global_frame_counter % 2],
695                                base.x-scroll_x - 8, base.y);
696                 }
697             }
698
699           if (!got_coffee)
700             {
701               if (!duck)
702                 {
703                   if (!timer_started(&skidding_timer))
704                     {
705                       if (!jumping || base.ym > 0)
706                         {
707                           if (dir == RIGHT)
708                             {
709                               texture_draw(&bigtux_right[frame_],
710                                            base.x- scroll_x - 8, base.y);
711                             }
712                           else
713                             {
714                               texture_draw(&bigtux_left[frame_],
715                                            base.x- scroll_x - 8, base.y);
716                             }
717                         }
718                       else
719                         {
720                           if (dir == RIGHT)
721                             {
722                               texture_draw(&bigtux_right_jump,
723                                            base.x- scroll_x - 8, base.y);
724                             }
725                           else
726                             {
727                               texture_draw(&bigtux_left_jump,
728                                            base.x- scroll_x - 8, base.y);
729                             }
730                         }
731                     }
732                   else
733                     {
734                       if (dir == RIGHT)
735                         {
736                           texture_draw(&skidtux_right,
737                                        base.x- scroll_x - 8, base.y);
738                         }
739                       else
740                         {
741                           texture_draw(&skidtux_left,
742                                        base.x- scroll_x - 8, base.y);
743                         }
744                     }
745                 }
746               else
747                 {
748                   if (dir == RIGHT)
749                     {
750                       texture_draw(&ducktux_right, base.x- scroll_x - 8, base.y - 16);
751                     }
752                   else
753                     {
754                       texture_draw(&ducktux_left, base.x- scroll_x - 8, base.y - 16);
755                     }
756                 }
757             }
758           else
759             {
760               /* Tux has coffee! */
761
762               if (!duck)
763                 {
764                   if (!timer_started(&skidding_timer))
765                     {
766                       if (!jumping || base.ym > 0)
767                         {
768                           if (dir == RIGHT)
769                             {
770                               texture_draw(&bigfiretux_right[frame_],
771                                            base.x- scroll_x - 8, base.y);
772                             }
773                           else
774                             {
775                               texture_draw(&bigfiretux_left[frame_],
776                                            base.x- scroll_x - 8, base.y);
777                             }
778                         }
779                       else
780                         {
781                           if (dir == RIGHT)
782                             {
783                               texture_draw(&bigfiretux_right_jump,
784                                            base.x- scroll_x - 8, base.y);
785                             }
786                           else
787                             {
788                               texture_draw(&bigfiretux_left_jump,
789                                            base.x- scroll_x - 8, base.y);
790                             }
791                         }
792                     }
793                   else
794                     {
795                       if (dir == RIGHT)
796                         {
797                           texture_draw(&skidfiretux_right,
798                                        base.x- scroll_x - 8, base.y);
799                         }
800                       else
801                         {
802                           texture_draw(&skidfiretux_left,
803                                        base.x- scroll_x - 8, base.y);
804                         }
805                     }
806                 }
807               else
808                 {
809                   if (dir == RIGHT)
810                     {
811                       texture_draw(&duckfiretux_right, base.x- scroll_x - 8, base.y - 16);
812                     }
813                   else
814                     {
815                       texture_draw(&duckfiretux_left, base.x- scroll_x - 8, base.y - 16);
816                     }
817                 }
818             }
819         }
820     }
821 }
822
823 void
824 Player::collision(void* p_c_object, int c_object)
825 {
826   BadGuy* pbad_c = NULL;
827
828   switch (c_object)
829     {
830     case CO_BADGUY:
831       pbad_c = (BadGuy*) p_c_object;
832       /* Hurt the player if he just touched it: */
833
834       if (!pbad_c->dying && !dying &&
835           !timer_started(&safe_timer) &&
836           pbad_c->mode != HELD)
837         {
838           if (pbad_c->mode == FLAT  && input_.fire != DOWN)
839             {
840               /* Kick: */
841
842               pbad_c->mode = KICK;
843               play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
844
845               if (base.x < pbad_c->base.x + (pbad_c->base.width/2))
846                 {
847                   pbad_c->dir = RIGHT;
848                   pbad_c->base.x = pbad_c->base.x + 16;
849                 }
850               else
851                 {
852                   pbad_c->dir = LEFT;
853                   pbad_c->base.x = pbad_c->base.x - 32;
854                 }
855
856               timer_start(&pbad_c->timer,5000);
857             }
858           else if (pbad_c->mode == FLAT && input_.fire == DOWN)
859             {
860               pbad_c->mode = HELD;
861               pbad_c->base.y-=8;
862             }
863           else if (pbad_c->mode == KICK)
864             {
865               if (base.y < pbad_c->base.y - 16 &&
866                   timer_started(&pbad_c->timer))
867                 {
868                   /* Step on (stop being kicked) */
869
870                   pbad_c->mode = FLAT;
871                   play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
872                   timer_start(&pbad_c->timer, 10000);
873                 }
874               else
875                 {
876                   /* Hurt if you get hit by kicked laptop: */
877
878                   if (timer_started(&pbad_c->timer))
879                     {
880                       if (!timer_started(&invincible_timer))
881                         {
882                           kill(SHRINK);
883                         }
884                       else
885                         {
886                           pbad_c->dying = DYING_FALLING;
887                           play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
888                           add_score(pbad_c->base.x - scroll_x,
889                                     pbad_c->base.y,
890                                     25 * score_multiplier);
891                         }
892                     }
893                 }
894             }
895           else
896             {
897               if (!timer_started(&invincible_timer ))
898                 {
899                   kill(SHRINK);
900                 }
901               else
902                 {
903                   pbad_c->dying = DYING_FALLING;
904                   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
905                   add_score(pbad_c->base.x - scroll_x,
906                             pbad_c->base.y,
907                             25 * score_multiplier);
908                 }
909             }
910           score_multiplier++;
911         }
912       break;
913     default:
914       break;
915     }
916
917 }
918
919 /* Kill Player! */
920
921 void
922 Player::kill(int mode)
923 {
924   base.ym = -5;
925
926   play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
927
928   if (dir == RIGHT)
929     base.xm = -8;
930   else if (dir == LEFT)
931     base.xm = 8;
932
933   if (mode == SHRINK && size == BIG)
934     {
935       if (got_coffee)
936         got_coffee = false;
937
938       size = SMALL;
939       base.height = 32;
940
941       timer_start(&safe_timer,TUX_SAFE_TIME);
942     }
943   else
944     {
945       dying = DYING_SQUISHED;
946     }
947 }
948
949 void
950 Player::is_dying()
951 {
952   base.ym = base.ym + gravity;
953
954   /* He died :^( */
955
956   --lives;
957   remove_powerups();
958   dying = DYING_NOT;
959   
960   level_begin();
961
962 }
963
964 /* Remove Tux's power ups */
965 void
966 Player::remove_powerups()
967 {
968   got_coffee = false;
969   size = SMALL;
970   base.height = 32;
971 }
972
973 void
974 Player::keep_in_bounds()
975 {
976   /* Keep tux in bounds: */
977   if (base.x< 0)
978     base.x= 0;
979   else if(base.x< scroll_x)
980     base.x= scroll_x;
981   else if (base.x< 160 + scroll_x && scroll_x > 0 && debug_mode)
982     {
983       scroll_x = base.x- 160;
984       /*base.x+= 160;*/
985
986       if(scroll_x < 0)
987         scroll_x = 0;
988
989     }
990   else if (base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
991     {
992       /* Scroll the screen in past center: */
993
994       scroll_x = base.x- screen->w / 2;
995       /*base.x= 320 + scroll_x;*/
996
997       if (scroll_x > ((current_level.width * 32) - screen->w))
998         scroll_x = ((current_level.width * 32) - screen->w);
999     }
1000   else if (base.x> 608 + scroll_x)
1001     {
1002       /* ... unless there's no more to scroll! */
1003
1004       /*base.x= 608 + scroll_x;*/
1005     }
1006
1007   /* Keep in-bounds, vertically: */
1008
1009   if (base.y > screen->h)
1010     {
1011       kill(KILL);
1012     }
1013 }