developers, developers!
This commit is contained in:
@@ -64,7 +64,9 @@ void Player::handleInput() {
|
||||
wanna_go_ = Direction::NONE;
|
||||
}
|
||||
|
||||
wanna_jump_ = Input::get()->checkAction(InputAction::JUMP);
|
||||
const bool JUMP_PRESSED = Input::get()->checkAction(InputAction::JUMP);
|
||||
wanna_jump_ = JUMP_PRESSED && !jump_held_; // Solo en el flanco de pulsación
|
||||
jump_held_ = JUMP_PRESSED;
|
||||
wanna_down_ = Input::get()->checkAction(InputAction::DOWN);
|
||||
}
|
||||
|
||||
@@ -416,7 +418,7 @@ void Player::switchBorders() {
|
||||
void Player::applyGravity(float delta_time) {
|
||||
if (state_ == State::ON_AIR) {
|
||||
// Si está subiendo y ha soltado el botón de salto, gravedad aumentada para cortar el salto
|
||||
const float GRAVITY = (vy_ < 0.0F && !wanna_jump_)
|
||||
const float GRAVITY = (vy_ < 0.0F && !jump_held_)
|
||||
? GRAVITY_FORCE * LOW_JUMP_GRAVITY_MULT
|
||||
: GRAVITY_FORCE;
|
||||
vy_ += GRAVITY * delta_time;
|
||||
@@ -582,15 +584,26 @@ void Player::setColor(Uint8 color) {
|
||||
|
||||
// Actualiza los puntos de colisión
|
||||
void Player::updateColliderPoints() {
|
||||
const SDL_FRect RECT = getRect();
|
||||
collider_points_[0] = {.x = RECT.x, .y = RECT.y};
|
||||
collider_points_[1] = {.x = RECT.x + 7, .y = RECT.y};
|
||||
collider_points_[2] = {.x = RECT.x + 7, .y = RECT.y + 7};
|
||||
collider_points_[3] = {.x = RECT.x, .y = RECT.y + 7};
|
||||
collider_points_[4] = {.x = RECT.x, .y = RECT.y + 8};
|
||||
collider_points_[5] = {.x = RECT.x + 7, .y = RECT.y + 8};
|
||||
collider_points_[6] = {.x = RECT.x + 7, .y = RECT.y + 15};
|
||||
collider_points_[7] = {.x = RECT.x, .y = RECT.y + 15};
|
||||
// 3 columnas × 4 filas: garantiza que cada tile de 8×8 que solape el jugador tenga al menos un punto
|
||||
const float L = x_;
|
||||
const float M = x_ + (WIDTH / 2);
|
||||
const float R = x_ + WIDTH - 1;
|
||||
const float Y0 = y_;
|
||||
const float Y1 = y_ + 8;
|
||||
const float Y2 = y_ + 16;
|
||||
const float Y3 = y_ + HEIGHT - 1;
|
||||
collider_points_[0] = {.x = L, .y = Y0};
|
||||
collider_points_[1] = {.x = M, .y = Y0};
|
||||
collider_points_[2] = {.x = R, .y = Y0};
|
||||
collider_points_[3] = {.x = L, .y = Y1};
|
||||
collider_points_[4] = {.x = M, .y = Y1};
|
||||
collider_points_[5] = {.x = R, .y = Y1};
|
||||
collider_points_[6] = {.x = L, .y = Y2};
|
||||
collider_points_[7] = {.x = M, .y = Y2};
|
||||
collider_points_[8] = {.x = R, .y = Y2};
|
||||
collider_points_[9] = {.x = L, .y = Y3};
|
||||
collider_points_[10] = {.x = M, .y = Y3};
|
||||
collider_points_[11] = {.x = R, .y = Y3};
|
||||
}
|
||||
|
||||
// Actualiza los puntos de los pies
|
||||
|
||||
@@ -36,7 +36,7 @@ class Player {
|
||||
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 JUMP_VELOCITY = -170.0F; // Velocidad inicial del salto en pixels/segundo
|
||||
static constexpr float GRAVITY_FORCE = 360.0F; // Fuerza de gravedad en pixels/segundo²
|
||||
static constexpr float LOW_JUMP_GRAVITY_MULT = 3.0F; // Multiplicador de gravedad al soltar el botón de salto (salto variable)
|
||||
|
||||
@@ -87,8 +87,8 @@ class Player {
|
||||
|
||||
private:
|
||||
// --- Constantes ---
|
||||
static constexpr int WIDTH = 8; // Ancho del jugador
|
||||
static constexpr int HEIGHT = 16; // ALto del jugador
|
||||
static constexpr int WIDTH = 12; // Ancho del jugador
|
||||
static constexpr int HEIGHT = 24; // Alto del jugador
|
||||
static constexpr int MAX_FALLING_HEIGHT = Tile::SIZE * 4; // Altura maxima permitida de caída en pixels
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
@@ -105,6 +105,7 @@ class Player {
|
||||
Direction wanna_go_ = Direction::NONE;
|
||||
bool wanna_jump_ = false;
|
||||
bool wanna_down_ = false;
|
||||
bool jump_held_ = false; // true mientras la tecla de salto esté pulsada (para detectar flanco)
|
||||
|
||||
// --- Variables de estado ---
|
||||
State state_ = State::ON_GROUND; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
@@ -112,7 +113,7 @@ class Player {
|
||||
|
||||
// --- Variables de colisión ---
|
||||
SDL_FRect collider_box_{}; // Caja de colisión con los enemigos u objetos
|
||||
std::array<SDL_FPoint, 8> collider_points_{}; // Puntos de colisión con el mapa
|
||||
std::array<SDL_FPoint, 12> collider_points_{}; // Puntos de colisión con el mapa (3 columnas × 4 filas, gap ≤ 8px)
|
||||
SDL_FPoint under_left_foot_ = {.x = 0.0F, .y = 0.0F}; // El punto bajo la esquina inferior izquierda del jugador
|
||||
SDL_FPoint under_right_foot_ = {.x = 0.0F, .y = 0.0F}; // El punto bajo la esquina inferior derecha del jugador
|
||||
const LineDiagonal* current_slope_{nullptr}; // Rampa actual sobe la que está el jugador
|
||||
|
||||
@@ -26,8 +26,6 @@ Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
|
||||
item_manager_ = std::make_unique<ItemManager>(room->number, data_);
|
||||
|
||||
initializeRoom(*room);
|
||||
openTheJail(); // Abre la Jail si se da el caso
|
||||
|
||||
// Crea el mapa de colisiones (necesita tile_map_, tile_set_width_, conveyor_belt_direction_)
|
||||
collision_map_ = std::make_unique<CollisionMap>(tile_map_, tile_set_width_, conveyor_belt_direction_);
|
||||
|
||||
@@ -80,25 +78,6 @@ void Room::initializeRoom(const Data& room) {
|
||||
}
|
||||
}
|
||||
|
||||
// Abre la jail para poder entrar
|
||||
void Room::openTheJail() { // NOLINT(readability-convert-member-functions-to-static)
|
||||
if (data_->jail_is_open && number_ == Defaults::Game::Room::END_ROOM) {
|
||||
// Elimina el último enemigo (Bry debe ser el último enemigo definido en el fichero)
|
||||
if (!enemy_manager_->isEmpty()) {
|
||||
enemy_manager_->removeLastEnemy();
|
||||
}
|
||||
|
||||
// Abre las puertas
|
||||
constexpr int TILE_A = 16 + (13 * 32);
|
||||
constexpr int TILE_B = 16 + (14 * 32);
|
||||
if (TILE_A < tile_map_.size()) {
|
||||
tile_map_[TILE_A] = -1;
|
||||
}
|
||||
if (TILE_B < tile_map_.size()) {
|
||||
tile_map_[TILE_B] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
void Room::renderMap() {
|
||||
|
||||
@@ -137,5 +137,4 @@ class Room {
|
||||
|
||||
// --- Funciones ---
|
||||
void initializeRoom(const Data& room); // Inicializa los valores
|
||||
void openTheJail(); // Abre la jail para poder entrar
|
||||
};
|
||||
@@ -598,10 +598,6 @@ void Game::handleDebugEvents(const SDL_Event& event) { // NOLINT(readability-co
|
||||
player_->setColor();
|
||||
break;
|
||||
|
||||
case SDLK_3:
|
||||
toggleCheat(Options::cheats.jail_is_open, Locale::get()->get("game.cheat_jail_open")); // NOLINT(readability-static-accessed-through-instance)
|
||||
break;
|
||||
|
||||
case SDLK_7:
|
||||
Notifier::get()->show({Locale::get()->get("achievements.header"), Locale::get()->get("achievements.c11")}, Notifier::Style::CHEEVO, -1, false, "F7"); // NOLINT(readability-static-accessed-through-instance)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user