Compare commits
9 Commits
66566913f6
...
568b941990
| Author | SHA1 | Date | |
|---|---|---|---|
| 568b941990 | |||
| 49a3989ecf | |||
| af7cb01ead | |||
| 5c82916650 | |||
| 0c0518adac | |||
| cb7b290818 | |||
| ae30c9b34f | |||
| 9acd9aa631 | |||
| 577510ff8c |
@@ -10,8 +10,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
|
|||||||
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
||||||
game.play_area.rect.w 320 # Ancho de la zona jugable
|
game.play_area.rect.w 320 # Ancho de la zona jugable
|
||||||
game.play_area.rect.h 200 # Alto de la zona jugable
|
game.play_area.rect.h 200 # Alto de la zona jugable
|
||||||
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||||
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
|
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida
|
||||||
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
||||||
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
|
|||||||
|
|
||||||
# --- TITLE ---
|
# --- TITLE ---
|
||||||
title.press_start_position 180 # Posición Y del texto "Press Start"
|
title.press_start_position 180 # Posición Y del texto "Press Start"
|
||||||
title.title_duration 800 # Duración de la pantalla de título (frames)
|
title.title_duration 14000 # Duración de la pantalla de título (milisegundos)
|
||||||
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
|
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
|
||||||
title.title_c_c_position 80 # Posición Y del título principal
|
title.title_c_c_position 80 # Posición Y del título principal
|
||||||
title.bg_color 41526F # Color de fondo en la sección titulo
|
title.bg_color 41526F # Color de fondo en la sección titulo
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
|
|||||||
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
||||||
game.play_area.rect.w 320 # Ancho de la zona jugable
|
game.play_area.rect.w 320 # Ancho de la zona jugable
|
||||||
game.play_area.rect.h 216 # Alto de la zona jugable
|
game.play_area.rect.h 216 # Alto de la zona jugable
|
||||||
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||||
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
|
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida
|
||||||
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
||||||
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
|
|||||||
|
|
||||||
# --- TITLE ---
|
# --- TITLE ---
|
||||||
title.press_start_position 180 # Posición Y del texto "Press Start"
|
title.press_start_position 180 # Posición Y del texto "Press Start"
|
||||||
title.title_duration 800 # Duración de la pantalla de título (frames)
|
title.title_duration 14000 # Duración de la pantalla de título (milisegundos)
|
||||||
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
|
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
|
||||||
title.title_c_c_position 80 # Posición Y del título principal
|
title.title_c_c_position 80 # Posición Y del título principal
|
||||||
title.bg_color 41526F # Color de fondo en la sección titulo
|
title.bg_color 41526F # Color de fondo en la sección titulo
|
||||||
|
|||||||
@@ -86,36 +86,6 @@ auto AnimatedSprite::getAnimationIndex(const std::string& name) -> int {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación (frame-based)
|
|
||||||
void AnimatedSprite::animate() {
|
|
||||||
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el frame actual a partir del contador
|
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
|
||||||
|
|
||||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
|
||||||
// en función de la variable loop y coloca el nuevo frame
|
|
||||||
if (animations_[current_animation_].current_frame >= animations_[current_animation_].frames.size()) {
|
|
||||||
if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame
|
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
|
||||||
animations_[current_animation_].completed = true;
|
|
||||||
} else { // Si hay loop, vuelve al frame indicado
|
|
||||||
animations_[current_animation_].counter = 0;
|
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// En caso contrario
|
|
||||||
else {
|
|
||||||
// Escoge el frame correspondiente de la animación
|
|
||||||
updateSpriteClip();
|
|
||||||
|
|
||||||
// Incrementa el contador de la animacion
|
|
||||||
animations_[current_animation_].counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación (time-based)
|
// Calcula el frame correspondiente a la animación (time-based)
|
||||||
void AnimatedSprite::animate(float deltaTime) {
|
void AnimatedSprite::animate(float deltaTime) {
|
||||||
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
|
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
|
||||||
@@ -196,12 +166,6 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto (frame-based)
|
|
||||||
void AnimatedSprite::update() {
|
|
||||||
animate();
|
|
||||||
MovingSprite::update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables del objeto (time-based)
|
// Actualiza las variables del objeto (time-based)
|
||||||
void AnimatedSprite::update(float deltaTime) {
|
void AnimatedSprite::update(float deltaTime) {
|
||||||
animate(deltaTime);
|
animate(deltaTime);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class AnimatedSprite : public MovingSprite {
|
|||||||
~AnimatedSprite() override = default;
|
~AnimatedSprite() override = default;
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update() override; // Actualiza la animación (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza la animación (time-based)
|
void update(float deltaTime); // Actualiza la animación (time-based)
|
||||||
|
|
||||||
// --- Control de animaciones ---
|
// --- Control de animaciones ---
|
||||||
@@ -80,7 +79,6 @@ class AnimatedSprite : public MovingSprite {
|
|||||||
int current_animation_ = 0; // Índice de la animación activa
|
int current_animation_ = 0; // Índice de la animación activa
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void animate(); // Calcula el frame correspondiente a la animación (frame-based)
|
|
||||||
void animate(float deltaTime); // Calcula el frame correspondiente a la animación (time-based)
|
void animate(float deltaTime); // Calcula el frame correspondiente a la animación (time-based)
|
||||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source); // Carga la animación desde un vector de cadenas
|
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source); // Carga la animación desde un vector de cadenas
|
||||||
void processConfigLine(const std::string& line, AnimationConfig& config); // Procesa una línea de configuración
|
void processConfigLine(const std::string& line, AnimationConfig& config); // Procesa una línea de configuración
|
||||||
|
|||||||
@@ -125,13 +125,6 @@ void Background::initializeTextures() {
|
|||||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_texture_);
|
SDL_SetTextureAlphaMod(color_texture_, alpha_color_texture_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
|
||||||
// Actualiza la lógica del objeto (compatibilidad)
|
|
||||||
void Background::update() {
|
|
||||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f; // 16.67ms por frame a 60 FPS
|
|
||||||
update(FRAME_TIME_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
// Actualiza la lógica del objeto
|
||||||
void Background::update(float delta_time) {
|
void Background::update(float delta_time) {
|
||||||
// Actualiza la progresión y calcula transiciones
|
// Actualiza la progresión y calcula transiciones
|
||||||
@@ -143,7 +136,7 @@ void Background::update(float delta_time) {
|
|||||||
updateAlphaColorTexture();
|
updateAlphaColorTexture();
|
||||||
|
|
||||||
// Actualiza las nubes
|
// Actualiza las nubes
|
||||||
updateClouds();
|
updateClouds(delta_time);
|
||||||
|
|
||||||
// Calcula el frame de la hierba
|
// Calcula el frame de la hierba
|
||||||
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
|
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
|
||||||
@@ -321,12 +314,12 @@ void Background::updateCloudsSpeed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las nubes
|
// Actualiza las nubes
|
||||||
void Background::updateClouds() {
|
void Background::updateClouds(float deltaTime) {
|
||||||
// Mueve las nubes
|
// Mueve las nubes
|
||||||
top_clouds_sprite_a_->update();
|
top_clouds_sprite_a_->update(deltaTime);
|
||||||
top_clouds_sprite_b_->update();
|
top_clouds_sprite_b_->update(deltaTime);
|
||||||
bottom_clouds_sprite_a_->update();
|
bottom_clouds_sprite_a_->update(deltaTime);
|
||||||
bottom_clouds_sprite_b_->update();
|
bottom_clouds_sprite_b_->update(deltaTime);
|
||||||
|
|
||||||
// Calcula el offset de las nubes
|
// Calcula el offset de las nubes
|
||||||
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
|
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class Background {
|
|||||||
~Background(); // Destructor
|
~Background(); // Destructor
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update(); // Actualiza la lógica del objeto (compatibilidad)
|
|
||||||
void update(float delta_time); // Actualiza la lógica del objeto
|
void update(float delta_time); // Actualiza la lógica del objeto
|
||||||
void render(); // Dibuja el objeto
|
void render(); // Dibuja el objeto
|
||||||
void reset(); // Reinicia la progresión
|
void reset(); // Reinicia la progresión
|
||||||
@@ -130,7 +129,7 @@ class Background {
|
|||||||
void renderBottomClouds(); // Dibuja las nubes inferiores
|
void renderBottomClouds(); // Dibuja las nubes inferiores
|
||||||
void fillCanvas(); // Compone todos los elementos en la textura
|
void fillCanvas(); // Compone todos los elementos en la textura
|
||||||
void updateAlphaColorTexture(); // Actualiza el alpha de la textura de atenuación
|
void updateAlphaColorTexture(); // Actualiza el alpha de la textura de atenuación
|
||||||
void updateClouds(); // Actualiza el movimiento de las nubes
|
void updateClouds(float deltaTime); // Actualiza el movimiento de las nubes (time-based)
|
||||||
void createSunPath(); // Precalcula el recorrido del sol
|
void createSunPath(); // Precalcula el recorrido del sol
|
||||||
void createMoonPath(); // Precalcula el recorrido de la luna
|
void createMoonPath(); // Precalcula el recorrido de la luna
|
||||||
};
|
};
|
||||||
@@ -135,17 +135,6 @@ void Balloon::render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición y estados del globo (frame-based)
|
|
||||||
void Balloon::move() {
|
|
||||||
if (isStopped()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleHorizontalMovement();
|
|
||||||
handleVerticalMovement();
|
|
||||||
applyGravity();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posición y estados del globo (time-based)
|
// Actualiza la posición y estados del globo (time-based)
|
||||||
void Balloon::move(float deltaTime) {
|
void Balloon::move(float deltaTime) {
|
||||||
if (isStopped()) {
|
if (isStopped()) {
|
||||||
@@ -157,18 +146,6 @@ void Balloon::move(float deltaTime) {
|
|||||||
applyGravity(deltaTime);
|
applyGravity(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Balloon::handleHorizontalMovement() {
|
|
||||||
x_ += vx_ * speed_;
|
|
||||||
|
|
||||||
const int CLIP = 2;
|
|
||||||
const float MIN_X = play_area_.x - CLIP;
|
|
||||||
const float MAX_X = play_area_.x + play_area_.w - w_ + CLIP;
|
|
||||||
|
|
||||||
if (isOutOfHorizontalBounds(MIN_X, MAX_X)) {
|
|
||||||
handleHorizontalBounce(MIN_X, MAX_X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Balloon::handleHorizontalMovement(float deltaTime) {
|
void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||||
@@ -183,16 +160,6 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Balloon::handleVerticalMovement() {
|
|
||||||
y_ += vy_ * speed_;
|
|
||||||
|
|
||||||
if (shouldCheckTopCollision()) {
|
|
||||||
handleTopCollision();
|
|
||||||
}
|
|
||||||
|
|
||||||
handleBottomCollision();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Balloon::handleVerticalMovement(float deltaTime) {
|
void Balloon::handleVerticalMovement(float deltaTime) {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||||
@@ -251,22 +218,6 @@ void Balloon::handleBottomCollision() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Balloon::applyGravity() {
|
|
||||||
/*
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
|
|
||||||
travel_y_ += speed_;
|
|
||||||
|
|
||||||
if (travel_y_ >= 1.0F) {
|
|
||||||
travel_y_ -= 1.0F;
|
|
||||||
vy_ += gravity_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Balloon::applyGravity(float deltaTime) {
|
void Balloon::applyGravity(float deltaTime) {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||||
@@ -291,17 +242,6 @@ void Balloon::playPoppingSound() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza al globo a su posicion, animación y controla los contadores (frame-based)
|
|
||||||
void Balloon::update() {
|
|
||||||
move();
|
|
||||||
updateState();
|
|
||||||
updateBounceEffect();
|
|
||||||
shiftSprite();
|
|
||||||
shiftColliders();
|
|
||||||
sprite_->update();
|
|
||||||
++counter_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza al globo a su posicion, animación y controla los contadores (time-based)
|
// Actualiza al globo a su posicion, animación y controla los contadores (time-based)
|
||||||
void Balloon::update(float deltaTime) {
|
void Balloon::update(float deltaTime) {
|
||||||
move(deltaTime);
|
move(deltaTime);
|
||||||
@@ -315,43 +255,6 @@ void Balloon::update(float deltaTime) {
|
|||||||
counter_ += frameFactor;
|
counter_ += frameFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los estados del globo (frame-based)
|
|
||||||
void Balloon::updateState() {
|
|
||||||
// Si se está creando
|
|
||||||
if (isBeingCreated()) {
|
|
||||||
// Actualiza el valor de las variables
|
|
||||||
stop();
|
|
||||||
setInvulnerable(true);
|
|
||||||
|
|
||||||
if (creation_counter_ > 0) {
|
|
||||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
|
||||||
if (static_cast<int>(creation_counter_) % 10 == 0) {
|
|
||||||
y_++;
|
|
||||||
x_ += vx_;
|
|
||||||
|
|
||||||
// Comprueba no se salga por los laterales
|
|
||||||
const int MIN_X = play_area_.x;
|
|
||||||
const int MAX_X = play_area_.w - w_;
|
|
||||||
|
|
||||||
if (x_ < MIN_X || x_ > MAX_X) {
|
|
||||||
// Corrige y cambia el sentido de la velocidad
|
|
||||||
x_ -= vx_;
|
|
||||||
vx_ = -vx_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
--creation_counter_;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
// El contador ha llegado a cero
|
|
||||||
being_created_ = false;
|
|
||||||
start();
|
|
||||||
setInvulnerable(false);
|
|
||||||
setAnimation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza los estados del globo (time-based)
|
// Actualiza los estados del globo (time-based)
|
||||||
void Balloon::updateState(float deltaTime) {
|
void Balloon::updateState(float deltaTime) {
|
||||||
// Si se está creando
|
// Si se está creando
|
||||||
|
|||||||
@@ -89,9 +89,7 @@ class Balloon {
|
|||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void alignTo(int x); // Centra el globo en la posición X
|
void alignTo(int x); // Centra el globo en la posición X
|
||||||
void render(); // Pinta el globo en la pantalla
|
void render(); // Pinta el globo en la pantalla
|
||||||
void move(); // Actualiza la posición y estados del globo (frame-based)
|
|
||||||
void move(float deltaTime); // Actualiza la posición y estados del globo (time-based)
|
void move(float deltaTime); // Actualiza la posición y estados del globo (time-based)
|
||||||
void update(); // Actualiza el globo (posición, animación, contadores) (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza el globo (posición, animación, contadores) (time-based)
|
void update(float deltaTime); // Actualiza el globo (posición, animación, contadores) (time-based)
|
||||||
void stop(); // Detiene el globo
|
void stop(); // Detiene el globo
|
||||||
void start(); // Pone el globo en movimiento
|
void start(); // Pone el globo en movimiento
|
||||||
@@ -283,11 +281,8 @@ class Balloon {
|
|||||||
void playPoppingSound(); // Reproduce el sonido de reventar
|
void playPoppingSound(); // Reproduce el sonido de reventar
|
||||||
|
|
||||||
// --- Movimiento y física ---
|
// --- Movimiento y física ---
|
||||||
void handleHorizontalMovement(); // Maneja el movimiento horizontal (frame-based)
|
|
||||||
void handleHorizontalMovement(float deltaTime); // Maneja el movimiento horizontal (time-based)
|
void handleHorizontalMovement(float deltaTime); // Maneja el movimiento horizontal (time-based)
|
||||||
void handleVerticalMovement(); // Maneja el movimiento vertical (frame-based)
|
|
||||||
void handleVerticalMovement(float deltaTime); // Maneja el movimiento vertical (time-based)
|
void handleVerticalMovement(float deltaTime); // Maneja el movimiento vertical (time-based)
|
||||||
void applyGravity(); // Aplica la gravedad al objeto (frame-based)
|
|
||||||
void applyGravity(float deltaTime); // Aplica la gravedad al objeto (time-based)
|
void applyGravity(float deltaTime); // Aplica la gravedad al objeto (time-based)
|
||||||
|
|
||||||
// --- Rebote ---
|
// --- Rebote ---
|
||||||
@@ -303,6 +298,5 @@ class Balloon {
|
|||||||
void handleBottomCollision(); // Maneja la colisión inferior
|
void handleBottomCollision(); // Maneja la colisión inferior
|
||||||
|
|
||||||
// --- Lógica de estado ---
|
// --- Lógica de estado ---
|
||||||
void updateState(); // Actualiza los estados del globo (frame-based)
|
|
||||||
void updateState(float deltaTime); // Actualiza los estados del globo (time-based)
|
void updateState(float deltaTime); // Actualiza los estados del globo (time-based)
|
||||||
};
|
};
|
||||||
@@ -62,15 +62,6 @@ void BalloonManager::init() {
|
|||||||
explosions_->addTexture(3, explosions_textures_.at(3), explosions_animations_.at(3));
|
explosions_->addTexture(3, explosions_textures_.at(3), explosions_animations_.at(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza (frame-based)
|
|
||||||
void BalloonManager::update() {
|
|
||||||
for (const auto &balloon : balloons_) {
|
|
||||||
balloon->update();
|
|
||||||
}
|
|
||||||
updateBalloonDeployCounter();
|
|
||||||
explosions_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza (time-based)
|
// Actualiza (time-based)
|
||||||
void BalloonManager::update(float deltaTime) {
|
void BalloonManager::update(float deltaTime) {
|
||||||
for (const auto &balloon : balloons_) {
|
for (const auto &balloon : balloons_) {
|
||||||
@@ -171,13 +162,6 @@ void BalloonManager::freeBalloons() {
|
|||||||
balloons_.erase(result.begin(), balloons_.end());
|
balloons_.erase(result.begin(), balloons_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la variable enemyDeployCounter (frame-based)
|
|
||||||
void BalloonManager::updateBalloonDeployCounter() {
|
|
||||||
if (balloon_deploy_counter_ > 0) {
|
|
||||||
--balloon_deploy_counter_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la variable enemyDeployCounter (time-based)
|
// Actualiza la variable enemyDeployCounter (time-based)
|
||||||
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
|
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
|
||||||
if (balloon_deploy_counter_ > 0) {
|
if (balloon_deploy_counter_ > 0) {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class BalloonManager {
|
|||||||
~BalloonManager() = default;
|
~BalloonManager() = default;
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update(); // Actualiza el estado de los globos (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
|
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
|
||||||
void render(); // Renderiza los globos en pantalla
|
void render(); // Renderiza los globos en pantalla
|
||||||
|
|
||||||
@@ -50,7 +49,6 @@ class BalloonManager {
|
|||||||
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
|
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
|
||||||
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base
|
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base
|
||||||
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos
|
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos
|
||||||
void updateBalloonDeployCounter(); // Actualiza el contador de despliegue (frame-based)
|
|
||||||
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
|
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
|
||||||
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
|
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
|
||||||
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
|
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
|
||||||
|
|||||||
@@ -60,38 +60,12 @@ void Bullet::render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado del objeto (frame-based)
|
|
||||||
auto Bullet::update() -> BulletMoveStatus {
|
|
||||||
sprite_->update();
|
|
||||||
return move();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado del objeto (time-based)
|
// Actualiza el estado del objeto (time-based)
|
||||||
auto Bullet::update(float deltaTime) -> BulletMoveStatus {
|
auto Bullet::update(float deltaTime) -> BulletMoveStatus {
|
||||||
sprite_->update(deltaTime);
|
sprite_->update(deltaTime);
|
||||||
return move(deltaTime);
|
return move(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementación del movimiento usando BulletMoveStatus (frame-based)
|
|
||||||
auto Bullet::move() -> BulletMoveStatus {
|
|
||||||
pos_x_ += vel_x_;
|
|
||||||
if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) {
|
|
||||||
disable();
|
|
||||||
return BulletMoveStatus::OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos_y_ += VEL_Y;
|
|
||||||
if (pos_y_ < param.game.play_area.rect.y - HEIGHT) {
|
|
||||||
disable();
|
|
||||||
return BulletMoveStatus::OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
shiftSprite();
|
|
||||||
shiftColliders();
|
|
||||||
|
|
||||||
return BulletMoveStatus::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementación del movimiento usando BulletMoveStatus (time-based)
|
// Implementación del movimiento usando BulletMoveStatus (time-based)
|
||||||
auto Bullet::move(float deltaTime) -> BulletMoveStatus {
|
auto Bullet::move(float deltaTime) -> BulletMoveStatus {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class Bullet {
|
|||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void render(); // Dibuja la bala en pantalla
|
void render(); // Dibuja la bala en pantalla
|
||||||
auto update() -> BulletMoveStatus; // Actualiza el estado del objeto (frame-based)
|
|
||||||
auto update(float deltaTime) -> BulletMoveStatus; // Actualiza el estado del objeto (time-based)
|
auto update(float deltaTime) -> BulletMoveStatus; // Actualiza el estado del objeto (time-based)
|
||||||
void disable(); // Desactiva la bala
|
void disable(); // Desactiva la bala
|
||||||
|
|
||||||
@@ -65,7 +64,6 @@ class Bullet {
|
|||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void shiftColliders(); // Ajusta el círculo de colisión
|
void shiftColliders(); // Ajusta el círculo de colisión
|
||||||
void shiftSprite(); // Ajusta el sprite
|
void shiftSprite(); // Ajusta el sprite
|
||||||
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado (frame-based)
|
|
||||||
auto move(float deltaTime) -> BulletMoveStatus; // Mueve la bala y devuelve su estado (time-based)
|
auto move(float deltaTime) -> BulletMoveStatus; // Mueve la bala y devuelve su estado (time-based)
|
||||||
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala
|
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala
|
||||||
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación
|
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace Game {
|
|||||||
constexpr float WIDTH = 320.0F;
|
constexpr float WIDTH = 320.0F;
|
||||||
constexpr float HEIGHT = 256.0F;
|
constexpr float HEIGHT = 256.0F;
|
||||||
constexpr float ITEM_SIZE = 20.0F;
|
constexpr float ITEM_SIZE = 20.0F;
|
||||||
constexpr int NAME_ENTRY_IDLE_TIME = 10;
|
constexpr int NAME_ENTRY_IDLE_TIME = 10000; // 10 segundos en milisegundos
|
||||||
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
|
constexpr int NAME_ENTRY_TOTAL_TIME = 60000; // 60 segundos en milisegundos
|
||||||
constexpr bool HIT_STOP = false;
|
constexpr bool HIT_STOP = false;
|
||||||
constexpr int HIT_STOP_MS = 500;
|
constexpr int HIT_STOP_MS = 500;
|
||||||
constexpr const char* ITEM_TEXT_OUTLINE_COLOR = "FFFFFF00"; // 255, 255, 255, 0
|
constexpr const char* ITEM_TEXT_OUTLINE_COLOR = "FFFFFF00"; // 255, 255, 255, 0
|
||||||
@@ -58,7 +58,7 @@ constexpr int SKIP_COUNTDOWN_VALUE = 8;
|
|||||||
// --- TITLE ---
|
// --- TITLE ---
|
||||||
namespace Title {
|
namespace Title {
|
||||||
constexpr int PRESS_START_POSITION = 180;
|
constexpr int PRESS_START_POSITION = 180;
|
||||||
constexpr int DURATION = 800;
|
constexpr float DURATION = 14000;
|
||||||
constexpr int ARCADE_EDITION_POSITION = 123;
|
constexpr int ARCADE_EDITION_POSITION = 123;
|
||||||
constexpr int TITLE_C_C_POSITION = 80;
|
constexpr int TITLE_C_C_POSITION = 80;
|
||||||
constexpr const char* BG_COLOR = "41526F";
|
constexpr const char* BG_COLOR = "41526F";
|
||||||
|
|||||||
@@ -6,16 +6,6 @@
|
|||||||
|
|
||||||
class Texture; // lines 4-4
|
class Texture; // lines 4-4
|
||||||
|
|
||||||
// Actualiza la lógica de la clase (frame-based)
|
|
||||||
void Explosions::update() {
|
|
||||||
for (auto &explosion : explosions_) {
|
|
||||||
explosion->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vacia el vector de elementos finalizados
|
|
||||||
freeExplosions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la lógica de la clase (time-based)
|
// Actualiza la lógica de la clase (time-based)
|
||||||
void Explosions::update(float deltaTime) {
|
void Explosions::update(float deltaTime) {
|
||||||
for (auto &explosion : explosions_) {
|
for (auto &explosion : explosions_) {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class Explosions {
|
|||||||
~Explosions() = default; // Destructor por defecto
|
~Explosions() = default; // Destructor por defecto
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update(); // Actualiza la lógica de la clase (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
||||||
void render(); // Dibuja el objeto en pantalla
|
void render(); // Dibuja el objeto en pantalla
|
||||||
|
|
||||||
|
|||||||
@@ -113,13 +113,6 @@ void GameLogo::render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica de la clase (frame-based)
|
|
||||||
void GameLogo::update() {
|
|
||||||
updateCoffeeCrisis();
|
|
||||||
updateArcadeEdition();
|
|
||||||
updatePostFinishedCounter();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la lógica de la clase (time-based)
|
// Actualiza la lógica de la clase (time-based)
|
||||||
void GameLogo::update(float deltaTime) {
|
void GameLogo::update(float deltaTime) {
|
||||||
updateCoffeeCrisis(deltaTime);
|
updateCoffeeCrisis(deltaTime);
|
||||||
@@ -127,22 +120,6 @@ void GameLogo::update(float deltaTime) {
|
|||||||
updatePostFinishedCounter(deltaTime);
|
updatePostFinishedCounter(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::updateCoffeeCrisis() {
|
|
||||||
switch (coffee_crisis_status_) {
|
|
||||||
case Status::MOVING:
|
|
||||||
handleCoffeeCrisisMoving();
|
|
||||||
break;
|
|
||||||
case Status::SHAKING:
|
|
||||||
handleCoffeeCrisisShaking();
|
|
||||||
break;
|
|
||||||
case Status::FINISHED:
|
|
||||||
handleCoffeeCrisisFinished();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
||||||
switch (coffee_crisis_status_) {
|
switch (coffee_crisis_status_) {
|
||||||
case Status::MOVING:
|
case Status::MOVING:
|
||||||
@@ -159,19 +136,6 @@ void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::updateArcadeEdition() {
|
|
||||||
switch (arcade_edition_status_) {
|
|
||||||
case Status::MOVING:
|
|
||||||
handleArcadeEditionMoving();
|
|
||||||
break;
|
|
||||||
case Status::SHAKING:
|
|
||||||
handleArcadeEditionShaking();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::updateArcadeEdition(float deltaTime) {
|
void GameLogo::updateArcadeEdition(float deltaTime) {
|
||||||
switch (arcade_edition_status_) {
|
switch (arcade_edition_status_) {
|
||||||
case Status::MOVING:
|
case Status::MOVING:
|
||||||
@@ -185,16 +149,6 @@ void GameLogo::updateArcadeEdition(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisMoving() {
|
|
||||||
coffee_sprite_->update();
|
|
||||||
crisis_sprite_->update();
|
|
||||||
|
|
||||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) {
|
|
||||||
coffee_crisis_status_ = Status::SHAKING;
|
|
||||||
playTitleEffects();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
||||||
coffee_sprite_->update(deltaTime);
|
coffee_sprite_->update(deltaTime);
|
||||||
crisis_sprite_->update(deltaTime);
|
crisis_sprite_->update(deltaTime);
|
||||||
@@ -205,16 +159,6 @@ void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisShaking() {
|
|
||||||
if (shake_.remaining > 0) {
|
|
||||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get());
|
|
||||||
} else {
|
|
||||||
finishCoffeeCrisisShaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDustSprites();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
||||||
if (shake_.remaining > 0) {
|
if (shake_.remaining > 0) {
|
||||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime);
|
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime);
|
||||||
@@ -225,23 +169,10 @@ void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
|||||||
updateDustSprites(deltaTime);
|
updateDustSprites(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisFinished() {
|
|
||||||
updateDustSprites();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
|
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
|
||||||
updateDustSprites(deltaTime);
|
updateDustSprites(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::handleArcadeEditionMoving() {
|
|
||||||
zoom_ -= 0.1F * ZOOM_FACTOR;
|
|
||||||
arcade_edition_sprite_->setZoom(zoom_);
|
|
||||||
|
|
||||||
if (zoom_ <= 1.0F) {
|
|
||||||
finishArcadeEditionMoving();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
||||||
// Convertir 0.1F * ZOOM_FACTOR por frame a por milisegundo (asumiendo 60fps)
|
// Convertir 0.1F * ZOOM_FACTOR por frame a por milisegundo (asumiendo 60fps)
|
||||||
zoom_ -= (0.1F * ZOOM_FACTOR) * deltaTime / (1000.0F / 60.0F);
|
zoom_ -= (0.1F * ZOOM_FACTOR) * deltaTime / (1000.0F / 60.0F);
|
||||||
@@ -252,15 +183,6 @@ void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::handleArcadeEditionShaking() {
|
|
||||||
if (shake_.remaining > 0) {
|
|
||||||
processArcadeEditionShake();
|
|
||||||
} else {
|
|
||||||
arcade_edition_sprite_->setX(shake_.origin);
|
|
||||||
arcade_edition_status_ = Status::FINISHED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::handleArcadeEditionShaking(float deltaTime) {
|
void GameLogo::handleArcadeEditionShaking(float deltaTime) {
|
||||||
if (shake_.remaining > 0) {
|
if (shake_.remaining > 0) {
|
||||||
processArcadeEditionShake(deltaTime);
|
processArcadeEditionShake(deltaTime);
|
||||||
@@ -301,17 +223,6 @@ void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* seco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::processArcadeEditionShake() {
|
|
||||||
if (shake_.counter > 0) {
|
|
||||||
shake_.counter--;
|
|
||||||
} else {
|
|
||||||
shake_.counter = shake_.delay;
|
|
||||||
const auto DISPLACEMENT = calculateShakeDisplacement();
|
|
||||||
arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT);
|
|
||||||
shake_.remaining--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::processArcadeEditionShake(float deltaTime) {
|
void GameLogo::processArcadeEditionShake(float deltaTime) {
|
||||||
// Convertir delay (frames) a tiempo: delay frames = delay * (1000ms/60fps)
|
// Convertir delay (frames) a tiempo: delay frames = delay * (1000ms/60fps)
|
||||||
float delayTime = static_cast<float>(shake_.delay) * (1000.0f / 60.0f);
|
float delayTime = static_cast<float>(shake_.delay) * (1000.0f / 60.0f);
|
||||||
@@ -351,24 +262,11 @@ void GameLogo::playTitleEffects() {
|
|||||||
Screen::get()->shake();
|
Screen::get()->shake();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::updateDustSprites() {
|
|
||||||
dust_right_sprite_->update();
|
|
||||||
dust_left_sprite_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::updateDustSprites(float deltaTime) {
|
void GameLogo::updateDustSprites(float deltaTime) {
|
||||||
dust_right_sprite_->update(deltaTime);
|
dust_right_sprite_->update(deltaTime);
|
||||||
dust_left_sprite_->update(deltaTime);
|
dust_left_sprite_->update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLogo::updatePostFinishedCounter() {
|
|
||||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
|
||||||
arcade_edition_status_ == Status::FINISHED &&
|
|
||||||
post_finished_counter_ > 0) {
|
|
||||||
--post_finished_counter_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameLogo::updatePostFinishedCounter(float deltaTime) {
|
void GameLogo::updatePostFinishedCounter(float deltaTime) {
|
||||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||||
arcade_edition_status_ == Status::FINISHED &&
|
arcade_edition_status_ == Status::FINISHED &&
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class GameLogo {
|
|||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void render(); // Pinta la clase en pantalla
|
void render(); // Pinta la clase en pantalla
|
||||||
void update(); // Actualiza la lógica de la clase (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
|
||||||
void enable(); // Activa la clase
|
void enable(); // Activa la clase
|
||||||
|
|
||||||
@@ -90,36 +89,26 @@ class GameLogo {
|
|||||||
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
|
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
|
||||||
|
|
||||||
// --- Actualización de estados específicos ---
|
// --- Actualización de estados específicos ---
|
||||||
void updateCoffeeCrisis(); // Actualiza el estado de "Coffee Crisis" (frame-based)
|
|
||||||
void updateCoffeeCrisis(float deltaTime); // Actualiza el estado de "Coffee Crisis" (time-based)
|
void updateCoffeeCrisis(float deltaTime); // Actualiza el estado de "Coffee Crisis" (time-based)
|
||||||
void updateArcadeEdition(); // Actualiza el estado de "Arcade Edition" (frame-based)
|
|
||||||
void updateArcadeEdition(float deltaTime); // Actualiza el estado de "Arcade Edition" (time-based)
|
void updateArcadeEdition(float deltaTime); // Actualiza el estado de "Arcade Edition" (time-based)
|
||||||
void updatePostFinishedCounter(); // Actualiza el contador tras finalizar una animación (frame-based)
|
|
||||||
void updatePostFinishedCounter(float deltaTime); // Actualiza el contador tras finalizar una animación (time-based)
|
void updatePostFinishedCounter(float deltaTime); // Actualiza el contador tras finalizar una animación (time-based)
|
||||||
|
|
||||||
// --- Efectos visuales: movimiento y sacudidas ---
|
// --- Efectos visuales: movimiento y sacudidas ---
|
||||||
void handleCoffeeCrisisMoving(); // Maneja el movimiento de "Coffee Crisis" (frame-based)
|
|
||||||
void handleCoffeeCrisisMoving(float deltaTime); // Maneja el movimiento de "Coffee Crisis" (time-based)
|
void handleCoffeeCrisisMoving(float deltaTime); // Maneja el movimiento de "Coffee Crisis" (time-based)
|
||||||
void handleCoffeeCrisisShaking(); // Maneja la sacudida de "Coffee Crisis" (frame-based)
|
|
||||||
void handleCoffeeCrisisShaking(float deltaTime); // Maneja la sacudida de "Coffee Crisis" (time-based)
|
void handleCoffeeCrisisShaking(float deltaTime); // Maneja la sacudida de "Coffee Crisis" (time-based)
|
||||||
void handleArcadeEditionMoving(); // Maneja el movimiento de "Arcade Edition" (frame-based)
|
|
||||||
void handleArcadeEditionMoving(float deltaTime); // Maneja el movimiento de "Arcade Edition" (time-based)
|
void handleArcadeEditionMoving(float deltaTime); // Maneja el movimiento de "Arcade Edition" (time-based)
|
||||||
void handleArcadeEditionShaking(); // Maneja la sacudida de "Arcade Edition" (frame-based)
|
|
||||||
void handleArcadeEditionShaking(float deltaTime); // Maneja la sacudida de "Arcade Edition" (time-based)
|
void handleArcadeEditionShaking(float deltaTime); // Maneja la sacudida de "Arcade Edition" (time-based)
|
||||||
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites (frame-based)
|
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites (frame-based)
|
||||||
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime); // Procesa el efecto de sacudida en sprites (time-based)
|
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime); // Procesa el efecto de sacudida en sprites (time-based)
|
||||||
void processArcadeEditionShake(); // Procesa la sacudida específica de "Arcade Edition" (frame-based)
|
|
||||||
void processArcadeEditionShake(float deltaTime); // Procesa la sacudida específica de "Arcade Edition" (time-based)
|
void processArcadeEditionShake(float deltaTime); // Procesa la sacudida específica de "Arcade Edition" (time-based)
|
||||||
[[nodiscard]] auto calculateShakeDisplacement() const -> int; // Calcula el desplazamiento de la sacudida
|
[[nodiscard]] auto calculateShakeDisplacement() const -> int; // Calcula el desplazamiento de la sacudida
|
||||||
|
|
||||||
// --- Gestión de finalización de efectos ---
|
// --- Gestión de finalización de efectos ---
|
||||||
void handleCoffeeCrisisFinished(); // Maneja el final de la animación "Coffee Crisis" (frame-based)
|
|
||||||
void handleCoffeeCrisisFinished(float deltaTime); // Maneja el final de la animación "Coffee Crisis" (time-based)
|
void handleCoffeeCrisisFinished(float deltaTime); // Maneja el final de la animación "Coffee Crisis" (time-based)
|
||||||
void finishCoffeeCrisisShaking(); // Finaliza la sacudida de "Coffee Crisis"
|
void finishCoffeeCrisisShaking(); // Finaliza la sacudida de "Coffee Crisis"
|
||||||
void finishArcadeEditionMoving(); // Finaliza el movimiento de "Arcade Edition"
|
void finishArcadeEditionMoving(); // Finaliza el movimiento de "Arcade Edition"
|
||||||
|
|
||||||
// --- Utilidades ---
|
// --- Utilidades ---
|
||||||
static void playTitleEffects(); // Reproduce efectos visuales/sonoros del título
|
static void playTitleEffects(); // Reproduce efectos visuales/sonoros del título
|
||||||
void updateDustSprites(); // Actualiza los sprites de polvo (frame-based)
|
|
||||||
void updateDustSprites(float deltaTime); // Actualiza los sprites de polvo (time-based)
|
void updateDustSprites(float deltaTime); // Actualiza los sprites de polvo (time-based)
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
#include <algorithm> // Para clamp
|
#include <algorithm> // Para clamp
|
||||||
|
#include <cmath> // Para fmod
|
||||||
#include <cstdlib> // Para rand
|
#include <cstdlib> // Para rand
|
||||||
|
|
||||||
#include "animated_sprite.h" // Para AnimatedSprite
|
#include "animated_sprite.h" // Para AnimatedSprite
|
||||||
@@ -66,24 +67,36 @@ void Item::alignTo(int x) {
|
|||||||
|
|
||||||
void Item::render() {
|
void Item::render() {
|
||||||
if (enabled_) {
|
if (enabled_) {
|
||||||
if (time_to_live_ > 200) {
|
// Muestra normalmente hasta los últimos ~3.3 segundos (200 frames)
|
||||||
|
constexpr float BLINK_START_MS = LIFETIME_DURATION_MS - (200.0f * (1000.0f / 60.0f));
|
||||||
|
|
||||||
|
if (lifetime_timer_ < BLINK_START_MS) {
|
||||||
sprite_->render();
|
sprite_->render();
|
||||||
} else if (time_to_live_ % 20 > 10) {
|
} else {
|
||||||
|
// Efecto de parpadeo en los últimos segundos (cada ~333ms o 20 frames)
|
||||||
|
constexpr float BLINK_INTERVAL_MS = 20.0f * (1000.0f / 60.0f);
|
||||||
|
const float phase = fmod(lifetime_timer_, BLINK_INTERVAL_MS);
|
||||||
|
const float half_interval = BLINK_INTERVAL_MS / 2.0f;
|
||||||
|
|
||||||
|
if (phase < half_interval) {
|
||||||
sprite_->render();
|
sprite_->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::move() {
|
void Item::move(float deltaTime) {
|
||||||
|
// Convertir deltaTime a factor de frame para compatibilidad (asumiendo 60fps)
|
||||||
|
const float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||||
floor_collision_ = false;
|
floor_collision_ = false;
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición (time-based)
|
||||||
pos_x_ += vel_x_;
|
pos_x_ += vel_x_ * frameFactor;
|
||||||
pos_y_ += vel_y_;
|
pos_y_ += vel_y_ * frameFactor;
|
||||||
|
|
||||||
// Aplica las aceleraciones a la velocidad
|
// Aplica las aceleraciones a la velocidad (time-based)
|
||||||
vel_x_ += accel_x_;
|
vel_x_ += accel_x_ * frameFactor;
|
||||||
vel_y_ += accel_y_;
|
vel_y_ += accel_y_ * frameFactor;
|
||||||
|
|
||||||
// Comprueba los laterales de la zona de juego
|
// Comprueba los laterales de la zona de juego
|
||||||
const float MIN_X = param.game.play_area.rect.x;
|
const float MIN_X = param.game.play_area.rect.x;
|
||||||
@@ -143,16 +156,15 @@ void Item::move() {
|
|||||||
|
|
||||||
void Item::disable() { enabled_ = false; }
|
void Item::disable() { enabled_ = false; }
|
||||||
|
|
||||||
void Item::update() {
|
void Item::update(float deltaTime) {
|
||||||
move();
|
move(deltaTime);
|
||||||
sprite_->update();
|
sprite_->update(deltaTime);
|
||||||
updateTimeToLive();
|
updateTimeToLive(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::updateTimeToLive() {
|
void Item::updateTimeToLive(float deltaTime) {
|
||||||
if (time_to_live_ > 0) {
|
lifetime_timer_ += deltaTime;
|
||||||
time_to_live_--;
|
if (lifetime_timer_ >= LIFETIME_DURATION_MS) {
|
||||||
} else {
|
|
||||||
disable();
|
disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Item {
|
|||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
static constexpr int COFFEE_MACHINE_WIDTH = 30; // Anchura de la máquina de café
|
static constexpr int COFFEE_MACHINE_WIDTH = 30; // Anchura de la máquina de café
|
||||||
static constexpr int COFFEE_MACHINE_HEIGHT = 39; // Altura de la máquina de café
|
static constexpr int COFFEE_MACHINE_HEIGHT = 39; // Altura de la máquina de café
|
||||||
|
static constexpr float LIFETIME_DURATION_MS = 10000.0f; // Duración de vida del ítem (600 frames a 60fps)
|
||||||
|
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Constructor principal
|
Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Constructor principal
|
||||||
@@ -38,7 +39,7 @@ class Item {
|
|||||||
void alignTo(int x); // Centra el objeto en la posición X indicada
|
void alignTo(int x); // Centra el objeto en la posición X indicada
|
||||||
void render(); // Renderiza el objeto en pantalla
|
void render(); // Renderiza el objeto en pantalla
|
||||||
void disable(); // Desactiva el objeto
|
void disable(); // Desactiva el objeto
|
||||||
void update(); // Actualiza la posición, animación y contadores
|
void update(float deltaTime); // Actualiza la posición, animación y contadores (time-based)
|
||||||
|
|
||||||
// --- Getters ---
|
// --- Getters ---
|
||||||
[[nodiscard]] auto getPosX() const -> float { return pos_x_; } // Obtiene la posición X
|
[[nodiscard]] auto getPosX() const -> float { return pos_x_; } // Obtiene la posición X
|
||||||
@@ -66,14 +67,14 @@ class Item {
|
|||||||
float accel_y_; // Aceleración en el eje Y
|
float accel_y_; // Aceleración en el eje Y
|
||||||
int width_; // Ancho del objeto
|
int width_; // Ancho del objeto
|
||||||
int height_; // Alto del objeto
|
int height_; // Alto del objeto
|
||||||
Uint16 time_to_live_ = 600; // Tiempo que el objeto está presente
|
float lifetime_timer_ = 0.0f; // Acumulador de tiempo de vida del ítem (milisegundos)
|
||||||
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
||||||
bool enabled_ = true; // Indica si el objeto está habilitado
|
bool enabled_ = true; // Indica si el objeto está habilitado
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void shiftColliders(); // Alinea el círculo de colisión con la posición del objeto
|
void shiftColliders(); // Alinea el círculo de colisión con la posición del objeto
|
||||||
void shiftSprite(); // Coloca el sprite en la posición del objeto
|
void shiftSprite(); // Coloca el sprite en la posición del objeto
|
||||||
void move(); // Actualiza la posición y estados del objeto
|
void move(float deltaTime); // Actualiza la posición y estados del objeto (time-based)
|
||||||
void updateTimeToLive(); // Actualiza el contador de tiempo de vida
|
void updateTimeToLive(float deltaTime); // Actualiza el contador de tiempo de vida (time-based)
|
||||||
static auto getCoffeeMachineSpawn(int player_x, int item_width, int area_width, int margin = 2) -> int; // Calcula la zona de aparición de la máquina de café
|
static auto getCoffeeMachineSpawn(int player_x, int item_width, int area_width, int margin = 2) -> int; // Calcula la zona de aparición de la máquina de café
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,18 +53,6 @@ void MovingSprite::stop() {
|
|||||||
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el sprite (frame-based)
|
|
||||||
void MovingSprite::move() {
|
|
||||||
x_ += vx_;
|
|
||||||
y_ += vy_;
|
|
||||||
|
|
||||||
vx_ += ax_;
|
|
||||||
vy_ += ay_;
|
|
||||||
|
|
||||||
pos_.x = static_cast<int>(x_);
|
|
||||||
pos_.y = static_cast<int>(y_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mueve el sprite (time-based)
|
// Mueve el sprite (time-based)
|
||||||
void MovingSprite::move(float deltaTime) {
|
void MovingSprite::move(float deltaTime) {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
@@ -80,12 +68,6 @@ void MovingSprite::move(float deltaTime) {
|
|||||||
pos_.y = static_cast<int>(y_);
|
pos_.y = static_cast<int>(y_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables internas del objeto (frame-based)
|
|
||||||
void MovingSprite::update() {
|
|
||||||
move();
|
|
||||||
rotate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables internas del objeto (time-based)
|
// Actualiza las variables internas del objeto (time-based)
|
||||||
void MovingSprite::update(float deltaTime) {
|
void MovingSprite::update(float deltaTime) {
|
||||||
move(deltaTime);
|
move(deltaTime);
|
||||||
@@ -93,17 +75,8 @@ void MovingSprite::update(float deltaTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void MovingSprite::render() { getTexture()->render(pos_.x, pos_.y, &sprite_clip_, horizontal_zoom_, vertical_zoom_, rotate_.angle, &rotate_.center, flip_); }
|
void MovingSprite::render() {
|
||||||
|
getTexture()->render(pos_.x, pos_.y, &sprite_clip_, horizontal_zoom_, vertical_zoom_, rotate_.angle, &rotate_.center, flip_);
|
||||||
// Establece la rotacion (frame-based)
|
|
||||||
void MovingSprite::rotate() {
|
|
||||||
if (rotate_.enabled) {
|
|
||||||
++rotate_.counter;
|
|
||||||
if (rotate_.counter % rotate_.speed == 0) {
|
|
||||||
updateAngle();
|
|
||||||
rotate_.counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la rotacion (time-based)
|
// Establece la rotacion (time-based)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class MovingSprite : public Sprite {
|
|||||||
~MovingSprite() override = default;
|
~MovingSprite() override = default;
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
virtual void update(); // Actualiza las variables internas del objeto (frame-based)
|
|
||||||
virtual void update(float deltaTime); // Actualiza las variables internas del objeto (time-based)
|
virtual void update(float deltaTime); // Actualiza las variables internas del objeto (time-based)
|
||||||
void clear() override; // Reinicia todas las variables a cero
|
void clear() override; // Reinicia todas las variables a cero
|
||||||
void stop(); // Elimina el movimiento del sprite
|
void stop(); // Elimina el movimiento del sprite
|
||||||
@@ -80,8 +79,6 @@ class MovingSprite : public Sprite {
|
|||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void updateAngle() { rotate_.angle += rotate_.amount; } // Incrementa el valor del ángulo
|
void updateAngle() { rotate_.angle += rotate_.amount; } // Incrementa el valor del ángulo
|
||||||
void move(); // Mueve el sprite según velocidad y aceleración (frame-based)
|
|
||||||
void move(float deltaTime); // Mueve el sprite según velocidad y aceleración (time-based)
|
void move(float deltaTime); // Mueve el sprite según velocidad y aceleración (time-based)
|
||||||
void rotate(); // Rota el sprite según los parámetros de rotación (frame-based)
|
|
||||||
void rotate(float deltaTime); // Rota el sprite según los parámetros de rotación (time-based)
|
void rotate(float deltaTime); // Rota el sprite según los parámetros de rotación (time-based)
|
||||||
};
|
};
|
||||||
@@ -106,7 +106,6 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
|||||||
{"scoreboard.rect.h", [](const std::string& v) { param.scoreboard.rect.h = std::stoi(v); }},
|
{"scoreboard.rect.h", [](const std::string& v) { param.scoreboard.rect.h = std::stoi(v); }},
|
||||||
{"scoreboard.skip_countdown_value", [](const std::string& v) { param.scoreboard.skip_countdown_value = std::stoi(v); }},
|
{"scoreboard.skip_countdown_value", [](const std::string& v) { param.scoreboard.skip_countdown_value = std::stoi(v); }},
|
||||||
{"title.press_start_position", [](const std::string& v) { param.title.press_start_position = std::stoi(v); }},
|
{"title.press_start_position", [](const std::string& v) { param.title.press_start_position = std::stoi(v); }},
|
||||||
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stoi(v); }},
|
|
||||||
{"title.arcade_edition_position", [](const std::string& v) { param.title.arcade_edition_position = std::stoi(v); }},
|
{"title.arcade_edition_position", [](const std::string& v) { param.title.arcade_edition_position = std::stoi(v); }},
|
||||||
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
|
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
|
||||||
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
|
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
|
||||||
@@ -182,6 +181,7 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
|||||||
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }},
|
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }},
|
||||||
{"tabe.min_spawn_time", [](const std::string& v) { param.tabe.min_spawn_time = std::stof(v); }},
|
{"tabe.min_spawn_time", [](const std::string& v) { param.tabe.min_spawn_time = std::stof(v); }},
|
||||||
{"tabe.max_spawn_time", [](const std::string& v) { param.tabe.max_spawn_time = std::stof(v); }},
|
{"tabe.max_spawn_time", [](const std::string& v) { param.tabe.max_spawn_time = std::stof(v); }},
|
||||||
|
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stof(v); }},
|
||||||
{"service_menu.window_message.padding", [](const std::string& v) { param.service_menu.window_message.padding = std::stof(v); }},
|
{"service_menu.window_message.padding", [](const std::string& v) { param.service_menu.window_message.padding = std::stof(v); }},
|
||||||
{"service_menu.window_message.line_spacing", [](const std::string& v) { param.service_menu.window_message.line_spacing = std::stof(v); }},
|
{"service_menu.window_message.line_spacing", [](const std::string& v) { param.service_menu.window_message.line_spacing = std::stof(v); }},
|
||||||
{"service_menu.window_message.title_separator_spacing", [](const std::string& v) { param.service_menu.window_message.title_separator_spacing = std::stof(v); }},
|
{"service_menu.window_message.title_separator_spacing", [](const std::string& v) { param.service_menu.window_message.title_separator_spacing = std::stof(v); }},
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct ParamFade {
|
|||||||
// --- Parámetros de la pantalla de título ---
|
// --- Parámetros de la pantalla de título ---
|
||||||
struct ParamTitle {
|
struct ParamTitle {
|
||||||
int press_start_position = GameDefaults::Title::PRESS_START_POSITION;
|
int press_start_position = GameDefaults::Title::PRESS_START_POSITION;
|
||||||
int title_duration = GameDefaults::Title::DURATION;
|
float title_duration = GameDefaults::Title::DURATION;
|
||||||
int arcade_edition_position = GameDefaults::Title::ARCADE_EDITION_POSITION;
|
int arcade_edition_position = GameDefaults::Title::ARCADE_EDITION_POSITION;
|
||||||
int title_c_c_position = GameDefaults::Title::TITLE_C_C_POSITION;
|
int title_c_c_position = GameDefaults::Title::TITLE_C_C_POSITION;
|
||||||
Color bg_color = Color::fromHex(GameDefaults::Title::BG_COLOR);
|
Color bg_color = Color::fromHex(GameDefaults::Title::BG_COLOR);
|
||||||
|
|||||||
@@ -60,17 +60,14 @@ void Player::init() {
|
|||||||
power_up_counter_ = POWERUP_COUNTER;
|
power_up_counter_ = POWERUP_COUNTER;
|
||||||
extra_hit_ = false;
|
extra_hit_ = false;
|
||||||
coffees_ = 0;
|
coffees_ = 0;
|
||||||
continue_ticks_ = 0;
|
|
||||||
continue_counter_ = 10;
|
continue_counter_ = 10;
|
||||||
name_entry_ticks_ = 0;
|
name_entry_idle_time_accumulator_ = 0.0f;
|
||||||
name_entry_idle_counter_ = 0;
|
name_entry_total_time_accumulator_ = 0.0f;
|
||||||
name_entry_total_counter_ = 0;
|
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
vel_x_ = 0;
|
vel_x_ = 0;
|
||||||
vel_y_ = 0;
|
vel_y_ = 0;
|
||||||
score_ = 0;
|
score_ = 0;
|
||||||
score_multiplier_ = 1.0F;
|
score_multiplier_ = 1.0F;
|
||||||
cant_fire_counter_ = 10;
|
|
||||||
enter_name_->init(last_enter_name_);
|
enter_name_->init(last_enter_name_);
|
||||||
|
|
||||||
// Establece la posición del sprite
|
// Establece la posición del sprite
|
||||||
@@ -149,14 +146,14 @@ void Player::setInputEnteringName(Input::Action action) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
name_entry_idle_counter_ = 0;
|
name_entry_idle_time_accumulator_ = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el jugador a la posición y animación que le corresponde
|
// Fase 1: Sistema de movimiento time-based
|
||||||
void Player::move() {
|
void Player::move(float deltaTime) {
|
||||||
switch (playing_state_) {
|
switch (playing_state_) {
|
||||||
case State::PLAYING:
|
case State::PLAYING:
|
||||||
handlePlayingMovement();
|
handlePlayingMovement(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::ROLLING:
|
case State::ROLLING:
|
||||||
handleRollingMovement();
|
handleRollingMovement();
|
||||||
@@ -174,10 +171,10 @@ void Player::move() {
|
|||||||
handleEnteringScreen();
|
handleEnteringScreen();
|
||||||
break;
|
break;
|
||||||
case State::CREDITS:
|
case State::CREDITS:
|
||||||
handleCreditsMovement();
|
handleCreditsMovement(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::WAITING:
|
case State::WAITING:
|
||||||
handleWaitingMovement();
|
handleWaitingMovement(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::RECOVER:
|
case State::RECOVER:
|
||||||
handleRecoverMovement();
|
handleRecoverMovement();
|
||||||
@@ -187,41 +184,6 @@ void Player::move() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fase 1: Sistema de movimiento time-based
|
|
||||||
void Player::move(float deltaTime) {
|
|
||||||
switch (playing_state_) {
|
|
||||||
case State::PLAYING:
|
|
||||||
handlePlayingMovement(deltaTime);
|
|
||||||
break;
|
|
||||||
case State::ROLLING:
|
|
||||||
handleRollingMovement(); // Usa MovingSprite que ya soporta deltaTime
|
|
||||||
break;
|
|
||||||
case State::TITLE_ANIMATION:
|
|
||||||
handleTitleAnimation(); // Sin cambios - usa solo animaciones
|
|
||||||
break;
|
|
||||||
case State::CONTINUE_TIME_OUT:
|
|
||||||
handleContinueTimeOut(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
|
||||||
break;
|
|
||||||
case State::LEAVING_SCREEN:
|
|
||||||
handleLeavingScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
|
||||||
break;
|
|
||||||
case State::ENTERING_SCREEN:
|
|
||||||
handleEnteringScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
|
||||||
break;
|
|
||||||
case State::CREDITS:
|
|
||||||
handleCreditsMovement(deltaTime); // Fase 4: Sistema de créditos time-based
|
|
||||||
break;
|
|
||||||
case State::WAITING:
|
|
||||||
handleWaitingMovement(deltaTime); // Fase 4: Sistema de waiting time-based
|
|
||||||
break;
|
|
||||||
case State::RECOVER:
|
|
||||||
handleRecoverMovement(); // Sin cambios - usa AnimatedSprite que ya soporta deltaTime
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::handlePlayingMovement() {
|
void Player::handlePlayingMovement() {
|
||||||
// Mueve el jugador a derecha o izquierda
|
// Mueve el jugador a derecha o izquierda
|
||||||
pos_x_ += vel_x_;
|
pos_x_ += vel_x_;
|
||||||
@@ -473,8 +435,22 @@ void Player::updateStepCounter(float deltaTime) {
|
|||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void Player::render() {
|
void Player::render() {
|
||||||
if (power_up_ && isPlaying()) {
|
if (power_up_ && isPlaying()) {
|
||||||
if (power_up_counter_ > (POWERUP_COUNTER / 4) || power_up_counter_ % 20 > 4) {
|
// Convertir lógica de parpadeo a deltaTime
|
||||||
|
float total_powerup_time_ms = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Total time in ms
|
||||||
|
float quarter_time_ms = total_powerup_time_ms / 4.0f; // 25% del tiempo total
|
||||||
|
|
||||||
|
if (power_up_time_accumulator_ > quarter_time_ms) {
|
||||||
|
// En los primeros 75% del tiempo, siempre visible
|
||||||
power_sprite_->render();
|
power_sprite_->render();
|
||||||
|
} else {
|
||||||
|
// En el último 25%, parpadea cada 20 frames (333ms aprox)
|
||||||
|
constexpr float blink_period_ms = 20.0f / 60.0f * 1000.0f; // 20 frames in ms
|
||||||
|
constexpr float visible_proportion = 4.0f / 20.0f; // 4 frames visible de 20 total
|
||||||
|
|
||||||
|
float cycle_position = fmod(power_up_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||||
|
if (cycle_position >= visible_proportion) {
|
||||||
|
power_sprite_->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,47 +513,6 @@ auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
|
|||||||
return {anim_name, flip_mode};
|
return {anim_name, flip_mode};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animación correspondiente al estado (frame-based)
|
|
||||||
void Player::setAnimation() {
|
|
||||||
switch (playing_state_) {
|
|
||||||
case State::PLAYING:
|
|
||||||
case State::ENTERING_NAME_GAME_COMPLETED:
|
|
||||||
case State::ENTERING_SCREEN:
|
|
||||||
case State::LEAVING_SCREEN:
|
|
||||||
case State::TITLE_ANIMATION:
|
|
||||||
case State::CREDITS: {
|
|
||||||
auto [animName, flipMode] = computeAnimation();
|
|
||||||
player_sprite_->setCurrentAnimation(animName, false);
|
|
||||||
player_sprite_->setFlip(flipMode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case State::RECOVER:
|
|
||||||
player_sprite_->setCurrentAnimation("recover");
|
|
||||||
break;
|
|
||||||
case State::WAITING:
|
|
||||||
case State::GAME_OVER:
|
|
||||||
player_sprite_->setCurrentAnimation("hello");
|
|
||||||
break;
|
|
||||||
case State::ROLLING:
|
|
||||||
case State::CONTINUE_TIME_OUT:
|
|
||||||
player_sprite_->setCurrentAnimation("rolling");
|
|
||||||
break;
|
|
||||||
case State::LYING_ON_THE_FLOOR_FOREVER:
|
|
||||||
case State::ENTERING_NAME:
|
|
||||||
case State::CONTINUE:
|
|
||||||
player_sprite_->setCurrentAnimation("dizzy");
|
|
||||||
break;
|
|
||||||
case State::CELEBRATING:
|
|
||||||
player_sprite_->setCurrentAnimation("celebration");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
player_sprite_->update();
|
|
||||||
power_sprite_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 1: Establece la animación correspondiente al estado (time-based)
|
// Fase 1: Establece la animación correspondiente al estado (time-based)
|
||||||
void Player::setAnimation(float deltaTime) {
|
void Player::setAnimation(float deltaTime) {
|
||||||
switch (playing_state_) {
|
switch (playing_state_) {
|
||||||
@@ -620,183 +555,18 @@ void Player::setAnimation(float deltaTime) {
|
|||||||
power_sprite_->update(deltaTime);
|
power_sprite_->update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable (frame-based)
|
// Actualiza al jugador con deltaTime (time-based)
|
||||||
void Player::updateCooldown() {
|
|
||||||
if (playing_state_ != State::PLAYING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cant_fire_counter_ > 0) {
|
|
||||||
handleFiringCooldown();
|
|
||||||
} else {
|
|
||||||
handleRecoilAndCooling();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 2: Actualiza el cooldown de disparo (time-based)
|
|
||||||
void Player::updateCooldown(float deltaTime) {
|
|
||||||
if (playing_state_ != State::PLAYING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cant_fire_time_accumulator_ > 0) {
|
|
||||||
handleFiringCooldown(deltaTime);
|
|
||||||
} else {
|
|
||||||
handleRecoilAndCooling(deltaTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::handleFiringCooldown() {
|
|
||||||
cooling_state_counter_ = COOLING_DURATION;
|
|
||||||
|
|
||||||
// Transition to recoiling state at halfway point
|
|
||||||
if (cant_fire_counter_ == recoiling_state_duration_ / 2) {
|
|
||||||
transitionToRecoiling();
|
|
||||||
}
|
|
||||||
|
|
||||||
--cant_fire_counter_;
|
|
||||||
if (cant_fire_counter_ == 0) {
|
|
||||||
recoiling_state_counter_ = recoiling_state_duration_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 2: Manejo de cooldown de disparo (time-based)
|
|
||||||
void Player::handleFiringCooldown(float deltaTime) {
|
|
||||||
cooling_time_accumulator_ = static_cast<float>(COOLING_DURATION) / 60.0f;
|
|
||||||
|
|
||||||
// Convertir frames a tiempo: 1 frame = 1/60 segundos
|
|
||||||
float frameTime = 1.0f / 60.0f;
|
|
||||||
float halfwayTime = static_cast<float>(recoiling_state_duration_) / 2.0f / 60.0f;
|
|
||||||
|
|
||||||
// Reducir tiempo acumulado
|
|
||||||
cant_fire_time_accumulator_ -= deltaTime;
|
|
||||||
|
|
||||||
// Transition to recoiling state at halfway point
|
|
||||||
if (cant_fire_time_accumulator_ <= halfwayTime && cant_fire_time_accumulator_ > halfwayTime - frameTime) {
|
|
||||||
transitionToRecoiling();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cant_fire_time_accumulator_ <= 0) {
|
|
||||||
cant_fire_time_accumulator_ = 0;
|
|
||||||
recoiling_time_accumulator_ = static_cast<float>(recoiling_state_duration_) / 60.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::handleRecoilAndCooling() {
|
|
||||||
if (recoiling_state_counter_ > 0) {
|
|
||||||
--recoiling_state_counter_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCoolingState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 2: Manejo de retroceso y enfriamiento (time-based)
|
|
||||||
void Player::handleRecoilAndCooling(float deltaTime) {
|
|
||||||
if (recoiling_time_accumulator_ > 0) {
|
|
||||||
recoiling_time_accumulator_ -= deltaTime;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCoolingState(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::handleCoolingState() {
|
|
||||||
if (cooling_state_counter_ > COOLING_COMPLETE) {
|
|
||||||
if (cooling_state_counter_ == COOLING_DURATION) {
|
|
||||||
transitionToCooling();
|
|
||||||
}
|
|
||||||
--cooling_state_counter_;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cooling_state_counter_ == COOLING_COMPLETE) {
|
|
||||||
completeCooling();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 2: Manejo del estado de enfriamiento (time-based)
|
|
||||||
void Player::handleCoolingState(float deltaTime) {
|
|
||||||
float coolingCompleteTime = static_cast<float>(COOLING_COMPLETE) / 60.0f;
|
|
||||||
float coolingDurationTime = static_cast<float>(COOLING_DURATION) / 60.0f;
|
|
||||||
float frameTime = 1.0f / 60.0f;
|
|
||||||
|
|
||||||
if (cooling_time_accumulator_ > coolingCompleteTime) {
|
|
||||||
// Transición a cooling cuando empezamos (equivalente a == COOLING_DURATION)
|
|
||||||
if (cooling_time_accumulator_ <= coolingDurationTime && cooling_time_accumulator_ > coolingDurationTime - frameTime) {
|
|
||||||
transitionToCooling();
|
|
||||||
}
|
|
||||||
cooling_time_accumulator_ -= deltaTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cooling_time_accumulator_ <= coolingCompleteTime) {
|
|
||||||
cooling_time_accumulator_ = coolingCompleteTime;
|
|
||||||
completeCooling();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::transitionToRecoiling() {
|
|
||||||
switch (firing_state_) {
|
|
||||||
case State::FIRING_LEFT:
|
|
||||||
setFiringState(State::RECOILING_LEFT);
|
|
||||||
break;
|
|
||||||
case State::FIRING_RIGHT:
|
|
||||||
setFiringState(State::RECOILING_RIGHT);
|
|
||||||
break;
|
|
||||||
case State::FIRING_UP:
|
|
||||||
setFiringState(State::RECOILING_UP);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::transitionToCooling() {
|
|
||||||
switch (firing_state_) {
|
|
||||||
case State::RECOILING_LEFT:
|
|
||||||
setFiringState(State::COOLING_LEFT);
|
|
||||||
break;
|
|
||||||
case State::RECOILING_RIGHT:
|
|
||||||
setFiringState(State::COOLING_RIGHT);
|
|
||||||
break;
|
|
||||||
case State::RECOILING_UP:
|
|
||||||
setFiringState(State::COOLING_UP);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::completeCooling() {
|
|
||||||
setFiringState(State::FIRING_NONE);
|
|
||||||
cooling_state_counter_ = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
|
||||||
void Player::update() {
|
|
||||||
move();
|
|
||||||
setAnimation();
|
|
||||||
shiftColliders();
|
|
||||||
updateCooldown();
|
|
||||||
updatePowerUp();
|
|
||||||
updateInvulnerable();
|
|
||||||
updateScoreboard();
|
|
||||||
updateContinueCounter();
|
|
||||||
updateEnterNameCounter();
|
|
||||||
updateShowingName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 1-4: Método deltaTime completo
|
|
||||||
void Player::update(float deltaTime) {
|
void Player::update(float deltaTime) {
|
||||||
move(deltaTime); // Sistema de movimiento time-based
|
move(deltaTime); // Sistema de movimiento time-based
|
||||||
setAnimation(deltaTime); // Animaciones time-based
|
setAnimation(deltaTime); // Animaciones time-based
|
||||||
shiftColliders(); // Sin cambios (posicional)
|
shiftColliders(); // Sin cambios (posicional)
|
||||||
updateCooldown(deltaTime); // Fase 2: Sistema de disparo time-based
|
updateFireSystem(deltaTime); // Sistema de disparo de dos líneas
|
||||||
updatePowerUp(deltaTime); // Fase 3: Sistema de power-up time-based
|
updatePowerUp(deltaTime); // Sistema de power-up time-based
|
||||||
updateInvulnerable(deltaTime); // Fase 3: Sistema de invulnerabilidad time-based
|
updateInvulnerable(deltaTime); // Sistema de invulnerabilidad time-based
|
||||||
updateScoreboard(); // Sin cambios (no temporal)
|
updateScoreboard(); // Sin cambios (no temporal)
|
||||||
updateContinueCounter(deltaTime); // Fase 4: Sistema de continue time-based
|
updateContinueCounter(deltaTime); // Sistema de continue time-based
|
||||||
updateEnterNameCounter(deltaTime); // Fase 4: Sistema de name entry time-based
|
updateEnterNameCounter(deltaTime); // Sistema de name entry time-based
|
||||||
updateShowingName(); // Sin cambios (no temporal)
|
updateShowingName(deltaTime); // Sistema de showing name time-based
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::passShowingName() {
|
void Player::passShowingName() {
|
||||||
@@ -866,7 +636,6 @@ void Player::setPlayingState(State state) {
|
|||||||
}
|
}
|
||||||
case State::CONTINUE: {
|
case State::CONTINUE: {
|
||||||
// Inicializa el contador de continuar
|
// Inicializa el contador de continuar
|
||||||
continue_ticks_ = SDL_GetTicks();
|
|
||||||
continue_counter_ = 9;
|
continue_counter_ = 9;
|
||||||
continue_time_accumulator_ = 0.0f; // Initialize time accumulator
|
continue_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||||
playSound("continue_clock.wav");
|
playSound("continue_clock.wav");
|
||||||
@@ -899,7 +668,7 @@ void Player::setPlayingState(State state) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case State::SHOWING_NAME: {
|
case State::SHOWING_NAME: {
|
||||||
showing_name_ticks_ = SDL_GetTicks();
|
showing_name_time_accumulator_ = 0.0f; // Inicializar acumulador time-based
|
||||||
setScoreboardMode(Scoreboard::Mode::SHOW_NAME);
|
setScoreboardMode(Scoreboard::Mode::SHOW_NAME);
|
||||||
Scoreboard::get()->setRecordName(scoreboard_panel_, last_enter_name_);
|
Scoreboard::get()->setRecordName(scoreboard_panel_, last_enter_name_);
|
||||||
addScoreToScoreBoard();
|
addScoreToScoreBoard();
|
||||||
@@ -1003,55 +772,25 @@ void Player::decScoreMultiplier() {
|
|||||||
void Player::setInvulnerable(bool value) {
|
void Player::setInvulnerable(bool value) {
|
||||||
invulnerable_ = value;
|
invulnerable_ = value;
|
||||||
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER : 0;
|
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER : 0;
|
||||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f : 0.0f; // Initialize time accumulator
|
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f : 0.0f; // Convert frames to milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitoriza el estado (frame-based)
|
// Monitoriza el estado (time-based)
|
||||||
void Player::updateInvulnerable() {
|
|
||||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
|
||||||
if (invulnerable_counter_ > 0) {
|
|
||||||
--invulnerable_counter_;
|
|
||||||
|
|
||||||
// Frecuencia fija de parpadeo (como el original)
|
|
||||||
constexpr int blink_speed = 8;
|
|
||||||
|
|
||||||
// Calcula proporción decreciente: menos textura blanca hacia el final
|
|
||||||
// Al inicio: 50-50, hacia el final: 70-30 (menos blanco)
|
|
||||||
float progress = 1.0f - (static_cast<float>(invulnerable_counter_) / INVULNERABLE_COUNTER);
|
|
||||||
int white_frames = static_cast<int>((0.5f - progress * 0.2f) * blink_speed);
|
|
||||||
|
|
||||||
// Alterna entre texturas con proporción variable
|
|
||||||
bool should_show_invulnerable = (invulnerable_counter_ % blink_speed) < white_frames;
|
|
||||||
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
|
||||||
|
|
||||||
// Solo cambia textura si es diferente (optimización)
|
|
||||||
if (player_sprite_->getActiveTexture() != target_texture) {
|
|
||||||
player_sprite_->setActiveTexture(target_texture);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fin de invulnerabilidad
|
|
||||||
setInvulnerable(false);
|
|
||||||
player_sprite_->setActiveTexture(coffees_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 3: Monitoriza el estado (time-based)
|
|
||||||
void Player::updateInvulnerable(float deltaTime) {
|
void Player::updateInvulnerable(float deltaTime) {
|
||||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||||
if (invulnerable_time_accumulator_ > 0) {
|
if (invulnerable_time_accumulator_ > 0) {
|
||||||
invulnerable_time_accumulator_ -= deltaTime;
|
invulnerable_time_accumulator_ -= deltaTime;
|
||||||
|
|
||||||
// Frecuencia fija de parpadeo adaptada a deltaTime
|
// Frecuencia fija de parpadeo adaptada a deltaTime (en milisegundos)
|
||||||
constexpr float blink_period = 8.0f / 60.0f; // 8 frames convertidos a segundos
|
constexpr float blink_period_ms = 8.0f / 60.0f * 1000.0f; // 8 frames convertidos a ms
|
||||||
|
|
||||||
// Calcula proporción decreciente basada en tiempo restante
|
// Calcula proporción decreciente basada en tiempo restante
|
||||||
float total_invulnerable_time = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f;
|
float total_invulnerable_time_ms = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f;
|
||||||
float progress = 1.0f - (invulnerable_time_accumulator_ / total_invulnerable_time);
|
float progress = 1.0f - (invulnerable_time_accumulator_ / total_invulnerable_time_ms);
|
||||||
float white_proportion = 0.5f - progress * 0.2f; // Menos blanco hacia el final
|
float white_proportion = 0.5f - progress * 0.2f; // Menos blanco hacia el final
|
||||||
|
|
||||||
// Calcula si debe mostrar textura de invulnerabilidad basado en el ciclo temporal
|
// Calcula si debe mostrar textura de invulnerabilidad basado en el ciclo temporal
|
||||||
float cycle_position = fmod(invulnerable_time_accumulator_, blink_period) / blink_period;
|
float cycle_position = fmod(invulnerable_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||||
bool should_show_invulnerable = cycle_position < white_proportion;
|
bool should_show_invulnerable = cycle_position < white_proportion;
|
||||||
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
||||||
|
|
||||||
@@ -1072,20 +811,10 @@ void Player::updateInvulnerable(float deltaTime) {
|
|||||||
void Player::setPowerUp() {
|
void Player::setPowerUp() {
|
||||||
power_up_ = true;
|
power_up_ = true;
|
||||||
power_up_counter_ = POWERUP_COUNTER;
|
power_up_counter_ = POWERUP_COUNTER;
|
||||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Initialize time accumulator
|
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Convert frames to milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable (frame-based)
|
// Actualiza el valor de la variable (time-based)
|
||||||
void Player::updatePowerUp() {
|
|
||||||
if (playing_state_ == State::PLAYING) {
|
|
||||||
if (power_up_) {
|
|
||||||
--power_up_counter_;
|
|
||||||
power_up_ = power_up_counter_ > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 3: Actualiza el valor de la variable (time-based)
|
|
||||||
void Player::updatePowerUp(float deltaTime) {
|
void Player::updatePowerUp(float deltaTime) {
|
||||||
if (playing_state_ == State::PLAYING) {
|
if (playing_state_ == State::PLAYING) {
|
||||||
if (power_up_) {
|
if (power_up_) {
|
||||||
@@ -1130,21 +859,11 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
|||||||
power_sprite_->setTexture(texture[1]);
|
power_sprite_->setTexture(texture[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador de continue (frame-based)
|
// Actualiza el contador de continue (time-based)
|
||||||
void Player::updateContinueCounter() {
|
|
||||||
if (playing_state_ == State::CONTINUE) {
|
|
||||||
constexpr int TICKS_SPEED = 1000;
|
|
||||||
if (SDL_GetTicks() - continue_ticks_ > TICKS_SPEED) {
|
|
||||||
decContinueCounter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 4: Actualiza el contador de continue (time-based)
|
|
||||||
void Player::updateContinueCounter(float deltaTime) {
|
void Player::updateContinueCounter(float deltaTime) {
|
||||||
if (playing_state_ == State::CONTINUE) {
|
if (playing_state_ == State::CONTINUE) {
|
||||||
continue_time_accumulator_ += deltaTime;
|
continue_time_accumulator_ += deltaTime;
|
||||||
constexpr float CONTINUE_INTERVAL = 1.0f; // 1 segundo
|
constexpr float CONTINUE_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL) {
|
if (continue_time_accumulator_ >= CONTINUE_INTERVAL) {
|
||||||
continue_time_accumulator_ -= CONTINUE_INTERVAL;
|
continue_time_accumulator_ -= CONTINUE_INTERVAL;
|
||||||
decContinueCounter();
|
decContinueCounter();
|
||||||
@@ -1152,21 +871,11 @@ void Player::updateContinueCounter(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador de entrar nombre (frame-based)
|
// Actualiza el contador de entrar nombre (time-based)
|
||||||
void Player::updateEnterNameCounter() {
|
|
||||||
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
|
||||||
constexpr int TICKS_SPEED = 1000;
|
|
||||||
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
|
|
||||||
decNameEntryCounter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fase 4: Actualiza el contador de entrar nombre (time-based)
|
|
||||||
void Player::updateEnterNameCounter(float deltaTime) {
|
void Player::updateEnterNameCounter(float deltaTime) {
|
||||||
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
||||||
name_entry_time_accumulator_ += deltaTime;
|
name_entry_time_accumulator_ += deltaTime;
|
||||||
constexpr float NAME_ENTRY_INTERVAL = 1.0f; // 1 segundo
|
constexpr float NAME_ENTRY_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL) {
|
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL) {
|
||||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL;
|
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL;
|
||||||
decNameEntryCounter();
|
decNameEntryCounter();
|
||||||
@@ -1174,11 +883,12 @@ void Player::updateEnterNameCounter(float deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado de SHOWING_NAME
|
// Actualiza el estado de SHOWING_NAME (time-based)
|
||||||
void Player::updateShowingName() {
|
void Player::updateShowingName(float deltaTime) {
|
||||||
if (playing_state_ == State::SHOWING_NAME) {
|
if (playing_state_ == State::SHOWING_NAME) {
|
||||||
constexpr int TICKS_SPEED = 5000;
|
showing_name_time_accumulator_ += deltaTime;
|
||||||
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
|
constexpr float SHOWING_NAME_DURATION = 5000.0f; // 5 segundos en milisegundos
|
||||||
|
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION) {
|
||||||
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
|
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1186,7 +896,7 @@ void Player::updateShowingName() {
|
|||||||
|
|
||||||
// Decrementa el contador de continuar
|
// Decrementa el contador de continuar
|
||||||
void Player::decContinueCounter() {
|
void Player::decContinueCounter() {
|
||||||
continue_ticks_ = SDL_GetTicks();
|
continue_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||||
--continue_counter_;
|
--continue_counter_;
|
||||||
if (continue_counter_ < 0) {
|
if (continue_counter_ < 0) {
|
||||||
setPlayingState(State::CONTINUE_TIME_OUT);
|
setPlayingState(State::CONTINUE_TIME_OUT);
|
||||||
@@ -1197,18 +907,17 @@ void Player::decContinueCounter() {
|
|||||||
|
|
||||||
// Decrementa el contador de entrar nombre
|
// Decrementa el contador de entrar nombre
|
||||||
void Player::decNameEntryCounter() {
|
void Player::decNameEntryCounter() {
|
||||||
name_entry_ticks_ = SDL_GetTicks();
|
|
||||||
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
|
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||||
|
|
||||||
// Actualiza contadores
|
// Incrementa acumuladores de tiempo (1 segundo = 1000ms)
|
||||||
++name_entry_idle_counter_;
|
name_entry_idle_time_accumulator_ += 1000.0f;
|
||||||
++name_entry_total_counter_;
|
name_entry_total_time_accumulator_ += 1000.0f;
|
||||||
|
|
||||||
// Comprueba los contadores
|
// Comprueba los acumuladores directamente contra los límites en milisegundos
|
||||||
if ((name_entry_total_counter_ >= param.game.name_entry_total_time) ||
|
if ((name_entry_total_time_accumulator_ >= param.game.name_entry_total_time) ||
|
||||||
(name_entry_idle_counter_ >= param.game.name_entry_idle_time)) {
|
(name_entry_idle_time_accumulator_ >= param.game.name_entry_idle_time)) {
|
||||||
name_entry_total_counter_ = 0;
|
name_entry_total_time_accumulator_ = 0.0f;
|
||||||
name_entry_idle_counter_ = 0;
|
name_entry_idle_time_accumulator_ = 0.0f;
|
||||||
if (playing_state_ == State::ENTERING_NAME) {
|
if (playing_state_ == State::ENTERING_NAME) {
|
||||||
last_enter_name_ = getRecordName();
|
last_enter_name_ = getRecordName();
|
||||||
setPlayingState(State::SHOWING_NAME);
|
setPlayingState(State::SHOWING_NAME);
|
||||||
@@ -1269,3 +978,144 @@ void Player::addCredit() {
|
|||||||
++credits_used_;
|
++credits_used_;
|
||||||
playSound("credit.wav");
|
playSound("credit.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// SISTEMA DE DISPARO DE DOS LÍNEAS
|
||||||
|
// ========================================
|
||||||
|
|
||||||
|
// Método principal del sistema de disparo
|
||||||
|
void Player::updateFireSystem(float deltaTime) {
|
||||||
|
updateFunctionalLine(deltaTime); // Línea 1: CanFire
|
||||||
|
updateVisualLine(deltaTime); // Línea 2: Animaciones
|
||||||
|
}
|
||||||
|
|
||||||
|
// LÍNEA 1: Sistema Funcional (CanFire)
|
||||||
|
void Player::updateFunctionalLine(float deltaTime) {
|
||||||
|
if (fire_cooldown_timer_ > 0) {
|
||||||
|
fire_cooldown_timer_ -= deltaTime;
|
||||||
|
can_fire_new_system_ = false;
|
||||||
|
} else {
|
||||||
|
fire_cooldown_timer_ = 0; // Evitar valores negativos
|
||||||
|
can_fire_new_system_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LÍNEA 2: Sistema Visual (Animaciones)
|
||||||
|
void Player::updateVisualLine(float deltaTime) {
|
||||||
|
if (visual_fire_state_ == VisualFireState::NORMAL) {
|
||||||
|
return; // No hay temporizador activo en estado NORMAL
|
||||||
|
}
|
||||||
|
|
||||||
|
visual_state_timer_ -= deltaTime;
|
||||||
|
|
||||||
|
switch (visual_fire_state_) {
|
||||||
|
case VisualFireState::AIMING:
|
||||||
|
if (visual_state_timer_ <= 0) {
|
||||||
|
transitionToRecoilingNew();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::RECOILING:
|
||||||
|
if (visual_state_timer_ <= 0) {
|
||||||
|
transitionToThreatPose();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::THREAT_POSE:
|
||||||
|
if (visual_state_timer_ <= 0) {
|
||||||
|
transitionToNormalNew();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::NORMAL:
|
||||||
|
// Ya manejado arriba
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicia un disparo en ambas líneas
|
||||||
|
void Player::startFiringSystem(int cooldown_frames) {
|
||||||
|
// LÍNEA 1: Inicia cooldown funcional
|
||||||
|
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f * 1000.0f; // Convertir frames a ms
|
||||||
|
can_fire_new_system_ = false;
|
||||||
|
|
||||||
|
// LÍNEA 2: Resetea completamente el estado visual
|
||||||
|
aiming_duration_ = fire_cooldown_timer_ * AIMING_DURATION_FACTOR; // 50% del cooldown
|
||||||
|
recoiling_duration_ = aiming_duration_ * RECOILING_DURATION_MULTIPLIER; // 4 veces la duración de aiming
|
||||||
|
|
||||||
|
visual_fire_state_ = VisualFireState::AIMING;
|
||||||
|
visual_state_timer_ = aiming_duration_;
|
||||||
|
|
||||||
|
updateFiringStateFromVisual(); // Sincroniza firing_state_ para animaciones
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sincroniza firing_state_ con visual_fire_state_
|
||||||
|
void Player::updateFiringStateFromVisual() {
|
||||||
|
// Mantener la dirección actual del disparo
|
||||||
|
State base_state = State::FIRING_NONE;
|
||||||
|
|
||||||
|
if (firing_state_ == State::FIRING_LEFT || firing_state_ == State::RECOILING_LEFT || firing_state_ == State::COOLING_LEFT) {
|
||||||
|
base_state = State::FIRING_LEFT;
|
||||||
|
} else if (firing_state_ == State::FIRING_RIGHT || firing_state_ == State::RECOILING_RIGHT || firing_state_ == State::COOLING_RIGHT) {
|
||||||
|
base_state = State::FIRING_RIGHT;
|
||||||
|
} else if (firing_state_ == State::FIRING_UP || firing_state_ == State::RECOILING_UP || firing_state_ == State::COOLING_UP) {
|
||||||
|
base_state = State::FIRING_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (visual_fire_state_) {
|
||||||
|
case VisualFireState::NORMAL:
|
||||||
|
firing_state_ = State::FIRING_NONE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::AIMING:
|
||||||
|
firing_state_ = base_state; // FIRING_LEFT/RIGHT/UP
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::RECOILING:
|
||||||
|
switch (base_state) {
|
||||||
|
case State::FIRING_LEFT: firing_state_ = State::RECOILING_LEFT; break;
|
||||||
|
case State::FIRING_RIGHT: firing_state_ = State::RECOILING_RIGHT; break;
|
||||||
|
case State::FIRING_UP: firing_state_ = State::RECOILING_UP; break;
|
||||||
|
default: firing_state_ = State::RECOILING_UP; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VisualFireState::THREAT_POSE:
|
||||||
|
switch (base_state) {
|
||||||
|
case State::FIRING_LEFT: firing_state_ = State::COOLING_LEFT; break;
|
||||||
|
case State::FIRING_RIGHT: firing_state_ = State::COOLING_RIGHT; break;
|
||||||
|
case State::FIRING_UP: firing_state_ = State::COOLING_UP; break;
|
||||||
|
default: firing_state_ = State::COOLING_UP; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transiciones del sistema visual
|
||||||
|
void Player::transitionToRecoilingNew() {
|
||||||
|
visual_fire_state_ = VisualFireState::RECOILING;
|
||||||
|
visual_state_timer_ = recoiling_duration_;
|
||||||
|
updateFiringStateFromVisual();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::transitionToThreatPose() {
|
||||||
|
visual_fire_state_ = VisualFireState::THREAT_POSE;
|
||||||
|
|
||||||
|
// Calcular threat_pose_duration ajustada:
|
||||||
|
// Duración original (833ms) menos el tiempo extra que ahora dura recoiling
|
||||||
|
float original_recoiling_duration = fire_cooldown_timer_; // Era 100% del cooldown
|
||||||
|
float new_recoiling_duration = aiming_duration_ * RECOILING_DURATION_MULTIPLIER; // Ahora es más del cooldown
|
||||||
|
float extra_recoiling_time = new_recoiling_duration - original_recoiling_duration;
|
||||||
|
float adjusted_threat_duration = THREAT_POSE_DURATION - extra_recoiling_time;
|
||||||
|
|
||||||
|
// Asegurar que no sea negativo
|
||||||
|
visual_state_timer_ = std::max(adjusted_threat_duration, MIN_THREAT_POSE_DURATION);
|
||||||
|
|
||||||
|
updateFiringStateFromVisual();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::transitionToNormalNew() {
|
||||||
|
visual_fire_state_ = VisualFireState::NORMAL;
|
||||||
|
visual_state_timer_ = 0;
|
||||||
|
updateFiringStateFromVisual();
|
||||||
|
}
|
||||||
119
source/player.h
119
source/player.h
@@ -17,7 +17,21 @@
|
|||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// --- Clase Player ---
|
// --- Clase Player: jugador principal del juego ---
|
||||||
|
//
|
||||||
|
// Esta clase gestiona todos los aspectos de un jugador durante el juego,
|
||||||
|
// incluyendo movimiento, disparos, animaciones y estados especiales.
|
||||||
|
//
|
||||||
|
// Funcionalidades principales:
|
||||||
|
// • Sistema de disparo de dos líneas: funcional (cooldown) + visual (animaciones)
|
||||||
|
// • Estados de animación: normal → aiming → recoiling → threat_pose → normal
|
||||||
|
// • Movimiento time-based: compatibilidad con deltaTime para fluidez variable
|
||||||
|
// • Power-ups e invulnerabilidad: coffee machine, extra hits, parpadeos
|
||||||
|
// • Sistema de puntuación: multipliers, high scores, entrada de nombres
|
||||||
|
// • Estados de juego: playing, rolling, continue, entering_name, etc.
|
||||||
|
//
|
||||||
|
// El sistema de disparo utiliza duraciones configurables mediante constantes
|
||||||
|
// para facilitar el ajuste del gameplay y la sensación de disparo.
|
||||||
class Player {
|
class Player {
|
||||||
public:
|
public:
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
@@ -95,7 +109,6 @@ class Player {
|
|||||||
|
|
||||||
// --- Inicialización y ciclo de vida ---
|
// --- Inicialización y ciclo de vida ---
|
||||||
void init(); // Inicializa el jugador
|
void init(); // Inicializa el jugador
|
||||||
void update(); // Actualiza estado, animación y contadores (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza estado, animación y contadores (time-based)
|
void update(float deltaTime); // Actualiza estado, animación y contadores (time-based)
|
||||||
void render(); // Dibuja el jugador en pantalla
|
void render(); // Dibuja el jugador en pantalla
|
||||||
|
|
||||||
@@ -105,17 +118,13 @@ class Player {
|
|||||||
void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
|
void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
|
||||||
|
|
||||||
// --- Movimiento y animación ---
|
// --- Movimiento y animación ---
|
||||||
void move(); // Mueve el jugador (frame-based)
|
|
||||||
void move(float deltaTime); // Mueve el jugador (time-based)
|
void move(float deltaTime); // Mueve el jugador (time-based)
|
||||||
void setAnimation(); // Establece la animación según el estado (frame-based)
|
|
||||||
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
|
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
|
||||||
|
|
||||||
// --- Texturas y animaciones ---
|
// --- Texturas y animaciones ---
|
||||||
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); // Cambia las texturas del jugador
|
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); // Cambia las texturas del jugador
|
||||||
|
|
||||||
// --- Estados y contadores ---
|
// --- Estados y contadores ---
|
||||||
void updateCooldown(); // Actualiza el cooldown de disparo (frame-based)
|
|
||||||
void updateCooldown(float deltaTime); // Actualiza el cooldown de disparo (time-based)
|
|
||||||
|
|
||||||
// --- Puntuación y marcador ---
|
// --- Puntuación y marcador ---
|
||||||
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
|
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
|
||||||
@@ -126,7 +135,6 @@ class Player {
|
|||||||
void setPlayingState(State state); // Cambia el estado de juego
|
void setPlayingState(State state); // Cambia el estado de juego
|
||||||
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
|
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
|
||||||
void setPowerUp(); // Activa el modo PowerUp
|
void setPowerUp(); // Activa el modo PowerUp
|
||||||
void updatePowerUp(); // Actualiza el valor de PowerUp (frame-based)
|
|
||||||
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp (time-based)
|
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp (time-based)
|
||||||
void giveExtraHit(); // Concede un toque extra al jugador
|
void giveExtraHit(); // Concede un toque extra al jugador
|
||||||
void removeExtraHit(); // Quita el toque extra al jugador
|
void removeExtraHit(); // Quita el toque extra al jugador
|
||||||
@@ -150,7 +158,7 @@ class Player {
|
|||||||
[[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; }
|
[[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; }
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
[[nodiscard]] auto canFire() const -> bool { return cant_fire_counter_ <= 0; }
|
[[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema
|
||||||
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
|
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
|
||||||
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
|
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
|
||||||
[[nodiscard]] auto isRecoiling() const -> bool { return firing_state_ == State::RECOILING_LEFT || firing_state_ == State::RECOILING_UP || firing_state_ == State::RECOILING_RIGHT; }
|
[[nodiscard]] auto isRecoiling() const -> bool { return firing_state_ == State::RECOILING_LEFT || firing_state_ == State::RECOILING_UP || firing_state_ == State::RECOILING_RIGHT; }
|
||||||
@@ -180,7 +188,7 @@ class Player {
|
|||||||
|
|
||||||
// Setters inline
|
// Setters inline
|
||||||
void setController(int index) { controller_index_ = index; }
|
void setController(int index) { controller_index_ = index; }
|
||||||
void setCantFireCounter(int counter) { recoiling_state_duration_ = cant_fire_counter_ = counter; }
|
void startFiringSystem(int cooldown_frames); // Método público para iniciar disparo
|
||||||
void setFiringState(State state) { firing_state_ = state; }
|
void setFiringState(State state) { firing_state_ = state; }
|
||||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||||
void setName(const std::string &name) { name_ = name; }
|
void setName(const std::string &name) { name_ = name; }
|
||||||
@@ -198,15 +206,27 @@ class Player {
|
|||||||
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes ---
|
// --- Constantes de física y movimiento ---
|
||||||
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
|
||||||
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable
|
|
||||||
static constexpr size_t INVULNERABLE_TEXTURE = 3; // Textura usada durante invulnerabilidad
|
|
||||||
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
|
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
|
||||||
|
|
||||||
|
// --- Constantes de power-ups y estados especiales ---
|
||||||
|
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp (frames)
|
||||||
|
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable (frames)
|
||||||
|
static constexpr size_t INVULNERABLE_TEXTURE = 3; // Textura usada durante invulnerabilidad
|
||||||
|
|
||||||
|
// --- Constantes del sistema de disparo (obsoletas - usar nuevo sistema) ---
|
||||||
static constexpr int COOLING_DURATION = 50; // Duración del enfriamiento tras disparar
|
static constexpr int COOLING_DURATION = 50; // Duración del enfriamiento tras disparar
|
||||||
static constexpr int COOLING_COMPLETE = 0; // Valor que indica enfriamiento completado
|
static constexpr int COOLING_COMPLETE = 0; // Valor que indica enfriamiento completado
|
||||||
|
|
||||||
|
// --- Constantes de estados de espera ---
|
||||||
static constexpr int WAITING_COUNTER = 1000; // Tiempo de espera en estado de espera
|
static constexpr int WAITING_COUNTER = 1000; // Tiempo de espera en estado de espera
|
||||||
|
|
||||||
|
// --- Constantes del nuevo sistema de disparo de dos líneas ---
|
||||||
|
static constexpr float AIMING_DURATION_FACTOR = 0.5f; // 50% del cooldown funcional
|
||||||
|
static constexpr float RECOILING_DURATION_MULTIPLIER = 4.0f; // 4 veces la duración de aiming
|
||||||
|
static constexpr float THREAT_POSE_DURATION = 833.33f; // 50 frames = ~833ms (duración base)
|
||||||
|
static constexpr float MIN_THREAT_POSE_DURATION = 100.0f; // Duración mínima para threat pose
|
||||||
|
|
||||||
// --- Objetos y punteros ---
|
// --- Objetos y punteros ---
|
||||||
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
||||||
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
|
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||||
@@ -227,9 +247,6 @@ class Player {
|
|||||||
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
|
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
|
||||||
State playing_state_ = State::WAITING; // Estado del jugador en el juego
|
State playing_state_ = State::WAITING; // Estado del jugador en el juego
|
||||||
|
|
||||||
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
|
|
||||||
Uint32 name_entry_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
|
||||||
Uint32 showing_name_ticks_ = 0; // Tiempo en el que se entra al estado SHOWING_NAME
|
|
||||||
float pos_x_ = 0.0F; // Posición en el eje X
|
float pos_x_ = 0.0F; // Posición en el eje X
|
||||||
float default_pos_x_; // Posición inicial para el jugador
|
float default_pos_x_; // Posición inicial para el jugador
|
||||||
float vel_x_ = 0.0F; // Cantidad de píxeles a desplazarse en el eje X
|
float vel_x_ = 0.0F; // Cantidad de píxeles a desplazarse en el eje X
|
||||||
@@ -237,19 +254,36 @@ class Player {
|
|||||||
int pos_y_ = 0; // Posición en el eje Y
|
int pos_y_ = 0; // Posición en el eje Y
|
||||||
int default_pos_y_; // Posición inicial para el jugador
|
int default_pos_y_; // Posición inicial para el jugador
|
||||||
int vel_y_ = 0; // Cantidad de píxeles a desplazarse en el eje Y
|
int vel_y_ = 0; // Cantidad de píxeles a desplazarse en el eje Y
|
||||||
int cant_fire_counter_ = 0; // Contador durante el cual no puede disparar (frame-based)
|
|
||||||
int recoiling_state_counter_ = 0; // Contador para la animación del estado de retroceso (frame-based)
|
|
||||||
int recoiling_state_duration_ = 0; // Número de frames que dura el estado de retroceso
|
|
||||||
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling (frame-based)
|
|
||||||
float cant_fire_time_accumulator_ = 0.0f; // Acumulador de tiempo para cooldown de disparo (time-based)
|
|
||||||
float recoiling_time_accumulator_ = 0.0f; // Acumulador de tiempo para retroceso (time-based)
|
|
||||||
float cooling_time_accumulator_ = 0.0f; // Acumulador de tiempo para enfriamiento (time-based)
|
|
||||||
float invulnerable_time_accumulator_ = 0.0f; // Acumulador de tiempo para invulnerabilidad (time-based)
|
float invulnerable_time_accumulator_ = 0.0f; // Acumulador de tiempo para invulnerabilidad (time-based)
|
||||||
float power_up_time_accumulator_ = 0.0f; // Acumulador de tiempo para power-up (time-based)
|
float power_up_time_accumulator_ = 0.0f; // Acumulador de tiempo para power-up (time-based)
|
||||||
float continue_time_accumulator_ = 0.0f; // Acumulador de tiempo para continue counter (time-based)
|
float continue_time_accumulator_ = 0.0f; // Acumulador de tiempo para continue counter (time-based)
|
||||||
float name_entry_time_accumulator_ = 0.0f; // Acumulador de tiempo para name entry counter (time-based)
|
float name_entry_time_accumulator_ = 0.0f; // Acumulador de tiempo para name entry counter (time-based)
|
||||||
|
float showing_name_time_accumulator_ = 0.0f; // Acumulador de tiempo para showing name (time-based)
|
||||||
float waiting_time_accumulator_ = 0.0f; // Acumulador de tiempo para waiting movement (time-based)
|
float waiting_time_accumulator_ = 0.0f; // Acumulador de tiempo para waiting movement (time-based)
|
||||||
float step_time_accumulator_ = 0.0f; // Acumulador de tiempo para step counter (time-based)
|
float step_time_accumulator_ = 0.0f; // Acumulador de tiempo para step counter (time-based)
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// NUEVO SISTEMA DE DISPARO DE DOS LÍNEAS
|
||||||
|
// ========================================
|
||||||
|
|
||||||
|
// LÍNEA 1: SISTEMA FUNCIONAL (CanFire)
|
||||||
|
float fire_cooldown_timer_ = 0.0f; // Tiempo restante hasta poder disparar otra vez
|
||||||
|
bool can_fire_new_system_ = true; // true si puede disparar ahora mismo
|
||||||
|
|
||||||
|
// LÍNEA 2: SISTEMA VISUAL (Animaciones)
|
||||||
|
enum class VisualFireState {
|
||||||
|
NORMAL, // Brazo en posición neutral
|
||||||
|
AIMING, // Brazo alzado (disparando)
|
||||||
|
RECOILING, // Brazo en retroceso
|
||||||
|
THREAT_POSE // Posición amenazante
|
||||||
|
};
|
||||||
|
|
||||||
|
VisualFireState visual_fire_state_ = VisualFireState::NORMAL;
|
||||||
|
float visual_state_timer_ = 0.0f; // Tiempo en el estado visual actual
|
||||||
|
float aiming_duration_ = 0.0f; // Duración del estado AIMING
|
||||||
|
float recoiling_duration_ = 0.0f; // Duración del estado RECOILING
|
||||||
|
|
||||||
|
|
||||||
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
|
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
|
||||||
int score_ = 0; // Puntos del jugador
|
int score_ = 0; // Puntos del jugador
|
||||||
int coffees_ = 0; // Indica cuántos cafés lleva acumulados
|
int coffees_ = 0; // Indica cuántos cafés lleva acumulados
|
||||||
@@ -257,8 +291,8 @@ class Player {
|
|||||||
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||||
int continue_counter_ = 10; // Contador para poder continuar
|
int continue_counter_ = 10; // Contador para poder continuar
|
||||||
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
||||||
int name_entry_idle_counter_ = 0; // Contador para poner nombre
|
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
|
||||||
int name_entry_total_counter_ = 0; // Segundos totales que lleva acumulados poniendo nombre
|
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
|
||||||
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
||||||
int credits_used_ = 0; // Indica el número de veces que ha continuado
|
int credits_used_ = 0; // Indica el número de veces que ha continuado
|
||||||
int waiting_counter_ = 0; // Contador para el estado de espera
|
int waiting_counter_ = 0; // Contador para el estado de espera
|
||||||
@@ -273,28 +307,37 @@ class Player {
|
|||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
||||||
void shiftSprite(); // Recoloca el sprite
|
void shiftSprite(); // Recoloca el sprite
|
||||||
void updateInvulnerable(); // Monitoriza el estado de invulnerabilidad (frame-based)
|
|
||||||
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad (time-based)
|
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad (time-based)
|
||||||
void updateContinueCounter(); // Actualiza el contador de continue (frame-based)
|
|
||||||
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue (time-based)
|
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue (time-based)
|
||||||
void updateEnterNameCounter(); // Actualiza el contador de entrar nombre (frame-based)
|
|
||||||
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre (time-based)
|
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre (time-based)
|
||||||
void updateShowingName(); // Actualiza el estado SHOWING_NAME
|
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME (time-based)
|
||||||
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
|
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
|
||||||
void updateScoreboard(); // Actualiza el panel del marcador
|
void updateScoreboard(); // Actualiza el panel del marcador
|
||||||
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
|
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
|
||||||
void playSound(const std::string &name) const; // Hace sonar un sonido
|
void playSound(const std::string &name) const; // Hace sonar un sonido
|
||||||
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
|
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
|
||||||
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
|
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
|
||||||
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo (frame-based)
|
|
||||||
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo (time-based)
|
// --- Métodos del sistema de disparo de dos líneas ---
|
||||||
void handleRecoilAndCooling(); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica (frame-based)
|
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
|
||||||
void handleRecoilAndCooling(float deltaTime); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica (time-based)
|
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
|
||||||
void handleCoolingState(); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento (frame-based)
|
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones)
|
||||||
void handleCoolingState(float deltaTime); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento (time-based)
|
void startFiring(int cooldown_frames); // Inicia un nuevo disparo en ambas líneas
|
||||||
void transitionToRecoiling(); // Cambia el estado actual al de retroceso después de disparar
|
void updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
|
||||||
void transitionToCooling(); // Cambia el estado actual al de enfriamiento (por ejemplo, tras una ráfaga o sobrecalentamiento)
|
void transitionToRecoilingNew(); // Transición AIMING → RECOILING
|
||||||
void completeCooling(); // Finaliza el proceso de enfriamiento y restablece el estado listo para disparar
|
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
|
||||||
|
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
|
||||||
|
|
||||||
|
// --- Métodos del sistema de disparo obsoleto ---
|
||||||
|
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar (frame-based)
|
||||||
|
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar (time-based)
|
||||||
|
void handleRecoilAndCooling(); // Procesa retroceso y enfriamiento (frame-based)
|
||||||
|
void handleRecoilAndCooling(float deltaTime); // Procesa retroceso y enfriamiento (time-based)
|
||||||
|
void handleCoolingState(); // Actualiza estado de enfriamiento (frame-based)
|
||||||
|
void handleCoolingState(float deltaTime); // Actualiza estado de enfriamiento (time-based)
|
||||||
|
void transitionToRecoiling(); // Transición a retroceso (sistema obsoleto)
|
||||||
|
void transitionToCooling(); // Transición a enfriamiento (sistema obsoleto)
|
||||||
|
void completeCooling(); // Finaliza enfriamiento (sistema obsoleto)
|
||||||
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (frame-based)
|
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (frame-based)
|
||||||
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (time-based)
|
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (time-based)
|
||||||
void handleRecoverMovement(); // Comprueba si ha acabado la animación
|
void handleRecoverMovement(); // Comprueba si ha acabado la animación
|
||||||
|
|||||||
@@ -99,29 +99,6 @@ void Credits::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables (frame-based)
|
|
||||||
void Credits::update() {
|
|
||||||
if (SDL_GetTicks() - last_time_ > param.game.speed) {
|
|
||||||
last_time_ = SDL_GetTicks();
|
|
||||||
const int REPEAT = want_to_pass_ ? 4 : 1;
|
|
||||||
for (int i = 0; i < REPEAT; ++i) {
|
|
||||||
tiled_bg_->update();
|
|
||||||
cycleColors();
|
|
||||||
balloon_manager_->update();
|
|
||||||
updateTextureDstRects();
|
|
||||||
throwBalloons();
|
|
||||||
updatePlayers();
|
|
||||||
updateAllFades();
|
|
||||||
++counter_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Screen::get()->update();
|
|
||||||
|
|
||||||
fillCanvas();
|
|
||||||
}
|
|
||||||
Audio::update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables (time-based)
|
// Actualiza las variables (time-based)
|
||||||
void Credits::update(float deltaTime) {
|
void Credits::update(float deltaTime) {
|
||||||
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
|
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
|
||||||
@@ -674,13 +651,6 @@ void Credits::cycleColors() {
|
|||||||
tiled_bg_->setColor(color_);
|
tiled_bg_->setColor(color_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualza los jugadores (frame-based)
|
|
||||||
void Credits::updatePlayers() {
|
|
||||||
for (auto &player : players_) {
|
|
||||||
player->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualza los jugadores (time-based)
|
// Actualza los jugadores (time-based)
|
||||||
void Credits::updatePlayers(float deltaTime) {
|
void Credits::updatePlayers(float deltaTime) {
|
||||||
for (auto &player : players_) {
|
for (auto &player : players_) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ class Credits {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Métodos del bucle principal ---
|
// --- Métodos del bucle principal ---
|
||||||
void update(); // Actualización principal de la lógica (frame-based)
|
|
||||||
void update(float deltaTime); // Actualización principal de la lógica (time-based)
|
void update(float deltaTime); // Actualización principal de la lógica (time-based)
|
||||||
auto calculateDeltaTime() -> float; // Calcula el deltatime
|
auto calculateDeltaTime() -> float; // Calcula el deltatime
|
||||||
|
|
||||||
@@ -123,7 +122,6 @@ class Credits {
|
|||||||
void updateAllFades(); // Actualizar estados de fade (frame-based)
|
void updateAllFades(); // Actualizar estados de fade (frame-based)
|
||||||
void updateAllFades(float deltaTime); // Actualizar estados de fade (time-based)
|
void updateAllFades(float deltaTime); // Actualizar estados de fade (time-based)
|
||||||
void cycleColors(); // Cambiar colores de fondo
|
void cycleColors(); // Cambiar colores de fondo
|
||||||
void updatePlayers(); // Actualza los jugadores (frame-based)
|
|
||||||
void updatePlayers(float deltaTime); // Actualza los jugadores (time-based)
|
void updatePlayers(float deltaTime); // Actualza los jugadores (time-based)
|
||||||
|
|
||||||
// --- Métodos de interfaz ---
|
// --- Métodos de interfaz ---
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
scoreboard_ = Scoreboard::get();
|
scoreboard_ = Scoreboard::get();
|
||||||
|
|
||||||
fade_in_->setColor(param.fade.color);
|
fade_in_->setColor(param.fade.color);
|
||||||
fade_in_->setPreDuration(demo_.enabled ? 500 : 0);
|
fade_in_->setPreDuration(demo_.enabled ? DEMO_FADE_PRE_DURATION_MS : 0);
|
||||||
fade_in_->setPostDuration(0);
|
fade_in_->setPostDuration(0);
|
||||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_in_->setMode(Fade::Mode::IN);
|
fade_in_->setMode(Fade::Mode::IN);
|
||||||
@@ -210,43 +210,7 @@ void Game::updateHiScore() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del jugador (frame-based)
|
// Actualiza las variables del jugador
|
||||||
void Game::updatePlayers() {
|
|
||||||
for (auto &player : players_) {
|
|
||||||
player->update();
|
|
||||||
|
|
||||||
if (player->isPlaying()) {
|
|
||||||
// Comprueba la colisión entre el jugador y los globos
|
|
||||||
auto balloon = checkPlayerBalloonCollision(player);
|
|
||||||
|
|
||||||
// Si hay colisión
|
|
||||||
if (balloon) {
|
|
||||||
// Si el globo está parado y el temporizador activo, lo explota
|
|
||||||
if (balloon->isStopped() && time_stopped_counter_ > 0) {
|
|
||||||
balloon_manager_->popBalloon(balloon);
|
|
||||||
}
|
|
||||||
// En caso contrario, el jugador ha sido golpeado por un globo activo
|
|
||||||
else {
|
|
||||||
handlePlayerCollision(player, balloon);
|
|
||||||
|
|
||||||
if (demo_.enabled && allPlayersAreNotPlaying()) {
|
|
||||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
|
||||||
fade_out_->setPostDuration(500);
|
|
||||||
fade_out_->activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba las colisiones entre el jugador y los items
|
|
||||||
checkPlayerItemCollision(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Organiza la lista de jugadores
|
|
||||||
sortPlayersByZOrder();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables del jugador (time-based)
|
|
||||||
void Game::updatePlayers(float deltaTime) {
|
void Game::updatePlayers(float deltaTime) {
|
||||||
for (auto &player : players_) {
|
for (auto &player : players_) {
|
||||||
player->update(deltaTime);
|
player->update(deltaTime);
|
||||||
@@ -258,7 +222,7 @@ void Game::updatePlayers(float deltaTime) {
|
|||||||
// Si hay colisión
|
// Si hay colisión
|
||||||
if (balloon) {
|
if (balloon) {
|
||||||
// Si el globo está parado y el temporizador activo, lo explota
|
// Si el globo está parado y el temporizador activo, lo explota
|
||||||
if (balloon->isStopped() && time_stopped_counter_ > 0) {
|
if (balloon->isStopped() && time_stopped_timer_ > 0) {
|
||||||
balloon_manager_->popBalloon(balloon);
|
balloon_manager_->popBalloon(balloon);
|
||||||
}
|
}
|
||||||
// En caso contrario, el jugador ha sido golpeado por un globo activo
|
// En caso contrario, el jugador ha sido golpeado por un globo activo
|
||||||
@@ -348,31 +312,28 @@ void Game::updateStage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado de fin de la partida
|
// Actualiza el estado de fin de la partida
|
||||||
void Game::updateGameStateGameOver() {
|
void Game::updateGameStateGameOver(float deltaTime) {
|
||||||
fade_out_->update();
|
fade_out_->update();
|
||||||
updatePlayers();
|
updatePlayers(deltaTime);
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground(deltaTime);
|
||||||
balloon_manager_->update();
|
balloon_manager_->update(deltaTime);
|
||||||
tabe_->update();
|
tabe_->update(deltaTime);
|
||||||
updateBullets();
|
updateBullets(deltaTime);
|
||||||
updateItems();
|
updateItems(deltaTime);
|
||||||
updateSmartSprites();
|
updateSmartSprites(deltaTime);
|
||||||
updatePathSprites();
|
updatePathSprites();
|
||||||
updateTimeStopped();
|
updateTimeStopped(deltaTime);
|
||||||
checkBulletCollision();
|
checkBulletCollision();
|
||||||
cleanVectors();
|
cleanVectors();
|
||||||
|
|
||||||
if (game_over_counter_ > 0) {
|
if (game_over_timer_ < GAME_OVER_DURATION_MS) {
|
||||||
if (game_over_counter_ == GAME_OVER_COUNTER) {
|
handleGameOverEvents(); // Maneja eventos al inicio
|
||||||
createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_text_game_over"));
|
|
||||||
Audio::get()->fadeOutMusic(1000);
|
|
||||||
balloon_manager_->setBouncingSounds(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
game_over_counter_--;
|
game_over_timer_ += deltaTime; // Incremento time-based
|
||||||
|
|
||||||
if (game_over_counter_ == 150) {
|
constexpr float FADE_TRIGGER_MS = GAME_OVER_DURATION_MS - (150.0f * (1000.0f / 60.0f)); // 2500ms antes del final
|
||||||
|
if (game_over_timer_ >= FADE_TRIGGER_MS && !fade_out_->isEnabled()) {
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,7 +346,7 @@ void Game::updateGameStateGameOver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fade_out_->hasEnded()) {
|
if (fade_out_->hasEnded()) {
|
||||||
if (game_completed_counter_ > 0) {
|
if (game_completed_timer_ > 0) {
|
||||||
Section::name = Section::Name::CREDITS; // Los jugadores han completado el juego
|
Section::name = Section::Name::CREDITS; // Los jugadores han completado el juego
|
||||||
} else {
|
} else {
|
||||||
Section::name = Section::Name::HI_SCORE_TABLE; // La partida ha terminado con la derrota de los jugadores
|
Section::name = Section::Name::HI_SCORE_TABLE; // La partida ha terminado con la derrota de los jugadores
|
||||||
@@ -399,55 +360,28 @@ void Game::updateGameStateGameOver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona eventos para el estado del final del juego
|
// Gestiona eventos para el estado del final del juego
|
||||||
void Game::updateGameStateCompleted() {
|
void Game::updateGameStateCompleted(float deltaTime) {
|
||||||
constexpr int START_CELEBRATIONS = 400;
|
updatePlayers(deltaTime);
|
||||||
constexpr int END_CELEBRATIONS = START_CELEBRATIONS + 300;
|
|
||||||
|
|
||||||
updatePlayers();
|
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground(deltaTime);
|
||||||
balloon_manager_->update();
|
balloon_manager_->update(deltaTime);
|
||||||
tabe_->update();
|
tabe_->update(deltaTime);
|
||||||
updateBullets();
|
updateBullets(deltaTime);
|
||||||
updateItems();
|
updateItems(deltaTime);
|
||||||
updateSmartSprites();
|
updateSmartSprites(deltaTime);
|
||||||
updatePathSprites();
|
updatePathSprites();
|
||||||
cleanVectors();
|
cleanVectors();
|
||||||
|
|
||||||
// Comienza las celebraciones
|
// Maneja eventos del juego completado
|
||||||
// Muestra el mensaje de felicitación y da los puntos a los jugadores
|
handleGameCompletedEvents();
|
||||||
if (game_completed_counter_ == START_CELEBRATIONS) {
|
|
||||||
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
|
||||||
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
|
||||||
|
|
||||||
for (auto &player : players_) {
|
|
||||||
if (player->isPlaying()) {
|
|
||||||
player->addScore(1000000, Options::settings.hi_score_table.back().score);
|
|
||||||
player->setPlayingState(Player::State::CELEBRATING);
|
|
||||||
} else {
|
|
||||||
player->setPlayingState(Player::State::GAME_OVER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateHiScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Termina las celebraciones
|
|
||||||
if (game_completed_counter_ == END_CELEBRATIONS) {
|
|
||||||
for (auto &player : players_) {
|
|
||||||
if (player->isCelebrating()) {
|
|
||||||
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si los jugadores ya no estan y no quedan mensajes en pantalla
|
// Si los jugadores ya no estan y no quedan mensajes en pantalla
|
||||||
if (allPlayersAreGameOver() && path_sprites_.empty()) {
|
if (allPlayersAreGameOver() && path_sprites_.empty()) {
|
||||||
setState(State::GAME_OVER);
|
setState(State::GAME_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa el contador al final
|
// Incrementa el acumulador al final
|
||||||
++game_completed_counter_;
|
game_completed_timer_ += deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el estado del juego
|
// Comprueba el estado del juego
|
||||||
@@ -663,9 +597,9 @@ void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mueve las balas activas
|
// Mueve las balas activas
|
||||||
void Game::updateBullets() {
|
void Game::updateBullets(float deltaTime) {
|
||||||
for (auto &bullet : bullets_) {
|
for (auto &bullet : bullets_) {
|
||||||
if (bullet->update() == BulletMoveStatus::OUT) {
|
if (bullet->update(deltaTime) == BulletMoveStatus::OUT) {
|
||||||
getPlayer(bullet->getOwner())->decScoreMultiplier();
|
getPlayer(bullet->getOwner())->decScoreMultiplier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -695,10 +629,10 @@ void Game::freeBullets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los items
|
// Actualiza los items
|
||||||
void Game::updateItems() {
|
void Game::updateItems(float deltaTime) {
|
||||||
for (auto &item : items_) {
|
for (auto &item : items_) {
|
||||||
if (item->isEnabled()) {
|
if (item->isEnabled()) {
|
||||||
item->update();
|
item->update(deltaTime);
|
||||||
if (item->isOnFloor()) {
|
if (item->isOnFloor()) {
|
||||||
playSound("title.wav");
|
playSound("title.wav");
|
||||||
screen_->shake(1, 2, 4);
|
screen_->shake(1, 2, 4);
|
||||||
@@ -865,9 +799,9 @@ void Game::throwCoffee(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los SmartSprites
|
// Actualiza los SmartSprites
|
||||||
void Game::updateSmartSprites() {
|
void Game::updateSmartSprites(float deltaTime) {
|
||||||
for (auto &sprite : smart_sprites_) {
|
for (auto &sprite : smart_sprites_) {
|
||||||
sprite->update();
|
sprite->update(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,21 +857,35 @@ void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_pt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza y comprueba el valor de la variable
|
// Actualiza el estado del tiempo detenido
|
||||||
void Game::updateTimeStopped() {
|
void Game::updateTimeStopped(float deltaTime) {
|
||||||
if (time_stopped_counter_ > 0) {
|
static constexpr float WARNING_THRESHOLD_MS = 2000.0f; // 120 frames a 60fps
|
||||||
time_stopped_counter_--;
|
static constexpr float CLOCK_SOUND_INTERVAL_MS = 500.0f; // 30 frames a 60fps
|
||||||
if (time_stopped_counter_ > 120) {
|
static constexpr float COLOR_FLASH_INTERVAL_MS = 250.0f; // 15 frames a 60fps
|
||||||
if (static_cast<int>(time_stopped_counter_) % 30 == 0) {
|
|
||||||
|
if (time_stopped_timer_ > 0) {
|
||||||
|
time_stopped_timer_ -= deltaTime;
|
||||||
|
|
||||||
|
// Fase de advertencia (últimos 2 segundos)
|
||||||
|
if (time_stopped_timer_ <= WARNING_THRESHOLD_MS) {
|
||||||
|
static float last_sound_time = 0.0f;
|
||||||
|
last_sound_time += deltaTime;
|
||||||
|
|
||||||
|
if (last_sound_time >= CLOCK_SOUND_INTERVAL_MS) {
|
||||||
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
|
playSound("clock.wav");
|
||||||
|
last_sound_time = 0.0f;
|
||||||
|
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_MS) {
|
||||||
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
playSound("clock.wav");
|
playSound("clock.wav");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (static_cast<int>(time_stopped_counter_) % 30 == 0) {
|
// Fase normal - solo sonido ocasional
|
||||||
balloon_manager_->normalColorsToAllBalloons();
|
static float sound_timer = 0.0f;
|
||||||
playSound("clock.wav");
|
sound_timer += deltaTime;
|
||||||
} else if (static_cast<int>(time_stopped_counter_) % 30 == 15) {
|
if (sound_timer >= CLOCK_SOUND_INTERVAL_MS) {
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
|
||||||
playSound("clock.wav");
|
playSound("clock.wav");
|
||||||
|
sound_timer = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -945,24 +893,7 @@ void Game::updateTimeStopped() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza toda la lógica del juego (frame-based)
|
// Actualiza toda la lógica del juego
|
||||||
void Game::update() {
|
|
||||||
if (SDL_GetTicks() - last_time_ > param.game.speed) {
|
|
||||||
last_time_ = SDL_GetTicks();
|
|
||||||
screen_->update();
|
|
||||||
|
|
||||||
updateDemo();
|
|
||||||
#ifdef RECORDING
|
|
||||||
updateRecording();
|
|
||||||
#endif
|
|
||||||
updateGameStates();
|
|
||||||
fillCanvas();
|
|
||||||
}
|
|
||||||
|
|
||||||
Audio::update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza toda la lógica del juego (time-based)
|
|
||||||
void Game::update(float deltaTime) {
|
void Game::update(float deltaTime) {
|
||||||
screen_->update();
|
screen_->update();
|
||||||
|
|
||||||
@@ -970,7 +901,7 @@ void Game::update(float deltaTime) {
|
|||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
updateRecording();
|
updateRecording();
|
||||||
#endif
|
#endif
|
||||||
updateGameStates();
|
updateGameStates(deltaTime);
|
||||||
fillCanvas();
|
fillCanvas();
|
||||||
|
|
||||||
Audio::update();
|
Audio::update();
|
||||||
@@ -989,26 +920,26 @@ void Game::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los estados del juego
|
// Actualiza los estados del juego
|
||||||
void Game::updateGameStates() {
|
void Game::updateGameStates(float deltaTime) {
|
||||||
if (!pause_manager_->isPaused()) {
|
if (!pause_manager_->isPaused()) {
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case State::FADE_IN:
|
case State::FADE_IN:
|
||||||
updateGameStateFadeIn();
|
updateGameStateFadeIn(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::ENTERING_PLAYER:
|
case State::ENTERING_PLAYER:
|
||||||
updateGameStateEnteringPlayer();
|
updateGameStateEnteringPlayer(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::SHOWING_GET_READY_MESSAGE:
|
case State::SHOWING_GET_READY_MESSAGE:
|
||||||
updateGameStateShowingGetReadyMessage();
|
updateGameStateShowingGetReadyMessage(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::PLAYING:
|
case State::PLAYING:
|
||||||
updateGameStatePlaying();
|
updateGameStatePlaying(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::COMPLETED:
|
case State::COMPLETED:
|
||||||
updateGameStateCompleted();
|
updateGameStateCompleted(deltaTime);
|
||||||
break;
|
break;
|
||||||
case State::GAME_OVER:
|
case State::GAME_OVER:
|
||||||
updateGameStateGameOver();
|
updateGameStateGameOver(deltaTime);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1017,8 +948,8 @@ void Game::updateGameStates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
void Game::updateBackground() {
|
void Game::updateBackground(float deltaTime) {
|
||||||
background_->update();
|
background_->update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los elementos de la zona de juego en su textura
|
// Dibuja los elementos de la zona de juego en su textura
|
||||||
@@ -1047,12 +978,12 @@ void Game::fillCanvas() {
|
|||||||
void Game::enableTimeStopItem() {
|
void Game::enableTimeStopItem() {
|
||||||
balloon_manager_->stopAllBalloons();
|
balloon_manager_->stopAllBalloons();
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
time_stopped_counter_ = TIME_STOPPED_COUNTER;
|
time_stopped_timer_ = TIME_STOPPED_DURATION_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita el efecto del item de detener el tiempo
|
// Deshabilita el efecto del item de detener el tiempo
|
||||||
void Game::disableTimeStopItem() {
|
void Game::disableTimeStopItem() {
|
||||||
time_stopped_counter_ = 0;
|
time_stopped_timer_ = 0;
|
||||||
balloon_manager_->startAllBalloons();
|
balloon_manager_->startAllBalloons();
|
||||||
balloon_manager_->normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
}
|
}
|
||||||
@@ -1391,7 +1322,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
cant_fire_counter = NORMAL_COOLDOWN;
|
cant_fire_counter = NORMAL_COOLDOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
player->setCantFireCounter(cant_fire_counter);
|
player->startFiringSystem(cant_fire_counter); // Sistema de disparo de dos líneas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1768,10 +1699,10 @@ void Game::updateRecording() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Actualiza las variables durante dicho estado
|
// Actualiza las variables durante dicho estado
|
||||||
void Game::updateGameStateFadeIn() {
|
void Game::updateGameStateFadeIn(float deltaTime) {
|
||||||
fade_in_->update();
|
fade_in_->update();
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground(deltaTime);
|
||||||
if (fade_in_->hasEnded()) {
|
if (fade_in_->hasEnded()) {
|
||||||
setState(State::ENTERING_PLAYER);
|
setState(State::ENTERING_PLAYER);
|
||||||
balloon_manager_->createTwoBigBalloons();
|
balloon_manager_->createTwoBigBalloons();
|
||||||
@@ -1780,11 +1711,11 @@ void Game::updateGameStateFadeIn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables durante dicho estado
|
// Actualiza las variables durante dicho estado
|
||||||
void Game::updateGameStateEnteringPlayer() {
|
void Game::updateGameStateEnteringPlayer(float deltaTime) {
|
||||||
balloon_manager_->update();
|
balloon_manager_->update(deltaTime);
|
||||||
updatePlayers();
|
updatePlayers(deltaTime);
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground(deltaTime);
|
||||||
for (const auto &player : players_) {
|
for (const auto &player : players_) {
|
||||||
if (player->isPlaying()) {
|
if (player->isPlaying()) {
|
||||||
setState(State::SHOWING_GET_READY_MESSAGE);
|
setState(State::SHOWING_GET_READY_MESSAGE);
|
||||||
@@ -1795,8 +1726,8 @@ void Game::updateGameStateEnteringPlayer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables durante dicho estado
|
// Actualiza las variables durante dicho estado
|
||||||
void Game::updateGameStateShowingGetReadyMessage() {
|
void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
|
||||||
updateGameStatePlaying();
|
updateGameStatePlaying(deltaTime);
|
||||||
if (path_sprites_.empty()) {
|
if (path_sprites_.empty()) {
|
||||||
setState(State::PLAYING);
|
setState(State::PLAYING);
|
||||||
}
|
}
|
||||||
@@ -1807,24 +1738,24 @@ void Game::updateGameStateShowingGetReadyMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables durante el transcurso normal del juego
|
// Actualiza las variables durante el transcurso normal del juego
|
||||||
void Game::updateGameStatePlaying() {
|
void Game::updateGameStatePlaying(float deltaTime) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (auto_pop_balloons_) {
|
if (auto_pop_balloons_) {
|
||||||
stage_manager_->addPower(5);
|
stage_manager_->addPower(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
updatePlayers();
|
updatePlayers(deltaTime);
|
||||||
checkPlayersStatusPlaying();
|
checkPlayersStatusPlaying();
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground(deltaTime);
|
||||||
balloon_manager_->update();
|
balloon_manager_->update(deltaTime);
|
||||||
tabe_->update();
|
tabe_->update(deltaTime);
|
||||||
updateBullets();
|
updateBullets(deltaTime);
|
||||||
updateItems();
|
updateItems(deltaTime);
|
||||||
updateStage();
|
updateStage();
|
||||||
updateSmartSprites();
|
updateSmartSprites(deltaTime);
|
||||||
updatePathSprites();
|
updatePathSprites();
|
||||||
updateTimeStopped();
|
updateTimeStopped(deltaTime);
|
||||||
updateHelper();
|
updateHelper();
|
||||||
checkBulletCollision();
|
checkBulletCollision();
|
||||||
updateMenace();
|
updateMenace();
|
||||||
@@ -1962,6 +1893,55 @@ void Game::onPauseStateChanged(bool is_paused) {
|
|||||||
tabe_->pauseTimer(is_paused);
|
tabe_->pauseTimer(is_paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maneja eventos del juego completado usando flags para triggers únicos
|
||||||
|
void Game::handleGameCompletedEvents() {
|
||||||
|
constexpr float START_CELEBRATIONS_MS = 6667.0f; // 400 frames a 60fps
|
||||||
|
constexpr float END_CELEBRATIONS_MS = 11667.0f; // 700 frames a 60fps
|
||||||
|
|
||||||
|
// Inicio de celebraciones
|
||||||
|
static bool start_celebrations_triggered = false;
|
||||||
|
if (!start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_MS) {
|
||||||
|
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
||||||
|
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
||||||
|
|
||||||
|
for (auto &player : players_) {
|
||||||
|
if (player->isPlaying()) {
|
||||||
|
player->addScore(1000000, Options::settings.hi_score_table.back().score);
|
||||||
|
player->setPlayingState(Player::State::CELEBRATING);
|
||||||
|
} else {
|
||||||
|
player->setPlayingState(Player::State::GAME_OVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateHiScore();
|
||||||
|
start_celebrations_triggered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fin de celebraciones
|
||||||
|
static bool end_celebrations_triggered = false;
|
||||||
|
if (!end_celebrations_triggered && game_completed_timer_ >= END_CELEBRATIONS_MS) {
|
||||||
|
for (auto &player : players_) {
|
||||||
|
if (player->isCelebrating()) {
|
||||||
|
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fade_out_->activate();
|
||||||
|
end_celebrations_triggered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maneja eventos de game over usando flag para trigger único
|
||||||
|
void Game::handleGameOverEvents() {
|
||||||
|
static bool game_over_triggered = false;
|
||||||
|
if (!game_over_triggered && game_over_timer_ == 0.0f) {
|
||||||
|
createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_text_game_over"));
|
||||||
|
Audio::get()->fadeOutMusic(1000);
|
||||||
|
balloon_manager_->setBouncingSounds(true);
|
||||||
|
game_over_triggered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Comprueba los eventos en el modo DEBUG
|
// Comprueba los eventos en el modo DEBUG
|
||||||
void Game::handleDebugEvents(const SDL_Event &event) {
|
void Game::handleDebugEvents(const SDL_Event &event) {
|
||||||
|
|||||||
@@ -33,7 +33,22 @@ namespace Difficulty {
|
|||||||
enum class Code;
|
enum class Code;
|
||||||
} // namespace Difficulty
|
} // namespace Difficulty
|
||||||
|
|
||||||
// --- Clase Game: gestor principal del juego ---
|
// --- Clase Game: núcleo principal del gameplay ---
|
||||||
|
//
|
||||||
|
// Esta clase gestiona toda la lógica del juego durante las partidas activas,
|
||||||
|
// incluyendo mecánicas de juego, estados, objetos y sistemas de puntuación.
|
||||||
|
//
|
||||||
|
// Funcionalidades principales:
|
||||||
|
// • Gestión de jugadores: soporte para 1 o 2 jugadores simultáneos
|
||||||
|
// • Sistema de estados: fade-in, entrada, jugando, completado, game-over
|
||||||
|
// • Mecánicas de juego: globos, balas, ítems, power-ups y efectos especiales
|
||||||
|
// • Sistema de puntuación: scoreboard y tabla de récords
|
||||||
|
// • Efectos temporales: tiempo detenido, ayudas automáticas
|
||||||
|
// • Modo demo: reproducción automática para attract mode
|
||||||
|
// • Gestión de fases: progresión entre niveles y dificultad
|
||||||
|
//
|
||||||
|
// Utiliza un sistema de tiempo basado en milisegundos para garantizar
|
||||||
|
// comportamiento consistente independientemente del framerate.
|
||||||
class Game {
|
class Game {
|
||||||
public:
|
public:
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
@@ -58,12 +73,13 @@ class Game {
|
|||||||
GAME_OVER, // Fin del juego
|
GAME_OVER, // Fin del juego
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Constantes internas ---
|
// --- Constantes de tiempo (en milisegundos) ---
|
||||||
static constexpr int HELP_COUNTER = 1000;
|
static constexpr float HELP_COUNTER_MS = 16667.0f; // Contador de ayuda (1000 frames a 60fps)
|
||||||
static constexpr int GAME_COMPLETED_START_FADE = 500;
|
static constexpr float GAME_COMPLETED_START_FADE_MS = 8333.0f; // Inicio del fade al completar (500 frames)
|
||||||
static constexpr int GAME_COMPLETED_END = 700;
|
static constexpr float GAME_COMPLETED_END_MS = 11667.0f; // Fin del juego completado (700 frames)
|
||||||
static constexpr int GAME_OVER_COUNTER = 350;
|
static constexpr float GAME_OVER_DURATION_MS = 5833.0f; // Duración game over (350 frames)
|
||||||
static constexpr int TIME_STOPPED_COUNTER = 360;
|
static constexpr float TIME_STOPPED_DURATION_MS = 6000.0f; // Duración del tiempo detenido (360 frames)
|
||||||
|
static constexpr int DEMO_FADE_PRE_DURATION_MS = 500; // Pre-duración del fade en modo demo
|
||||||
static constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
static constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
||||||
static constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
static constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
||||||
static constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
static constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
||||||
@@ -86,7 +102,7 @@ class Game {
|
|||||||
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
|
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
|
||||||
|
|
||||||
Helper()
|
Helper()
|
||||||
: counter(HELP_COUNTER),
|
: counter(HELP_COUNTER_MS),
|
||||||
item_disk_odds(ITEM_POINTS_1_DISK_ODDS),
|
item_disk_odds(ITEM_POINTS_1_DISK_ODDS),
|
||||||
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS),
|
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS),
|
||||||
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS),
|
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS),
|
||||||
@@ -137,11 +153,11 @@ class Game {
|
|||||||
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
|
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
|
||||||
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
|
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
|
||||||
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
|
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
|
||||||
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
|
float difficulty_score_multiplier_ = 1.0f; // Multiplicador de puntos en función de la dificultad
|
||||||
float counter_ = 0; // Contador para el juego
|
float counter_ = 0.0f; // Contador para el juego
|
||||||
float game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más globos
|
float game_completed_timer_ = 0.0f; // Acumulador de tiempo para el tramo final (milisegundos)
|
||||||
float game_over_counter_ = GAME_OVER_COUNTER; // Contador para el estado de fin de partida
|
float game_over_timer_ = 0.0f; // Timer para el estado de fin de partida (milisegundos)
|
||||||
float time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
|
float time_stopped_timer_ = 0.0f; // Temporizador para llevar la cuenta del tiempo detenido
|
||||||
int menace_ = 0; // Nivel de amenaza actual
|
int menace_ = 0; // Nivel de amenaza actual
|
||||||
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||||
State state_ = State::FADE_IN; // Estado
|
State state_ = State::FADE_IN; // Estado
|
||||||
@@ -154,8 +170,7 @@ class Game {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --- Ciclo principal del juego ---
|
// --- Ciclo principal del juego ---
|
||||||
void update(); // Actualiza la lógica principal del juego (frame-based)
|
void update(float deltaTime); // Actualiza la lógica principal del juego
|
||||||
void update(float deltaTime); // Actualiza la lógica principal del juego (time-based)
|
|
||||||
auto calculateDeltaTime() -> float; // Calcula el deltatime
|
auto calculateDeltaTime() -> float; // Calcula el deltatime
|
||||||
void render(); // Renderiza todos los elementos del juego
|
void render(); // Renderiza todos los elementos del juego
|
||||||
void handleEvents(); // Procesa los eventos del sistema en cola
|
void handleEvents(); // Procesa los eventos del sistema en cola
|
||||||
@@ -164,18 +179,17 @@ class Game {
|
|||||||
void cleanVectors(); // Limpia vectores de elementos deshabilitados
|
void cleanVectors(); // Limpia vectores de elementos deshabilitados
|
||||||
|
|
||||||
// --- Gestión de estados del juego ---
|
// --- Gestión de estados del juego ---
|
||||||
void updateGameStates(); // Actualiza todos los estados del juego (usa deltaTime interno)
|
void updateGameStates(float deltaTime); // Actualiza todos los estados del juego
|
||||||
void updateGameStateFadeIn(); // Gestiona el estado de transición de entrada
|
void updateGameStateFadeIn(float deltaTime); // Gestiona el estado de transición de entrada (time-based)
|
||||||
void updateGameStateEnteringPlayer(); // Gestiona el estado de entrada de jugador
|
void updateGameStateEnteringPlayer(float deltaTime); // Gestiona el estado de entrada de jugador
|
||||||
void updateGameStateShowingGetReadyMessage(); // Gestiona el estado de mensaje "preparado"
|
void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado"
|
||||||
void updateGameStatePlaying(); // Gestiona el estado de juego activo
|
void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo
|
||||||
void updateGameStateCompleted(); // Gestiona el estado de juego completado
|
void updateGameStateCompleted(float deltaTime); // Gestiona el estado de juego completado
|
||||||
void updateGameStateGameOver(); // Gestiona el estado de fin de partida
|
void updateGameStateGameOver(float deltaTime); // Gestiona el estado de fin de partida
|
||||||
|
|
||||||
// --- Gestión de jugadores ---
|
// --- Gestión de jugadores ---
|
||||||
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
|
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
|
||||||
void updatePlayers(); // Actualiza las variables y estados de los jugadores (frame-based)
|
void updatePlayers(float deltaTime); // Actualiza las variables y estados de los jugadores
|
||||||
void updatePlayers(float deltaTime); // Actualiza las variables y estados de los jugadores (time-based)
|
|
||||||
void renderPlayers(); // Renderiza todos los jugadores en pantalla
|
void renderPlayers(); // Renderiza todos los jugadores en pantalla
|
||||||
void sortPlayersByZOrder(); // Reorganiza el orden de dibujado de jugadores
|
void sortPlayersByZOrder(); // Reorganiza el orden de dibujado de jugadores
|
||||||
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador por su identificador
|
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador por su identificador
|
||||||
@@ -212,7 +226,7 @@ class Game {
|
|||||||
void demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa entrada de jugador en demo
|
void demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa entrada de jugador en demo
|
||||||
|
|
||||||
// --- Sistema de balas y proyectiles ---
|
// --- Sistema de balas y proyectiles ---
|
||||||
void updateBullets(); // Actualiza posición y estado de todas las balas
|
void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based)
|
||||||
void renderBullets(); // Renderiza todas las balas activas
|
void renderBullets(); // Renderiza todas las balas activas
|
||||||
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala
|
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala
|
||||||
void checkBulletCollision(); // Verifica colisiones de todas las balas
|
void checkBulletCollision(); // Verifica colisiones de todas las balas
|
||||||
@@ -224,7 +238,7 @@ class Game {
|
|||||||
void processBalloonHit(const std::shared_ptr<Bullet> &bullet, const std::shared_ptr<Balloon> &balloon); // Procesa impacto en globo
|
void processBalloonHit(const std::shared_ptr<Bullet> &bullet, const std::shared_ptr<Balloon> &balloon); // Procesa impacto en globo
|
||||||
|
|
||||||
// --- Sistema de ítems y power-ups ---
|
// --- Sistema de ítems y power-ups ---
|
||||||
void updateItems(); // Actualiza posición y estado de todos los ítems
|
void updateItems(float deltaTime); // Actualiza posición y estado de todos los ítems
|
||||||
void renderItems(); // Renderiza todos los ítems activos
|
void renderItems(); // Renderiza todos los ítems activos
|
||||||
auto dropItem() -> ItemType; // Determina aleatoriamente qué ítem soltar
|
auto dropItem() -> ItemType; // Determina aleatoriamente qué ítem soltar
|
||||||
void createItem(ItemType type, float x, float y); // Crea un nuevo ítem en posición específica
|
void createItem(ItemType type, float x, float y); // Crea un nuevo ítem en posición específica
|
||||||
@@ -234,15 +248,16 @@ class Game {
|
|||||||
// --- ítems especiales ---
|
// --- ítems especiales ---
|
||||||
void enableTimeStopItem(); // Activa el efecto de detener el tiempo
|
void enableTimeStopItem(); // Activa el efecto de detener el tiempo
|
||||||
void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo
|
void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo
|
||||||
void updateTimeStopped(); // Actualiza el estado del tiempo detenido (frame-based)
|
void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido
|
||||||
void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido (time-based)
|
void handleGameCompletedEvents(); // Maneja eventos del juego completado
|
||||||
|
void handleGameOverEvents(); // Maneja eventos de game over
|
||||||
void throwCoffee(int x, int y); // Crea efecto de café arrojado al ser golpeado
|
void throwCoffee(int x, int y); // Crea efecto de café arrojado al ser golpeado
|
||||||
|
|
||||||
// --- Gestión de caída de ítems ---
|
// --- Gestión de caída de ítems ---
|
||||||
void handleItemDrop(const std::shared_ptr<Balloon> &balloon, const std::shared_ptr<Player> &player); // Gestiona caída de ítem desde globo
|
void handleItemDrop(const std::shared_ptr<Balloon> &balloon, const std::shared_ptr<Player> &player); // Gestiona caída de ítem desde globo
|
||||||
|
|
||||||
// --- Sprites inteligentes (smartsprites) ---
|
// --- Sprites inteligentes (smartsprites) ---
|
||||||
void updateSmartSprites(); // Actualiza todos los sprites con lógica propia
|
void updateSmartSprites(float deltaTime); // Actualiza todos los sprites con lógica propia (time-based)
|
||||||
void renderSmartSprites(); // Renderiza todos los sprites inteligentes
|
void renderSmartSprites(); // Renderiza todos los sprites inteligentes
|
||||||
void freeSmartSprites(); // Libera memoria de sprites inteligentes
|
void freeSmartSprites(); // Libera memoria de sprites inteligentes
|
||||||
|
|
||||||
@@ -281,7 +296,7 @@ class Game {
|
|||||||
|
|
||||||
// --- Recursos y renderizado ---
|
// --- Recursos y renderizado ---
|
||||||
void setResources(); // Asigna texturas y animaciones a los objetos
|
void setResources(); // Asigna texturas y animaciones a los objetos
|
||||||
void updateBackground(); // Actualiza elementos del fondo
|
void updateBackground(float deltaTime); // Actualiza elementos del fondo (time-based)
|
||||||
void fillCanvas(); // Renderiza elementos del área de juego en su textura
|
void fillCanvas(); // Renderiza elementos del área de juego en su textura
|
||||||
void updateHelper(); // Actualiza variables auxiliares de renderizado
|
void updateHelper(); // Actualiza variables auxiliares de renderizado
|
||||||
|
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ void Intro::initSprites() {
|
|||||||
|
|
||||||
// Constantes
|
// Constantes
|
||||||
constexpr int TOTAL_SPRITES = TEXTURE_LIST.size();
|
constexpr int TOTAL_SPRITES = TEXTURE_LIST.size();
|
||||||
const float BORDER = 2.0F;
|
const float BORDER = CARD_BORDER_SIZE;
|
||||||
|
|
||||||
auto texture = Resource::get()->getTexture(TEXTURE_LIST.front());
|
auto texture = Resource::get()->getTexture(TEXTURE_LIST.front());
|
||||||
const float CARD_WIDTH = texture->getWidth() + (BORDER * 2);
|
const float CARD_WIDTH = texture->getWidth() + (BORDER * 2);
|
||||||
@@ -338,16 +338,16 @@ void Intro::initSprites() {
|
|||||||
const float X_DEST = param.game.game_area.center_x - (CARD_WIDTH / 2);
|
const float X_DEST = param.game.game_area.center_x - (CARD_WIDTH / 2);
|
||||||
const float Y_DEST = param.game.game_area.first_quarter_y - (CARD_HEIGHT / 4);
|
const float Y_DEST = param.game.game_area.first_quarter_y - (CARD_HEIGHT / 4);
|
||||||
|
|
||||||
card_sprites_.at(0)->addPath(-CARD_WIDTH - 10, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeInOutExpo, 0);
|
card_sprites_.at(0)->addPath(-CARD_WIDTH - CARD_OFFSET_MARGIN, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0);
|
||||||
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeOutBounce, 0);
|
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0);
|
||||||
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 40, easeOutQuint, 0);
|
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0);
|
||||||
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, 300, easeInOutExpo, 0);
|
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0);
|
||||||
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 70, easeOutElastic, 0);
|
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0);
|
||||||
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 250, easeOutQuad, 450);
|
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||||
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, 80, easeInElastic, 0);
|
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0);
|
||||||
|
|
||||||
// Constantes
|
// Constantes
|
||||||
const float DESP = 8;
|
const float DESP = SHADOW_OFFSET;
|
||||||
const float SHADOW_SPRITE_WIDTH = CARD_WIDTH;
|
const float SHADOW_SPRITE_WIDTH = CARD_WIDTH;
|
||||||
const float SHADOW_SPRITE_HEIGHT = CARD_HEIGHT;
|
const float SHADOW_SPRITE_HEIGHT = CARD_HEIGHT;
|
||||||
|
|
||||||
@@ -389,13 +389,13 @@ void Intro::initSprites() {
|
|||||||
const float S_X_DEST = X_DEST + DESP;
|
const float S_X_DEST = X_DEST + DESP;
|
||||||
const float S_Y_DEST = Y_DEST + DESP;
|
const float S_Y_DEST = Y_DEST + DESP;
|
||||||
|
|
||||||
shadow_sprites_.at(0)->addPath(param.game.height + 10, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeInOutExpo, 0);
|
shadow_sprites_.at(0)->addPath(param.game.height + CARD_OFFSET_MARGIN, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0);
|
||||||
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeOutBounce, 0);
|
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0);
|
||||||
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 40, easeOutQuint, 0);
|
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0);
|
||||||
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 300, easeInOutExpo, 0);
|
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0);
|
||||||
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 70, easeOutElastic, 0);
|
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0);
|
||||||
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 250, easeOutQuad, 450);
|
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||||
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, 80, easeInElastic, 0);
|
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
@@ -405,47 +405,47 @@ void Intro::initTexts() {
|
|||||||
auto writer = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
|
auto writer = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
|
||||||
writer->setPosX(0);
|
writer->setPosX(0);
|
||||||
writer->setPosY(param.game.height - param.intro.text_distance_from_bottom);
|
writer->setPosY(param.game.height - param.intro.text_distance_from_bottom);
|
||||||
writer->setKerning(-2);
|
writer->setKerning(TEXT_KERNING);
|
||||||
writer->setEnabled(false);
|
writer->setEnabled(false);
|
||||||
writer->setFinishedCounter(180);
|
writer->setFinishedTimerMs(TEXT_DISPLAY_DURATION_MS);
|
||||||
texts_.push_back(std::move(writer));
|
texts_.push_back(std::move(writer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Un dia qualsevol de l'any 2000
|
// Un dia qualsevol de l'any 2000
|
||||||
texts_.at(0)->setCaption(Lang::getText("[INTRO] 1"));
|
texts_.at(0)->setCaption(Lang::getText("[INTRO] 1"));
|
||||||
texts_.at(0)->setSpeed(8);
|
texts_.at(0)->setSpeed(TEXT_SPEED_NORMAL);
|
||||||
|
|
||||||
// Tot esta tranquil a la UPV
|
// Tot esta tranquil a la UPV
|
||||||
texts_.at(1)->setCaption(Lang::getText("[INTRO] 2"));
|
texts_.at(1)->setCaption(Lang::getText("[INTRO] 2"));
|
||||||
texts_.at(1)->setSpeed(8);
|
texts_.at(1)->setSpeed(TEXT_SPEED_NORMAL);
|
||||||
|
|
||||||
// Fins que un desaprensiu...
|
// Fins que un desaprensiu...
|
||||||
texts_.at(2)->setCaption(Lang::getText("[INTRO] 3"));
|
texts_.at(2)->setCaption(Lang::getText("[INTRO] 3"));
|
||||||
texts_.at(2)->setSpeed(12);
|
texts_.at(2)->setSpeed(TEXT_SPEED_FAST);
|
||||||
|
|
||||||
// HEY! ME ANE A FERME UN CORTAET...
|
// HEY! ME ANE A FERME UN CORTAET...
|
||||||
texts_.at(3)->setCaption(Lang::getText("[INTRO] 4"));
|
texts_.at(3)->setCaption(Lang::getText("[INTRO] 4"));
|
||||||
texts_.at(3)->setSpeed(8);
|
texts_.at(3)->setSpeed(TEXT_SPEED_NORMAL);
|
||||||
|
|
||||||
// UAAAAAAAAAAAAA!!!
|
// UAAAAAAAAAAAAA!!!
|
||||||
texts_.at(4)->setCaption(Lang::getText("[INTRO] 5"));
|
texts_.at(4)->setCaption(Lang::getText("[INTRO] 5"));
|
||||||
texts_.at(4)->setSpeed(1);
|
texts_.at(4)->setSpeed(TEXT_SPEED_VERY_SLOW);
|
||||||
|
|
||||||
// Espera un moment...
|
// Espera un moment...
|
||||||
texts_.at(5)->setCaption(Lang::getText("[INTRO] 6"));
|
texts_.at(5)->setCaption(Lang::getText("[INTRO] 6"));
|
||||||
texts_.at(5)->setSpeed(16);
|
texts_.at(5)->setSpeed(TEXT_SPEED_VERY_FAST);
|
||||||
|
|
||||||
// Si resulta que no tinc solt!
|
// Si resulta que no tinc solt!
|
||||||
texts_.at(6)->setCaption(Lang::getText("[INTRO] 7"));
|
texts_.at(6)->setCaption(Lang::getText("[INTRO] 7"));
|
||||||
texts_.at(6)->setSpeed(2);
|
texts_.at(6)->setSpeed(TEXT_SPEED_SLOW);
|
||||||
|
|
||||||
// MERDA DE MAQUINA!
|
// MERDA DE MAQUINA!
|
||||||
texts_.at(7)->setCaption(Lang::getText("[INTRO] 8"));
|
texts_.at(7)->setCaption(Lang::getText("[INTRO] 8"));
|
||||||
texts_.at(7)->setSpeed(3);
|
texts_.at(7)->setSpeed(TEXT_SPEED_MEDIUM_SLOW);
|
||||||
|
|
||||||
// Blop... blop... blop...
|
// Blop... blop... blop...
|
||||||
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
|
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
|
||||||
texts_.at(8)->setSpeed(20);
|
texts_.at(8)->setSpeed(TEXT_SPEED_ULTRA_FAST);
|
||||||
|
|
||||||
for (auto &text : texts_) {
|
for (auto &text : texts_) {
|
||||||
text->center(param.game.game_area.center_x);
|
text->center(param.game.game_area.center_x);
|
||||||
@@ -489,8 +489,8 @@ void Intro::updatePostState() {
|
|||||||
|
|
||||||
switch (post_state_) {
|
switch (post_state_) {
|
||||||
case PostState::STOP_BG:
|
case PostState::STOP_BG:
|
||||||
// EVENTO: Detiene el fondo después de 1 segundo
|
// EVENTO: Detiene el fondo después del tiempo especificado
|
||||||
if (ELAPSED_TIME >= 1000) {
|
if (ELAPSED_TIME >= POST_BG_STOP_DELAY_MS) {
|
||||||
tiled_bg_->stopGracefully();
|
tiled_bg_->stopGracefully();
|
||||||
|
|
||||||
if (!bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
|
if (!bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
|
||||||
@@ -508,8 +508,8 @@ void Intro::updatePostState() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PostState::END:
|
case PostState::END:
|
||||||
// Finaliza la intro después de 1 segundo
|
// Finaliza la intro después del tiempo especificado
|
||||||
if (ELAPSED_TIME >= 1000) {
|
if (ELAPSED_TIME >= POST_END_DELAY_MS) {
|
||||||
Audio::get()->stopMusic();
|
Audio::get()->stopMusic();
|
||||||
Section::name = Section::Name::TITLE;
|
Section::name = Section::Name::TITLE;
|
||||||
Section::options = Section::Options::TITLE_1;
|
Section::options = Section::Options::TITLE_1;
|
||||||
|
|||||||
@@ -11,9 +11,22 @@
|
|||||||
#include "tiled_bg.h" // Para TiledBG
|
#include "tiled_bg.h" // Para TiledBG
|
||||||
#include "writer.h" // Para Writer
|
#include "writer.h" // Para Writer
|
||||||
|
|
||||||
// --- Clase Intro: muestra la secuencia de introducción ---
|
// --- Clase Intro: secuencia cinemática de introducción del juego ---
|
||||||
// Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
|
//
|
||||||
// de introducción.
|
// Esta clase gestiona la secuencia de introducción narrativa del juego, mostrando
|
||||||
|
// una serie de escenas con imágenes, texto y efectos visuales sincronizados.
|
||||||
|
//
|
||||||
|
// Funcionalidades principales:
|
||||||
|
// • Sistema de escenas secuencial: 6 escenas con transiciones automáticas
|
||||||
|
// • Animaciones de tarjetas: efectos de entrada con diferentes tipos de easing
|
||||||
|
// • Texto narrativo: velocidades de escritura configurables por escena
|
||||||
|
// • Efectos visuales: sombras, bordes y transiciones de color
|
||||||
|
// • Audio sincronizado: música de fondo durante toda la secuencia
|
||||||
|
// • Estado POST: transición suave hacia el menú principal
|
||||||
|
//
|
||||||
|
// Todas las duraciones y velocidades están configuradas mediante constantes
|
||||||
|
// para facilitar el ajuste fino de la experiencia cinematográfica.
|
||||||
|
|
||||||
class Intro {
|
class Intro {
|
||||||
public:
|
public:
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
@@ -24,6 +37,35 @@ class Intro {
|
|||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// --- Constantes de tiempo (en milisegundos) ---
|
||||||
|
static constexpr float TEXT_DISPLAY_DURATION_MS = 3000.0f; // Duración de visualización de texto (180 frames a 60fps)
|
||||||
|
static constexpr Uint32 POST_BG_STOP_DELAY_MS = 1000; // Retraso antes de detener el fondo
|
||||||
|
static constexpr Uint32 POST_END_DELAY_MS = 1000; // Retraso antes de finalizar intro
|
||||||
|
|
||||||
|
// --- Constantes de layout ---
|
||||||
|
static constexpr float CARD_BORDER_SIZE = 2.0f; // Tamaño del borde de tarjetas
|
||||||
|
static constexpr float SHADOW_OFFSET = 8.0f; // Desplazamiento de sombra
|
||||||
|
static constexpr int TEXT_KERNING = -2; // Espaciado entre caracteres
|
||||||
|
|
||||||
|
// --- Constantes de velocidades de texto ---
|
||||||
|
static constexpr int TEXT_SPEED_NORMAL = 8; // Velocidad normal de escritura
|
||||||
|
static constexpr int TEXT_SPEED_FAST = 12; // Velocidad rápida
|
||||||
|
static constexpr int TEXT_SPEED_VERY_SLOW = 1; // Velocidad muy lenta (grito)
|
||||||
|
static constexpr int TEXT_SPEED_VERY_FAST = 16; // Velocidad muy rápida
|
||||||
|
static constexpr int TEXT_SPEED_SLOW = 2; // Velocidad lenta
|
||||||
|
static constexpr int TEXT_SPEED_MEDIUM_SLOW = 3; // Velocidad medio-lenta
|
||||||
|
static constexpr int TEXT_SPEED_ULTRA_FAST = 20; // Velocidad ultra rápida
|
||||||
|
|
||||||
|
// --- Constantes de animaciones de tarjetas (duraciones en ms) ---
|
||||||
|
static constexpr int CARD_ANIM_DURATION_NORMAL = 100; // Duración estándar (100ms)
|
||||||
|
static constexpr int CARD_ANIM_DURATION_FAST = 40; // Duración rápida (40ms)
|
||||||
|
static constexpr int CARD_ANIM_DURATION_MEDIUM = 70; // Duración media (70ms)
|
||||||
|
static constexpr int CARD_ANIM_DURATION_SHORT = 80; // Duración corta (80ms)
|
||||||
|
static constexpr int CARD_ANIM_DURATION_SLOW = 250; // Duración lenta (250ms)
|
||||||
|
static constexpr int CARD_ANIM_DURATION_VERY_SLOW = 300; // Duración muy lenta (300ms)
|
||||||
|
static constexpr int CARD_ANIM_DELAY_LONG = 450; // Retraso largo antes de animación
|
||||||
|
static constexpr float CARD_OFFSET_MARGIN = 10.0f; // Margen fuera de pantalla
|
||||||
|
|
||||||
// --- Estados internos ---
|
// --- Estados internos ---
|
||||||
enum class State {
|
enum class State {
|
||||||
SCENES,
|
SCENES,
|
||||||
|
|||||||
@@ -28,38 +28,38 @@ Logo::Logo()
|
|||||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||||
since_sprite_->setPosition(SDL_FRect{
|
since_sprite_->setPosition(SDL_FRect{
|
||||||
static_cast<float>((param.game.width - since_texture_->getWidth()) / 2),
|
static_cast<float>((param.game.width - since_texture_->getWidth()) / 2),
|
||||||
static_cast<float>(83 + jail_texture_->getHeight() + 5),
|
static_cast<float>(SINCE_SPRITE_Y_OFFSET + jail_texture_->getHeight() + LOGO_SPACING),
|
||||||
static_cast<float>(since_texture_->getWidth()),
|
static_cast<float>(since_texture_->getWidth()),
|
||||||
static_cast<float>(since_texture_->getHeight())});
|
static_cast<float>(since_texture_->getHeight())});
|
||||||
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + LOGO_SPACING);
|
||||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||||
since_texture_->setColor(0x00, 0x00, 0x00);
|
since_texture_->setColor(SPECTRUM_BLACK.r, SPECTRUM_BLACK.g, SPECTRUM_BLACK.b);
|
||||||
|
|
||||||
// Crea los sprites de cada linea
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < jail_texture_->getHeight(); ++i) {
|
for (int i = 0; i < jail_texture_->getHeight(); ++i) {
|
||||||
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), SPRITE_LINE_HEIGHT);
|
||||||
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
temp->setSpriteClip(0, i, jail_texture_->getWidth(), SPRITE_LINE_HEIGHT);
|
||||||
const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
const int POS_X = (i % 2 == 0) ? param.game.width + (i * LINE_OFFSET_FACTOR) : -jail_texture_->getWidth() - (i * LINE_OFFSET_FACTOR);
|
||||||
temp->setX(POS_X);
|
temp->setX(POS_X);
|
||||||
temp->setY(dest_.y + i);
|
temp->setY(dest_.y + i);
|
||||||
jail_sprite_.push_back(std::move(temp));
|
jail_sprite_.push_back(std::move(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores con la paleta ZX Spectrum
|
||||||
color_.emplace_back(0x00, 0x00, 0x00); // Black
|
color_.emplace_back(SPECTRUM_BLACK);
|
||||||
color_.emplace_back(0x00, 0x00, 0xd8); // Blue
|
color_.emplace_back(SPECTRUM_BLUE);
|
||||||
color_.emplace_back(0xd8, 0x00, 0x00); // Red
|
color_.emplace_back(SPECTRUM_RED);
|
||||||
color_.emplace_back(0xd8, 0x00, 0xd8); // Magenta
|
color_.emplace_back(SPECTRUM_MAGENTA);
|
||||||
color_.emplace_back(0x00, 0xd8, 0x00); // Green
|
color_.emplace_back(SPECTRUM_GREEN);
|
||||||
color_.emplace_back(0x00, 0xd8, 0xd8); // Cyan
|
color_.emplace_back(SPECTRUM_CYAN);
|
||||||
color_.emplace_back(0xd8, 0xd8, 0x00); // Yellow
|
color_.emplace_back(SPECTRUM_YELLOW);
|
||||||
color_.emplace_back(0xFF, 0xFF, 0xFF); // Bright white
|
color_.emplace_back(SPECTRUM_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Logo::~Logo() {
|
Logo::~Logo() {
|
||||||
jail_texture_->setColor(255, 255, 255);
|
jail_texture_->setColor(RESET_COLOR.r, RESET_COLOR.g, RESET_COLOR.b);
|
||||||
since_texture_->setColor(255, 255, 255);
|
since_texture_->setColor(RESET_COLOR.r, RESET_COLOR.g, RESET_COLOR.b);
|
||||||
Audio::get()->stopAllSounds();
|
Audio::get()->stopAllSounds();
|
||||||
Audio::get()->stopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
@@ -78,24 +78,30 @@ void Logo::checkInput() {
|
|||||||
GlobalInputs::check();
|
GlobalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maneja la reproducción del sonido del logo
|
||||||
|
void Logo::handleSound() {
|
||||||
|
static bool sound_triggered = false;
|
||||||
|
|
||||||
|
if (!sound_triggered && elapsed_time_ms_ >= SOUND_TRIGGER_TIME_MS) {
|
||||||
|
Audio::get()->playSound("logo.wav");
|
||||||
|
sound_triggered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAMES
|
// Gestiona el logo de JAILGAMES
|
||||||
void Logo::updateJAILGAMES(float delta_time) {
|
void Logo::updateJAILGAMES(float delta_time) {
|
||||||
if (counter_ == 30) {
|
if (elapsed_time_ms_ > SOUND_TRIGGER_TIME_MS) {
|
||||||
Audio::get()->playSound("logo.wav");
|
const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_MS * delta_time;
|
||||||
}
|
|
||||||
|
|
||||||
if (counter_ > 30) {
|
for (size_t i = 0; i < jail_sprite_.size(); ++i) {
|
||||||
const float pixels_to_move = SPEED * delta_time;
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i) {
|
|
||||||
if (jail_sprite_[i]->getX() != dest_.x) {
|
if (jail_sprite_[i]->getX() != dest_.x) {
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
jail_sprite_[i]->incX(-pixels_to_move);
|
jail_sprite_[i]->incX(-PIXELS_TO_MOVE);
|
||||||
if (jail_sprite_[i]->getX() < dest_.x) {
|
if (jail_sprite_[i]->getX() < dest_.x) {
|
||||||
jail_sprite_[i]->setX(dest_.x);
|
jail_sprite_[i]->setX(dest_.x);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jail_sprite_[i]->incX(pixels_to_move);
|
jail_sprite_[i]->incX(PIXELS_TO_MOVE);
|
||||||
if (jail_sprite_[i]->getX() > dest_.x) {
|
if (jail_sprite_[i]->getX() > dest_.x) {
|
||||||
jail_sprite_[i]->setX(dest_.x);
|
jail_sprite_[i]->setX(dest_.x);
|
||||||
}
|
}
|
||||||
@@ -105,48 +111,41 @@ void Logo::updateJAILGAMES(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION) {
|
if (elapsed_time_ms_ >= END_LOGO_TIME_MS + POST_LOGO_DURATION_MS) {
|
||||||
Section::name = Section::Name::INTRO;
|
Section::name = Section::Name::INTRO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
void Logo::updateTextureColors() {
|
void Logo::updateTextureColors(float delta_time) {
|
||||||
constexpr int INC = 4;
|
|
||||||
|
|
||||||
// Manejo de 'sinceTexture'
|
// Manejo de 'sinceTexture'
|
||||||
for (int i = 0; i <= 7; ++i) {
|
for (int i = 0; i <= MAX_SINCE_COLOR_INDEX; ++i) {
|
||||||
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + INC * i) {
|
const float target_time = SHOW_SINCE_SPRITE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i;
|
||||||
|
if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) {
|
||||||
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
|
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
|
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
|
||||||
for (int i = 0; i <= 6; ++i) {
|
for (int i = 0; i <= MAX_FADE_COLOR_INDEX; ++i) {
|
||||||
if (counter_ == INIT_FADE_COUNTER_MARK + INC * i) {
|
const float target_time = INIT_FADE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i;
|
||||||
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
|
if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) {
|
||||||
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
|
jail_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
|
||||||
|
since_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void Logo::update(float delta_time) {
|
void Logo::update(float delta_time) {
|
||||||
static float logic_accumulator = 0.0f;
|
elapsed_time_ms_ += delta_time; // Acumula el tiempo transcurrido
|
||||||
logic_accumulator += delta_time;
|
|
||||||
|
|
||||||
// Ejecutar lógica a 60 FPS (cada 16.67ms) para mantener consistencia en counter_ y colores
|
|
||||||
constexpr float LOGIC_FRAME_TIME = 1000.0f / 60.0f;
|
|
||||||
|
|
||||||
if (logic_accumulator >= LOGIC_FRAME_TIME) {
|
|
||||||
Screen::get()->update(); // Actualiza el objeto screen
|
Screen::get()->update(); // Actualiza el objeto screen
|
||||||
updateTextureColors(); // Actualiza los colores de las texturas
|
Audio::update(); // Actualiza el objeto audio
|
||||||
++counter_; // Gestiona el contador
|
|
||||||
logic_accumulator -= LOGIC_FRAME_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateJAILGAMES(delta_time); // Actualiza el logo de JAILGAMES con delta-time real
|
handleSound(); // Maneja la reproducción del sonido
|
||||||
Audio::update();
|
updateTextureColors(delta_time); // Actualiza los colores de las texturas
|
||||||
|
updateJAILGAMES(delta_time); // Actualiza el logo de JAILGAMES
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
@@ -190,7 +189,7 @@ void Logo::renderJAILGAMES() {
|
|||||||
sprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK) {
|
if (elapsed_time_ms_ >= SHOW_SINCE_SPRITE_TIME_MS) {
|
||||||
since_sprite_->render();
|
since_sprite_->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,21 @@
|
|||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// --- Clase Logo: dibuja el logo de JAILGAMES con efectos visuales ---
|
// --- Clase Logo: pantalla de presentación de JAILGAMES con efectos retro ---
|
||||||
// Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
//
|
||||||
// logo de "JAILGAMES" utilizando un sencillo efecto consistente en generar un sprite por
|
// Esta clase gestiona el estado inicial del programa, mostrando el logo corporativo
|
||||||
// cada línea del bitmap que forma la palabra "JAILGAMES". Posteriormente realiza una
|
// de JAILGAMES con efectos visuales inspirados en el ZX Spectrum.
|
||||||
// modulación de color sobre la textura para simular un fade to black al estilo
|
//
|
||||||
// ZX Spectrum.
|
// Funcionalidades principales:
|
||||||
|
// • Animación de convergencia: cada línea del logo entra desde los laterales
|
||||||
|
// • Efectos de color: transiciones automáticas usando la paleta ZX Spectrum
|
||||||
|
// • Audio sincronizado: reproduce sonido del logo en momento específico
|
||||||
|
// • Transición temporal: duración controlada con paso automático al siguiente estado
|
||||||
|
// • Sistema delta-time: animaciones suaves independientes del framerate
|
||||||
|
//
|
||||||
|
// La clase utiliza un sistema de tiempo basado en milisegundos para garantizar
|
||||||
|
// consistencia visual en diferentes velocidades de procesamiento.
|
||||||
|
|
||||||
class Logo {
|
class Logo {
|
||||||
public:
|
public:
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
@@ -26,12 +35,35 @@ class Logo {
|
|||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes ---
|
// --- Constantes de tiempo (en milisegundos) ---
|
||||||
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
static constexpr float SOUND_TRIGGER_TIME_MS = 500.0f; // Tiempo para activar el sonido del logo
|
||||||
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
static constexpr float SHOW_SINCE_SPRITE_TIME_MS = 1167.0f; // Tiempo para mostrar el sprite "SINCE 1998"
|
||||||
static constexpr int END_LOGO_COUNTER_MARK = 400; // Tiempo del contador para terminar el logo
|
static constexpr float INIT_FADE_TIME_MS = 5000.0f; // Tiempo de inicio del fade a negro
|
||||||
static constexpr int POST_LOGO_DURATION = 20; // Tiempo que dura el logo con el fade al máximo
|
static constexpr float END_LOGO_TIME_MS = 6668.0f; // Tiempo de finalización del logo
|
||||||
static constexpr float SPEED = 8.0f / 15.0f; // Velocidad de desplazamiento de cada línea (píxeles por ms)
|
static constexpr float POST_LOGO_DURATION_MS = 333.0f; // Duración adicional después del fade
|
||||||
|
static constexpr float LOGO_SPEED_PX_PER_MS = 8.0f / 16.67f; // Velocidad de desplazamiento (píxeles por ms)
|
||||||
|
static constexpr float COLOR_CHANGE_INTERVAL_MS = 66.7f; // Intervalo entre cambios de color (~4 frames a 60fps)
|
||||||
|
|
||||||
|
// --- Constantes de layout ---
|
||||||
|
static constexpr int SINCE_SPRITE_Y_OFFSET = 83; // Posición Y base del sprite "Since 1998"
|
||||||
|
static constexpr int LOGO_SPACING = 5; // Espaciado entre elementos del logo
|
||||||
|
static constexpr int LINE_OFFSET_FACTOR = 3; // Factor de desplazamiento inicial por línea
|
||||||
|
static constexpr int SPRITE_LINE_HEIGHT = 1; // Altura de cada línea sprite
|
||||||
|
|
||||||
|
// --- Constantes de colores ---
|
||||||
|
static constexpr int MAX_SINCE_COLOR_INDEX = 7; // Índice máximo para colores del sprite "Since"
|
||||||
|
static constexpr int MAX_FADE_COLOR_INDEX = 6; // Índice máximo para colores del fade
|
||||||
|
|
||||||
|
// --- Paleta ZX Spectrum para efectos de logo ---
|
||||||
|
static constexpr Color SPECTRUM_BLACK = Color(0x00, 0x00, 0x00); // Negro
|
||||||
|
static constexpr Color SPECTRUM_BLUE = Color(0x00, 0x00, 0xd8); // Azul
|
||||||
|
static constexpr Color SPECTRUM_RED = Color(0xd8, 0x00, 0x00); // Rojo
|
||||||
|
static constexpr Color SPECTRUM_MAGENTA = Color(0xd8, 0x00, 0xd8); // Magenta
|
||||||
|
static constexpr Color SPECTRUM_GREEN = Color(0x00, 0xd8, 0x00); // Verde
|
||||||
|
static constexpr Color SPECTRUM_CYAN = Color(0x00, 0xd8, 0xd8); // Cian
|
||||||
|
static constexpr Color SPECTRUM_YELLOW = Color(0xd8, 0xd8, 0x00); // Amarillo
|
||||||
|
static constexpr Color SPECTRUM_WHITE = Color(0xFF, 0xFF, 0xFF); // Blanco brillante
|
||||||
|
static constexpr Color RESET_COLOR = Color(255, 255, 255); // Color de reset
|
||||||
|
|
||||||
// --- Objetos y punteros ---
|
// --- Objetos y punteros ---
|
||||||
std::shared_ptr<Texture> since_texture_; // Textura con los gráficos "Since 1998"
|
std::shared_ptr<Texture> since_texture_; // Textura con los gráficos "Since 1998"
|
||||||
@@ -41,7 +73,7 @@ class Logo {
|
|||||||
|
|
||||||
// --- Variables ---
|
// --- Variables ---
|
||||||
std::vector<Color> color_; // Vector con los colores para el fade
|
std::vector<Color> color_; // Vector con los colores para el fade
|
||||||
int counter_ = 0; // Contador
|
float elapsed_time_ms_ = 0.0f; // Tiempo transcurrido en milisegundos
|
||||||
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
||||||
SDL_FPoint dest_; // Posición donde dibujar el logo
|
SDL_FPoint dest_; // Posición donde dibujar el logo
|
||||||
|
|
||||||
@@ -52,6 +84,7 @@ class Logo {
|
|||||||
static void checkInput(); // Comprueba las entradas
|
static void checkInput(); // Comprueba las entradas
|
||||||
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAMES
|
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAMES
|
||||||
void renderJAILGAMES(); // Renderiza el logo de JAILGAMES
|
void renderJAILGAMES(); // Renderiza el logo de JAILGAMES
|
||||||
void updateTextureColors(); // Gestiona el color de las texturas
|
void updateTextureColors(float delta_time); // Gestiona el color de las texturas
|
||||||
|
void handleSound(); // Maneja la reproducción del sonido del logo
|
||||||
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Title::Title()
|
|||||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
|
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
|
||||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||||
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
||||||
state_(TitleState::LOGO_ANIMATING),
|
state_(State::LOGO_ANIMATING),
|
||||||
num_controllers_(Input::get()->getNumGamepads()) {
|
num_controllers_(Input::get()->getNumGamepads()) {
|
||||||
// Configura objetos
|
// Configura objetos
|
||||||
tiled_bg_->setColor(param.title.bg_color);
|
tiled_bg_->setColor(param.title.bg_color);
|
||||||
@@ -60,16 +60,16 @@ Title::Title()
|
|||||||
Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO;
|
Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
|
||||||
// Define los anclajes de los elementos
|
// Define los anclajes de los elementos
|
||||||
anchor_.mini_logo = (param.game.height / 5 * 4) + BLOCK;
|
anchor_.mini_logo = (param.game.height / MINI_LOGO_Y_DIVISOR * MINI_LOGO_Y_FACTOR) + BLOCK;
|
||||||
mini_logo_sprite_->setY(anchor_.mini_logo);
|
mini_logo_sprite_->setY(anchor_.mini_logo);
|
||||||
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + 3;
|
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + COPYRIGHT_TEXT_SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Title::~Title() {
|
Title::~Title() {
|
||||||
Audio::get()->stopAllSounds();
|
Audio::get()->stopAllSounds();
|
||||||
if (Section::name == Section::Name::LOGO) {
|
if (Section::name == Section::Name::LOGO) {
|
||||||
Audio::get()->fadeOutMusic(300);
|
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_SHORT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desregistra los jugadores de Options
|
// Desregistra los jugadores de Options
|
||||||
@@ -77,22 +77,7 @@ Title::~Title() {
|
|||||||
Options::gamepad_manager.clearPlayers();
|
Options::gamepad_manager.clearPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto (frame-based)
|
// Actualiza las variables del objeto
|
||||||
void Title::update() {
|
|
||||||
if (SDL_GetTicks() - last_time_ > param.game.speed) {
|
|
||||||
last_time_ = SDL_GetTicks();
|
|
||||||
Screen::get()->update();
|
|
||||||
|
|
||||||
updateFade();
|
|
||||||
updateState();
|
|
||||||
updateStartPrompt();
|
|
||||||
updatePlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
Audio::update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables del objeto (time-based)
|
|
||||||
void Title::update(float deltaTime) {
|
void Title::update(float deltaTime) {
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
updateFade();
|
updateFade();
|
||||||
@@ -100,7 +85,7 @@ void Title::update(float deltaTime) {
|
|||||||
updateStartPrompt();
|
updateStartPrompt();
|
||||||
|
|
||||||
for (auto& player : players_) {
|
for (auto& player : players_) {
|
||||||
player->update(deltaTime); // deltaTime ya está en segundos
|
player->update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::update();
|
Audio::update();
|
||||||
@@ -292,7 +277,7 @@ void Title::handleStartButtonPress(const Options::Gamepad* controller) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto Title::canProcessStartButton() const -> bool {
|
auto Title::canProcessStartButton() const -> bool {
|
||||||
return (state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP);
|
return (state_ != State::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Title::processPlayer1Start() {
|
void Title::processPlayer1Start() {
|
||||||
@@ -311,7 +296,7 @@ void Title::processPlayer2Start() {
|
|||||||
|
|
||||||
void Title::activatePlayerAndSetState(Player::Id player_id) {
|
void Title::activatePlayerAndSetState(Player::Id player_id) {
|
||||||
getPlayer(player_id)->setPlayingState(Player::State::TITLE_ANIMATION);
|
getPlayer(player_id)->setPlayingState(Player::State::TITLE_ANIMATION);
|
||||||
setState(TitleState::START_HAS_BEEN_PRESSED);
|
setState(State::START_HAS_BEEN_PRESSED);
|
||||||
counter_time_ = 0.0f;
|
counter_time_ = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,59 +377,22 @@ void Title::updateFade() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado
|
// Actualiza el estado
|
||||||
void Title::updateState() {
|
|
||||||
// Establece la lógica según el estado
|
|
||||||
switch (state_) {
|
|
||||||
case TitleState::LOGO_ANIMATING: {
|
|
||||||
game_logo_->update(); // Mantener frame-based para consistencia del estado
|
|
||||||
if (game_logo_->hasFinished()) {
|
|
||||||
setState(TitleState::LOGO_FINISHED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TitleState::LOGO_FINISHED: {
|
|
||||||
// Ya no se usa counter_ aquí, se usa updateState(deltaTime)
|
|
||||||
game_logo_->update();
|
|
||||||
tiled_bg_->update();
|
|
||||||
|
|
||||||
// Esta lógica se movió a updateState(deltaTime)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TitleState::START_HAS_BEEN_PRESSED: {
|
|
||||||
// Ya no se usa counter_ aquí, se usa updateState(deltaTime)
|
|
||||||
game_logo_->update();
|
|
||||||
tiled_bg_->update();
|
|
||||||
|
|
||||||
// Esta lógica se movió a updateState(deltaTime)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado (time-based)
|
|
||||||
void Title::updateState(float deltaTime) {
|
void Title::updateState(float deltaTime) {
|
||||||
// deltaTime ya está en segundos desde calculateDeltaTime()
|
|
||||||
game_logo_->update(deltaTime);
|
game_logo_->update(deltaTime);
|
||||||
tiled_bg_->update(deltaTime);
|
tiled_bg_->update(deltaTime);
|
||||||
|
|
||||||
// Establece la lógica según el estado
|
// Establece la lógica según el estado
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case TitleState::LOGO_ANIMATING: {
|
case State::LOGO_ANIMATING: {
|
||||||
if (game_logo_->hasFinished()) {
|
if (game_logo_->hasFinished()) {
|
||||||
setState(TitleState::LOGO_FINISHED);
|
setState(State::LOGO_FINISHED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TitleState::LOGO_FINISHED: {
|
case State::LOGO_FINISHED: {
|
||||||
counter_time_ += deltaTime; // deltaTime está en milisegundos
|
counter_time_ += deltaTime;
|
||||||
|
|
||||||
// param.title.title_duration está en frames (60fps), convertir a ms: frames * (1000ms/60fps)
|
if (counter_time_ >= param.title.title_duration) {
|
||||||
float duration_ms = static_cast<float>(param.title.title_duration) * (1000.0f / 60.0f);
|
|
||||||
|
|
||||||
if (counter_time_ >= duration_ms) {
|
|
||||||
// El menu ha hecho time out
|
// El menu ha hecho time out
|
||||||
fade_->setPostDuration(0);
|
fade_->setPostDuration(0);
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
@@ -452,11 +400,10 @@ void Title::updateState(float deltaTime) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TitleState::START_HAS_BEEN_PRESSED: {
|
case State::START_HAS_BEEN_PRESSED: {
|
||||||
counter_time_ += deltaTime; // deltaTime está en milisegundos
|
counter_time_ += deltaTime;
|
||||||
|
|
||||||
// 100 frames a 60fps convertir a ms: 100 * (1000/60) = 1666.67 ms
|
if (counter_time_ >= START_PRESSED_DELAY_MS) {
|
||||||
if (counter_time_ >= (100.0f * 1000.0f / 60.0f)) {
|
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -468,22 +415,16 @@ void Title::updateState(float deltaTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Title::updateStartPrompt() {
|
void Title::updateStartPrompt() {
|
||||||
constexpr Uint32 LOGO_BLINK_PERIOD = 833; // milisegundos
|
|
||||||
constexpr Uint32 LOGO_BLINK_ON_TIME = 583; // 833 - 250
|
|
||||||
|
|
||||||
constexpr Uint32 START_BLINK_PERIOD = 167;
|
|
||||||
constexpr Uint32 START_BLINK_ON_TIME = 83; // 167 - 83
|
|
||||||
|
|
||||||
Uint32 time_ms = SDL_GetTicks();
|
Uint32 time_ms = SDL_GetTicks();
|
||||||
bool condition_met = false;
|
bool condition_met = false;
|
||||||
|
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case TitleState::LOGO_FINISHED:
|
case State::LOGO_FINISHED:
|
||||||
condition_met = (time_ms % LOGO_BLINK_PERIOD) >= (LOGO_BLINK_PERIOD - LOGO_BLINK_ON_TIME);
|
condition_met = (time_ms % LOGO_BLINK_PERIOD_MS) >= (LOGO_BLINK_PERIOD_MS - LOGO_BLINK_ON_TIME_MS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TitleState::START_HAS_BEEN_PRESSED:
|
case State::START_HAS_BEEN_PRESSED:
|
||||||
condition_met = (time_ms % START_BLINK_PERIOD) >= (START_BLINK_PERIOD - START_BLINK_ON_TIME);
|
condition_met = (time_ms % START_BLINK_PERIOD_MS) >= (START_BLINK_PERIOD_MS - START_BLINK_ON_TIME_MS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -507,7 +448,7 @@ void Title::renderStartPrompt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Title::renderCopyright() {
|
void Title::renderCopyright() {
|
||||||
if (state_ != TitleState::LOGO_ANIMATING) {
|
if (state_ != State::LOGO_ANIMATING) {
|
||||||
// Mini logo
|
// Mini logo
|
||||||
mini_logo_sprite_->render();
|
mini_logo_sprite_->render();
|
||||||
|
|
||||||
@@ -524,20 +465,20 @@ void Title::renderCopyright() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el estado
|
// Cambia el estado
|
||||||
void Title::setState(TitleState state) {
|
void Title::setState(State state) {
|
||||||
if (state_ == state) {
|
if (state_ == state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state_ = state;
|
state_ = state;
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case TitleState::LOGO_ANIMATING:
|
case State::LOGO_ANIMATING:
|
||||||
break;
|
break;
|
||||||
case TitleState::LOGO_FINISHED:
|
case State::LOGO_FINISHED:
|
||||||
Audio::get()->playMusic("title.ogg");
|
Audio::get()->playMusic("title.ogg");
|
||||||
break;
|
break;
|
||||||
case TitleState::START_HAS_BEEN_PRESSED:
|
case State::START_HAS_BEEN_PRESSED:
|
||||||
Audio::get()->fadeOutMusic(1500);
|
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,13 +547,6 @@ void Title::initPlayers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los jugadores
|
|
||||||
void Title::updatePlayers() {
|
|
||||||
for (auto& player : players_) {
|
|
||||||
player->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderiza los jugadores
|
// Renderiza los jugadores
|
||||||
void Title::renderPlayers() {
|
void Title::renderPlayers() {
|
||||||
for (auto const& player : players_) {
|
for (auto const& player : players_) {
|
||||||
|
|||||||
@@ -19,11 +19,22 @@ namespace Options {
|
|||||||
struct Gamepad;
|
struct Gamepad;
|
||||||
} // namespace Options
|
} // namespace Options
|
||||||
|
|
||||||
// --- Constantes ---
|
// --- Clase Title: pantalla de título y menú principal del juego ---
|
||||||
constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner"; // Texto de copyright
|
//
|
||||||
constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false; // Permite saltar la animación del título
|
// Esta clase gestiona la pantalla de título del juego, incluyendo el menú principal
|
||||||
|
// y la transición entre diferentes modos de juego.
|
||||||
// --- Clase Title: gestiona el estado de título/menú principal del juego ---
|
//
|
||||||
|
// Funcionalidades principales:
|
||||||
|
// • Logo animado: muestra y anima el logotipo principal del juego
|
||||||
|
// • Selección de jugadores: permite iniciar partidas de 1 o 2 jugadores
|
||||||
|
// • Modo attract: cicla automáticamente entre título y demo
|
||||||
|
// • Efectos visuales: parpadeos, transiciones y efectos de fondo
|
||||||
|
// • Gestión de controles: soporte para teclado y múltiples gamepads
|
||||||
|
// • Timeouts automáticos: transición automática si no hay interacción
|
||||||
|
// • Debug de colores: herramientas de depuración para ajustes visuales
|
||||||
|
//
|
||||||
|
// La clase utiliza un sistema de tiempo basado en milisegundos para garantizar
|
||||||
|
// comportamiento consistente independientemente del framerate.
|
||||||
class Title {
|
class Title {
|
||||||
public:
|
public:
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
@@ -34,8 +45,28 @@ class Title {
|
|||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// --- Constantes de tiempo (en milisegundos) ---
|
||||||
|
static constexpr float START_PRESSED_DELAY_MS = 1666.67f; // Tiempo antes de fade tras pulsar start (100 frames a 60fps)
|
||||||
|
static constexpr int MUSIC_FADE_OUT_LONG_MS = 1500; // Fade out largo de música
|
||||||
|
static constexpr int MUSIC_FADE_OUT_SHORT_MS = 300; // Fade out corto de música
|
||||||
|
|
||||||
|
// --- Constantes de parpadeo ---
|
||||||
|
static constexpr Uint32 LOGO_BLINK_PERIOD_MS = 833; // Período de parpadeo del logo
|
||||||
|
static constexpr Uint32 LOGO_BLINK_ON_TIME_MS = 583; // Tiempo encendido del logo (833-250)
|
||||||
|
static constexpr Uint32 START_BLINK_PERIOD_MS = 167; // Período de parpadeo del start
|
||||||
|
static constexpr Uint32 START_BLINK_ON_TIME_MS = 83; // Tiempo encendido del start (167-83)
|
||||||
|
|
||||||
|
// --- Constantes de layout ---
|
||||||
|
static constexpr int MINI_LOGO_Y_DIVISOR = 5; // Divisor para posición Y del mini logo
|
||||||
|
static constexpr int MINI_LOGO_Y_FACTOR = 4; // Factor para posición Y del mini logo
|
||||||
|
static constexpr int COPYRIGHT_TEXT_SPACING = 3; // Espaciado del texto de copyright
|
||||||
|
|
||||||
|
// --- Constantes de texto y configuración ---
|
||||||
|
static constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner"; // Texto de copyright
|
||||||
|
static constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false; // Permite saltar la animación del título
|
||||||
|
|
||||||
// --- Enums ---
|
// --- Enums ---
|
||||||
enum class TitleState {
|
enum class State {
|
||||||
LOGO_ANIMATING, // El logo está animándose
|
LOGO_ANIMATING, // El logo está animándose
|
||||||
LOGO_FINISHED, // El logo ha terminado de animarse
|
LOGO_FINISHED, // El logo ha terminado de animarse
|
||||||
START_HAS_BEEN_PRESSED, // Se ha pulsado el botón de start
|
START_HAS_BEEN_PRESSED, // Se ha pulsado el botón de start
|
||||||
@@ -59,7 +90,7 @@ class Title {
|
|||||||
Anchor anchor_; // Anclas para definir la posición de los elementos del título
|
Anchor anchor_; // Anclas para definir la posición de los elementos del título
|
||||||
Section::Name next_section_; // Siguiente sección a cargar
|
Section::Name next_section_; // Siguiente sección a cargar
|
||||||
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
|
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
|
||||||
TitleState state_; // Estado actual de la sección
|
State state_; // Estado actual de la sección
|
||||||
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
||||||
float counter_time_ = 0.0f; // Temporizador para la pantalla de título (en milisegundos)
|
float counter_time_ = 0.0f; // Temporizador para la pantalla de título (en milisegundos)
|
||||||
int num_controllers_; // Número de mandos conectados
|
int num_controllers_; // Número de mandos conectados
|
||||||
@@ -68,12 +99,10 @@ class Title {
|
|||||||
bool player2_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 2
|
bool player2_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 2
|
||||||
|
|
||||||
// --- Ciclo de vida del título ---
|
// --- Ciclo de vida del título ---
|
||||||
void update(); // Actualiza las variables del objeto (frame-based)
|
void update(float deltaTime); // Actualiza las variables del objeto
|
||||||
void update(float deltaTime); // Actualiza las variables del objeto (time-based)
|
|
||||||
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
||||||
void updateState(); // Actualiza el estado actual del título (frame-based)
|
void updateState(float deltaTime); // Actualiza el estado actual del título
|
||||||
void updateState(float deltaTime); // Actualiza el estado actual del título (time-based)
|
void setState(State state); // Cambia el estado del título
|
||||||
void setState(TitleState state); // Cambia el estado del título
|
|
||||||
void resetCounter(); // Reinicia el contador interno
|
void resetCounter(); // Reinicia el contador interno
|
||||||
|
|
||||||
// --- Entrada de usuario ---
|
// --- Entrada de usuario ---
|
||||||
|
|||||||
@@ -2,15 +2,6 @@
|
|||||||
|
|
||||||
#include "moving_sprite.h" // Para MovingSprite
|
#include "moving_sprite.h" // Para MovingSprite
|
||||||
|
|
||||||
// Actualiza la posición y comprueba si ha llegado a su destino (frame-based)
|
|
||||||
void SmartSprite::update() {
|
|
||||||
if (enabled_) {
|
|
||||||
MovingSprite::update();
|
|
||||||
checkMove();
|
|
||||||
checkFinished();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
// Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
||||||
void SmartSprite::update(float deltaTime) {
|
void SmartSprite::update(float deltaTime) {
|
||||||
if (enabled_) {
|
if (enabled_) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class SmartSprite : public AnimatedSprite {
|
|||||||
~SmartSprite() override = default;
|
~SmartSprite() override = default;
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update() override; // Actualiza la posición y comprueba si ha llegado a su destino (frame-based)
|
|
||||||
void update(float deltaTime) override; // Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
void update(float deltaTime) override; // Actualiza la posición y comprueba si ha llegado a su destino (time-based)
|
||||||
void render() override; // Dibuja el sprite
|
void render() override; // Dibuja el sprite
|
||||||
|
|
||||||
|
|||||||
@@ -17,20 +17,6 @@ Tabe::Tabe()
|
|||||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))),
|
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))),
|
||||||
timer_(Timer(param.tabe.min_spawn_time, param.tabe.max_spawn_time)) {}
|
timer_(Timer(param.tabe.min_spawn_time, param.tabe.max_spawn_time)) {}
|
||||||
|
|
||||||
// Actualiza la lógica (frame-based)
|
|
||||||
void Tabe::update() {
|
|
||||||
if (enabled_ && !timer_.is_paused) {
|
|
||||||
sprite_->update();
|
|
||||||
move();
|
|
||||||
updateState();
|
|
||||||
}
|
|
||||||
|
|
||||||
timer_.update();
|
|
||||||
if (timer_.shouldSpawn()) {
|
|
||||||
enable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la lógica (time-based)
|
// Actualiza la lógica (time-based)
|
||||||
void Tabe::update(float deltaTime) {
|
void Tabe::update(float deltaTime) {
|
||||||
if (enabled_ && !timer_.is_paused) {
|
if (enabled_ && !timer_.is_paused) {
|
||||||
@@ -52,71 +38,6 @@ void Tabe::render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el objeto (frame-based)
|
|
||||||
void Tabe::move() {
|
|
||||||
const int X = static_cast<int>(x_);
|
|
||||||
speed_ += accel_;
|
|
||||||
x_ += speed_;
|
|
||||||
fly_distance_ -= std::abs(X - static_cast<int>(x_));
|
|
||||||
|
|
||||||
// Comprueba si sale por los bordes
|
|
||||||
const float MIN_X = param.game.game_area.rect.x - WIDTH;
|
|
||||||
const float MAX_X = param.game.game_area.rect.x + param.game.game_area.rect.w;
|
|
||||||
switch (destiny_) {
|
|
||||||
case Direction::TO_THE_LEFT: {
|
|
||||||
if (x_ < MIN_X) {
|
|
||||||
disable();
|
|
||||||
}
|
|
||||||
if (x_ > param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH && direction_ == Direction::TO_THE_RIGHT) {
|
|
||||||
setRandomFlyPath(Direction::TO_THE_LEFT, 80);
|
|
||||||
x_ = param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Direction::TO_THE_RIGHT: {
|
|
||||||
if (x_ > MAX_X) {
|
|
||||||
disable();
|
|
||||||
}
|
|
||||||
if (x_ < param.game.game_area.rect.x && direction_ == Direction::TO_THE_LEFT) {
|
|
||||||
setRandomFlyPath(Direction::TO_THE_RIGHT, 80);
|
|
||||||
x_ = param.game.game_area.rect.x;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fly_distance_ <= 0) {
|
|
||||||
if (waiting_counter_ > 0) {
|
|
||||||
accel_ = speed_ = 0.0F;
|
|
||||||
--waiting_counter_;
|
|
||||||
} else {
|
|
||||||
constexpr int CHOICES = 4;
|
|
||||||
const std::array<Direction, CHOICES> LEFT = {
|
|
||||||
Direction::TO_THE_LEFT,
|
|
||||||
Direction::TO_THE_LEFT,
|
|
||||||
Direction::TO_THE_LEFT,
|
|
||||||
Direction::TO_THE_RIGHT};
|
|
||||||
|
|
||||||
const std::array<Direction, CHOICES> RIGHT = {
|
|
||||||
Direction::TO_THE_LEFT,
|
|
||||||
Direction::TO_THE_RIGHT,
|
|
||||||
Direction::TO_THE_RIGHT,
|
|
||||||
Direction::TO_THE_RIGHT};
|
|
||||||
|
|
||||||
const Direction DIRECTION = destiny_ == Direction::TO_THE_LEFT
|
|
||||||
? LEFT[rand() % CHOICES]
|
|
||||||
: RIGHT[rand() % CHOICES];
|
|
||||||
|
|
||||||
setRandomFlyPath(DIRECTION, 20 + (rand() % 40));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shiftSprite();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mueve el objeto (time-based)
|
// Mueve el objeto (time-based)
|
||||||
void Tabe::move(float deltaTime) {
|
void Tabe::move(float deltaTime) {
|
||||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||||
@@ -258,16 +179,6 @@ void Tabe::setState(State state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado (frame-based)
|
|
||||||
void Tabe::updateState() {
|
|
||||||
if (state_ == State::HIT) {
|
|
||||||
--hit_counter_;
|
|
||||||
if (hit_counter_ <= 0) {
|
|
||||||
setState(State::FLY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado (time-based)
|
// Actualiza el estado (time-based)
|
||||||
void Tabe::updateState(float deltaTime) {
|
void Tabe::updateState(float deltaTime) {
|
||||||
if (state_ == State::HIT) {
|
if (state_ == State::HIT) {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class Tabe {
|
|||||||
~Tabe() = default;
|
~Tabe() = default;
|
||||||
|
|
||||||
// --- Métodos principales ---
|
// --- Métodos principales ---
|
||||||
void update(); // Actualiza la lógica (frame-based)
|
|
||||||
void update(float deltaTime); // Actualiza la lógica (time-based)
|
void update(float deltaTime); // Actualiza la lógica (time-based)
|
||||||
void render(); // Dibuja el objeto
|
void render(); // Dibuja el objeto
|
||||||
void enable(); // Habilita el objeto
|
void enable(); // Habilita el objeto
|
||||||
@@ -142,11 +141,9 @@ class Tabe {
|
|||||||
Timer timer_; // Temporizador para gestionar la aparición
|
Timer timer_; // Temporizador para gestionar la aparición
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void move(); // Mueve el objeto (frame-based)
|
|
||||||
void move(float deltaTime); // Mueve el objeto (time-based)
|
void move(float deltaTime); // Mueve el objeto (time-based)
|
||||||
void shiftSprite() { sprite_->setPos(x_, y_); } // Actualiza la posición del sprite
|
void shiftSprite() { sprite_->setPos(x_, y_); } // Actualiza la posición del sprite
|
||||||
void setRandomFlyPath(Direction direction, int length); // Establece un vuelo aleatorio
|
void setRandomFlyPath(Direction direction, int length); // Establece un vuelo aleatorio
|
||||||
void updateState(); // Actualiza el estado (frame-based)
|
|
||||||
void updateState(float deltaTime); // Actualiza el estado (time-based)
|
void updateState(float deltaTime); // Actualiza el estado (time-based)
|
||||||
void updateTimer(); // Actualiza el temporizador
|
void updateTimer(); // Actualiza el temporizador
|
||||||
void disable(); // Deshabilita el objeto
|
void disable(); // Deshabilita el objeto
|
||||||
|
|||||||
@@ -70,11 +70,9 @@ auto Writer::isEnabled() const -> bool {
|
|||||||
return enabled_;
|
return enabled_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el temporizador para deshabilitar el objeto (en milisegundos)
|
||||||
void Writer::setFinishedCounter(int time) {
|
void Writer::setFinishedTimerMs(float time_ms) {
|
||||||
// Convierte frames a milisegundos (frames * 16.67ms)
|
enabled_timer_target_ = time_ms;
|
||||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
|
|
||||||
enabled_timer_target_ = static_cast<float>(time) * FRAME_TIME_MS;
|
|
||||||
enabled_timer_ = 0.0f;
|
enabled_timer_ = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class Writer {
|
|||||||
void setCaption(const std::string &text); // Establece el texto a escribir
|
void setCaption(const std::string &text); // Establece el texto a escribir
|
||||||
void setSpeed(int value); // Establece la velocidad de escritura
|
void setSpeed(int value); // Establece la velocidad de escritura
|
||||||
void setEnabled(bool value); // Habilita o deshabilita el objeto
|
void setEnabled(bool value); // Habilita o deshabilita el objeto
|
||||||
void setFinishedCounter(int time); // Establece el temporizador para deshabilitar el objeto
|
void setFinishedTimerMs(float time_ms); // Establece el temporizador para deshabilitar el objeto (en ms)
|
||||||
|
|
||||||
void center(int x); // Centra la cadena de texto a un punto X
|
void center(int x); // Centra la cadena de texto a un punto X
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user