game fix: la velocitat dels globos dins de la fase actual muntava al primer globo explotat
game fix: al trencar una powerball ja no eixien mes globos style: renombrades variables i funcions
This commit is contained in:
@@ -41,7 +41,7 @@ void handleInputEvents(const SDL_Event &event) {
|
||||
}
|
||||
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||
void check(const SDL_Event &event) {
|
||||
void handle(const SDL_Event &event) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT: // Evento de salida de la aplicación
|
||||
Section::name = Section::Name::QUIT;
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||
void check(const SDL_Event &event);
|
||||
void handle(const SDL_Event &event);
|
||||
} // namespace GlobalEvents
|
||||
@@ -603,10 +603,10 @@ void Player::update() {
|
||||
}
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
void Player::addScore(int score, int last_hi_score_entry) {
|
||||
void Player::addScore(int score, int lowest_hi_score_entry) {
|
||||
if (isPlaying()) {
|
||||
score_ += score;
|
||||
qualifies_for_high_score_ = score_ > last_hi_score_entry;
|
||||
qualifies_for_high_score_ = score_ > lowest_hi_score_entry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class Player {
|
||||
void updateCooldown(); // Actualiza el cooldown de disparo
|
||||
|
||||
// --- Puntuación y marcador ---
|
||||
void addScore(int score, int last_hi_score_entry); // Añade puntos
|
||||
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
|
||||
void incScoreMultiplier(); // Incrementa el multiplicador
|
||||
void decScoreMultiplier(); // Decrementa el multiplicador
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ void Credits::render() {
|
||||
void Credits::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -626,13 +626,12 @@ void Game::handleItemDrop(std::shared_ptr<Balloon> balloon, std::shared_ptr<Play
|
||||
|
||||
// Maneja la destrucción del globo y puntuación
|
||||
void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, std::shared_ptr<Player> player) {
|
||||
evaluateAndSetMenace();
|
||||
|
||||
if (player->isPlaying()) {
|
||||
auto const SCORE = balloon_manager_->popBalloon(balloon) * player->getScoreMultiplier() * difficulty_score_multiplier_;
|
||||
player->addScore(SCORE, Options::settings.hi_score_table.back().score);
|
||||
player->incScoreMultiplier();
|
||||
}
|
||||
setMenace();
|
||||
updateHiScore();
|
||||
}
|
||||
|
||||
@@ -1022,7 +1021,7 @@ void Game::run() {
|
||||
checkInput();
|
||||
#endif
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
handleEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -1083,7 +1082,7 @@ void Game::initPaths() {
|
||||
// Actualiza las variables de ayuda
|
||||
void Game::updateHelper() {
|
||||
// Solo ofrece ayuda cuando la amenaza es elevada
|
||||
if (menace_current_ > 15) {
|
||||
if (menace_ > 15) {
|
||||
helper_.need_coffee = true;
|
||||
helper_.need_coffee_machine = true;
|
||||
for (const auto &player : players_) {
|
||||
@@ -1128,7 +1127,7 @@ auto Game::allPlayersAreNotPlaying() -> bool {
|
||||
}
|
||||
|
||||
// Comprueba los eventos que hay en cola
|
||||
void Game::checkEvents() {
|
||||
void Game::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
@@ -1145,9 +1144,9 @@ void Game::checkEvents() {
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
checkDebugEvents(event);
|
||||
handleDebugEvents(event);
|
||||
#endif
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1705,7 +1704,7 @@ void Game::updateGameStateFadeIn() {
|
||||
if (fade_in_->hasEnded()) {
|
||||
setState(State::ENTERING_PLAYER);
|
||||
balloon_manager_->createTwoBigBalloons();
|
||||
evaluateAndSetMenace();
|
||||
setMenace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1791,15 +1790,16 @@ void Game::updateMenace() {
|
||||
// Aumenta el nivel de amenaza en función del progreso de la fase
|
||||
menace_threshold_ = stage.getMinMenace() + (difference * fraction);
|
||||
|
||||
if (menace_current_ < menace_threshold_) {
|
||||
if (menace_ < menace_threshold_) {
|
||||
balloon_manager_->deployRandomFormation(stage_manager_->getCurrentStageIndex());
|
||||
evaluateAndSetMenace();
|
||||
setMenace();
|
||||
}
|
||||
std::cout << "MT: " << menace_threshold_ << " | MC: " << menace_ << std::endl;
|
||||
}
|
||||
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
void Game::evaluateAndSetMenace() {
|
||||
menace_current_ = balloon_manager_->getMenace();
|
||||
void Game::setMenace() {
|
||||
menace_ = balloon_manager_->getMenace();
|
||||
}
|
||||
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
@@ -1808,8 +1808,7 @@ void Game::checkAndUpdateBalloonSpeed() {
|
||||
return;
|
||||
}
|
||||
|
||||
// const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
||||
const float PERCENT = stage_manager_->getCurrentStageProgressPercentage();
|
||||
const float PERCENT = stage_manager_->getCurrentStageProgressFraction();
|
||||
constexpr std::array<float, 4> THRESHOLDS = {0.2F, 0.4F, 0.6F, 0.8F};
|
||||
|
||||
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {
|
||||
@@ -1883,13 +1882,13 @@ void Game::onPauseStateChanged(bool is_paused) {
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Comprueba los eventos en el modo DEBUG
|
||||
void Game::checkDebugEvents(const SDL_Event &event) {
|
||||
void Game::handleDebugEvents(const SDL_Event &event) {
|
||||
static int formation_id_ = 0;
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDLK_1: // Crea una powerball
|
||||
{
|
||||
// balloon_manager_->createPowerBall();
|
||||
balloon_manager_->createPowerBall();
|
||||
// throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "path_sprite.h" // Para PathSprite, Path
|
||||
#include "player.h" // Para Player
|
||||
#include "smart_sprite.h" // Para SmartSprite
|
||||
#include "utils.h" // Para Demo
|
||||
#include "stage.h" // Para StageManager
|
||||
#include "utils.h" // Para Demo
|
||||
|
||||
class Background;
|
||||
class Balloon;
|
||||
@@ -142,7 +142,7 @@ class Game {
|
||||
int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más globos
|
||||
int game_over_counter_ = GAME_OVER_COUNTER; // Contador para el estado de fin de partida
|
||||
int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
int menace_current_ = 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
|
||||
State state_ = State::FADE_IN; // Estado
|
||||
std::vector<std::shared_ptr<Player>> players_to_put_at_back_;
|
||||
@@ -156,7 +156,7 @@ class Game {
|
||||
// --- Ciclo principal del juego ---
|
||||
void update(); // Actualiza la lógica principal del juego
|
||||
void render(); // Renderiza todos los elementos del juego
|
||||
void checkEvents(); // Procesa los eventos del sistema en cola
|
||||
void handleEvents(); // Procesa los eventos del sistema en cola
|
||||
void checkState(); // Verifica y actualiza el estado actual del juego
|
||||
void setState(State state); // Cambia el estado del juego
|
||||
void cleanVectors(); // Limpia vectores de elementos deshabilitados
|
||||
@@ -264,7 +264,7 @@ class Game {
|
||||
|
||||
// --- Sistema de amenaza ---
|
||||
void updateMenace(); // Gestiona el nivel de amenaza del juego
|
||||
void evaluateAndSetMenace(); // Calcula y establece amenaza según globos activos
|
||||
void setMenace(); // Calcula y establece amenaza según globos activos
|
||||
|
||||
// --- Puntuación y marcador ---
|
||||
void updateHiScore(); // Actualiza el récord máximo si es necesario
|
||||
@@ -300,6 +300,6 @@ class Game {
|
||||
|
||||
// --- Depuración (solo en modo DEBUG) ---
|
||||
#ifdef _DEBUG
|
||||
void checkDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG
|
||||
void handleDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG
|
||||
#endif
|
||||
};
|
||||
@@ -108,7 +108,7 @@ void HiScoreTable::fillTexture() {
|
||||
void HiScoreTable::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ void Instructions::render() {
|
||||
void Instructions::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ Intro::Intro()
|
||||
void Intro::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ Logo::~Logo() {
|
||||
void Logo::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ void Title::checkEvents() {
|
||||
handleKeyDownEvent(event);
|
||||
}
|
||||
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user