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)))
494 if(fabs(vx)>SKID_XM && !skidding_timer.check())
496 skidding_timer.start(SKID_TIME);
497 SoundManager::get()->play_sound(IDToSound(SND_SKID));
498 // dust some partcles
499 Sector::current()->add_particles(
500 Vector(base.x + (dir == LEFT ? base.width : 0), base.y+base.height),
501 dir == LEFT ? 270+20 : 90-40, dir == LEFT ? 270+40 : 90-20,
502 Vector(2.8,-2.6), Vector(0,0.030), 3, Color(100,100,100), 3, 800);
512 // we get slower when not pressing any keys
514 if(fabs(vx) < WALK_SPEED) {
518 ax = WALK_ACCELERATION_X * 1.5;
520 ax = WALK_ACCELERATION_X * -1.5;
524 // if we're on ice slow down acceleration or deceleration
525 if (isice(base.x, base.y + base.height))
527 /* the acceleration/deceleration rate on ice is inversely proportional to
528 * the current velocity.
531 // increasing 1 will increase acceleration/deceleration rate
532 // decreasing 1 will decrease acceleration/deceleration rate
533 // must stay above zero, though
534 if (ax != 0) ax *= 1 / fabs(vx);
537 physic.set_velocity(vx, vy);
538 physic.set_acceleration(ax, ay);
542 Player::handle_vertical_input()
547 fall_mode = ON_GROUND;
548 last_ground_y = base.y;
550 if(base.y > last_ground_y)
552 else if(fall_mode == ON_GROUND)
557 if(input.jump == DOWN && can_jump && on_ground())
559 if(duck) { // only jump a little bit when in duck mode {
560 physic.set_velocity_y(3);
562 // jump higher if we are running
563 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
564 physic.set_velocity_y(5.8);
566 physic.set_velocity_y(5.2);
575 SoundManager::get()->play_sound(IDToSound(SND_JUMP));
577 SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
579 // Let go of jump key
580 else if(input.jump == UP)
582 if (!flapping && !duck && !falling_from_flap && !on_ground())
586 if (jumping && physic.get_velocity_y() > 0)
589 physic.set_velocity_y(0);
594 // Flapping, Marek's version
595 if (input.jump == DOWN && can_flap)
597 if (!flapping_timer.started())
599 flapping_timer.start(TUX_FLAPPING_TIME);
600 flapping_velocity = physic.get_velocity_x();
602 if (!flapping_timer.check())
605 falling_from_flap = true;
609 if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
612 if (flapping_velocity == 0) {cv = 0;}
613 else {cv = flapping_velocity*(sqrt(TUX_FLAPPING_TIME-(float)flapping_timer.get_gone()))/sqrt(TUX_FLAPPING_TIME);}
614 //Handle change of direction while flapping
615 if (((dir == LEFT) && (cv > 0)) || (dir == RIGHT) && (cv < 0)) {cv *= (-1);}
616 physic.set_velocity_x(cv);
617 physic.set_velocity_y((float)flapping_timer.get_gone()/850);
621 /* // Flapping, Ryan's version
622 if (input.jump == DOWN && can_flap)
624 if (!flapping_timer.started())
626 flapping_timer.start(TUX_FLAPPING_TIME);
628 if (!flapping_timer.check())
631 falling_from_flap = true;
635 if (flapping && flapping_timer.get_gone() <= TUX_FLAPPING_TIME
636 && physic.get_velocity_y() < 0)
638 float gravity = Sector::current()->gravity;
639 float xr = (fabsf(physic.get_velocity_x()) / MAX_RUN_XM);
641 // XXX: magic numbers. should be a percent of gravity
642 // gravity is (by default) -0.1f
643 physic.set_acceleration_y(.12 + .01f*xr);
646 // To slow down x-vel when flapping (not working)
647 if (fabsf(physic.get_velocity_x()) > MAX_WALK_XM)
649 if (physic.get_velocity_x() < 0)
650 physic.set_acceleration_x(1.0f);
651 else if (physic.get_velocity_x() > 0)
652 physic.set_acceleration_x(-1.0f);
659 physic.set_acceleration_y(0);
664 //(disabled by default, use cheat code "hover" to toggle on/off)
665 //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys
666 if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0)
668 physic.set_velocity_y(-1);
671 /* In case the player has pressed Down while in a certain range of air,
672 enable butt jump action */
673 if (input.down == DOWN && !butt_jump && !duck)
674 if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
677 /* When Down is not held anymore, disable butt jump */
678 if(butt_jump && input.down == UP)
682 if (butt_jump && on_ground() && size == BIG)
686 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y));
688 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32));
692 // Break bricks beneath Tux
693 if(Sector::current()->trybreakbrick(
694 Vector(base.x + 1, base.y + base.height), false)
695 || Sector::current()->trybreakbrick(
696 Vector(base.x + base.width - 1, base.y + base.height), false))
698 physic.set_velocity_y(2);
702 // Kill nearby badguys
703 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
704 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
705 i != gameobjects.end();
708 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
711 // don't kill when badguys are already dying or in a certain mode
712 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
713 badguy->mode != BadGuy::BOMB_EXPLODE)
715 if (fabsf(base.x - badguy->base.x) < 150 &&
716 fabsf(base.y - badguy->base.y) < 60 &&
717 (issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
718 issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
725 if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
726 issolid(base.x + 1, base.y + base.height + 64) ||
727 issolid(base.x + base.width - 1, base.y + base.height + 64))
730 && input.jump == DOWN
731 && input.old_jump == UP)
736 if(on_ground()) /* Make sure jumping is off. */
740 falling_from_flap = false;
741 if (flapping_timer.started()) {flapping_timer.stop();}
743 physic.set_acceleration_y(0); //for flapping
746 input.old_jump = input.jump;
750 Player::handle_input()
752 /* Handle horizontal movement: */
753 handle_horizontal_input();
757 if (on_ground() && input.jump == UP)
759 handle_vertical_input();
762 if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
764 if(Sector::current()->add_bullet(Vector(base.x, base.y + (base.height/2)),
765 physic.get_velocity_x(), dir))
766 shooting_timer.start(SHOOTING_TIME);
767 input.old_fire = DOWN;
770 /* tux animations: */
771 if(!frame_timer.check())
773 frame_timer.start(25);
774 if (input.right == UP && input.left == UP)
781 if ((input.fire == DOWN && (global_frame_counter % 2) == 0) ||
782 (global_frame_counter % 4) == 0)
783 frame_main = (frame_main + 1) % 4;
793 if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
798 // changing base size confuses collision otherwise
799 old_base = previous_base = base;
801 else if(input.down == UP && size == BIG && duck)
803 // try if we can really unduck
806 // when unducking in air we need some space to do so
807 if(on_ground() || !collision_object_map(base)) {
809 // changing base size confuses collision otherwise
810 old_base = previous_base = base;
812 // undo the ducking changes
820 Player::grow(bool animate)
830 growing_timer.start(GROWING_TIME);
832 old_base = previous_base = base;
836 Player::grabdistros()
841 Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
842 Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
843 Sector::current()->trygrabdistro(
844 Vector(base.x, base.y + base.height), NO_BOUNCE);
845 Sector::current()->trygrabdistro(
846 Vector(base.x+ 31, base.y + base.height), NO_BOUNCE);
850 Sector::current()->trygrabdistro(
851 Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
852 Sector::current()->trygrabdistro(
853 Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
858 /* Enough distros for a One-up? */
859 if (player_status.distros >= DISTROS_LIFEUP)
861 player_status.distros = player_status.distros - DISTROS_LIFEUP;
862 if(player_status.lives < MAX_LIVES)
863 ++player_status.lives;
864 /*We want to hear the sound even, if MAX_LIVES is reached*/
865 SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
870 Player::draw(DrawingContext& context)
872 TuxBodyParts* tux_body;
875 tux_body = small_tux;
876 else if (got_power == FIRE_POWER)
878 else if (got_power == ICE_POWER)
883 int layer = LAYER_OBJECTS - 1;
884 Vector pos = Vector(base.x, base.y);
886 /* Set Tux sprite action */
887 if (duck && size == BIG)
890 tux_body->set_action("duck-left");
892 tux_body->set_action("duck-right");
894 else if (skidding_timer.started())
897 tux_body->set_action("skid-left");
899 tux_body->set_action("skid-right");
901 else if (kick_timer.started())
904 tux_body->set_action("kick-left");
906 tux_body->set_action("kick-right");
908 else if (butt_jump && size == BIG)
911 tux_body->set_action("buttjump-left");
913 tux_body->set_action("buttjump-right");
915 else if (physic.get_velocity_y() != 0)
918 tux_body->set_action("jump-left");
920 tux_body->set_action("jump-right");
924 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
927 tux_body->set_action("stand-left");
929 tux_body->set_action("stand-right");
934 tux_body->set_action("walk-left");
936 tux_body->set_action("walk-right");
940 if(idle_timer.get_left() < 0)
945 tux_body->head->set_action("idle-left");
947 tux_body->head->set_action("idle-right");
949 tux_body->head->start_animation(1);
952 idle_timer.start(IDLE_TIME);
955 // Tux is holding something
956 if ((holding_something && physic.get_velocity_y() == 0) ||
957 shooting_timer.check())
962 tux_body->arms->set_action("duck+grab-left");
964 tux_body->arms->set_action("duck+grab-right");
969 tux_body->arms->set_action("grab-left");
971 tux_body->arms->set_action("grab-right");
976 if (dying == DYING_SQUISHED)
978 smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
980 else if(growing_timer.check())
985 context.draw_surface(growingtux_right[GROWING_FRAMES-1 -
986 ((growing_timer.get_gone() *
987 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
989 context.draw_surface(growingtux_left[GROWING_FRAMES-1 -
990 ((growing_timer.get_gone() *
991 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
996 context.draw_surface(growingtux_right[(growing_timer.get_gone() *
997 GROWING_FRAMES) / GROWING_TIME], pos, layer);
999 context.draw_surface(growingtux_left[(growing_timer.get_gone() *
1000 GROWING_FRAMES) / GROWING_TIME], pos, layer);
1003 else if (safe_timer.started() && global_frame_counter%2)
1006 tux_body->draw(context, pos, layer);
1008 // Draw blinking star overlay
1009 if (invincible_timer.started() &&
1010 (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3)
1013 if (size == SMALL || duck)
1014 smalltux_star->draw(context, pos, LAYER_OBJECTS + 2);
1016 bigtux_star->draw(context, pos, LAYER_OBJECTS + 2);
1020 context.draw_filled_rect(Vector(base.x, base.y),
1021 Vector(base.width, base.height), Color(75,75,75, 150), LAYER_OBJECTS+1);
1025 Player::collision(const MovingObject& other, int collision_type)
1028 (void) collision_type;
1029 // will be implemented later
1033 Player::collision(void* p_c_object, int c_object)
1035 BadGuy* pbad_c = NULL;
1036 Trampoline* ptramp_c = NULL;
1037 FlyingPlatform* pplatform_c = NULL;
1042 pbad_c = (BadGuy*) p_c_object;
1044 /* Hurt player if he touches a badguy */
1045 if (!pbad_c->dying && !dying &&
1046 !safe_timer.started() &&
1047 pbad_c->mode != BadGuy::HELD)
1049 if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN
1050 && !holding_something)
1052 holding_something = true;
1053 pbad_c->mode = BadGuy::HELD;
1056 else if (pbad_c->mode == BadGuy::FLAT)
1058 // Don't get hurt if we're kicking a flat badguy!
1060 else if (pbad_c->mode == BadGuy::KICK)
1062 /* Hurt if you get hit by kicked laptop: */
1063 if (!invincible_timer.started())
1068 pbad_c->kill_me(20);
1070 else if (pbad_c->frozen_timer.check() && (pbad_c->kind == BAD_MRBOMB
1071 || pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FISH
1072 || pbad_c->kind == BAD_SPIKY))
1073 pbad_c->kill_me(20);
1076 if (!invincible_timer.started())
1082 pbad_c->kill_me(25);
1085 player_status.score_multiplier++;
1090 ptramp_c = (Trampoline*) p_c_object;
1092 // Pick up trampoline
1093 if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something && on_ground())
1095 holding_something = true;
1096 ptramp_c->mode = Trampoline::M_HELD;
1097 ptramp_c->base.y -= 8;
1099 // Set down trampoline
1100 else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN)
1102 holding_something = false;
1103 ptramp_c->mode = Trampoline::M_NORMAL;
1104 ptramp_c->base.y += 8;
1105 ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y());
1108 // ptramp_c->base.x = base.x + base.width+1;
1110 // ptramp_c->base.x = base.x - base.width-1;
1113 // Don't let tux walk through trampoline
1114 else if (ptramp_c->mode != Trampoline::M_HELD && on_ground())
1116 if (physic.get_velocity_x() > 0) // RIGHT
1118 physic.set_velocity_x(0);
1119 base.x = ptramp_c->base.x - base.width;
1121 else if (physic.get_velocity_x() < 0) // LEFT
1123 physic.set_velocity_x(0);
1124 base.x = ptramp_c->base.x + ptramp_c->base.width;
1129 case CO_FLYING_PLATFORM:
1130 pplatform_c = (FlyingPlatform*) p_c_object;
1132 base.y = pplatform_c->base.y - base.height;
1133 physic.set_velocity_x(pplatform_c->get_vel_x());
1135 physic.enable_gravity(false);
1137 fall_mode = ON_GROUND;
1149 Player::kill(HurtMode mode)
1154 SoundManager::get()->play_sound(IDToSound(SND_HURT));
1156 physic.set_velocity_x(0);
1158 if (mode == SHRINK && size == BIG)
1160 if (got_power != NONE_POWER)
1162 safe_timer.start(TUX_SAFE_TIME);
1163 got_power = NONE_POWER;
1167 growing_timer.start(GROWING_TIME);
1168 safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
1176 physic.enable_gravity(true);
1177 physic.set_acceleration(0, 0);
1178 physic.set_velocity(0, 7);
1179 --player_status.lives;
1180 dying = DYING_SQUISHED;
1181 dying_timer.start(3000);
1185 /* Remove Tux's power ups */
1187 Player::remove_powerups()
1189 got_power = NONE_POWER;
1195 Player::move(const Vector& vector)
1199 old_base = previous_base = base;
1203 Player::check_bounds(Camera* camera)
1205 /* Keep tux in bounds: */
1207 { // Lock Tux to the size of the level, so that he doesn't fall of
1212 /* Keep in-bounds, vertically: */
1213 if (base.y > Sector::current()->solids->get_height() * 32)
1219 bool adjust = false;
1220 // can happen if back scrolling is disabled
1221 if(base.x < camera->get_translation().x) {
1222 base.x = camera->get_translation().x;
1225 if(base.x >= camera->get_translation().x + screen->w - base.width) {
1226 base.x = camera->get_translation().x + screen->w - base.width;
1232 if(collision_object_map(base)) {
1240 Player::bounce(BadGuy* badguy)
1242 //Make sure we stopped flapping
1244 falling_from_flap = false;
1246 if(player_status.score_multiplier >= 5)
1249 // if (player_status.score_multiplier <= 4) {sprintf(str, _("Combo x%d"), player_status.score_multiplier);}
1250 if (player_status.score_multiplier == 5)
1251 sprintf(str, _("Good! x%d"), player_status.score_multiplier);
1252 else if (player_status.score_multiplier == 6)
1253 sprintf(str, _("Great! x%d"), player_status.score_multiplier);
1254 else if (player_status.score_multiplier == 7)
1255 sprintf(str, _("Awesome! x%d"), player_status.score_multiplier);
1256 else if (player_status.score_multiplier == 8)
1257 sprintf(str, _("Incredible! x%d"), player_status.score_multiplier);
1258 else if (player_status.score_multiplier == 9)
1259 sprintf(str, _("Godlike! ;-) x%d"), player_status.score_multiplier);
1261 sprintf(str, _("Unbelievable!! x%d"), player_status.score_multiplier);
1262 Sector::current()->add_floating_text(base, str);
1266 physic.set_velocity_y(5.2);
1268 physic.set_velocity_y(2);
1270 // Move the player a little bit above the badguy to avoid collision
1271 // between badguy and player directly after the bounce has happend
1272 base.y = badguy->base.y - base.height - 2;