* Split systemRandom into graphicsRandom (particles, eye candy, etc.) and gameRandom...
[supertux.git] / src / object / player.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 2
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 #include "object/player.hpp"
19
20 #include "audio/sound_manager.hpp"
21 #include "badguy/badguy.hpp"
22 #include "control/joystickkeyboardcontroller.hpp"
23 #include "math/random_generator.hpp"
24 #include "object/bullet.hpp"
25 #include "object/camera.hpp"
26 #include "object/display_effect.hpp"
27 #include "object/falling_coin.hpp"
28 #include "object/particles.hpp"
29 #include "object/portable.hpp"
30 #include "object/sprite_particle.hpp"
31 #include "scripting/squirrel_util.hpp"
32 #include "supertux/game_session.hpp"
33 #include "supertux/globals.hpp"
34 #include "supertux/sector.hpp"
35 #include "supertux/tile.hpp"
36 #include "trigger/climbable.hpp"
37
38 #include <math.h>
39
40 //#define SWIMMING
41
42 namespace {
43 static const int TILES_FOR_BUTTJUMP = 3;
44 static const float BUTTJUMP_MIN_VELOCITY_Y = 400.0f;
45 static const float SHOOTING_TIME = .150f;
46
47 /** number of idle stages, including standing */
48 static const unsigned int IDLE_STAGE_COUNT = 5;
49 /**
50  * how long to play each idle animation in milliseconds
51  * '0' means the sprite action is played once before moving onto the next
52  * animation
53  */
54 static const int IDLE_TIME[] = { 5000, 0, 2500, 0, 2500 };
55 /** idle stages */
56 static const std::string IDLE_STAGES[] =
57 { "stand",
58   "idle",
59   "stand",
60   "idle",
61   "stand" };
62
63 /** acceleration in horizontal direction when walking
64  * (all accelerations are in  pixel/s^2) */
65 static const float WALK_ACCELERATION_X = 300;
66 /** acceleration in horizontal direction when running */ 
67 static const float RUN_ACCELERATION_X = 400;
68 /** acceleration when skidding */
69 static const float SKID_XM = 200;
70 /** time of skidding in seconds */
71 static const float SKID_TIME = .3f;
72 /** maximum walk velocity (pixel/s) */
73 static const float MAX_WALK_XM = 230;
74 /** maximum run velocity (pixel/s) */
75 static const float MAX_RUN_XM = 320;
76 /** maximum horizontal climb velocity */
77 static const float MAX_CLIMB_XM = 48;
78 /** maximum vertical climb velocity */
79 static const float MAX_CLIMB_YM = 128;
80 /** instant velocity when tux starts to walk */
81 static const float WALK_SPEED = 100;
82
83 /** multiplied by WALK_ACCELERATION to give friction */
84 static const float NORMAL_FRICTION_MULTIPLIER = 1.5f;
85 /** multiplied by WALK_ACCELERATION to give friction */
86 static const float ICE_FRICTION_MULTIPLIER = 0.1f;
87 static const float ICE_ACCELERATION_MULTIPLIER = 0.25f;
88
89 /** time of the kick (kicking mriceblock) animation */
90 static const float KICK_TIME = .3f;
91 /** time of tux cheering (currently unused) */
92 static const float CHEER_TIME = 1.0f;
93
94 /** if Tux cannot unduck for this long, he will get hurt */
95 static const float UNDUCK_HURT_TIME = 0.25f;
96 /** gravity is higher after the jump key is released before
97     the apex of the jump is reached */
98 static const float JUMP_EARLY_APEX_FACTOR = 3.0;
99
100 static const float JUMP_GRACE_TIME = 0.25f; /**< time before hitting the ground that the jump button may be pressed (and still trigger a jump) */
101
102 bool no_water = true;
103 }
104
105 Player::Player(PlayerStatus* _player_status, const std::string& name) :
106   deactivated(),
107   controller(),
108   scripting_controller(0), 
109   player_status(_player_status), 
110   duck(),
111   dead(),
112   dying(),
113   backflipping(),
114   backflip_direction(),
115   peekingX(),
116   peekingY(),
117   swimming(),
118   speedlimit(),
119   scripting_controller_old(0),
120   jump_early_apex(),
121   on_ice(),
122   ice_this_frame(),
123   dir(),
124   old_dir(),
125   last_ground_y(),
126   fall_mode(),
127   on_ground_flag(),
128   jumping(),
129   can_jump(),
130   jump_button_timer(), 
131   wants_buttjump(),
132   does_buttjump(),
133   invincible_timer(),
134   skidding_timer(),
135   safe_timer(),
136   kick_timer(),
137   shooting_timer(),
138   dying_timer(),
139   growing(),
140   backflip_timer(),
141   physic(),
142   visible(),
143   grabbed_object(NULL), 
144   sprite(),
145   airarrow(),
146   floor_normal(),
147   ghost_mode(false), 
148   edit_mode(false), 
149   unduck_hurt_timer(),
150   idle_timer(),
151   idle_stage(0),
152   climbing(0)
153 {
154   this->name = name;
155   controller = g_main_controller;
156   scripting_controller.reset(new CodeController());
157   sprite = sprite_manager->create("images/creatures/tux/tux.sprite");
158   airarrow = Surface::create("images/engine/hud/airarrow.png");
159   idle_timer.start(IDLE_TIME[0]/1000.0f);
160
161   sound_manager->preload("sounds/bigjump.wav");
162   sound_manager->preload("sounds/jump.wav");
163   sound_manager->preload("sounds/hurt.wav");
164   sound_manager->preload("sounds/kill.wav");
165   sound_manager->preload("sounds/skid.wav");
166   sound_manager->preload("sounds/flip.wav");
167   sound_manager->preload("sounds/invincible_start.ogg");
168   sound_manager->preload("sounds/splash.ogg");
169
170   init();
171 }
172
173 Player::~Player()
174 {
175   if (climbing) stop_climbing(*climbing);
176 }
177
178 void
179 Player::init()
180 {
181   if(is_big())
182     set_size(31.8f, 62.8f);
183   else
184     set_size(31.8f, 30.8f);
185
186   dir = RIGHT;
187   old_dir = dir;
188   duck = false;
189   dead = false;
190
191   dying = false;
192   peekingX = AUTO;
193   peekingY = AUTO;
194   last_ground_y = 0;
195   fall_mode = ON_GROUND;
196   jumping = false;
197   jump_early_apex = false;
198   can_jump = true;
199   wants_buttjump = false;
200   does_buttjump = false;
201   growing = false;
202   deactivated = false;
203   backflipping = false;
204   backflip_direction = 0;
205   visible = true;
206   swimming = false;
207   on_ice = false;
208   ice_this_frame = false;
209   speedlimit = 0; //no special limit
210
211   on_ground_flag = false;
212   grabbed_object = NULL;
213
214   climbing = 0;
215
216   physic.reset();
217 }
218
219 void
220 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
221 {
222   if (name.empty())
223     return;
224
225   scripting::expose_object(vm, table_idx, dynamic_cast<scripting::Player *>(this), name, false);
226 }
227
228 void
229 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
230 {
231   if (name.empty())
232     return;
233
234   scripting::unexpose_object(vm, table_idx, name);
235 }
236
237 float
238 Player::get_speedlimit()
239 {
240   return speedlimit;
241 }
242
243 void
244 Player::set_speedlimit(float newlimit)
245 {
246   speedlimit=newlimit;
247 }
248
249 void
250 Player::set_controller(Controller* controller)
251 {
252   this->controller = controller;
253 }
254
255 void 
256 Player::use_scripting_controller(bool use_or_release)
257 {
258   if ((use_or_release == true) && (controller != scripting_controller.get())) {
259     scripting_controller_old = get_controller();
260     set_controller(scripting_controller.get());
261   }
262   if ((use_or_release == false) && (controller == scripting_controller.get())) {
263     set_controller(scripting_controller_old);
264     scripting_controller_old = 0;
265   }
266 }
267
268 void 
269 Player::do_scripting_controller(std::string control, bool pressed)
270 {
271   for(int i = 0; Controller::controlNames[i] != 0; ++i) {
272     if(control == std::string(Controller::controlNames[i])) {
273       scripting_controller->press(Controller::Control(i), pressed);
274     }
275   }
276 }
277
278 bool
279 Player::adjust_height(float new_height)
280 {
281   Rectf bbox2 = bbox;
282   bbox2.move(Vector(0, bbox.get_height() - new_height));
283   bbox2.set_height(new_height);
284
285   if(new_height > bbox.get_height()) {
286     Rectf additional_space = bbox2;
287     additional_space.set_height(new_height - bbox.get_height());
288     if(!Sector::current()->is_free_of_statics(additional_space, this, true))
289       return false;
290   }
291
292   // adjust bbox accordingly
293   // note that we use members of moving_object for this, so we can run this during CD, too
294   set_pos(bbox2.p1);
295   set_size(bbox2.get_width(), bbox2.get_height());
296   return true;
297 }
298
299 void
300 Player::trigger_sequence(std::string sequence_name)
301 {
302   if (climbing) stop_climbing(*climbing);
303   GameSession::current()->start_sequence(sequence_name);
304 }
305
306 void
307 Player::update(float elapsed_time)
308 {
309   if( no_water ){
310     swimming = false;
311   }
312   no_water = true;
313
314   if(dying && dying_timer.check()) {
315     dead = true;
316     return;
317   }
318
319   if(!dying && !deactivated)
320     handle_input();
321
322   // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
323   if (deactivated)
324     apply_friction();
325
326   // extend/shrink tux collision rectangle so that we fall through/walk over 1
327   // tile holes
328   if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
329     set_width(34);
330   } else {
331     set_width(31.8f);
332   }
333
334   // on downward slopes, adjust vertical velocity so tux walks smoothly down
335   if (on_ground()) {
336     if(floor_normal.y != 0) {
337       if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
338         physic.set_velocity_y(250);
339       }
340     }
341   }
342
343   // handle backflipping
344   if (backflipping) {
345     //prevent player from changing direction when backflipping
346     dir = (backflip_direction == 1) ? LEFT : RIGHT;
347     if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
348   }
349
350   // set fall mode...
351   if(on_ground()) {
352     fall_mode = ON_GROUND;
353     last_ground_y = get_pos().y;
354   } else {
355     if(get_pos().y > last_ground_y)
356       fall_mode = FALLING;
357     else if(fall_mode == ON_GROUND)
358       fall_mode = JUMPING;
359   }
360
361   // check if we landed
362   if(on_ground()) {
363     jumping = false;
364     if (backflipping && (!backflip_timer.started())) {
365       backflipping = false;
366       backflip_direction = 0;
367
368       // if controls are currently deactivated, we take care of standing up ourselves
369       if (deactivated)
370         do_standup();
371     }
372   }
373
374   // calculate movement for this frame
375   movement = physic.get_movement(elapsed_time);
376
377   if(grabbed_object != NULL && !dying) {
378     position_grabbed_object();
379   }
380
381   if(grabbed_object != NULL && dying){
382     grabbed_object->ungrab(*this, dir);
383     grabbed_object = NULL;
384   }
385
386   if(!ice_this_frame && on_ground())
387     on_ice = false;
388
389   on_ground_flag = false;
390   ice_this_frame = false;
391
392   // when invincible, spawn particles
393   if (invincible_timer.started())
394   {
395     if (graphicsRandom.rand(0, 2) == 0) {
396       float px = graphicsRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
397       float py = graphicsRandom.randf(bbox.p1.y+0, bbox.p2.y-0);
398       Vector ppos = Vector(px, py);
399       Vector pspeed = Vector(0, 0);
400       Vector paccel = Vector(0, 0);
401       Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", 
402                                                        // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
403                                                        (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) ?
404                                                        // make every other a longer sparkle to make trail a bit fuzzy
405                                                        (size_t(game_time*20)%2) ? "small" : "medium"
406                                                        :
407                                                        "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
408     }
409   }
410
411   if (growing) {
412     if (sprite->animation_done()) growing = false;
413   }
414
415 }
416
417 bool
418 Player::on_ground()
419 {
420   return on_ground_flag;
421 }
422
423 bool
424 Player::is_big()
425 {
426   if(player_status->bonus == NO_BONUS)
427     return false;
428
429   return true;
430 }
431
432 void
433 Player::apply_friction()
434 {
435   if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
436     physic.set_velocity_x(0);
437     physic.set_acceleration_x(0);
438   } else {
439     float friction = WALK_ACCELERATION_X * (on_ice ? ICE_FRICTION_MULTIPLIER : NORMAL_FRICTION_MULTIPLIER);
440     if(physic.get_velocity_x() < 0) {
441       physic.set_acceleration_x(friction);
442     } else if(physic.get_velocity_x() > 0) {
443       physic.set_acceleration_x(-friction);
444     } // no friction for physic.get_velocity_x() == 0
445   }
446 }
447
448 void
449 Player::handle_horizontal_input()
450 {
451   float vx = physic.get_velocity_x();
452   float vy = physic.get_velocity_y();
453   float ax = physic.get_acceleration_x();
454   float ay = physic.get_acceleration_y();
455
456   float dirsign = 0;
457   if(!duck || physic.get_velocity_y() != 0) {
458     if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
459       old_dir = dir;
460       dir = LEFT;
461       dirsign = -1;
462     } else if(!controller->hold(Controller::LEFT)
463               && controller->hold(Controller::RIGHT)) {
464       old_dir = dir;
465       dir = RIGHT;
466       dirsign = 1;
467     }
468   }
469
470   // do not run if action key is pressed or we're holding something
471   // so tux can only walk while shooting
472   if ( controller->hold(Controller::ACTION) || grabbed_object ) {
473     ax = dirsign * WALK_ACCELERATION_X;
474     // limit speed
475     if(vx >= MAX_WALK_XM && dirsign > 0) {
476       vx = MAX_WALK_XM;
477       ax = 0;
478     } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
479       vx = -MAX_WALK_XM;
480       ax = 0;
481     }
482   } else {
483     if( vx * dirsign < MAX_WALK_XM ) {
484       ax = dirsign * WALK_ACCELERATION_X;
485     } else {
486       ax = dirsign * RUN_ACCELERATION_X;
487     }
488     // limit speed
489     if(vx >= MAX_RUN_XM && dirsign > 0) {
490       vx = MAX_RUN_XM;
491       ax = 0;
492     } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
493       vx = -MAX_RUN_XM;
494       ax = 0;
495     }
496   }
497
498   // we can reach WALK_SPEED without any acceleration
499   if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
500     vx = dirsign * WALK_SPEED;
501   }
502
503   //Check speedlimit.
504   if( speedlimit > 0 &&  vx * dirsign >= speedlimit ) {
505     vx = dirsign * speedlimit;
506     ax = 0;
507   }
508
509   // changing directions?
510   if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
511     // let's skid!
512     if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
513       skidding_timer.start(SKID_TIME);
514       sound_manager->play("sounds/skid.wav");
515       // dust some particles
516       Sector::current()->add_object(
517         new Particles(
518           Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
519           dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
520           Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
521           LAYER_OBJECTS+1));
522
523       ax *= 2.5;
524     } else {
525       ax *= 2;
526     }
527   }
528
529   if(on_ice) {
530     ax *= ICE_ACCELERATION_MULTIPLIER;
531   }
532
533   physic.set_velocity(vx, vy);
534   physic.set_acceleration(ax, ay);
535
536   // we get slower when not pressing any keys
537   if(dirsign == 0) {
538     apply_friction();
539   }
540
541 }
542
543 void
544 Player::do_cheer()
545 {
546   do_duck();
547   do_backflip();
548   do_standup();
549 }
550
551 void
552 Player::do_duck() {
553   if (duck)
554     return;
555   if (!is_big())
556     return;
557
558   if (physic.get_velocity_y() != 0)
559     return;
560   if (!on_ground())
561     return;
562   if (does_buttjump)
563     return;
564
565   if (adjust_height(31.8f)) {
566     duck = true;
567     growing = false;
568     unduck_hurt_timer.stop();
569   } else {
570     // FIXME: what now?
571   }
572 }
573
574 void
575 Player::do_standup() {
576   if (!duck)
577     return;
578   if (!is_big())
579     return;
580   if (backflipping)
581     return;
582
583   if (adjust_height(63.8f)) {
584     duck = false;
585     unduck_hurt_timer.stop();
586   } else {
587     // if timer is not already running, start it.
588     if (unduck_hurt_timer.get_period() == 0) {
589       unduck_hurt_timer.start(UNDUCK_HURT_TIME);
590     }
591     else if (unduck_hurt_timer.check()) {
592       kill(false);
593     }
594   }
595
596 }
597
598 void
599 Player::do_backflip() {
600   if (!duck)
601     return;
602   if (!on_ground())
603     return;
604
605   backflip_direction = (dir == LEFT)?(+1):(-1);
606   backflipping = true;
607   do_jump(-580);
608   sound_manager->play("sounds/flip.wav");
609   backflip_timer.start(0.15f);
610 }
611
612 void
613 Player::do_jump(float yspeed) {
614   if (!on_ground())
615     return;
616
617   physic.set_velocity_y(yspeed);
618   //bbox.move(Vector(0, -1));
619   jumping = true;
620   on_ground_flag = false;
621   can_jump = false;
622
623   // play sound
624   if (is_big()) {
625     sound_manager->play("sounds/bigjump.wav");
626   } else {
627     sound_manager->play("sounds/jump.wav");
628   }
629 }
630
631 void
632 Player::early_jump_apex() 
633 {
634   if (!jump_early_apex)
635   {
636     jump_early_apex = true;
637     physic.set_gravity_modifier(JUMP_EARLY_APEX_FACTOR);
638   }
639 }
640
641 void
642 Player::do_jump_apex()
643 {
644   if (jump_early_apex)
645   {
646     jump_early_apex = false;
647     physic.set_gravity_modifier(1.0f);
648   }
649 }
650
651 void
652 Player::handle_vertical_input()
653 {
654   // Press jump key
655   if(controller->pressed(Controller::JUMP)) jump_button_timer.start(JUMP_GRACE_TIME);
656   if(controller->hold(Controller::JUMP) && jump_button_timer.started() && can_jump) {
657     jump_button_timer.stop();
658     if (duck) {
659       // when running, only jump a little bit; else do a backflip
660       if ((physic.get_velocity_x() != 0) || 
661           (controller->hold(Controller::LEFT)) || 
662           (controller->hold(Controller::RIGHT))) 
663       {
664         do_jump(-300);
665       }
666       else 
667       {
668         do_backflip();
669       }
670     } else {
671       // jump a bit higher if we are running; else do a normal jump
672       if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
673     }
674   }
675   // Let go of jump key
676   else if(!controller->hold(Controller::JUMP)) {
677     if (!backflipping && jumping && physic.get_velocity_y() < 0) {
678       jumping = false;
679       early_jump_apex();
680     }
681   }
682
683   if(jump_early_apex && physic.get_velocity_y() >= 0) {
684     do_jump_apex();
685   }
686
687   /* In case the player has pressed Down while in a certain range of air,
688      enable butt jump action */
689   if (controller->hold(Controller::DOWN) && !duck && is_big() && !on_ground()) {
690     wants_buttjump = true;
691     if (physic.get_velocity_y() >= BUTTJUMP_MIN_VELOCITY_Y) does_buttjump = true;
692   }
693
694   /* When Down is not held anymore, disable butt jump */
695   if(!controller->hold(Controller::DOWN)) {
696     wants_buttjump = false;
697     does_buttjump = false;
698   }
699
700   // swimming
701   physic.set_acceleration_y(0);
702 #ifdef SWIMMING
703   if (swimming) {
704     if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP))
705       physic.set_acceleration_y(-2000);
706     physic.set_velocity_y(physic.get_velocity_y() * 0.94);
707   }
708 #endif
709 }
710
711 void
712 Player::handle_input()
713 {
714   if (ghost_mode) {
715     handle_input_ghost();
716     return;
717   }
718   if (climbing) {
719     handle_input_climbing();
720     return;
721   }
722
723   /* Peeking */
724   if( controller->released( Controller::PEEK_LEFT ) || controller->released( Controller::PEEK_RIGHT ) ) {
725     peekingX = AUTO;
726   }
727   if( controller->released( Controller::PEEK_UP ) || controller->released( Controller::PEEK_DOWN ) ) {
728     peekingY = AUTO;
729   }
730   if( controller->pressed( Controller::PEEK_LEFT ) ) {
731     peekingX = LEFT;
732   }
733   if( controller->pressed( Controller::PEEK_RIGHT ) ) {
734     peekingX = RIGHT;
735   }
736   if(!backflipping && !jumping && on_ground()) {
737     if( controller->pressed( Controller::PEEK_UP ) ) {
738       peekingY = UP;
739     } else if( controller->pressed( Controller::PEEK_DOWN ) ) {
740       peekingY = DOWN;
741     }
742   }
743
744   /* Handle horizontal movement: */
745   if (!backflipping) handle_horizontal_input();
746
747   /* Jump/jumping? */
748   if (on_ground())
749     can_jump = true;
750
751   /* Handle vertical movement: */
752   handle_vertical_input();
753
754   /* Shoot! */
755   if (controller->pressed(Controller::ACTION) && (player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS)) {
756     if(Sector::current()->add_bullet(
757          get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
758                       : Vector(32, bbox.get_height()/2)),
759          player_status,
760          physic.get_velocity_x(), dir))
761       shooting_timer.start(SHOOTING_TIME);
762   }
763
764   /* Duck or Standup! */
765   if (controller->hold(Controller::DOWN)) {
766     do_duck();
767   } else {
768     do_standup();
769   }
770
771   /* grabbing */
772   try_grab();
773
774   if(!controller->hold(Controller::ACTION) && grabbed_object) {
775     MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
776     if(moving_object) {
777       // move the grabbed object a bit away from tux
778       Rectf grabbed_bbox = moving_object->get_bbox();
779       Rectf dest;
780       dest.p2.y = bbox.get_top() + bbox.get_height()*0.66666;
781       dest.p1.y = dest.p2.y - grabbed_bbox.get_height();
782       if(dir == LEFT) {
783         dest.p2.x = bbox.get_left() - 1;
784         dest.p1.x = dest.p2.x - grabbed_bbox.get_width();
785       } else {
786         dest.p1.x = bbox.get_right() + 1;
787         dest.p2.x = dest.p1.x + grabbed_bbox.get_width();
788       }
789       if(Sector::current()->is_free_of_movingstatics(dest)) {
790         moving_object->set_pos(dest.p1);
791         if(controller->hold(Controller::UP)) {
792           grabbed_object->ungrab(*this, UP);
793         } else {
794           grabbed_object->ungrab(*this, dir);
795         }
796         grabbed_object = NULL;
797       }
798     } else {
799       log_debug << "Non MovingObject grabbed?!?" << std::endl;
800     }
801   }
802 }
803
804 void
805 Player::position_grabbed_object()
806 {
807   MovingObject* moving_object = dynamic_cast<MovingObject*>(grabbed_object);
808   assert(moving_object);
809
810   // Position where we will hold the lower-inner corner
811   Vector pos(get_bbox().get_left() + get_bbox().get_width()/2,
812       get_bbox().get_top() + get_bbox().get_height()*0.66666);
813
814   // Adjust to find the grabbed object's upper-left corner
815   if (dir == LEFT)
816     pos.x -= moving_object->get_bbox().get_width();
817   pos.y -= moving_object->get_bbox().get_height();
818
819   grabbed_object->grab(*this, pos, dir);
820 }
821
822 void
823 Player::try_grab()
824 {
825   if(controller->hold(Controller::ACTION) && !grabbed_object
826      && !duck) {
827     Sector* sector = Sector::current();
828     Vector pos;
829     if(dir == LEFT) {
830       pos = Vector(bbox.get_left() - 5, bbox.get_bottom() - 16);
831     } else {
832       pos = Vector(bbox.get_right() + 5, bbox.get_bottom() - 16);
833     }
834
835     for(Sector::Portables::iterator i = sector->portables.begin();
836         i != sector->portables.end(); ++i) {
837       Portable* portable = *i;
838       if(!portable->is_portable())
839         continue;
840
841       // make sure the Portable is a MovingObject
842       MovingObject* moving_object = dynamic_cast<MovingObject*> (portable);
843       assert(moving_object);
844       if(moving_object == NULL)
845         continue;
846
847       // make sure the Portable isn't currently non-solid
848       if(moving_object->get_group() == COLGROUP_DISABLED) continue;
849
850       // check if we are within reach
851       if(moving_object->get_bbox().contains(pos)) {
852         if (climbing) stop_climbing(*climbing);
853         grabbed_object = portable;
854         position_grabbed_object();
855         break;
856       }
857     }
858   }
859 }
860
861 void
862 Player::handle_input_ghost()
863 {
864   float vx = 0;
865   float vy = 0;
866   if (controller->hold(Controller::LEFT)) {
867     dir = LEFT;
868     vx -= MAX_RUN_XM * 2;
869   }
870   if (controller->hold(Controller::RIGHT)) {
871     dir = RIGHT;
872     vx += MAX_RUN_XM * 2;
873   }
874   if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
875     vy -= MAX_RUN_XM * 2;
876   }
877   if (controller->hold(Controller::DOWN)) {
878     vy += MAX_RUN_XM * 2;
879   }
880   if (controller->hold(Controller::ACTION)) {
881     set_ghost_mode(false);
882   }
883   physic.set_velocity(vx, vy);
884   physic.set_acceleration(0, 0);
885 }
886
887 void
888 Player::add_coins(int count)
889 {
890   player_status->add_coins(count);
891 }
892
893 int
894 Player::get_coins()
895 {
896   return player_status->coins;
897 }
898
899 bool
900 Player::add_bonus(const std::string& bonustype)
901 {
902   BonusType type = NO_BONUS;
903
904   if(bonustype == "grow") {
905     type = GROWUP_BONUS;
906   } else if(bonustype == "fireflower") {
907     type = FIRE_BONUS;
908   } else if(bonustype == "iceflower") {
909     type = ICE_BONUS;
910   } else if(bonustype == "none") {
911     type = NO_BONUS;
912   } else {
913     std::ostringstream msg;
914     msg << "Unknown bonus type "  << bonustype;
915     throw std::runtime_error(msg.str());
916   }
917
918   return add_bonus(type);
919 }
920
921 bool
922 Player::add_bonus(BonusType type, bool animate)
923 {
924   // always ignore NO_BONUS
925   if (type == NO_BONUS) {
926     return true;
927   }
928
929   // ignore GROWUP_BONUS if we're already big
930   if (type == GROWUP_BONUS) {
931     if (player_status->bonus == GROWUP_BONUS)
932       return true;
933     if (player_status->bonus == FIRE_BONUS)
934       return true;
935     if (player_status->bonus == ICE_BONUS)
936       return true;
937   }
938
939   return set_bonus(type, animate);
940 }
941
942 bool
943 Player::set_bonus(BonusType type, bool animate)
944 {
945   if(player_status->bonus == NO_BONUS) {
946     if (!adjust_height(62.8f)) {
947       printf("can't adjust\n");
948       return false;
949     }
950     if(animate) {
951       growing = true;
952       sprite->set_action((dir == LEFT)?"grow-left":"grow-right", 1);
953     }
954     if (climbing) stop_climbing(*climbing);
955   }
956
957   if (type == NO_BONUS) {
958     if (does_buttjump) does_buttjump = false;
959   }
960
961   if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
962     if ((player_status->bonus == FIRE_BONUS) && (animate)) {
963       // visually lose helmet
964       Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
965       Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
966       Vector paccel = Vector(0, 1000);
967       std::string action = (dir==LEFT)?"left":"right";
968       Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
969       if (climbing) stop_climbing(*climbing);
970     }
971     if ((player_status->bonus == ICE_BONUS) && (animate)) {
972       // visually lose cap
973       Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
974       Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
975       Vector paccel = Vector(0, 1000);
976       std::string action = (dir==LEFT)?"left":"right";
977       Sector::current()->add_object(new SpriteParticle("images/objects/particles/icetux-cap.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
978       if (climbing) stop_climbing(*climbing);
979     }
980     player_status->max_fire_bullets = 0;
981     player_status->max_ice_bullets = 0;
982   }
983   if (type == FIRE_BONUS) player_status->max_fire_bullets++;
984   if (type == ICE_BONUS) player_status->max_ice_bullets++;
985
986   player_status->bonus = type;
987   return true;
988 }
989
990 void
991 Player::set_visible(bool visible)
992 {
993   this->visible = visible;
994   if( visible )
995     set_group(COLGROUP_MOVING);
996   else
997     set_group(COLGROUP_DISABLED);
998 }
999
1000 bool
1001 Player::get_visible()
1002 {
1003   return visible;
1004 }
1005
1006 void
1007 Player::kick()
1008 {
1009   kick_timer.start(KICK_TIME);
1010 }
1011
1012 void
1013 Player::draw(DrawingContext& context)
1014 {
1015   if(!visible)
1016     return;
1017
1018   // if Tux is above camera, draw little "air arrow" to show where he is x-wise
1019   if (Sector::current() && Sector::current()->camera && (get_bbox().p2.y - 16 < Sector::current()->camera->get_translation().y)) {
1020     float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
1021     float py = Sector::current()->camera->get_translation().y;
1022     py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
1023     context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
1024   }
1025
1026   std::string sa_prefix = "";
1027   std::string sa_postfix = "";
1028
1029   if (player_status->bonus == GROWUP_BONUS)
1030     sa_prefix = "big";
1031   else if (player_status->bonus == FIRE_BONUS)
1032     sa_prefix = "fire";
1033   else if (player_status->bonus == ICE_BONUS)
1034     sa_prefix = "ice";
1035   else
1036     sa_prefix = "small";
1037
1038   if(dir == LEFT)
1039     sa_postfix = "-left";
1040   else
1041     sa_postfix = "-right";
1042
1043   /* Set Tux sprite action */
1044   if(dying) {
1045     sprite->set_action("gameover");
1046   }
1047   else if (growing) {
1048     sprite->set_action_continued("grow"+sa_postfix);
1049     // while growing, do not change action
1050     // do_duck() will take care of cancelling growing manually
1051     // update() will take care of cancelling when growing completed
1052   }
1053   else if (climbing) {
1054     sprite->set_action(sa_prefix+"-skid"+sa_postfix);
1055   }
1056   else if (backflipping) {
1057     sprite->set_action(sa_prefix+"-backflip"+sa_postfix);
1058   }
1059   else if (duck && is_big()) {
1060     sprite->set_action(sa_prefix+"-duck"+sa_postfix);
1061   }
1062   else if (skidding_timer.started() && !skidding_timer.check()) {
1063     sprite->set_action(sa_prefix+"-skid"+sa_postfix);
1064   }
1065   else if (kick_timer.started() && !kick_timer.check()) {
1066     sprite->set_action(sa_prefix+"-kick"+sa_postfix);
1067   }
1068   else if ((wants_buttjump || does_buttjump) && is_big()) {
1069     sprite->set_action(sa_prefix+"-buttjump"+sa_postfix);
1070   }
1071   else if (!on_ground()) {
1072     sprite->set_action(sa_prefix+"-jump"+sa_postfix);
1073   }
1074   else {
1075     if (fabsf(physic.get_velocity_x()) < 1.0f) {
1076       // Determine which idle stage we're at
1077       if (sprite->get_action().find("-stand-") == std::string::npos && sprite->get_action().find("-idle-") == std::string::npos) {
1078         idle_stage = 0;
1079         idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);
1080
1081         sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
1082       }
1083       else if (idle_timer.check() || (IDLE_TIME[idle_stage] == 0 && sprite->animation_done())) {
1084         idle_stage++;
1085         if (idle_stage >= IDLE_STAGE_COUNT)
1086           idle_stage = 1;
1087
1088         idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);
1089
1090         if (IDLE_TIME[idle_stage] == 0)
1091           sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix, 1);
1092         else
1093           sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
1094       }
1095       else {
1096         sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
1097       }
1098     }
1099     else {
1100       sprite->set_action(sa_prefix+"-walk"+sa_postfix);
1101     }
1102   }
1103
1104   /*
1105   // Tux is holding something
1106   if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
1107   (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) {
1108   if (duck) {
1109   } else {
1110   }
1111   }
1112   */
1113
1114   /* Draw Tux */
1115   if (safe_timer.started() && size_t(game_time*40)%2)
1116     ;  // don't draw Tux
1117   else {
1118     sprite->draw(context, get_pos(), LAYER_OBJECTS + 1);
1119   }
1120
1121 }
1122
1123 void
1124 Player::collision_tile(uint32_t tile_attributes)
1125 {
1126   if(tile_attributes & Tile::HURTS)
1127     kill(false);
1128
1129 #ifdef SWIMMING
1130   if( swimming ){
1131     if( tile_attributes & Tile::WATER ){
1132       no_water = false;
1133     } else {
1134       swimming = false;
1135     }
1136   } else {
1137     if( tile_attributes & Tile::WATER ){
1138       swimming = true;
1139       no_water = false;
1140       sound_manager->play( "sounds/splash.ogg" );
1141     }
1142   }
1143 #endif
1144
1145   if(tile_attributes & Tile::ICE) {
1146     ice_this_frame = true;
1147     on_ice = true;
1148   }
1149 }
1150
1151 void
1152 Player::collision_solid(const CollisionHit& hit)
1153 {
1154   if(hit.bottom) {
1155     if(physic.get_velocity_y() > 0)
1156       physic.set_velocity_y(0);
1157
1158     on_ground_flag = true;
1159     floor_normal = hit.slope_normal;
1160
1161     // Butt Jump landed    
1162     if (does_buttjump) {
1163       does_buttjump = false;
1164       physic.set_velocity_y(-300);
1165       on_ground_flag = false;
1166       Sector::current()->add_object(new Particles(
1167                                       Vector(get_bbox().p2.x, get_bbox().p2.y),
1168                                       270+20, 270+40,
1169                                       Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
1170                                       LAYER_OBJECTS+1));
1171       Sector::current()->add_object(new Particles(
1172                                       Vector(get_bbox().p1.x, get_bbox().p2.y),
1173                                       90-40, 90-20,
1174                                       Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
1175                                       LAYER_OBJECTS+1));
1176       Sector::current()->camera->shake(.1f, 0, 5);
1177     }
1178
1179   } else if(hit.top) {
1180     if(physic.get_velocity_y() < 0)
1181       physic.set_velocity_y(.2f);
1182   }
1183
1184   if(hit.left || hit.right) {
1185     physic.set_velocity_x(0);
1186   }
1187
1188   // crushed?
1189   if(hit.crush) {
1190     if(hit.left || hit.right) {
1191       kill(true);
1192     } else if(hit.top || hit.bottom) {
1193       kill(false);
1194     }
1195   }
1196 }
1197
1198 HitResponse
1199 Player::collision(GameObject& other, const CollisionHit& hit)
1200 {
1201   Bullet* bullet = dynamic_cast<Bullet*> (&other);
1202   if(bullet) {
1203     return FORCE_MOVE;
1204   }
1205
1206   if(hit.left || hit.right) {
1207     try_grab(); //grab objects right now, in update it will be too late
1208   }
1209   assert(dynamic_cast<MovingObject*> (&other) != NULL);
1210   MovingObject* moving_object = static_cast<MovingObject*> (&other);
1211   if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
1212     TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
1213     if(trigger) {
1214       if(controller->pressed(Controller::UP))
1215         trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
1216     }
1217
1218     return FORCE_MOVE;
1219   }
1220
1221   BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
1222   if(badguy != NULL) {
1223     if(safe_timer.started() || invincible_timer.started())
1224       return FORCE_MOVE;
1225
1226     return CONTINUE;
1227   }
1228
1229   return CONTINUE;
1230 }
1231
1232 void
1233 Player::make_invincible()
1234 {
1235   sound_manager->play("sounds/invincible_start.ogg");
1236   invincible_timer.start(TUX_INVINCIBLE_TIME);
1237   Sector::current()->play_music(HERRING_MUSIC);
1238 }
1239
1240 /* Kill Player! */
1241 void
1242 Player::kill(bool completely)
1243 {
1244   if(dying || deactivated)
1245     return;
1246
1247   if(!completely && (safe_timer.started() || invincible_timer.started()))
1248     return;
1249
1250   growing = false;
1251
1252   if (climbing) stop_climbing(*climbing);
1253
1254   physic.set_velocity_x(0);
1255
1256   if(!completely && is_big()) {
1257     sound_manager->play("sounds/hurt.wav");
1258
1259     if(player_status->bonus == FIRE_BONUS
1260        || player_status->bonus == ICE_BONUS) {
1261       safe_timer.start(TUX_SAFE_TIME);
1262       set_bonus(GROWUP_BONUS, true);
1263     } else if(player_status->bonus == GROWUP_BONUS) {
1264       safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
1265       adjust_height(30.8f);
1266       duck = false;
1267       backflipping = false;
1268       set_bonus(NO_BONUS, true);
1269     } else if(player_status->bonus == NO_BONUS) {
1270       safe_timer.start(TUX_SAFE_TIME);
1271       adjust_height(30.8f);
1272       duck = false;
1273     }
1274   } else {
1275     sound_manager->play("sounds/kill.wav");
1276
1277     // do not die when in edit mode
1278     if (edit_mode) {
1279       set_ghost_mode(true);
1280       return;
1281     }
1282
1283     if (player_status->coins >= 25 && !GameSession::current()->get_reset_point_sectorname().empty())
1284     {
1285       for (int i = 0; i < 5; i++)
1286       {
1287         // the numbers: starting x, starting y, velocity y
1288         Sector::current()->add_object(new FallingCoin(get_pos() +
1289                                                       Vector(graphicsRandom.rand(5), graphicsRandom.rand(-32,18)),
1290                                                       graphicsRandom.rand(-100,100)));
1291       }
1292       player_status->coins -= std::max(player_status->coins/10, 25);
1293     }
1294     else
1295     {
1296       GameSession::current()->set_reset_point("", Vector());
1297     }
1298     physic.enable_gravity(true);
1299     physic.set_gravity_modifier(1.0f); // Undo jump_early_apex
1300     safe_timer.stop();
1301     invincible_timer.stop();
1302     physic.set_acceleration(0, 0);
1303     physic.set_velocity(0, -700);
1304     set_bonus(NO_BONUS, true);
1305     dying = true;
1306     dying_timer.start(3.0);
1307     set_group(COLGROUP_DISABLED);
1308
1309     Sector::current()->effect->fade_out(3.0);
1310     sound_manager->stop_music(3.0);
1311   }
1312 }
1313
1314 void
1315 Player::move(const Vector& vector)
1316 {
1317   set_pos(vector);
1318
1319   // TODO: do we need the following? Seems irrelevant to moving the player
1320   if(is_big())
1321     set_size(31.8f, 63.8f);
1322   else
1323     set_size(31.8f, 31.8f);
1324   duck = false;
1325   backflipping = false;
1326   last_ground_y = vector.y;
1327   if (climbing) stop_climbing(*climbing);
1328
1329   physic.reset();
1330 }
1331
1332 void
1333 Player::check_bounds()
1334 {
1335   /* Keep tux in sector bounds: */
1336   if (get_pos().x < 0) {
1337     // Lock Tux to the size of the level, so that he doesn't fall off
1338     // the left side
1339     set_pos(Vector(0, get_pos().y));
1340   }
1341
1342   if (get_bbox().get_right() > Sector::current()->get_width()) {
1343     // Lock Tux to the size of the level, so that he doesn't fall off
1344     // the right side
1345     set_pos(Vector(Sector::current()->get_width() - get_bbox().get_width(), get_pos().y));
1346   }
1347
1348   /* fallen out of the level? */
1349   if ((get_pos().y > Sector::current()->get_height()) && (!ghost_mode)) {
1350     kill(true);
1351     return;
1352   }
1353 }
1354
1355 void
1356 Player::add_velocity(const Vector& velocity)
1357 {
1358   physic.set_velocity(physic.get_velocity() + velocity);
1359 }
1360
1361 void
1362 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1363 {
1364   if (end_speed.x > 0)
1365     physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1366   if (end_speed.x < 0)
1367     physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1368   if (end_speed.y > 0)
1369     physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1370   if (end_speed.y < 0)
1371     physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1372 }
1373
1374 Vector 
1375 Player::get_velocity()
1376 {
1377   return physic.get_velocity();
1378 }
1379
1380 void
1381 Player::bounce(BadGuy& )
1382 {
1383   if(controller->hold(Controller::JUMP))
1384     physic.set_velocity_y(-520);
1385   else
1386     physic.set_velocity_y(-300);
1387 }
1388
1389 //scripting Functions Below
1390
1391 void
1392 Player::deactivate()
1393 {
1394   if (deactivated)
1395     return;
1396   deactivated = true;
1397   physic.set_velocity_x(0);
1398   physic.set_velocity_y(0);
1399   physic.set_acceleration_x(0);
1400   physic.set_acceleration_y(0);
1401   if (climbing) stop_climbing(*climbing);
1402 }
1403
1404 void
1405 Player::activate()
1406 {
1407   if (!deactivated)
1408     return;
1409   deactivated = false;
1410 }
1411
1412 void Player::walk(float speed)
1413 {
1414   physic.set_velocity_x(speed);
1415 }
1416
1417 void
1418 Player::set_ghost_mode(bool enable)
1419 {
1420   if (ghost_mode == enable)
1421     return;
1422
1423   if (climbing) stop_climbing(*climbing);
1424
1425   if (enable) {
1426     ghost_mode = true;
1427     set_group(COLGROUP_DISABLED);
1428     physic.enable_gravity(false);
1429     log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1430   } else {
1431     ghost_mode = false;
1432     set_group(COLGROUP_MOVING);
1433     physic.enable_gravity(true);
1434     log_debug << "You feel solid again." << std::endl;
1435   }
1436 }
1437
1438 void
1439 Player::set_edit_mode(bool enable)
1440 {
1441   edit_mode = enable;
1442 }
1443
1444 void 
1445 Player::start_climbing(Climbable& climbable)
1446 {
1447   if (climbing == &climbable) return;
1448
1449   climbing = &climbable;
1450   physic.enable_gravity(false);
1451   physic.set_velocity(0, 0);
1452   physic.set_acceleration(0, 0);
1453 }
1454
1455 void 
1456 Player::stop_climbing(Climbable& /*climbable*/)
1457 {
1458   if (!climbing) return;
1459
1460   climbing = 0;
1461
1462   if (grabbed_object) {    
1463     grabbed_object->ungrab(*this, dir);
1464     grabbed_object = NULL;
1465   }
1466
1467   physic.enable_gravity(true);
1468   physic.set_velocity(0, 0);
1469   physic.set_acceleration(0, 0);
1470
1471   if ((controller->hold(Controller::JUMP)) || (controller->hold(Controller::UP))) {
1472     on_ground_flag = true;
1473     // TODO: This won't help. Why?
1474     do_jump(-300);
1475   }
1476 }
1477
1478 void
1479 Player::handle_input_climbing()
1480 {
1481   if (!climbing) {
1482     log_warning << "handle_input_climbing called with climbing set to 0. Input handling skipped" << std::endl;
1483     return;
1484   }
1485
1486   float vx = 0;
1487   float vy = 0;
1488   if (controller->hold(Controller::LEFT)) {
1489     dir = LEFT;
1490     vx -= MAX_CLIMB_XM;
1491   }
1492   if (controller->hold(Controller::RIGHT)) {
1493     dir = RIGHT;
1494     vx += MAX_CLIMB_XM;
1495   }
1496   if (controller->hold(Controller::UP)) {
1497     vy -= MAX_CLIMB_YM;
1498   }
1499   if (controller->hold(Controller::DOWN)) {
1500     vy += MAX_CLIMB_YM;
1501   }
1502   if (controller->hold(Controller::JUMP)) {
1503     if (can_jump) {
1504       stop_climbing(*climbing);
1505       return;
1506     }  
1507   } else {
1508     can_jump = true;
1509   }
1510   if (controller->hold(Controller::ACTION)) {
1511     stop_climbing(*climbing);
1512     return;
1513   }
1514   physic.set_velocity(vx, vy);
1515   physic.set_acceleration(0, 0);
1516 }
1517
1518 /* EOF */