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"
52 static const int TILES_FOR_BUTTJUMP = 3;
53 static const float SHOOTING_TIME = .150;
54 /// time before idle animation starts
55 static const float IDLE_TIME = 2.5;
57 static const float WALK_ACCELERATION_X = 300;
58 static const float RUN_ACCELERATION_X = 400;
59 static const float SKID_XM = 200;
60 static const float SKID_TIME = .3;
61 static const float MAX_WALK_XM = 230;
62 static const float MAX_RUN_XM = 320;
63 static const float WALK_SPEED = 100;
65 static const float KICK_TIME = .3;
67 static const float UNDUCK_HURT_TIME = 0.25; /**< if Tux cannot unduck for this long, he will get hurt */
70 Surface* growingtux_left[GROWING_FRAMES];
71 Surface* growingtux_right[GROWING_FRAMES];
73 Surface* tux_life = 0;
75 TuxBodyParts* small_tux = 0;
76 TuxBodyParts* big_tux = 0;
77 TuxBodyParts* fire_tux = 0;
78 TuxBodyParts* ice_tux = 0;
81 TuxBodyParts::set_action(std::string action, int loops)
84 head->set_action(action, loops);
86 body->set_action(action, loops);
88 arms->set_action(action, loops);
90 feet->set_action(action, loops);
94 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
97 head->draw(context, pos, layer-1);
99 body->draw(context, pos, layer-3);
101 arms->draw(context, pos, layer+10);
103 feet->draw(context, pos, layer-2);
106 Player::Player(PlayerStatus* _player_status)
107 : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
109 controller = main_controller;
110 smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
111 smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite");
112 bigtux_star = sprite_manager->create("images/creatures/tux_big/bigtux-star.sprite");
114 sound_manager->preload("sounds/bigjump.wav");
115 sound_manager->preload("sounds/jump.wav");
116 sound_manager->preload("sounds/hurt.wav");
117 sound_manager->preload("sounds/skid.wav");
124 delete smalltux_gameover;
125 delete smalltux_star;
133 set_size(31.8, 62.8);
135 set_size(31.8, 30.8);
144 fall_mode = ON_GROUND;
149 backflipping = false;
150 backflip_direction = 0;
153 on_ground_flag = false;
154 grabbed_object = NULL;
156 floor_normal = Vector(0,-1);
162 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
164 Scripting::Player* interface = static_cast<Scripting::Player*> (this);
165 Scripting::expose_object(vm, table_idx, interface, "Tux", false);
169 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
171 Scripting::unexpose_object(vm, table_idx, "Tux");
175 Player::set_controller(Controller* controller)
177 this->controller = controller;
181 Player::adjust_height(float new_height)
184 bbox2.move(Vector(0, bbox.get_height() - new_height));
185 bbox2.set_height(new_height);
186 if (!Sector::current()->is_free_space(bbox2)) return false;
187 // adjust bbox accordingly
188 // note that we use members of moving_object for this, so we can run this during CD, too
190 set_size(bbox2.get_width(), bbox2.get_height());
195 Player::update(float elapsed_time)
197 if(dying && dying_timer.check()) {
202 if(!dying && !deactivated)
205 movement = physic.get_movement(elapsed_time);
207 if(grabbed_object != NULL && !dying) {
208 Vector pos = get_pos() +
209 Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
210 grabbed_object->grab(*this, pos, dir);
213 if(grabbed_object != NULL && dying){
214 grabbed_object->ungrab(*this, dir);
215 grabbed_object = NULL;
218 on_ground_flag = false;
224 return on_ground_flag;
230 if(player_status->bonus == NO_BONUS)
237 Player::handle_horizontal_input()
239 float vx = physic.get_velocity_x();
240 float vy = physic.get_velocity_y();
241 float ax = physic.get_acceleration_x();
242 float ay = physic.get_acceleration_y();
245 if(!duck || physic.get_velocity_y() != 0) {
246 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
250 } else if(!controller->hold(Controller::LEFT)
251 && controller->hold(Controller::RIGHT)) {
258 if (!controller->hold(Controller::ACTION)) {
259 ax = dirsign * WALK_ACCELERATION_X;
261 if(vx >= MAX_WALK_XM && dirsign > 0) {
264 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
269 ax = dirsign * RUN_ACCELERATION_X;
271 if(vx >= MAX_RUN_XM && dirsign > 0) {
274 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
280 // we can reach WALK_SPEED without any acceleration
281 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
282 vx = dirsign * WALK_SPEED;
285 // changing directions?
286 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
288 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
289 skidding_timer.start(SKID_TIME);
290 sound_manager->play("sounds/skid.wav");
291 // dust some particles
292 Sector::current()->add_object(
294 Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
295 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
296 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
305 // we get slower when not pressing any keys
307 if ((on_ground()) && (fabs(vx) < WALK_SPEED)) {
311 ax = WALK_ACCELERATION_X * 1.5;
313 ax = WALK_ACCELERATION_X * -1.5;
318 // if we're on ice slow down acceleration or deceleration
319 if (isice(base.x, base.y + base.height))
321 /* the acceleration/deceleration rate on ice is inversely proportional to
322 * the current velocity.
325 // increasing 1 will increase acceleration/deceleration rate
326 // decreasing 1 will decrease acceleration/deceleration rate
327 // must stay above zero, though
328 if (ax != 0) ax *= 1 / fabs(vx);
332 // extend/shrink tux collision rectangle so that we fall through/walk over 1
334 if(fabsf(vx) > MAX_WALK_XM) {
340 // on downward slopes, adjust vertical velocity to match slope angle
342 if (floor_normal.y != 0) {
343 if ((floor_normal.x * vx) > 0) {
344 // we overdo it a little, just to be on the safe side
345 vy = -vx * (floor_normal.x / floor_normal.y) * 2;
350 physic.set_velocity(vx, vy);
351 physic.set_acceleration(ax, ay);
355 Player::handle_vertical_input()
359 fall_mode = ON_GROUND;
360 last_ground_y = get_pos().y;
362 if(get_pos().y > last_ground_y)
364 else if(fall_mode == ON_GROUND)
368 if(on_ground()) { /* Make sure jumping is off. */
371 backflipping = false;
372 backflip_direction = 0;
377 if(controller->pressed(Controller::JUMP) && can_jump && on_ground()) {
379 if (physic.get_velocity_x() != 0) // only jump a little bit when running ducked
380 physic.set_velocity_y(-300);
381 else { //do a backflip
383 physic.set_velocity_y(-580);
384 backflip_timer.start(0.15);
387 else if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) // jump higher if we are running
388 physic.set_velocity_y(-580);
390 physic.set_velocity_y(-520);
392 //bbox.move(Vector(0, -1));
396 sound_manager->play("sounds/bigjump.wav");
398 sound_manager->play("sounds/jump.wav");
399 } else if(!controller->hold(Controller::JUMP)) { // Let go of jump key
400 if (!backflipping && jumping && physic.get_velocity_y() < 0) {
402 physic.set_velocity_y(0);
406 /* In case the player has pressed Down while in a certain range of air,
407 enable butt jump action */
408 if (controller->hold(Controller::DOWN) && !butt_jump && !duck)
409 //if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
412 /* When Down is not held anymore, disable butt jump */
413 if(butt_jump && !controller->hold(Controller::DOWN))
418 if (butt_jump && on_ground() && is_big()) {
421 Sector::current()->add_smoke_cloud(Vector(get_pos().x - 32, get_pos().y));
423 Sector::current()->add_smoke_cloud(
424 Vector(get_pos().x - 32, get_pos().y + 32));
428 // Break bricks beneath Tux
429 if(Sector::current()->trybreakbrick(
430 Vector(base.x + 1, base.y + base.height), false)
431 || Sector::current()->trybreakbrick(
432 Vector(base.x + base.width - 1, base.y + base.height), false)) {
433 physic.set_velocity_y(-2);
437 // Kill nearby badguys
438 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
439 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
440 i != gameobjects.end();
442 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
444 // don't kill when badguys are already dying or in a certain mode
445 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
446 badguy->mode != BadGuy::BOMB_EXPLODE) {
447 if (fabsf(base.x - badguy->base.x) < 96 &&
448 fabsf(base.y - badguy->base.y) < 64)
456 /** jumping is only allowed if we're about to touch ground soon and if the
457 * button has been up in between the last jump
461 if ( (issolid(get_pos().x + bbox.get_width() / 2,
462 get_pos().y + bbox.get_height() + 64) ||
463 issolid(get_pos().x + 1, get_pos().y + bbox.get_height() + 64) ||
464 issolid(get_pos().x + bbox.get_width() - 1,
465 get_pos().y + bbox.get_height() + 64))
468 && input.jump && !input.old_jump)
476 Player::handle_input()
479 handle_input_ghost();
483 if(!controller->hold(Controller::ACTION) && grabbed_object) {
484 // move the grabbed object a bit away from tux
485 Vector pos = get_pos() +
486 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
487 bbox.get_height()*0.66666 - 32);
488 Rect dest(pos, pos + Vector(32, 32));
489 if(Sector::current()->is_free_space(dest)) {
490 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
492 moving_object->set_pos(pos);
494 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
496 grabbed_object->ungrab(*this, dir);
497 grabbed_object = NULL;
501 /* Handle horizontal movement: */
502 if (!backflipping) handle_horizontal_input();
504 if (backflip_direction == 0) {
505 dir == LEFT ? backflip_direction = 1 : backflip_direction = -1;
507 else backflip_direction == 1 ? dir = LEFT : dir = RIGHT; //prevent player from changing direction when backflipping
508 if (backflip_timer.check()) physic.set_velocity_x(100 * backflip_direction);
513 if (on_ground() && !controller->hold(Controller::JUMP))
515 handle_vertical_input();
518 if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
519 if(Sector::current()->add_bullet(
520 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
521 : Vector(32, bbox.get_height()/2)),
522 physic.get_velocity_x(), dir))
523 shooting_timer.start(SHOOTING_TIME);
527 if (controller->hold(Controller::DOWN) && is_big() && !duck
528 && physic.get_velocity_y() == 0 && on_ground()) {
529 if (adjust_height(31.8)) {
531 unduck_hurt_timer.stop();
537 else if(!controller->hold(Controller::DOWN) && is_big() && duck) {
538 if (adjust_height(63.8)) {
540 unduck_hurt_timer.stop();
542 // if timer is not already running, start it.
543 if (unduck_hurt_timer.get_period() == 0) {
544 unduck_hurt_timer.start(UNDUCK_HURT_TIME);
546 else if (unduck_hurt_timer.check()) {
554 Player::handle_input_ghost()
558 if (controller->hold(Controller::LEFT)) {
560 vx -= MAX_RUN_XM * 2;
562 if (controller->hold(Controller::RIGHT)) {
564 vx += MAX_RUN_XM * 2;
566 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
567 vy -= MAX_RUN_XM * 2;
569 if (controller->hold(Controller::DOWN)) {
570 vy += MAX_RUN_XM * 2;
572 if (controller->hold(Controller::ACTION)) {
573 set_ghost_mode(false);
575 physic.set_velocity(vx, vy);
576 physic.set_acceleration(0, 0);
580 Player::add_coins(int count)
582 player_status->add_coins(count);
586 Player::add_bonus(const std::string& bonustype)
588 if(bonustype == "grow") {
589 add_bonus(GROWUP_BONUS);
590 } else if(bonustype == "fireflower") {
591 add_bonus(FIRE_BONUS);
592 } else if(bonustype == "iceflower") {
593 add_bonus(ICE_BONUS);
594 } else if(bonustype == "none") {
597 std::ostringstream msg;
598 msg << "Unknown bonus type " << bonustype;
599 throw std::runtime_error(msg.str());
604 Player::add_bonus(BonusType type, bool animate)
606 // always ignore NO_BONUS
607 if (type == NO_BONUS) {
611 // ignore GROWUP_BONUS if we're already big
612 if (type == GROWUP_BONUS) {
613 if (player_status->bonus == GROWUP_BONUS) return;
614 if (player_status->bonus == FIRE_BONUS) return;
615 if (player_status->bonus == ICE_BONUS) return;
618 set_bonus(type, animate);
622 Player::set_bonus(BonusType type, bool animate)
624 if(player_status->bonus == NO_BONUS) {
625 if (!adjust_height(62.8)) return;
627 growing_timer.start(GROWING_TIME);
630 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
631 player_status->max_fire_bullets = 0;
632 player_status->max_ice_bullets = 0;
634 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
635 if (type == ICE_BONUS) player_status->max_ice_bullets++;
637 player_status->bonus = type;
641 Player::set_visible(bool visible)
643 this->visible = visible;
647 Player::get_visible()
655 kick_timer.start(KICK_TIME);
659 Player::draw(DrawingContext& context)
664 TuxBodyParts* tux_body;
666 if (player_status->bonus == GROWUP_BONUS)
668 else if (player_status->bonus == FIRE_BONUS)
670 else if (player_status->bonus == ICE_BONUS)
673 tux_body = small_tux;
675 int layer = LAYER_OBJECTS + 1;
677 /* Set Tux sprite action */
678 if (duck && is_big())
681 tux_body->set_action("duck-left");
683 tux_body->set_action("duck-right");
685 else if (skidding_timer.started() && !skidding_timer.check())
688 tux_body->set_action("skid-left");
690 tux_body->set_action("skid-right");
692 else if (kick_timer.started() && !kick_timer.check())
695 tux_body->set_action("kick-left");
697 tux_body->set_action("kick-right");
699 else if (butt_jump && is_big())
702 tux_body->set_action("buttjump-left");
704 tux_body->set_action("buttjump-right");
706 else if (!on_ground())
709 tux_body->set_action("jump-left");
711 tux_body->set_action("jump-right");
715 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
718 tux_body->set_action("stand-left");
720 tux_body->set_action("stand-right");
725 tux_body->set_action("walk-left");
727 tux_body->set_action("walk-right");
731 if(idle_timer.check())
736 tux_body->head->set_action("idle-left", 1);
738 tux_body->head->set_action("idle-right", 1);
743 // Tux is holding something
744 if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
745 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
750 tux_body->arms->set_action("duck+grab-left");
752 tux_body->arms->set_action("duck+grab-right");
757 tux_body->arms->set_action("grab-left");
759 tux_body->arms->set_action("grab-right");
765 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
767 else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
769 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
770 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
772 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
773 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
776 else if (safe_timer.started() && size_t(game_time*40)%2)
779 tux_body->draw(context, get_pos(), layer);
781 // Draw blinking star overlay
782 if (invincible_timer.started() &&
783 (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
784 || size_t(game_time*20)%2)
787 if (!is_big() || duck)
788 smalltux_star->draw(context, get_pos(), layer + 5);
790 bigtux_star->draw(context, get_pos(), layer + 5);
795 Player::collision_tile(uint32_t tile_attributes)
797 if(tile_attributes & Tile::HURTS)
802 Player::collision(GameObject& other, const CollisionHit& hit)
804 Bullet* bullet = dynamic_cast<Bullet*> (&other);
809 if(other.get_flags() & FLAG_PORTABLE) {
810 Portable* portable = dynamic_cast<Portable*> (&other);
811 assert(portable != NULL);
812 if(portable && grabbed_object == NULL
813 && controller->hold(Controller::ACTION)
814 && fabsf(hit.normal.x) > .9) {
815 grabbed_object = portable;
816 grabbed_object->grab(*this, get_pos(), dir);
821 if(other.get_flags() & FLAG_SOLID) {
823 printf("Col %p: HN: %3.1f %3.1f D %.1f P: %3.1f %3.1f M: %3.1f %3.1f\n",
825 hit.normal.x, hit.normal.y, hit.depth,
826 get_pos().x, get_pos().y,
827 movement.x, movement.y);
830 if(hit.normal.y < 0) { // landed on floor?
831 if(physic.get_velocity_y() > 0)
832 physic.set_velocity_y(0);
834 on_ground_flag = true;
836 // remember normal of this tile
837 if (hit.normal.y > -0.9) {
838 floor_normal.x = hit.normal.x;
839 floor_normal.y = hit.normal.y;
841 // slowly adjust to unisolid tiles.
842 // Necessary because our bounding box sometimes reaches through slopes and thus hits unisolid tiles
843 floor_normal.x = (floor_normal.x * 0.9) + (hit.normal.x * 0.1);
844 floor_normal.y = (floor_normal.y * 0.9) + (hit.normal.y * 0.1);
847 // hack platforms so that we stand normally on them when going down...
848 Platform* platform = dynamic_cast<Platform*> (&other);
849 if(platform != NULL) {
850 if(platform->get_speed().y > 0)
851 physic.set_velocity_y(platform->get_speed().y);
852 //physic.set_velocity_x(platform->get_speed().x);
854 } else if(hit.normal.y > 0) { // bumped against the roof
855 physic.set_velocity_y(-.1);
857 // hack platform so that we are not glued to it from below
858 Platform* platform = dynamic_cast<Platform*> (&other);
859 if(platform != NULL) {
860 physic.set_velocity_y(platform->get_speed().y);
864 if(fabsf(hit.normal.x) > .9) { // hit on the side?
865 physic.set_velocity_x(0);
868 MovingObject* omov = dynamic_cast<MovingObject*> (&other);
870 Vector mov = movement - omov->get_movement();
872 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",
874 hit.normal.x, hit.normal.y,
876 movement.x, movement.y,
877 dest.p1.x, dest.p1.y,
878 omov->get_movement().x, omov->get_movement().y);
886 assert(dynamic_cast<MovingObject*> (&other) != NULL);
888 MovingObject* moving_object = static_cast<MovingObject*> (&other);
889 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
890 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
892 if(controller->pressed(Controller::UP))
893 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
899 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
901 if(safe_timer.started() || invincible_timer.started())
911 Player::make_invincible()
913 sound_manager->play("sounds/invincible.wav");
914 invincible_timer.start(TUX_INVINCIBLE_TIME);
915 Sector::current()->play_music(HERRING_MUSIC);
920 Player::kill(bool completely)
922 if(dying || deactivated)
925 if(!completely && safe_timer.started() || invincible_timer.started())
928 sound_manager->play("sounds/hurt.wav");
930 physic.set_velocity_x(0);
932 if(!completely && is_big()) {
933 if(player_status->bonus == FIRE_BONUS
934 || player_status->bonus == ICE_BONUS) {
935 safe_timer.start(TUX_SAFE_TIME);
936 set_bonus(GROWUP_BONUS);
938 //growing_timer.start(GROWING_TIME);
939 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
945 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
947 // the numbers: starting x, starting y, velocity y
948 Sector::current()->add_object(new FallingCoin(get_pos() +
949 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
950 systemRandom.rand(-100,100)));
952 physic.enable_gravity(true);
953 physic.set_acceleration(0, 0);
954 physic.set_velocity(0, -700);
955 player_status->coins -= 25;
958 dying_timer.start(3.0);
959 set_group(COLGROUP_DISABLED);
961 DisplayEffect* effect = new DisplayEffect();
962 effect->fade_out(3.0);
963 Sector::current()->add_object(effect);
964 sound_manager->stop_music(3.0);
969 Player::move(const Vector& vector)
973 // TODO: do we need the following? Seems irrelevant to moving the player
975 set_size(31.8, 63.8);
977 set_size(31.8, 31.8);
979 last_ground_y = vector.y;
985 Player::check_bounds(Camera* camera)
987 /* Keep tux in bounds: */
988 if (get_pos().x < 0) {
989 // Lock Tux to the size of the level, so that he doesn't fall of
991 set_pos(Vector(0, get_pos().y));
994 /* Keep in-bounds, vertically: */
995 if (get_pos().y > Sector::current()->solids->get_height() * 32) {
1000 bool adjust = false;
1001 // can happen if back scrolling is disabled
1002 if(get_pos().x < camera->get_translation().x) {
1003 set_pos(Vector(camera->get_translation().x, get_pos().y));
1006 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
1009 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
1018 if(collision_object_map(bbox)) {
1027 Player::add_velocity(const Vector& velocity)
1029 physic.set_velocity(physic.get_velocity() + velocity);
1033 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1035 if (end_speed.x > 0) physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1036 if (end_speed.x < 0) physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1037 if (end_speed.y > 0) physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1038 if (end_speed.y < 0) physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1042 Player::bounce(BadGuy& )
1044 if(controller->hold(Controller::JUMP))
1045 physic.set_velocity_y(-520);
1047 physic.set_velocity_y(-300);
1050 //Scripting Functions Below
1053 Player::deactivate()
1056 physic.set_velocity_x(0);
1057 physic.set_velocity_y(0);
1058 physic.set_acceleration_x(0);
1059 physic.set_acceleration_y(0);
1065 deactivated = false;
1068 void Player::walk(float speed)
1070 physic.set_velocity_x(speed);
1074 Player::set_ghost_mode(bool enable)
1076 if (ghost_mode == enable) return;
1079 set_group(COLGROUP_DISABLED);
1080 physic.enable_gravity(false);
1081 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1084 set_group(COLGROUP_MOVING);
1085 physic.enable_gravity(true);
1086 log_debug << "You feel solid again." << std::endl;