Afegit el disparador per a la aparició del enemic nou

This commit is contained in:
2025-02-06 09:59:58 +01:00
parent 5755947ff7
commit ccf005dce1
2 changed files with 92 additions and 13 deletions

View File

@@ -1,8 +1,9 @@
#pragma once
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <memory> // Para unique_ptr
#include "animated_sprite.h" // Para AnimatedSprite
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL.h>
#include <memory> // Para unique_ptr
#include "animated_sprite.h" // Para AnimatedSprite
enum class TabeDirection : int
{
@@ -16,6 +17,55 @@ enum class TabeState : int
HIT = 1,
};
struct TabeTimer
{
Uint32 time_until_next_spawn; // Tiempo restante para la próxima aparición
Uint32 min_spawn_time; // Tiempo mínimo entre apariciones
Uint32 max_spawn_time; // Tiempo máximo entre apariciones
Uint32 current_time; // Tiempo actual
Uint32 delta_time; // Diferencia de tiempo desde la última actualización
Uint32 last_time; // Tiempo de la última actualización
// Constructor
TabeTimer(float minTime, float maxTime)
: min_spawn_time(minTime * 60000), max_spawn_time(maxTime * 60000)
{
current_time = SDL_GetTicks();
reset();
}
// Restablece el temporizador con un nuevo tiempo hasta la próxima aparición
void reset()
{
Uint32 range = max_spawn_time - min_spawn_time;
time_until_next_spawn = min_spawn_time + rand() % (range + 1);
last_time = SDL_GetTicks();
}
// Actualiza el temporizador, decrementando el tiempo hasta la próxima aparición
void update()
{
current_time = SDL_GetTicks();
delta_time = current_time - last_time;
last_time = current_time;
if (time_until_next_spawn > delta_time)
{
time_until_next_spawn -= delta_time;
}
else
{
time_until_next_spawn = 0;
}
}
// Indica si el temporizador ha finalizado
bool should_spawn() const
{
return time_until_next_spawn == 0;
}
};
// Clase Tabe
class Tabe
{
@@ -41,6 +91,7 @@ private:
int hit_counter_ = 0; // Contador para el estado HIT
int number_of_hits_ = 0; // Cantidad de disparos que ha recibido
bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar
TabeTimer timer_; // Temporizador para gestionar la aparición del Tabe
// Mueve el objeto
void move();
@@ -54,6 +105,12 @@ private:
// Actualiza el estado
void updateState();
// Actualiza el temporizador
void updateTimer();
// Deshabilita el objeto
void disable();
public:
// Constructor
Tabe();