Acabat BalloonManager
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
#include "smart_sprite.h" // Para SmartSprite
|
||||
#include "stage.h" // Para get, number, Stage, power
|
||||
#include "text.h" // Para Text
|
||||
#include "dbgtxt.h" // Para dbg_print
|
||||
#include "dbgtxt.h" // Para dbg_print
|
||||
#include "texture.h" // Para Texture
|
||||
struct JA_Sound_t; // lines 37-37
|
||||
|
||||
@@ -84,7 +84,7 @@ Game::Game(int player_id, int current_stage, bool demo)
|
||||
if (!demo_.enabled)
|
||||
for (int i = 0; i < Stage::number; ++i)
|
||||
{
|
||||
balloons_popped_ += Stage::get(i).power_to_complete;
|
||||
Stage::total_power += Stage::get(i).power_to_complete;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -247,8 +247,8 @@ void Game::updateStage()
|
||||
if (Stage::power >= Stage::get(Stage::number).power_to_complete)
|
||||
{
|
||||
// Cambio de fase
|
||||
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
|
||||
++Stage::number;
|
||||
Stage::power = 0;
|
||||
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
||||
balloon_manager_->resetBalloonSpeed();
|
||||
screen_->flash(flash_color, 100);
|
||||
@@ -257,9 +257,8 @@ void Game::updateStage()
|
||||
// Escribe el texto por pantalla
|
||||
if (Stage::number < 10)
|
||||
{
|
||||
const auto stage_number = Stage::get(Stage::number).number;
|
||||
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
|
||||
if (stage_number == 10)
|
||||
if (Stage::number == 9)
|
||||
{
|
||||
createMessage(paths, Resource::get()->getTexture("last_stage"));
|
||||
}
|
||||
@@ -499,15 +498,8 @@ void Game::checkBulletBalloonCollision()
|
||||
{
|
||||
if (checkCollision(balloon->getCollider(), bullet->getCollider()))
|
||||
{
|
||||
// Otorga los puntos al jugador que disparó la bala
|
||||
// Obtiene al jugador que disparó la bala
|
||||
auto player = getPlayer(bullet->getOwner());
|
||||
if (!player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player->addScore(balloon->getScore() * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||
player->incScoreMultiplier();
|
||||
updateHiScore();
|
||||
|
||||
// Suelta el item si se da el caso
|
||||
const auto droppeditem = dropItem();
|
||||
@@ -526,10 +518,17 @@ void Game::checkBulletBalloonCollision()
|
||||
}
|
||||
|
||||
// Explota el globo
|
||||
balloon_manager_->popBalloon(balloon);
|
||||
balloons_popped_++;
|
||||
const auto score = balloon_manager_->popBalloon(balloon);
|
||||
evaluateAndSetMenace();
|
||||
|
||||
// Otorga los puntos al jugador que disparó la bala
|
||||
if (player->isPlaying())
|
||||
{
|
||||
player->addScore(score * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||
player->incScoreMultiplier();
|
||||
}
|
||||
updateHiScore();
|
||||
|
||||
// Sonido de explosión
|
||||
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
||||
|
||||
@@ -869,17 +868,18 @@ void Game::updateBackground()
|
||||
// Si el juego está completado, se reduce la velocidad de las nubes
|
||||
if (state_ == GameState::COMPLETED)
|
||||
{
|
||||
balloons_popped_ = (balloons_popped_ > 400) ? (balloons_popped_ - 25) : 200;
|
||||
Stage::total_power = (Stage::total_power > 400) ? (Stage::total_power - 25) : 200;
|
||||
}
|
||||
|
||||
// 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_final_speed = 2.00f - clouds_initial_speed;
|
||||
const float cloudsSpeed = (-clouds_initial_speed) + (-clouds_final_speed * (static_cast<float>(balloons_popped_) / total_power_to_complete_game_));
|
||||
const float cloudsSpeed = (-clouds_initial_speed) + (-clouds_final_speed * (static_cast<float>(Stage::total_power) / total_power_to_complete_game_));
|
||||
background_->setCloudsSpeed(cloudsSpeed);
|
||||
|
||||
// Calcula la transición de los diferentes fondos
|
||||
const float gradient_number = std::min(balloons_popped_ / 1250.0f, 3.0f);
|
||||
constexpr float num = 1525.0f; // total_power_to_complete div 4
|
||||
const float gradient_number = std::min(Stage::total_power / num, 3.0f);
|
||||
const float percent = gradient_number - static_cast<int>(gradient_number);
|
||||
background_->setGradientNumber(static_cast<int>(gradient_number));
|
||||
background_->setTransition(percent);
|
||||
@@ -903,8 +903,8 @@ void Game::fillCanvas()
|
||||
renderBullets();
|
||||
renderPathSprites();
|
||||
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);
|
||||
// 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
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
@@ -1201,7 +1201,7 @@ void Game::updateScoreboard()
|
||||
}
|
||||
|
||||
// Resto de marcador
|
||||
scoreboard_->setStage(Stage::get(Stage::number).number);
|
||||
scoreboard_->setStage(Stage::number + 1);
|
||||
scoreboard_->setPower((float)Stage::power / (float)Stage::get(Stage::number).power_to_complete);
|
||||
scoreboard_->setHiScore(hi_score_.score);
|
||||
scoreboard_->setHiScoreName(hi_score_.name);
|
||||
@@ -1213,8 +1213,8 @@ void Game::updateScoreboard()
|
||||
// Pausa el juego
|
||||
void Game::pause(bool value)
|
||||
{
|
||||
//paused_ = value;
|
||||
//screen_->attenuate(paused_);
|
||||
paused_ = value;
|
||||
screen_->attenuate(paused_);
|
||||
}
|
||||
|
||||
// Añade una puntuación a la tabla de records
|
||||
@@ -1547,7 +1547,7 @@ void Game::initDemo(int player_id)
|
||||
// Actualiza el numero de globos explotados según la fase del modo demostración
|
||||
for (int i = 0; i < Stage::number; ++i)
|
||||
{
|
||||
balloons_popped_ += Stage::get(i).power_to_complete;
|
||||
Stage::total_power += Stage::get(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Activa o no al otro jugador
|
||||
@@ -1588,9 +1588,9 @@ void Game::initDemo(int player_id)
|
||||
void Game::setTotalPower()
|
||||
{
|
||||
total_power_to_complete_game_ = 0;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
for (const auto &stage : Stage::stages)
|
||||
{
|
||||
total_power_to_complete_game_ += Stage::get(i).power_to_complete;
|
||||
total_power_to_complete_game_ += stage.power_to_complete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1671,21 +1671,27 @@ void Game::initPlayers(int player_id)
|
||||
void Game::pauseMusic()
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING && !demo_.enabled)
|
||||
{
|
||||
JA_PauseMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Reanuda la música
|
||||
void Game::resumeMusic()
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_PAUSED && !demo_.enabled)
|
||||
{
|
||||
JA_ResumeMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Detiene la música
|
||||
void Game::stopMusic()
|
||||
{
|
||||
if (!demo_.enabled)
|
||||
{
|
||||
JA_StopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables durante el modo demo
|
||||
@@ -1741,8 +1747,7 @@ void Game::updateGame()
|
||||
#ifdef DEBUG
|
||||
if (auto_pop_balloons_ && state_ == GameState::PLAYING)
|
||||
{
|
||||
balloons_popped_ += 5;
|
||||
Stage::power += 5;
|
||||
Stage::addPower(5);
|
||||
}
|
||||
#endif
|
||||
fade_->update();
|
||||
|
||||
Reference in New Issue
Block a user