4 // Copyright (C) 2006 Matthias Braun <matze@braunis.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.
26 #include "gettext.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "audio/sound_manager.hpp"
31 #include "sprite/sprite.hpp"
33 #include "resources.hpp"
34 #include "statistics.hpp"
35 #include "game_session.hpp"
36 #include "object/tilemap.hpp"
37 #include "object/camera.hpp"
38 #include "object/particles.hpp"
39 #include "object/portable.hpp"
40 #include "object/bullet.hpp"
41 #include "trigger/trigger_base.hpp"
42 #include "control/joystickkeyboardcontroller.hpp"
43 #include "scripting/squirrel_util.hpp"
45 #include "platform.hpp"
46 #include "badguy/badguy.hpp"
47 #include "player_status.hpp"
49 #include "falling_coin.hpp"
50 #include "random_generator.hpp"
51 #include "object/sprite_particle.hpp"
53 static const int TILES_FOR_BUTTJUMP = 3;
54 static const float SHOOTING_TIME = .150;
55 /// time before idle animation starts
56 static const float IDLE_TIME = 2.5;
58 static const float WALK_ACCELERATION_X = 300;
59 static const float RUN_ACCELERATION_X = 400;
60 static const float SKID_XM = 200;
61 static const float SKID_TIME = .3;
62 static const float MAX_WALK_XM = 230;
63 static const float MAX_RUN_XM = 320;
64 static const float WALK_SPEED = 100;
66 static const float KICK_TIME = .3;
67 static const float CHEER_TIME = 1;
69 static const float UNDUCK_HURT_TIME = 0.25; /**< if Tux cannot unduck for this long, he will get hurt */
72 Surface* growingtux_left[GROWING_FRAMES];
73 Surface* growingtux_right[GROWING_FRAMES];
75 Surface* tux_life = 0;
77 TuxBodyParts* small_tux = 0;
78 TuxBodyParts* big_tux = 0;
79 TuxBodyParts* fire_tux = 0;
80 TuxBodyParts* ice_tux = 0;
83 TuxBodyParts::set_action(std::string action, int loops)
86 head->set_action(action, loops);
88 body->set_action(action, loops);
90 arms->set_action(action, loops);
92 feet->set_action(action, loops);
96 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
99 head->draw(context, pos, layer-1);
101 body->draw(context, pos, layer-3);
103 arms->draw(context, pos, layer+10);
105 feet->draw(context, pos, layer-2);
108 Player::Player(PlayerStatus* _player_status)
109 : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
111 controller = main_controller;
112 smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
113 smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite");
114 bigtux_star = sprite_manager->create("images/creatures/tux_big/bigtux-star.sprite");
116 sound_manager->preload("sounds/bigjump.wav");
117 sound_manager->preload("sounds/jump.wav");
118 sound_manager->preload("sounds/hurt.wav");
119 sound_manager->preload("sounds/skid.wav");
126 delete smalltux_gameover;
127 delete smalltux_star;
135 set_size(31.8, 62.8);
137 set_size(31.8, 30.8);
146 fall_mode = ON_GROUND;
151 backflipping = false;
152 backflip_direction = 0;
155 on_ground_flag = false;
156 grabbed_object = NULL;
158 floor_normal = Vector(0,-1);
164 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
166 Scripting::Player* interface = static_cast<Scripting::Player*> (this);
167 Scripting::expose_object(vm, table_idx, interface, "Tux", false);
171 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
173 Scripting::unexpose_object(vm, table_idx, "Tux");
177 Player::set_controller(Controller* controller)
179 this->controller = controller;
183 Player::adjust_height(float new_height)
186 bbox2.move(Vector(0, bbox.get_height() - new_height));
187 bbox2.set_height(new_height);
188 if (!Sector::current()->is_free_space(bbox2)) return false;
189 // adjust bbox accordingly
190 // note that we use members of moving_object for this, so we can run this during CD, too
192 set_size(bbox2.get_width(), bbox2.get_height());
197 Player::update(float elapsed_time)
199 if(dying && dying_timer.check()) {
204 if(!dying && !deactivated)
207 // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
208 if (deactivated) apply_friction();
210 // extend/shrink tux collision rectangle so that we fall through/walk over 1
212 if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
218 // on downward slopes, adjust vertical velocity to match slope angle
220 if (floor_normal.y != 0) {
221 if ((floor_normal.x * physic.get_velocity_x()) > 0) {
222 // we overdo it a little, just to be on the safe side
223 physic.set_velocity_y(-physic.get_velocity_x() * (floor_normal.x / floor_normal.y) * 2);
228 // handle backflipping
230 //prevent player from changing direction when backflipping
231 dir = (backflip_direction == 1) ? LEFT : RIGHT;
232 if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
237 fall_mode = ON_GROUND;
238 last_ground_y = get_pos().y;
240 if(get_pos().y > last_ground_y)
242 else if(fall_mode == ON_GROUND)
246 // check if we landed
249 if (backflipping && (!backflip_timer.started())) {
250 backflipping = false;
251 backflip_direction = 0;
253 // if controls are currently deactivated, we take care of standing up ourselves
254 if (deactivated) do_standup();
260 if (butt_jump && on_ground() && is_big()) {
263 Sector::current()->add_smoke_cloud(Vector(get_pos().x - 32, get_pos().y));
265 Sector::current()->add_smoke_cloud(
266 Vector(get_pos().x - 32, get_pos().y + 32));
270 // Break bricks beneath Tux
271 if(Sector::current()->trybreakbrick(
272 Vector(base.x + 1, base.y + base.height), false)
273 || Sector::current()->trybreakbrick(
274 Vector(base.x + base.width - 1, base.y + base.height), false)) {
275 physic.set_velocity_y(-2);
279 // Kill nearby badguys
280 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
281 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
282 i != gameobjects.end();
284 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
286 // don't kill when badguys are already dying or in a certain mode
287 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
288 badguy->mode != BadGuy::BOMB_EXPLODE) {
289 if (fabsf(base.x - badguy->base.x) < 96 &&
290 fabsf(base.y - badguy->base.y) < 64)
298 // calculate movement for this frame
299 movement = physic.get_movement(elapsed_time);
301 if(grabbed_object != NULL && !dying) {
302 Vector pos = get_pos() +
303 Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
304 grabbed_object->grab(*this, pos, dir);
307 if(grabbed_object != NULL && dying){
308 grabbed_object->ungrab(*this, dir);
309 grabbed_object = NULL;
312 on_ground_flag = false;
318 return on_ground_flag;
324 if(player_status->bonus == NO_BONUS)
331 Player::apply_friction()
333 if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
334 physic.set_velocity_x(0);
335 physic.set_acceleration_x(0);
336 } else if(physic.get_velocity_x() < 0) {
337 physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5);
339 physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5);
343 // if we're on ice slow down acceleration or deceleration
344 if (isice(base.x, base.y + base.height))
346 /* the acceleration/deceleration rate on ice is inversely proportional to
347 * the current velocity.
350 // increasing 1 will increase acceleration/deceleration rate
351 // decreasing 1 will decrease acceleration/deceleration rate
352 // must stay above zero, though
353 if (ax != 0) ax *= 1 / fabs(vx);
360 Player::handle_horizontal_input()
362 float vx = physic.get_velocity_x();
363 float vy = physic.get_velocity_y();
364 float ax = physic.get_acceleration_x();
365 float ay = physic.get_acceleration_y();
368 if(!duck || physic.get_velocity_y() != 0) {
369 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
373 } else if(!controller->hold(Controller::LEFT)
374 && controller->hold(Controller::RIGHT)) {
381 if (!controller->hold(Controller::ACTION)) {
382 ax = dirsign * WALK_ACCELERATION_X;
384 if(vx >= MAX_WALK_XM && dirsign > 0) {
387 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
392 ax = dirsign * RUN_ACCELERATION_X;
394 if(vx >= MAX_RUN_XM && dirsign > 0) {
397 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
403 // we can reach WALK_SPEED without any acceleration
404 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
405 vx = dirsign * WALK_SPEED;
408 // changing directions?
409 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
411 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
412 skidding_timer.start(SKID_TIME);
413 sound_manager->play("sounds/skid.wav");
414 // dust some particles
415 Sector::current()->add_object(
417 Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
418 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
419 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
428 physic.set_velocity(vx, vy);
429 physic.set_acceleration(ax, ay);
431 // we get slower when not pressing any keys
449 if (!is_big()) return;
451 if (physic.get_velocity_y() != 0) return;
452 if (!on_ground()) return;
454 if (adjust_height(31.8)) {
456 unduck_hurt_timer.stop();
463 Player::do_standup() {
465 if (!is_big()) return;
466 if (backflipping) return;
468 if (adjust_height(63.8)) {
470 unduck_hurt_timer.stop();
472 // if timer is not already running, start it.
473 if (unduck_hurt_timer.get_period() == 0) {
474 unduck_hurt_timer.start(UNDUCK_HURT_TIME);
476 else if (unduck_hurt_timer.check()) {
484 Player::do_backflip() {
486 if (!on_ground()) return;
488 // TODO: we don't have an animation for firetux backflipping, so let's revert to bigtux
489 set_bonus(GROWUP_BONUS, true);
491 backflip_direction = (dir == LEFT)?(+1):(-1);
494 backflip_timer.start(0.15);
498 Player::do_jump(float yspeed) {
499 if (!on_ground()) return;
501 physic.set_velocity_y(yspeed);
502 //bbox.move(Vector(0, -1));
504 on_ground_flag = false;
509 sound_manager->play("sounds/bigjump.wav");
511 sound_manager->play("sounds/jump.wav");
516 Player::handle_vertical_input()
520 if(controller->pressed(Controller::JUMP) && (can_jump)) {
522 // when running, only jump a little bit; else do a backflip
523 if (physic.get_velocity_x() != 0) do_jump(-300); else do_backflip();
525 // jump a bit higher if we are running; else do a normal jump
526 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
529 // Let go of jump key
530 else if(!controller->hold(Controller::JUMP)) {
531 if (!backflipping && jumping && physic.get_velocity_y() < 0) {
533 physic.set_velocity_y(0);
537 /* In case the player has pressed Down while in a certain range of air,
538 enable butt jump action */
539 if (controller->hold(Controller::DOWN) && !butt_jump && !duck && is_big() && jumping) {
543 /* When Down is not held anymore, disable butt jump */
544 if(butt_jump && !controller->hold(Controller::DOWN)) butt_jump = false;
546 /** jumping is only allowed if we're about to touch ground soon and if the
547 * button has been up in between the last jump
551 if ( (issolid(get_pos().x + bbox.get_width() / 2,
552 get_pos().y + bbox.get_height() + 64) ||
553 issolid(get_pos().x + 1, get_pos().y + bbox.get_height() + 64) ||
554 issolid(get_pos().x + bbox.get_width() - 1,
555 get_pos().y + bbox.get_height() + 64))
558 && input.jump && !input.old_jump)
566 Player::handle_input()
569 handle_input_ghost();
573 if(!controller->hold(Controller::ACTION) && grabbed_object) {
574 // move the grabbed object a bit away from tux
575 Vector pos = get_pos() +
576 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
577 bbox.get_height()*0.66666 - 32);
578 Rect dest(pos, pos + Vector(32, 32));
579 if(Sector::current()->is_free_space(dest)) {
580 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
582 moving_object->set_pos(pos);
584 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
586 grabbed_object->ungrab(*this, dir);
587 grabbed_object = NULL;
591 /* Handle horizontal movement: */
592 if (!backflipping) handle_horizontal_input();
595 if (on_ground() && !controller->hold(Controller::JUMP))
598 /* Handle vertical movement: */
599 handle_vertical_input();
602 if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
603 if(Sector::current()->add_bullet(
604 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
605 : Vector(32, bbox.get_height()/2)),
606 physic.get_velocity_x(), dir))
607 shooting_timer.start(SHOOTING_TIME);
610 /* Duck or Standup! */
611 if (controller->hold(Controller::DOWN)) do_duck(); else do_standup();
616 Player::handle_input_ghost()
620 if (controller->hold(Controller::LEFT)) {
622 vx -= MAX_RUN_XM * 2;
624 if (controller->hold(Controller::RIGHT)) {
626 vx += MAX_RUN_XM * 2;
628 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
629 vy -= MAX_RUN_XM * 2;
631 if (controller->hold(Controller::DOWN)) {
632 vy += MAX_RUN_XM * 2;
634 if (controller->hold(Controller::ACTION)) {
635 set_ghost_mode(false);
637 physic.set_velocity(vx, vy);
638 physic.set_acceleration(0, 0);
642 Player::add_coins(int count)
644 player_status->add_coins(count);
648 Player::add_bonus(const std::string& bonustype)
650 if(bonustype == "grow") {
651 add_bonus(GROWUP_BONUS);
652 } else if(bonustype == "fireflower") {
653 add_bonus(FIRE_BONUS);
654 } else if(bonustype == "iceflower") {
655 add_bonus(ICE_BONUS);
656 } else if(bonustype == "none") {
659 std::ostringstream msg;
660 msg << "Unknown bonus type " << bonustype;
661 throw std::runtime_error(msg.str());
666 Player::add_bonus(BonusType type, bool animate)
668 // always ignore NO_BONUS
669 if (type == NO_BONUS) {
673 // ignore GROWUP_BONUS if we're already big
674 if (type == GROWUP_BONUS) {
675 if (player_status->bonus == GROWUP_BONUS) return;
676 if (player_status->bonus == FIRE_BONUS) return;
677 if (player_status->bonus == ICE_BONUS) return;
680 set_bonus(type, animate);
684 Player::set_bonus(BonusType type, bool animate)
686 if(player_status->bonus == NO_BONUS) {
687 if (!adjust_height(62.8)) return;
689 growing_timer.start(GROWING_TIME);
692 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
693 if ((player_status->bonus == FIRE_BONUS) && (animate)) {
694 // visually lose helmet
695 Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
696 Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
697 Vector paccel = Vector(0, 1000);
698 Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS+1));
700 player_status->max_fire_bullets = 0;
701 player_status->max_ice_bullets = 0;
703 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
704 if (type == ICE_BONUS) player_status->max_ice_bullets++;
706 player_status->bonus = type;
710 Player::set_visible(bool visible)
712 this->visible = visible;
716 Player::get_visible()
724 kick_timer.start(KICK_TIME);
728 Player::draw(DrawingContext& context)
733 TuxBodyParts* tux_body;
735 if (player_status->bonus == GROWUP_BONUS)
737 else if (player_status->bonus == FIRE_BONUS)
739 else if (player_status->bonus == ICE_BONUS)
742 tux_body = small_tux;
744 int layer = LAYER_OBJECTS + 1;
746 /* Set Tux sprite action */
750 tux_body->set_action("backflip-left");
752 tux_body->set_action("backflip-right");
754 else if (duck && is_big())
757 tux_body->set_action("duck-left");
759 tux_body->set_action("duck-right");
761 else if (skidding_timer.started() && !skidding_timer.check())
764 tux_body->set_action("skid-left");
766 tux_body->set_action("skid-right");
768 else if (kick_timer.started() && !kick_timer.check())
771 tux_body->set_action("kick-left");
773 tux_body->set_action("kick-right");
775 else if (butt_jump && is_big())
778 tux_body->set_action("buttjump-left");
780 tux_body->set_action("buttjump-right");
782 else if (!on_ground())
785 tux_body->set_action("jump-left");
787 tux_body->set_action("jump-right");
791 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
794 tux_body->set_action("stand-left");
796 tux_body->set_action("stand-right");
801 tux_body->set_action("walk-left");
803 tux_body->set_action("walk-right");
807 if(idle_timer.check())
812 tux_body->head->set_action("idle-left", 1);
814 tux_body->head->set_action("idle-right", 1);
819 // Tux is holding something
820 if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
821 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
826 tux_body->arms->set_action("duck+grab-left");
828 tux_body->arms->set_action("duck+grab-right");
833 tux_body->arms->set_action("grab-left");
835 tux_body->arms->set_action("grab-right");
841 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
843 else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
845 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
846 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
848 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
849 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
852 else if (safe_timer.started() && size_t(game_time*40)%2)
855 tux_body->draw(context, get_pos(), layer);
857 // Draw blinking star overlay
858 if (invincible_timer.started() &&
859 (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
860 || size_t(game_time*20)%2)
863 if (!is_big() || duck)
864 smalltux_star->draw(context, get_pos(), layer + 5);
866 bigtux_star->draw(context, get_pos(), layer + 5);
871 Player::collision_tile(uint32_t tile_attributes)
873 if(tile_attributes & Tile::HURTS)
878 Player::collision(GameObject& other, const CollisionHit& hit)
880 Bullet* bullet = dynamic_cast<Bullet*> (&other);
885 if(other.get_flags() & FLAG_PORTABLE) {
886 Portable* portable = dynamic_cast<Portable*> (&other);
887 assert(portable != NULL);
888 if(portable && grabbed_object == NULL
889 && controller->hold(Controller::ACTION)
890 && fabsf(hit.normal.x) > .9) {
891 grabbed_object = portable;
892 grabbed_object->grab(*this, get_pos(), dir);
897 if(other.get_flags() & FLAG_SOLID) {
899 printf("Col %p: HN: %3.1f %3.1f D %.1f P: %3.1f %3.1f M: %3.1f %3.1f\n",
901 hit.normal.x, hit.normal.y, hit.depth,
902 get_pos().x, get_pos().y,
903 movement.x, movement.y);
906 if(hit.normal.y < 0) { // landed on floor?
907 if(physic.get_velocity_y() > 0)
908 physic.set_velocity_y(0);
910 on_ground_flag = true;
912 // remember normal of this tile
913 if (hit.normal.y > -0.9) {
914 floor_normal.x = hit.normal.x;
915 floor_normal.y = hit.normal.y;
917 // slowly adjust to unisolid tiles.
918 // Necessary because our bounding box sometimes reaches through slopes and thus hits unisolid tiles
919 floor_normal.x = (floor_normal.x * 0.9) + (hit.normal.x * 0.1);
920 floor_normal.y = (floor_normal.y * 0.9) + (hit.normal.y * 0.1);
923 // hack platforms so that we stand normally on them when going down...
924 Platform* platform = dynamic_cast<Platform*> (&other);
925 if(platform != NULL) {
926 if(platform->get_speed().y > 0)
927 physic.set_velocity_y(platform->get_speed().y);
928 //physic.set_velocity_x(platform->get_speed().x);
930 } else if(hit.normal.y > 0) { // bumped against the roof
931 physic.set_velocity_y(-.1);
933 // hack platform so that we are not glued to it from below
934 Platform* platform = dynamic_cast<Platform*> (&other);
935 if(platform != NULL) {
936 physic.set_velocity_y(platform->get_speed().y);
940 if(fabsf(hit.normal.x) > .9) { // hit on the side?
941 physic.set_velocity_x(0);
944 MovingObject* omov = dynamic_cast<MovingObject*> (&other);
946 Vector mov = movement - omov->get_movement();
948 printf("W %p - HITN: %3.1f %3.1f D:%3.1f TM: %3.1f %3.1f TD: %3.1f %3.1f PM: %3.2f %3.1f\n",
950 hit.normal.x, hit.normal.y,
952 movement.x, movement.y,
953 dest.p1.x, dest.p1.y,
954 omov->get_movement().x, omov->get_movement().y);
962 assert(dynamic_cast<MovingObject*> (&other) != NULL);
964 MovingObject* moving_object = static_cast<MovingObject*> (&other);
965 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
966 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
968 if(controller->pressed(Controller::UP))
969 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
975 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
977 if(safe_timer.started() || invincible_timer.started())
987 Player::make_invincible()
989 sound_manager->play("sounds/invincible.wav");
990 invincible_timer.start(TUX_INVINCIBLE_TIME);
991 Sector::current()->play_music(HERRING_MUSIC);
996 Player::kill(bool completely)
998 if(dying || deactivated)
1001 if(!completely && safe_timer.started() || invincible_timer.started())
1004 sound_manager->play("sounds/hurt.wav");
1006 physic.set_velocity_x(0);
1008 if(!completely && is_big()) {
1009 if(player_status->bonus == FIRE_BONUS
1010 || player_status->bonus == ICE_BONUS) {
1011 safe_timer.start(TUX_SAFE_TIME);
1012 set_bonus(GROWUP_BONUS, true);
1014 //growing_timer.start(GROWING_TIME);
1015 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
1016 adjust_height(30.8);
1018 set_bonus(NO_BONUS, true);
1021 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
1023 // the numbers: starting x, starting y, velocity y
1024 Sector::current()->add_object(new FallingCoin(get_pos() +
1025 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
1026 systemRandom.rand(-100,100)));
1028 physic.enable_gravity(true);
1029 physic.set_acceleration(0, 0);
1030 physic.set_velocity(0, -700);
1031 player_status->coins -= 25;
1032 set_bonus(NO_BONUS, true);
1034 dying_timer.start(3.0);
1035 set_group(COLGROUP_DISABLED);
1037 DisplayEffect* effect = new DisplayEffect();
1038 effect->fade_out(3.0);
1039 Sector::current()->add_object(effect);
1040 sound_manager->stop_music(3.0);
1045 Player::move(const Vector& vector)
1049 // TODO: do we need the following? Seems irrelevant to moving the player
1051 set_size(31.8, 63.8);
1053 set_size(31.8, 31.8);
1055 last_ground_y = vector.y;
1061 Player::check_bounds(Camera* camera)
1063 /* Keep tux in bounds: */
1064 if (get_pos().x < 0) {
1065 // Lock Tux to the size of the level, so that he doesn't fall of
1067 set_pos(Vector(0, get_pos().y));
1070 /* Keep in-bounds, vertically: */
1071 if (get_pos().y > Sector::current()->solids->get_height() * 32) {
1076 bool adjust = false;
1077 // can happen if back scrolling is disabled
1078 if(get_pos().x < camera->get_translation().x) {
1079 set_pos(Vector(camera->get_translation().x, get_pos().y));
1082 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
1085 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
1094 if(collision_object_map(bbox)) {
1103 Player::add_velocity(const Vector& velocity)
1105 physic.set_velocity(physic.get_velocity() + velocity);
1109 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1111 if (end_speed.x > 0) physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1112 if (end_speed.x < 0) physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1113 if (end_speed.y > 0) physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1114 if (end_speed.y < 0) physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1118 Player::bounce(BadGuy& )
1120 if(controller->hold(Controller::JUMP))
1121 physic.set_velocity_y(-520);
1123 physic.set_velocity_y(-300);
1126 //Scripting Functions Below
1129 Player::deactivate()
1131 if (deactivated) return;
1133 physic.set_velocity_x(0);
1134 physic.set_velocity_y(0);
1135 physic.set_acceleration_x(0);
1136 physic.set_acceleration_y(0);
1142 if (!deactivated) return;
1143 deactivated = false;
1146 void Player::walk(float speed)
1148 physic.set_velocity_x(speed);
1152 Player::set_ghost_mode(bool enable)
1154 if (ghost_mode == enable) return;
1157 set_group(COLGROUP_DISABLED);
1158 physic.enable_gravity(false);
1159 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1162 set_group(COLGROUP_MOVING);
1163 physic.enable_gravity(true);
1164 log_debug << "You feel solid again." << std::endl;