migrat Game, Player i Item a time based

This commit is contained in:
2025-10-28 10:52:13 +01:00
parent 9e8c5e13df
commit 31c84f9676
8 changed files with 190 additions and 153 deletions

View File

@@ -66,10 +66,18 @@ struct PlayerData {
class Player {
private:
// Constantes
static constexpr int WIDTH = 8; // Ancho del jugador
static constexpr int HEIGHT = 16; // ALto del jugador
static constexpr int MAX_FALLING_HEIGHT = BLOCK * 4; // Altura maxima permitida de caída.
static constexpr float MAX_VY = 1.2F; // Velocidad máxima que puede alcanzar al desplazarse en vertical
static constexpr int WIDTH = 8; // Ancho del jugador
static constexpr int HEIGHT = 16; // ALto del jugador
static constexpr int MAX_FALLING_HEIGHT = BLOCK * 4; // Altura maxima permitida de caída en pixels
// Constantes de física (per-second values)
static constexpr float HORIZONTAL_VELOCITY = 40.0F; // Velocidad horizontal en pixels/segundo (0.6 * 66.67fps)
static constexpr float MAX_VY = 80.0F; // Velocidad vertical máxima en pixels/segundo (1.2 * 66.67fps)
static constexpr float JUMP_VELOCITY = -80.0F; // Velocidad inicial del salto en pixels/segundo
static constexpr float GRAVITY_FORCE = 155.6F; // Fuerza de gravedad en pixels/segundo² (0.035 * 66.67²)
// Constantes de sonido
static constexpr float SOUND_INTERVAL = 0.06F; // Intervalo entre sonidos de salto/caída en segundos (4 frames a 66.67fps)
// Objetos y punteros
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
@@ -96,8 +104,8 @@ class Player {
int jump_init_pos_; // Valor del eje Y en el que se inicia el salto
std::vector<JA_Sound_t*> jumping_sound_; // Vecor con todos los sonidos del salto
std::vector<JA_Sound_t*> falling_sound_; // Vecor con todos los sonidos de la caída
int jumping_counter_ = 0; // Cuenta el tiempo de salto
int falling_counter_ = 0; // Cuenta el tiempo de caida
float jumping_time_ = 0.0F; // Tiempo acumulado de salto en segundos
float falling_time_ = 0.0F; // Tiempo acumulado de caída en segundos
#ifdef _DEBUG
SDL_FRect debug_rect_x_; // Rectangulo de desplazamiento para el modo debug
@@ -107,34 +115,34 @@ class Player {
#endif
// Comprueba las entradas y modifica variables
void checkInput();
void checkInput(float delta_time);
// Comprueba si se halla en alguno de los cuatro bordes
void checkBorders();
// Comprueba el estado del jugador
void checkState();
void checkState(float delta_time);
// Aplica gravedad al jugador
void applyGravity();
void applyGravity(float delta_time);
// Recalcula la posición del jugador y su animación
void move();
void move(float delta_time);
// Maneja el movimiento horizontal hacia la izquierda
void moveHorizontalLeft();
void moveHorizontalLeft(float delta_time);
// Maneja el movimiento horizontal hacia la derecha
void moveHorizontalRight();
void moveHorizontalRight(float delta_time);
// Maneja el movimiento vertical hacia arriba
void moveVerticalUp();
void moveVerticalUp(float delta_time);
// Maneja el movimiento vertical hacia abajo
void moveVerticalDown();
void moveVerticalDown(float delta_time);
// Establece la animación del jugador
void animate();
void animate(float delta_time);
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
void checkJumpEnd();
@@ -194,7 +202,7 @@ public:
void render();
// Actualiza las variables del objeto
void update();
void update(float delta_time);
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
[[nodiscard]] auto getOnBorder() const -> bool { return is_on_border_; }