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;
68 Surface* growingtux_left[GROWING_FRAMES];
69 Surface* growingtux_right[GROWING_FRAMES];
71 Surface* tux_life = 0;
73 TuxBodyParts* small_tux = 0;
74 TuxBodyParts* big_tux = 0;
75 TuxBodyParts* fire_tux = 0;
76 TuxBodyParts* ice_tux = 0;
79 TuxBodyParts::set_action(std::string action, int loops)
82 head->set_action(action, loops);
84 body->set_action(action, loops);
86 arms->set_action(action, loops);
88 feet->set_action(action, loops);
92 TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer)
95 head->draw(context, pos, layer-1);
97 body->draw(context, pos, layer-3);
99 arms->draw(context, pos, layer+10);
101 feet->draw(context, pos, layer-2);
104 Player::Player(PlayerStatus* _player_status)
105 : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
107 controller = main_controller;
108 smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
109 smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite");
110 bigtux_star = sprite_manager->create("images/creatures/tux_big/bigtux-star.sprite");
112 sound_manager->preload("sounds/bigjump.wav");
113 sound_manager->preload("sounds/jump.wav");
114 sound_manager->preload("sounds/hurt.wav");
115 sound_manager->preload("sounds/skid.wav");
122 delete smalltux_gameover;
123 delete smalltux_star;
131 bbox.set_size(31.8, 62.8);
133 bbox.set_size(31.8, 30.8);
143 fall_mode = ON_GROUND;
148 backflipping = false;
149 backflip_direction = 0;
152 on_ground_flag = false;
153 grabbed_object = NULL;
155 floor_normal = Vector(0,-1);
161 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
163 Scripting::Player* interface = static_cast<Scripting::Player*> (this);
164 Scripting::expose_object(vm, table_idx, interface, "Tux", false);
168 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
170 Scripting::unexpose_object(vm, table_idx, "Tux");
174 Player::set_controller(Controller* controller)
176 this->controller = controller;
180 Player::update(float elapsed_time)
182 if(dying && dying_timer.check()) {
187 if(adjust_height != 0) {
188 bbox.move(Vector(0, bbox.get_height() - adjust_height));
189 bbox.set_height(adjust_height);
193 if(!dying && !deactivated)
196 movement = physic.get_movement(elapsed_time);
198 if(grabbed_object != NULL && !dying) {
199 Vector pos = get_pos() +
200 Vector(dir == LEFT ? -16 : 16,
201 bbox.get_height()*0.66666 - 32);
202 grabbed_object->grab(*this, pos, dir);
205 if(grabbed_object != NULL && dying){
206 grabbed_object->ungrab(*this, dir);
207 grabbed_object = NULL;
210 on_ground_flag = false;
216 return on_ground_flag;
222 if(player_status->bonus == NO_BONUS)
229 Player::handle_horizontal_input()
231 float vx = physic.get_velocity_x();
232 float vy = physic.get_velocity_y();
233 float ax = physic.get_acceleration_x();
234 float ay = physic.get_acceleration_y();
237 if(!duck || physic.get_velocity_y() != 0) {
238 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
242 } else if(!controller->hold(Controller::LEFT)
243 && controller->hold(Controller::RIGHT)) {
250 if (!controller->hold(Controller::ACTION)) {
251 ax = dirsign * WALK_ACCELERATION_X;
253 if(vx >= MAX_WALK_XM && dirsign > 0) {
256 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
261 ax = dirsign * RUN_ACCELERATION_X;
263 if(vx >= MAX_RUN_XM && dirsign > 0) {
266 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
272 // we can reach WALK_SPEED without any acceleration
273 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
274 vx = dirsign * WALK_SPEED;
277 // changing directions?
278 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
280 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
281 skidding_timer.start(SKID_TIME);
282 sound_manager->play("sounds/skid.wav");
283 // dust some particles
284 Sector::current()->add_object(
286 Vector(dir == RIGHT ? bbox.p2.x : bbox.p1.x, bbox.p2.y),
287 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
288 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
297 // we get slower when not pressing any keys
299 if ((on_ground()) && (fabs(vx) < WALK_SPEED)) {
303 ax = WALK_ACCELERATION_X * 1.5;
305 ax = WALK_ACCELERATION_X * -1.5;
310 // if we're on ice slow down acceleration or deceleration
311 if (isice(base.x, base.y + base.height))
313 /* the acceleration/deceleration rate on ice is inversely proportional to
314 * the current velocity.
317 // increasing 1 will increase acceleration/deceleration rate
318 // decreasing 1 will decrease acceleration/deceleration rate
319 // must stay above zero, though
320 if (ax != 0) ax *= 1 / fabs(vx);
324 // extend/shrink tux collision rectangle so that we fall through/walk over 1
326 if(fabsf(vx) > MAX_WALK_XM) {
329 bbox.set_width(31.8);
332 // on downward slopes, adjust vertical velocity to match slope angle
334 if (floor_normal.y != 0) {
335 if ((floor_normal.x * vx) > 0) {
336 // we overdo it a little, just to be on the safe side
337 vy = vx * (floor_normal.x / floor_normal.y) * 2;
342 physic.set_velocity(vx, vy);
343 physic.set_acceleration(ax, ay);
347 Player::handle_vertical_input()
351 fall_mode = ON_GROUND;
352 last_ground_y = get_pos().y;
354 if(get_pos().y > last_ground_y)
356 else if(fall_mode == ON_GROUND)
360 if(on_ground()) { /* Make sure jumping is off. */
363 backflipping = false;
364 backflip_direction = 0;
369 if(controller->pressed(Controller::JUMP) && can_jump && on_ground()) {
371 if (physic.get_velocity_x() != 0) // only jump a little bit when running ducked
372 physic.set_velocity_y(300);
373 else { //do a backflip
375 physic.set_velocity_y(580);
376 backflip_timer.start(0.15);
379 else if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) // jump higher if we are running
380 physic.set_velocity_y(580);
382 physic.set_velocity_y(520);
384 //bbox.move(Vector(0, -1));
388 sound_manager->play("sounds/bigjump.wav");
390 sound_manager->play("sounds/jump.wav");
391 } else if(!controller->hold(Controller::JUMP)) { // Let go of jump key
392 if (!backflipping && jumping && physic.get_velocity_y() > 0) {
394 physic.set_velocity_y(0);
398 /* In case the player has pressed Down while in a certain range of air,
399 enable butt jump action */
400 if (controller->hold(Controller::DOWN) && !butt_jump && !duck)
401 //if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
404 /* When Down is not held anymore, disable butt jump */
405 if(butt_jump && !controller->hold(Controller::DOWN))
410 if (butt_jump && on_ground() && is_big()) {
413 Sector::current()->add_smoke_cloud(Vector(get_pos().x - 32, get_pos().y));
415 Sector::current()->add_smoke_cloud(
416 Vector(get_pos().x - 32, get_pos().y + 32));
420 // Break bricks beneath Tux
421 if(Sector::current()->trybreakbrick(
422 Vector(base.x + 1, base.y + base.height), false)
423 || Sector::current()->trybreakbrick(
424 Vector(base.x + base.width - 1, base.y + base.height), false)) {
425 physic.set_velocity_y(2);
429 // Kill nearby badguys
430 std::vector<GameObject*> gameobjects = Sector::current()->gameobjects;
431 for (std::vector<GameObject*>::iterator i = gameobjects.begin();
432 i != gameobjects.end();
434 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
436 // don't kill when badguys are already dying or in a certain mode
437 if(badguy->dying == DYING_NOT && badguy->mode != BadGuy::BOMB_TICKING &&
438 badguy->mode != BadGuy::BOMB_EXPLODE) {
439 if (fabsf(base.x - badguy->base.x) < 96 &&
440 fabsf(base.y - badguy->base.y) < 64)
448 /** jumping is only allowed if we're about to touch ground soon and if the
449 * button has been up in between the last jump
453 if ( (issolid(get_pos().x + bbox.get_width() / 2,
454 get_pos().y + bbox.get_height() + 64) ||
455 issolid(get_pos().x + 1, get_pos().y + bbox.get_height() + 64) ||
456 issolid(get_pos().x + bbox.get_width() - 1,
457 get_pos().y + bbox.get_height() + 64))
460 && input.jump && !input.old_jump)
468 Player::handle_input()
471 handle_input_ghost();
475 if(!controller->hold(Controller::ACTION) && grabbed_object) {
476 // move the grabbed object a bit away from tux
477 Vector pos = get_pos() +
478 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
479 bbox.get_height()*0.66666 - 32);
480 Rect dest(pos, pos + Vector(32, 32));
481 if(Sector::current()->is_free_space(dest)) {
482 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
484 moving_object->set_pos(pos);
486 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
488 grabbed_object->ungrab(*this, dir);
489 grabbed_object = NULL;
493 /* Handle horizontal movement: */
494 if (!backflipping) handle_horizontal_input();
496 if (backflip_direction == 0) {
497 dir == LEFT ? backflip_direction = 1 : backflip_direction = -1;
499 else backflip_direction == 1 ? dir = LEFT : dir = RIGHT; //prevent player from changing direction when backflipping
500 if (backflip_timer.check()) physic.set_velocity_x(100 * backflip_direction);
505 if (on_ground() && !controller->hold(Controller::JUMP))
507 handle_vertical_input();
510 if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
511 if(Sector::current()->add_bullet(
512 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
513 : Vector(32, bbox.get_height()/2)),
514 physic.get_velocity_x(), dir))
515 shooting_timer.start(SHOOTING_TIME);
519 if (controller->hold(Controller::DOWN) && is_big() && !duck
520 && physic.get_velocity_y() == 0 && on_ground()) {
522 bbox.move(Vector(0, 32));
523 bbox.set_height(31.8);
524 } else if(!controller->hold(Controller::DOWN) && is_big() && duck) {
525 // if we have some velocity left then check if there is space for
527 bbox.move(Vector(0, -32));
528 bbox.set_height(63.8);
529 if(Sector::current()->is_free_space(bbox) || (
530 physic.get_velocity_x() > -.01 && physic.get_velocity_x() < .01
531 && physic.get_velocity_y() > -.01 && physic.get_velocity_y() < .01))
535 // undo the ducking changes
536 bbox.move(Vector(0, 32));
537 bbox.set_height(31.8);
543 Player::handle_input_ghost()
547 if (controller->hold(Controller::LEFT)) vx -= MAX_RUN_XM;
548 if (controller->hold(Controller::RIGHT)) vx += MAX_RUN_XM;
549 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) vy += MAX_RUN_XM;
550 if (controller->hold(Controller::DOWN)) vy -= MAX_RUN_XM;
551 if (controller->hold(Controller::ACTION)) set_ghost_mode(false);
552 physic.set_velocity(vx, vy);
553 physic.set_acceleration(0, 0);
557 Player::add_coins(int count)
559 player_status->add_coins(count);
563 Player::add_bonus(const std::string& bonustype)
565 if(bonustype == "grow") {
566 add_bonus(GROWUP_BONUS);
567 } else if(bonustype == "fireflower") {
568 add_bonus(FIRE_BONUS);
569 } else if(bonustype == "iceflower") {
570 add_bonus(ICE_BONUS);
571 } else if(bonustype == "none") {
574 std::ostringstream msg;
575 msg << "Unknown bonus type " << bonustype;
576 throw std::runtime_error(msg.str());
581 Player::add_bonus(BonusType type, bool animate)
583 // always ignore NO_BONUS
584 if (type == NO_BONUS) {
588 // ignore GROWUP_BONUS if we're already big
589 if (type == GROWUP_BONUS) {
590 if (player_status->bonus == GROWUP_BONUS) return;
591 if (player_status->bonus == FIRE_BONUS) return;
592 if (player_status->bonus == ICE_BONUS) return;
595 set_bonus(type, animate);
599 Player::set_bonus(BonusType type, bool animate)
601 if(player_status->bonus == NO_BONUS) {
602 adjust_height = 62.8;
604 growing_timer.start(GROWING_TIME);
607 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
608 player_status->max_fire_bullets = 0;
609 player_status->max_ice_bullets = 0;
611 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
612 if (type == ICE_BONUS) player_status->max_ice_bullets++;
614 player_status->bonus = type;
618 Player::set_visible(bool visible)
620 this->visible = visible;
624 Player::get_visible()
632 kick_timer.start(KICK_TIME);
636 Player::draw(DrawingContext& context)
641 TuxBodyParts* tux_body;
643 if (player_status->bonus == GROWUP_BONUS)
645 else if (player_status->bonus == FIRE_BONUS)
647 else if (player_status->bonus == ICE_BONUS)
650 tux_body = small_tux;
652 int layer = LAYER_OBJECTS + 1;
654 /* Set Tux sprite action */
655 if (duck && is_big())
658 tux_body->set_action("duck-left");
660 tux_body->set_action("duck-right");
662 else if (skidding_timer.started() && !skidding_timer.check())
665 tux_body->set_action("skid-left");
667 tux_body->set_action("skid-right");
669 else if (kick_timer.started() && !kick_timer.check())
672 tux_body->set_action("kick-left");
674 tux_body->set_action("kick-right");
676 else if (butt_jump && is_big())
679 tux_body->set_action("buttjump-left");
681 tux_body->set_action("buttjump-right");
683 else if (!on_ground())
686 tux_body->set_action("jump-left");
688 tux_body->set_action("jump-right");
692 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
695 tux_body->set_action("stand-left");
697 tux_body->set_action("stand-right");
702 tux_body->set_action("walk-left");
704 tux_body->set_action("walk-right");
708 if(idle_timer.check())
713 tux_body->head->set_action("idle-left", 1);
715 tux_body->head->set_action("idle-right", 1);
720 // Tux is holding something
721 if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
722 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
727 tux_body->arms->set_action("duck+grab-left");
729 tux_body->arms->set_action("duck+grab-right");
734 tux_body->arms->set_action("grab-left");
736 tux_body->arms->set_action("grab-right");
742 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
743 } else if(growing_timer.get_timeleft() > 0) {
745 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
746 GROWING_FRAMES) / GROWING_TIME)], get_pos() - Vector(0, 32), layer);
748 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
749 GROWING_FRAMES) / GROWING_TIME)], get_pos() - Vector(0, 32), layer);
752 else if (safe_timer.started() && size_t(game_time*40)%2)
755 tux_body->draw(context, get_pos(), layer);
757 // Draw blinking star overlay
758 if (invincible_timer.started() &&
759 (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
760 || size_t(game_time*20)%2)
763 if (!is_big() || duck)
764 smalltux_star->draw(context, get_pos(), layer + 5);
766 bigtux_star->draw(context, get_pos(), layer + 5);
771 Player::collision_tile(uint32_t tile_attributes)
773 if(tile_attributes & Tile::HURTS)
778 Player::collision(GameObject& other, const CollisionHit& hit)
780 Bullet* bullet = dynamic_cast<Bullet*> (&other);
785 if(other.get_flags() & FLAG_PORTABLE) {
786 Portable* portable = dynamic_cast<Portable*> (&other);
787 assert(portable != NULL);
788 if(portable && grabbed_object == NULL
789 && controller->hold(Controller::ACTION)
790 && fabsf(hit.normal.x) > .9) {
791 grabbed_object = portable;
792 grabbed_object->grab(*this, get_pos(), dir);
797 if(other.get_flags() & FLAG_SOLID) {
799 printf("Col %p: HN: %3.1f %3.1f D %.1f P: %3.1f %3.1f M: %3.1f %3.1f\n",
801 hit.normal.x, hit.normal.y, hit.depth,
802 get_pos().x, get_pos().y,
803 movement.x, movement.y);
806 if(hit.normal.y < 0) { // landed on floor?
807 if(physic.get_velocity_y() < 0)
808 physic.set_velocity_y(0);
810 on_ground_flag = true;
812 // remember normal of this tile
813 if (hit.normal.y > -0.9) {
814 floor_normal.x = hit.normal.x;
815 floor_normal.y = hit.normal.y;
817 // slowly adjust to unisolid tiles.
818 // Necessary because our bounding box sometimes reaches through slopes and thus hits unisolid tiles
819 floor_normal.x = (floor_normal.x * 0.9) + (hit.normal.x * 0.1);
820 floor_normal.y = (floor_normal.y * 0.9) + (hit.normal.y * 0.1);
823 // hack platforms so that we stand normally on them when going down...
824 Platform* platform = dynamic_cast<Platform*> (&other);
825 if(platform != NULL) {
826 if(platform->get_speed().y > 0)
827 physic.set_velocity_y(-platform->get_speed().y);
828 //physic.set_velocity_x(platform->get_speed().x);
830 } else if(hit.normal.y > 0) { // bumped against the roof
831 physic.set_velocity_y(.1);
833 // hack platform so that we are not glued to it from below
834 Platform* platform = dynamic_cast<Platform*> (&other);
835 if(platform != NULL) {
836 physic.set_velocity_y(-platform->get_speed().y);
840 if(fabsf(hit.normal.x) > .9) { // hit on the side?
841 physic.set_velocity_x(0);
844 MovingObject* omov = dynamic_cast<MovingObject*> (&other);
846 Vector mov = movement - omov->get_movement();
848 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",
850 hit.normal.x, hit.normal.y,
852 movement.x, movement.y,
853 dest.p1.x, dest.p1.y,
854 omov->get_movement().x, omov->get_movement().y);
862 assert(dynamic_cast<MovingObject*> (&other) != NULL);
864 MovingObject* moving_object = static_cast<MovingObject*> (&other);
865 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
866 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
868 if(controller->pressed(Controller::UP))
869 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
875 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
877 if(safe_timer.started() || invincible_timer.started())
887 Player::make_invincible()
889 sound_manager->play("sounds/invincible.wav");
890 invincible_timer.start(TUX_INVINCIBLE_TIME);
891 Sector::current()->play_music(HERRING_MUSIC);
896 Player::kill(bool completely)
898 if(dying || deactivated)
901 if(!completely && safe_timer.started() || invincible_timer.started())
904 sound_manager->play("sounds/hurt.wav");
906 physic.set_velocity_x(0);
908 if(!completely && is_big()) {
909 if(player_status->bonus == FIRE_BONUS
910 || player_status->bonus == ICE_BONUS) {
911 safe_timer.start(TUX_SAFE_TIME);
912 set_bonus(GROWUP_BONUS);
914 //growing_timer.start(GROWING_TIME);
915 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
916 adjust_height = 30.8;
921 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
923 // the numbers: starting x, starting y, velocity y
924 Sector::current()->add_object(new FallingCoin(get_pos() +
925 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
926 systemRandom.rand(-100,100)));
928 physic.enable_gravity(true);
929 physic.set_acceleration(0, 0);
930 physic.set_velocity(0, 700);
931 player_status->coins -= 25;
934 dying_timer.start(3.0);
935 set_group(COLGROUP_DISABLED);
937 DisplayEffect* effect = new DisplayEffect();
938 effect->fade_out(3.0);
939 Sector::current()->add_object(effect);
940 sound_manager->stop_music(3.0);
945 Player::move(const Vector& vector)
947 bbox.set_pos(vector);
949 bbox.set_size(31.8, 63.8);
951 bbox.set_size(31.8, 31.8);
953 last_ground_y = vector.y;
959 Player::check_bounds(Camera* camera)
961 /* Keep tux in bounds: */
962 if (get_pos().x < 0) {
963 // Lock Tux to the size of the level, so that he doesn't fall of
965 bbox.set_pos(Vector(0, get_pos().y));
968 /* Keep in-bounds, vertically: */
969 if (get_pos().y > Sector::current()->solids->get_height() * 32) {
975 // can happen if back scrolling is disabled
976 if(get_pos().x < camera->get_translation().x) {
977 bbox.set_pos(Vector(camera->get_translation().x, get_pos().y));
980 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
983 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
992 if(collision_object_map(bbox)) {
1001 Player::add_velocity(const Vector& velocity)
1003 physic.set_velocity(physic.get_velocity() + velocity);
1007 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1009 if (end_speed.x > 0) physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1010 if (end_speed.x < 0) physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1011 if (end_speed.y > 0) physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1012 if (end_speed.y < 0) physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1016 Player::bounce(BadGuy& )
1018 if(controller->hold(Controller::JUMP))
1019 physic.set_velocity_y(520);
1021 physic.set_velocity_y(300);
1024 //Scripting Functions Below
1027 Player::deactivate()
1030 physic.set_velocity_x(0);
1031 physic.set_velocity_y(0);
1032 physic.set_acceleration_x(0);
1033 physic.set_acceleration_y(0);
1039 deactivated = false;
1042 void Player::walk(float speed)
1044 physic.set_velocity_x(speed);
1048 Player::set_ghost_mode(bool enable)
1050 if (ghost_mode == enable) return;
1053 set_group(COLGROUP_DISABLED);
1054 physic.enable_gravity(false);
1055 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1058 set_group(COLGROUP_MOVING);
1059 physic.enable_gravity(true);
1060 log_debug << "You feel solid again." << std::endl;