fent improvements a balloon (canvi de pc)
This commit is contained in:
@@ -32,10 +32,6 @@ class Balloon {
|
||||
static constexpr float VELX_POSITIVE = 0.7F;
|
||||
static constexpr float VELX_NEGATIVE = -0.7F;
|
||||
|
||||
static constexpr int MOVING_ANIMATION = 0;
|
||||
static constexpr int POP_ANIMATION = 1;
|
||||
static constexpr int BORN_ANIMATION = 2;
|
||||
|
||||
static constexpr std::array<float, 5> SPEED = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F};
|
||||
|
||||
static constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string> // Para allocator, char_traits, operator==, string, operator<=>, basic_string, stoi, getline
|
||||
|
||||
#include "asset.h" // Para Asset
|
||||
#include "balloon.h" // Para BALLOON_SIZE, BalloonSize, BalloonType, BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||
#include "balloon.h" // Para Balloon::SIZE, Balloon::Size, Balloon::Type, Balloon::VELX_NEGATIVE, Balloon::VELX_POSITIVE
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "utils.h" // Para Zone, BLOCK
|
||||
|
||||
@@ -20,18 +20,18 @@ void BalloonFormations::initFormations() {
|
||||
const int DEFAULT_POS_Y = param.game.play_area.rect.h - BALLOON_SPAWN_HEIGHT;
|
||||
|
||||
const int X4_0 = param.game.play_area.rect.x;
|
||||
const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(3);
|
||||
const int X4_100 = param.game.play_area.rect.w - Balloon::SIZE.at(3);
|
||||
const int X3_0 = param.game.play_area.rect.x;
|
||||
const int X3_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(2);
|
||||
const int X3_100 = param.game.play_area.rect.w - Balloon::SIZE.at(2);
|
||||
const int X2_0 = param.game.play_area.rect.x;
|
||||
const int X2_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(1);
|
||||
const int X2_100 = param.game.play_area.rect.w - Balloon::SIZE.at(1);
|
||||
const int X1_0 = param.game.play_area.rect.x;
|
||||
const int X1_50 = param.game.play_area.center_x - (BALLOON_SIZE.at(0) / 2);
|
||||
const int X1_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(0);
|
||||
const int X1_50 = param.game.play_area.center_x - (Balloon::SIZE.at(0) / 2);
|
||||
const int X1_100 = param.game.play_area.rect.w - Balloon::SIZE.at(0);
|
||||
|
||||
// Variables calculadas para posiciones especiales
|
||||
const int QUARTER1_X4 = param.game.play_area.first_quarter_x - (BALLOON_SIZE.at(3) / 2);
|
||||
const int QUARTER3_X4 = param.game.play_area.third_quarter_x - (BALLOON_SIZE.at(3) / 2);
|
||||
const int QUARTER1_X4 = param.game.play_area.first_quarter_x - (Balloon::SIZE.at(3) / 2);
|
||||
const int QUARTER3_X4 = param.game.play_area.third_quarter_x - (Balloon::SIZE.at(3) / 2);
|
||||
|
||||
// Mapa de variables para reemplazar en el archivo
|
||||
std::map<std::string, float> variables = {
|
||||
@@ -47,12 +47,12 @@ void BalloonFormations::initFormations() {
|
||||
{"QUARTER1_X4", QUARTER1_X4},
|
||||
{"QUARTER3_X4", QUARTER3_X4},
|
||||
{"DEFAULT_POS_Y", DEFAULT_POS_Y},
|
||||
{"BALLOON_SIZE_0", BALLOON_SIZE.at(0)},
|
||||
{"BALLOON_SIZE_1", BALLOON_SIZE.at(1)},
|
||||
{"BALLOON_SIZE_2", BALLOON_SIZE.at(2)},
|
||||
{"BALLOON_SIZE_3", BALLOON_SIZE.at(3)},
|
||||
{"RIGHT", BALLOON_VELX_POSITIVE},
|
||||
{"LEFT", BALLOON_VELX_NEGATIVE}};
|
||||
{"BALLOON_SIZE_0", Balloon::SIZE.at(0)},
|
||||
{"BALLOON_SIZE_1", Balloon::SIZE.at(1)},
|
||||
{"BALLOON_SIZE_2", Balloon::SIZE.at(2)},
|
||||
{"BALLOON_SIZE_3", Balloon::SIZE.at(3)},
|
||||
{"RIGHT", Balloon::VELX_POSITIVE},
|
||||
{"LEFT", Balloon::VELX_NEGATIVE}};
|
||||
|
||||
balloon_formation_.reserve(NUMBER_OF_BALLOON_FORMATIONS);
|
||||
|
||||
@@ -138,21 +138,21 @@ auto BalloonFormations::parseBalloonLine(const std::string& line, const std::map
|
||||
int y = evaluateExpression(tokens.at(2), variables);
|
||||
float vel_x = evaluateExpression(tokens.at(3), variables);
|
||||
|
||||
BalloonType type = (tokens.at(4) == "BALLOON") ? BalloonType::BALLOON : BalloonType::FLOATER;
|
||||
Balloon::Type type = (tokens.at(4) == "BALLOON") ? Balloon::Type::BALLOON : Balloon::Type::FLOATER;
|
||||
|
||||
BalloonSize size;
|
||||
Balloon::Size size;
|
||||
if (tokens.at(5) == "SIZE_0") {
|
||||
size = BalloonSize::SIZE_0;
|
||||
desp = desp * (BALLOON_SIZE.at(0) + 1);
|
||||
size = Balloon::Size::SIZE_0;
|
||||
desp = desp * (Balloon::SIZE.at(0) + 1);
|
||||
} else if (tokens.at(5) == "SIZE_1") {
|
||||
size = BalloonSize::SIZE_1;
|
||||
desp = desp * (BALLOON_SIZE.at(1) + 1);
|
||||
size = Balloon::Size::SIZE_1;
|
||||
desp = desp * (Balloon::SIZE.at(1) + 1);
|
||||
} else if (tokens.at(5) == "SIZE_2") {
|
||||
size = BalloonSize::SIZE_2;
|
||||
desp = desp * (BALLOON_SIZE.at(2) + 1);
|
||||
size = Balloon::Size::SIZE_2;
|
||||
desp = desp * (Balloon::SIZE.at(2) + 1);
|
||||
} else if (tokens.at(5) == "SIZE_3") {
|
||||
size = BalloonSize::SIZE_3;
|
||||
desp = desp * (BALLOON_SIZE.at(3) + 1);
|
||||
size = Balloon::Size::SIZE_3;
|
||||
desp = desp * (Balloon::SIZE.at(3) + 1);
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -230,7 +230,7 @@ void BalloonFormations::createFloaterVariants() {
|
||||
for (int i = 0; i < balloon_formation_.at(k).number_of_balloons; i++) {
|
||||
const auto& original = balloon_formation_.at(k).init.at(i);
|
||||
floater_params.emplace_back(
|
||||
original.x, original.y, original.vel_x, BalloonType::FLOATER, original.size, original.creation_counter);
|
||||
original.x, original.y, original.vel_x, Balloon::Type::FLOATER, original.size, original.creation_counter);
|
||||
}
|
||||
|
||||
balloon_formation_.at(k + 50) = BalloonFormationUnit(
|
||||
@@ -240,10 +240,10 @@ void BalloonFormations::createFloaterVariants() {
|
||||
|
||||
void BalloonFormations::addTestFormation() {
|
||||
std::vector<BalloonFormationParams> test_params = {
|
||||
{10, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE_0, 200},
|
||||
{50, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE_1, 200},
|
||||
{90, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE_2, 200},
|
||||
{140, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE_3, 200}};
|
||||
{10, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SIZE_0, 200},
|
||||
{50, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SIZE_1, 200},
|
||||
{90, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SIZE_2, 200},
|
||||
{140, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SIZE_3, 200}};
|
||||
|
||||
balloon_formation_.at(99) = BalloonFormationUnit(4, test_params);
|
||||
}
|
||||
@@ -254,12 +254,12 @@ void BalloonFormations::loadDefaultFormations() {
|
||||
|
||||
const int DEFAULT_POS_Y = param.game.play_area.rect.h - BALLOON_SPAWN_HEIGHT;
|
||||
const int X4_0 = param.game.play_area.rect.x;
|
||||
const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(3);
|
||||
const int X4_100 = param.game.play_area.rect.w - Balloon::SIZE.at(3);
|
||||
|
||||
// Formación básica #00
|
||||
std::vector<BalloonFormationParams> basic_formation = {
|
||||
BalloonFormationParams(X4_0, DEFAULT_POS_Y, BALLOON_VELX_POSITIVE, BalloonType::BALLOON, BalloonSize::SIZE_3, CREATION_TIME),
|
||||
BalloonFormationParams(X4_100, DEFAULT_POS_Y, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE_3, CREATION_TIME)};
|
||||
BalloonFormationParams(X4_0, DEFAULT_POS_Y, Balloon::VELX_POSITIVE, Balloon::Type::BALLOON, Balloon::Size::SIZE_3, CREATION_TIME),
|
||||
BalloonFormationParams(X4_100, DEFAULT_POS_Y, Balloon::VELX_NEGATIVE, Balloon::Type::BALLOON, Balloon::Size::SIZE_3, CREATION_TIME)};
|
||||
balloon_formation_.emplace_back(2, basic_formation);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "balloon.h" // Para BalloonSize, BalloonType
|
||||
#include "balloon.h" // Para Balloon::Size, Balloon::Type
|
||||
|
||||
// --- Constantes de configuración ---
|
||||
|
||||
@@ -15,15 +15,15 @@ struct BalloonFormationParams {
|
||||
int x = 0; // Posición en el eje X donde crear el globo
|
||||
int y = 0; // Posición en el eje Y donde crear el globo
|
||||
float vel_x = 0.0F; // Velocidad inicial en el eje X
|
||||
BalloonType type = BalloonType::BALLOON; // Tipo de globo
|
||||
BalloonSize size = BalloonSize::SIZE_0; // Tamaño de globo
|
||||
Balloon::Type type = Balloon::Type::BALLOON; // Tipo de globo
|
||||
Balloon::Size size = Balloon::Size::SIZE_0; // Tamaño de globo
|
||||
int creation_counter = 0; // Temporizador para la creación del globo
|
||||
|
||||
// Constructor por defecto
|
||||
BalloonFormationParams() = default;
|
||||
|
||||
// Constructor con parámetros
|
||||
BalloonFormationParams(int x_val, int y_val, float vel_x_val, BalloonType type_val, BalloonSize size_val, int creation_counter_val)
|
||||
BalloonFormationParams(int x_val, int y_val, float vel_x_val, Balloon::Type type_val, Balloon::Size size_val, int creation_counter_val)
|
||||
: x(x_val), y(y_val), vel_x(vel_x_val), type(type_val), size(size_val), creation_counter(creation_counter_val) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ BalloonManager::BalloonManager()
|
||||
|
||||
// Inicializa
|
||||
void BalloonManager::init() {
|
||||
// Limpia
|
||||
balloon_textures_.clear();
|
||||
balloon_animations_.clear();
|
||||
explosions_textures_.clear();
|
||||
explosions_animations_.clear();
|
||||
|
||||
// Texturas - Globos
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon0.png"));
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon1.png"));
|
||||
@@ -49,10 +55,10 @@ void BalloonManager::init() {
|
||||
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion3.ani"));
|
||||
|
||||
// Añade texturas
|
||||
explosions_->addTexture(0, explosions_textures_[0], explosions_animations_[0]);
|
||||
explosions_->addTexture(1, explosions_textures_[1], explosions_animations_[1]);
|
||||
explosions_->addTexture(2, explosions_textures_[2], explosions_animations_[2]);
|
||||
explosions_->addTexture(3, explosions_textures_[3], explosions_animations_[3]);
|
||||
explosions_->addTexture(0, explosions_textures_.at(0), explosions_animations_.at(0));
|
||||
explosions_->addTexture(1, explosions_textures_.at(1), explosions_animations_.at(1));
|
||||
explosions_->addTexture(2, explosions_textures_.at(2), explosions_animations_.at(2));
|
||||
explosions_->addTexture(3, explosions_textures_.at(3), explosions_animations_.at(3));
|
||||
}
|
||||
|
||||
// Actualiza
|
||||
@@ -121,8 +127,8 @@ void BalloonManager::deploySet(int set_number) {
|
||||
const auto SET = balloon_formations_->getSet(set_number);
|
||||
const auto NUM_ENEMIES = SET.number_of_balloons;
|
||||
for (int i = 0; i < NUM_ENEMIES; ++i) {
|
||||
auto p = SET.init[i];
|
||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
auto balloon = SET.init[i];
|
||||
createBalloon(balloon.x, balloon.y, balloon.type, balloon.size, balloon.vel_x, balloon_speed_, balloon.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +137,8 @@ void BalloonManager::deploySet(int set_number, int y) {
|
||||
const auto SET = balloon_formations_->getSet(set_number);
|
||||
const auto NUM_ENEMIES = SET.number_of_balloons;
|
||||
for (int i = 0; i < NUM_ENEMIES; ++i) {
|
||||
auto p = SET.init[i];
|
||||
createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
auto balloon = SET.init[i];
|
||||
createBalloon(balloon.x, y, balloon.type, balloon.size, balloon.vel_x, balloon_speed_, balloon.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para Uint8
|
||||
#include <bits/std_abs.h> // Para abs
|
||||
|
||||
#include <algorithm> // Para max, min
|
||||
#include <array> // Para array
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "asset.h" // Para Asset
|
||||
#include "audio.h" // Para Audio
|
||||
#include "background.h" // Para Background
|
||||
#include "balloon.h" // Para Balloon, BALLOON_SPEED
|
||||
#include "balloon.h" // Para Balloon, Balloon::SPEED
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
||||
#include "color.h" // Para Color, FLASH_COLOR
|
||||
@@ -1539,21 +1539,21 @@ void Game::initDifficultyVars() {
|
||||
// Variables relacionadas con la dificultad
|
||||
switch (difficulty_) {
|
||||
case Difficulty::Code::EASY: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||
balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(0));
|
||||
difficulty_score_multiplier_ = 0.5F;
|
||||
scoreboard_->setColor(param.scoreboard.easy_color);
|
||||
break;
|
||||
}
|
||||
|
||||
case Difficulty::Code::NORMAL: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||
balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(0));
|
||||
difficulty_score_multiplier_ = 1.0F;
|
||||
scoreboard_->setColor(param.scoreboard.normal_color);
|
||||
break;
|
||||
}
|
||||
|
||||
case Difficulty::Code::HARD: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
|
||||
balloon_manager_->setDefaultBalloonSpeed(Balloon::SPEED.at(4));
|
||||
difficulty_score_multiplier_ = 1.5F;
|
||||
scoreboard_->setColor(param.scoreboard.hard_color);
|
||||
break;
|
||||
@@ -1768,9 +1768,11 @@ void Game::checkAndUpdateBalloonSpeed() {
|
||||
constexpr std::array<float, 4> 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
|
||||
// Si la velocidad actual del globo es la correspondiente al umbral "i" y el porcentaje de progreso ha superado ese umbral
|
||||
if (balloon_manager_->getBalloonSpeed() == Balloon::SPEED.at(i) && PERCENT > THRESHOLDS.at(i)) {
|
||||
// Sube la velocidad al siguiente nivel (i + 1)
|
||||
balloon_manager_->setBalloonSpeed(Balloon::SPEED.at(i + 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user