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;
173 // temporary to help player's choosing a flapping
174 int flapping_mode = MAREK_FLAP;
176 // Ricardo's flapping
182 player_input_init(&input);
184 invincible_timer.init(true);
185 skidding_timer.init(true);
186 safe_timer.init(true);
187 frame_timer.init(true);
188 kick_timer.init(true);
189 shooting_timer.init(true);
190 growing_timer.init(true);
191 idle_timer.init(true);
192 flapping_timer.init(true);
198 Player::key_event(SDLKey key, int state)
200 idle_timer.start(IDLE_TIME);
202 if(key == keymap.right)
207 else if(key == keymap.left)
212 else if(key == keymap.up)
216 /* Up key also opens activates stuff */
217 input.activate = state;
220 /** check for interactive objects */
221 for(Sector::InteractiveObjects::iterator i
222 = Sector::current()->interactive_objects.begin();
223 i != Sector::current()->interactive_objects.end(); ++i) {
224 if(rectcollision(base, (*i)->get_area())) {
225 (*i)->interaction(INTERACTION_ACTIVATE);
232 else if(key == keymap.down)
237 else if(key == keymap.power)
245 else if(key == keymap.jump)
257 Player::level_begin()
261 previous_base = old_base = base;
266 player_input_init(&input);
268 invincible_timer.init(true);
269 skidding_timer.init(true);
270 safe_timer.init(true);
271 frame_timer.init(true);
272 growing_timer.init(true);
273 idle_timer.init(true);
279 Player::action(float elapsed_time)
281 bool jumped_in_solid = false;
283 if(dying && !dying_timer.check()) {
288 if (input.fire == UP)
289 holding_something = false;
292 previous_base = base;
294 /* --- HANDLE TUX! --- */
295 if(dying == DYING_NOT)
298 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
300 if(dying == DYING_NOT)
302 base_type target = base;
304 collision_swept_object_map(&old_base, &base);
306 if ((!invincible_timer.started() && !safe_timer.started())
307 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
308 || isspike(base.x, base.y + base.height)
309 || isspike(base.x + base.width, base.y + base.height)))
314 // Don't accelerate Tux if he is running against a wall
315 if (target.x != base.x)
317 physic.set_velocity_x(0);
320 // special exception for cases where we're stuck under tiles after
321 // being ducked. In this case we drift out
322 if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
323 && collision_object_map(base))
325 base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1);
326 previous_base = old_base = base;
332 physic.enable_gravity(true);
336 physic.set_velocity_y(0);
337 jumped_in_solid = true;
345 if (physic.get_velocity_y() < 0)
347 base.y = (int)(((int)base.y / 32) * 32);
348 physic.set_velocity_y(0);
351 physic.enable_gravity(false);
352 /* Reset score multiplier (for multi-hits): */
353 if (!invincible_timer.started())
355 /*if(player_status.score_multiplier > 2)
358 sprintf(str, _("%d bad guys in a row!"), player_status.score_multiplier-1);
359 Sector::current()->add_floating_text(base, str);
361 player_status.score_multiplier = 1;
367 if (isbrick(base.x, base.y) ||
368 isfullbox(base.x, base.y))
370 Sector::current()->trygrabdistro(
371 Vector(base.x, base.y - 32), BOUNCE);
372 Sector::current()->trybumpbadguy(Vector(base.x, base.y - 64));
374 Sector::current()->trybreakbrick(
375 Vector(base.x, base.y), size == SMALL);
377 bumpbrick(base.x, base.y);
378 Sector::current()->tryemptybox(Vector(base.x, base.y), RIGHT);
381 if (isbrick(base.x+ 31, base.y) ||
382 isfullbox(base.x+ 31, base.y))
384 Sector::current()->trygrabdistro(
385 Vector(base.x+ 31, base.y - 32), BOUNCE);
386 Sector::current()->trybumpbadguy(Vector(base.x+ 31, base.y - 64));
389 Sector::current()->trybreakbrick(
390 Vector(base.x+ 31, base.y), size == SMALL);
392 bumpbrick(base.x+ 31, base.y);
393 Sector::current()->tryemptybox(Vector(base.x+ 31, base.y), LEFT);
405 /* Make sure jumping is off. */
412 /* ---- DONE HANDLING TUX! --- */
415 skidding_timer.check();
416 invincible_timer.check();
424 return ( issolid(base.x + base.width / 2, base.y + base.height) ||
425 issolid(base.x + 1, base.y + base.height) ||
426 issolid(base.x + base.width - 1, base.y + base.height));
430 Player::under_solid()
432 return ( issolid(base.x + base.width / 2, base.y) ||
433 issolid(base.x + 1, base.y) ||
434 issolid(base.x + base.width - 1, base.y) );
438 Player::tiles_on_air(int tiles)
440 for(int t = 0; t != tiles; t++)
442 if(issolid(base.x + base.width / 2, base.y + base.height + (tiles*32)) ||
443 issolid(base.x + 1, base.y + base.height + (tiles*32)) ||
444 issolid(base.x + base.width - 1, base.y + base.height + (tiles*32)))
451 Player::handle_horizontal_input()
453 float vx = physic.get_velocity_x();
454 float vy = physic.get_velocity_y();
455 float ax = physic.get_acceleration_x();
456 float ay = physic.get_acceleration_y();
459 if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
463 } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
469 if (input.fire == UP) {
470 ax = dirsign * WALK_ACCELERATION_X;
472 if(vx >= MAX_WALK_XM && dirsign > 0) {
475 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
480 ax = dirsign * RUN_ACCELERATION_X;
482 if(vx >= MAX_RUN_XM && dirsign > 0) {
485 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
491 // we can reach WALK_SPEED without any acceleration
492 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
493 vx = dirsign * WALK_SPEED;
496 // changing directions?
497 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0)))
500 if(fabs(vx)>SKID_XM && !skidding_timer.check())
502 skidding_timer.start(SKID_TIME);
503 SoundManager::get()->play_sound(IDToSound(SND_SKID));
504 // dust some partcles
505 Sector::current()->add_particles(
506 Vector(base.x + (dir == RIGHT ? base.width : 0), base.y+base.height),
507 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
508 Vector(2.8,-2.6), Vector(0,0.030), 3, Color(100,100,100), 3, 800,
519 // we get slower when not pressing any keys
521 if(fabs(vx) < WALK_SPEED) {
525 ax = WALK_ACCELERATION_X * 1.5;
527 ax = WALK_ACCELERATION_X * -1.5;
531 // if we're on ice slow down acceleration or deceleration
532 if (isice(base.x, base.y + base.height))
534 /* the acceleration/deceleration rate on ice is inversely proportional to
535 * the current velocity.
538 // increasing 1 will increase acceleration/deceleration rate
539 // decreasing 1 will decrease acceleration/deceleration rate
540 // must stay above zero, though
541 if (ax != 0) ax *= 1 / fabs(vx);
544 physic.set_velocity(vx, vy);
545 physic.set_acceleration(ax, ay);
549 Player::handle_vertical_input()
554 fall_mode = ON_GROUND;
555 last_ground_y = base.y;
557 if(base.y > last_ground_y)
559 else if(fall_mode == ON_GROUND)
564 if(input.jump == DOWN && can_jump && on_ground())
566 if(duck) { // only jump a little bit when in duck mode {
567 physic.set_velocity_y(3);
569 // jump higher if we are running
570 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
571 physic.set_velocity_y(5.8);
573 physic.set_velocity_y(5.2);
581 flaps_nb = 0; // Ricardo's flapping
583 SoundManager::get()->play_sound(IDToSound(SND_JUMP));
585 SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
587 // Let go of jump key
588 else if(input.jump == UP)
590 if (!flapping && !duck && !falling_from_flap && !on_ground())
594 if (jumping && physic.get_velocity_y() > 0)
597 physic.set_velocity_y(0);
601 // temporary to help player's choosing a flapping
602 if(flapping_mode == RICARDO_FLAP)
604 // Flapping, Ricardo's version
605 // similar to SM3 Fox
606 if(input.jump == DOWN && input.old_jump == UP && can_flap &&
609 physic.set_velocity_y(3.5);
610 physic.set_velocity_x(physic.get_velocity_x() * 0.35);
614 else if(flapping_mode == MAREK_FLAP)
616 // Flapping, Marek's version
617 if (input.jump == DOWN && can_flap)
619 if (!flapping_timer.started())
621 flapping_timer.start(TUX_FLAPPING_TIME);
622 flapping_velocity = physic.get_velocity_x();
624 if (!flapping_timer.check())
627 falling_from_flap = true;
631 if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
634 if (flapping_velocity == 0) {cv = 0;}
635 else {cv = flapping_velocity*(sqrt(TUX_FLAPPING_TIME-(float)flapping_timer.get_gone()))/sqrt(TUX_FLAPPING_TIME);}
636 //Handle change of direction while flapping
637 if (((dir == LEFT) && (cv > 0)) || (dir == RIGHT) && (cv < 0)) {cv *= (-1);}
638 physic.set_velocity_x(cv);
639 physic.set_velocity_y((float)flapping_timer.get_gone()/850);
643 else if(flapping_mode == RYAN_FLAP)
645 // Flapping, Ryan's version
646 if (input.jump == DOWN && can_flap)
648 if (!flapping_timer.started())
650 flapping_timer.start(TUX_FLAPPING_TIME);
652 if (!flapping_timer.check())
655 falling_from_flap = true;
659 if (flapping && flapping_timer.get_gone() <= TUX_FLAPPING_TIME
660 && physic.get_velocity_y() < 0)
662 float gravity = Sector::current()->gravity;
663 float xr = (fabsf(physic.get_velocity_x()) / MAX_RUN_XM);
665 // XXX: magic numbers. should be a percent of gravity
666 // gravity is (by default) -0.1f
667 physic.set_acceleration_y(.12 + .01f*xr);
670 // To slow down x-vel when flapping (not working)
671 if (fabsf(physic.get_velocity_x()) > MAX_WALK_XM)
673 if (physic.get_velocity_x() < 0)
674 physic.set_acceleration_x(1.0f);
675 else if (physic.get_velocity_x() > 0)
676 physic.set_acceleration_x(-1.0f);
683 physic.set_acceleration_y(0);
689 //(disabled by default, use cheat code "hover" to toggle on/off)
690 //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys
691 if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0)
693 physic.set_velocity_y(-1);
696 /* In case the player has pressed Down while in a certain range of air,
697 enable butt jump action */
698 if (input.down == DOWN && !butt_jump && !duck)
699 if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
702 /* When Down is not held anymore, disable butt jump */
703 if(butt_jump && input.down == UP)
707 if (butt_jump && on_ground() && size == BIG)
711 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y));
713 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32));
717 // Break bricks beneath Tux
718 if(Sector::current()->trybreakbrick(
719 Vector(base.x + 1, base.y + base.height), false)
720 || Sector::current()->trybreakbrick(
721 Vector(base.x + base.width - 1, base.y + base.height), false))
723 physic.set_velocity_y(2);
727 // Kill nearby badguys
728 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
729 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
730 i != gameobjects.end();
733 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
736 // don't kill when badguys are already dying or in a certain mode
737 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
738 badguy->mode != BadGuy::BOMB_EXPLODE)
740 if (fabsf(base.x - badguy->base.x) < 150 &&
741 fabsf(base.y - badguy->base.y) < 60 &&
742 (issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
743 issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
750 if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
751 issolid(base.x + 1, base.y + base.height + 64) ||
752 issolid(base.x + base.width - 1, base.y + base.height + 64))
755 && input.jump == DOWN
756 && input.old_jump == UP)
761 if(on_ground()) /* Make sure jumping is off. */
765 falling_from_flap = false;
766 if (flapping_timer.started()) {flapping_timer.stop();}
768 physic.set_acceleration_y(0); //for flapping
771 input.old_jump = input.jump;
775 Player::handle_input()
777 /* Handle horizontal movement: */
778 handle_horizontal_input();
782 if (on_ground() && input.jump == UP)
784 handle_vertical_input();
787 if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
789 if(Sector::current()->add_bullet(Vector(base.x, base.y + (base.height/2)),
790 physic.get_velocity_x(), dir))
791 shooting_timer.start(SHOOTING_TIME);
792 input.old_fire = DOWN;
795 /* tux animations: */
796 if(!frame_timer.check())
798 frame_timer.start(25);
799 if (input.right == UP && input.left == UP)
806 if ((input.fire == DOWN && (global_frame_counter % 2) == 0) ||
807 (global_frame_counter % 4) == 0)
808 frame_main = (frame_main + 1) % 4;
818 if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
823 // changing base size confuses collision otherwise
824 old_base = previous_base = base;
826 else if(input.down == UP && size == BIG && duck)
828 // try if we can really unduck
831 // when unducking in air we need some space to do so
832 if(on_ground() || !collision_object_map(base)) {
834 // changing base size confuses collision otherwise
835 old_base = previous_base = base;
837 // undo the ducking changes
845 Player::grow(bool animate)
855 growing_timer.start(GROWING_TIME);
857 old_base = previous_base = base;
861 Player::grabdistros()
866 Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
867 Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
868 Sector::current()->trygrabdistro(
869 Vector(base.x, base.y + base.height), NO_BOUNCE);
870 Sector::current()->trygrabdistro(
871 Vector(base.x+ 31, base.y + base.height), NO_BOUNCE);
875 Sector::current()->trygrabdistro(
876 Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
877 Sector::current()->trygrabdistro(
878 Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
883 /* Enough distros for a One-up? */
884 if (player_status.distros >= DISTROS_LIFEUP)
886 player_status.distros = player_status.distros - DISTROS_LIFEUP;
887 if(player_status.lives < MAX_LIVES)
888 ++player_status.lives;
889 /*We want to hear the sound even, if MAX_LIVES is reached*/
890 SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
895 Player::draw(DrawingContext& context)
897 TuxBodyParts* tux_body;
900 tux_body = small_tux;
901 else if (got_power == FIRE_POWER)
903 else if (got_power == ICE_POWER)
908 int layer = LAYER_OBJECTS - 1;
909 Vector pos = Vector(base.x, base.y);
911 /* Set Tux sprite action */
912 if (duck && size == BIG)
915 tux_body->set_action("duck-left");
917 tux_body->set_action("duck-right");
919 else if (skidding_timer.started())
922 tux_body->set_action("skid-left");
924 tux_body->set_action("skid-right");
926 else if (kick_timer.started())
929 tux_body->set_action("kick-left");
931 tux_body->set_action("kick-right");
933 else if (butt_jump && size == BIG)
936 tux_body->set_action("buttjump-left");
938 tux_body->set_action("buttjump-right");
940 else if (physic.get_velocity_y() != 0)
943 tux_body->set_action("jump-left");
945 tux_body->set_action("jump-right");
949 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
952 tux_body->set_action("stand-left");
954 tux_body->set_action("stand-right");
959 tux_body->set_action("walk-left");
961 tux_body->set_action("walk-right");
965 if(idle_timer.get_left() < 0)
970 tux_body->head->set_action("idle-left");
972 tux_body->head->set_action("idle-right");
974 tux_body->head->start_animation(1);
977 idle_timer.start(IDLE_TIME);
980 // Tux is holding something
981 if ((holding_something && physic.get_velocity_y() == 0) ||
982 shooting_timer.check())
987 tux_body->arms->set_action("duck+grab-left");
989 tux_body->arms->set_action("duck+grab-right");
994 tux_body->arms->set_action("grab-left");
996 tux_body->arms->set_action("grab-right");
1001 if (dying == DYING_SQUISHED)
1003 smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
1005 else if(growing_timer.check())
1010 context.draw_surface(growingtux_right[GROWING_FRAMES-1 -
1011 ((growing_timer.get_gone() *
1012 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
1014 context.draw_surface(growingtux_left[GROWING_FRAMES-1 -
1015 ((growing_timer.get_gone() *
1016 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
1021 context.draw_surface(growingtux_right[(growing_timer.get_gone() *
1022 GROWING_FRAMES) / GROWING_TIME], pos, layer);
1024 context.draw_surface(growingtux_left[(growing_timer.get_gone() *
1025 GROWING_FRAMES) / GROWING_TIME], pos, layer);
1028 else if (safe_timer.started() && global_frame_counter%2)
1031 tux_body->draw(context, pos, layer);
1033 // Draw blinking star overlay
1034 if (invincible_timer.started() &&
1035 (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3)
1038 if (size == SMALL || duck)
1039 smalltux_star->draw(context, pos, LAYER_OBJECTS + 2);
1041 bigtux_star->draw(context, pos, LAYER_OBJECTS + 2);
1045 context.draw_filled_rect(Vector(base.x, base.y),
1046 Vector(base.width, base.height), Color(75,75,75, 150), LAYER_OBJECTS+1);
1050 Player::collision(const MovingObject& other, int collision_type)
1053 (void) collision_type;
1054 // will be implemented later
1058 Player::collision(void* p_c_object, int c_object)
1060 BadGuy* pbad_c = NULL;
1061 Trampoline* ptramp_c = NULL;
1062 FlyingPlatform* pplatform_c = NULL;
1067 pbad_c = (BadGuy*) p_c_object;
1069 /* Hurt player if he touches a badguy */
1070 if (!pbad_c->dying && !dying &&
1071 !safe_timer.started() &&
1072 pbad_c->mode != BadGuy::HELD)
1074 if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN
1075 && !holding_something)
1077 holding_something = true;
1078 pbad_c->mode = BadGuy::HELD;
1081 else if (pbad_c->mode == BadGuy::FLAT)
1083 // Don't get hurt if we're kicking a flat badguy!
1085 else if (pbad_c->mode == BadGuy::KICK)
1087 /* Hurt if you get hit by kicked laptop: */
1088 if (!invincible_timer.started())
1093 pbad_c->kill_me(20);
1095 else if (pbad_c->frozen_timer.check() && (pbad_c->kind == BAD_MRBOMB
1096 || pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FISH
1097 || pbad_c->kind == BAD_SPIKY))
1098 pbad_c->kill_me(20);
1101 if (!invincible_timer.started())
1107 pbad_c->kill_me(25);
1110 player_status.score_multiplier++;
1115 ptramp_c = (Trampoline*) p_c_object;
1117 // Pick up trampoline
1118 if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something && on_ground())
1120 holding_something = true;
1121 ptramp_c->mode = Trampoline::M_HELD;
1122 ptramp_c->base.y -= 8;
1124 // Set down trampoline
1125 else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN)
1127 holding_something = false;
1128 ptramp_c->mode = Trampoline::M_NORMAL;
1129 ptramp_c->base.y += 8;
1130 ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y());
1133 // ptramp_c->base.x = base.x + base.width+1;
1135 // ptramp_c->base.x = base.x - base.width-1;
1138 // Don't let tux walk through trampoline
1139 else if (ptramp_c->mode != Trampoline::M_HELD && on_ground())
1141 if (physic.get_velocity_x() > 0) // RIGHT
1143 physic.set_velocity_x(0);
1144 base.x = ptramp_c->base.x - base.width;
1146 else if (physic.get_velocity_x() < 0) // LEFT
1148 physic.set_velocity_x(0);
1149 base.x = ptramp_c->base.x + ptramp_c->base.width;
1154 case CO_FLYING_PLATFORM:
1155 pplatform_c = (FlyingPlatform*) p_c_object;
1157 base.y = pplatform_c->base.y - base.height;
1158 physic.set_velocity_x(pplatform_c->get_vel_x());
1160 physic.enable_gravity(false);
1162 fall_mode = ON_GROUND;
1174 Player::kill(HurtMode mode)
1179 SoundManager::get()->play_sound(IDToSound(SND_HURT));
1181 physic.set_velocity_x(0);
1183 if (mode == SHRINK && size == BIG)
1185 if (got_power != NONE_POWER)
1187 safe_timer.start(TUX_SAFE_TIME);
1188 got_power = NONE_POWER;
1192 growing_timer.start(GROWING_TIME);
1193 safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
1201 physic.enable_gravity(true);
1202 physic.set_acceleration(0, 0);
1203 physic.set_velocity(0, 7);
1204 --player_status.lives;
1205 dying = DYING_SQUISHED;
1206 dying_timer.start(3000);
1210 /* Remove Tux's power ups */
1212 Player::remove_powerups()
1214 got_power = NONE_POWER;
1220 Player::move(const Vector& vector)
1224 old_base = previous_base = base;
1228 Player::check_bounds(Camera* camera)
1230 /* Keep tux in bounds: */
1232 { // Lock Tux to the size of the level, so that he doesn't fall of
1237 /* Keep in-bounds, vertically: */
1238 if (base.y > Sector::current()->solids->get_height() * 32)
1244 bool adjust = false;
1245 // can happen if back scrolling is disabled
1246 if(base.x < camera->get_translation().x) {
1247 base.x = camera->get_translation().x;
1250 if(base.x >= camera->get_translation().x + screen->w - base.width) {
1251 base.x = camera->get_translation().x + screen->w - base.width;
1257 if(collision_object_map(base)) {
1265 Player::bounce(BadGuy* badguy)
1267 //Make sure we stopped flapping
1269 falling_from_flap = false;
1271 if(player_status.score_multiplier >= 5)
1274 // if (player_status.score_multiplier <= 4) {sprintf(str, _("Combo x%d"), player_status.score_multiplier);}
1275 if (player_status.score_multiplier == 5)
1276 sprintf(str, _("Good! x%d"), player_status.score_multiplier);
1277 else if (player_status.score_multiplier == 6)
1278 sprintf(str, _("Great! x%d"), player_status.score_multiplier);
1279 else if (player_status.score_multiplier == 7)
1280 sprintf(str, _("Awesome! x%d"), player_status.score_multiplier);
1281 else if (player_status.score_multiplier == 8)
1282 sprintf(str, _("Incredible! x%d"), player_status.score_multiplier);
1283 else if (player_status.score_multiplier == 9)
1284 sprintf(str, _("Godlike! ;-) x%d"), player_status.score_multiplier);
1286 sprintf(str, _("Unbelievable!! x%d"), player_status.score_multiplier);
1287 Sector::current()->add_floating_text(base, str);
1291 physic.set_velocity_y(5.2);
1293 physic.set_velocity_y(2);
1295 // Move the player a little bit above the badguy to avoid collision
1296 // between badguy and player directly after the bounce has happend
1297 base.y = badguy->base.y - base.height - 2;