ajustant al jugador
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 323 B After Width: | Height: | Size: 324 B |
@@ -201,7 +201,7 @@ void Player::updateOnAir(float delta_time) {
|
||||
// Movimiento físico del estado ON_GROUND
|
||||
void Player::moveOnGround(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
|
||||
@@ -233,7 +233,7 @@ void Player::moveOnGround(float delta_time) {
|
||||
// Movimiento físico del estado ON_SLOPE
|
||||
void Player::moveOnSlope(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
|
||||
// Verificar rampa válida antes de comprobar velocidad: si no hay rampa siempre caer,
|
||||
// independientemente de si hay o no input (evita bloqueo con vx_=0 y slope null)
|
||||
@@ -320,7 +320,7 @@ void Player::moveOnSlope(float delta_time) {
|
||||
// El jugador puede moverse horizontalmente en el aire y la gravedad siempre actúa.
|
||||
void Player::moveOnAir(float delta_time) {
|
||||
// Movimiento horizontal libre según wanna_go_ (permite girar en el aire)
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
applyHorizontalMovement(delta_time);
|
||||
|
||||
// Gravedad
|
||||
@@ -649,31 +649,31 @@ void Player::placeSprite() {
|
||||
sprite_->setPos(x_, y_);
|
||||
}
|
||||
|
||||
// Calcula la velocidad en x
|
||||
void Player::updateVelocity() {
|
||||
// Calcula la velocidad en x con inercia ligera (interpolación hacia vel. objetivo)
|
||||
void Player::updateVelocity(float delta_time) {
|
||||
float target = 0.0F;
|
||||
if (auto_movement_) {
|
||||
// La cinta transportadora tiene el control
|
||||
vx_ = HORIZONTAL_VELOCITY * room_->getConveyorBeltDirection();
|
||||
sprite_->setFlip(vx_ < 0.0F ? Flip::LEFT : Flip::RIGHT);
|
||||
target = HORIZONTAL_VELOCITY * room_->getConveyorBeltDirection();
|
||||
} else {
|
||||
// El jugador tiene el control
|
||||
switch (wanna_go_) {
|
||||
case Direction::LEFT:
|
||||
vx_ = -HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::LEFT);
|
||||
break;
|
||||
case Direction::RIGHT:
|
||||
vx_ = HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::RIGHT);
|
||||
break;
|
||||
case Direction::NONE:
|
||||
vx_ = 0.0F;
|
||||
break;
|
||||
default:
|
||||
vx_ = 0.0F;
|
||||
break;
|
||||
case Direction::LEFT: target = -HORIZONTAL_VELOCITY; break;
|
||||
case Direction::RIGHT: target = HORIZONTAL_VELOCITY; break;
|
||||
default: target = 0.0F; break;
|
||||
}
|
||||
}
|
||||
|
||||
// Orientación del sprite según la dirección deseada (sin cambiar cuando target=0)
|
||||
if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); }
|
||||
else if (target < 0.0F) { sprite_->setFlip(Flip::LEFT); }
|
||||
|
||||
// Aproximar vx_ al objetivo con paso limitado por la aceleración
|
||||
const float STEP = HORIZONTAL_ACCEL * delta_time;
|
||||
if (vx_ < target) {
|
||||
vx_ = std::min(vx_ + STEP, target);
|
||||
} else if (vx_ > target) {
|
||||
vx_ = std::max(vx_ - STEP, target);
|
||||
}
|
||||
}
|
||||
|
||||
// Aplica movimiento horizontal con colisión de muros
|
||||
|
||||
@@ -33,7 +33,8 @@ class Player {
|
||||
};
|
||||
|
||||
// --- Constantes de física (públicas para permitir cálculos en structs) ---
|
||||
static constexpr float HORIZONTAL_VELOCITY = 60.0F; // Velocidad horizontal en pixels/segundo
|
||||
static constexpr float HORIZONTAL_VELOCITY = 60.0F; // Velocidad horizontal objetivo en pixels/segundo
|
||||
static constexpr float HORIZONTAL_ACCEL = 500.0F; // Aceleración/deceleración horizontal en pixels/segundo² (inercia ligera)
|
||||
static constexpr float MAX_VY = 160.0F; // Velocidad vertical máxima en pixels/segundo
|
||||
static constexpr float JUMP_VELOCITY = -140.0F; // Velocidad inicial del salto en pixels/segundo
|
||||
static constexpr float GRAVITY_FORCE = 360.0F; // Fuerza de gravedad en pixels/segundo²
|
||||
@@ -180,6 +181,6 @@ class Player {
|
||||
void animate(float delta_time); // Establece la animación del jugador
|
||||
auto handleBorders() -> Room::Border; // Comprueba si se halla en alguno de los cuatro bordes
|
||||
auto handleKillingTiles() -> bool; // Comprueba que el jugador no toque ningun tile de los que matan
|
||||
void updateVelocity(); // Calcula la velocidad en x
|
||||
void updateVelocity(float delta_time); // Calcula la velocidad en x con inercia ligera
|
||||
void markAsDead(); // Marca al jugador como muerto
|
||||
};
|
||||
Reference in New Issue
Block a user