nou: bales de colors diferents per a cada jugador

This commit is contained in:
2025-09-26 20:37:00 +02:00
parent 0459b39366
commit 83871273ec
9 changed files with 118 additions and 39 deletions

View File

@@ -33,10 +33,27 @@ auto Bullet::calculateVelocity(Type type) -> float {
}
}
// Construye el string de animación basado en el tipo de bala y si está potenciada
// Construye el string de animación basado en el tipo de bala y color específico
auto Bullet::buildAnimationString(Type type, Color color) -> std::string {
std::string animation_string = color == Color::GREEN ? "powered_" : "normal_";
std::string animation_string;
// Mapear color a string específico
switch (color) {
case Color::YELLOW:
animation_string = "yellow_";
break;
case Color::GREEN:
animation_string = "green_";
break;
case Color::RED:
animation_string = "red_";
break;
case Color::PURPLE:
animation_string = "purple_";
break;
}
// Añadir dirección
switch (type) {
case Type::UP:
animation_string += "up";

View File

@@ -30,7 +30,9 @@ class Bullet {
enum class Color : Uint8 {
YELLOW,
GREEN
GREEN,
RED,
PURPLE
};
// --- Constructor y destructor ---

View File

@@ -774,7 +774,7 @@ void Player::updatePowerUp(float deltaTime) {
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
bullet_color_ = Bullet::Color::YELLOW;
// Los colores ahora se manejan dinámicamente en getNextBulletColor()
} else {
// Calcular visibilidad del power sprite
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f;
@@ -784,7 +784,6 @@ void Player::updatePowerUp(float deltaTime) {
// En los primeros 75% del tiempo, siempre visible
power_sprite_visible_ = true;
in_power_up_ending_phase_ = false;
bullet_color_ = Bullet::Color::GREEN;
} else {
// En el último 25%, parpadea cada 20 frames (≈0.333s)
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f;
@@ -793,14 +792,12 @@ void Player::updatePowerUp(float deltaTime) {
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
power_sprite_visible_ = cycle_position >= VISIBLE_PROPORTION;
in_power_up_ending_phase_ = true; // Activar modo alternancia de colores de balas
bullet_color_ = power_sprite_visible_ ? Bullet::Color::GREEN : Bullet::Color::YELLOW;
}
}
} else {
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
bullet_color_ = Bullet::Color::YELLOW;
}
}
}
@@ -935,15 +932,26 @@ auto Player::isRenderable() const -> bool {
return !isTitleHidden();
};
// Devuelve el color actual de bala según el estado
auto Player::getBulletColor() const -> Bullet::Color {
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Devuelve el color para la próxima bala (alterna si está en modo toggle)
auto Player::getNextBulletColor() -> Bullet::Color {
if (in_power_up_ending_phase_) {
// En fase final: alternar entre verde y amarillo
// En fase final: alternar entre colores powered y normal
bullet_color_toggle_ = !bullet_color_toggle_;
return bullet_color_toggle_ ? Bullet::Color::GREEN : Bullet::Color::YELLOW;
return bullet_color_toggle_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Modo normal: sin power-up = amarillo, con power-up = verde
return bullet_color_;
// Modo normal: sin power-up = normal_color, con power-up = powered_color
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Establece los colores de bala para este jugador
void Player::setBulletColors(Bullet::Color normal, Bullet::Color powered) {
bullet_colors_.normal_color = normal;
bullet_colors_.powered_color = powered;
}
// Añade una puntuación a la tabla de records

View File

@@ -39,6 +39,12 @@ class Player {
static constexpr int WIDTH = 32; // Anchura
static constexpr int HEIGHT = 32; // Altura
// --- Estructuras ---
struct BulletColorPair {
Bullet::Color normal_color; // Color de bala sin power-up
Bullet::Color powered_color; // Color de bala con power-up
};
// --- Enums ---
enum class Id : int {
NO_PLAYER = -1, // Sin jugador
@@ -134,7 +140,7 @@ class Player {
void setPlayingState(State state); // Cambia el estado de juego
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
void setPowerUp(); // Activa el modo PowerUp
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp (time-based)
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp
void giveExtraHit(); // Concede un toque extra al jugador
void removeExtraHit(); // Quita el toque extra al jugador
void decContinueCounter(); // Decrementa el contador de continuar
@@ -190,8 +196,9 @@ class Player {
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
[[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; }
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
[[nodiscard]] auto getBulletColor() const -> Bullet::Color { return bullet_color_; }
[[nodiscard]] auto getBulletColor() const -> Bullet::Color; // Devuelve el color actual de bala según el estado
auto getNextBulletColor() -> Bullet::Color; // Devuelve el color para la próxima bala (alterna si está en modo toggle)
void setBulletColors(Bullet::Color normal, Bullet::Color powered); // Establece los colores de bala para este jugador
// Contadores y timers
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
@@ -249,7 +256,7 @@ class Player {
State walking_state_ = State::WALKING_STOP; // Estado del jugador al moverse
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
State playing_state_ = State::WAITING; // Estado del jugador en el juego
Bullet::Color bullet_color_ = Bullet::Color::YELLOW; // Color de la bala del jugador
BulletColorPair bullet_colors_ = {Bullet::Color::YELLOW, Bullet::Color::GREEN}; // Par de colores de balas para este jugador
float pos_x_ = 0.0F; // Posición en el eje X
float default_pos_x_; // Posición inicial para el jugador

View File

@@ -1635,6 +1635,7 @@ void Game::initPlayers(Player::Id player_id) {
.stage_info = stage_manager_.get()};
auto player1 = std::make_unique<Player>(config_player1);
player1->setBulletColors(Bullet::Color::YELLOW, Bullet::Color::GREEN);
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
player1->setName(Lang::getText("[SCOREBOARD] 1"));
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
@@ -1655,6 +1656,7 @@ void Game::initPlayers(Player::Id player_id) {
.stage_info = stage_manager_.get()};
auto player2 = std::make_unique<Player>(config_player2);
player2->setBulletColors(Bullet::Color::RED, Bullet::Color::PURPLE);
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
player2->setName(Lang::getText("[SCOREBOARD] 2"));
player2->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER2).instance);