nou: bales de colors diferents per a cada jugador
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -17,4 +17,5 @@ coffee_crisis*
|
||||
debug.txt
|
||||
cppcheck-result*
|
||||
desktop.ini
|
||||
ccae_release/
|
||||
ccae_release/
|
||||
resources.pack
|
||||
@@ -2,43 +2,85 @@ frame_width=12
|
||||
frame_height=12
|
||||
|
||||
[animation]
|
||||
name=normal_up
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=0,1,2
|
||||
name=yellow_up
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=0
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_left
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=3,4,5,5,4,3
|
||||
name=yellow_left
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=1
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_right
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=6,7,8,8,7,6
|
||||
name=yellow_right
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=2
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_up
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=9,10,11,11,10,9
|
||||
name=green_up
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=3
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_left
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=12,13,14,14,13,12
|
||||
name=green_left
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=4
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_right
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=15,16,17,17,26,15
|
||||
name=green_right
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=5
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red_up
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=6
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red_left
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=7
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red_right
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=8
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=purple_up
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=purple_left
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=10
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=purple_right
|
||||
speed=20
|
||||
loop=-1
|
||||
frames=11
|
||||
[/animation]
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.7 KiB |
BIN
resources.pack
BIN
resources.pack
Binary file not shown.
@@ -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";
|
||||
|
||||
@@ -30,7 +30,9 @@ class Bullet {
|
||||
|
||||
enum class Color : Uint8 {
|
||||
YELLOW,
|
||||
GREEN
|
||||
GREEN,
|
||||
RED,
|
||||
PURPLE
|
||||
};
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user