check that place is free before releasing a grabbed object
[supertux.git] / src / object / player.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #include <config.h>
20
21 #include <typeinfo>
22 #include <cmath>
23 #include <iostream>
24 #include <cassert>
25
26 #include "gettext.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "audio/sound_manager.hpp"
29 #include "player.hpp"
30 #include "tile.hpp"
31 #include "sprite/sprite.hpp"
32 #include "sector.hpp"
33 #include "resources.hpp"
34 #include "video/screen.hpp"
35 #include "statistics.hpp"
36 #include "game_session.hpp"
37 #include "object/tilemap.hpp"
38 #include "object/camera.hpp"
39 #include "object/gameobjs.hpp"
40 #include "object/portable.hpp"
41 #include "trigger/trigger_base.hpp"
42 #include "control/joystickkeyboardcontroller.hpp"
43 #include "main.hpp"
44 #include "player_status.hpp"
45
46 static const int TILES_FOR_BUTTJUMP = 3;
47 static const float SHOOTING_TIME = .150;
48 /// time before idle animation starts
49 static const float IDLE_TIME = 2.5;
50
51 static const float WALK_ACCELERATION_X = 300;
52 static const float RUN_ACCELERATION_X = 400;
53 static const float SKID_XM = 200;
54 static const float SKID_TIME = .3;
55 static const float MAX_WALK_XM = 230;
56 static const float MAX_RUN_XM = 320;
57 static const float WALK_SPEED = 100;
58
59 // growing animation
60 Surface* growingtux_left[GROWING_FRAMES];
61 Surface* growingtux_right[GROWING_FRAMES];
62
63 Surface* tux_life = 0;
64
65 TuxBodyParts* small_tux = 0;
66 TuxBodyParts* big_tux = 0;
67 TuxBodyParts* fire_tux = 0;
68 TuxBodyParts* ice_tux = 0;
69
70 void
71 TuxBodyParts::set_action(std::string action, int loops)
72 {
73   if(head != NULL)
74     head->set_action(action, loops);
75   if(body != NULL)
76     body->set_action(action, loops);
77   if(arms != NULL)
78     arms->set_action(action, loops);
79   if(feet != NULL)
80     feet->set_action(action, loops);
81 }
82
83 void
84 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
85 {
86   if(head != NULL)
87     head->draw(context, pos, layer-1);
88   if(body != NULL)
89     body->draw(context, pos, layer-3);
90   if(arms != NULL)
91     arms->draw(context, pos, layer);
92   if(feet != NULL)
93     feet->draw(context, pos, layer-2);
94 }
95
96 Player::Player(PlayerStatus* _player_status)
97   : player_status(_player_status), grabbed_object(0)
98 {
99   controller = main_controller;
100   smalltux_gameover = sprite_manager->create("smalltux-gameover");
101   smalltux_star = sprite_manager->create("smalltux-star");
102   bigtux_star = sprite_manager->create("bigtux-star");
103   init();
104 }
105
106 Player::~Player()
107 {
108   delete smalltux_gameover;
109   delete smalltux_star;
110   delete bigtux_star;
111 }
112
113 void
114 Player::init()
115 {
116   if(is_big())
117     bbox.set_size(31.8, 63.8);
118   else
119     bbox.set_size(31.8, 31.8);
120
121   dir = RIGHT;
122   old_dir = dir;
123   duck = false;
124   dead = false;
125
126   dying = false;
127   last_ground_y = 0;
128   fall_mode = ON_GROUND;
129   jumping = false;
130   can_jump = true;
131   butt_jump = false;
132   deactivated = false;
133   backflipping = false;
134   backflip_direction = 0;
135   
136   on_ground_flag = false;
137   grabbed_object = 0;
138
139   physic.reset();
140 }
141
142 void
143 Player::set_controller(Controller* controller)
144 {
145   this->controller = controller;
146 }
147
148 void
149 Player::update(float elapsed_time)
150 {
151   if(dying && dying_timer.check()) {
152     dead = true;
153     return;
154   }
155
156   if(!controller->hold(Controller::ACTION) && grabbed_object) {
157     // move the grabbed object a bit away from tux
158     Vector pos = get_pos() + 
159         Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
160                 bbox.get_height()*0.66666 - 32);
161     Rect dest(pos, pos + Vector(32, 32));
162     if(Sector::current()->is_free_space(dest)) {
163       MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
164       if(moving_object) {
165         moving_object->set_pos(pos);
166       } else {
167 #ifdef DEBUG
168         std::cout << "Non MovingObjetc grabbed?!?\n";
169 #endif
170       }
171       grabbed_object = 0;
172     }
173   }
174
175   if(!dying && !deactivated)
176     handle_input();
177
178   movement = physic.get_movement(elapsed_time);
179   on_ground_flag = false;
180
181 #if 0
182   // special exception for cases where we're stuck under tiles after
183   // being ducked. In this case we drift out
184   if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
185      && collision_object_map(base)) {
186     base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1);
187     previous_base = old_base = base;
188   }
189 #endif
190
191   if(grabbed_object != 0) {
192     Vector pos = get_pos() + 
193       Vector(dir == LEFT ? -16 : 16,
194              bbox.get_height()*0.66666 - 32);
195     grabbed_object->grab(*this, pos);
196   }
197 }
198
199 bool
200 Player::on_ground()
201 {
202   return on_ground_flag;
203 }
204
205 bool
206 Player::is_big()
207 {
208   if(player_status->bonus == NO_BONUS)
209     return false;
210
211   return true;
212 }
213
214 void
215 Player::handle_horizontal_input()
216 {
217   float vx = physic.get_velocity_x();
218   float vy = physic.get_velocity_y();
219   float ax = physic.get_acceleration_x();
220   float ay = physic.get_acceleration_y();
221
222   float dirsign = 0;
223   if(!duck || physic.get_velocity_y() != 0) {
224     if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
225       old_dir = dir;
226       dir = LEFT;
227       dirsign = -1;
228     } else if(!controller->hold(Controller::LEFT)
229               && controller->hold(Controller::RIGHT)) {
230       old_dir = dir;
231       dir = RIGHT;
232       dirsign = 1;
233     }
234   }
235
236   if (!controller->hold(Controller::ACTION)) {
237     ax = dirsign * WALK_ACCELERATION_X;
238     // limit speed
239     if(vx >= MAX_WALK_XM && dirsign > 0) {
240       vx = MAX_WALK_XM;
241       ax = 0;
242     } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
243       vx = -MAX_WALK_XM;
244       ax = 0;
245     }
246   } else {
247     ax = dirsign * RUN_ACCELERATION_X;
248     // limit speed
249     if(vx >= MAX_RUN_XM && dirsign > 0) {
250       vx = MAX_RUN_XM;
251       ax = 0;
252     } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
253       vx = -MAX_RUN_XM;
254       ax = 0;
255     }
256   }
257
258   // we can reach WALK_SPEED without any acceleration
259   if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
260     vx = dirsign * WALK_SPEED;
261   }
262
263   // changing directions?
264   if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
265     // let's skid!
266     if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
267       skidding_timer.start(SKID_TIME);
268       sound_manager->play("sounds/skid.wav");
269       // dust some particles
270       Sector::current()->add_object(
271         new Particles(
272           Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0),
273                  bbox.p2.y),
274           dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
275           Vector(280,-260), Vector(0,0.030), 3, Color(100,100,100), 3, .8,
276           LAYER_OBJECTS+1));
277       
278       ax *= 2.5;
279     } else {
280       ax *= 2;
281     }
282   }
283
284   // we get slower when not pressing any keys
285   if(dirsign == 0) {
286     if(fabs(vx) < WALK_SPEED) {
287       vx = 0;
288       ax = 0;
289     } else if(vx < 0) {
290       ax = WALK_ACCELERATION_X * 1.5;
291     } else {
292       ax = WALK_ACCELERATION_X * -1.5;
293     }
294   }
295
296 #if 0
297   // if we're on ice slow down acceleration or deceleration
298   if (isice(base.x, base.y + base.height))
299   {
300     /* the acceleration/deceleration rate on ice is inversely proportional to
301      * the current velocity.
302      */
303
304     // increasing 1 will increase acceleration/deceleration rate
305     // decreasing 1 will decrease acceleration/deceleration rate
306     //  must stay above zero, though
307     if (ax != 0) ax *= 1 / fabs(vx);
308   }
309 #endif
310
311   // extend/shrink tux collision rectangle so that we fall through/walk over 1
312   // tile holes
313   if(fabsf(vx) > MAX_WALK_XM) {
314     bbox.set_width(33);
315   } else {
316     bbox.set_width(31.8);
317   }
318
319   physic.set_velocity(vx, vy);
320   physic.set_acceleration(ax, ay);
321 }
322
323 void
324 Player::handle_vertical_input()
325 {
326   // set fall mode...
327   if(on_ground()) {
328     fall_mode = ON_GROUND;
329     last_ground_y = get_pos().y;
330   } else {
331     if(get_pos().y > last_ground_y)
332       fall_mode = FALLING;
333     else if(fall_mode == ON_GROUND)
334       fall_mode = JUMPING;
335   }
336
337   if(on_ground()) { /* Make sure jumping is off. */
338     jumping = false;
339     if (backflipping) {
340       backflipping = false;
341       backflip_direction = 0;
342     }
343   }
344
345   // Press jump key
346   if(controller->pressed(Controller::JUMP) && can_jump && on_ground()) {
347     if (duck) { 
348       if (physic.get_velocity_x() != 0) // only jump a little bit when running ducked
349         physic.set_velocity_y(300);
350       else { //do a backflip
351         backflipping = true;
352         physic.set_velocity_y(580);
353         backflip_timer.start(0.15);
354       }
355     }
356     else if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) // jump higher if we are running
357       physic.set_velocity_y(580);
358     else
359       physic.set_velocity_y(520);
360     
361     //bbox.move(Vector(0, -1));
362     jumping = true;
363     can_jump = false;
364     if (is_big())
365       sound_manager->play("sounds/bigjump.wav");
366     else
367       sound_manager->play("sounds/jump.wav");
368   } else if(!controller->hold(Controller::JUMP)) { // Let go of jump key
369     if (!backflipping && jumping && physic.get_velocity_y() > 0) {
370       jumping = false;
371       physic.set_velocity_y(0);
372     }
373   }
374
375   /* In case the player has pressed Down while in a certain range of air,
376      enable butt jump action */
377   if (controller->hold(Controller::DOWN) && !butt_jump && !duck)
378     //if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
379     butt_jump = true;
380   
381   /* When Down is not held anymore, disable butt jump */
382   if(butt_jump && !controller->hold(Controller::DOWN))
383     butt_jump = false;
384   
385 #if 0
386   // Do butt jump
387   if (butt_jump && on_ground() && is_big()) {
388     // Add a smoke cloud
389     if (duck) 
390       Sector::current()->add_smoke_cloud(Vector(get_pos().x - 32, get_pos().y));
391     else 
392       Sector::current()->add_smoke_cloud(
393         Vector(get_pos().x - 32, get_pos().y + 32));
394     
395     butt_jump = false;
396     
397     // Break bricks beneath Tux
398     if(Sector::current()->trybreakbrick(
399          Vector(base.x + 1, base.y + base.height), false)
400        || Sector::current()->trybreakbrick(
401          Vector(base.x + base.width - 1, base.y + base.height), false)) {
402       physic.set_velocity_y(2);
403       butt_jump = true;
404     }
405     
406     // Kill nearby badguys
407     std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
408     for (std::vector<GameObject*>::iterator i = gameobjects.begin();
409          i != gameobjects.end();
410          i++) {
411       BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
412       if(badguy) {
413         // don't kill when badguys are already dying or in a certain mode
414         if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
415            badguy->mode != BadGuy::BOMB_EXPLODE) {
416           if (fabsf(base.x - badguy->base.x) < 96 &&
417               fabsf(base.y - badguy->base.y) < 64)
418             badguy->kill_me(25);
419         }
420       }
421     }
422   }
423 #endif
424
425   /** jumping is only allowed if we're about to touch ground soon and if the
426    * button has been up in between the last jump
427    */
428   // FIXME
429 #if 0
430   if ( (issolid(get_pos().x + bbox.get_width() / 2,
431           get_pos().y + bbox.get_height() + 64) ||
432         issolid(get_pos().x + 1, get_pos().y + bbox.get_height() + 64) ||
433         issolid(get_pos().x + bbox.get_width() - 1,
434           get_pos().y + bbox.get_height() + 64))
435        && jumping  == false
436        && can_jump == false
437        && input.jump && !input.old_jump)
438     {
439       can_jump = true;
440     }
441 #endif
442 }
443
444 void
445 Player::handle_input()
446 {
447   /* Handle horizontal movement: */
448   if (!backflipping) handle_horizontal_input();
449   else {
450     if (backflip_direction == 0) {
451       dir == LEFT ? backflip_direction = 1 : backflip_direction = -1;
452     }
453     else backflip_direction == 1 ? dir = LEFT : dir = RIGHT; //prevent player from changing direction when backflipping 
454     if (backflip_timer.check()) physic.set_velocity_x(100 * backflip_direction);
455   }
456
457
458   /* Jump/jumping? */
459   if (on_ground() && !controller->hold(Controller::JUMP))
460     can_jump = true;
461   handle_vertical_input();
462
463   /* Shoot! */
464   if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
465     if(Sector::current()->add_bullet(
466          get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) 
467                       : Vector(32, bbox.get_height()/2)),
468          physic.get_velocity_x(), dir))
469       shooting_timer.start(SHOOTING_TIME);
470   }
471   
472   /* Duck! */
473   if (controller->hold(Controller::DOWN) && is_big() && !duck 
474       && physic.get_velocity_y() == 0 && on_ground()) {
475     duck = true;
476     bbox.move(Vector(0, 32));
477     bbox.set_height(31.8);
478   } else if(!controller->hold(Controller::DOWN) && is_big() && duck) {
479     // try if we can really unduck
480     bbox.move(Vector(0, -32));
481     bbox.set_height(63.8);
482     duck = false;
483     // FIXME
484 #if 0
485     // when unducking in air we need some space to do so
486     if(on_ground() || !collision_object_map(bbox)) {
487       duck = false;
488     } else {
489       // undo the ducking changes
490       bbox.move(Vector(0, 32));
491       bbox.set_height(31.8);
492     }
493 #endif
494   }
495 }
496
497 void
498 Player::set_bonus(BonusType type, bool animate)
499 {
500   if(player_status->bonus >= type)
501     return;
502   
503   if(player_status->bonus == NO_BONUS) {
504     bbox.set_height(63.8);
505     bbox.move(Vector(0, -32));
506     if(animate)
507       growing_timer.start(GROWING_TIME);
508   }
509   
510   player_status->bonus = type;
511 }
512
513 void
514 Player::draw(DrawingContext& context)
515 {
516   TuxBodyParts* tux_body;
517           
518   if (player_status->bonus == GROWUP_BONUS)
519     tux_body = big_tux;
520   else if (player_status->bonus == FIRE_BONUS)
521     tux_body = fire_tux;
522   else if (player_status->bonus == ICE_BONUS)
523     tux_body = ice_tux;
524   else
525     tux_body = small_tux;
526
527   int layer = LAYER_OBJECTS + 10;
528
529   /* Set Tux sprite action */
530   if (duck && is_big())
531     {
532     if(dir == LEFT)
533       tux_body->set_action("duck-left");
534     else // dir == RIGHT
535       tux_body->set_action("duck-right");
536     }
537   else if (skidding_timer.started() && !skidding_timer.check())
538     {
539     if(dir == LEFT)
540       tux_body->set_action("skid-left");
541     else // dir == RIGHT
542       tux_body->set_action("skid-right");
543     }
544   else if (kick_timer.started() && !kick_timer.check())
545     {
546     if(dir == LEFT)
547       tux_body->set_action("kick-left");
548     else // dir == RIGHT
549       tux_body->set_action("kick-right");
550     }
551   else if (butt_jump && is_big())
552     {
553     if(dir == LEFT)
554       tux_body->set_action("buttjump-left");
555     else // dir == RIGHT
556       tux_body->set_action("buttjump-right");
557     }
558   else if (physic.get_velocity_y() != 0)
559     {
560     if(dir == LEFT)
561       tux_body->set_action("jump-left");
562     else // dir == RIGHT
563       tux_body->set_action("jump-right");
564     }
565   else
566     {
567     if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
568       {
569       if(dir == LEFT)
570         tux_body->set_action("stand-left");
571       else // dir == RIGHT
572         tux_body->set_action("stand-right");
573       }
574     else // moving
575       {
576       if(dir == LEFT)
577         tux_body->set_action("walk-left");
578       else // dir == RIGHT
579         tux_body->set_action("walk-right");
580       }
581     }
582
583   if(idle_timer.check())
584     {
585     if(is_big())
586       {
587       if(dir == LEFT)
588         tux_body->head->set_action("idle-left", 1);
589       else // dir == RIGHT
590         tux_body->head->set_action("idle-right", 1);
591       }
592
593     }
594
595   // Tux is holding something
596   if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
597       (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
598     {
599     if (duck)
600       {
601       if(dir == LEFT)
602         tux_body->arms->set_action("duck+grab-left");
603       else // dir == RIGHT
604         tux_body->arms->set_action("duck+grab-right");
605       }
606     else
607       {
608       if(dir == LEFT)
609         tux_body->arms->set_action("grab-left");
610       else // dir == RIGHT
611         tux_body->arms->set_action("grab-right");
612       }
613     }
614
615   /* Draw Tux */
616   if(dying) {
617     smalltux_gameover->draw(context, get_pos(), layer);
618   } else if(growing_timer.get_timeleft() > 0) {
619     if(!is_big())
620       {
621       if (dir == RIGHT)
622         context.draw_surface(growingtux_right[GROWING_FRAMES-1 - 
623                  int((growing_timer.get_timegone() *
624                  GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
625       else
626         context.draw_surface(growingtux_left[GROWING_FRAMES-1 - 
627                 int((growing_timer.get_timegone() *
628                 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
629       }
630     else
631       {
632       if (dir == RIGHT)
633         context.draw_surface(growingtux_right[
634             int((growing_timer.get_timegone() *
635                 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
636       else
637         context.draw_surface(growingtux_left[
638             int((growing_timer.get_timegone() *
639                              GROWING_FRAMES) / GROWING_TIME)],
640             get_pos(), layer);
641       }
642     }
643   else if (safe_timer.started() && size_t(game_time*40)%2)
644     ;  // don't draw Tux
645   else
646     tux_body->draw(context, get_pos(), layer);
647
648   // Draw blinking star overlay
649   if (invincible_timer.started() &&
650      (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
651       || size_t(game_time*20)%2)
652      && !dying)
653   {
654     if (!is_big() || duck)
655       smalltux_star->draw(context, get_pos(), layer + 5);
656     else
657       bigtux_star->draw(context, get_pos(), layer + 5);
658   } 
659 }
660
661 void
662 Player::collision_tile(uint32_t tile_attributes)
663 {
664   if(tile_attributes & Tile::HURTS)
665     kill(SHRINK);
666 }
667
668 HitResponse
669 Player::collision(GameObject& other, const CollisionHit& hit)
670 {
671   Portable* portable = dynamic_cast<Portable*> (&other);
672   if(portable && grabbed_object == 0 && controller->hold(Controller::ACTION)
673      && fabsf(hit.normal.x) > .9) {
674     grabbed_object = portable;
675     return CONTINUE;
676   }
677  
678   if(other.get_flags() & FLAG_SOLID) {
679     if(hit.normal.y < 0) { // landed on floor?
680       if(physic.get_velocity_y() < 0)
681         physic.set_velocity_y(0);
682       on_ground_flag = true;
683     } else if(hit.normal.y > 0) { // bumped against the roof
684       physic.set_velocity_y(.1);
685     }
686     
687     if(fabsf(hit.normal.x) > .9) { // hit on the side?
688       physic.set_velocity_x(0);
689     }
690
691     return CONTINUE;
692   }
693
694   TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
695   if(trigger) {
696     if(controller->pressed(Controller::UP))
697       trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
698
699     return FORCE_MOVE;
700   }
701
702   MovingObject* moving_object = static_cast<MovingObject*> (&other);
703   if(moving_object->get_group() == COLGROUP_TOUCHABLE)
704     return FORCE_MOVE;
705
706   if(is_invincible())
707     return FORCE_MOVE;
708
709   return CONTINUE;
710 }
711
712 void
713 Player::make_invincible()
714 {
715   sound_manager->play("sounds/invincible.wav");
716   invincible_timer.start(TUX_INVINCIBLE_TIME);
717   Sector::current()->play_music(HERRING_MUSIC);               
718 }
719
720 /* Kill Player! */
721 void
722 Player::kill(HurtMode mode)
723 {
724   if(dying || deactivated)
725     return;
726
727   if(mode != KILL && 
728           safe_timer.get_timeleft() > 0 || invincible_timer.get_timeleft() > 0)
729     return;                          
730   
731   sound_manager->play("sounds/hurt.wav");
732
733   physic.set_velocity_x(0);
734
735   if (mode == SHRINK && is_big())
736     {
737       if (player_status->bonus == FIRE_BONUS
738           || player_status->bonus == ICE_BONUS)
739         {
740           safe_timer.start(TUX_SAFE_TIME);
741           player_status->bonus = GROWUP_BONUS;
742         }
743       else 
744         {
745           growing_timer.start(GROWING_TIME);
746           safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
747           bbox.set_height(31.8);
748           duck = false;
749           player_status->bonus = NO_BONUS;
750         }
751     }
752   else
753     {
754       physic.enable_gravity(true);
755       physic.set_acceleration(0, 0);
756       physic.set_velocity(0, 700);
757       player_status->lives -= 1;
758       player_status->bonus = NO_BONUS;
759       dying = true;
760       dying_timer.start(3.0);
761       set_group(COLGROUP_DISABLED);
762     }
763 }
764
765 void
766 Player::move(const Vector& vector)
767 {
768   bbox.set_pos(vector);
769   if(is_big())
770     bbox.set_size(31.8, 63.8);
771   else
772     bbox.set_size(31.8, 31.8);
773   on_ground_flag = false;
774   duck = false;
775   last_ground_y = vector.y;
776
777   physic.reset();
778 }
779
780 void
781 Player::check_bounds(Camera* camera)
782 {
783   /* Keep tux in bounds: */
784   if (get_pos().x < 0)
785     { // Lock Tux to the size of the level, so that he doesn't fall of
786       // on the left side
787       bbox.set_pos(Vector(0, get_pos().y));
788     }
789
790   /* Keep in-bounds, vertically: */
791   if (get_pos().y > Sector::current()->solids->get_height() * 32)
792     {
793       kill(KILL);
794       return;
795     }
796
797   bool adjust = false;
798   // can happen if back scrolling is disabled
799   if(get_pos().x < camera->get_translation().x) {
800     bbox.set_pos(Vector(camera->get_translation().x, get_pos().y));
801     adjust = true;
802   }
803   if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
804   {
805     bbox.set_pos(Vector(
806           camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
807           get_pos().y));
808     adjust = true;
809   }
810
811   if(adjust) {
812     // FIXME
813 #if 0
814     // squished now?
815     if(collision_object_map(bbox)) {
816       kill(KILL);
817       return;
818     }
819 #endif
820   }
821 }
822
823 void
824 Player::bounce(BadGuy& )
825 {
826   if(controller->hold(Controller::JUMP))
827     physic.set_velocity_y(520);
828   else
829     physic.set_velocity_y(300);
830 }
831
832 //Scripting Functions Below
833
834 void
835 Player::deactivate()
836 {
837   deactivated = true;
838   physic.set_velocity_x(0);
839   physic.set_velocity_y(0);
840 }
841
842 void
843 Player::activate()
844 {
845   deactivated = false;
846 }
847
848 void Player::walk(float speed)
849 {
850   physic.set_velocity_x(speed);
851 }