X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fplayer.cpp;h=6608f8c48dc836242c3e7284ef48e3d6b7cc2311;hb=6e843b1780f62f45b7021bd8c38181aa211588ee;hp=2ecaaadc52232c589c5b5e73037998e0b79072cd;hpb=00fb759c2385ff08caf38e916c2d0ba8cafc8a41;p=supertux.git diff --git a/src/player.cpp b/src/player.cpp index 2ecaaadc5..6608f8c48 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -40,13 +40,18 @@ #include "gameloop.h" #include "trigger/trigger_base.h" -// behavior definitions: -#define TILES_FOR_BUTTJUMP 3 -// animation times (in ms): -#define SHOOTING_TIME .150 - -// time before idle animation starts -#define IDLE_TIME 2.500 +static const int TILES_FOR_BUTTJUMP = 3; +static const float SHOOTING_TIME = .150; +/// time before idle animation starts +static const float IDLE_TIME = 2.5; + +static const float WALK_ACCELERATION_X = 300; +static const float RUN_ACCELERATION_X = 400; +static const float SKID_XM = 200; +static const float SKID_TIME = .3; +static const float MAX_WALK_XM = 230; +static const float MAX_RUN_XM = 320; +static const float WALK_SPEED = 100; // growing animation Surface* growingtux_left[GROWING_FRAMES]; @@ -73,7 +78,7 @@ PlayerKeymap::PlayerKeymap() keymap.right = SDLK_RIGHT; keymap.power = SDLK_LCTRL; - keymap.jump = SDLK_LALT; + keymap.jump = SDLK_SPACE; } void player_input_init(player_input_type* pplayer_input) @@ -91,29 +96,16 @@ void player_input_init(player_input_type* pplayer_input) } void -TuxBodyParts::set_action(std::string action) +TuxBodyParts::set_action(std::string action, int loops) { if(head != NULL) - head->set_action(action); + head->set_action(action, loops); if(body != NULL) - body->set_action(action); + body->set_action(action, loops); if(arms != NULL) - arms->set_action(action); + arms->set_action(action, loops); if(feet != NULL) - feet->set_action(action); -} - -void -TuxBodyParts::one_time_animation() -{ - if(head != NULL) - head->start_animation(1); - if(body != NULL) - body->start_animation(1); - if(arms != NULL) - arms->start_animation(1); - if(feet != NULL) - feet->start_animation(1); + feet->set_action(action, loops); } void @@ -144,7 +136,7 @@ Player::init() { holding_something = false; - bbox.set_size(32, 32); + bbox.set_size(31.8, 31.8); size = SMALL; got_power = NONE_POWER; @@ -401,6 +393,14 @@ Player::handle_horizontal_input() } #endif + // extend/shrink tux collision rectangle so that we fall through/walk over 1 + // tile holes + if(fabsf(vx) > MAX_WALK_XM) { + bbox.set_width(33); + } else { + bbox.set_width(31.8); + } + physic.set_velocity(vx, vy); physic.set_acceleration(ax, ay); } @@ -673,13 +673,13 @@ Player::handle_input() { duck = true; bbox.move(Vector(0, 32)); - bbox.set_height(32); + bbox.set_height(31.8); } else if(input.down == UP && size == BIG && duck) { // try if we can really unduck bbox.move(Vector(0, -32)); - bbox.set_height(64); + bbox.set_height(63.8); duck = false; // FIXME #if 0 @@ -689,7 +689,7 @@ Player::handle_input() } else { // undo the ducking changes bbox.move(Vector(0, 32)); - bbox.set_height(32); + bbox.set_height(31.8); } #endif } @@ -702,7 +702,7 @@ Player::grow(bool animate) return; size = BIG; - bbox.set_height(64); + bbox.set_height(63.8); bbox.move(Vector(0, -32)); if(animate) @@ -728,7 +728,7 @@ Player::draw(DrawingContext& context) else tux_body = big_tux; - int layer = LAYER_OBJECTS - 1; + int layer = LAYER_OBJECTS + 10; /* Set Tux sprite action */ if (duck && size == BIG) @@ -789,11 +789,9 @@ Player::draw(DrawingContext& context) if(size == BIG) { if(dir == LEFT) - tux_body->head->set_action("idle-left"); + tux_body->head->set_action("idle-left", 1); else // dir == RIGHT - tux_body->head->set_action("idle-right"); - - tux_body->head->start_animation(1); + tux_body->head->set_action("idle-right", 1); } } @@ -858,36 +856,31 @@ Player::draw(DrawingContext& context) && !dying) { if (size == SMALL || duck) - smalltux_star->draw(context, get_pos(), LAYER_OBJECTS + 2); + smalltux_star->draw(context, get_pos(), layer + 5); else - bigtux_star->draw(context, get_pos(), LAYER_OBJECTS + 2); + bigtux_star->draw(context, get_pos(), layer + 5); } if (debug_mode) context.draw_filled_rect(get_pos(), Vector(bbox.get_width(), bbox.get_height()), - Color(75,75,75, 150), LAYER_OBJECTS+1); + Color(75,75,75, 150), LAYER_OBJECTS+20); } HitResponse Player::collision(GameObject& other, const CollisionHit& hit) { - if(dying) { - return FORCE_MOVE; - } - if(other.get_flags() & FLAG_SOLID) { if(hit.normal.y < 0) { // landed on floor? if (physic.get_velocity_y() < 0) physic.set_velocity_y(0); on_ground_flag = true; } else if(hit.normal.y > 0) { // bumped against the roof - physic.set_velocity_y(0); + physic.set_velocity_y(.1); } - if(hit.normal.x != 0) { // hit on the side? - if(hit.normal.y > 0.6) // limits the slopes we can move up... - physic.set_velocity_x(0); + if(fabsf(hit.normal.x) > .9) { // hit on the side? + physic.set_velocity_x(0); } return CONTINUE; @@ -936,7 +929,7 @@ Player::kill(HurtMode mode) growing_timer.start(GROWING_TIME); safe_timer.start(TUX_SAFE_TIME + GROWING_TIME); size = SMALL; - bbox.set_height(32); + bbox.set_height(31.8); duck = false; } } @@ -948,6 +941,7 @@ Player::kill(HurtMode mode) --player_status.lives; dying = DYING_SQUISHED; dying_timer.start(3.0); + flags |= FLAG_NO_COLLDET; } } @@ -957,7 +951,7 @@ Player::remove_powerups() { got_power = NONE_POWER; size = SMALL; - bbox.set_height(32); + bbox.set_height(31.8); } void @@ -1010,7 +1004,7 @@ Player::check_bounds(Camera* camera) } void -Player::bounce(BadGuy& badguy) +Player::bounce(BadGuy& ) { //Make sure we stopped flapping flapping = false;