3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
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.
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.
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.
24 #include "app/globals.h"
25 #include "app/gettext.h"
30 #include "special/sprite.h"
35 #include "resources.h"
36 #include "interactive_object.h"
37 #include "video/screen.h"
38 #include "statistics.h"
41 // behavior definitions:
42 #define TILES_FOR_BUTTJUMP 3
43 // animation times (in ms):
44 #define SHOOTING_TIME 320
46 #define AUTOSCROLL_DEAD_INTERVAL 300
48 // time before idle animation starts
49 #define IDLE_TIME 2500
52 Surface* growingtux_left[GROWING_FRAMES];
53 Surface* growingtux_right[GROWING_FRAMES];
57 Sprite* smalltux_gameover;
58 Sprite* smalltux_star;
61 TuxBodyParts* small_tux;
62 TuxBodyParts* big_tux;
63 TuxBodyParts* fire_tux;
64 TuxBodyParts* ice_tux;
68 PlayerKeymap::PlayerKeymap()
71 keymap.down = SDLK_DOWN;
72 keymap.left = SDLK_LEFT;
73 keymap.right = SDLK_RIGHT;
75 keymap.power = SDLK_LCTRL;
76 keymap.jump = SDLK_LALT;
79 void player_input_init(player_input_type* pplayer_input)
81 pplayer_input->up = UP;
82 pplayer_input->down = UP;
83 pplayer_input->fire = UP;
84 pplayer_input->left = UP;
85 pplayer_input->old_fire = UP;
86 pplayer_input->right = UP;
87 pplayer_input->jump = UP;
88 pplayer_input->old_jump = UP;
89 pplayer_input->activate = UP;
93 TuxBodyParts::set_action(std::string action)
96 head->set_action(action);
98 body->set_action(action);
100 arms->set_action(action);
102 feet->set_action(action);
106 TuxBodyParts::one_time_animation()
109 head->start_animation(1);
111 body->start_animation(1);
113 arms->start_animation(1);
115 feet->start_animation(1);
119 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer,
120 Uint32 drawing_effect)
123 head->draw(context, pos, layer-1, drawing_effect);
125 body->draw(context, pos, layer-3, drawing_effect);
127 arms->draw(context, pos, layer, drawing_effect);
129 feet->draw(context, pos, layer-2, drawing_effect);
144 holding_something = false;
150 got_power = NONE_POWER;
154 previous_base = old_base = base;
162 fall_mode = ON_GROUND;
167 falling_from_flap = false;
168 enable_hover = false;
171 flapping_velocity = 0;
176 player_input_init(&input);
178 invincible_timer.init(true);
179 skidding_timer.init(true);
180 safe_timer.init(true);
181 frame_timer.init(true);
182 kick_timer.init(true);
183 shooting_timer.init(true);
184 growing_timer.init(true);
185 idle_timer.init(true);
186 flapping_timer.init(true);
192 Player::key_event(SDLKey key, int state)
194 idle_timer.start(IDLE_TIME);
196 if(key == keymap.right)
201 else if(key == keymap.left)
206 else if(key == keymap.up)
210 /* Up key also opens activates stuff */
211 input.activate = state;
214 /** check for interactive objects */
215 for(Sector::InteractiveObjects::iterator i
216 = Sector::current()->interactive_objects.begin();
217 i != Sector::current()->interactive_objects.end(); ++i) {
218 if(rectcollision(base, (*i)->get_area())) {
219 (*i)->interaction(INTERACTION_ACTIVATE);
226 else if(key == keymap.down)
231 else if(key == keymap.power)
239 else if(key == keymap.jump)
251 Player::level_begin()
255 previous_base = old_base = base;
260 player_input_init(&input);
262 invincible_timer.init(true);
263 skidding_timer.init(true);
264 safe_timer.init(true);
265 frame_timer.init(true);
266 growing_timer.init(true);
267 idle_timer.init(true);
273 Player::action(float elapsed_time)
275 bool jumped_in_solid = false;
277 if(dying && !dying_timer.check()) {
282 if (input.fire == UP)
283 holding_something = false;
286 previous_base = base;
288 /* --- HANDLE TUX! --- */
289 if(dying == DYING_NOT)
292 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
294 if(dying == DYING_NOT)
296 base_type target = base;
298 collision_swept_object_map(&old_base, &base);
300 if ((!invincible_timer.started() && !safe_timer.started())
301 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
302 || isspike(base.x, base.y + base.height)
303 || isspike(base.x + base.width, base.y + base.height)))
308 // Don't accelerate Tux if he is running against a wall
309 if (target.x != base.x)
311 physic.set_velocity_x(0);
314 // special exception for cases where we're stuck under tiles after
315 // being ducked. In this case we drift out
316 if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
317 && collision_object_map(base))
319 base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1);
320 previous_base = old_base = base;
326 physic.enable_gravity(true);
330 physic.set_velocity_y(0);
331 jumped_in_solid = true;
339 if (physic.get_velocity_y() < 0)
341 base.y = (int)(((int)base.y / 32) * 32);
342 physic.set_velocity_y(0);
345 physic.enable_gravity(false);
346 /* Reset score multiplier (for multi-hits): */
347 if (!invincible_timer.started())
349 /*if(player_status.score_multiplier > 2)
352 sprintf(str, _("%d bad guys in a row!"), player_status.score_multiplier-1);
353 Sector::current()->add_floating_text(base, str);
355 player_status.score_multiplier = 1;
361 if (isbrick(base.x, base.y) ||
362 isfullbox(base.x, base.y))
364 Sector::current()->trygrabdistro(
365 Vector(base.x, base.y - 32), BOUNCE);
366 Sector::current()->trybumpbadguy(Vector(base.x, base.y - 64));
368 Sector::current()->trybreakbrick(
369 Vector(base.x, base.y), size == SMALL);
371 bumpbrick(base.x, base.y);
372 Sector::current()->tryemptybox(Vector(base.x, base.y), RIGHT);
375 if (isbrick(base.x+ 31, base.y) ||
376 isfullbox(base.x+ 31, base.y))
378 Sector::current()->trygrabdistro(
379 Vector(base.x+ 31, base.y - 32), BOUNCE);
380 Sector::current()->trybumpbadguy(Vector(base.x+ 31, base.y - 64));
383 Sector::current()->trybreakbrick(
384 Vector(base.x+ 31, base.y), size == SMALL);
386 bumpbrick(base.x+ 31, base.y);
387 Sector::current()->tryemptybox(Vector(base.x+ 31, base.y), LEFT);
399 /* Make sure jumping is off. */
406 /* ---- DONE HANDLING TUX! --- */
409 skidding_timer.check();
410 invincible_timer.check();
418 return ( issolid(base.x + base.width / 2, base.y + base.height) ||
419 issolid(base.x + 1, base.y + base.height) ||
420 issolid(base.x + base.width - 1, base.y + base.height));
424 Player::under_solid()
426 return ( issolid(base.x + base.width / 2, base.y) ||
427 issolid(base.x + 1, base.y) ||
428 issolid(base.x + base.width - 1, base.y) );
432 Player::tiles_on_air(int tiles)
434 for(int t = 0; t != tiles; t++)
436 if(issolid(base.x + base.width / 2, base.y + base.height + (tiles*32)) ||
437 issolid(base.x + 1, base.y + base.height + (tiles*32)) ||
438 issolid(base.x + base.width - 1, base.y + base.height + (tiles*32)))
445 Player::handle_horizontal_input()
447 float vx = physic.get_velocity_x();
448 float vy = physic.get_velocity_y();
449 float ax = physic.get_acceleration_x();
450 float ay = physic.get_acceleration_y();
453 if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
457 } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
463 if (input.fire == UP) {
464 ax = dirsign * WALK_ACCELERATION_X;
466 if(vx >= MAX_WALK_XM && dirsign > 0) {
469 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
474 ax = dirsign * RUN_ACCELERATION_X;
476 if(vx >= MAX_RUN_XM && dirsign > 0) {
479 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
485 // we can reach WALK_SPEED without any acceleration
486 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
487 vx = dirsign * WALK_SPEED;
490 // changing directions?
491 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
492 if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
493 skidding_timer.start(SKID_TIME);
494 SoundManager::get()->play_sound(IDToSound(SND_SKID));
501 // we get slower when not pressing any keys
503 if(fabs(vx) < WALK_SPEED) {
507 ax = WALK_ACCELERATION_X * 1.5;
509 ax = WALK_ACCELERATION_X * -1.5;
513 // if we're on ice slow down acceleration or deceleration
514 if (isice(base.x, base.y + base.height))
516 /* the acceleration/deceleration rate on ice is inversely proportional to
517 * the current velocity.
520 // increasing 1 will increase acceleration/deceleration rate
521 // decreasing 1 will decrease acceleration/deceleration rate
522 // must stay above zero, though
523 if (ax != 0) ax *= 1 / fabs(vx);
526 physic.set_velocity(vx, vy);
527 physic.set_acceleration(ax, ay);
531 Player::handle_vertical_input()
536 fall_mode = ON_GROUND;
537 last_ground_y = base.y;
539 if(base.y > last_ground_y)
541 else if(fall_mode == ON_GROUND)
546 if(input.jump == DOWN && can_jump && on_ground())
548 if(duck) { // only jump a little bit when in duck mode {
549 physic.set_velocity_y(3);
551 // jump higher if we are running
552 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
553 physic.set_velocity_y(5.8);
555 physic.set_velocity_y(5.2);
564 SoundManager::get()->play_sound(IDToSound(SND_JUMP));
566 SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
568 // Let go of jump key
569 else if(input.jump == UP)
571 if (!flapping && !duck && !falling_from_flap && !on_ground())
575 if (jumping && physic.get_velocity_y() > 0)
578 physic.set_velocity_y(0);
583 // Flapping, Marek's version
584 if (input.jump == DOWN && can_flap)
586 if (!flapping_timer.started())
588 flapping_timer.start(TUX_FLAPPING_TIME);
589 flapping_velocity = physic.get_velocity_x();
591 if (!flapping_timer.check())
594 falling_from_flap = true;
598 if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
601 if (flapping_velocity == 0) {cv = 0;}
602 else {cv = flapping_velocity*(sqrt(TUX_FLAPPING_TIME-(float)flapping_timer.get_gone()))/sqrt(TUX_FLAPPING_TIME);}
603 //Handle change of direction while flapping
604 if (((dir == LEFT) && (cv > 0)) || (dir == RIGHT) && (cv < 0)) {cv *= (-1);}
605 physic.set_velocity_x(cv);
606 physic.set_velocity_y((float)flapping_timer.get_gone()/850);
610 /* // Flapping, Ryan's version
611 if (input.jump == DOWN && can_flap)
613 if (!flapping_timer.started())
615 flapping_timer.start(TUX_FLAPPING_TIME);
617 if (!flapping_timer.check())
620 falling_from_flap = true;
624 if (flapping && flapping_timer.get_gone() <= TUX_FLAPPING_TIME
625 && physic.get_velocity_y() < 0)
627 float gravity = Sector::current()->gravity;
628 float xr = (fabsf(physic.get_velocity_x()) / MAX_RUN_XM);
630 // XXX: magic numbers. should be a percent of gravity
631 // gravity is (by default) -0.1f
632 physic.set_acceleration_y(.12 + .01f*xr);
635 // To slow down x-vel when flapping (not working)
636 if (fabsf(physic.get_velocity_x()) > MAX_WALK_XM)
638 if (physic.get_velocity_x() < 0)
639 physic.set_acceleration_x(1.0f);
640 else if (physic.get_velocity_x() > 0)
641 physic.set_acceleration_x(-1.0f);
648 physic.set_acceleration_y(0);
653 //(disabled by default, use cheat code "hover" to toggle on/off)
654 //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys
655 if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0)
657 physic.set_velocity_y(-1);
660 /* In case the player has pressed Down while in a certain range of air,
661 enable butt jump action */
662 if (input.down == DOWN && !butt_jump && !duck)
663 if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
666 /* When Down is not held anymore, disable butt jump */
667 if(butt_jump && input.down == UP)
671 if (butt_jump && on_ground() && size == BIG)
675 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y));
677 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32));
681 // Break bricks beneath Tux
682 if(Sector::current()->trybreakbrick(
683 Vector(base.x + 1, base.y + base.height), false)
684 || Sector::current()->trybreakbrick(
685 Vector(base.x + base.width - 1, base.y + base.height), false))
687 physic.set_velocity_y(2);
691 // Kill nearby badguys
692 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
693 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
694 i != gameobjects.end();
697 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
700 // don't kill when badguys are already dying or in a certain mode
701 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
702 badguy->mode != BadGuy::BOMB_EXPLODE)
704 if (fabsf(base.x - badguy->base.x) < 150 &&
705 fabsf(base.y - badguy->base.y) < 60 &&
706 (issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
707 issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
714 if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
715 issolid(base.x + 1, base.y + base.height + 64) ||
716 issolid(base.x + base.width - 1, base.y + base.height + 64))
719 && input.jump == DOWN
720 && input.old_jump == UP)
725 if(on_ground()) /* Make sure jumping is off. */
729 falling_from_flap = false;
730 if (flapping_timer.started()) {flapping_timer.stop();}
732 physic.set_acceleration_y(0); //for flapping
735 input.old_jump = input.jump;
739 Player::handle_input()
741 /* Handle horizontal movement: */
742 handle_horizontal_input();
746 if (on_ground() && input.jump == UP)
748 handle_vertical_input();
751 if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
753 if(Sector::current()->add_bullet(Vector(base.x, base.y + (base.height/2)),
754 physic.get_velocity_x(), dir))
755 shooting_timer.start(SHOOTING_TIME);
756 input.old_fire = DOWN;
759 /* tux animations: */
760 if(!frame_timer.check())
762 frame_timer.start(25);
763 if (input.right == UP && input.left == UP)
770 if ((input.fire == DOWN && (global_frame_counter % 2) == 0) ||
771 (global_frame_counter % 4) == 0)
772 frame_main = (frame_main + 1) % 4;
782 if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
787 // changing base size confuses collision otherwise
788 old_base = previous_base = base;
790 else if(input.down == UP && size == BIG && duck)
792 // try if we can really unduck
795 // when unducking in air we need some space to do so
796 if(on_ground() || !collision_object_map(base)) {
798 // changing base size confuses collision otherwise
799 old_base = previous_base = base;
801 // undo the ducking changes
809 Player::grow(bool animate)
819 growing_timer.start(GROWING_TIME);
821 old_base = previous_base = base;
825 Player::grabdistros()
830 Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
831 Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
832 Sector::current()->trygrabdistro(
833 Vector(base.x, base.y + base.height), NO_BOUNCE);
834 Sector::current()->trygrabdistro(
835 Vector(base.x+ 31, base.y + base.height), NO_BOUNCE);
839 Sector::current()->trygrabdistro(
840 Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
841 Sector::current()->trygrabdistro(
842 Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
847 /* Enough distros for a One-up? */
848 if (player_status.distros >= DISTROS_LIFEUP)
850 player_status.distros = player_status.distros - DISTROS_LIFEUP;
851 if(player_status.lives < MAX_LIVES)
852 ++player_status.lives;
853 /*We want to hear the sound even, if MAX_LIVES is reached*/
854 SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
859 Player::draw(DrawingContext& context)
861 TuxBodyParts* tux_body;
864 tux_body = small_tux;
865 else if (got_power == FIRE_POWER)
867 else if (got_power == ICE_POWER)
872 int layer = LAYER_OBJECTS - 1;
873 Vector pos = Vector(base.x, base.y);
875 /* Set Tux sprite action */
876 if (duck && size == BIG)
879 tux_body->set_action("duck-left");
881 tux_body->set_action("duck-right");
883 else if (skidding_timer.started())
886 tux_body->set_action("skid-left");
888 tux_body->set_action("skid-right");
890 else if (kick_timer.started())
893 tux_body->set_action("kick-left");
895 tux_body->set_action("kick-right");
900 tux_body->set_action("buttjump-left");
902 tux_body->set_action("buttjump-right");
904 else if (physic.get_velocity_y() != 0)
907 tux_body->set_action("jump-left");
909 tux_body->set_action("jump-right");
913 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
916 tux_body->set_action("stand-left");
918 tux_body->set_action("stand-right");
923 tux_body->set_action("walk-left");
925 tux_body->set_action("walk-right");
929 if(idle_timer.get_left() < 0)
934 tux_body->head->set_action("idle-left");
936 tux_body->head->set_action("idle-right");
938 tux_body->head->start_animation(1);
941 idle_timer.start(IDLE_TIME);
944 // Tux is holding something
945 if ((holding_something && physic.get_velocity_y() == 0) ||
946 shooting_timer.check())
951 tux_body->arms->set_action("duck+grab-left");
953 tux_body->arms->set_action("duck+grab-right");
958 tux_body->arms->set_action("grab-left");
960 tux_body->arms->set_action("grab-right");
965 if (dying == DYING_SQUISHED)
967 smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
969 else if(growing_timer.check())
974 context.draw_surface(growingtux_right[GROWING_FRAMES-1 -
975 ((growing_timer.get_gone() *
976 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
978 context.draw_surface(growingtux_left[GROWING_FRAMES-1 -
979 ((growing_timer.get_gone() *
980 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
985 context.draw_surface(growingtux_right[(growing_timer.get_gone() *
986 GROWING_FRAMES) / GROWING_TIME], pos, layer);
988 context.draw_surface(growingtux_left[(growing_timer.get_gone() *
989 GROWING_FRAMES) / GROWING_TIME], pos, layer);
992 else if (safe_timer.started() && global_frame_counter%2)
995 tux_body->draw(context, pos, layer, dir == LEFT ? HORIZONTAL_FLIP : NONE_EFFECT);
997 // Draw blinking star overlay
998 if (invincible_timer.started() &&
999 (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3)
1002 if (size == SMALL || duck)
1003 smalltux_star->draw(context, pos, LAYER_OBJECTS + 2);
1005 bigtux_star->draw(context, pos, LAYER_OBJECTS + 2);
1009 context.draw_filled_rect(Vector(base.x, base.y),
1010 Vector(base.width, base.height), Color(75,75,75, 150), LAYER_OBJECTS+1);
1014 Player::collision(const MovingObject& other, int collision_type)
1017 (void) collision_type;
1018 // will be implemented later
1022 Player::collision(void* p_c_object, int c_object)
1024 BadGuy* pbad_c = NULL;
1025 Trampoline* ptramp_c = NULL;
1026 FlyingPlatform* pplatform_c = NULL;
1031 pbad_c = (BadGuy*) p_c_object;
1033 /* Hurt player if he touches a badguy */
1034 if (!pbad_c->dying && !dying &&
1035 !safe_timer.started() &&
1036 pbad_c->mode != BadGuy::HELD)
1038 if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN
1039 && !holding_something)
1041 holding_something = true;
1042 pbad_c->mode = BadGuy::HELD;
1045 else if (pbad_c->mode == BadGuy::FLAT)
1047 // Don't get hurt if we're kicking a flat badguy!
1049 else if (pbad_c->mode == BadGuy::KICK)
1051 /* Hurt if you get hit by kicked laptop: */
1052 if (!invincible_timer.started())
1057 pbad_c->kill_me(20);
1059 else if (pbad_c->frozen_timer.check() && (pbad_c->kind == BAD_MRBOMB
1060 || pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FISH
1061 || pbad_c->kind == BAD_SPIKY))
1062 pbad_c->kill_me(20);
1065 if (!invincible_timer.started())
1071 pbad_c->kill_me(25);
1074 player_status.score_multiplier++;
1079 ptramp_c = (Trampoline*) p_c_object;
1081 // Pick up trampoline
1082 if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something && on_ground())
1084 holding_something = true;
1085 ptramp_c->mode = Trampoline::M_HELD;
1086 ptramp_c->base.y -= 8;
1088 // Set down trampoline
1089 else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN)
1091 holding_something = false;
1092 ptramp_c->mode = Trampoline::M_NORMAL;
1093 ptramp_c->base.y += 8;
1094 ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y());
1097 // ptramp_c->base.x = base.x + base.width+1;
1099 // ptramp_c->base.x = base.x - base.width-1;
1102 // Don't let tux walk through trampoline
1103 else if (ptramp_c->mode != Trampoline::M_HELD && on_ground())
1105 if (physic.get_velocity_x() > 0) // RIGHT
1107 physic.set_velocity_x(0);
1108 base.x = ptramp_c->base.x - base.width;
1110 else if (physic.get_velocity_x() < 0) // LEFT
1112 physic.set_velocity_x(0);
1113 base.x = ptramp_c->base.x + ptramp_c->base.width;
1118 case CO_FLYING_PLATFORM:
1119 pplatform_c = (FlyingPlatform*) p_c_object;
1121 base.y = pplatform_c->base.y - base.height;
1122 physic.set_velocity_x(pplatform_c->get_vel_x());
1124 physic.enable_gravity(false);
1126 fall_mode = ON_GROUND;
1138 Player::kill(HurtMode mode)
1143 SoundManager::get()->play_sound(IDToSound(SND_HURT));
1145 physic.set_velocity_x(0);
1147 if (mode == SHRINK && size == BIG)
1149 if (got_power != NONE_POWER)
1151 safe_timer.start(TUX_SAFE_TIME);
1152 got_power = NONE_POWER;
1156 growing_timer.start(GROWING_TIME);
1157 safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
1165 physic.enable_gravity(true);
1166 physic.set_acceleration(0, 0);
1167 physic.set_velocity(0, 7);
1168 --player_status.lives;
1169 dying = DYING_SQUISHED;
1170 dying_timer.start(3000);
1174 /* Remove Tux's power ups */
1176 Player::remove_powerups()
1178 got_power = NONE_POWER;
1184 Player::move(const Vector& vector)
1188 old_base = previous_base = base;
1192 Player::check_bounds(Camera* camera)
1194 /* Keep tux in bounds: */
1196 { // Lock Tux to the size of the level, so that he doesn't fall of
1201 /* Keep in-bounds, vertically: */
1202 if (base.y > Sector::current()->solids->get_height() * 32)
1208 bool adjust = false;
1209 // can happen if back scrolling is disabled
1210 if(base.x < camera->get_translation().x) {
1211 base.x = camera->get_translation().x;
1214 if(base.x >= camera->get_translation().x + screen->w - base.width) {
1215 base.x = camera->get_translation().x + screen->w - base.width;
1221 if(collision_object_map(base)) {
1229 Player::bounce(BadGuy* badguy)
1231 //Make sure we stopped flapping
1233 falling_from_flap = false;
1235 if(player_status.score_multiplier >= 5)
1238 // if (player_status.score_multiplier <= 4) {sprintf(str, _("Combo x%d"), player_status.score_multiplier);}
1239 if (player_status.score_multiplier == 5)
1240 sprintf(str, _("Good! x%d"), player_status.score_multiplier);
1241 else if (player_status.score_multiplier == 6)
1242 sprintf(str, _("Great! x%d"), player_status.score_multiplier);
1243 else if (player_status.score_multiplier == 7)
1244 sprintf(str, _("Awesome! x%d"), player_status.score_multiplier);
1245 else if (player_status.score_multiplier == 8)
1246 sprintf(str, _("Incredible! x%d"), player_status.score_multiplier);
1247 else if (player_status.score_multiplier == 9)
1248 sprintf(str, _("Godlike! ;-) x%d"), player_status.score_multiplier);
1250 sprintf(str, _("Unbelievable!! x%d"), player_status.score_multiplier);
1251 Sector::current()->add_floating_text(base, str);
1255 physic.set_velocity_y(5.2);
1257 physic.set_velocity_y(2);
1259 // Move the player a little bit above the badguy to avoid collision
1260 // between badguy and player directly after the bounce has happend
1261 base.y = badguy->base.y - base.height - 2;