treball en curs: correccions de tidy
This commit is contained in:
+356
-344
File diff suppressed because it is too large
Load Diff
+172
-253
@@ -1,253 +1,172 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
constexpr int MAX_BOUNCE = 10;
|
||||
|
||||
// Tipos de globo
|
||||
constexpr int BALLOON_1 = 1;
|
||||
constexpr int BALLOON_2 = 2;
|
||||
constexpr int BALLOON_3 = 3;
|
||||
constexpr int BALLOON_4 = 4;
|
||||
constexpr int HEXAGON_1 = 5;
|
||||
constexpr int HEXAGON_2 = 6;
|
||||
constexpr int HEXAGON_3 = 7;
|
||||
constexpr int HEXAGON_4 = 8;
|
||||
constexpr int POWER_BALL = 9;
|
||||
|
||||
// Puntos de globo
|
||||
constexpr int BALLOON_SCORE_1 = 50;
|
||||
constexpr int BALLOON_SCORE_2 = 100;
|
||||
constexpr int BALLOON_SCORE_3 = 200;
|
||||
constexpr int BALLOON_SCORE_4 = 400;
|
||||
|
||||
// Tamaños de globo
|
||||
constexpr int BALLOON_SIZE_1 = 1;
|
||||
constexpr int BALLOON_SIZE_2 = 2;
|
||||
constexpr int BALLOON_SIZE_3 = 3;
|
||||
constexpr int BALLOON_SIZE_4 = 4;
|
||||
|
||||
// Clases de globo
|
||||
constexpr int BALLOON_CLASS = 0;
|
||||
constexpr int HEXAGON_CLASS = 1;
|
||||
|
||||
// Velocidad del globo
|
||||
constexpr float BALLOON_VELX_POSITIVE = 0.7F;
|
||||
constexpr float BALLOON_VELX_NEGATIVE = -0.7F;
|
||||
|
||||
// Índice para las animaciones de los globos
|
||||
constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||
|
||||
// Cantidad posible de globos
|
||||
constexpr int MAX_BALLOONS = 100;
|
||||
|
||||
// Velocidades a las que se mueven los globos
|
||||
constexpr float BALLOON_SPEED_1 = 0.60F;
|
||||
constexpr float BALLOON_SPEED_2 = 0.70F;
|
||||
constexpr float BALLOON_SPEED_3 = 0.80F;
|
||||
constexpr float BALLOON_SPEED_4 = 0.90F;
|
||||
constexpr float BALLOON_SPEED_5 = 1.00F;
|
||||
|
||||
// Tamaño de los globos
|
||||
constexpr int BALLOON_WIDTH_1 = 8;
|
||||
constexpr int BALLOON_WIDTH_2 = 13;
|
||||
constexpr int BALLOON_WIDTH_3 = 21;
|
||||
constexpr int BALLOON_WIDTH_4 = 37;
|
||||
|
||||
// PowerBall
|
||||
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||
constexpr int POWERBALL_COUNTER = 8;
|
||||
|
||||
// Clase Balloon
|
||||
class Balloon {
|
||||
private:
|
||||
// Estructura para las variables para el efecto de los rebotes
|
||||
struct Bouncing {
|
||||
bool enabled; // Si el efecto está activo
|
||||
Uint8 counter; // Countador para el efecto
|
||||
Uint8 speed; // Velocidad a la que transcurre el efecto
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
||||
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
|
||||
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
AnimatedSprite *sprite; // Sprite del objeto globo
|
||||
|
||||
// Variables
|
||||
float posX; // Posición en el eje X
|
||||
float posY; // Posición en el eje Y
|
||||
Uint8 width; // Ancho
|
||||
Uint8 height; // Alto
|
||||
float velX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float velY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
float gravity; // Aceleración en el eje Y. Modifica la velocidad
|
||||
float defaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo
|
||||
float maxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y
|
||||
bool beingCreated; // Indica si el globo se está creando
|
||||
bool blinking; // Indica si el globo está intermitente
|
||||
bool enabled; // Indica si el globo esta activo
|
||||
bool invulnerable; // Indica si el globo es invulnerable
|
||||
bool popping; // Indica si el globo está explotando
|
||||
bool stopped; // Indica si el globo está parado
|
||||
bool visible; // Indica si el globo es visible
|
||||
Circle collider; // Circulo de colisión del objeto
|
||||
Uint16 creationCounter; // Temporizador para controlar el estado "creandose"
|
||||
Uint16 creationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose"
|
||||
Uint16 score; // Puntos que da el globo al ser destruido
|
||||
Uint16 stoppedCounter; // Contador para controlar el estado "parado"
|
||||
Uint8 kind; // Tipo de globo
|
||||
Uint8 menace; // Cantidad de amenaza que genera el globo
|
||||
Uint32 counter; // Contador interno
|
||||
float travelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
||||
float speed; // Velocidad a la que se mueven los globos
|
||||
Uint8 size; // Tamaño del globo
|
||||
Uint8 power; // Cantidad de poder que alberga el globo
|
||||
Bouncing bouncing; // Contiene las variables para el efecto de rebote
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void updateColliders();
|
||||
|
||||
// Activa el efecto
|
||||
void bounceStart();
|
||||
|
||||
// Detiene el efecto
|
||||
void bounceStop();
|
||||
|
||||
// Aplica el efecto
|
||||
void updateBounce();
|
||||
|
||||
// Actualiza los estados del globo
|
||||
void updateState();
|
||||
|
||||
// Establece la animación correspondiente
|
||||
void updateAnimation();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setBeingCreated(bool value);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Balloon();
|
||||
|
||||
Balloon(const Balloon &) = delete;
|
||||
auto operator=(const Balloon &) -> Balloon & = delete;
|
||||
|
||||
// Centra el globo en la posición X
|
||||
void allignTo(int x);
|
||||
|
||||
// Pinta el globo en la pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza la posición y estados del globo
|
||||
void move();
|
||||
|
||||
// Deshabilita el globo y pone a cero todos los valores
|
||||
void disable();
|
||||
|
||||
// Explosiona el globo
|
||||
void pop();
|
||||
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores
|
||||
void update();
|
||||
|
||||
// Comprueba si el globo está habilitado
|
||||
[[nodiscard]] auto isEnabled() const -> bool;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getPosX() const -> float;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> float;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getVelY() const -> float;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getWidth() const -> int;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getHeight() const -> int;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float velY);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpeed(float speed);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getKind() const -> int;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getSize() const -> Uint8;
|
||||
|
||||
// Obtiene la clase a la que pertenece el globo
|
||||
[[nodiscard]] auto getClass() const -> Uint8;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setStop(bool state);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isStopped() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setBlink(bool value);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isBlinking() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVisible(bool value);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isVisible() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerable(bool value);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isBeingCreated() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPopping(bool value);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isPopping() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setStoppedTimer(Uint16 time);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getStoppedTimer() const -> Uint16;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getScore() const -> Uint16;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto getCollider() -> Circle &;
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
[[nodiscard]] auto getMenace() const -> Uint8;
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
[[nodiscard]] auto getPower() const -> Uint8;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Tipos de globo
|
||||
constexpr int BALLOON_1 = 1;
|
||||
constexpr int BALLOON_2 = 2;
|
||||
constexpr int BALLOON_3 = 3;
|
||||
constexpr int BALLOON_4 = 4;
|
||||
constexpr int HEXAGON_1 = 5;
|
||||
constexpr int HEXAGON_2 = 6;
|
||||
constexpr int HEXAGON_3 = 7;
|
||||
constexpr int HEXAGON_4 = 8;
|
||||
constexpr int POWER_BALL = 9;
|
||||
|
||||
// Puntos de globo
|
||||
constexpr int BALLOON_SCORE_1 = 50;
|
||||
constexpr int BALLOON_SCORE_2 = 100;
|
||||
constexpr int BALLOON_SCORE_3 = 200;
|
||||
constexpr int BALLOON_SCORE_4 = 400;
|
||||
|
||||
// Tamaños de globo
|
||||
constexpr int BALLOON_SIZE_1 = 1;
|
||||
constexpr int BALLOON_SIZE_2 = 2;
|
||||
constexpr int BALLOON_SIZE_3 = 3;
|
||||
constexpr int BALLOON_SIZE_4 = 4;
|
||||
|
||||
// Clases de globo
|
||||
constexpr int BALLOON_CLASS = 0;
|
||||
constexpr int HEXAGON_CLASS = 1;
|
||||
|
||||
// Velocidad del globo
|
||||
constexpr float BALLOON_VELX_POSITIVE = 0.7F;
|
||||
constexpr float BALLOON_VELX_NEGATIVE = -0.7F;
|
||||
|
||||
// Velocidades a las que se mueven los globos
|
||||
constexpr float BALLOON_SPEED_1 = 0.60F;
|
||||
constexpr float BALLOON_SPEED_2 = 0.70F;
|
||||
constexpr float BALLOON_SPEED_3 = 0.80F;
|
||||
constexpr float BALLOON_SPEED_4 = 0.90F;
|
||||
constexpr float BALLOON_SPEED_5 = 1.00F;
|
||||
|
||||
// Tamaño de los globos
|
||||
constexpr int BALLOON_WIDTH_1 = 8;
|
||||
constexpr int BALLOON_WIDTH_2 = 13;
|
||||
constexpr int BALLOON_WIDTH_3 = 21;
|
||||
constexpr int BALLOON_WIDTH_4 = 37;
|
||||
|
||||
// PowerBall
|
||||
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||
constexpr int POWERBALL_COUNTER = 8;
|
||||
|
||||
// Clase Balloon
|
||||
class Balloon {
|
||||
public:
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer); // Constructor
|
||||
~Balloon(); // Destructor
|
||||
|
||||
Balloon(const Balloon &) = delete;
|
||||
auto operator=(const Balloon &) -> Balloon & = delete;
|
||||
|
||||
void allignTo(int x); // Centra el globo en la posición X
|
||||
void render(); // Pinta el globo en la pantalla
|
||||
void move(); // Actualiza la posición y estados del globo
|
||||
void disable(); // Deshabilita el globo y pone a cero todos los valores
|
||||
void pop(); // Explosiona el globo
|
||||
void update(); // Actualiza al globo a su posicion, animación y controla los contadores
|
||||
|
||||
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si el globo está habilitado
|
||||
[[nodiscard]] auto isStopped() const -> bool; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isBlinking() const -> bool; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isVisible() const -> bool; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isBeingCreated() const -> bool; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto isPopping() const -> bool; // Obtiene del valor de la variable
|
||||
|
||||
[[nodiscard]] auto getPosX() const -> float; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> float; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getVelY() 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 getKind() const -> int; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getSize() const -> Uint8; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getClass() const -> Uint8; // Obtiene la clase a la que pertenece el globo
|
||||
[[nodiscard]] auto getStoppedTimer() const -> Uint16; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getScore() const -> Uint16; // Obtiene del valor de la variable
|
||||
[[nodiscard]] auto getMenace() const -> Uint8; // Obtiene le valor de la variable
|
||||
[[nodiscard]] auto getPower() const -> Uint8; // Obtiene le valor de la variable
|
||||
|
||||
void setVelY(float vel_y); // Establece el valor de la variable
|
||||
void setSpeed(float speed); // Establece el valor de la variable
|
||||
void setStop(bool state); // Establece el valor de la variable
|
||||
void setBlink(bool value); // Establece el valor de la variable
|
||||
void setVisible(bool value); // Establece el valor de la variable
|
||||
void setInvulnerable(bool value); // Establece el valor de la variable
|
||||
void setPopping(bool value); // Establece el valor de la variable
|
||||
void setStoppedTimer(Uint16 time); // Establece el valor de la variable
|
||||
|
||||
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
|
||||
|
||||
private:
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
static constexpr int MAX_BOUNCE = 10;
|
||||
|
||||
// Estructura para las variables para el efecto de los rebotes
|
||||
struct Bouncing {
|
||||
bool enabled; // Si el efecto está activo
|
||||
Uint8 counter; // Countador para el efecto
|
||||
Uint8 speed; // Velocidad a la que transcurre el efecto
|
||||
float zoom_width; // Zoom aplicado a la anchura
|
||||
float zoom_height; // Zoom aplicado a la altura
|
||||
float desp_x; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
float desp_y; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
||||
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
|
||||
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
AnimatedSprite *sprite_; // Sprite del objeto globo
|
||||
|
||||
// Variables
|
||||
float pos_x_; // Posición en el eje X
|
||||
float pos_y_; // Posición en el eje Y
|
||||
Uint8 width_; // Ancho
|
||||
Uint8 height_; // Alto
|
||||
float vel_x_; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vel_y_; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
float gravity_; // Aceleración en el eje Y. Modifica la velocidad
|
||||
float default_vel_y_; // Velocidad inicial que tienen al rebotar contra el suelo
|
||||
float max_vel_y_; // Máxima velocidad que puede alcanzar el objeto en el eje Y
|
||||
bool being_created_; // Indica si el globo se está creando
|
||||
bool blinking_; // Indica si el globo está intermitente
|
||||
bool enabled_; // Indica si el globo esta activo
|
||||
bool invulnerable_; // Indica si el globo es invulnerable
|
||||
bool popping_; // Indica si el globo está explotando
|
||||
bool stopped_; // Indica si el globo está parado
|
||||
bool visible_; // Indica si el globo es visible
|
||||
Circle collider_; // Circulo de colisión del objeto
|
||||
Uint16 creation_counter_; // Temporizador para controlar el estado "creandose"
|
||||
Uint16 creation_counter_ini_; // Valor inicial para el temporizador para controlar el estado "creandose"
|
||||
Uint16 score_; // Puntos que da el globo al ser destruido
|
||||
Uint16 stopped_counter_; // Contador para controlar el estado "parado"
|
||||
Uint8 kind_; // Tipo de globo
|
||||
Uint8 menace_; // Cantidad de amenaza que genera el globo
|
||||
Uint32 counter_; // Contador interno
|
||||
float travel_y_; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
||||
float speed_; // Velocidad a la que se mueven los globos
|
||||
Uint8 size_; // Tamaño del globo
|
||||
Uint8 power_; // Cantidad de poder que alberga el globo
|
||||
Bouncing bouncing_; // Contiene las variables para el efecto de rebote
|
||||
|
||||
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
|
||||
void bounceStart(); // Activa el efecto
|
||||
void bounceStop(); // Detiene el efecto
|
||||
void updateBounce(); // Aplica el efecto
|
||||
void updateAnimation(); // Establece la animación correspondiente
|
||||
void setBeingCreated(bool value); // Establece el valor de la variable
|
||||
|
||||
void updateState(); // Actualiza los estados del globo
|
||||
|
||||
// Helpers de updateState, uno por cada rama de estado
|
||||
void updateStatePopping();
|
||||
void updateStateBeingCreated();
|
||||
void updateStateStopped();
|
||||
};
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
#include "game/entities/bullet.h"
|
||||
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "game/defaults.hpp" // for BulletKind::NONE, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
#include "game/defaults.hpp" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer) {
|
||||
sprite = new Sprite({x, y, 10, 10}, texture, renderer);
|
||||
Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Texture *texture, SDL_Renderer *renderer) {
|
||||
sprite_ = new Sprite({x, y, 10, 10}, texture, renderer);
|
||||
|
||||
// Posición inicial del objeto
|
||||
posX = x;
|
||||
posY = y;
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
width = 10;
|
||||
height = 10;
|
||||
width_ = 10;
|
||||
height_ = 10;
|
||||
|
||||
// Velocidad inicial en el eje Y
|
||||
velY = -3;
|
||||
vel_y_ = -3;
|
||||
|
||||
// Tipo de bala
|
||||
this->kind = kind;
|
||||
this->kind_ = kind;
|
||||
|
||||
// Identificador del dueño del objeto
|
||||
this->owner = owner;
|
||||
this->owner_ = owner;
|
||||
|
||||
// Valores especificos según el tipo
|
||||
switch (kind) {
|
||||
case BulletKind::UP:
|
||||
case Bullet::Kind::UP:
|
||||
// Establece la velocidad inicial
|
||||
velX = 0;
|
||||
vel_x_ = 0;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(0 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(0 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((0 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((0 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
case BulletKind::LEFT:
|
||||
case Bullet::Kind::LEFT:
|
||||
// Establece la velocidad inicial
|
||||
velX = -2;
|
||||
vel_x_ = -2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(1 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(1 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((1 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((1 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
case BulletKind::RIGHT:
|
||||
case Bullet::Kind::RIGHT:
|
||||
// Establece la velocidad inicial
|
||||
velX = 2;
|
||||
vel_x_ = 2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(2 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(2 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((2 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((2 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -68,7 +68,7 @@ Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture
|
||||
}
|
||||
|
||||
// Establece el tamaño del circulo de colisión
|
||||
collider.r = width / 2;
|
||||
collider_.r = width_ / 2;
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
@@ -76,46 +76,46 @@ Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture
|
||||
|
||||
// Destructor
|
||||
Bullet::~Bullet() {
|
||||
delete sprite;
|
||||
delete sprite_;
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void Bullet::render() {
|
||||
sprite->render();
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Actualiza la posición y estado del objeto en horizontal
|
||||
auto Bullet::move() -> Uint8 {
|
||||
auto Bullet::move() -> MoveResult {
|
||||
// Variable con el valor de retorno
|
||||
Uint8 msg = BULLET_MOVE_OK;
|
||||
MoveResult msg = MoveResult::OK;
|
||||
|
||||
// Mueve el objeto a su nueva posición
|
||||
posX += velX;
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el objeto se sale del area de juego por los laterales
|
||||
if ((posX < PLAY_AREA_LEFT - width) || (posX > PLAY_AREA_RIGHT)) {
|
||||
if ((pos_x_ < PLAY_AREA_LEFT - width_) || (pos_x_ > PLAY_AREA_RIGHT)) {
|
||||
// Se deshabilita
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
msg = MoveResult::OUT;
|
||||
}
|
||||
|
||||
// Mueve el objeto a su nueva posición en vertical
|
||||
posY += velY;
|
||||
pos_y_ += vel_y_;
|
||||
|
||||
// Si el objeto se sale del area de juego por la parte superior
|
||||
if (posY < PLAY_AREA_TOP - height) {
|
||||
if (pos_y_ < PLAY_AREA_TOP - height_) {
|
||||
// Se deshabilita
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
msg = MoveResult::OUT;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
sprite->setPosX(posX);
|
||||
sprite->setPosY(posY);
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
@@ -125,56 +125,56 @@ auto Bullet::move() -> Uint8 {
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
auto Bullet::isEnabled() const -> bool {
|
||||
return kind != BulletKind::NONE;
|
||||
return kind_ != Bullet::Kind::NONE;
|
||||
}
|
||||
|
||||
// Deshabilita el objeto
|
||||
void Bullet::disable() {
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getPosX() const -> int {
|
||||
return posX;
|
||||
return pos_x_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getPosY() const -> int {
|
||||
return posY;
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Bullet::setPosX(int x) {
|
||||
posX = x;
|
||||
pos_x_ = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Bullet::setPosY(int y) {
|
||||
posY = y;
|
||||
pos_y_ = y;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getVelY() const -> int {
|
||||
return velY;
|
||||
return vel_y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getKind() const -> BulletKind {
|
||||
return kind;
|
||||
auto Bullet::getKind() const -> Bullet::Kind {
|
||||
return kind_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getOwner() const -> int {
|
||||
return owner;
|
||||
return owner_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto Bullet::getCollider() -> Circle & {
|
||||
return collider;
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
void Bullet::shiftColliders() {
|
||||
collider.x = posX + collider.r;
|
||||
collider.y = posY + collider.r;
|
||||
collider_.x = pos_x_ + collider_.r;
|
||||
collider_.y = pos_y_ + collider_.r;
|
||||
}
|
||||
|
||||
@@ -1,88 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint> // for uint8_t
|
||||
#include "utils/utils.h" // for Circle
|
||||
class Sprite;
|
||||
class Texture;
|
||||
|
||||
// Tipus de bala. Enum class fortament tipat per evitar confusió accidental
|
||||
// amb altres `int`/`Uint8` (p.ex. el `owner` a `createBullet`).
|
||||
enum class BulletKind : std::uint8_t {
|
||||
NONE = 0, // bala desactivada / fora de pantalla
|
||||
UP = 1,
|
||||
LEFT = 2,
|
||||
RIGHT = 3,
|
||||
};
|
||||
|
||||
// Tipos de retorno de la función move de la bala
|
||||
constexpr int BULLET_MOVE_OK = 0;
|
||||
constexpr int BULLET_MOVE_OUT = 1;
|
||||
|
||||
// Clase Bullet
|
||||
class Bullet {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
Sprite *sprite; // Sprite con los graficos y métodos de pintado
|
||||
|
||||
// Variables
|
||||
int posX; // Posición en el eje X
|
||||
int posY; // Posición en el eje Y
|
||||
Uint8 width; // Ancho del objeto
|
||||
Uint8 height; // Alto del objeto
|
||||
int velX; // Velocidad en el eje X
|
||||
int velY; // Velocidad en el eje Y
|
||||
BulletKind kind; // Tipo de objeto
|
||||
int owner; // Identificador del dueño del objeto
|
||||
Circle collider; // Circulo de colisión del objeto
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
void shiftColliders();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Bullet();
|
||||
|
||||
Bullet(const Bullet &) = delete;
|
||||
auto operator=(const Bullet &) -> Bullet & = delete;
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza la posición y estado del objeto
|
||||
auto move() -> Uint8;
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
[[nodiscard]] auto isEnabled() const -> bool;
|
||||
|
||||
// Deshabilita el objeto
|
||||
void disable();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosX() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> int;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(int y);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getVelY() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getKind() const -> BulletKind;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getOwner() const -> int;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto getCollider() -> Circle &;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint> // for uint8_t
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
class Sprite;
|
||||
class Texture;
|
||||
|
||||
// Clase Bullet
|
||||
class Bullet {
|
||||
public:
|
||||
// Tipus de bala. Enum class fortament tipat per evitar confusió accidental
|
||||
// amb altres `int`/`Uint8` (p.ex. el `owner` a `createBullet`).
|
||||
enum class Kind : std::uint8_t {
|
||||
NONE = 0, // bala desactivada / fora de pantalla
|
||||
UP = 1,
|
||||
LEFT = 2,
|
||||
RIGHT = 3,
|
||||
};
|
||||
|
||||
// Resultado de Bullet::move()
|
||||
enum class MoveResult : std::uint8_t {
|
||||
OK = 0,
|
||||
OUT = 1,
|
||||
};
|
||||
|
||||
Bullet(int x, int y, Kind kind, bool powered_up, int owner, Texture *texture, SDL_Renderer *renderer); // Constructor
|
||||
~Bullet(); // Destructor
|
||||
|
||||
Bullet(const Bullet &) = delete;
|
||||
auto operator=(const Bullet &) -> Bullet & = delete;
|
||||
|
||||
void render(); // Pinta el objeto en pantalla
|
||||
auto move() -> MoveResult; // Actualiza la posición y estado del objeto
|
||||
void disable(); // Deshabilita el objeto
|
||||
|
||||
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si el objeto está habilitado
|
||||
[[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getVelY() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getKind() const -> Kind; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getOwner() const -> int; // Obtiene el valor de la variable
|
||||
|
||||
void setPosX(int x); // Establece el valor de la variable
|
||||
void setPosY(int y); // Establece el valor de la variable
|
||||
|
||||
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
|
||||
|
||||
private:
|
||||
// Objetos y punteros
|
||||
Sprite *sprite_; // Sprite con los graficos y métodos de pintado
|
||||
|
||||
// Variables
|
||||
int pos_x_; // Posición en el eje X
|
||||
int pos_y_; // Posición en el eje Y
|
||||
Uint8 width_; // Ancho del objeto
|
||||
Uint8 height_; // Alto del objeto
|
||||
int vel_x_; // Velocidad en el eje X
|
||||
int vel_y_; // Velocidad en el eje Y
|
||||
Kind kind_; // Tipo de objeto
|
||||
int owner_; // Identificador del dueño del objeto
|
||||
Circle collider_; // Circulo de colisión del objeto
|
||||
|
||||
void shiftColliders(); // Alinea el circulo de colisión con el objeto
|
||||
};
|
||||
|
||||
@@ -7,58 +7,58 @@
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Item::Item(Uint8 kind, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer) {
|
||||
sprite = new AnimatedSprite(texture, renderer, "", animation);
|
||||
Item::Item(Id id, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer) {
|
||||
sprite_ = new AnimatedSprite(texture, renderer, "", animation);
|
||||
|
||||
this->kind = kind;
|
||||
enabled = true;
|
||||
timeToLive = 600;
|
||||
accelX = 0.0F;
|
||||
floorCollision = false;
|
||||
this->id_ = id;
|
||||
enabled_ = true;
|
||||
time_to_live_ = 600;
|
||||
accel_x_ = 0.0F;
|
||||
floor_collision_ = false;
|
||||
|
||||
if (kind == ITEM_COFFEE_MACHINE) {
|
||||
width = 23;
|
||||
height = 29;
|
||||
posX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width - 5)) + 2;
|
||||
posY = PLAY_AREA_TOP - height;
|
||||
velX = 0.0F;
|
||||
velY = -0.1F;
|
||||
accelY = 0.1F;
|
||||
collider.r = 10;
|
||||
if (id == Item::Id::COFFEE_MACHINE) {
|
||||
width_ = 23;
|
||||
height_ = 29;
|
||||
pos_x_ = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width_ - 5)) + 2;
|
||||
pos_y_ = PLAY_AREA_TOP - height_;
|
||||
vel_x_ = 0.0F;
|
||||
vel_y_ = -0.1F;
|
||||
accel_y_ = 0.1F;
|
||||
collider_.r = 10;
|
||||
} else {
|
||||
width = 16;
|
||||
height = 16;
|
||||
posX = x;
|
||||
posY = y;
|
||||
velX = -1.0F + ((rand() % 5) * 0.5F);
|
||||
velY = -4.0F;
|
||||
accelY = 0.2F;
|
||||
collider.r = width / 2;
|
||||
width_ = 16;
|
||||
height_ = 16;
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
vel_x_ = -1.0F + ((rand() % 5) * 0.5F);
|
||||
vel_y_ = -4.0F;
|
||||
accel_y_ = 0.2F;
|
||||
collider_.r = width_ / 2;
|
||||
}
|
||||
|
||||
sprite->setPosX(posX);
|
||||
sprite->setPosY(posY);
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Item::~Item() {
|
||||
delete sprite;
|
||||
delete sprite_;
|
||||
}
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void Item::allignTo(int x) {
|
||||
posX = float(x - (width / 2));
|
||||
pos_x_ = float(x - (width_ / 2));
|
||||
|
||||
if (posX < PLAY_AREA_LEFT) {
|
||||
posX = PLAY_AREA_LEFT + 1;
|
||||
} else if ((posX + width) > PLAY_AREA_RIGHT) {
|
||||
posX = float(PLAY_AREA_RIGHT - width - 1);
|
||||
if (pos_x_ < PLAY_AREA_LEFT) {
|
||||
pos_x_ = PLAY_AREA_LEFT + 1;
|
||||
} else if ((pos_x_ + width_) > PLAY_AREA_RIGHT) {
|
||||
pos_x_ = float(PLAY_AREA_RIGHT - width_ - 1);
|
||||
}
|
||||
|
||||
// Posición X,Y del sprite
|
||||
sprite->setPosX(int(posX));
|
||||
sprite->setPosY(int(posY));
|
||||
sprite_->setPosX(int(pos_x_));
|
||||
sprite_->setPosY(int(pos_y_));
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
@@ -68,129 +68,129 @@ void Item::allignTo(int x) {
|
||||
void Item::render() {
|
||||
// Mentre quede temps de sobra (>200) es renderitza sempre; quan està a
|
||||
// punt d'expirar, parpalleja alternant 10 frames visibles i 10 invisibles.
|
||||
if (enabled && (timeToLive > 200 || timeToLive % 20 > 10)) {
|
||||
sprite->render();
|
||||
if (enabled_ && (time_to_live_ > 200 || time_to_live_ % 20 > 10)) {
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
void Item::move() {
|
||||
floorCollision = false;
|
||||
floor_collision_ = false;
|
||||
|
||||
// Calcula la nueva posición
|
||||
posX += velX;
|
||||
posY += velY;
|
||||
pos_x_ += vel_x_;
|
||||
pos_y_ += vel_y_;
|
||||
|
||||
// Aplica las aceleraciones a la velocidad
|
||||
velX += accelX;
|
||||
velY += accelY;
|
||||
vel_x_ += accel_x_;
|
||||
vel_y_ += accel_y_;
|
||||
|
||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||
if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT)) {
|
||||
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ + width_ > PLAY_AREA_RIGHT)) {
|
||||
// Corregir posición
|
||||
posX -= velX;
|
||||
pos_x_ -= vel_x_;
|
||||
|
||||
// Invertir sentido
|
||||
velX = -velX;
|
||||
vel_x_ = -vel_x_;
|
||||
}
|
||||
|
||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||
if ((posY < PLAY_AREA_TOP) && !(kind == ITEM_COFFEE_MACHINE)) {
|
||||
if ((pos_y_ < PLAY_AREA_TOP) && !(id_ == Item::Id::COFFEE_MACHINE)) {
|
||||
// Corrige
|
||||
posY -= velY;
|
||||
pos_y_ -= vel_y_;
|
||||
|
||||
// Invierte el sentido
|
||||
velY = -velY;
|
||||
vel_y_ = -vel_y_;
|
||||
}
|
||||
|
||||
// Si el objeto se sale por la parte inferior
|
||||
if (posY + height > PLAY_AREA_BOTTOM) {
|
||||
if (pos_y_ + height_ > PLAY_AREA_BOTTOM) {
|
||||
// Detiene el objeto
|
||||
velY = 0;
|
||||
velX = 0;
|
||||
accelX = 0;
|
||||
accelY = 0;
|
||||
posY = PLAY_AREA_BOTTOM - height;
|
||||
if (kind == ITEM_COFFEE_MACHINE) {
|
||||
floorCollision = true;
|
||||
vel_y_ = 0;
|
||||
vel_x_ = 0;
|
||||
accel_x_ = 0;
|
||||
accel_y_ = 0;
|
||||
pos_y_ = PLAY_AREA_BOTTOM - height_;
|
||||
if (id_ == Item::Id::COFFEE_MACHINE) {
|
||||
floor_collision_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
sprite->setPosX(int(posX));
|
||||
sprite->setPosY(int(posY));
|
||||
sprite_->setPosX(int(pos_x_));
|
||||
sprite_->setPosY(int(pos_y_));
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Pone a cero todos los valores del objeto
|
||||
void Item::disable() {
|
||||
enabled = false;
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||
void Item::update() {
|
||||
move();
|
||||
sprite->animate();
|
||||
sprite_->animate();
|
||||
updateTimeToLive();
|
||||
checkTimeToLive();
|
||||
}
|
||||
|
||||
// Actualiza el contador
|
||||
void Item::updateTimeToLive() {
|
||||
if (timeToLive > 0) {
|
||||
timeToLive--;
|
||||
if (time_to_live_ > 0) {
|
||||
time_to_live_--;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si el objeto sigue vivo
|
||||
void Item::checkTimeToLive() {
|
||||
if (timeToLive == 0) {
|
||||
if (time_to_live_ == 0) {
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
auto Item::getPosX() const -> float {
|
||||
return posX;
|
||||
return pos_x_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
auto Item::getPosY() const -> float {
|
||||
return posY;
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
auto Item::getWidth() const -> int {
|
||||
return width;
|
||||
return width_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
auto Item::getHeight() const -> int {
|
||||
return height;
|
||||
return height_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
auto Item::getClass() const -> int {
|
||||
return kind;
|
||||
auto Item::getId() const -> Id {
|
||||
return id_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Item::isEnabled() const -> bool {
|
||||
return enabled;
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto Item::getCollider() -> Circle & {
|
||||
return collider;
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto
|
||||
void Item::shiftColliders() {
|
||||
collider.x = int(posX + (width / 2));
|
||||
collider.y = int(posY + (height / 2));
|
||||
collider_.x = int(pos_x_ + (width_ / 2));
|
||||
collider_.y = int(pos_y_ + (height_ / 2));
|
||||
}
|
||||
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
auto Item::isOnFloor() const -> bool {
|
||||
return floorCollision;
|
||||
return floor_collision_;
|
||||
}
|
||||
+70
-99
@@ -1,99 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Tipos de objetos
|
||||
constexpr int ITEM_POINTS_1_DISK = 1;
|
||||
constexpr int ITEM_POINTS_2_GAVINA = 2;
|
||||
constexpr int ITEM_POINTS_3_PACMAR = 3;
|
||||
constexpr int ITEM_CLOCK = 4;
|
||||
constexpr int ITEM_COFFEE = 5;
|
||||
constexpr int ITEM_COFFEE_MACHINE = 6;
|
||||
|
||||
// Clase Item
|
||||
class Item {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
AnimatedSprite *sprite; // Sprite con los graficos del objeto
|
||||
|
||||
// Variables
|
||||
float posX; // Posición X del objeto
|
||||
float posY; // Posición Y del objeto
|
||||
Uint8 width; // Ancho del objeto
|
||||
Uint8 height; // Alto del objeto
|
||||
float velX; // Velocidad en el eje X
|
||||
float velY; // Velocidad en el eje Y
|
||||
float accelX; // Aceleración en el eje X
|
||||
float accelY; // Aceleración en el eje Y
|
||||
bool floorCollision; // Indica si el objeto colisiona con el suelo
|
||||
Uint8 kind; // Especifica el tipo de objeto que es
|
||||
bool enabled; // Especifica si el objeto está habilitado
|
||||
Circle collider; // Circulo de colisión del objeto
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto
|
||||
void shiftColliders();
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
void move();
|
||||
|
||||
public:
|
||||
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||
|
||||
// Constructor
|
||||
Item(Uint8 kind, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Item();
|
||||
|
||||
Item(const Item &) = delete;
|
||||
auto operator=(const Item &) -> Item & = delete;
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void allignTo(int x);
|
||||
|
||||
// Pinta el objeto en la pantalla
|
||||
void render();
|
||||
|
||||
// Pone a cero todos los valores del objeto
|
||||
void disable();
|
||||
|
||||
// Actualiza al objeto a su posicion, animación y controla los contadores
|
||||
void update();
|
||||
|
||||
// Actualiza el contador
|
||||
void updateTimeToLive();
|
||||
|
||||
// Comprueba si el objeto sigue vivo
|
||||
void checkTimeToLive();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
[[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 getClass() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto isEnabled() const -> bool;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto getCollider() -> Circle &;
|
||||
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
[[nodiscard]] auto isOnFloor() const -> bool;
|
||||
};
|
||||
#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, 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 a su posicion, animación y controla los contadores
|
||||
void updateTimeToLive(); // Actualiza el contador
|
||||
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:
|
||||
// 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
|
||||
float vel_y_; // Velocidad en el eje Y
|
||||
float accel_x_; // Aceleración en el eje X
|
||||
float accel_y_; // Aceleración en el eje Y
|
||||
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 con el tiempo que el objeto está presente
|
||||
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
|
||||
};
|
||||
|
||||
+187
-187
@@ -11,117 +11,117 @@
|
||||
// Constructor
|
||||
Player::Player(float x, int y, SDL_Renderer *renderer, const std::vector<Texture *> &texture, const std::vector<std::vector<std::string> *> &animations) {
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->renderer_ = renderer;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
headSprite = new AnimatedSprite(texture[0], renderer, "", animations[0]);
|
||||
bodySprite = new AnimatedSprite(texture[1], renderer, "", animations[1]);
|
||||
legsSprite = new AnimatedSprite(texture[2], renderer, "", animations[2]);
|
||||
deathSprite = new AnimatedSprite(texture[3], renderer, "", animations[3]);
|
||||
fireSprite = new AnimatedSprite(texture[4], renderer, "", animations[4]);
|
||||
fireSprite->getTexture()->setAlpha(224);
|
||||
head_sprite_ = new AnimatedSprite(texture[0], renderer, "", animations[0]);
|
||||
body_sprite_ = new AnimatedSprite(texture[1], renderer, "", animations[1]);
|
||||
legs_sprite_ = new AnimatedSprite(texture[2], renderer, "", animations[2]);
|
||||
death_sprite_ = new AnimatedSprite(texture[3], renderer, "", animations[3]);
|
||||
fire_sprite_ = new AnimatedSprite(texture[4], renderer, "", animations[4]);
|
||||
fire_sprite_->getTexture()->setAlpha(224);
|
||||
|
||||
// Establece la posición inicial del jugador
|
||||
posX = x;
|
||||
posY = y;
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Player::~Player() {
|
||||
delete headSprite;
|
||||
delete bodySprite;
|
||||
delete legsSprite;
|
||||
delete deathSprite;
|
||||
delete fireSprite;
|
||||
delete head_sprite_;
|
||||
delete body_sprite_;
|
||||
delete legs_sprite_;
|
||||
delete death_sprite_;
|
||||
delete fire_sprite_;
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void Player::init() {
|
||||
// Inicializa variables de estado
|
||||
alive = true;
|
||||
deathCounter = DEATH_COUNTER;
|
||||
statusWalking = PLAYER_STATUS_WALKING_STOP;
|
||||
statusFiring = PLAYER_STATUS_FIRING_NO;
|
||||
invulnerable = false;
|
||||
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
powerUp = false;
|
||||
powerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
extraHit = false;
|
||||
coffees = 0;
|
||||
input = true;
|
||||
alive_ = true;
|
||||
death_counter_ = DEATH_COUNTER;
|
||||
status_walking_ = STATUS_WALKING_STOP;
|
||||
status_firing_ = STATUS_FIRING_NO;
|
||||
invulnerable_ = false;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER;
|
||||
power_up_ = false;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
extra_hit_ = false;
|
||||
coffees_ = 0;
|
||||
input_ = true;
|
||||
|
||||
// Establece la altura y el ancho del jugador
|
||||
width = 24;
|
||||
height = 24;
|
||||
width_ = 24;
|
||||
height_ = 24;
|
||||
|
||||
// Establece el tamaño del circulo de colisión
|
||||
collider.r = 7;
|
||||
collider_.r = 7;
|
||||
|
||||
// Actualiza la posición del circulo de colisión
|
||||
shiftColliders();
|
||||
|
||||
// Establece la velocidad inicial
|
||||
velX = 0;
|
||||
velY = 0;
|
||||
vel_x_ = 0;
|
||||
vel_y_ = 0;
|
||||
|
||||
// Establece la velocidad base
|
||||
baseSpeed = 1.5;
|
||||
base_speed_ = 1.5;
|
||||
|
||||
// Establece la puntuación inicial
|
||||
score = 0;
|
||||
score_ = 0;
|
||||
|
||||
// Establece el multiplicador de puntos inicial
|
||||
scoreMultiplier = 1.0F;
|
||||
score_multiplier_ = 1.0F;
|
||||
|
||||
// Inicia el contador para la cadencia de disparo
|
||||
cooldown = 10;
|
||||
cooldown_ = 10;
|
||||
|
||||
// Establece la posición del sprite
|
||||
legsSprite->setPosX(posX);
|
||||
legsSprite->setPosY(posY);
|
||||
legs_sprite_->setPosX(pos_x_);
|
||||
legs_sprite_->setPosY(pos_y_);
|
||||
|
||||
bodySprite->setPosX(posX);
|
||||
bodySprite->setPosY(posY);
|
||||
body_sprite_->setPosX(pos_x_);
|
||||
body_sprite_->setPosY(pos_y_);
|
||||
|
||||
headSprite->setPosX(posX);
|
||||
headSprite->setPosY(posY);
|
||||
head_sprite_->setPosX(pos_x_);
|
||||
head_sprite_->setPosY(pos_y_);
|
||||
|
||||
// Selecciona un frame para pintar
|
||||
legsSprite->setCurrentAnimation("stand");
|
||||
bodySprite->setCurrentAnimation("stand");
|
||||
headSprite->setCurrentAnimation("stand");
|
||||
legs_sprite_->setCurrentAnimation("stand");
|
||||
body_sprite_->setCurrentAnimation("stand");
|
||||
head_sprite_->setCurrentAnimation("stand");
|
||||
}
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(Uint8 input) {
|
||||
switch (input) {
|
||||
case input_left:
|
||||
velX = -baseSpeed;
|
||||
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
|
||||
vel_x_ = -base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_LEFT);
|
||||
break;
|
||||
|
||||
case input_right:
|
||||
velX = baseSpeed;
|
||||
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
||||
vel_x_ = base_speed_;
|
||||
setWalkingStatus(STATUS_WALKING_RIGHT);
|
||||
break;
|
||||
|
||||
case input_fire_center:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
||||
setFiringStatus(STATUS_FIRING_UP);
|
||||
break;
|
||||
|
||||
case input_fire_left:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
||||
setFiringStatus(STATUS_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case input_fire_right:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
||||
setFiringStatus(STATUS_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
default:
|
||||
velX = 0;
|
||||
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
|
||||
vel_x_ = 0;
|
||||
setWalkingStatus(STATUS_WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -130,35 +130,35 @@ void Player::setInput(Uint8 input) {
|
||||
void Player::move() {
|
||||
if (isAlive()) {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
posX += velX;
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((posX < PLAY_AREA_LEFT - 5) || (posX + width > PLAY_AREA_RIGHT + 5)) { // Restaura su posición
|
||||
posX -= velX;
|
||||
if ((pos_x_ < PLAY_AREA_LEFT - 5) || (pos_x_ + width_ > PLAY_AREA_RIGHT + 5)) { // Restaura su posición
|
||||
pos_x_ -= vel_x_;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
legsSprite->setPosX(getPosX());
|
||||
legsSprite->setPosY(posY);
|
||||
legs_sprite_->setPosX(getPosX());
|
||||
legs_sprite_->setPosY(pos_y_);
|
||||
|
||||
bodySprite->setPosX(getPosX());
|
||||
bodySprite->setPosY(posY);
|
||||
body_sprite_->setPosX(getPosX());
|
||||
body_sprite_->setPosY(pos_y_);
|
||||
|
||||
headSprite->setPosX(getPosX());
|
||||
headSprite->setPosY(posY);
|
||||
head_sprite_->setPosX(getPosX());
|
||||
head_sprite_->setPosY(pos_y_);
|
||||
|
||||
fireSprite->setPosX(getPosX() - 2);
|
||||
fireSprite->setPosY(posY - 8);
|
||||
fire_sprite_->setPosX(getPosX() - 2);
|
||||
fire_sprite_->setPosY(pos_y_ - 8);
|
||||
} else {
|
||||
deathSprite->update();
|
||||
death_sprite_->update();
|
||||
|
||||
// Si el cadaver abandona el area de juego por los laterales
|
||||
if ((deathSprite->getPosX() < PLAY_AREA_LEFT) || (deathSprite->getPosX() + width > PLAY_AREA_RIGHT)) { // Restaura su posición
|
||||
const float vx = deathSprite->getVelX();
|
||||
deathSprite->setPosX(deathSprite->getPosX() - vx);
|
||||
if ((death_sprite_->getPosX() < PLAY_AREA_LEFT) || (death_sprite_->getPosX() + width_ > PLAY_AREA_RIGHT)) { // Restaura su posición
|
||||
const float VX = death_sprite_->getVelX();
|
||||
death_sprite_->setPosX(death_sprite_->getPosX() - VX);
|
||||
|
||||
// Rebota
|
||||
deathSprite->setVelX(-vx);
|
||||
death_sprite_->setVelX(-VX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,119 +166,119 @@ void Player::move() {
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (isAlive()) {
|
||||
if (invulnerable) {
|
||||
if ((invulnerableCounter % 10) > 4) {
|
||||
if (powerUp) {
|
||||
fireSprite->render();
|
||||
if (invulnerable_) {
|
||||
if ((invulnerable_counter_ % 10) > 4) {
|
||||
if (power_up_) {
|
||||
fire_sprite_->render();
|
||||
}
|
||||
legsSprite->render();
|
||||
bodySprite->render();
|
||||
headSprite->render();
|
||||
legs_sprite_->render();
|
||||
body_sprite_->render();
|
||||
head_sprite_->render();
|
||||
}
|
||||
} else {
|
||||
if (powerUp) {
|
||||
fireSprite->render();
|
||||
if (power_up_) {
|
||||
fire_sprite_->render();
|
||||
}
|
||||
legsSprite->render();
|
||||
bodySprite->render();
|
||||
headSprite->render();
|
||||
legs_sprite_->render();
|
||||
body_sprite_->render();
|
||||
head_sprite_->render();
|
||||
}
|
||||
} else {
|
||||
deathSprite->render();
|
||||
death_sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando camina
|
||||
void Player::setWalkingStatus(Uint8 status) {
|
||||
statusWalking = status;
|
||||
status_walking_ = status;
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando dispara
|
||||
void Player::setFiringStatus(Uint8 status) {
|
||||
statusFiring = status;
|
||||
status_firing_ = status;
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Player::setAnimation() {
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
std::string aBodyCoffees;
|
||||
std::string aHeadCoffees;
|
||||
if (coffees > 0) {
|
||||
aBodyCoffees = coffees == 1 ? "_1C" : "_2C";
|
||||
aHeadCoffees = "_1C";
|
||||
std::string body_coffees;
|
||||
std::string head_coffees;
|
||||
if (coffees_ > 0) {
|
||||
body_coffees = coffees_ == 1 ? "_1C" : "_2C";
|
||||
head_coffees = "_1C";
|
||||
}
|
||||
|
||||
const std::string aPowerUp = powerUp ? "_pwr" : "";
|
||||
const std::string aWalking = statusWalking == PLAYER_STATUS_WALKING_STOP ? "stand" : "walk";
|
||||
const std::string aFiring = statusFiring == PLAYER_STATUS_FIRING_UP ? "centershoot" : "sideshoot";
|
||||
const std::string POWER_UP = power_up_ ? "_pwr" : "";
|
||||
const std::string WALKING = status_walking_ == STATUS_WALKING_STOP ? "stand" : "walk";
|
||||
const std::string FIRING = status_firing_ == STATUS_FIRING_UP ? "centershoot" : "sideshoot";
|
||||
|
||||
const SDL_FlipMode flipWalk = statusWalking == PLAYER_STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode flipFire = statusFiring == PLAYER_STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_WALK = status_walking_ == STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_FIRE = status_firing_ == STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
legsSprite->setCurrentAnimation(aWalking);
|
||||
legsSprite->setFlip(flipWalk);
|
||||
if (statusFiring == PLAYER_STATUS_FIRING_NO) { // No esta disparando
|
||||
bodySprite->setCurrentAnimation(aWalking + aBodyCoffees + aPowerUp);
|
||||
bodySprite->setFlip(flipWalk);
|
||||
headSprite->setCurrentAnimation(aWalking + aHeadCoffees + aPowerUp);
|
||||
headSprite->setFlip(flipWalk);
|
||||
legs_sprite_->setCurrentAnimation(WALKING);
|
||||
legs_sprite_->setFlip(FLIP_WALK);
|
||||
if (status_firing_ == STATUS_FIRING_NO) { // No esta disparando
|
||||
body_sprite_->setCurrentAnimation(WALKING + body_coffees + POWER_UP);
|
||||
body_sprite_->setFlip(FLIP_WALK);
|
||||
head_sprite_->setCurrentAnimation(WALKING + head_coffees + POWER_UP);
|
||||
head_sprite_->setFlip(FLIP_WALK);
|
||||
} else { // Está disparando
|
||||
bodySprite->setCurrentAnimation(aFiring + aBodyCoffees + aPowerUp);
|
||||
bodySprite->setFlip(flipFire);
|
||||
headSprite->setCurrentAnimation(aFiring + aHeadCoffees + aPowerUp);
|
||||
headSprite->setFlip(flipFire);
|
||||
body_sprite_->setCurrentAnimation(FIRING + body_coffees + POWER_UP);
|
||||
body_sprite_->setFlip(FLIP_FIRE);
|
||||
head_sprite_->setCurrentAnimation(FIRING + head_coffees + POWER_UP);
|
||||
head_sprite_->setFlip(FLIP_FIRE);
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
legsSprite->animate();
|
||||
bodySprite->animate();
|
||||
headSprite->animate();
|
||||
legs_sprite_->animate();
|
||||
body_sprite_->animate();
|
||||
head_sprite_->animate();
|
||||
|
||||
fireSprite->animate();
|
||||
fireSprite->setFlip(flipWalk);
|
||||
fire_sprite_->animate();
|
||||
fire_sprite_->setFlip(FLIP_WALK);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getPosX() const -> int {
|
||||
return int(posX);
|
||||
return int(pos_x_);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getPosY() const -> int {
|
||||
return posY;
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getWidth() const -> int {
|
||||
return width;
|
||||
return width_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getHeight() const -> int {
|
||||
return height;
|
||||
return height_;
|
||||
}
|
||||
|
||||
// Indica si el jugador puede disparar
|
||||
auto Player::canFire() const -> bool {
|
||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||
return cooldown <= 0;
|
||||
return cooldown_ <= 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setFireCooldown(int time) {
|
||||
cooldown = time;
|
||||
cooldown_ = time;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateCooldown() {
|
||||
if (cooldown > 0) {
|
||||
cooldown--;
|
||||
if (powerUp) {
|
||||
cooldown--;
|
||||
if (cooldown_ > 0) {
|
||||
cooldown_--;
|
||||
if (power_up_) {
|
||||
cooldown_--;
|
||||
}
|
||||
} else {
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_NO);
|
||||
setFiringStatus(STATUS_FIRING_NO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,213 +296,213 @@ void Player::update() {
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
auto Player::getScore() const -> Uint32 {
|
||||
return score;
|
||||
return score_;
|
||||
}
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void Player::setScore(Uint32 score) {
|
||||
this->score = score;
|
||||
this->score_ = score;
|
||||
}
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
void Player::addScore(Uint32 score) {
|
||||
this->score += score;
|
||||
this->score_ += score;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::isAlive() const -> bool {
|
||||
return alive;
|
||||
return alive_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setAlive(bool value) {
|
||||
alive = value;
|
||||
alive_ = value;
|
||||
|
||||
if (!value) {
|
||||
deathSprite->setPosX(headSprite->getRect().x);
|
||||
deathSprite->setPosY(headSprite->getRect().y);
|
||||
deathSprite->setAccelY(0.2F);
|
||||
deathSprite->setVelY(-6.6F);
|
||||
deathSprite->setVelX(3.3F);
|
||||
death_sprite_->setPosX(head_sprite_->getRect().x);
|
||||
death_sprite_->setPosY(head_sprite_->getRect().y);
|
||||
death_sprite_->setAccelY(0.2F);
|
||||
death_sprite_->setVelY(-6.6F);
|
||||
death_sprite_->setVelX(3.3F);
|
||||
if (rand() % 2 == 0) {
|
||||
deathSprite->setVelX(-3.3F);
|
||||
death_sprite_->setVelX(-3.3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getScoreMultiplier() const -> float {
|
||||
return scoreMultiplier;
|
||||
return score_multiplier_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setScoreMultiplier(float value) {
|
||||
scoreMultiplier = value;
|
||||
score_multiplier_ = value;
|
||||
}
|
||||
|
||||
// Aumenta el valor de la variable hasta un máximo
|
||||
void Player::incScoreMultiplier() {
|
||||
if (scoreMultiplier < 5.0F) {
|
||||
scoreMultiplier += 0.1F;
|
||||
if (score_multiplier_ < 5.0F) {
|
||||
score_multiplier_ += 0.1F;
|
||||
} else {
|
||||
scoreMultiplier = 5.0F;
|
||||
score_multiplier_ = 5.0F;
|
||||
}
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable hasta un mínimo
|
||||
void Player::decScoreMultiplier() {
|
||||
if (scoreMultiplier > 1.0F) {
|
||||
scoreMultiplier -= 0.1F;
|
||||
if (score_multiplier_ > 1.0F) {
|
||||
score_multiplier_ -= 0.1F;
|
||||
} else {
|
||||
scoreMultiplier = 1.0F;
|
||||
score_multiplier_ = 1.0F;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::isInvulnerable() const -> bool {
|
||||
return invulnerable;
|
||||
return invulnerable_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerable(bool value) {
|
||||
invulnerable = value;
|
||||
invulnerable_ = value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getInvulnerableCounter() const -> Uint16 {
|
||||
return invulnerableCounter;
|
||||
return invulnerable_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerableCounter(Uint16 value) {
|
||||
invulnerableCounter = value;
|
||||
invulnerable_counter_ = value;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateInvulnerableCounter() {
|
||||
if (invulnerable) {
|
||||
if (invulnerableCounter > 0) {
|
||||
invulnerableCounter--;
|
||||
if (invulnerable_) {
|
||||
if (invulnerable_counter_ > 0) {
|
||||
invulnerable_counter_--;
|
||||
} else {
|
||||
invulnerable = false;
|
||||
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
invulnerable_ = false;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateDeathCounter() {
|
||||
if (!alive) {
|
||||
if (deathCounter > 0) {
|
||||
deathCounter--;
|
||||
if (!alive_) {
|
||||
if (death_counter_ > 0) {
|
||||
death_counter_--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::isPowerUp() const -> bool {
|
||||
return powerUp;
|
||||
return power_up_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUp(bool value) {
|
||||
powerUp = value;
|
||||
power_up_ = value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getPowerUpCounter() const -> Uint16 {
|
||||
return powerUpCounter;
|
||||
return power_up_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUpCounter(Uint16 value) {
|
||||
powerUpCounter = value;
|
||||
power_up_counter_ = value;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpCounter() {
|
||||
if ((powerUpCounter > 0) && (powerUp)) {
|
||||
powerUpCounter--;
|
||||
if ((power_up_counter_ > 0) && (power_up_)) {
|
||||
power_up_counter_--;
|
||||
} else {
|
||||
powerUp = false;
|
||||
powerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
power_up_ = false;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::hasExtraHit() const -> bool {
|
||||
return extraHit;
|
||||
return extra_hit_;
|
||||
}
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void Player::giveExtraHit() {
|
||||
extraHit = true;
|
||||
coffees++;
|
||||
coffees = std::min<int>(coffees, 2);
|
||||
extra_hit_ = true;
|
||||
coffees_++;
|
||||
coffees_ = std::min<int>(coffees_, 2);
|
||||
}
|
||||
|
||||
// Quita el toque extra al jugador
|
||||
void Player::removeExtraHit() {
|
||||
if (coffees > 0) {
|
||||
coffees--;
|
||||
if (coffees_ > 0) {
|
||||
coffees_--;
|
||||
}
|
||||
if (coffees == 0) {
|
||||
extraHit = false;
|
||||
if (coffees_ == 0) {
|
||||
extra_hit_ = false;
|
||||
}
|
||||
invulnerable = true;
|
||||
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
invulnerable_ = true;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER;
|
||||
}
|
||||
|
||||
// Habilita la entrada de ordenes
|
||||
void Player::enableInput() {
|
||||
input = true;
|
||||
input_ = true;
|
||||
}
|
||||
|
||||
// Deshabilita la entrada de ordenes
|
||||
void Player::disableInput() {
|
||||
input = false;
|
||||
input_ = false;
|
||||
}
|
||||
|
||||
// Devuelve el numero de cafes actuales
|
||||
auto Player::getCoffees() const -> Uint8 {
|
||||
return coffees;
|
||||
return coffees_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto Player::getCollider() -> Circle & {
|
||||
return collider;
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void Player::shiftColliders() {
|
||||
collider.x = int(posX + (width / 2));
|
||||
collider.y = (posY + (height / 2));
|
||||
collider_.x = int(pos_x_ + (width_ / 2));
|
||||
collider_.y = (pos_y_ + (height_ / 2));
|
||||
}
|
||||
|
||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||
auto Player::getDeadTexture() -> Texture * {
|
||||
return deathSprite->getTexture();
|
||||
return death_sprite_->getTexture();
|
||||
;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Player::getDeathCounter() const -> Uint16 {
|
||||
return deathCounter;
|
||||
return death_counter_;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpHeadOffset() {
|
||||
if (!powerUp) {
|
||||
if (!power_up_) {
|
||||
// powerUpHeadOffset = 0;
|
||||
} else {
|
||||
// powerUpHeadOffset = 96;
|
||||
if (powerUpCounter < 300) {
|
||||
if (powerUpCounter % 10 > 4) {
|
||||
if (power_up_counter_ < 300) {
|
||||
if (power_up_counter_ % 10 > 4) {
|
||||
// powerUpHeadOffset = 96;
|
||||
fireSprite->setEnabled(false);
|
||||
fire_sprite_->setEnabled(false);
|
||||
} else {
|
||||
// powerUpHeadOffset = 0;
|
||||
fireSprite->setEnabled(true);
|
||||
fire_sprite_->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -510,9 +510,9 @@ void Player::updatePowerUpHeadOffset() {
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void Player::setPlayerTextures(const std::vector<Texture *> &texture) {
|
||||
headSprite->setTexture(texture[0]);
|
||||
bodySprite->setTexture(texture[1]);
|
||||
legsSprite->setTexture(texture[2]);
|
||||
deathSprite->setTexture(texture[3]);
|
||||
fireSprite->setTexture(texture[4]);
|
||||
head_sprite_->setTexture(texture[0]);
|
||||
body_sprite_->setTexture(texture[1]);
|
||||
legs_sprite_->setTexture(texture[2]);
|
||||
death_sprite_->setTexture(texture[3]);
|
||||
fire_sprite_->setTexture(texture[4]);
|
||||
}
|
||||
+136
-220
@@ -1,220 +1,136 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "utils/utils.h" // for Circle
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
// Contadores
|
||||
constexpr int DEATH_COUNTER = 350;
|
||||
|
||||
// Estados del jugador
|
||||
constexpr int PLAYER_STATUS_WALKING_LEFT = 0;
|
||||
constexpr int PLAYER_STATUS_WALKING_RIGHT = 1;
|
||||
constexpr int PLAYER_STATUS_WALKING_STOP = 2;
|
||||
|
||||
constexpr int PLAYER_STATUS_FIRING_UP = 0;
|
||||
constexpr int PLAYER_STATUS_FIRING_LEFT = 1;
|
||||
constexpr int PLAYER_STATUS_FIRING_RIGHT = 2;
|
||||
constexpr int PLAYER_STATUS_FIRING_NO = 3;
|
||||
|
||||
// Variables del jugador
|
||||
constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
|
||||
constexpr int PLAYER_POWERUP_COUNTER = 1500;
|
||||
|
||||
// Clase Player
|
||||
class Player {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
AnimatedSprite *headSprite; // Sprite para dibujar la cabeza
|
||||
AnimatedSprite *bodySprite; // Sprite para dibujar el cuerpo
|
||||
AnimatedSprite *legsSprite; // Sprite para dibujar las piernas
|
||||
AnimatedSprite *deathSprite; // Sprite para dibujar el jugador derrotado
|
||||
AnimatedSprite *fireSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
|
||||
// Variables
|
||||
float posX; // Posicion en el eje X
|
||||
int posY; // Posicion en el eje Y
|
||||
|
||||
Uint8 width; // Anchura
|
||||
Uint8 height; // Altura
|
||||
|
||||
float velX; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int velY; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
|
||||
float baseSpeed; // Velocidad base del jugador
|
||||
int cooldown; // Contador durante el cual no puede disparar
|
||||
|
||||
Uint32 score; // Puntos del jugador
|
||||
float scoreMultiplier; // Multiplicador de puntos
|
||||
|
||||
Uint8 statusWalking; // Estado del jugador
|
||||
Uint8 statusFiring; // Estado del jugador
|
||||
|
||||
bool alive; // Indica si el jugador está vivo
|
||||
Uint16 deathCounter; // Contador para la animación de morirse
|
||||
bool invulnerable; // Indica si el jugador es invulnerable
|
||||
Uint16 invulnerableCounter; // Contador para la invulnerabilidad
|
||||
bool extraHit; // Indica si el jugador tiene un toque extra
|
||||
Uint8 coffees; // Indica cuantos cafes lleva acumulados
|
||||
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||
Uint16 powerUpCounter; // Temporizador para el modo PowerUp
|
||||
bool input; // Indica si puede recibir ordenes de entrada
|
||||
Circle collider; // Circulo de colisión del jugador
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void shiftColliders();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateInvulnerableCounter();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateDeathCounter();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpHeadOffset();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player(float x, int y, SDL_Renderer *renderer, const std::vector<Texture *> &texture, const std::vector<std::vector<std::string> *> &animations);
|
||||
|
||||
// Destructor
|
||||
~Player();
|
||||
|
||||
Player(const Player &) = delete;
|
||||
auto operator=(const Player &) -> Player & = delete;
|
||||
|
||||
// Iniciador
|
||||
void init();
|
||||
|
||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||
void update();
|
||||
|
||||
// Pinta el jugador en pantalla
|
||||
void render();
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void setPlayerTextures(const std::vector<Texture *> &texture);
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void setInput(Uint8 input);
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void move();
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setWalkingStatus(Uint8 status);
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setFiringStatus(Uint8 status);
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void setAnimation();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosX() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getWidth() const -> int;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getHeight() const -> int;
|
||||
|
||||
// Indica si el jugador puede disparar
|
||||
[[nodiscard]] auto canFire() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFireCooldown(int time);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateCooldown();
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
[[nodiscard]] auto getScore() const -> Uint32;
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void setScore(Uint32 score);
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
void addScore(Uint32 score);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto isAlive() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAlive(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getScoreMultiplier() const -> float;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setScoreMultiplier(float value);
|
||||
|
||||
// Aumenta el valor de la variable hasta un máximo
|
||||
void incScoreMultiplier();
|
||||
|
||||
// Decrementa el valor de la variable hasta un mínimo
|
||||
void decScoreMultiplier();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerable(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getInvulnerableCounter() const -> Uint16;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerableCounter(Uint16 value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto isPowerUp() const -> bool;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUp(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPowerUpCounter() const -> Uint16;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUpCounter(Uint16 value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpCounter();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto hasExtraHit() const -> bool;
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void giveExtraHit();
|
||||
|
||||
// Quita el toque extra al jugador
|
||||
void removeExtraHit();
|
||||
|
||||
// Habilita la entrada de ordenes
|
||||
void enableInput();
|
||||
|
||||
// Deshabilita la entrada de ordenes
|
||||
void disableInput();
|
||||
|
||||
// Devuelve el numero de cafes actuales
|
||||
[[nodiscard]] auto getCoffees() const -> Uint8;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto getCollider() -> Circle &;
|
||||
|
||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||
auto getDeadTexture() -> Texture *;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getDeathCounter() const -> Uint16;
|
||||
};
|
||||
#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 Player
|
||||
class Player {
|
||||
public:
|
||||
static constexpr int DEATH_COUNTER = 350; // Frames de la animación de muerte
|
||||
|
||||
Player(float x, int y, SDL_Renderer *renderer, const std::vector<Texture *> &texture, const std::vector<std::vector<std::string> *> &animations); // Constructor
|
||||
~Player(); // Destructor
|
||||
|
||||
Player(const Player &) = delete;
|
||||
auto operator=(const Player &) -> Player & = delete;
|
||||
|
||||
void init(); // Iniciador
|
||||
void update(); // Actualiza al jugador a su posicion, animación y controla los contadores
|
||||
void render(); // Pinta el jugador en pantalla
|
||||
void move(); // Mueve el jugador a la posición y animación que le corresponde
|
||||
|
||||
void setPlayerTextures(const std::vector<Texture *> &texture); // Pone las texturas del jugador
|
||||
void setInput(Uint8 input); // Actua en consecuencia de la entrada recibida
|
||||
void setAnimation(); // Establece la animación correspondiente al estado
|
||||
|
||||
[[nodiscard]] auto getPosX() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getPosY() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getWidth() const -> int; // Obtiene el valor de la variable
|
||||
[[nodiscard]] auto getHeight() const -> int; // Obtiene el valor de la variable
|
||||
|
||||
[[nodiscard]] auto canFire() const -> bool; // Indica si el jugador puede disparar
|
||||
void setFireCooldown(int time); // Establece el valor de la variable
|
||||
void updateCooldown(); // Actualiza el valor de la variable
|
||||
|
||||
[[nodiscard]] auto getScore() const -> Uint32; // Obtiene la puntuación del jugador
|
||||
void setScore(Uint32 score); // Asigna un valor a la puntuación del jugador
|
||||
void addScore(Uint32 score); // Incrementa la puntuación del jugador
|
||||
|
||||
[[nodiscard]] auto isAlive() const -> bool; // Obtiene el valor de la variable
|
||||
void setAlive(bool value); // Establece el valor de la variable
|
||||
|
||||
[[nodiscard]] auto getScoreMultiplier() const -> float; // Obtiene el valor de la variable
|
||||
void setScoreMultiplier(float value); // Establece el valor de la variable
|
||||
void incScoreMultiplier(); // Aumenta el valor de la variable hasta un máximo
|
||||
void decScoreMultiplier(); // Decrementa el valor de la variable hasta un mínimo
|
||||
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool; // Obtiene el valor de la variable
|
||||
void setInvulnerable(bool value); // Establece el valor de la variable
|
||||
[[nodiscard]] auto getInvulnerableCounter() const -> Uint16; // Obtiene el valor de la variable
|
||||
void setInvulnerableCounter(Uint16 value); // Establece el valor de la variable
|
||||
|
||||
[[nodiscard]] auto isPowerUp() const -> bool; // Obtiene el valor de la variable
|
||||
void setPowerUp(bool value); // Establece el valor de la variable
|
||||
[[nodiscard]] auto getPowerUpCounter() const -> Uint16; // Obtiene el valor de la variable
|
||||
void setPowerUpCounter(Uint16 value); // Establece el valor de la variable
|
||||
void updatePowerUpCounter(); // Actualiza el valor de la variable
|
||||
|
||||
[[nodiscard]] auto hasExtraHit() const -> bool; // Obtiene el valor de la variable
|
||||
void giveExtraHit(); // Concede un toque extra al jugador
|
||||
void removeExtraHit(); // Quita el toque extra al jugador
|
||||
|
||||
void enableInput(); // Habilita la entrada de ordenes
|
||||
void disableInput(); // Deshabilita la entrada de ordenes
|
||||
|
||||
[[nodiscard]] auto getCoffees() const -> Uint8; // Devuelve el numero de cafes actuales
|
||||
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
|
||||
auto getDeadTexture() -> Texture *; // Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||
[[nodiscard]] auto getDeathCounter() const -> Uint16; // Obtiene el valor de la variable
|
||||
|
||||
private:
|
||||
// Estados del jugador
|
||||
static constexpr int STATUS_WALKING_LEFT = 0;
|
||||
static constexpr int STATUS_WALKING_RIGHT = 1;
|
||||
static constexpr int STATUS_WALKING_STOP = 2;
|
||||
|
||||
static constexpr int STATUS_FIRING_UP = 0;
|
||||
static constexpr int STATUS_FIRING_LEFT = 1;
|
||||
static constexpr int STATUS_FIRING_RIGHT = 2;
|
||||
static constexpr int STATUS_FIRING_NO = 3;
|
||||
|
||||
// Variables del jugador
|
||||
static constexpr int INVULNERABLE_COUNTER = 200;
|
||||
static constexpr int POWERUP_COUNTER = 1500;
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
AnimatedSprite *head_sprite_; // Sprite para dibujar la cabeza
|
||||
AnimatedSprite *body_sprite_; // Sprite para dibujar el cuerpo
|
||||
AnimatedSprite *legs_sprite_; // Sprite para dibujar las piernas
|
||||
AnimatedSprite *death_sprite_; // Sprite para dibujar el jugador derrotado
|
||||
AnimatedSprite *fire_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
|
||||
// Variables
|
||||
float pos_x_; // Posicion en el eje X
|
||||
int pos_y_; // Posicion en el eje Y
|
||||
|
||||
Uint8 width_; // Anchura
|
||||
Uint8 height_; // Altura
|
||||
|
||||
float vel_x_; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int vel_y_; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
|
||||
float base_speed_; // Velocidad base del jugador
|
||||
int cooldown_; // Contador durante el cual no puede disparar
|
||||
|
||||
Uint32 score_; // Puntos del jugador
|
||||
float score_multiplier_; // Multiplicador de puntos
|
||||
|
||||
Uint8 status_walking_; // Estado del jugador
|
||||
Uint8 status_firing_; // Estado del jugador
|
||||
|
||||
bool alive_; // Indica si el jugador está vivo
|
||||
Uint16 death_counter_; // Contador para la animación de morirse
|
||||
bool invulnerable_; // Indica si el jugador es invulnerable
|
||||
Uint16 invulnerable_counter_; // Contador para la invulnerabilidad
|
||||
bool extra_hit_; // Indica si el jugador tiene un toque extra
|
||||
Uint8 coffees_; // Indica cuantos cafes lleva acumulados
|
||||
bool power_up_; // Indica si el jugador tiene activo el modo PowerUp
|
||||
Uint16 power_up_counter_; // Temporizador para el modo PowerUp
|
||||
bool input_; // Indica si puede recibir ordenes de entrada
|
||||
Circle collider_; // Circulo de colisión del jugador
|
||||
|
||||
void setWalkingStatus(Uint8 status); // Establece el estado del jugador
|
||||
void setFiringStatus(Uint8 status); // Establece el estado del jugador
|
||||
|
||||
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
|
||||
void updateInvulnerableCounter(); // Actualiza el valor de la variable
|
||||
void updateDeathCounter(); // Actualiza el valor de la variable
|
||||
void updatePowerUpHeadOffset(); // Actualiza el valor de la variable
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user