cleanup time-based: elimina entitats frame-based (Bullet/Item/Player/Balloon), VELX en px/s, Game::popBalloon amb vel en px/s

This commit is contained in:
2026-05-19 18:28:14 +02:00
parent 2a69eaf041
commit 635662d65d
9 changed files with 95 additions and 694 deletions
+35 -321
View File
@@ -18,32 +18,19 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
switch (kind) {
case BALLOON_1:
// Alto y ancho del objeto
width_ = WIDTH_1;
height_ = WIDTH_1;
size_ = SIZE_1;
power_ = 1;
// Inicializa los valores de velocidad y gravedad (frame-based)
this->vel_x_ = velx;
vel_y_ = 0;
max_vel_y_ = 3.0F;
gravity_ = 0.09F;
default_vel_y_ = 2.6F;
// Time-based equivalents (x60 per vel, x3600 per gravetat)
vel_x_s_ = velx * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = 0.0F;
max_vel_y_s_ = 180.0F;
gravity_s_ = 324.0F;
default_vel_y_s_ = 156.0F;
// Puntos que da el globo al ser destruido
score_ = SCORE_1;
// Amenaza que genera el globo
menace_ = 1;
break;
case BALLOON_2:
@@ -52,13 +39,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_2;
power_ = 3;
this->vel_x_ = velx;
vel_y_ = 0;
max_vel_y_ = 3.0F;
gravity_ = 0.10F;
default_vel_y_ = 3.5F;
vel_x_s_ = velx * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = 0.0F;
max_vel_y_s_ = 180.0F;
gravity_s_ = 360.0F;
@@ -74,13 +55,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_3;
power_ = 7;
this->vel_x_ = velx;
vel_y_ = 0;
max_vel_y_ = 3.0F;
gravity_ = 0.10F;
default_vel_y_ = 4.50F;
vel_x_s_ = velx * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = 0.0F;
max_vel_y_s_ = 180.0F;
gravity_s_ = 360.0F;
@@ -96,13 +71,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_4;
power_ = 15;
this->vel_x_ = velx;
vel_y_ = 0;
max_vel_y_ = 3.0F;
gravity_ = 0.10F;
default_vel_y_ = 4.95F;
vel_x_s_ = velx * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = 0.0F;
max_vel_y_s_ = 180.0F;
gravity_s_ = 360.0F;
@@ -118,17 +87,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_1;
power_ = 1;
this->vel_x_ = velx;
vel_y_ = std::fabs(velx) * 2;
max_vel_y_ = std::fabs(velx) * 2;
gravity_ = 0.00F;
default_vel_y_ = std::fabs(velx) * 2;
vel_x_s_ = velx * 60.0F;
vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = std::fabs(velx) * 2.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F;
gravity_s_ = 0.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F;
score_ = SCORE_1;
menace_ = 1;
@@ -140,17 +103,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_2;
power_ = 3;
this->vel_x_ = velx;
vel_y_ = std::fabs(velx) * 2;
max_vel_y_ = std::fabs(velx) * 2;
gravity_ = 0.00F;
default_vel_y_ = std::fabs(velx) * 2;
vel_x_s_ = velx * 60.0F;
vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = std::fabs(velx) * 2.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F;
gravity_s_ = 0.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F;
score_ = SCORE_2;
menace_ = 2;
@@ -162,17 +119,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_3;
power_ = 7;
this->vel_x_ = velx;
vel_y_ = std::fabs(velx) * 2;
max_vel_y_ = std::fabs(velx) * 2;
gravity_ = 0.00F;
default_vel_y_ = std::fabs(velx) * 2;
vel_x_s_ = velx * 60.0F;
vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = std::fabs(velx) * 2.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F;
gravity_s_ = 0.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F;
score_ = SCORE_3;
menace_ = 4;
@@ -184,17 +135,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = SIZE_4;
power_ = 15;
this->vel_x_ = velx;
vel_y_ = std::fabs(velx) * 2;
max_vel_y_ = std::fabs(velx) * 2;
gravity_ = 0.00F;
default_vel_y_ = std::fabs(velx) * 2;
vel_x_s_ = velx * 60.0F;
vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = std::fabs(velx) * 2.0F;
max_vel_y_s_ = std::fabs(velx) * 2.0F;
gravity_s_ = 0.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F * 60.0F;
default_vel_y_s_ = std::fabs(velx) * 2.0F;
score_ = SCORE_4;
menace_ = 8;
@@ -206,13 +151,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
size_ = 4;
power_ = 0;
this->vel_x_ = velx;
vel_y_ = 0;
max_vel_y_ = 3.0F;
gravity_ = 0.10F;
default_vel_y_ = 4.95F;
vel_x_s_ = velx * 60.0F;
vel_x_s_ = velx;
vel_y_s_ = 0.0F;
max_vel_y_s_ = 180.0F;
gravity_s_ = 360.0F;
@@ -229,7 +168,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// sempre que canvia. setRotateSpeed(1) evita la UB del `counter_
// % 0` dins MovingSprite::rotate().
sprite_->setRotateSpeed(1);
sprite_->setRotateAmount(vel_x_ > 0.0F ? 2.0 : -2.0);
sprite_->setRotateAmount(vel_x_s_ > 0.0F ? 2.0 : -2.0);
break;
@@ -284,8 +223,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
being_created_ = creation_counter_ != 0;
invulnerable_ = being_created_;
counter_ = 0;
travel_y_ = 1.0F;
this->speed_ = speed;
// Tipo
@@ -351,96 +288,8 @@ void Balloon::render() {
}
}
// Actualiza la posición y estados del globo
void Balloon::move() {
// Comprueba si se puede mover
if (!isStopped()) {
// Lo mueve a izquierda o derecha
pos_x_ += (vel_x_ * speed_);
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ + width_ > PLAY_AREA_RIGHT)) {
// Corrige posición
pos_x_ -= (vel_x_ * speed_);
// Invierte sentido
vel_x_ = -vel_x_;
// Invierte la rotación
sprite_->switchRotate();
// Activa el efecto de rebote
if (kind_ != POWER_BALL) {
bounceStart();
}
}
// Mueve el globo hacia arriba o hacia abajo
pos_y_ += (vel_y_ * speed_);
// Si se sale por arriba
if (pos_y_ < PLAY_AREA_TOP) {
// Corrige
pos_y_ = PLAY_AREA_TOP;
// Invierte sentido
vel_y_ = -vel_y_;
// Activa el efecto de rebote
if (kind_ != POWER_BALL) {
bounceStart();
}
}
// Si el globo se sale por la parte inferior
if (pos_y_ + height_ > PLAY_AREA_BOTTOM) {
// Corrige
pos_y_ = PLAY_AREA_BOTTOM - height_;
// Invierte colocando una velocidad por defecto
vel_y_ = -default_vel_y_;
// Activa el efecto de rebote
if (kind_ != POWER_BALL) {
bounceStart();
}
}
/*
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
*/
// Incrementa la variable que calcula la distancia acumulada en Y
travel_y_ += speed_;
// Si la distancia acumulada en Y es igual a la velocidad, se aplica la gravedad
if (travel_y_ >= 1.0F) {
// Quita el excedente
travel_y_ -= 1.0F;
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
vel_y_ += gravity_;
// Al parecer esta asignación se quedó sin hacer y ahora el juego no funciona
// correctamente si se aplica, así que se deja sin efecto
// velY = std::min(velY, maxVelY);
}
// Actualiza la posición del sprite
sprite_->setPosX(getPosX());
sprite_->setPosY(getPosY());
}
}
// Actualiza la posición y estados del globo (time-based).
// Reemplaça l'acumulador `travel_y_` per integració contínua: gravetat i
// posició s'apliquen escalades per `speed_` (tempo del joc) cada tick,
// equivalent en mitjana a l'original però sense l'efecte chunky.
// Actualiza la posición y estados del globo. Integració contínua: gravetat i
// posició s'apliquen escalades per `speed_` (tempo del joc) cada tick.
void Balloon::move(float dt_s) {
if (!isStopped()) {
// Eix X
@@ -449,7 +298,6 @@ void Balloon::move(float dt_s) {
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ + width_ > PLAY_AREA_RIGHT)) {
pos_x_ -= vel_x_s_ * speed_ * dt_s;
vel_x_s_ = -vel_x_s_;
vel_x_ = -vel_x_; // mantenir frame-based sincronitzat (UB-free per a sprite->switchRotate)
sprite_->switchRotate();
if (kind_ != POWER_BALL) { bounceStart(); }
}
@@ -460,19 +308,16 @@ void Balloon::move(float dt_s) {
if (pos_y_ < PLAY_AREA_TOP) {
pos_y_ = PLAY_AREA_TOP;
vel_y_s_ = -vel_y_s_;
vel_y_ = -vel_y_;
if (kind_ != POWER_BALL) { bounceStart(); }
}
if (pos_y_ + height_ > PLAY_AREA_BOTTOM) {
pos_y_ = PLAY_AREA_BOTTOM - height_;
vel_y_s_ = -default_vel_y_s_;
vel_y_ = -default_vel_y_;
if (kind_ != POWER_BALL) { bounceStart(); }
}
// Gravetat contínua (el tempo `speed_` escala també la gravetat per
// mantenir el mateix patró de rebot que la versió frame-based).
// Gravetat contínua (el tempo `speed_` escala també la gravetat).
vel_y_s_ += gravity_s_ * speed_ * dt_s;
sprite_->setPosX(getPosX());
@@ -487,22 +332,18 @@ void Balloon::disable() {
collider_.r = 0;
collider_.x = 0;
collider_.y = 0;
counter_ = 0;
creation_counter_ = 0;
creation_counter_ini_ = 0;
creation_counter_s_ = 0.0F;
creation_counter_ini_s_ = 0.0F;
creation_phase_s_ = 0.0F;
bounce_phase_s_ = 0.0F;
default_vel_y_ = 0.0F;
default_vel_y_s_ = 0.0F;
enabled_ = false;
gravity_ = 0.0F;
gravity_s_ = 0.0F;
height_ = 0;
invulnerable_ = false;
kind_ = 0;
max_vel_y_ = 0.0F;
max_vel_y_s_ = 0.0F;
menace_ = 0;
popping_ = false;
@@ -515,9 +356,6 @@ void Balloon::disable() {
stopped_ = false;
stopped_counter_ = 0;
stopped_counter_s_ = 0.0F;
travel_y_ = 0;
vel_x_ = 0.0F;
vel_y_ = 0.0F;
vel_x_s_ = 0.0F;
vel_y_s_ = 0.0F;
visible_ = false;
@@ -536,19 +374,6 @@ void Balloon::pop() {
}
// Actualiza al globo a su posicion, animación y controla los contadores
void Balloon::update() {
if (enabled_) {
sprite_->MovingSprite::update();
move();
updateAnimation();
updateColliders();
updateState();
updateBounce();
counter_++;
}
}
// Actualiza al globo (time-based)
void Balloon::update(float dt_s) {
if (enabled_) {
// MovingSprite::update(dt_s) avança la rotació (entre altres). La posició
@@ -563,21 +388,6 @@ void Balloon::update(float dt_s) {
}
// Actualiza los estados del globo
void Balloon::updateState() {
if (isPopping()) {
updateStatePopping();
}
if (isBeingCreated()) {
updateStateBeingCreated();
}
// Solo comprueba el estado detenido cuando no se está creando
else if (isStopped()) {
updateStateStopped();
}
}
// Actualiza los estados del globo (time-based)
void Balloon::updateState(float dt_s) {
if (isPopping()) {
updateStatePopping();
@@ -599,46 +409,10 @@ void Balloon::updateStatePopping() {
}
}
// Rama de updateState: globo creándose
void Balloon::updateStateBeingCreated() {
setStop(true);
setInvulnerable(true);
// Todavia tiene tiempo en el contador
if (creation_counter_ > 0) {
// Desplaza lentamente el globo hacia abajo y hacia un lado
if (creation_counter_ % 10 == 0) {
pos_y_++;
pos_x_ += vel_x_;
// Comprueba no se salga por los laterales
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ > (PLAY_AREA_RIGHT - width_))) {
// Corrige y cambia el sentido de la velocidad
pos_x_ -= vel_x_;
vel_x_ = -vel_x_;
}
// Actualiza la posición del sprite
sprite_->setPosX(getPosX());
sprite_->setPosY(getPosY());
// Actualiza la posición del circulo de colisión
updateColliders();
}
creation_counter_--;
}
// El contador ha llegado a cero
else {
setBeingCreated(false);
setStop(false); // reactiva la rotació de la PowerBall si escau
setVisible(true);
setInvulnerable(false);
}
}
// Rama de updateState: globo creándose (time-based). Manté el chunk pattern
// original: cada CREATION_STEP_S s'aplica un step de drift.
// Rama de updateState: globo creándose. Manté el chunk pattern original:
// cada CREATION_STEP_S s'aplica un step de drift (equivalent a "cada 10
// frames" del codi original). El drift en X usa vel_x_s_/60 per a obtenir
// el mateix delta px-per-step.
void Balloon::updateStateBeingCreated(float dt_s) {
setStop(true);
setInvulnerable(true);
@@ -648,11 +422,11 @@ void Balloon::updateStateBeingCreated(float dt_s) {
while (creation_phase_s_ >= CREATION_STEP_S) {
creation_phase_s_ -= CREATION_STEP_S;
pos_y_ += 1.0F;
pos_x_ += vel_x_; // drift idèntic a l'original (vel_x_ en px/frame)
const float DRIFT_X = vel_x_s_ / 60.0F;
pos_x_ += DRIFT_X;
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ > (PLAY_AREA_RIGHT - width_))) {
pos_x_ -= vel_x_;
vel_x_ = -vel_x_;
pos_x_ -= DRIFT_X;
vel_x_s_ = -vel_x_s_;
}
@@ -672,18 +446,6 @@ void Balloon::updateStateBeingCreated(float dt_s) {
}
// Rama de updateState: globo detenido (no creándose)
void Balloon::updateStateStopped() {
// Reduce el contador
if (stopped_counter_ > 0) {
stopped_counter_--;
}
// Quitarles el estado "detenido" si no estan explosionando
else if (!isPopping()) {
setStop(false); // reactiva la rotació de la PowerBall si escau
}
}
// Rama de updateState: globo detenido (time-based)
void Balloon::updateStateStopped(float dt_s) {
if (stopped_counter_s_ > 0.0F) {
stopped_counter_s_ = std::max(0.0F, stopped_counter_s_ - dt_s);
@@ -694,31 +456,6 @@ void Balloon::updateStateStopped(float dt_s) {
}
// Establece la animación correspondiente al estado
void Balloon::updateAnimation() {
std::string creating_animation = "blue";
std::string normal_animation = "orange";
if (kind_ == POWER_BALL) {
creating_animation = "powerball";
normal_animation = "powerball";
} else if (getClass() == HEXAGON_CLASS) {
creating_animation = "red";
normal_animation = "green";
}
// Establece el frame de animación
if (isPopping()) {
sprite_->setCurrentAnimation("pop");
} else if (isBeingCreated()) {
sprite_->setCurrentAnimation(creating_animation);
} else {
sprite_->setCurrentAnimation(normal_animation);
}
sprite_->animate();
}
// Establece la animación correspondiente (time-based)
void Balloon::updateAnimation(float dt_s) {
std::string creating_animation = "blue";
std::string normal_animation = "orange";
@@ -757,11 +494,6 @@ auto Balloon::getPosY() const -> float {
return pos_y_;
}
// Obtiene del valor de la variable
auto Balloon::getVelY() const -> float {
return vel_y_;
}
// Obtiene del valor de la variable
auto Balloon::getWidth() const -> int {
return width_;
@@ -772,10 +504,9 @@ auto Balloon::getHeight() const -> int {
return height_;
}
// Establece el valor de la variable
// Establece el valor de la variable (px/s)
void Balloon::setVelY(float vel_y) {
this->vel_y_ = vel_y;
this->vel_y_s_ = vel_y * 60.0F;
this->vel_y_s_ = vel_y;
}
// Establece el valor de la variable
@@ -933,23 +664,6 @@ void Balloon::bounceStop() {
bouncing_.desp_y = 0.0F;
}
void Balloon::updateBounce() {
if (bouncing_.enabled) {
bouncing_.zoom_width = bouncing_.w[bouncing_.counter / bouncing_.speed];
bouncing_.zoom_height = bouncing_.h[bouncing_.counter / bouncing_.speed];
sprite_->setZoomW(bouncing_.zoom_width);
sprite_->setZoomH(bouncing_.zoom_height);
bouncing_.desp_x = (sprite_->getSpriteClip().w - (sprite_->getSpriteClip().w * bouncing_.zoom_width));
bouncing_.desp_y = (sprite_->getSpriteClip().h - (sprite_->getSpriteClip().h * bouncing_.zoom_height));
bouncing_.counter++;
if ((bouncing_.counter / bouncing_.speed) > (MAX_BOUNCE - 1)) {
bounceStop();
}
}
}
// Aplica l'efecte de rebote (time-based). Manté la mateixa cadència: cada
// `bouncing_.speed` "frames" (a 60Hz) avança un slot del vector w/h.
void Balloon::updateBounce(float dt_s) {
if (!bouncing_.enabled) { return; }
@@ -973,4 +687,4 @@ void Balloon::updateBounce(float dt_s) {
sprite_->setZoomH(bouncing_.zoom_height);
bouncing_.desp_x = (sprite_->getSpriteClip().w - (sprite_->getSpriteClip().w * bouncing_.zoom_width));
bouncing_.desp_y = (sprite_->getSpriteClip().h - (sprite_->getSpriteClip().h * bouncing_.zoom_height));
}
}
+20 -35
View File
@@ -39,9 +39,9 @@ class Balloon {
static constexpr int BALLOON_CLASS = 0;
static constexpr int HEXAGON_CLASS = 1;
// Velocidad del globo
static constexpr float VELX_POSITIVE = 0.7F;
static constexpr float VELX_NEGATIVE = -0.7F;
// Velocitat horitzontal en px/s (era 0.7 px/frame * 60).
static constexpr float VELX_POSITIVE = 42.0F;
static constexpr float VELX_NEGATIVE = -42.0F;
// Velocidades a las que se mueven los globos
static constexpr float SPEED_1 = 0.60F;
@@ -68,12 +68,10 @@ class Balloon {
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 (frame-based)
void move(float dt_s); // Actualiza la posición y estados del globo (time-based)
void move(float dt_s); // 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 (frame-based)
void update(float dt_s); // Actualiza al globo (time-based)
void update(float dt_s); // Actualiza al globo
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si el globo está habilitado
[[nodiscard]] auto isStopped() const -> bool; // Obtiene del valor de la variable
@@ -85,7 +83,6 @@ class Balloon {
[[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
@@ -137,16 +134,11 @@ class Balloon {
float pos_y_; // Posición en el eje Y
Uint8 width_; // Ancho
Uint8 height_; // Alto
float vel_x_; // Velocidad en X (frame-based: px/frame)
float vel_y_; // Velocidad en Y (frame-based: px/frame)
float gravity_; // Aceleración Y (frame-based: px/frame²)
float default_vel_y_; // Velocitat inicial al rebotar contra el terra (frame-based)
float max_vel_y_; // Velocitat màxima en Y (frame-based)
float vel_x_s_{0.0F}; // Velocidad en X (time-based: px/s)
float vel_y_s_{0.0F}; // Velocidad en Y (time-based: px/s)
float gravity_s_{0.0F}; // Aceleración Y (time-based: px/s²)
float default_vel_y_s_{0.0F}; // Velocitat inicial al rebotar (time-based)
float max_vel_y_s_{0.0F}; // Velocitat màxima en Y (time-based)
float vel_x_s_{0.0F}; // Velocidad en X (px/s)
float vel_y_s_{0.0F}; // Velocidad en Y (px/s)
float gravity_s_{0.0F}; // Aceleración Y (px/s²)
float default_vel_y_s_{0.0F}; // Velocitat inicial al rebotar (px/s)
float max_vel_y_s_{0.0F}; // Velocitat màxima en Y (px/s, no aplicada en time-based actual)
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
@@ -155,40 +147,33 @@ class Balloon {
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 (frame-based)
Uint16 creation_counter_; // Temporizador (frames, derivat de creation_counter_s_ per a render alpha)
Uint16 creation_counter_ini_; // Valor inicial del temporizador (frames)
float creation_counter_s_{0.0F}; // Temporizador (time-based)
float creation_counter_s_{0.0F}; // Temporizador (font de veritat, segons)
float creation_counter_ini_s_{0.0F}; // Valor inicial del temporizador (segons)
float creation_phase_s_{0.0F}; // Acumulador de fase per als steps de creació (time-based)
float creation_phase_s_{0.0F}; // Acumulador de fase per als steps de creació
Uint16 score_; // Puntos que da el globo al ser destruido
Uint16 stopped_counter_; // Contador (frame-based)
float stopped_counter_s_{0.0F}; // Contador (time-based)
Uint16 stopped_counter_; // Contador (frames, derivat de stopped_counter_s_)
float stopped_counter_s_{0.0F}; // Contador (font de veritat, segons)
Uint8 kind_; // Tipo de globo
Uint8 menace_; // Cantidad de amenaza que genera el globo
Uint32 counter_; // Contador interno (legacy, no usat per cap lector)
float travel_y_; // Acumulador per a aplicar la gravetat (frame-based)
float speed_; // Tempo del joc (multiplicador adimensional, frame i time-based)
float speed_; // Tempo del joc (multiplicador adimensional)
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
float bounce_phase_s_{0.0F}; // Fase del bounce (time-based)
float bounce_phase_s_{0.0F}; // Fase del bounce
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 (frame-based)
void updateBounce(float dt_s); // Aplica el efecto (time-based)
void updateAnimation(); // Establece la animación correspondiente (frame-based)
void updateAnimation(float dt_s); // Establece la animación correspondiente (time-based)
void updateBounce(float dt_s); // Aplica el efecto
void updateAnimation(float dt_s); // Establece la animación correspondiente
void setBeingCreated(bool value); // Establece el valor de la variable
void updateState(); // Actualiza los estados del globo (frame-based)
void updateState(float dt_s); // Actualiza los estados del globo (time-based)
void updateState(float dt_s); // Actualiza los estados del globo
// Helpers de updateState, uno por cada rama de estado
void updateStatePopping();
void updateStateBeingCreated();
void updateStateBeingCreated(float dt_s);
void updateStateStopped();
void updateStateStopped(float dt_s);
};
+1 -49
View File
@@ -19,7 +19,6 @@ Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Text
height_ = 10;
// Velocidad inicial en el eje Y
vel_y_ = -3;
vel_y_s_ = VEL_Y_PX_PER_S;
// Tipo de bala
@@ -32,7 +31,6 @@ Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Text
switch (kind) {
case Bullet::Kind::UP:
// Establece la velocidad inicial
vel_x_ = 0;
vel_x_s_ = 0.0F;
// Rectangulo con los gráficos del objeto
@@ -45,7 +43,6 @@ Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Text
case Bullet::Kind::LEFT:
// Establece la velocidad inicial
vel_x_ = -2;
vel_x_s_ = VEL_X_LEFT_PX_PER_S;
// Rectangulo con los gráficos del objeto
@@ -58,7 +55,6 @@ Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Text
case Bullet::Kind::RIGHT:
// Establece la velocidad inicial
vel_x_ = 2;
vel_x_s_ = VEL_X_RIGHT_PX_PER_S;
// Rectangulo con los gráficos del objeto
@@ -90,46 +86,7 @@ void Bullet::render() {
sprite_->render();
}
// Actualiza la posición y estado del objeto en horizontal
auto Bullet::move() -> MoveResult {
// Variable con el valor de retorno
MoveResult msg = MoveResult::OK;
// Mueve el objeto a su nueva posición
pos_x_ += vel_x_;
// Si el objeto se sale del area de juego por los laterales
if ((pos_x_ < PLAY_AREA_LEFT - width_) || (pos_x_ > PLAY_AREA_RIGHT)) {
// Se deshabilita
kind_ = Bullet::Kind::NONE;
// Mensaje de salida
msg = MoveResult::OUT;
}
// Mueve el objeto a su nueva posición en vertical
pos_y_ += vel_y_;
// Si el objeto se sale del area de juego por la parte superior
if (pos_y_ < PLAY_AREA_TOP - height_) {
// Se deshabilita
kind_ = Bullet::Kind::NONE;
// Mensaje de salida
msg = MoveResult::OUT;
}
// Actualiza la posición del sprite
sprite_->setPosX(pos_x_);
sprite_->setPosY(pos_y_);
// Alinea el circulo de colisión con el objeto
shiftColliders();
return msg;
}
// Actualiza la posición y estado del objeto (time-based)
// Actualiza la posición y estado del objeto
auto Bullet::move(float dt_s) -> MoveResult {
MoveResult msg = MoveResult::OK;
@@ -189,11 +146,6 @@ void Bullet::setPosY(int y) {
pos_y_f_ = static_cast<float>(y);
}
// Obtiene el valor de la variable
auto Bullet::getVelY() const -> int {
return vel_y_;
}
// Obtiene el valor de la variable
auto Bullet::getKind() const -> Bullet::Kind {
return kind_;
+6 -10
View File
@@ -33,14 +33,12 @@ class Bullet {
auto operator=(const Bullet &) -> Bullet & = delete;
void render(); // Pinta el objeto en pantalla
auto move() -> MoveResult; // Actualiza la posición y estado del objeto (frame-based)
auto move(float dt_s) -> MoveResult; // Actualiza la posición y estado del objeto (time-based)
auto move(float dt_s) -> 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
@@ -50,7 +48,7 @@ class Bullet {
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
private:
// Velocidades time-based (px/s). Derivades de les antigues px/frame * 60.
// Velocitats en px/s (derivades de les antigues px/frame * 60).
static constexpr float VEL_Y_PX_PER_S = -180.0F; // Era -3 px/frame
static constexpr float VEL_X_LEFT_PX_PER_S = -120.0F; // Era -2 px/frame
static constexpr float VEL_X_RIGHT_PX_PER_S = 120.0F; // Era +2 px/frame
@@ -61,14 +59,12 @@ class Bullet {
// Variables
int pos_x_; // Posición en el eje X (px enters per al sprite/collider)
int pos_y_; // Posición en el eje Y
float pos_x_f_{0}; // Acumulador subpíxel per al moviment time-based
float pos_y_f_{0}; // Acumulador subpíxel per al moviment time-based
float pos_x_f_{0}; // Acumulador subpíxel
float pos_y_f_{0}; // Acumulador subpíxel
Uint8 width_; // Ancho del objeto
Uint8 height_; // Alto del objeto
int vel_x_; // Velocidad en el eje X (frame-based: px/frame)
int vel_y_; // Velocidad en el eje Y (frame-based: px/frame)
float vel_x_s_{0}; // Velocidad en el eje X (time-based: px/s)
float vel_y_s_{0}; // Velocidad en el eje Y (time-based: px/s)
float vel_x_s_{0}; // Velocidad en el eje X (px/s)
float vel_y_s_{0}; // Velocidad en el eje Y (px/s)
Kind kind_; // Tipo de objeto
int owner_; // Identificador del dueño del objeto
Circle collider_; // Circulo de colisión del objeto
+3 -73
View File
@@ -15,7 +15,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
enabled_ = true;
time_to_live_ = 600;
time_to_live_s_ = TIME_TO_LIVE_S;
accel_x_ = 0.0F;
accel_x_s_ = 0.0F;
floor_collision_ = false;
@@ -24,9 +23,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
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;
vel_x_s_ = 0.0F;
vel_y_s_ = COFFEE_VEL_Y_PX_PER_S;
accel_y_s_ = COFFEE_ACCEL_Y_PX_PER_S2;
@@ -38,9 +34,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
pos_y_ = y;
// Distribució original: -1.0, -0.5, 0.0, 0.5, 1.0 px/frame ⇒ -60..60 px/s en passos de 30.
const int RAND_STEP = rand() % 5;
vel_x_ = -1.0F + (static_cast<float>(RAND_STEP) * 0.5F);
vel_y_ = -4.0F;
accel_y_ = 0.2F;
vel_x_s_ = (-2.0F + static_cast<float>(RAND_STEP)) * ITEM_VEL_X_STEP_PX_PER_S;
vel_y_s_ = ITEM_VEL_Y_PX_PER_S;
accel_y_s_ = ITEM_ACCEL_Y_PX_PER_S2;
@@ -85,55 +78,6 @@ void Item::render() {
}
// Actualiza la posición y estados del objeto
void Item::move() {
floor_collision_ = false;
// Calcula la nueva posición
pos_x_ += vel_x_;
pos_y_ += vel_y_;
// Aplica las aceleraciones a la velocidad
vel_x_ += accel_x_;
vel_y_ += accel_y_;
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ + width_ > PLAY_AREA_RIGHT)) {
// Corregir posición
pos_x_ -= vel_x_;
// Invertir sentido
vel_x_ = -vel_x_;
}
// Si se sale por arriba rebota (excepto la maquina de café)
if ((pos_y_ < PLAY_AREA_TOP) && !(id_ == Item::Id::COFFEE_MACHINE)) {
// Corrige
pos_y_ -= vel_y_;
// Invierte el sentido
vel_y_ = -vel_y_;
}
// Si el objeto se sale por la parte inferior
if (pos_y_ + height_ > PLAY_AREA_BOTTOM) {
// Detiene el objeto
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(pos_x_));
sprite_->setPosY(int(pos_y_));
shiftColliders();
}
// Actualiza la posición y estados del objeto (time-based)
void Item::move(float dt_s) {
floor_collision_ = false;
@@ -180,14 +124,6 @@ void Item::disable() {
}
// Actualiza el objeto a su posicion, animación y controla los contadores
void Item::update() {
move();
sprite_->animate();
updateTimeToLive();
checkTimeToLive();
}
// Actualiza el objeto (time-based)
void Item::update(float dt_s) {
move(dt_s);
sprite_->animate(dt_s);
@@ -195,15 +131,9 @@ void Item::update(float dt_s) {
checkTimeToLive();
}
// Actualiza el contador
void Item::updateTimeToLive() {
if (time_to_live_ > 0) {
time_to_live_--;
}
}
// Actualiza el contador (time-based). Manté time_to_live_ sincronitzat per a
// que render() segueixi funcionant amb la mateixa condició de parpelleig.
// Actualiza el contador. Manté time_to_live_ (frames) sincronitzat amb el
// segons per a que render() segueixi funcionant amb la mateixa condició de
// parpelleig.
void Item::updateTimeToLive(float dt_s) {
if (time_to_live_s_ > 0.0F) {
time_to_live_s_ = std::max(0.0F, time_to_live_s_ - dt_s);
+9 -16
View File
@@ -32,10 +32,8 @@ class Item {
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 update(float dt_s); // Actualiza al objeto
void updateTimeToLive(float dt_s); // Actualiza el contador
void checkTimeToLive(); // Comprueba si el objeto sigue vivo
[[nodiscard]] auto getPosX() const -> float; // Obtiene del valor de la variable
@@ -68,22 +66,17 @@ class Item {
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²)
float vel_x_s_{0.0F}; // Velocidad en el eje X (px/s)
float vel_y_s_{0.0F}; // Velocidad en el eje Y (px/s)
float accel_x_s_{0.0F}; // Aceleración en el eje X (px/s²)
float accel_y_s_{0.0F}; // Aceleración en el eje Y (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)
Uint16 time_to_live_; // Temporizador (frames, derivat de time_to_live_s_ per a render())
float time_to_live_s_{0.0F}; // Temporizador (font de veritat, segons)
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)
void move(float dt_s); // Actualiza la posición y estados del objeto
};
+7 -164
View File
@@ -67,12 +67,9 @@ void Player::init() {
shiftColliders();
// Establece la velocidad inicial
vel_x_ = 0;
vel_y_ = 0;
vel_x_s_ = 0.0F;
// Establece la velocidad base
base_speed_ = 1.5;
base_speed_s_ = BASE_SPEED_PX_PER_S;
// Establece la puntuación inicial
@@ -105,13 +102,11 @@ void Player::init() {
void Player::setInput(Input::Action input) {
switch (input) {
case Input::Action::LEFT:
vel_x_ = -base_speed_;
vel_x_s_ = -base_speed_s_;
setWalkingStatus(STATUS_WALKING_LEFT);
break;
case Input::Action::RIGHT:
vel_x_ = base_speed_;
vel_x_s_ = base_speed_s_;
setWalkingStatus(STATUS_WALKING_RIGHT);
break;
@@ -129,7 +124,6 @@ void Player::setInput(Input::Action input) {
break;
default:
vel_x_ = 0;
vel_x_s_ = 0.0F;
setWalkingStatus(STATUS_WALKING_STOP);
break;
@@ -137,43 +131,6 @@ void Player::setInput(Input::Action input) {
}
// Mueve el jugador a la posición y animación que le corresponde
void Player::move() {
if (isAlive()) {
// Mueve el jugador a derecha o izquierda
pos_x_ += vel_x_;
// Si el jugador abandona el area de juego por los laterales
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
legs_sprite_->setPosX(getPosX());
legs_sprite_->setPosY(pos_y_);
body_sprite_->setPosX(getPosX());
body_sprite_->setPosY(pos_y_);
head_sprite_->setPosX(getPosX());
head_sprite_->setPosY(pos_y_);
fire_sprite_->setPosX(getPosX() - 2);
fire_sprite_->setPosY(pos_y_ - 8);
} else {
death_sprite_->update();
// Si el cadaver abandona el area de juego por los laterales
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
death_sprite_->setVelX(-VX);
}
}
}
// Mueve el jugador a la posición y animación que le corresponde (time-based)
void Player::move(float dt_s) {
if (isAlive()) {
pos_x_ += vel_x_s_ * dt_s;
@@ -240,47 +197,6 @@ void Player::setFiringStatus(Uint8 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 body_coffees;
std::string head_coffees;
if (coffees_ > 0) {
body_coffees = coffees_ == 1 ? "_1C" : "_2C";
head_coffees = "_1C";
}
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 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
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
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
legs_sprite_->animate();
body_sprite_->animate();
head_sprite_->animate();
fire_sprite_->animate();
fire_sprite_->setFlip(FLIP_WALK);
}
// Establece la animación correspondiente al estado (time-based)
void Player::setAnimation(float dt_s) {
std::string body_coffees;
std::string head_coffees;
@@ -356,19 +272,7 @@ void Player::setFireCooldownS(float seconds) {
cooldown_ = static_cast<int>(seconds * 60.0F);
}
// Actualiza el valor de la variable
void Player::updateCooldown() {
if (cooldown_ > 0) {
cooldown_--;
if (power_up_) {
cooldown_--;
}
} else {
setFiringStatus(STATUS_FIRING_NO);
}
}
// Actualiza el cooldown (time-based). Quan està en mode PowerUp, el cooldown
// Actualiza el cooldown. Quan està en mode PowerUp, el cooldown
// es consumeix el doble de ràpid (equivalent a decrementar 2 frames per tick).
void Player::updateCooldown(float dt_s) {
if (cooldown_s_ > 0.0F) {
@@ -381,18 +285,6 @@ void Player::updateCooldown(float dt_s) {
}
// Actualiza al jugador a su posicion, animación y controla los contadores
void Player::update() {
move();
setAnimation();
shiftColliders();
updateCooldown();
updatePowerUpCounter();
updateInvulnerableCounter();
updateDeathCounter();
updatePowerUpHeadOffset();
}
// Actualiza al jugador (time-based)
void Player::update(float dt_s) {
move(dt_s);
setAnimation(dt_s);
@@ -491,20 +383,8 @@ void Player::setInvulnerableCounter(Uint16 value) {
invulnerable_counter_s_ = static_cast<float>(value) / 60.0F;
}
// Actualiza el valor de la variable
void Player::updateInvulnerableCounter() {
if (invulnerable_) {
if (invulnerable_counter_ > 0) {
invulnerable_counter_--;
} else {
invulnerable_ = false;
invulnerable_counter_ = INVULNERABLE_COUNTER;
}
}
}
// Actualiza el contador d'invulnerabilitat (time-based). Manté el counter
// enter sincronitzat perquè render() segueixi parpellejant igual.
// Actualiza el contador d'invulnerabilitat. Manté el counter enter
// sincronitzat perquè render() segueixi parpellejant igual.
void Player::updateInvulnerableCounter(float dt_s) {
if (invulnerable_) {
if (invulnerable_counter_s_ > 0.0F) {
@@ -518,16 +398,7 @@ void Player::updateInvulnerableCounter(float dt_s) {
}
}
// Actualiza el valor de la variable
void Player::updateDeathCounter() {
if (!alive_) {
if (death_counter_ > 0) {
death_counter_--;
}
}
}
// Actualiza el comptador de mort (time-based)
// Actualiza el comptador de mort
void Player::updateDeathCounter(float dt_s) {
if (!alive_) {
if (death_counter_s_ > 0.0F) {
@@ -558,17 +429,7 @@ void Player::setPowerUpCounter(Uint16 value) {
power_up_counter_s_ = static_cast<float>(value) / 60.0F;
}
// Actualiza el valor de la variable
void Player::updatePowerUpCounter() {
if ((power_up_counter_ > 0) && (power_up_)) {
power_up_counter_--;
} else {
power_up_ = false;
power_up_counter_ = POWERUP_COUNTER;
}
}
// Actualiza el comptador de PowerUp (time-based)
// Actualiza el comptador de PowerUp
void Player::updatePowerUpCounter(float dt_s) {
if ((power_up_counter_s_ > 0.0F) && (power_up_)) {
power_up_counter_s_ = std::max(0.0F, power_up_counter_s_ - dt_s);
@@ -642,26 +503,8 @@ auto Player::getDeathCounter() const -> Uint16 {
return death_counter_;
}
// Actualiza el valor de la variable
void Player::updatePowerUpHeadOffset() {
if (!power_up_) {
// powerUpHeadOffset = 0;
} else {
// powerUpHeadOffset = 96;
if (power_up_counter_ < 300) {
if (power_up_counter_ % 10 > 4) {
// powerUpHeadOffset = 96;
fire_sprite_->setEnabled(false);
} else {
// powerUpHeadOffset = 0;
fire_sprite_->setEnabled(true);
}
}
}
}
// Actualiza l'offset (time-based). dt_s no s'usa directament: el blink final
// depèn de power_up_counter_s_ que ja s'està actualitzant a updatePowerUpCounter.
// Actualiza l'offset. dt_s no s'usa directament: el blink final depèn de
// power_up_counter_s_ que ja s'està actualitzant a updatePowerUpCounter.
void Player::updatePowerUpHeadOffset([[maybe_unused]] float dt_s) {
if (!power_up_) { return; }
if (power_up_counter_s_ < POWERUP_BLINK_THRESHOLD_S) {
+12 -24
View File
@@ -22,16 +22,13 @@ class Player {
auto operator=(const Player &) -> Player & = delete;
void init(); // Iniciador
void update(); // Actualiza al jugador (frame-based)
void update(float dt_s); // Actualiza al jugador (time-based)
void update(float dt_s); // Actualiza al jugador
void render(); // Pinta el jugador en pantalla
void move(); // Mueve el jugador (frame-based)
void move(float dt_s); // Mueve el jugador (time-based)
void move(float dt_s); // Mueve el jugador
void setPlayerTextures(const std::vector<Texture *> &texture); // Pone las texturas del jugador
void setInput(Input::Action input); // Actua en consecuencia de la entrada recibida
void setAnimation(); // Establece la animación correspondiente al estado (frame-based)
void setAnimation(float dt_s); // Establece la animación correspondiente al estado (time-based)
void setAnimation(float dt_s); // 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
@@ -41,8 +38,7 @@ class Player {
[[nodiscard]] auto canFire() const -> bool; // Indica si el jugador puede disparar
void setFireCooldown(int time); // Establece el valor de la variable (frames)
void setFireCooldownS(float seconds); // Establece el valor de la variable (segons)
void updateCooldown(); // Actualiza el valor de la variable (frame-based)
void updateCooldown(float dt_s); // Actualiza el valor de la variable (time-based)
void updateCooldown(float dt_s); // 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
@@ -65,8 +61,7 @@ class Player {
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 (frame-based)
void updatePowerUpCounter(float dt_s); // Actualiza el valor de la variable (time-based)
void updatePowerUpCounter(float dt_s); // 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
@@ -124,15 +119,11 @@ class Player {
Uint8 width_; // Anchura
Uint8 height_; // Altura
float vel_x_; // Cantidad de pixeles a desplazarse en el eje X (frame-based: px/frame)
int vel_y_; // Cantidad de pixeles a desplazarse en el eje Y
float vel_x_s_{0.0F}; // Velocidad en el eje X (px/s)
float vel_x_s_{0.0F}; // Velocidad en el eje X (time-based: px/s)
float base_speed_; // Velocidad base del jugador (frame-based: px/frame)
float base_speed_s_{0.0F}; // Velocidad base del jugador (time-based: px/s)
int cooldown_; // Contador durante el cual no puede disparar (frames)
float cooldown_s_{0.0F}; // Contador durante el cual no puede disparar (segons)
float base_speed_s_{0.0F}; // Velocidad base del jugador (px/s)
int cooldown_; // Contador durante el cual no puede disparar (frames, derivat de cooldown_s_)
float cooldown_s_{0.0F}; // Contador durante el cual no puede disparar (font de veritat, segons)
Uint32 score_; // Puntos del jugador
float score_multiplier_; // Multiplicador de puntos
@@ -158,10 +149,7 @@ class Player {
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 (frame-based)
void updateInvulnerableCounter(float dt_s); // Actualiza el valor de la variable (time-based)
void updateDeathCounter(); // Actualiza el valor de la variable (frame-based)
void updateDeathCounter(float dt_s); // Actualiza el valor de la variable (time-based)
void updatePowerUpHeadOffset(); // Actualiza el valor de la variable (frame-based)
void updatePowerUpHeadOffset(float dt_s); // Actualiza el valor de la variable (time-based)
void updateInvulnerableCounter(float dt_s); // Actualiza el valor de la variable
void updateDeathCounter(float dt_s); // Actualiza el valor de la variable
void updatePowerUpHeadOffset(float dt_s); // Actualiza el valor de la variable
};
+2 -2
View File
@@ -1676,7 +1676,7 @@ void Game::popBalloon(Balloon *balloon) {
const int INDEX = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, Balloon::VELX_NEGATIVE, enemy_speed_, 0);
balloons_[INDEX]->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons_[INDEX]->getClass() == Balloon::BALLOON_CLASS) {
balloons_[INDEX]->setVelY(-2.50F);
balloons_[INDEX]->setVelY(-150.0F); // -2.5 px/frame ⇒ -150 px/s
} else {
balloons_[INDEX]->setVelY(Balloon::VELX_NEGATIVE);
}
@@ -1684,7 +1684,7 @@ void Game::popBalloon(Balloon *balloon) {
const int INDEX2 = createBalloon(0, balloon->getPosY(), balloon->getKind() - 1, Balloon::VELX_POSITIVE, enemy_speed_, 0);
balloons_[INDEX2]->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
if (balloons_[INDEX2]->getClass() == Balloon::BALLOON_CLASS) {
balloons_[INDEX2]->setVelY(-2.50F);
balloons_[INDEX2]->setVelY(-150.0F);
} else {
balloons_[INDEX2]->setVelY(Balloon::VELX_NEGATIVE);
}