Continue amb BalloonManager
This commit is contained in:
@@ -25,22 +25,20 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_.reserve(NUMBER_OF_BALLOON_FORMATIONS);
|
balloon_formation_.reserve(NUMBER_OF_BALLOON_FORMATIONS);
|
||||||
|
|
||||||
constexpr int CREATION_TIME = 300;
|
constexpr int CREATION_TIME = 300;
|
||||||
int inc_x = 0;
|
|
||||||
int inc_time = 0;
|
|
||||||
|
|
||||||
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
||||||
{
|
{
|
||||||
std::vector<BalloonFormationParams> init_params = {
|
std::vector<BalloonFormationParams> init_params = {
|
||||||
BalloonFormationParams(x4_0, y4, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
|
BalloonFormationParams(x4_0, y4, BALLOON_VELX_POSITIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
|
||||||
BalloonFormationParams(x4_100, y4, -BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
|
BalloonFormationParams(x4_100, y4, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
|
||||||
balloon_formation_.emplace_back(2, init_params);
|
balloon_formation_.emplace_back(2, init_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||||
{
|
{
|
||||||
std::vector<BalloonFormationParams> init_params = {
|
std::vector<BalloonFormationParams> init_params = {
|
||||||
BalloonFormationParams(param.game.play_area.first_quarter_x - (BALLOON_SIZE[3] / 2), y4, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
|
BalloonFormationParams(param.game.play_area.first_quarter_x - (BALLOON_SIZE[3] / 2), y4, BALLOON_VELX_POSITIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
|
||||||
BalloonFormationParams(param.game.play_area.third_quarter_x - (BALLOON_SIZE[3] / 2), y4, -BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
|
BalloonFormationParams(param.game.play_area.third_quarter_x - (BALLOON_SIZE[3] / 2), y4, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
|
||||||
balloon_formation_.emplace_back(2, init_params);
|
balloon_formation_.emplace_back(2, init_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +122,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_.emplace_back(6, init_params);
|
balloon_formation_.emplace_back(6, init_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda. Hacia la derecha
|
||||||
{
|
{
|
||||||
std::vector<BalloonFormationParams> init_params;
|
std::vector<BalloonFormationParams> init_params;
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
@@ -134,7 +132,7 @@ void BalloonFormations::initBalloonFormations()
|
|||||||
balloon_formation_.emplace_back(3, init_params);
|
balloon_formation_.emplace_back(3, init_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha. Hacia la izquierda
|
||||||
{
|
{
|
||||||
std::vector<BalloonFormationParams> init_params;
|
std::vector<BalloonFormationParams> init_params;
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
|
|||||||
@@ -33,8 +33,12 @@ struct BalloonFormationUnit
|
|||||||
// Constructor
|
// Constructor
|
||||||
BalloonFormationUnit(int num_balloons, const std::vector<BalloonFormationParams> &init_params)
|
BalloonFormationUnit(int num_balloons, const std::vector<BalloonFormationParams> &init_params)
|
||||||
: number_of_balloons(num_balloons), init(init_params) {}
|
: number_of_balloons(num_balloons), init(init_params) {}
|
||||||
|
|
||||||
|
// Default constructor
|
||||||
|
BalloonFormationUnit() : number_of_balloons(0), init() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using BalloonFormationPool = std::vector<const BalloonFormationUnit *>;
|
using BalloonFormationPool = std::vector<const BalloonFormationUnit *>;
|
||||||
|
|
||||||
class BalloonFormations
|
class BalloonFormations
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
#include "balloon_manager.h"
|
#include "balloon_manager.h"
|
||||||
#include "stage.h"
|
#include <stdlib.h> // Para rand
|
||||||
|
#include <algorithm> // Para remove_if
|
||||||
#include <numeric> // Para accumulate
|
#include <numeric> // Para accumulate
|
||||||
#include <algorithm> // Para find_if, clamp, min, remove_if
|
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
|
||||||
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VE...
|
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
|
||||||
#include "balloon_formations.h" // Para BalloonFormations, BalloonFormatio...
|
#include "explosions.h" // Para Explosions
|
||||||
#include "resource.h"
|
#include "jail_audio.h" // Para JA_PlaySound
|
||||||
#include "game.h"
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "screen.h"
|
#include "resource.h" // Para Resource
|
||||||
#include "explosions.h" // Para Explosions
|
#include "screen.h" // Para Screen
|
||||||
#include "jail_audio.h"
|
#include "stage.h" // Para power
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "utils.h" // Para Zone, BLOCK, Color, flash_color
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BalloonManager::BalloonManager()
|
BalloonManager::BalloonManager()
|
||||||
@@ -58,19 +61,22 @@ void BalloonManager::update()
|
|||||||
{
|
{
|
||||||
balloon->update();
|
balloon->update();
|
||||||
}
|
}
|
||||||
|
updateBalloonDeployCounter();
|
||||||
|
explosions_->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renderiza los globos
|
// Renderiza los objetos
|
||||||
void BalloonManager::renderBalloons()
|
void BalloonManager::render()
|
||||||
{
|
{
|
||||||
for (auto &balloon : balloons_)
|
for (auto &balloon : balloons_)
|
||||||
{
|
{
|
||||||
balloon->render();
|
balloon->render();
|
||||||
}
|
}
|
||||||
|
explosions_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una formación de enemigos
|
// Crea una formación de enemigos
|
||||||
void BalloonManager::deployBalloonFormation()
|
void BalloonManager::deployBalloonFormation(int stage)
|
||||||
{
|
{
|
||||||
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
||||||
if (balloon_deploy_counter_ == 0)
|
if (balloon_deploy_counter_ == 0)
|
||||||
@@ -100,7 +106,7 @@ void BalloonManager::deployBalloonFormation()
|
|||||||
|
|
||||||
last_balloon_deploy_ = formation;
|
last_balloon_deploy_ = formation;
|
||||||
|
|
||||||
const auto set = balloon_formations_->getStage(game_.getCurrentStage()).balloon_pool.set[formation];
|
const auto set = balloon_formations_->getSet(stage, formation);
|
||||||
const auto numEnemies = set.number_of_balloons;
|
const auto numEnemies = set.number_of_balloons;
|
||||||
for (int i = 0; i < numEnemies; ++i)
|
for (int i = 0; i < numEnemies; ++i)
|
||||||
{
|
{
|
||||||
@@ -125,7 +131,9 @@ void BalloonManager::freeBalloons()
|
|||||||
void BalloonManager::updateBalloonDeployCounter()
|
void BalloonManager::updateBalloonDeployCounter()
|
||||||
{
|
{
|
||||||
if (balloon_deploy_counter_ > 0)
|
if (balloon_deploy_counter_ > 0)
|
||||||
|
{
|
||||||
--balloon_deploy_counter_;
|
--balloon_deploy_counter_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si se puede crear una powerball
|
// Indica si se puede crear una powerball
|
||||||
@@ -184,33 +192,17 @@ void BalloonManager::createPowerBall()
|
|||||||
// Establece la velocidad de los globos
|
// Establece la velocidad de los globos
|
||||||
void BalloonManager::setBalloonSpeed(float speed)
|
void BalloonManager::setBalloonSpeed(float speed)
|
||||||
{
|
{
|
||||||
|
balloon_speed_ = speed;
|
||||||
for (auto &balloon : balloons_)
|
for (auto &balloon : balloons_)
|
||||||
|
{
|
||||||
balloon->setSpeed(speed);
|
balloon->setSpeed(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
|
||||||
void BalloonManager::checkAndUpdateBalloonSpeed()
|
|
||||||
{
|
|
||||||
if (difficulty_ != GameDifficulty::NORMAL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const float percent = static_cast<float>(game_.getCurrentPower()) / balloon_formations_->getStage(game_.getCurrentStage()).power_to_complete;
|
|
||||||
const float thresholds[] = {0.2f, 0.4f, 0.6f, 0.8f};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(thresholds); ++i)
|
|
||||||
if (balloon_speed_ == BALLOON_SPEED[i] && percent > thresholds[i])
|
|
||||||
{
|
|
||||||
balloon_speed_ = BALLOON_SPEED[i + 1];
|
|
||||||
setBalloonSpeed(balloon_speed_);
|
|
||||||
break; // Salir del bucle una vez actualizada la velocidad y aplicada
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
void BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
|
void BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
|
||||||
{
|
{
|
||||||
game_.increaseStageCurrentPower(1);
|
++Stage::power;
|
||||||
balloons_popped_++;
|
|
||||||
|
|
||||||
if (balloon->getType() == BalloonType::POWERBALL)
|
if (balloon->getType() == BalloonType::POWERBALL)
|
||||||
{
|
{
|
||||||
@@ -230,13 +222,10 @@ void BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
|
|||||||
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
||||||
balloon->pop();
|
balloon->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalcula el nivel de amenaza
|
|
||||||
evaluateAndSetMenace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye = no crea otros globos
|
// Explosiona un globo. Lo destruye = no crea otros globos
|
||||||
void BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
||||||
{
|
{
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
@@ -261,32 +250,41 @@ void BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otorga los puntos correspondientes al globo
|
// Otorga los puntos correspondientes al globo
|
||||||
|
/*
|
||||||
for (auto &player : players_)
|
for (auto &player : players_)
|
||||||
|
{
|
||||||
player->addScore(score * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
player->addScore(score * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||||
|
}
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
|
*/
|
||||||
|
|
||||||
// Aumenta el poder de la fase
|
// Aumenta el poder de la fase
|
||||||
const auto power = balloon->getPower();
|
const auto power = balloon->getPower();
|
||||||
game_.increaseStageCurrentPower(power);
|
Stage::power += power;
|
||||||
balloons_popped_ += power;
|
// balloons_popped_ += power;
|
||||||
|
|
||||||
// Destruye el globo
|
// Destruye el globo
|
||||||
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
||||||
balloon->pop();
|
balloon->pop();
|
||||||
|
|
||||||
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destruye todos los globos
|
// Destruye todos los globos
|
||||||
void BalloonManager::destroyAllBalloons()
|
int BalloonManager::destroyAllBalloons()
|
||||||
{
|
{
|
||||||
|
int score = 0;
|
||||||
for (auto &balloon : balloons_)
|
for (auto &balloon : balloons_)
|
||||||
{
|
{
|
||||||
destroyBalloon(balloon);
|
score += destroyBalloon(balloon);
|
||||||
}
|
}
|
||||||
|
|
||||||
balloon_deploy_counter_ = 300;
|
balloon_deploy_counter_ = 300;
|
||||||
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
||||||
Screen::get()->flash(flash_color, 100);
|
Screen::get()->flash(flash_color, 100);
|
||||||
Screen::get()->shake();
|
Screen::get()->shake();
|
||||||
|
|
||||||
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detiene todos los globos
|
// Detiene todos los globos
|
||||||
@@ -350,4 +348,11 @@ void BalloonManager::createTwoBigBalloons()
|
|||||||
auto p = set.init[i];
|
auto p = set.init[i];
|
||||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el nivel de ameza actual generado por los globos
|
||||||
|
int BalloonManager::getMenace()
|
||||||
|
{
|
||||||
|
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
||||||
|
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "balloon.h"
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
class BalloonFormations; // lines 16-16
|
#include <string> // Para string
|
||||||
class Explosions; // lines 18-18
|
#include <vector> // Para vector
|
||||||
|
#include "balloon.h" // Para BALLOON_SPEED, Balloon
|
||||||
|
#include "balloon_formations.h" // Para BalloonFormations
|
||||||
|
#include "explosions.h" // Para Explosions
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
using Balloons = std::vector<std::shared_ptr<Balloon>>;
|
||||||
|
|
||||||
class BalloonManager
|
class BalloonManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
Balloons balloons_; // Vector con los globos
|
||||||
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
||||||
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para gestionar las oleadas enemigas
|
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para gestionar las oleadas enemigas
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Texture>> balloon_textures_; // Vector con las texturas de los globos
|
std::vector<std::shared_ptr<Texture>> balloon_textures_; // Vector con las texturas de los globos
|
||||||
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Vector con las texturas de las explosiones
|
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Vector con las texturas de las explosiones
|
||||||
|
|
||||||
std::vector<std::vector<std::string>> balloon_animations_; // Vector con las animaciones de los globos
|
std::vector<std::vector<std::string>> balloon_animations_; // Vector con las animaciones de los globos
|
||||||
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||||
|
|
||||||
float balloon_speed_; // Velocidad a la que se mueven los enemigos
|
float balloon_speed_ = BALLOON_SPEED[0]; // Velocidad a la que se mueven los enemigos
|
||||||
float default_balloon_speed_; // Velocidad base de los enemigos, sin incrementar
|
float default_balloon_speed_ = BALLOON_SPEED[0]; // Velocidad base de los enemigos, sin incrementar
|
||||||
int balloon_deploy_counter_ = 0; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
int balloon_deploy_counter_ = 0; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||||
int balloons_popped_ = 0; // Lleva la cuenta de los globos explotados
|
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
|
||||||
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
|
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||||
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||||
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
|
|
||||||
|
|
||||||
// Inicializa
|
// Inicializa
|
||||||
void init();
|
void init();
|
||||||
@@ -39,13 +44,13 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Renderiza los globos
|
// Renderiza los globos
|
||||||
void renderBalloons();
|
void render();
|
||||||
|
|
||||||
// Vacia del vector de globos los globos que ya no sirven
|
// Vacia del vector de globos los globos que ya no sirven
|
||||||
void freeBalloons();
|
void freeBalloons();
|
||||||
|
|
||||||
// Crea una formación de enemigos
|
// Crea una formación de enemigos
|
||||||
void deployBalloonFormation();
|
void deployBalloonFormation(int stage);
|
||||||
|
|
||||||
// Actualiza la variable enemyDeployCounter
|
// Actualiza la variable enemyDeployCounter
|
||||||
void updateBalloonDeployCounter();
|
void updateBalloonDeployCounter();
|
||||||
@@ -68,17 +73,14 @@ public:
|
|||||||
// Establece la velocidad de los globos
|
// Establece la velocidad de los globos
|
||||||
void setBalloonSpeed(float speed);
|
void setBalloonSpeed(float speed);
|
||||||
|
|
||||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
|
||||||
void checkAndUpdateBalloonSpeed();
|
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
void popBalloon(std::shared_ptr<Balloon> balloon);
|
void popBalloon(std::shared_ptr<Balloon> balloon);
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye = no crea otros globos
|
// Explosiona un globo. Lo destruye = no crea otros globos
|
||||||
void destroyBalloon(std::shared_ptr<Balloon> &balloon);
|
int destroyBalloon(std::shared_ptr<Balloon> &balloon);
|
||||||
|
|
||||||
// Destruye todos los globos
|
// Destruye todos los globos
|
||||||
void destroyAllBalloons();
|
int destroyAllBalloons();
|
||||||
|
|
||||||
// Detiene todos los globos
|
// Detiene todos los globos
|
||||||
void stopAllBalloons();
|
void stopAllBalloons();
|
||||||
@@ -96,5 +98,16 @@ public:
|
|||||||
void reLoad();
|
void reLoad();
|
||||||
|
|
||||||
// Crea dos globos gordos
|
// Crea dos globos gordos
|
||||||
void createTwoBigBalloons();
|
void createTwoBigBalloons();
|
||||||
|
|
||||||
|
// Obtiene el nivel de ameza actual generado por los globos
|
||||||
|
int getMenace();
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
float getBalloonSpeed() const { return balloon_speed_; }
|
||||||
|
Balloons &getBalloons() { return balloons_; }
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }
|
||||||
|
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "define_buttons.h"
|
#include "define_buttons.h"
|
||||||
#include <utility> // Para move
|
|
||||||
#include "input.h" // Para Input, InputType
|
#include "input.h" // Para Input, InputType
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "options.h" // Para OptionsController, Options, options
|
#include "options.h" // Para OptionsController, Options, options
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||||
#include <chrono> // Para duration, system_clock
|
#include <bits/chrono.h> // Para duration, system_clock
|
||||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#include <stdio.h> // Para printf, perror
|
#include <stdio.h> // Para printf, perror
|
||||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <algorithm> // Para min
|
#include <algorithm> // Para min
|
||||||
#include <cstdlib> // Para exit, EXIT_FAILURE, size_t, rand
|
#include <cstdlib> // Para exit, EXIT_FAILURE, size_t, rand
|
||||||
#include <iostream> // Para basic_ostream, operator<<, basi...
|
#include <iostream> // Para basic_ostream, operator<<, basi...
|
||||||
#include <memory> // Para make_unique, unique_ptr, make_s...
|
#include <memory> // Para make_unique, unique_ptr
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // Para operator+, char_traits, allocator
|
#include <string> // Para operator+, char_traits, allocator
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Name, Options, name, options
|
#include "section.h" // Para Name, Options, name, options
|
||||||
#include "text.h" // Para Text
|
|
||||||
#include "title.h" // Para Title
|
#include "title.h" // Para Title
|
||||||
#include "utils.h" // Para Overrides, overrides
|
#include "utils.h" // Para Overrides, overrides
|
||||||
|
|
||||||
|
|||||||
166
source/game.cpp
166
source/game.cpp
@@ -1,9 +1,19 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "stage.h"
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include "asset.h" // Para Asset
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include "background.h" // Para Background
|
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4
|
||||||
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
#include "balloon_manager.h"
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
||||||
|
#include <stdlib.h> // Para rand, size_t
|
||||||
|
#include <algorithm> // Para find_if, clamp, min
|
||||||
|
#include <functional> // Para function
|
||||||
|
#include <iterator> // Para distance, size
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "background.h" // Para Background
|
||||||
|
#include "balloon.h" // Para Balloon, BALLOON_SPEED
|
||||||
|
#include "balloon_manager.h" // Para BalloonManager
|
||||||
|
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
||||||
#include "fade.h" // Para Fade, FadeType
|
#include "fade.h" // Para Fade, FadeType
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_inputs.h" // Para check
|
||||||
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL...
|
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL...
|
||||||
@@ -14,27 +24,17 @@
|
|||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
|
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
|
||||||
#include "player.h" // Para Player, PlayerStatus
|
#include "player.h" // Para Player, PlayerState
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
|
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Name, name, Options, options
|
#include "section.h" // Para Name, name, Options, options
|
||||||
#include "smart_sprite.h" // Para SmartSprite
|
#include "smart_sprite.h" // Para SmartSprite
|
||||||
|
#include "stage.h" // Para get, number, Stage, power
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
|
#include "dbgtxt.h" // Para dbg_print
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
struct JA_Sound_t; // lines 37-37
|
||||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
|
||||||
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4
|
|
||||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
|
||||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
|
||||||
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
|
||||||
#include <algorithm> // Para find_if, clamp, min, remove_if
|
|
||||||
#include <functional> // Para function
|
|
||||||
#include <iterator> // Para distance, size
|
|
||||||
#include <numeric> // Para accumulate
|
|
||||||
#include <stdlib.h> // Para rand, size_t
|
|
||||||
|
|
||||||
struct JA_Sound_t; // lines 36-36
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int player_id, int current_stage, bool demo)
|
Game::Game(int player_id, int current_stage, bool demo)
|
||||||
@@ -45,8 +45,7 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
background_(std::make_unique<Background>()),
|
background_(std::make_unique<Background>()),
|
||||||
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
||||||
fade_(std::make_unique<Fade>()),
|
fade_(std::make_unique<Fade>()),
|
||||||
balloon_manager_(std::make_unique<BalloonManager>(*this)),
|
balloon_manager_(std::make_unique<BalloonManager>())
|
||||||
current_stage_(current_stage)
|
|
||||||
{
|
{
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
demo_.enabled = demo;
|
demo_.enabled = demo;
|
||||||
@@ -54,6 +53,8 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
// Otras variables
|
// Otras variables
|
||||||
section::name = section::Name::GAME;
|
section::name = section::Name::GAME;
|
||||||
section::options = section::Options::GAME_PLAY_1P;
|
section::options = section::Options::GAME_PLAY_1P;
|
||||||
|
Stage::init();
|
||||||
|
Stage::number = current_stage;
|
||||||
|
|
||||||
// Asigna texturas y animaciones
|
// Asigna texturas y animaciones
|
||||||
setResources();
|
setResources();
|
||||||
@@ -81,16 +82,16 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Si se empieza en una fase que no es la primera
|
// Si se empieza en una fase que no es la primera
|
||||||
if (!demo_.enabled)
|
if (!demo_.enabled)
|
||||||
for (int i = 0; i < current_stage_; ++i)
|
for (int i = 0; i < Stage::number; ++i)
|
||||||
{
|
{
|
||||||
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
balloons_popped_ += Stage::get(i).power_to_complete;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Crea los primeros globos y el mensaje de inicio
|
// Crea los primeros globos y el mensaje de inicio
|
||||||
if (!demo_.enabled)
|
if (!demo_.enabled)
|
||||||
{
|
{
|
||||||
createTwoBigBalloons();
|
balloon_manager_->createTwoBigBalloons();
|
||||||
evaluateAndSetMenace();
|
evaluateAndSetMenace();
|
||||||
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("get_ready"));
|
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("get_ready"));
|
||||||
}
|
}
|
||||||
@@ -243,28 +244,29 @@ void Game::updateStage()
|
|||||||
{
|
{
|
||||||
if (state_ == GameState::PLAYING)
|
if (state_ == GameState::PLAYING)
|
||||||
{
|
{
|
||||||
if (current_power_ >= balloon_formations_->getStage(current_stage_).power_to_complete)
|
if (Stage::power >= Stage::get(Stage::number).power_to_complete)
|
||||||
{
|
{
|
||||||
// Cambio de fase
|
// Cambio de fase
|
||||||
++current_stage_;
|
++Stage::number;
|
||||||
current_power_ = 0;
|
Stage::power = 0;
|
||||||
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
||||||
balloon_speed_ = default_balloon_speed_;
|
balloon_manager_->resetBalloonSpeed();
|
||||||
setBalloonSpeed(balloon_speed_);
|
|
||||||
screen_->flash(flash_color, 100);
|
screen_->flash(flash_color, 100);
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
|
|
||||||
// Escribe el texto por pantalla
|
// Escribe el texto por pantalla
|
||||||
if (current_stage_ < 10)
|
if (Stage::number < 10)
|
||||||
{
|
{
|
||||||
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
const auto stage_number = Stage::get(Stage::number).number;
|
||||||
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
|
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
|
||||||
if (stage_number == 10)
|
if (stage_number == 10)
|
||||||
|
{
|
||||||
createMessage(paths, Resource::get()->getTexture("last_stage"));
|
createMessage(paths, Resource::get()->getTexture("last_stage"));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto text = Resource::get()->getText("04b_25_2x");
|
auto text = Resource::get()->getText("04b_25_2x");
|
||||||
const std::string caption = std::to_string(10 - current_stage_) + lang::getText(38);
|
const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38);
|
||||||
createMessage(paths, text->writeToTexture(caption, 1, -4));
|
createMessage(paths, text->writeToTexture(caption, 1, -4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,10 +316,10 @@ void Game::updateCompletedState()
|
|||||||
if (game_completed_counter_ == 0)
|
if (game_completed_counter_ == 0)
|
||||||
{
|
{
|
||||||
stopMusic();
|
stopMusic();
|
||||||
current_stage_ = 9; // Deja el valor dentro de los limites
|
Stage::number = 9; // Deja el valor dentro de los limites
|
||||||
destroyAllBalloons(); // Destruye a todos los globos
|
balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos
|
||||||
destroyAllItems(); // Destruye todos los items
|
destroyAllItems(); // Destruye todos los items
|
||||||
current_power_ = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
|
Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comienza las celebraciones
|
// Comienza las celebraciones
|
||||||
@@ -359,7 +361,7 @@ void Game::updateCompletedState()
|
|||||||
// Comprueba el estado del juego
|
// Comprueba el estado del juego
|
||||||
void Game::checkState()
|
void Game::checkState()
|
||||||
{
|
{
|
||||||
if (state_ != GameState::COMPLETED && current_stage_ == 10)
|
if (state_ != GameState::COMPLETED && Stage::number == 10)
|
||||||
{
|
{
|
||||||
state_ = GameState::COMPLETED;
|
state_ = GameState::COMPLETED;
|
||||||
}
|
}
|
||||||
@@ -380,10 +382,16 @@ void Game::destroyAllItems()
|
|||||||
// Comprueba la colisión entre el jugador y los globos activos
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
bool Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player)
|
bool Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player)
|
||||||
{
|
{
|
||||||
for (auto &balloon : balloons_)
|
for (auto &balloon : balloon_manager_->getBalloons())
|
||||||
|
{
|
||||||
if (!balloon->isStopped() && !balloon->isInvulnerable())
|
if (!balloon->isStopped() && !balloon->isInvulnerable())
|
||||||
|
{
|
||||||
if (checkCollision(player->getCollider(), balloon->getCollider()))
|
if (checkCollision(player->getCollider(), balloon->getCollider()))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -485,7 +493,7 @@ void Game::checkBulletBalloonCollision()
|
|||||||
{
|
{
|
||||||
for (auto &bullet : bullets_)
|
for (auto &bullet : bullets_)
|
||||||
{
|
{
|
||||||
for (auto &balloon : balloons_)
|
for (auto &balloon : balloon_manager_->getBalloons())
|
||||||
{
|
{
|
||||||
if (balloon->isEnabled() && (!balloon->isInvulnerable()) && bullet->isEnabled())
|
if (balloon->isEnabled() && (!balloon->isInvulnerable()) && bullet->isEnabled())
|
||||||
{
|
{
|
||||||
@@ -518,7 +526,9 @@ void Game::checkBulletBalloonCollision()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explota el globo
|
// Explota el globo
|
||||||
popBalloon(balloon);
|
balloon_manager_->popBalloon(balloon);
|
||||||
|
balloons_popped_++;
|
||||||
|
evaluateAndSetMenace();
|
||||||
|
|
||||||
// Sonido de explosión
|
// Sonido de explosión
|
||||||
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
||||||
@@ -821,9 +831,9 @@ void Game::updateTimeStopped()
|
|||||||
if (time_stopped_counter_ % 15 == 0)
|
if (time_stopped_counter_ % 15 == 0)
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
if (time_stopped_counter_ % 30 == 15)
|
if (time_stopped_counter_ % 30 == 15)
|
||||||
reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -858,7 +868,9 @@ void Game::updateBackground()
|
|||||||
{
|
{
|
||||||
// Si el juego está completado, se reduce la velocidad de las nubes
|
// Si el juego está completado, se reduce la velocidad de las nubes
|
||||||
if (state_ == GameState::COMPLETED)
|
if (state_ == GameState::COMPLETED)
|
||||||
|
{
|
||||||
balloons_popped_ = (balloons_popped_ > 400) ? (balloons_popped_ - 25) : 200;
|
balloons_popped_ = (balloons_popped_ > 400) ? (balloons_popped_ - 25) : 200;
|
||||||
|
}
|
||||||
|
|
||||||
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
|
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
|
||||||
constexpr float clouds_initial_speed = 0.05f;
|
constexpr float clouds_initial_speed = 0.05f;
|
||||||
@@ -887,11 +899,12 @@ void Game::fillCanvas()
|
|||||||
background_->render();
|
background_->render();
|
||||||
renderItems();
|
renderItems();
|
||||||
renderSmartSprites();
|
renderSmartSprites();
|
||||||
explosions_->render();
|
balloon_manager_->render();
|
||||||
balloon_manager_->renderBalloons();
|
|
||||||
renderBullets();
|
renderBullets();
|
||||||
renderPathSprites();
|
renderPathSprites();
|
||||||
renderPlayers();
|
renderPlayers();
|
||||||
|
dbg_print(0, 40, std::to_string(menace_current_).c_str(), 255, 0 ,0);
|
||||||
|
dbg_print(0, 50, std::to_string(menace_threshold_).c_str(), 255, 0 ,0);
|
||||||
|
|
||||||
// Deja el renderizador apuntando donde estaba
|
// Deja el renderizador apuntando donde estaba
|
||||||
SDL_SetRenderTarget(renderer_, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
@@ -919,8 +932,8 @@ void Game::render()
|
|||||||
// Habilita el efecto del item de detener el tiempo
|
// Habilita el efecto del item de detener el tiempo
|
||||||
void Game::enableTimeStopItem()
|
void Game::enableTimeStopItem()
|
||||||
{
|
{
|
||||||
stopAllBalloons();
|
balloon_manager_->stopAllBalloons();
|
||||||
reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
time_stopped_counter_ = TIME_STOPPED_COUNTER_;
|
time_stopped_counter_ = TIME_STOPPED_COUNTER_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,8 +941,8 @@ void Game::enableTimeStopItem()
|
|||||||
void Game::disableTimeStopItem()
|
void Game::disableTimeStopItem()
|
||||||
{
|
{
|
||||||
time_stopped_counter_ = 0;
|
time_stopped_counter_ = 0;
|
||||||
startAllBalloons();
|
balloon_manager_->startAllBalloons();
|
||||||
normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si la música ha de estar sonando
|
// Comprueba si la música ha de estar sonando
|
||||||
@@ -1118,7 +1131,7 @@ void Game::checkEvents()
|
|||||||
}
|
}
|
||||||
case SDLK_2: // Crea dos globos gordos
|
case SDLK_2: // Crea dos globos gordos
|
||||||
{
|
{
|
||||||
createTwoBigBalloons();
|
balloon_manager_->createTwoBigBalloons();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
||||||
@@ -1188,8 +1201,8 @@ void Game::updateScoreboard()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resto de marcador
|
// Resto de marcador
|
||||||
scoreboard_->setStage(balloon_formations_->getStage(current_stage_).number);
|
scoreboard_->setStage(Stage::get(Stage::number).number);
|
||||||
scoreboard_->setPower((float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete);
|
scoreboard_->setPower((float)Stage::power / (float)Stage::get(Stage::number).power_to_complete);
|
||||||
scoreboard_->setHiScore(hi_score_.score);
|
scoreboard_->setHiScore(hi_score_.score);
|
||||||
scoreboard_->setHiScoreName(hi_score_.name);
|
scoreboard_->setHiScoreName(hi_score_.name);
|
||||||
|
|
||||||
@@ -1200,8 +1213,8 @@ void Game::updateScoreboard()
|
|||||||
// Pausa el juego
|
// Pausa el juego
|
||||||
void Game::pause(bool value)
|
void Game::pause(bool value)
|
||||||
{
|
{
|
||||||
paused_ = value;
|
//paused_ = value;
|
||||||
screen_->attenuate(paused_);
|
//screen_->attenuate(paused_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade una puntuación a la tabla de records
|
// Añade una puntuación a la tabla de records
|
||||||
@@ -1528,13 +1541,13 @@ void Game::initDemo(int player_id)
|
|||||||
constexpr auto demos = 3;
|
constexpr auto demos = 3;
|
||||||
const auto demo = rand() % demos;
|
const auto demo = rand() % demos;
|
||||||
const int stages[demos] = {0, 3, 5};
|
const int stages[demos] = {0, 3, 5};
|
||||||
current_stage_ = stages[demo];
|
Stage::number = stages[demo];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el numero de globos explotados según la fase del modo demostración
|
// Actualiza el numero de globos explotados según la fase del modo demostración
|
||||||
for (int i = 0; i < current_stage_; ++i)
|
for (int i = 0; i < Stage::number; ++i)
|
||||||
{
|
{
|
||||||
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
balloons_popped_ += Stage::get(i).power_to_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
@@ -1604,7 +1617,7 @@ void Game::initDifficultyVars()
|
|||||||
{
|
{
|
||||||
case GameDifficulty::EASY:
|
case GameDifficulty::EASY:
|
||||||
{
|
{
|
||||||
default_balloon_speed_ = BALLOON_SPEED[0];
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||||
difficulty_score_multiplier_ = 0.5f;
|
difficulty_score_multiplier_ = 0.5f;
|
||||||
scoreboard_->setColor(scoreboard_easy_color);
|
scoreboard_->setColor(scoreboard_easy_color);
|
||||||
break;
|
break;
|
||||||
@@ -1612,7 +1625,7 @@ void Game::initDifficultyVars()
|
|||||||
|
|
||||||
case GameDifficulty::NORMAL:
|
case GameDifficulty::NORMAL:
|
||||||
{
|
{
|
||||||
default_balloon_speed_ = BALLOON_SPEED[0];
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||||
difficulty_score_multiplier_ = 1.0f;
|
difficulty_score_multiplier_ = 1.0f;
|
||||||
scoreboard_->setColor(scoreboard_normal_color);
|
scoreboard_->setColor(scoreboard_normal_color);
|
||||||
break;
|
break;
|
||||||
@@ -1620,7 +1633,7 @@ void Game::initDifficultyVars()
|
|||||||
|
|
||||||
case GameDifficulty::HARD:
|
case GameDifficulty::HARD:
|
||||||
{
|
{
|
||||||
default_balloon_speed_ = BALLOON_SPEED[4];
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
|
||||||
difficulty_score_multiplier_ = 1.5f;
|
difficulty_score_multiplier_ = 1.5f;
|
||||||
scoreboard_->setColor(scoreboard_hard_color);
|
scoreboard_->setColor(scoreboard_hard_color);
|
||||||
break;
|
break;
|
||||||
@@ -1630,7 +1643,7 @@ void Game::initDifficultyVars()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
balloon_speed_ = default_balloon_speed_;
|
balloon_manager_->resetBalloonSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa los jugadores
|
// Inicializa los jugadores
|
||||||
@@ -1729,7 +1742,7 @@ void Game::updateGame()
|
|||||||
if (auto_pop_balloons_ && state_ == GameState::PLAYING)
|
if (auto_pop_balloons_ && state_ == GameState::PLAYING)
|
||||||
{
|
{
|
||||||
balloons_popped_ += 5;
|
balloons_popped_ += 5;
|
||||||
increaseStageCurrentPower(5);
|
Stage::power += 5;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fade_->update();
|
fade_->update();
|
||||||
@@ -1738,7 +1751,6 @@ void Game::updateGame()
|
|||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground();
|
||||||
balloon_manager_->update();
|
balloon_manager_->update();
|
||||||
explosions_->update();
|
|
||||||
moveBullets();
|
moveBullets();
|
||||||
updateItems();
|
updateItems();
|
||||||
updateStage();
|
updateStage();
|
||||||
@@ -1747,7 +1759,6 @@ void Game::updateGame()
|
|||||||
updateSmartSprites();
|
updateSmartSprites();
|
||||||
updatePathSprites();
|
updatePathSprites();
|
||||||
updateTimeStopped();
|
updateTimeStopped();
|
||||||
updateBalloonDeployCounter();
|
|
||||||
updateHelper();
|
updateHelper();
|
||||||
checkBulletBalloonCollision();
|
checkBulletBalloonCollision();
|
||||||
updateMenace();
|
updateMenace();
|
||||||
@@ -1770,8 +1781,8 @@ void Game::cleanVectors()
|
|||||||
// Gestiona el nivel de amenaza
|
// Gestiona el nivel de amenaza
|
||||||
void Game::updateMenace()
|
void Game::updateMenace()
|
||||||
{
|
{
|
||||||
const auto stage = balloon_formations_->getStage(current_stage_);
|
const auto stage = Stage::get(Stage::number);
|
||||||
const float percent = current_power_ / stage.power_to_complete;
|
const float percent = Stage::power / stage.power_to_complete;
|
||||||
const int difference = stage.max_menace - stage.min_menace;
|
const int difference = stage.max_menace - stage.min_menace;
|
||||||
|
|
||||||
// Aumenta el nivel de amenaza en función de la puntuación
|
// Aumenta el nivel de amenaza en función de la puntuación
|
||||||
@@ -1781,7 +1792,7 @@ void Game::updateMenace()
|
|||||||
if (menace_current_ < menace_threshold_)
|
if (menace_current_ < menace_threshold_)
|
||||||
{
|
{
|
||||||
// Crea una formación de enemigos
|
// Crea una formación de enemigos
|
||||||
balloon_manager_->deployBalloonFormation();
|
balloon_manager_->deployBalloonFormation(Stage::number);
|
||||||
|
|
||||||
// Recalcula el nivel de amenaza con el nuevo globo
|
// Recalcula el nivel de amenaza con el nuevo globo
|
||||||
evaluateAndSetMenace();
|
evaluateAndSetMenace();
|
||||||
@@ -1791,7 +1802,24 @@ void Game::updateMenace()
|
|||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
void Game::evaluateAndSetMenace()
|
void Game::evaluateAndSetMenace()
|
||||||
{
|
{
|
||||||
menace_current_ = std::accumulate(
|
menace_current_ = balloon_manager_->getMenace();
|
||||||
balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
}
|
||||||
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
|
|
||||||
|
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||||
|
void Game::checkAndUpdateBalloonSpeed()
|
||||||
|
{
|
||||||
|
if (difficulty_ != GameDifficulty::NORMAL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const float percent = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
||||||
|
const float thresholds[] = {0.2f, 0.4f, 0.6f, 0.8f};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < std::size(thresholds); ++i)
|
||||||
|
{
|
||||||
|
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && percent > thresholds[i])
|
||||||
|
{
|
||||||
|
balloon_manager_->setBalloonSpeed(BALLOON_SPEED[i + 1]);
|
||||||
|
break; // Salir del bucle una vez actualizada la velocidad y aplicada
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,25 +5,25 @@
|
|||||||
#include <memory> // Para shared_ptr, unique_ptr
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "balloon_manager.h" // Para BalloonManager
|
|
||||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
#include "options.h" // Para Options, OptionsGame, options
|
#include "options.h" // Para Options, OptionsGame, options
|
||||||
#include "player.h" // Para Player
|
#include "player.h" // Para Player
|
||||||
#include "utils.h" // Para Demo
|
#include "utils.h" // Para Demo
|
||||||
class Asset; // lines 14-14
|
class Asset; // lines 13-13
|
||||||
class Background; // lines 15-15
|
class Background; // lines 14-14
|
||||||
class Bullet; // lines 17-17
|
class BalloonManager;
|
||||||
class Fade; // lines 19-19
|
class Bullet; // lines 15-15
|
||||||
class Input; // lines 20-20
|
class Fade; // lines 16-16
|
||||||
class Item; // lines 21-21
|
class Input; // lines 17-17
|
||||||
class PathSprite; // lines 22-22
|
class Item; // lines 18-18
|
||||||
class Scoreboard; // lines 23-23
|
class PathSprite; // lines 19-19
|
||||||
class Screen; // lines 24-24
|
class Scoreboard; // lines 20-20
|
||||||
class SmartSprite; // lines 25-25
|
class Screen; // lines 21-21
|
||||||
class Texture; // lines 27-27
|
class SmartSprite; // lines 22-22
|
||||||
enum class BulletType : Uint8; // lines 28-28
|
class Texture; // lines 23-23
|
||||||
enum class ItemType; // lines 29-29
|
enum class BulletType : Uint8; // lines 24-24
|
||||||
struct Path;
|
enum class ItemType; // lines 25-25
|
||||||
|
struct Path; // lines 26-26
|
||||||
|
|
||||||
// Modo demo
|
// Modo demo
|
||||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||||
@@ -149,8 +149,6 @@ private:
|
|||||||
options.game.hi_score_table[0].name,
|
options.game.hi_score_table[0].name,
|
||||||
options.game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
|
options.game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
|
||||||
|
|
||||||
int current_stage_; // Indica la fase actual
|
|
||||||
int current_power_ = 0; // Poder actual almacenado para completar la fase
|
|
||||||
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
|
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
|
||||||
GameDifficulty difficulty_ = options.game.difficulty; // Dificultad del juego
|
GameDifficulty difficulty_ = options.game.difficulty; // Dificultad del juego
|
||||||
Helper helper_; // Variable para gestionar las ayudas
|
Helper helper_; // Variable para gestionar las ayudas
|
||||||
@@ -164,6 +162,7 @@ private:
|
|||||||
int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida
|
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 time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
|
||||||
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
|
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
|
||||||
|
int balloons_popped_ = 0; // Lleva la cuenta de los globos explotados
|
||||||
int menace_current_ = 0; // Nivel de amenaza actual
|
int menace_current_ = 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
|
||||||
GameState state_ = GameState::PLAYING; // Estado
|
GameState state_ = GameState::PLAYING; // Estado
|
||||||
@@ -402,6 +401,9 @@ private:
|
|||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
void evaluateAndSetMenace();
|
void evaluateAndSetMenace();
|
||||||
|
|
||||||
|
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||||
|
void checkAndUpdateBalloonSpeed();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int playerID, int current_stage, bool demo);
|
Game(int playerID, int current_stage, bool demo);
|
||||||
@@ -411,14 +413,4 @@ public:
|
|||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
// Aumenta el poder de la fase
|
|
||||||
void increaseStageCurrentPower(int power) { current_power_ += power; }
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
int getCurrentStage() const { return current_stage_; }
|
|
||||||
void setCurrentStage(int stage) { current_stage_ = stage; }
|
|
||||||
|
|
||||||
int getCurrentPower() const { return current_power_; }
|
|
||||||
void setCurrentPower(int power) { current_power_ = power; }
|
|
||||||
};
|
};
|
||||||
@@ -2,13 +2,14 @@
|
|||||||
#include <algorithm> // Para find_if
|
#include <algorithm> // Para find_if
|
||||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
|
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
|
#include <utility> // Para pair
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "lang.h" // Para lang
|
|
||||||
#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound
|
#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound
|
||||||
|
#include "lang.h" // Para getText
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text, loadTextFile
|
||||||
struct JA_Music_t;
|
struct JA_Music_t; // lines 10-10
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t; // lines 11-11
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Resource *Resource::resource_ = nullptr;
|
Resource *Resource::resource_ = nullptr;
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
namespace Stage
|
namespace Stage
|
||||||
{
|
{
|
||||||
|
|
||||||
|
std::vector<Stage> stages; // Variable con los datos de cada pantalla
|
||||||
|
int power = 0; // Poder acumulado en la fase
|
||||||
|
int number = 0; // Fase actual
|
||||||
|
|
||||||
|
// Devuelve una fase
|
||||||
|
Stage get(int index) { return stages.at(index); }
|
||||||
|
|
||||||
// Inicializa las fases del juego
|
// Inicializa las fases del juego
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ namespace Stage
|
|||||||
: number(number), power_to_complete(power_to_complete), min_menace(min_menace), max_menace(max_menace) {}
|
: number(number), power_to_complete(power_to_complete), min_menace(min_menace), max_menace(max_menace) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Stage> stages; // Variable con los datos de cada pantalla
|
extern std::vector<Stage> stages; // Variable con los datos de cada pantalla
|
||||||
|
extern int power; // Poder acumulado en la fase
|
||||||
|
extern int number; // Fase actual
|
||||||
|
|
||||||
// Devuelve una fase
|
// Devuelve una fase
|
||||||
Stage get(int index) { return stages.at(index); }
|
Stage get(int index);
|
||||||
|
|
||||||
// Inicializa las fases del juego
|
// Inicializa las fases del juego
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <stddef.h> // Para size_t
|
#include <stddef.h> // Para size_t
|
||||||
#include <string> // Para char_traits, operator+, basic_string
|
#include <string> // Para char_traits, operator+, basic_string
|
||||||
#include <utility> // Para move
|
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "define_buttons.h" // Para DefineButtons
|
#include "define_buttons.h" // Para DefineButtons
|
||||||
#include "fade.h" // Para Fade, FadeType
|
#include "fade.h" // Para Fade, FadeType
|
||||||
@@ -21,7 +20,7 @@
|
|||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Options, options, Name, name, AttractMode
|
#include "section.h" // Para Options, options, Name, name, AttractMode
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
#include "text.h" // Para TEXT_CENTER, TEXT_SHADOW, Text
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||||
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
||||||
|
|||||||
Reference in New Issue
Block a user