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, std::string name) :
112 MovingObject(name), player_status(_player_status), grabbed_object(NULL),
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");
120 sound_manager->preload("sounds/bigjump.wav");
121 sound_manager->preload("sounds/jump.wav");
122 sound_manager->preload("sounds/hurt.wav");
123 sound_manager->preload("sounds/skid.wav");
124 sound_manager->preload("sounds/flip.wav");
125 sound_manager->preload("sounds/invincible.wav");
126 sound_manager->preload("sounds/splash.ogg");
134 delete smalltux_gameover;
135 delete smalltux_star;
143 set_size(31.8, 62.8);
145 set_size(31.8, 30.8);
155 fall_mode = ON_GROUND;
160 backflipping = false;
161 backflip_direction = 0;
165 on_ground_flag = false;
166 grabbed_object = NULL;
172 Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
174 if (name.empty()) return;
175 Scripting::expose_object(vm, table_idx, dynamic_cast<Scripting::Player *>(this), name, false);
179 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
181 if (name.empty()) return;
182 Scripting::unexpose_object(vm, table_idx, name);
186 Player::set_controller(Controller* controller)
188 this->controller = controller;
192 Player::adjust_height(float new_height)
195 bbox2.move(Vector(0, bbox.get_height() - new_height));
196 bbox2.set_height(new_height);
198 if(new_height > bbox.get_height()) {
199 Rect additional_space = bbox2;
200 additional_space.set_height(new_height - bbox.get_height());
201 if(!Sector::current()->is_free_space(additional_space))
205 // adjust bbox accordingly
206 // note that we use members of moving_object for this, so we can run this during CD, too
208 set_size(bbox2.get_width(), bbox2.get_height());
213 Player::update(float elapsed_time)
220 if(dying && dying_timer.check()) {
225 if(!dying && !deactivated)
228 // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
229 if (deactivated) apply_friction();
231 // extend/shrink tux collision rectangle so that we fall through/walk over 1
233 if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
239 // on downward slopes, adjust vertical velocity so tux walks smoothly down
241 if(floor_normal.y != 0) {
242 if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
243 physic.set_velocity_y(250);
248 // handle backflipping
250 //prevent player from changing direction when backflipping
251 dir = (backflip_direction == 1) ? LEFT : RIGHT;
252 if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
257 fall_mode = ON_GROUND;
258 last_ground_y = get_pos().y;
260 if(get_pos().y > last_ground_y)
262 else if(fall_mode == ON_GROUND)
266 // check if we landed
269 if (backflipping && (!backflip_timer.started())) {
270 backflipping = false;
271 backflip_direction = 0;
273 // if controls are currently deactivated, we take care of standing up ourselves
279 // calculate movement for this frame
280 movement = physic.get_movement(elapsed_time);
282 if(grabbed_object != NULL && !dying) {
283 Vector pos = get_pos() +
284 Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
285 grabbed_object->grab(*this, pos, dir);
288 if(grabbed_object != NULL && dying){
289 grabbed_object->ungrab(*this, dir);
290 grabbed_object = NULL;
293 on_ground_flag = false;
295 // when invincible, spawn particles
296 if (invincible_timer.started() && !dying)
298 if (systemRandom.rand(0, 2) == 0) {
299 float px = systemRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
300 float py = systemRandom.randf(bbox.p1.y+0, bbox.p2.y-0);
301 Vector ppos = Vector(px, py);
302 Vector pspeed = Vector(0, 0);
303 Vector paccel = Vector(0, 0);
304 // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
305 if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
306 // make every other a longer sparkle to make trail a bit fuzzy
307 if (size_t(game_time*20)%2) {
308 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
310 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
313 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
323 return on_ground_flag;
329 if(player_status->bonus == NO_BONUS)
336 Player::apply_friction()
338 if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
339 physic.set_velocity_x(0);
340 physic.set_acceleration_x(0);
341 } else if(physic.get_velocity_x() < 0) {
342 physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5);
344 physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5);
349 Player::handle_horizontal_input()
351 float vx = physic.get_velocity_x();
352 float vy = physic.get_velocity_y();
353 float ax = physic.get_acceleration_x();
354 float ay = physic.get_acceleration_y();
357 if(!duck || physic.get_velocity_y() != 0) {
358 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
362 } else if(!controller->hold(Controller::LEFT)
363 && controller->hold(Controller::RIGHT)) {
370 // only run if action key is pressed and we're not holding anything
371 if (!(controller->hold(Controller::ACTION) && (!grabbed_object))) {
372 ax = dirsign * WALK_ACCELERATION_X;
374 if(vx >= MAX_WALK_XM && dirsign > 0) {
377 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
382 ax = dirsign * RUN_ACCELERATION_X;
384 if(vx >= MAX_RUN_XM && dirsign > 0) {
387 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
393 // we can reach WALK_SPEED without any acceleration
394 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
395 vx = dirsign * WALK_SPEED;
398 // changing directions?
399 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
401 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
402 skidding_timer.start(SKID_TIME);
403 sound_manager->play("sounds/skid.wav");
404 // dust some particles
405 Sector::current()->add_object(
407 Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
408 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
409 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
418 physic.set_velocity(vx, vy);
419 physic.set_acceleration(ax, ay);
421 // we get slower when not pressing any keys
443 if (physic.get_velocity_y() != 0)
448 if (adjust_height(31.8)) {
450 unduck_hurt_timer.stop();
457 Player::do_standup() {
465 if (adjust_height(63.8)) {
467 unduck_hurt_timer.stop();
469 // if timer is not already running, start it.
470 if (unduck_hurt_timer.get_period() == 0) {
471 unduck_hurt_timer.start(UNDUCK_HURT_TIME);
473 else if (unduck_hurt_timer.check()) {
481 Player::do_backflip() {
487 // TODO: we don't have an animation for firetux backflipping, so let's revert to bigtux
488 set_bonus(GROWUP_BONUS, true);
490 backflip_direction = (dir == LEFT)?(+1):(-1);
493 sound_manager->play("sounds/flip.wav");
494 backflip_timer.start(0.15);
498 Player::do_jump(float yspeed) {
502 physic.set_velocity_y(yspeed);
503 //bbox.move(Vector(0, -1));
505 on_ground_flag = false;
510 sound_manager->play("sounds/bigjump.wav");
512 sound_manager->play("sounds/jump.wav");
517 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))
548 physic.set_acceleration_y(0);
550 if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP)) physic.set_acceleration_y(-2000);
551 physic.set_velocity_y(physic.get_velocity_y() * 0.94);
556 Player::handle_input()
559 handle_input_ghost();
563 if(!controller->hold(Controller::ACTION) && grabbed_object) {
564 // move the grabbed object a bit away from tux
565 Vector pos = get_pos() +
566 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
567 bbox.get_height()*0.66666 - 32);
568 Rect dest(pos, pos + Vector(32, 32));
569 if(Sector::current()->is_free_space(dest)) {
570 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
572 moving_object->set_pos(pos);
574 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
576 grabbed_object->ungrab(*this, dir);
577 grabbed_object = NULL;
582 if( controller->released( Controller::PEEK_LEFT ) ) {
585 if( controller->released( Controller::PEEK_RIGHT ) ) {
588 if( controller->pressed( Controller::PEEK_LEFT ) ) {
591 if( controller->pressed( Controller::PEEK_RIGHT ) ) {
595 /* Handle horizontal movement: */
596 if (!backflipping) handle_horizontal_input();
599 if (on_ground() && !controller->hold(Controller::JUMP))
602 /* Handle vertical movement: */
603 handle_vertical_input();
606 if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
607 if(Sector::current()->add_bullet(
608 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
609 : Vector(32, bbox.get_height()/2)),
610 physic.get_velocity_x(), dir))
611 shooting_timer.start(SHOOTING_TIME);
614 /* Duck or Standup! */
615 if (controller->hold(Controller::DOWN)) do_duck(); else do_standup();
620 Player::handle_input_ghost()
624 if (controller->hold(Controller::LEFT)) {
626 vx -= MAX_RUN_XM * 2;
628 if (controller->hold(Controller::RIGHT)) {
630 vx += MAX_RUN_XM * 2;
632 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
633 vy -= MAX_RUN_XM * 2;
635 if (controller->hold(Controller::DOWN)) {
636 vy += MAX_RUN_XM * 2;
638 if (controller->hold(Controller::ACTION)) {
639 set_ghost_mode(false);
641 physic.set_velocity(vx, vy);
642 physic.set_acceleration(0, 0);
646 Player::add_coins(int count)
648 player_status->add_coins(count);
652 Player::add_bonus(const std::string& bonustype)
654 BonusType type = NO_BONUS;
656 if(bonustype == "grow") {
658 } else if(bonustype == "fireflower") {
660 } else if(bonustype == "iceflower") {
662 } else if(bonustype == "none") {
665 std::ostringstream msg;
666 msg << "Unknown bonus type " << bonustype;
667 throw std::runtime_error(msg.str());
670 return add_bonus(type);
674 Player::add_bonus(BonusType type, bool animate)
676 // always ignore NO_BONUS
677 if (type == NO_BONUS) {
681 // ignore GROWUP_BONUS if we're already big
682 if (type == GROWUP_BONUS) {
683 if (player_status->bonus == GROWUP_BONUS)
685 if (player_status->bonus == FIRE_BONUS)
687 if (player_status->bonus == ICE_BONUS)
691 return set_bonus(type, animate);
695 Player::set_bonus(BonusType type, bool animate)
697 if(player_status->bonus == NO_BONUS) {
698 if (!adjust_height(62.8)) {
699 printf("can't adjust\n");
703 growing_timer.start(GROWING_TIME);
706 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
707 if ((player_status->bonus == FIRE_BONUS) && (animate)) {
708 // visually lose helmet
709 Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
710 Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
711 Vector paccel = Vector(0, 1000);
712 std::string action = (dir==LEFT)?"left":"right";
713 Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
715 player_status->max_fire_bullets = 0;
716 player_status->max_ice_bullets = 0;
718 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
719 if (type == ICE_BONUS) player_status->max_ice_bullets++;
721 player_status->bonus = type;
726 Player::set_visible(bool visible)
728 this->visible = visible;
730 set_group(COLGROUP_MOVING);
732 set_group(COLGROUP_DISABLED);
736 Player::get_visible()
744 kick_timer.start(KICK_TIME);
748 Player::draw(DrawingContext& context)
753 TuxBodyParts* tux_body;
755 if (player_status->bonus == GROWUP_BONUS)
757 else if (player_status->bonus == FIRE_BONUS)
759 else if (player_status->bonus == ICE_BONUS)
762 tux_body = small_tux;
764 int layer = LAYER_OBJECTS + 1;
766 /* Set Tux sprite action */
770 tux_body->set_action("backflip-left");
772 tux_body->set_action("backflip-right");
774 else if (duck && is_big())
777 tux_body->set_action("duck-left");
779 tux_body->set_action("duck-right");
781 else if (skidding_timer.started() && !skidding_timer.check())
784 tux_body->set_action("skid-left");
786 tux_body->set_action("skid-right");
788 else if (kick_timer.started() && !kick_timer.check())
791 tux_body->set_action("kick-left");
793 tux_body->set_action("kick-right");
795 else if (butt_jump && is_big())
798 tux_body->set_action("buttjump-left");
800 tux_body->set_action("buttjump-right");
802 else if (!on_ground())
805 tux_body->set_action("jump-left");
807 tux_body->set_action("jump-right");
811 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
814 tux_body->set_action("stand-left");
816 tux_body->set_action("stand-right");
821 tux_body->set_action("walk-left");
823 tux_body->set_action("walk-right");
827 if(idle_timer.check())
832 tux_body->head->set_action("idle-left", 1);
834 tux_body->head->set_action("idle-right", 1);
839 // Tux is holding something
840 if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
841 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
846 tux_body->arms->set_action("duck+grab-left");
848 tux_body->arms->set_action("duck+grab-right");
853 tux_body->arms->set_action("grab-left");
855 tux_body->arms->set_action("grab-right");
861 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
863 else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
865 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
866 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
868 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
869 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
872 else if (safe_timer.started() && size_t(game_time*40)%2)
875 tux_body->draw(context, get_pos(), layer);
880 Player::collision_tile(uint32_t tile_attributes)
882 if(tile_attributes & Tile::HURTS)
886 if( tile_attributes & Tile::WATER ){
892 if( tile_attributes & Tile::WATER ){
895 sound_manager->play( "sounds/splash.ogg" );
901 Player::collision_solid(const CollisionHit& hit)
904 if(physic.get_velocity_y() > 0)
905 physic.set_velocity_y(0);
907 on_ground_flag = true;
908 floor_normal = hit.slope_normal;
910 if(physic.get_velocity_y() < 0)
911 physic.set_velocity_y(.2);
914 if(hit.left || hit.right) {
915 physic.set_velocity_x(0);
920 if(hit.left || hit.right) {
922 } else if(hit.top || hit.bottom) {
929 Player::collision(GameObject& other, const CollisionHit& hit)
931 Bullet* bullet = dynamic_cast<Bullet*> (&other);
936 // if we hit something from the side that is portable, the ACTION button is pressed and we are not already holding anything: grab it
937 Portable* portable = dynamic_cast<Portable*> (&other);
938 if ((hit.left || hit.right) && (portable && portable->is_portable()) && controller->hold(Controller::ACTION) && (!grabbed_object)) {
939 grabbed_object = portable;
940 grabbed_object->grab(*this, get_pos(), dir);
945 assert(dynamic_cast<MovingObject*> (&other) != NULL);
947 MovingObject* moving_object = static_cast<MovingObject*> (&other);
948 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
949 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
951 if(controller->pressed(Controller::UP))
952 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
958 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
960 if(safe_timer.started() || invincible_timer.started())
970 Player::make_invincible()
972 sound_manager->play("sounds/invincible.wav");
973 invincible_timer.start(TUX_INVINCIBLE_TIME);
974 Sector::current()->play_music(HERRING_MUSIC);
979 Player::kill(bool completely)
981 if(dying || deactivated)
984 if(!completely && (safe_timer.started() || invincible_timer.started()))
987 sound_manager->play("sounds/hurt.wav");
989 physic.set_velocity_x(0);
991 if(!completely && is_big()) {
992 if(player_status->bonus == FIRE_BONUS
993 || player_status->bonus == ICE_BONUS) {
994 safe_timer.start(TUX_SAFE_TIME);
995 set_bonus(GROWUP_BONUS, true);
997 //growing_timer.start(GROWING_TIME);
998 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
1001 set_bonus(NO_BONUS, true);
1004 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
1006 // the numbers: starting x, starting y, velocity y
1007 Sector::current()->add_object(new FallingCoin(get_pos() +
1008 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
1009 systemRandom.rand(-100,100)));
1011 physic.enable_gravity(true);
1012 physic.set_acceleration(0, 0);
1013 physic.set_velocity(0, -700);
1014 player_status->coins -= 25;
1015 set_bonus(NO_BONUS, true);
1017 dying_timer.start(3.0);
1018 set_group(COLGROUP_DISABLED);
1020 DisplayEffect* effect = new DisplayEffect();
1021 effect->fade_out(3.0);
1022 Sector::current()->add_object(effect);
1023 sound_manager->stop_music(3.0);
1028 Player::move(const Vector& vector)
1032 // TODO: do we need the following? Seems irrelevant to moving the player
1034 set_size(31.8, 63.8);
1036 set_size(31.8, 31.8);
1038 last_ground_y = vector.y;
1044 Player::check_bounds(Camera* camera)
1046 /* Keep tux in bounds: */
1047 if (get_pos().x < 0) {
1048 // Lock Tux to the size of the level, so that he doesn't fall of
1050 set_pos(Vector(0, get_pos().y));
1053 /* fallen out of the level? */
1054 if (get_pos().y > Sector::current()->get_height()) {
1059 // can happen if back scrolling is disabled
1060 if(get_pos().x < camera->get_translation().x) {
1061 set_pos(Vector(camera->get_translation().x, get_pos().y));
1063 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
1066 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
1072 Player::add_velocity(const Vector& velocity)
1074 physic.set_velocity(physic.get_velocity() + velocity);
1078 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1080 if (end_speed.x > 0)
1081 physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1082 if (end_speed.x < 0)
1083 physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1084 if (end_speed.y > 0)
1085 physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1086 if (end_speed.y < 0)
1087 physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1091 Player::bounce(BadGuy& )
1093 if(controller->hold(Controller::JUMP))
1094 physic.set_velocity_y(-520);
1096 physic.set_velocity_y(-300);
1099 //Scripting Functions Below
1102 Player::deactivate()
1107 physic.set_velocity_x(0);
1108 physic.set_velocity_y(0);
1109 physic.set_acceleration_x(0);
1110 physic.set_acceleration_y(0);
1118 deactivated = false;
1121 void Player::walk(float speed)
1123 physic.set_velocity_x(speed);
1127 Player::set_ghost_mode(bool enable)
1129 if (ghost_mode == enable)
1134 set_group(COLGROUP_DISABLED);
1135 physic.enable_gravity(false);
1136 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1139 set_group(COLGROUP_MOVING);
1140 physic.enable_gravity(true);
1141 log_debug << "You feel solid again." << std::endl;