90 lines
4.7 KiB
C++
90 lines
4.7 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <string> // for string
|
|
#include <vector> // for vector
|
|
|
|
#include "utils/utils.h" // for Circle
|
|
class AnimatedSprite;
|
|
class Texture;
|
|
|
|
// Clase Item
|
|
class Item {
|
|
public:
|
|
// Tipos de objetos
|
|
enum class Id : Uint8 {
|
|
NONE = 0,
|
|
DISK = 1,
|
|
GAVINA = 2,
|
|
PACMAR = 3,
|
|
CLOCK = 4,
|
|
COFFEE = 5,
|
|
COFFEE_MACHINE = 6,
|
|
};
|
|
|
|
Item(Id id, float x, float y, Texture *texture, const std::vector<std::string> *animation, SDL_Renderer *renderer); // Constructor
|
|
~Item(); // Destructor
|
|
|
|
Item(const Item &) = delete;
|
|
auto operator=(const Item &) -> Item & = delete;
|
|
|
|
void allignTo(int x); // Centra el objeto en la posición X
|
|
void render(); // Pinta el objeto en la pantalla
|
|
void disable(); // Pone a cero todos los valores del objeto
|
|
void update(); // Actualiza al objeto (frame-based)
|
|
void update(float dt_s); // Actualiza al objeto (time-based)
|
|
void updateTimeToLive(); // Actualiza el contador (frame-based)
|
|
void updateTimeToLive(float dt_s); // Actualiza el contador (time-based)
|
|
void checkTimeToLive(); // Comprueba si el objeto sigue vivo
|
|
|
|
[[nodiscard]] auto getPosX() const -> float; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getPosY() const -> float; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getWidth() const -> int; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getHeight() const -> int; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getId() const -> Id; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isEnabled() const -> bool; // Obtiene el valor de la variable
|
|
[[nodiscard]] auto isOnFloor() const -> bool; // Informa si el objeto ha colisionado con el suelo
|
|
|
|
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
|
|
|
|
private:
|
|
// Time-based: equivalents en unitats físiques precalculades a 60Hz.
|
|
static constexpr float ITEM_VEL_Y_PX_PER_S = -240.0F; // Era -4.0 px/frame
|
|
static constexpr float ITEM_ACCEL_Y_PX_PER_S2 = 720.0F; // Era +0.2 px/frame²
|
|
static constexpr float ITEM_VEL_X_STEP_PX_PER_S = 30.0F; // Era 0.5 px/frame, 5 valors en [-1.0, 1.0]
|
|
static constexpr float COFFEE_VEL_Y_PX_PER_S = -6.0F; // Era -0.1 px/frame
|
|
static constexpr float COFFEE_ACCEL_Y_PX_PER_S2 = 360.0F; // Era +0.1 px/frame²
|
|
static constexpr float TIME_TO_LIVE_S = 10.0F; // Era 600 frames
|
|
static constexpr float BLINK_START_S = TIME_TO_LIVE_S - (200.0F / 60.0F); // Era time_to_live_ > 200
|
|
static constexpr float BLINK_PERIOD_S = 20.0F / 60.0F; // Era % 20
|
|
static constexpr float BLINK_OFF_S = 10.0F / 60.0F; // Era % 20 <= 10
|
|
|
|
// Objetos y punteros
|
|
AnimatedSprite *sprite_; // Sprite con los graficos del objeto
|
|
|
|
// Variables
|
|
float pos_x_; // Posición X del objeto
|
|
float pos_y_; // Posición Y del objeto
|
|
Uint8 width_; // Ancho del objeto
|
|
Uint8 height_; // Alto del objeto
|
|
float vel_x_; // Velocidad en el eje X (frame-based: px/frame)
|
|
float vel_y_; // Velocidad en el eje Y (frame-based: px/frame)
|
|
float accel_x_; // Aceleración en el eje X (frame-based: px/frame²)
|
|
float accel_y_; // Aceleración en el eje Y (frame-based: px/frame²)
|
|
float vel_x_s_{0.0F}; // Velocidad en el eje X (time-based: px/s)
|
|
float vel_y_s_{0.0F}; // Velocidad en el eje Y (time-based: px/s)
|
|
float accel_x_s_{0.0F}; // Aceleración en el eje X (time-based: px/s²)
|
|
float accel_y_s_{0.0F}; // Aceleración en el eje Y (time-based: px/s²)
|
|
bool floor_collision_; // Indica si el objeto colisiona con el suelo
|
|
Id id_; // Especifica el tipo de objeto que es
|
|
bool enabled_; // Especifica si el objeto está habilitado
|
|
Uint16 time_to_live_; // Temporizador (frame-based)
|
|
float time_to_live_s_{0.0F}; // Temporizador (time-based)
|
|
Circle collider_; // Circulo de colisión del objeto
|
|
|
|
void shiftColliders(); // Alinea el circulo de colisión con la posición del objeto
|
|
void move(); // Actualiza la posición y estados del objeto (frame-based)
|
|
void move(float dt_s); // Actualiza la posición y estados del objeto (time-based)
|
|
};
|