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;
86 TuxBodyParts::set_action(std::string action, int loops)
89 head->set_action(action, loops);
91 body->set_action(action, loops);
93 arms->set_action(action, loops);
95 feet->set_action(action, loops);
99 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
102 head->draw(context, pos, layer-1);
104 body->draw(context, pos, layer-3);
106 arms->draw(context, pos, layer+10);
108 feet->draw(context, pos, layer-2);
111 Player::Player(PlayerStatus* _player_status, const std::string& name)
112 : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
115 controller = main_controller;
116 smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
117 smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite");
118 bigtux_star = sprite_manager->create("images/creatures/tux_big/bigtux-star.sprite");
119 airarrow.reset(new Surface("images/engine/hud/airarrow.png"));
121 sound_manager->preload("sounds/bigjump.wav");
122 sound_manager->preload("sounds/jump.wav");
123 sound_manager->preload("sounds/hurt.wav");
124 sound_manager->preload("sounds/skid.wav");
125 sound_manager->preload("sounds/flip.wav");
126 sound_manager->preload("sounds/invincible.wav");
127 sound_manager->preload("sounds/splash.ogg");
135 delete smalltux_gameover;
136 delete smalltux_star;
144 set_size(31.8, 62.8);
146 set_size(31.8, 30.8);
156 fall_mode = ON_GROUND;
161 backflipping = false;
162 backflip_direction = 0;
166 on_ground_flag = false;
167 grabbed_object = NULL;
173 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
178 Scripting::expose_object(vm, table_idx, dynamic_cast<Scripting::Player *>(this), name, false);
182 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
187 Scripting::unexpose_object(vm, table_idx, name);
191 Player::set_controller(Controller* controller)
193 this->controller = controller;
197 Player::adjust_height(float new_height)
200 bbox2.move(Vector(0, bbox.get_height() - new_height));
201 bbox2.set_height(new_height);
203 if(new_height > bbox.get_height()) {
204 Rect additional_space = bbox2;
205 additional_space.set_height(new_height - bbox.get_height());
206 if(!Sector::current()->is_free_of_statics(additional_space, this))
210 // adjust bbox accordingly
211 // note that we use members of moving_object for this, so we can run this during CD, too
213 set_size(bbox2.get_width(), bbox2.get_height());
218 Player::update(float elapsed_time)
225 if(dying && dying_timer.check()) {
230 if(!dying && !deactivated)
233 // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
237 // extend/shrink tux collision rectangle so that we fall through/walk over 1
239 if(fabsf(physic.vx) > MAX_WALK_XM) {
245 // on downward slopes, adjust vertical velocity so tux walks smoothly down
247 if(floor_normal.y != 0) {
248 if ((floor_normal.x * physic.vx) >= 0) {
254 // handle backflipping
256 //prevent player from changing direction when backflipping
257 dir = (backflip_direction == 1) ? LEFT : RIGHT;
258 if (backflip_timer.started()) physic.vx = 100 * backflip_direction;
263 fall_mode = ON_GROUND;
264 last_ground_y = get_pos().y;
266 if(get_pos().y > last_ground_y)
268 else if(fall_mode == ON_GROUND)
272 // check if we landed
275 if (backflipping && (!backflip_timer.started())) {
276 backflipping = false;
277 backflip_direction = 0;
279 // if controls are currently deactivated, we take care of standing up ourselves
285 // calculate movement for this frame
286 movement = physic.get_movement(elapsed_time);
288 if(grabbed_object != NULL && !dying) {
289 Vector pos = get_pos() +
290 Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
291 grabbed_object->grab(*this, pos, dir);
294 if(grabbed_object != NULL && dying){
295 grabbed_object->ungrab(*this, dir);
296 grabbed_object = NULL;
299 on_ground_flag = false;
301 // when invincible, spawn particles
302 if (invincible_timer.started() && !dying)
304 if (systemRandom.rand(0, 2) == 0) {
305 float px = systemRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
306 float py = systemRandom.randf(bbox.p1.y+0, bbox.p2.y-0);
307 Vector ppos = Vector(px, py);
308 Vector pspeed = Vector(0, 0);
309 Vector paccel = Vector(0, 0);
310 // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
311 if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
312 // make every other a longer sparkle to make trail a bit fuzzy
313 if (size_t(game_time*20)%2) {
314 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
316 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
319 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
329 return on_ground_flag;
335 if(player_status->bonus == NO_BONUS)
342 Player::apply_friction()
344 if ((on_ground()) && (fabs(physic.vx) < WALK_SPEED)) {
347 } else if(physic.vx < 0) {
348 physic.ax = WALK_ACCELERATION_X * 1.5;
350 physic.ax = WALK_ACCELERATION_X * -1.5;
355 Player::handle_horizontal_input()
357 float vx = physic.vx;
358 float vy = physic.vy;
359 float ax = physic.ax;
360 float ay = physic.ay;
363 if(!duck || physic.vy != 0) {
364 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
368 } else if(!controller->hold(Controller::LEFT)
369 && controller->hold(Controller::RIGHT)) {
376 // only run if action key is pressed and we're not holding anything
377 if (!(controller->hold(Controller::ACTION) && (!grabbed_object))) {
378 ax = dirsign * WALK_ACCELERATION_X;
380 if(vx >= MAX_WALK_XM && dirsign > 0) {
383 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
388 ax = dirsign * RUN_ACCELERATION_X;
390 if(vx >= MAX_RUN_XM && dirsign > 0) {
393 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
399 // we can reach WALK_SPEED without any acceleration
400 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
401 vx = dirsign * WALK_SPEED;
404 // changing directions?
405 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
407 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
408 skidding_timer.start(SKID_TIME);
409 sound_manager->play("sounds/skid.wav");
410 // dust some particles
411 Sector::current()->add_object(
413 Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
414 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
415 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
429 // we get slower when not pressing any keys
456 if (adjust_height(31.8)) {
458 unduck_hurt_timer.stop();
465 Player::do_standup() {
473 if (adjust_height(63.8)) {
475 unduck_hurt_timer.stop();
477 // if timer is not already running, start it.
478 if (unduck_hurt_timer.get_period() == 0) {
479 unduck_hurt_timer.start(UNDUCK_HURT_TIME);
481 else if (unduck_hurt_timer.check()) {
489 Player::do_backflip() {
495 // TODO: we don't have an animation for firetux backflipping, so let's revert to bigtux
496 set_bonus(GROWUP_BONUS, true);
498 backflip_direction = (dir == LEFT)?(+1):(-1);
501 sound_manager->play("sounds/flip.wav");
502 backflip_timer.start(0.15);
506 Player::do_jump(float yspeed) {
511 //bbox.move(Vector(0, -1));
513 on_ground_flag = false;
518 sound_manager->play("sounds/bigjump.wav");
520 sound_manager->play("sounds/jump.wav");
525 Player::handle_vertical_input()
528 if(controller->pressed(Controller::JUMP) && (can_jump)) {
530 // when running, only jump a little bit; else do a backflip
531 if ((physic.vx != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip();
533 // jump a bit higher if we are running; else do a normal jump
534 if (fabs(physic.vx) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
537 // Let go of jump key
538 else if(!controller->hold(Controller::JUMP)) {
539 if (!backflipping && jumping && physic.vy < 0) {
545 /* In case the player has pressed Down while in a certain range of air,
546 enable butt jump action */
547 if (controller->hold(Controller::DOWN) && !butt_jump && !duck && is_big() && jumping) {
551 /* When Down is not held anymore, disable butt jump */
552 if(butt_jump && !controller->hold(Controller::DOWN))
558 if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP))
560 physic.vy = physic.vy * 0.94;
565 Player::handle_input()
568 handle_input_ghost();
573 if( controller->released( Controller::PEEK_LEFT ) ) {
576 if( controller->released( Controller::PEEK_RIGHT ) ) {
579 if( controller->pressed( Controller::PEEK_LEFT ) ) {
582 if( controller->pressed( Controller::PEEK_RIGHT ) ) {
586 /* Handle horizontal movement: */
587 if (!backflipping) handle_horizontal_input();
590 if (on_ground() && !controller->hold(Controller::JUMP))
593 /* Handle vertical movement: */
594 handle_vertical_input();
597 if (controller->pressed(Controller::ACTION) && (player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS)) {
598 if(Sector::current()->add_bullet(
599 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
600 : Vector(32, bbox.get_height()/2)),
602 shooting_timer.start(SHOOTING_TIME);
605 /* Duck or Standup! */
606 if (controller->hold(Controller::DOWN)) {
615 if(!controller->hold(Controller::ACTION) && grabbed_object) {
616 // move the grabbed object a bit away from tux
617 Vector pos = get_pos() +
618 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
619 bbox.get_height()*0.66666 - 32);
620 Rect dest(pos, pos + Vector(32, 32));
621 if(Sector::current()->is_free_of_statics(dest)) {
622 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
624 moving_object->set_pos(pos);
626 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
628 grabbed_object->ungrab(*this, dir);
629 grabbed_object = NULL;
637 if(controller->hold(Controller::ACTION) && !grabbed_object
639 Sector* sector = Sector::current();
642 pos = Vector(bbox.get_left() - 5, bbox.get_bottom() - 16);
644 pos = Vector(bbox.get_right() + 5, bbox.get_bottom() - 16);
647 for(Sector::Portables::iterator i = sector->portables.begin();
648 i != sector->portables.end(); ++i) {
649 Portable* portable = *i;
650 if(!portable->is_portable())
653 MovingObject* moving_object = dynamic_cast<MovingObject*> (portable);
655 if(moving_object == NULL)
658 if(moving_object->get_bbox().contains(pos)) {
659 grabbed_object = portable;
660 grabbed_object->grab(*this, get_pos(), dir);
668 Player::handle_input_ghost()
672 if (controller->hold(Controller::LEFT)) {
674 vx -= MAX_RUN_XM * 2;
676 if (controller->hold(Controller::RIGHT)) {
678 vx += MAX_RUN_XM * 2;
680 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
681 vy -= MAX_RUN_XM * 2;
683 if (controller->hold(Controller::DOWN)) {
684 vy += MAX_RUN_XM * 2;
686 if (controller->hold(Controller::ACTION)) {
687 set_ghost_mode(false);
696 Player::add_coins(int count)
698 player_status->add_coins(count);
704 return player_status->coins;
708 Player::add_bonus(const std::string& bonustype)
710 BonusType type = NO_BONUS;
712 if(bonustype == "grow") {
714 } else if(bonustype == "fireflower") {
716 } else if(bonustype == "iceflower") {
718 } else if(bonustype == "none") {
721 std::ostringstream msg;
722 msg << "Unknown bonus type " << bonustype;
723 throw std::runtime_error(msg.str());
726 return add_bonus(type);
730 Player::add_bonus(BonusType type, bool animate)
732 // always ignore NO_BONUS
733 if (type == NO_BONUS) {
737 // ignore GROWUP_BONUS if we're already big
738 if (type == GROWUP_BONUS) {
739 if (player_status->bonus == GROWUP_BONUS)
741 if (player_status->bonus == FIRE_BONUS)
743 if (player_status->bonus == ICE_BONUS)
747 return set_bonus(type, animate);
751 Player::set_bonus(BonusType type, bool animate)
753 if(player_status->bonus == NO_BONUS) {
754 if (!adjust_height(62.8)) {
755 printf("can't adjust\n");
759 growing_timer.start(GROWING_TIME);
762 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
763 if ((player_status->bonus == FIRE_BONUS) && (animate)) {
764 // visually lose helmet
765 Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
766 Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
767 Vector paccel = Vector(0, 1000);
768 std::string action = (dir==LEFT)?"left":"right";
769 Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
771 if ((player_status->bonus == ICE_BONUS) && (animate)) {
773 Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
774 Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
775 Vector paccel = Vector(0, 1000);
776 std::string action = (dir==LEFT)?"left":"right";
777 Sector::current()->add_object(new SpriteParticle("images/objects/particles/icetux-cap.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
779 player_status->max_fire_bullets = 0;
780 player_status->max_ice_bullets = 0;
782 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
783 if (type == ICE_BONUS) player_status->max_ice_bullets++;
785 player_status->bonus = type;
790 Player::set_visible(bool visible)
792 this->visible = visible;
794 set_group(COLGROUP_MOVING);
796 set_group(COLGROUP_DISABLED);
800 Player::get_visible()
808 kick_timer.start(KICK_TIME);
812 Player::draw(DrawingContext& context)
817 // if Tux is above camera, draw little "air arrow" to show where he is x-wise
818 if (Sector::current() && Sector::current()->camera && (get_bbox().p2.y - 16 < Sector::current()->camera->get_translation().y)) {
819 float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
820 float py = Sector::current()->camera->get_translation().y;
821 py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
822 context.draw_surface(airarrow.get(), Vector(px, py), LAYER_HUD - 1);
825 TuxBodyParts* tux_body;
827 if (player_status->bonus == GROWUP_BONUS)
829 else if (player_status->bonus == FIRE_BONUS)
831 else if (player_status->bonus == ICE_BONUS)
834 tux_body = small_tux;
836 int layer = LAYER_OBJECTS + 1;
838 /* Set Tux sprite action */
842 tux_body->set_action("backflip-left");
844 tux_body->set_action("backflip-right");
846 else if (duck && is_big())
849 tux_body->set_action("duck-left");
851 tux_body->set_action("duck-right");
853 else if (skidding_timer.started() && !skidding_timer.check())
856 tux_body->set_action("skid-left");
858 tux_body->set_action("skid-right");
860 else if (kick_timer.started() && !kick_timer.check())
863 tux_body->set_action("kick-left");
865 tux_body->set_action("kick-right");
867 else if (butt_jump && is_big())
870 tux_body->set_action("buttjump-left");
872 tux_body->set_action("buttjump-right");
874 else if (!on_ground())
877 tux_body->set_action("jump-left");
879 tux_body->set_action("jump-right");
883 if (fabsf(physic.vx) < 1.0f) // standing
886 tux_body->set_action("stand-left");
888 tux_body->set_action("stand-right");
893 tux_body->set_action("walk-left");
895 tux_body->set_action("walk-right");
899 if(idle_timer.check())
904 tux_body->head->set_action("idle-left", 1);
906 tux_body->head->set_action("idle-right", 1);
911 // Tux is holding something
912 if ((grabbed_object != 0 && physic.vy == 0) ||
913 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
918 tux_body->arms->set_action("duck+grab-left");
920 tux_body->arms->set_action("duck+grab-right");
925 tux_body->arms->set_action("grab-left");
927 tux_body->arms->set_action("grab-right");
933 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
935 else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
937 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
938 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
940 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
941 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
944 else if (safe_timer.started() && size_t(game_time*40)%2)
947 tux_body->draw(context, get_pos(), layer);
952 Player::collision_tile(uint32_t tile_attributes)
954 if(tile_attributes & Tile::HURTS)
958 if( tile_attributes & Tile::WATER ){
964 if( tile_attributes & Tile::WATER ){
967 sound_manager->play( "sounds/splash.ogg" );
973 Player::collision_solid(const CollisionHit& hit)
979 on_ground_flag = true;
980 floor_normal = hit.slope_normal;
986 if(hit.left || hit.right) {
992 if(hit.left || hit.right) {
994 } else if(hit.top || hit.bottom) {
1001 Player::collision(GameObject& other, const CollisionHit& hit)
1003 Bullet* bullet = dynamic_cast<Bullet*> (&other);
1008 if(hit.left || hit.right) {
1009 try_grab(); //grab objects right now, in update it will be too late
1012 assert(dynamic_cast<MovingObject*> (&other) != NULL);
1014 MovingObject* moving_object = static_cast<MovingObject*> (&other);
1015 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
1016 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
1018 if(controller->pressed(Controller::UP))
1019 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
1025 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
1026 if(badguy != NULL) {
1027 if(safe_timer.started() || invincible_timer.started())
1037 Player::make_invincible()
1039 sound_manager->play("sounds/invincible.wav");
1040 invincible_timer.start(TUX_INVINCIBLE_TIME);
1041 Sector::current()->play_music(HERRING_MUSIC);
1046 Player::kill(bool completely)
1048 if(dying || deactivated)
1051 if(!completely && (safe_timer.started() || invincible_timer.started()))
1054 sound_manager->play("sounds/hurt.wav");
1058 if(!completely && is_big()) {
1059 if(player_status->bonus == FIRE_BONUS
1060 || player_status->bonus == ICE_BONUS) {
1061 safe_timer.start(TUX_SAFE_TIME);
1062 set_bonus(GROWUP_BONUS, true);
1064 //growing_timer.start(GROWING_TIME);
1065 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
1066 adjust_height(30.8);
1068 set_bonus(NO_BONUS, true);
1071 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
1073 // the numbers: starting x, starting y, velocity y
1074 Sector::current()->add_object(new FallingCoin(get_pos() +
1075 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
1076 systemRandom.rand(-100,100)));
1078 physic.gravity_enabled = true;
1083 player_status->coins -= 25;
1084 set_bonus(NO_BONUS, true);
1086 dying_timer.start(3.0);
1087 set_group(COLGROUP_DISABLED);
1089 DisplayEffect* effect = new DisplayEffect();
1090 effect->fade_out(3.0);
1091 Sector::current()->add_object(effect);
1092 sound_manager->stop_music(3.0);
1097 Player::move(const Vector& vector)
1101 // TODO: do we need the following? Seems irrelevant to moving the player
1103 set_size(31.8, 63.8);
1105 set_size(31.8, 31.8);
1107 last_ground_y = vector.y;
1113 Player::check_bounds(Camera* camera)
1115 /* Keep tux in bounds: */
1116 if (get_pos().x < 0) {
1117 // Lock Tux to the size of the level, so that he doesn't fall of
1119 set_pos(Vector(0, get_pos().y));
1122 /* fallen out of the level? */
1123 if (get_pos().y > Sector::current()->get_height()) {
1128 // can happen if back scrolling is disabled
1129 if(get_pos().x < camera->get_translation().x) {
1130 set_pos(Vector(camera->get_translation().x, get_pos().y));
1132 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
1135 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
1141 Player::add_velocity(const Vector& velocity)
1143 physic.vx += velocity.x;
1144 physic.vy += velocity.y;
1148 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1150 if (end_speed.x > 0)
1151 physic.vx = std::min(physic.vx + velocity.x, end_speed.x);
1152 if (end_speed.x < 0)
1153 physic.vx = std::max(physic.vx + velocity.x, end_speed.x);
1154 if (end_speed.y > 0)
1155 physic.vy = std::min(physic.vy + velocity.y, end_speed.y);
1156 if (end_speed.y < 0)
1157 physic.vy = std::max(physic.vy + velocity.y, end_speed.y);
1161 Player::bounce(BadGuy& )
1163 if(controller->hold(Controller::JUMP))
1169 //Scripting Functions Below
1172 Player::deactivate()
1188 deactivated = false;
1191 void Player::walk(float speed)
1197 Player::set_ghost_mode(bool enable)
1199 if (ghost_mode == enable)
1204 set_group(COLGROUP_DISABLED);
1205 physic.gravity_enabled = false;
1206 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1209 set_group(COLGROUP_MOVING);
1210 physic.gravity_enabled = true;
1211 log_debug << "You feel solid again." << std::endl;