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