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");
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)
177 Scripting::expose_object(vm, table_idx, dynamic_cast<Scripting::Player *>(this), name, false);
181 Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
186 Scripting::unexpose_object(vm, table_idx, name);
190 Player::set_controller(Controller* controller)
192 this->controller = controller;
196 Player::adjust_height(float new_height)
199 bbox2.move(Vector(0, bbox.get_height() - new_height));
200 bbox2.set_height(new_height);
202 if(new_height > bbox.get_height()) {
203 Rect additional_space = bbox2;
204 additional_space.set_height(new_height - bbox.get_height());
205 if(!Sector::current()->is_free_space(additional_space))
209 // adjust bbox accordingly
210 // note that we use members of moving_object for this, so we can run this during CD, too
212 set_size(bbox2.get_width(), bbox2.get_height());
217 Player::update(float elapsed_time)
224 if(dying && dying_timer.check()) {
229 if(!dying && !deactivated)
232 // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
233 if (deactivated) apply_friction();
235 // extend/shrink tux collision rectangle so that we fall through/walk over 1
237 if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
243 // on downward slopes, adjust vertical velocity so tux walks smoothly down
245 if(floor_normal.y != 0) {
246 if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
247 physic.set_velocity_y(250);
252 // handle backflipping
254 //prevent player from changing direction when backflipping
255 dir = (backflip_direction == 1) ? LEFT : RIGHT;
256 if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
261 fall_mode = ON_GROUND;
262 last_ground_y = get_pos().y;
264 if(get_pos().y > last_ground_y)
266 else if(fall_mode == ON_GROUND)
270 // check if we landed
273 if (backflipping && (!backflip_timer.started())) {
274 backflipping = false;
275 backflip_direction = 0;
277 // if controls are currently deactivated, we take care of standing up ourselves
283 // calculate movement for this frame
284 movement = physic.get_movement(elapsed_time);
286 if(grabbed_object != NULL && !dying) {
287 Vector pos = get_pos() +
288 Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
289 grabbed_object->grab(*this, pos, dir);
292 if(grabbed_object != NULL && dying){
293 grabbed_object->ungrab(*this, dir);
294 grabbed_object = NULL;
297 on_ground_flag = false;
299 // when invincible, spawn particles
300 if (invincible_timer.started() && !dying)
302 if (systemRandom.rand(0, 2) == 0) {
303 float px = systemRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
304 float py = systemRandom.randf(bbox.p1.y+0, bbox.p2.y-0);
305 Vector ppos = Vector(px, py);
306 Vector pspeed = Vector(0, 0);
307 Vector paccel = Vector(0, 0);
308 // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
309 if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
310 // make every other a longer sparkle to make trail a bit fuzzy
311 if (size_t(game_time*20)%2) {
312 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
314 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
317 Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
327 return on_ground_flag;
333 if(player_status->bonus == NO_BONUS)
340 Player::apply_friction()
342 if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
343 physic.set_velocity_x(0);
344 physic.set_acceleration_x(0);
345 } else if(physic.get_velocity_x() < 0) {
346 physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5);
348 physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5);
353 Player::handle_horizontal_input()
355 float vx = physic.get_velocity_x();
356 float vy = physic.get_velocity_y();
357 float ax = physic.get_acceleration_x();
358 float ay = physic.get_acceleration_y();
361 if(!duck || physic.get_velocity_y() != 0) {
362 if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
366 } else if(!controller->hold(Controller::LEFT)
367 && controller->hold(Controller::RIGHT)) {
374 // only run if action key is pressed and we're not holding anything
375 if (!(controller->hold(Controller::ACTION) && (!grabbed_object))) {
376 ax = dirsign * WALK_ACCELERATION_X;
378 if(vx >= MAX_WALK_XM && dirsign > 0) {
381 } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
386 ax = dirsign * RUN_ACCELERATION_X;
388 if(vx >= MAX_RUN_XM && dirsign > 0) {
391 } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
397 // we can reach WALK_SPEED without any acceleration
398 if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
399 vx = dirsign * WALK_SPEED;
402 // changing directions?
403 if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
405 if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
406 skidding_timer.start(SKID_TIME);
407 sound_manager->play("sounds/skid.wav");
408 // dust some particles
409 Sector::current()->add_object(
411 Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
412 dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
413 Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
422 physic.set_velocity(vx, vy);
423 physic.set_acceleration(ax, ay);
425 // we get slower when not pressing any keys
447 if (physic.get_velocity_y() != 0)
452 if (adjust_height(31.8)) {
454 unduck_hurt_timer.stop();
461 Player::do_standup() {
469 if (adjust_height(63.8)) {
471 unduck_hurt_timer.stop();
473 // if timer is not already running, start it.
474 if (unduck_hurt_timer.get_period() == 0) {
475 unduck_hurt_timer.start(UNDUCK_HURT_TIME);
477 else if (unduck_hurt_timer.check()) {
485 Player::do_backflip() {
491 // TODO: we don't have an animation for firetux backflipping, so let's revert to bigtux
492 set_bonus(GROWUP_BONUS, true);
494 backflip_direction = (dir == LEFT)?(+1):(-1);
497 sound_manager->play("sounds/flip.wav");
498 backflip_timer.start(0.15);
502 Player::do_jump(float yspeed) {
506 physic.set_velocity_y(yspeed);
507 //bbox.move(Vector(0, -1));
509 on_ground_flag = false;
514 sound_manager->play("sounds/bigjump.wav");
516 sound_manager->play("sounds/jump.wav");
521 Player::handle_vertical_input()
524 if(controller->pressed(Controller::JUMP) && (can_jump)) {
526 // when running, only jump a little bit; else do a backflip
527 if (physic.get_velocity_x() != 0) do_jump(-300); else do_backflip();
529 // jump a bit higher if we are running; else do a normal jump
530 if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
533 // Let go of jump key
534 else if(!controller->hold(Controller::JUMP)) {
535 if (!backflipping && jumping && physic.get_velocity_y() < 0) {
537 physic.set_velocity_y(0);
541 /* In case the player has pressed Down while in a certain range of air,
542 enable butt jump action */
543 if (controller->hold(Controller::DOWN) && !butt_jump && !duck && is_big() && jumping) {
547 /* When Down is not held anymore, disable butt jump */
548 if(butt_jump && !controller->hold(Controller::DOWN))
552 physic.set_acceleration_y(0);
554 if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP)) physic.set_acceleration_y(-2000);
555 physic.set_velocity_y(physic.get_velocity_y() * 0.94);
560 Player::handle_input()
563 handle_input_ghost();
567 if(!controller->hold(Controller::ACTION) && grabbed_object) {
568 // move the grabbed object a bit away from tux
569 Vector pos = get_pos() +
570 Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
571 bbox.get_height()*0.66666 - 32);
572 Rect dest(pos, pos + Vector(32, 32));
573 if(Sector::current()->is_free_space(dest)) {
574 MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
576 moving_object->set_pos(pos);
578 log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
580 grabbed_object->ungrab(*this, dir);
581 grabbed_object = NULL;
586 if( controller->released( Controller::PEEK_LEFT ) ) {
589 if( controller->released( Controller::PEEK_RIGHT ) ) {
592 if( controller->pressed( Controller::PEEK_LEFT ) ) {
595 if( controller->pressed( Controller::PEEK_RIGHT ) ) {
599 /* Handle horizontal movement: */
600 if (!backflipping) handle_horizontal_input();
603 if (on_ground() && !controller->hold(Controller::JUMP))
606 /* Handle vertical movement: */
607 handle_vertical_input();
610 if (controller->pressed(Controller::ACTION) && player_status->bonus == FIRE_BONUS) {
611 if(Sector::current()->add_bullet(
612 get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
613 : Vector(32, bbox.get_height()/2)),
614 physic.get_velocity_x(), dir))
615 shooting_timer.start(SHOOTING_TIME);
618 /* Duck or Standup! */
619 if (controller->hold(Controller::DOWN)) do_duck(); else do_standup();
624 Player::handle_input_ghost()
628 if (controller->hold(Controller::LEFT)) {
630 vx -= MAX_RUN_XM * 2;
632 if (controller->hold(Controller::RIGHT)) {
634 vx += MAX_RUN_XM * 2;
636 if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
637 vy -= MAX_RUN_XM * 2;
639 if (controller->hold(Controller::DOWN)) {
640 vy += MAX_RUN_XM * 2;
642 if (controller->hold(Controller::ACTION)) {
643 set_ghost_mode(false);
645 physic.set_velocity(vx, vy);
646 physic.set_acceleration(0, 0);
650 Player::add_coins(int count)
652 player_status->add_coins(count);
656 Player::add_bonus(const std::string& bonustype)
658 BonusType type = NO_BONUS;
660 if(bonustype == "grow") {
662 } else if(bonustype == "fireflower") {
664 } else if(bonustype == "iceflower") {
666 } else if(bonustype == "none") {
669 std::ostringstream msg;
670 msg << "Unknown bonus type " << bonustype;
671 throw std::runtime_error(msg.str());
674 return add_bonus(type);
678 Player::add_bonus(BonusType type, bool animate)
680 // always ignore NO_BONUS
681 if (type == NO_BONUS) {
685 // ignore GROWUP_BONUS if we're already big
686 if (type == GROWUP_BONUS) {
687 if (player_status->bonus == GROWUP_BONUS)
689 if (player_status->bonus == FIRE_BONUS)
691 if (player_status->bonus == ICE_BONUS)
695 return set_bonus(type, animate);
699 Player::set_bonus(BonusType type, bool animate)
701 if(player_status->bonus == NO_BONUS) {
702 if (!adjust_height(62.8)) {
703 printf("can't adjust\n");
707 growing_timer.start(GROWING_TIME);
710 if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
711 if ((player_status->bonus == FIRE_BONUS) && (animate)) {
712 // visually lose helmet
713 Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
714 Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
715 Vector paccel = Vector(0, 1000);
716 std::string action = (dir==LEFT)?"left":"right";
717 Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
719 player_status->max_fire_bullets = 0;
720 player_status->max_ice_bullets = 0;
722 if (type == FIRE_BONUS) player_status->max_fire_bullets++;
723 if (type == ICE_BONUS) player_status->max_ice_bullets++;
725 player_status->bonus = type;
730 Player::set_visible(bool visible)
732 this->visible = visible;
734 set_group(COLGROUP_MOVING);
736 set_group(COLGROUP_DISABLED);
740 Player::get_visible()
748 kick_timer.start(KICK_TIME);
752 Player::draw(DrawingContext& context)
757 TuxBodyParts* tux_body;
759 if (player_status->bonus == GROWUP_BONUS)
761 else if (player_status->bonus == FIRE_BONUS)
763 else if (player_status->bonus == ICE_BONUS)
766 tux_body = small_tux;
768 int layer = LAYER_OBJECTS + 1;
770 /* Set Tux sprite action */
774 tux_body->set_action("backflip-left");
776 tux_body->set_action("backflip-right");
778 else if (duck && is_big())
781 tux_body->set_action("duck-left");
783 tux_body->set_action("duck-right");
785 else if (skidding_timer.started() && !skidding_timer.check())
788 tux_body->set_action("skid-left");
790 tux_body->set_action("skid-right");
792 else if (kick_timer.started() && !kick_timer.check())
795 tux_body->set_action("kick-left");
797 tux_body->set_action("kick-right");
799 else if (butt_jump && is_big())
802 tux_body->set_action("buttjump-left");
804 tux_body->set_action("buttjump-right");
806 else if (!on_ground())
809 tux_body->set_action("jump-left");
811 tux_body->set_action("jump-right");
815 if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
818 tux_body->set_action("stand-left");
820 tux_body->set_action("stand-right");
825 tux_body->set_action("walk-left");
827 tux_body->set_action("walk-right");
831 if(idle_timer.check())
836 tux_body->head->set_action("idle-left", 1);
838 tux_body->head->set_action("idle-right", 1);
843 // Tux is holding something
844 if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
845 (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
850 tux_body->arms->set_action("duck+grab-left");
852 tux_body->arms->set_action("duck+grab-right");
857 tux_body->arms->set_action("grab-left");
859 tux_body->arms->set_action("grab-right");
865 smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
867 else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
869 context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
870 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
872 context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
873 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
876 else if (safe_timer.started() && size_t(game_time*40)%2)
879 tux_body->draw(context, get_pos(), layer);
884 Player::collision_tile(uint32_t tile_attributes)
886 if(tile_attributes & Tile::HURTS)
890 if( tile_attributes & Tile::WATER ){
896 if( tile_attributes & Tile::WATER ){
899 sound_manager->play( "sounds/splash.ogg" );
905 Player::collision_solid(const CollisionHit& hit)
908 if(physic.get_velocity_y() > 0)
909 physic.set_velocity_y(0);
911 on_ground_flag = true;
912 floor_normal = hit.slope_normal;
914 if(physic.get_velocity_y() < 0)
915 physic.set_velocity_y(.2);
918 if(hit.left || hit.right) {
919 physic.set_velocity_x(0);
924 if(hit.left || hit.right) {
926 } else if(hit.top || hit.bottom) {
933 Player::collision(GameObject& other, const CollisionHit& hit)
935 Bullet* bullet = dynamic_cast<Bullet*> (&other);
940 // if we hit something from the side that is portable, the ACTION button is pressed and we are not already holding anything: grab it
941 Portable* portable = dynamic_cast<Portable*> (&other);
942 if ((hit.left || hit.right) && (portable && portable->is_portable()) && controller->hold(Controller::ACTION) && (!grabbed_object)) {
943 grabbed_object = portable;
944 grabbed_object->grab(*this, get_pos(), dir);
949 assert(dynamic_cast<MovingObject*> (&other) != NULL);
951 MovingObject* moving_object = static_cast<MovingObject*> (&other);
952 if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
953 TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
955 if(controller->pressed(Controller::UP))
956 trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
962 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
964 if(safe_timer.started() || invincible_timer.started())
974 Player::make_invincible()
976 sound_manager->play("sounds/invincible.wav");
977 invincible_timer.start(TUX_INVINCIBLE_TIME);
978 Sector::current()->play_music(HERRING_MUSIC);
983 Player::kill(bool completely)
985 if(dying || deactivated)
988 if(!completely && (safe_timer.started() || invincible_timer.started()))
991 sound_manager->play("sounds/hurt.wav");
993 physic.set_velocity_x(0);
995 if(!completely && is_big()) {
996 if(player_status->bonus == FIRE_BONUS
997 || player_status->bonus == ICE_BONUS) {
998 safe_timer.start(TUX_SAFE_TIME);
999 set_bonus(GROWUP_BONUS, true);
1001 //growing_timer.start(GROWING_TIME);
1002 safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
1003 adjust_height(30.8);
1005 set_bonus(NO_BONUS, true);
1008 for (int i = 0; (i < 5) && (i < player_status->coins); i++)
1010 // the numbers: starting x, starting y, velocity y
1011 Sector::current()->add_object(new FallingCoin(get_pos() +
1012 Vector(systemRandom.rand(5), systemRandom.rand(-32,18)),
1013 systemRandom.rand(-100,100)));
1015 physic.enable_gravity(true);
1016 physic.set_acceleration(0, 0);
1017 physic.set_velocity(0, -700);
1018 player_status->coins -= 25;
1019 set_bonus(NO_BONUS, true);
1021 dying_timer.start(3.0);
1022 set_group(COLGROUP_DISABLED);
1024 DisplayEffect* effect = new DisplayEffect();
1025 effect->fade_out(3.0);
1026 Sector::current()->add_object(effect);
1027 sound_manager->stop_music(3.0);
1032 Player::move(const Vector& vector)
1036 // TODO: do we need the following? Seems irrelevant to moving the player
1038 set_size(31.8, 63.8);
1040 set_size(31.8, 31.8);
1042 last_ground_y = vector.y;
1048 Player::check_bounds(Camera* camera)
1050 /* Keep tux in bounds: */
1051 if (get_pos().x < 0) {
1052 // Lock Tux to the size of the level, so that he doesn't fall of
1054 set_pos(Vector(0, get_pos().y));
1057 /* fallen out of the level? */
1058 if (get_pos().y > Sector::current()->get_height()) {
1063 // can happen if back scrolling is disabled
1064 if(get_pos().x < camera->get_translation().x) {
1065 set_pos(Vector(camera->get_translation().x, get_pos().y));
1067 if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width())
1070 camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(),
1076 Player::add_velocity(const Vector& velocity)
1078 physic.set_velocity(physic.get_velocity() + velocity);
1082 Player::add_velocity(const Vector& velocity, const Vector& end_speed)
1084 if (end_speed.x > 0)
1085 physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
1086 if (end_speed.x < 0)
1087 physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
1088 if (end_speed.y > 0)
1089 physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
1090 if (end_speed.y < 0)
1091 physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
1095 Player::bounce(BadGuy& )
1097 if(controller->hold(Controller::JUMP))
1098 physic.set_velocity_y(-520);
1100 physic.set_velocity_y(-300);
1103 //Scripting Functions Below
1106 Player::deactivate()
1111 physic.set_velocity_x(0);
1112 physic.set_velocity_y(0);
1113 physic.set_acceleration_x(0);
1114 physic.set_acceleration_y(0);
1122 deactivated = false;
1125 void Player::walk(float speed)
1127 physic.set_velocity_x(speed);
1131 Player::set_ghost_mode(bool enable)
1133 if (ghost_mode == enable)
1138 set_group(COLGROUP_DISABLED);
1139 physic.enable_gravity(false);
1140 log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
1143 set_group(COLGROUP_MOVING);
1144 physic.enable_gravity(true);
1145 log_debug << "You feel solid again." << std::endl;