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;
174 player_input_init(&input);
176 invincible_timer.init(true);
177 skidding_timer.init(true);
178 safe_timer.init(true);
179 frame_timer.init(true);
180 kick_timer.init(true);
181 shooting_timer.init(true);
182 growing_timer.init(true);
183 idle_timer.init(true);
184 flapping_timer.init(true);
190 Player::key_event(SDLKey key, int state)
192 idle_timer.start(IDLE_TIME);
194 if(key == keymap.right)
199 else if(key == keymap.left)
204 else if(key == keymap.up)
208 /* Up key also opens activates stuff */
209 input.activate = state;
212 /** check for interactive objects */
213 for(Sector::InteractiveObjects::iterator i
214 = Sector::current()->interactive_objects.begin();
215 i != Sector::current()->interactive_objects.end(); ++i) {
216 if(rectcollision(base, (*i)->get_area())) {
217 (*i)->interaction(INTERACTION_ACTIVATE);
224 else if(key == keymap.down)
229 else if(key == keymap.power)
237 else if(key == keymap.jump)
249 Player::level_begin()
253 previous_base = old_base = base;
258 player_input_init(&input);
260 invincible_timer.init(true);
261 skidding_timer.init(true);
262 safe_timer.init(true);
263 frame_timer.init(true);
264 growing_timer.init(true);
265 idle_timer.init(true);
271 Player::action(float elapsed_time)
273 bool jumped_in_solid = false;
275 if(dying && !dying_timer.check()) {
280 if (input.fire == UP)
281 holding_something = false;
284 previous_base = base;
286 /* --- HANDLE TUX! --- */
287 if(dying == DYING_NOT)
290 physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
292 if(dying == DYING_NOT)
294 base_type target = base;
296 collision_swept_object_map(&old_base, &base);
298 if ((!invincible_timer.started() && !safe_timer.started())
299 && (isspike(base.x, base.y) || isspike(base.x + base.width, base.y)
300 || isspike(base.x, base.y + base.height)
301 || isspike(base.x + base.width, base.y + base.height)))
306 // Don't accelerate Tux if he is running against a wall
307 if (target.x != base.x)
309 physic.set_velocity_x(0);
312 // special exception for cases where we're stuck under tiles after
313 // being ducked. In this case we drift out
314 if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
315 && collision_object_map(base))
317 base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1);
318 previous_base = old_base = base;
324 physic.enable_gravity(true);
328 physic.set_velocity_y(0);
329 jumped_in_solid = true;
337 if (physic.get_velocity_y() < 0)
339 base.y = (int)(((int)base.y / 32) * 32);
340 physic.set_velocity_y(0);
343 physic.enable_gravity(false);
344 /* Reset score multiplier (for multi-hits): */
345 if (!invincible_timer.started())
347 /*if(player_status.score_multiplier > 2)
350 sprintf(str, _("%d bad guys in a row!"), player_status.score_multiplier-1);
351 Sector::current()->add_floating_text(base, str);
353 player_status.score_multiplier = 1;
359 if (isbrick(base.x, base.y) ||
360 isfullbox(base.x, base.y))
362 Sector::current()->trygrabdistro(
363 Vector(base.x, base.y - 32), BOUNCE);
364 Sector::current()->trybumpbadguy(Vector(base.x, base.y - 64));
366 Sector::current()->trybreakbrick(
367 Vector(base.x, base.y), size == SMALL);
369 bumpbrick(base.x, base.y);
370 Sector::current()->tryemptybox(Vector(base.x, base.y), RIGHT);
373 if (isbrick(base.x+ 31, base.y) ||
374 isfullbox(base.x+ 31, base.y))
376 Sector::current()->trygrabdistro(
377 Vector(base.x+ 31, base.y - 32), BOUNCE);
378 Sector::current()->trybumpbadguy(Vector(base.x+ 31, base.y - 64));
381 Sector::current()->trybreakbrick(
382 Vector(base.x+ 31, base.y), size == SMALL);
384 bumpbrick(base.x+ 31, base.y);
385 Sector::current()->tryemptybox(Vector(base.x+ 31, base.y), LEFT);
397 /* Make sure jumping is off. */
404 /* ---- DONE HANDLING TUX! --- */
407 skidding_timer.check();
408 invincible_timer.check();
416 return ( issolid(base.x + base.width / 2, base.y + base.height) ||
417 issolid(base.x + 1, base.y + base.height) ||
418 issolid(base.x + base.width - 1, base.y + base.height));
422 Player::under_solid()
424 return ( issolid(base.x + base.width / 2, base.y) ||
425 issolid(base.x + 1, base.y) ||
426 issolid(base.x + base.width - 1, base.y) );
430 Player::tiles_on_air(int tiles)
432 for(int t = 0; t != tiles; t++)
434 if(issolid(base.x + base.width / 2, base.y + base.height + (tiles*32)) ||
435 issolid(base.x + 1, base.y + base.height + (tiles*32)) ||
436 issolid(base.x + base.width - 1, base.y + base.height + (tiles*32)))
443 Player::handle_horizontal_input()
445 float vx = physic.get_velocity_x();
446 float vy = physic.get_velocity_y();
447 float ax = physic.get_acceleration_x();
448 float ay = physic.get_acceleration_y();
451 if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
455 } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
461 if (input.fire == UP) {
462 ax = dirsign * WALK_ACCELERATION_X;
464 if(vx >= MAX_WALK_XM && dirsign > 0) {
467 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
472 ax = dirsign * RUN_ACCELERATION_X;
474 if(vx >= MAX_RUN_XM && dirsign > 0) {
477 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
483 // we can reach WALK_SPEED without any acceleration
484 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
485 vx = dirsign * WALK_SPEED;
488 // changing directions?
489 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
490 if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
491 skidding_timer.start(SKID_TIME);
492 SoundManager::get()->play_sound(IDToSound(SND_SKID));
499 // we get slower when not pressing any keys
501 if(fabs(vx) < WALK_SPEED) {
505 ax = WALK_ACCELERATION_X * 1.5;
507 ax = WALK_ACCELERATION_X * -1.5;
511 // if we're on ice slow down acceleration or deceleration
512 if (isice(base.x, base.y + base.height))
514 /* the acceleration/deceleration rate on ice is inversely proportional to
515 * the current velocity.
518 // increasing 1 will increase acceleration/deceleration rate
519 // decreasing 1 will decrease acceleration/deceleration rate
520 // must stay above zero, though
521 if (ax != 0) ax *= 1 / fabs(vx);
524 physic.set_velocity(vx, vy);
525 physic.set_acceleration(ax, ay);
529 Player::handle_vertical_input()
534 fall_mode = ON_GROUND;
535 last_ground_y = base.y;
537 if(base.y > last_ground_y)
539 else if(fall_mode == ON_GROUND)
544 if(input.jump == DOWN && can_jump && on_ground())
546 if(duck) { // only jump a little bit when in duck mode {
547 physic.set_velocity_y(3);
549 // jump higher if we are running
550 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
551 physic.set_velocity_y(5.8);
553 physic.set_velocity_y(5.2);
562 SoundManager::get()->play_sound(IDToSound(SND_JUMP));
564 SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
566 // Let go of jump key
567 else if(input.jump == UP)
569 if (!flapping && !duck && !falling_from_flap && !on_ground())
573 if (jumping && physic.get_velocity_y() > 0)
576 physic.set_velocity_y(0);
581 // Flapping, Marek's version
582 if (input.jump == DOWN && can_flap)
584 if (!flapping_timer.started())
586 flapping_timer.start(TUX_FLAPPING_TIME);
588 if (!flapping_timer.check())
591 falling_from_flap = true;
595 float iv = physic.get_velocity_x(); //flapping speed depends on initial velocity
596 //float fv = 1.2; //fixed velocity that is reached when flapping is done
597 float cv = 0; //current velocity
598 //if (iv < 0) {fv *= (-1);} //make fv negative or positive depending on direction of iv
599 if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
601 //TODO: Values okay when running, but that's pure coincidence; they don't depend on iv anymore.
602 if (iv == 0) {cv = 0;}
603 //else {cv = (iv-((iv-fv)*(float)flapping_timer.get_gone()/TUX_FLAPPING_TIME));}
604 else {cv = (sqrt(1000-(float)flapping_timer.get_gone()))/10;}
605 //Handle change of direction while flapping
606 if (((dir == LEFT) && (cv > 0)) || (dir == RIGHT) && (cv < 0)) {cv *= (-1);}
607 //std::cout << cv << std::endl;
608 physic.set_velocity_x(cv);
609 physic.set_velocity_y((float)flapping_timer.get_gone()/800);
613 /* // Flapping, Ryan's version
614 if (input.jump == DOWN && can_flap)
616 if (!flapping_timer.started())
618 flapping_timer.start(TUX_FLAPPING_TIME);
620 if (!flapping_timer.check())
623 falling_from_flap = true;
627 if (flapping && flapping_timer.get_gone() <= TUX_FLAPPING_TIME
628 && physic.get_velocity_y() < 0)
630 float gravity = Sector::current()->gravity;
631 float xr = (fabsf(physic.get_velocity_x()) / MAX_RUN_XM);
633 // XXX: magic numbers. should be a percent of gravity
634 // gravity is (by default) -0.1f
635 physic.set_acceleration_y(.12 + .01f*xr);
638 // To slow down x-vel when flapping (not working)
639 if (fabsf(physic.get_velocity_x()) > MAX_WALK_XM)
641 if (physic.get_velocity_x() < 0)
642 physic.set_acceleration_x(1.0f);
643 else if (physic.get_velocity_x() > 0)
644 physic.set_acceleration_x(-1.0f);
651 physic.set_acceleration_y(0);
656 //(disabled by default, use cheat code "hover" to toggle on/off)
657 //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys
658 if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0)
660 physic.set_velocity_y(-1);
663 /* In case the player has pressed Down while in a certain range of air,
664 enable butt jump action */
665 if (input.down == DOWN && !butt_jump && !duck)
666 if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
669 /* When Down is not held anymore, disable butt jump */
670 if(butt_jump && input.down == UP)
674 if (butt_jump && on_ground() && size == BIG)
678 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y));
680 Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32));
684 // Break bricks beneath Tux
685 if(Sector::current()->trybreakbrick(
686 Vector(base.x + 1, base.y + base.height), false)
687 || Sector::current()->trybreakbrick(
688 Vector(base.x + base.width - 1, base.y + base.height), false))
690 physic.set_velocity_y(2);
694 // Kill nearby badguys
695 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
696 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
697 i != gameobjects.end();
700 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
703 // don't kill when badguys are already dying or in a certain mode
704 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
705 badguy->mode != BadGuy::BOMB_EXPLODE)
707 if (fabsf(base.x - badguy->base.x) < 150 &&
708 fabsf(base.y - badguy->base.y) < 60 &&
709 (issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
710 issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
717 if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
718 issolid(base.x + 1, base.y + base.height + 64) ||
719 issolid(base.x + base.width - 1, base.y + base.height + 64))
722 && input.jump == DOWN
723 && input.old_jump == UP)
728 if(on_ground()) /* Make sure jumping is off. */
732 falling_from_flap = false;
733 if (flapping_timer.started()) {flapping_timer.stop();}
735 physic.set_acceleration_y(0); //for flapping
738 input.old_jump = input.jump;
742 Player::handle_input()
744 /* Handle horizontal movement: */
745 handle_horizontal_input();
749 if (on_ground() && input.jump == UP)
751 handle_vertical_input();
754 if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
756 if(Sector::current()->add_bullet(Vector(base.x, base.y + (base.height/2)),
757 physic.get_velocity_x(), dir))
758 shooting_timer.start(SHOOTING_TIME);
759 input.old_fire = DOWN;
762 /* tux animations: */
763 if(!frame_timer.check())
765 frame_timer.start(25);
766 if (input.right == UP && input.left == UP)
773 if ((input.fire == DOWN && (global_frame_counter % 2) == 0) ||
774 (global_frame_counter % 4) == 0)
775 frame_main = (frame_main + 1) % 4;
785 if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
790 // changing base size confuses collision otherwise
791 old_base = previous_base = base;
793 else if(input.down == UP && size == BIG && duck)
795 // try if we can really unduck
798 // when unducking in air we need some space to do so
799 if(on_ground() || !collision_object_map(base)) {
801 // changing base size confuses collision otherwise
802 old_base = previous_base = base;
804 // undo the ducking changes
812 Player::grow(bool animate)
822 growing_timer.start(GROWING_TIME);
824 old_base = previous_base = base;
828 Player::grabdistros()
833 Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
834 Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
835 Sector::current()->trygrabdistro(
836 Vector(base.x, base.y + base.height), NO_BOUNCE);
837 Sector::current()->trygrabdistro(
838 Vector(base.x+ 31, base.y + base.height), NO_BOUNCE);
842 Sector::current()->trygrabdistro(
843 Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
844 Sector::current()->trygrabdistro(
845 Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
850 /* Enough distros for a One-up? */
851 if (player_status.distros >= DISTROS_LIFEUP)
853 player_status.distros = player_status.distros - DISTROS_LIFEUP;
854 if(player_status.lives < MAX_LIVES)
855 ++player_status.lives;
856 /*We want to hear the sound even, if MAX_LIVES is reached*/
857 SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
862 Player::draw(DrawingContext& context)
864 TuxBodyParts* tux_body;
867 tux_body = small_tux;
868 else if (got_power == FIRE_POWER)
870 else if (got_power == ICE_POWER)
875 int layer = LAYER_OBJECTS - 1;
876 Vector pos = Vector(base.x, base.y);
878 /* Set Tux sprite action */
879 if (duck && size == BIG)
882 tux_body->set_action("duck-left");
884 tux_body->set_action("duck-right");
886 else if (skidding_timer.started())
889 tux_body->set_action("skid-left");
891 tux_body->set_action("skid-right");
893 else if (kick_timer.started())
896 tux_body->set_action("kick-left");
898 tux_body->set_action("kick-right");
903 tux_body->set_action("buttjump-left");
905 tux_body->set_action("buttjump-right");
907 else if (physic.get_velocity_y() != 0)
910 tux_body->set_action("jump-left");
912 tux_body->set_action("jump-right");
916 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
919 tux_body->set_action("stand-left");
921 tux_body->set_action("stand-right");
926 tux_body->set_action("walk-left");
928 tux_body->set_action("walk-right");
932 if(idle_timer.get_left() < 0)
937 tux_body->head->set_action("idle-left");
939 tux_body->head->set_action("idle-right");
941 tux_body->head->start_animation(1);
944 idle_timer.start(IDLE_TIME);
947 // Tux is holding something
948 if ((holding_something && physic.get_velocity_y() == 0) ||
949 shooting_timer.check())
954 tux_body->arms->set_action("duck+grab-left");
956 tux_body->arms->set_action("duck+grab-right");
961 tux_body->arms->set_action("grab-left");
963 tux_body->arms->set_action("grab-right");
968 if (dying == DYING_SQUISHED)
970 smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
972 else if(growing_timer.check())
977 context.draw_surface(growingtux_right[GROWING_FRAMES-1 -
978 ((growing_timer.get_gone() *
979 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
981 context.draw_surface(growingtux_left[GROWING_FRAMES-1 -
982 ((growing_timer.get_gone() *
983 GROWING_FRAMES) / GROWING_TIME)], pos, layer);
988 context.draw_surface(growingtux_right[(growing_timer.get_gone() *
989 GROWING_FRAMES) / GROWING_TIME], pos, layer);
991 context.draw_surface(growingtux_left[(growing_timer.get_gone() *
992 GROWING_FRAMES) / GROWING_TIME], pos, layer);
995 else if (safe_timer.started() && global_frame_counter%2)
998 tux_body->draw(context, pos, layer, dir == LEFT ? HORIZONTAL_FLIP : NONE_EFFECT);
1000 // Draw blinking star overlay
1001 if (invincible_timer.started() &&
1002 (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3)
1005 if (size == SMALL || duck)
1006 smalltux_star->draw(context, pos, LAYER_OBJECTS + 2);
1008 bigtux_star->draw(context, pos, LAYER_OBJECTS + 2);
1012 context.draw_filled_rect(Vector(base.x, base.y),
1013 Vector(base.width, base.height), Color(75,75,75, 150), LAYER_OBJECTS+1);
1017 Player::collision(const MovingObject& other, int collision_type)
1020 (void) collision_type;
1021 // will be implemented later
1025 Player::collision(void* p_c_object, int c_object)
1027 BadGuy* pbad_c = NULL;
1028 Trampoline* ptramp_c = NULL;
1029 FlyingPlatform* pplatform_c = NULL;
1034 pbad_c = (BadGuy*) p_c_object;
1036 /* Hurt player if he touches a badguy */
1037 if (!pbad_c->dying && !dying &&
1038 !safe_timer.started() &&
1039 pbad_c->mode != BadGuy::HELD)
1041 if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN
1042 && !holding_something)
1044 holding_something = true;
1045 pbad_c->mode = BadGuy::HELD;
1048 else if (pbad_c->mode == BadGuy::FLAT)
1050 // Don't get hurt if we're kicking a flat badguy!
1052 else if (pbad_c->mode == BadGuy::KICK)
1054 /* Hurt if you get hit by kicked laptop: */
1055 if (!invincible_timer.started())
1060 pbad_c->kill_me(20);
1062 else if (pbad_c->frozen_timer.check() && (pbad_c->kind == BAD_MRBOMB
1063 || pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FISH
1064 || pbad_c->kind == BAD_SPIKY))
1065 pbad_c->kill_me(20);
1068 if (!invincible_timer.started())
1074 pbad_c->kill_me(25);
1077 player_status.score_multiplier++;
1082 ptramp_c = (Trampoline*) p_c_object;
1084 // Pick up trampoline
1085 if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something && on_ground())
1087 holding_something = true;
1088 ptramp_c->mode = Trampoline::M_HELD;
1089 ptramp_c->base.y -= 8;
1091 // Set down trampoline
1092 else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN)
1094 holding_something = false;
1095 ptramp_c->mode = Trampoline::M_NORMAL;
1096 ptramp_c->base.y += 8;
1097 ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y());
1100 // ptramp_c->base.x = base.x + base.width+1;
1102 // ptramp_c->base.x = base.x - base.width-1;
1105 // Don't let tux walk through trampoline
1106 else if (ptramp_c->mode != Trampoline::M_HELD && on_ground())
1108 if (physic.get_velocity_x() > 0) // RIGHT
1110 physic.set_velocity_x(0);
1111 base.x = ptramp_c->base.x - base.width;
1113 else if (physic.get_velocity_x() < 0) // LEFT
1115 physic.set_velocity_x(0);
1116 base.x = ptramp_c->base.x + ptramp_c->base.width;
1121 case CO_FLYING_PLATFORM:
1122 pplatform_c = (FlyingPlatform*) p_c_object;
1124 base.y = pplatform_c->base.y - base.height;
1125 physic.set_velocity_x(pplatform_c->get_vel_x());
1127 physic.enable_gravity(false);
1129 fall_mode = ON_GROUND;
1141 Player::kill(HurtMode mode)
1146 SoundManager::get()->play_sound(IDToSound(SND_HURT));
1148 physic.set_velocity_x(0);
1150 if (mode == SHRINK && size == BIG)
1152 if (got_power != NONE_POWER)
1154 safe_timer.start(TUX_SAFE_TIME);
1155 got_power = NONE_POWER;
1159 growing_timer.start(GROWING_TIME);
1160 safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
1168 physic.enable_gravity(true);
1169 physic.set_acceleration(0, 0);
1170 physic.set_velocity(0, 7);
1171 --player_status.lives;
1172 dying = DYING_SQUISHED;
1173 dying_timer.start(3000);
1177 /* Remove Tux's power ups */
1179 Player::remove_powerups()
1181 got_power = NONE_POWER;
1187 Player::move(const Vector& vector)
1191 old_base = previous_base = base;
1195 Player::check_bounds(Camera* camera)
1197 /* Keep tux in bounds: */
1199 { // Lock Tux to the size of the level, so that he doesn't fall of
1204 /* Keep in-bounds, vertically: */
1205 if (base.y > Sector::current()->solids->get_height() * 32)
1211 bool adjust = false;
1212 // can happen if back scrolling is disabled
1213 if(base.x < camera->get_translation().x) {
1214 base.x = camera->get_translation().x;
1217 if(base.x >= camera->get_translation().x + screen->w - base.width) {
1218 base.x = camera->get_translation().x + screen->w - base.width;
1224 if(collision_object_map(base)) {
1232 Player::bounce(BadGuy* badguy)
1234 //Make sure we stopped flapping
1236 falling_from_flap = false;
1238 if(player_status.score_multiplier >= 5)
1241 // if (player_status.score_multiplier <= 4) {sprintf(str, _("Combo x%d"), player_status.score_multiplier);}
1242 if (player_status.score_multiplier == 5)
1243 sprintf(str, _("Good! x%d"), player_status.score_multiplier);
1244 else if (player_status.score_multiplier == 6)
1245 sprintf(str, _("Great! x%d"), player_status.score_multiplier);
1246 else if (player_status.score_multiplier == 7)
1247 sprintf(str, _("Awesome! x%d"), player_status.score_multiplier);
1248 else if (player_status.score_multiplier == 8)
1249 sprintf(str, _("Incredible! x%d"), player_status.score_multiplier);
1250 else if (player_status.score_multiplier == 9)
1251 sprintf(str, _("Godlike! ;-) x%d"), player_status.score_multiplier);
1253 sprintf(str, _("Unbelievable!! x%d"), player_status.score_multiplier);
1254 Sector::current()->add_floating_text(base, str);
1258 physic.set_velocity_y(5.2);
1260 physic.set_velocity_y(2);
1262 // Move the player a little bit above the badguy to avoid collision
1263 // between badguy and player directly after the bounce has happend
1264 base.y = badguy->base.y - base.height - 2;