Continuem estandaritzant noms
This commit is contained in:
@@ -7,109 +7,115 @@
|
||||
#include "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text)
|
||||
: text(std::move(text))
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
: text_(std::move(text_))
|
||||
{
|
||||
// Copia punteros a los objetos
|
||||
input = Input::get();
|
||||
input_ = Input::get();
|
||||
|
||||
// Inicializa variables
|
||||
enabled = false;
|
||||
x = param.game.width / 2;
|
||||
y = param.title.press_start_position;
|
||||
indexController = 0;
|
||||
indexButton = 0;
|
||||
enabled_ = false;
|
||||
x_ = param.game.width / 2;
|
||||
y_ = param.title.press_start_position;
|
||||
index_controller_ = 0;
|
||||
index_button_ = 0;
|
||||
|
||||
buttons.clear();
|
||||
db_button_t button;
|
||||
buttons_.clear();
|
||||
DefineButtonsButton button;
|
||||
|
||||
button.label = lang::getText(95);
|
||||
button.input = input_fire_left;
|
||||
button.button = SDL_CONTROLLER_BUTTON_X;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(96);
|
||||
button.input = input_fire_center;
|
||||
button.button = SDL_CONTROLLER_BUTTON_Y;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(97);
|
||||
button.input = input_fire_right;
|
||||
button.button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(98);
|
||||
button.input = input_start;
|
||||
button.button = SDL_CONTROLLER_BUTTON_START;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
button.label = lang::getText(99);
|
||||
button.input = input_exit;
|
||||
button.button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
buttons.push_back(button);
|
||||
buttons_.push_back(button);
|
||||
|
||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
controllerNames.push_back(input->getControllerName(i));
|
||||
controller_names_.push_back(input_->getControllerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void DefineButtons::render()
|
||||
{
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
text->writeCentered(x, y - 10, lang::getText(100) + std::to_string(options.controller[indexController].player_id));
|
||||
text->writeCentered(x, y, controllerNames[indexController]);
|
||||
text->writeCentered(x, y + 10, buttons[indexButton].label);
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller[index_controller_].player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_[index_controller_]);
|
||||
text_->writeCentered(x_, y_ + 10, buttons_[index_button_].label);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent *event)
|
||||
{
|
||||
int i = input->getJoyIndex(event->which);
|
||||
int i = input_->getJoyIndex(event->which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != indexController)
|
||||
if (i != index_controller_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons[indexButton].button = (SDL_GameControllerButton)event->button;
|
||||
buttons_[index_button_].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
// Asigna los botones definidos al input
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (int i = 0; i < (int)buttons.size(); ++i)
|
||||
for (int i = 0; i < (int)buttons_.size(); ++i)
|
||||
{
|
||||
input->bindGameControllerButton(indexController, buttons[i].input, buttons[i].button);
|
||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void DefineButtons::checkInput()
|
||||
{
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::options = section::OPTIONS_QUIT_NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
{
|
||||
doControllerButtonDown(&event.cbutton);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,11 +124,11 @@ void DefineButtons::checkInput()
|
||||
// Habilita el objeto
|
||||
bool DefineButtons::enable(int index)
|
||||
{
|
||||
if (index < input->getNumControllers())
|
||||
if (index < input_->getNumControllers())
|
||||
{
|
||||
enabled = true;
|
||||
indexController = index;
|
||||
indexButton = 0;
|
||||
enabled_ = true;
|
||||
index_controller_ = index;
|
||||
index_button_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,29 +138,29 @@ bool DefineButtons::enable(int index)
|
||||
// Comprueba si está habilitado
|
||||
bool DefineButtons::isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
indexButton++;
|
||||
index_button_++;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (indexButton == (int)buttons.size())
|
||||
if (index_button_ == (int)buttons_.size())
|
||||
{
|
||||
// Asigna los botones definidos al input
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
input->allActive(indexController);
|
||||
input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
indexButton = 0;
|
||||
indexController = 0;
|
||||
enabled = false;
|
||||
index_button_ = 0;
|
||||
index_controller_ = 0;
|
||||
enabled_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,10 +168,10 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
options.controller[indexController].name = input->getControllerName(indexController);
|
||||
for (int j = 0; j < (int)options.controller[indexController].inputs.size(); ++j)
|
||||
options.controller[index_controller_].name = input_->getControllerName(index_controller_);
|
||||
for (int j = 0; j < (int)options.controller[index_controller_].inputs.size(); ++j)
|
||||
{
|
||||
options.controller[indexController].buttons[j] = input->getControllerBinding(indexController, options.controller[indexController].inputs[j]);
|
||||
options.controller[index_controller_].buttons[j] = input_->getControllerBinding(index_controller_, options.controller[index_controller_].inputs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for inputs_e
|
||||
#include <SDL2/SDL_events.h> // for SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for inputs_e
|
||||
#include "text.h"
|
||||
#include <memory>
|
||||
|
||||
struct db_button_t
|
||||
struct DefineButtonsButton
|
||||
{
|
||||
std::string label; // Texto en pantalla para el botón
|
||||
inputs_e input; // Input asociado
|
||||
@@ -20,17 +20,17 @@ class DefineButtons
|
||||
{
|
||||
private:
|
||||
// Objetos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
std::shared_ptr<Text> text; // Objeto para escribir texto
|
||||
Input *input_; // Objeto pata gestionar la entrada
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
bool enabled; // Indica si el objeto está habilitado
|
||||
int x; // Posición donde dibujar el texto
|
||||
int y; // Posición donde dibujar el texto
|
||||
std::vector<db_button_t> buttons; // Vector con las nuevas definiciones de botones/acciones
|
||||
int indexController; // Indice del controlador a reasignar
|
||||
int indexButton; // Indice para saber qué bot´çon se está definiendo
|
||||
std::vector<std::string> controllerNames; // Nombres de los mandos
|
||||
bool enabled_; // Indica si el objeto está habilitado
|
||||
int x_; // Posición donde dibujar el texto
|
||||
int y_; // Posición donde dibujar el texto
|
||||
std::vector<DefineButtonsButton> buttons_; // Vector con las nuevas definiciones de botones/acciones
|
||||
int index_controller_; // Indice del controlador a reasignar
|
||||
int index_button_; // Indice para saber qué bot´çon se está definiendo
|
||||
std::vector<std::string> controller_names_; // Nombres de los mandos
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void incIndexButton();
|
||||
|
||||
@@ -60,7 +60,7 @@ Director::Director(int argc, char *argv[])
|
||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executablePath);
|
||||
Asset::init(executable_path_);
|
||||
|
||||
// Si falta algún fichero no inicia el programa
|
||||
if (!setFileList())
|
||||
@@ -75,7 +75,7 @@ Director::Director(int argc, char *argv[])
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = paramFileArgument == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
const std::string paramFilePath = param_file_argument_ == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParams(paramFilePath);
|
||||
|
||||
@@ -90,7 +90,7 @@ Director::Director(int argc, char *argv[])
|
||||
initJailAudio();
|
||||
|
||||
// Inicializa el texto de debug
|
||||
dbg_init(renderer);
|
||||
dbg_init(renderer_);
|
||||
|
||||
// Crea los objetos
|
||||
lang::loadFromFile(getLangFile((lang::lang_e)options.game.language));
|
||||
@@ -98,7 +98,7 @@ Director::Director(int argc, char *argv[])
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
|
||||
Screen::init(window, renderer);
|
||||
Screen::init(window_, renderer_);
|
||||
|
||||
OnScreenHelp::init();
|
||||
|
||||
@@ -120,11 +120,11 @@ Director::~Director()
|
||||
Screen::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
sounds.clear();
|
||||
musics.clear();
|
||||
sounds_.clear();
|
||||
musics_.clear();
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
@@ -290,8 +290,8 @@ bool Director::initSDL()
|
||||
}
|
||||
#endif // NO_SHADERS
|
||||
// Crea la ventana
|
||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||
if (!window)
|
||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||
if (!window_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
@@ -310,9 +310,9 @@ bool Director::initSDL()
|
||||
// La aceleración se activa según el define
|
||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||
#endif
|
||||
renderer = SDL_CreateRenderer(window, -1, flags);
|
||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||
|
||||
if (!renderer)
|
||||
if (!renderer_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
@@ -322,14 +322,14 @@ bool Director::initSDL()
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(renderer, param.game.width, param.game.height);
|
||||
SDL_RenderSetIntegerScale(renderer, static_cast<SDL_bool>(options.video.integer_scale));
|
||||
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
||||
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,8 +350,8 @@ bool Director::setFileList()
|
||||
#endif
|
||||
|
||||
// Ficheros de configuración
|
||||
Asset::get()->add(systemFolder + "/config.txt", AssetType::DATA, false, true);
|
||||
Asset::get()->add(systemFolder + "/score.bin", AssetType::DATA, false, true);
|
||||
Asset::get()->add(system_folder_ + "/config.txt", AssetType::DATA, false, true);
|
||||
Asset::get()->add(system_folder_ + "/score.bin", AssetType::DATA, false, true);
|
||||
Asset::get()->add(prefix + "/data/config/param_320x240.txt", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/config/param_320x256.txt", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/config/demo1.bin", AssetType::DATA);
|
||||
@@ -493,17 +493,17 @@ void Director::loadParams(std::string filepath)
|
||||
void Director::checkProgramArguments(int argc, char *argv[])
|
||||
{
|
||||
// Establece la ruta del programa
|
||||
executablePath = argv[0];
|
||||
executable_path_ = argv[0];
|
||||
|
||||
// Valores por defecto
|
||||
paramFileArgument = "";
|
||||
param_file_argument_ = "";
|
||||
|
||||
// Comprueba el resto de parametros
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (strcmp(argv[i], "--320x240") == 0)
|
||||
{
|
||||
paramFileArgument = argv[i];
|
||||
param_file_argument_ = argv[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -512,25 +512,36 @@ void Director::checkProgramArguments(int argc, char *argv[])
|
||||
void Director::createSystemFolder(std::string folder)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
system_folder_ = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
#elif __APPLE__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
system_folder_ = std::string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
#elif __linux__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/.config/" + folder;
|
||||
system_folder_ = std::string(homedir) + "/.config/" + folder;
|
||||
|
||||
{
|
||||
// Intenta crear ".config", per si no existeix
|
||||
std::string config_base_folder = std::string(homedir) + "/.config";
|
||||
int ret = mkdir(config_base_folder.c_str(), S_IRWXU);
|
||||
if (ret == -1 && errno != EEXIST)
|
||||
{
|
||||
printf("ERROR CREATING CONFIG BASE FOLDER.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct stat st = {0};
|
||||
if (stat(systemFolder.c_str(), &st) == -1)
|
||||
if (stat(system_folder_.c_str(), &st) == -1)
|
||||
{
|
||||
errno = 0;
|
||||
#ifdef _WIN32
|
||||
int ret = mkdir(systemFolder.c_str());
|
||||
int ret = mkdir(system_folder_.c_str());
|
||||
#else
|
||||
int ret = mkdir(systemFolder.c_str(), S_IRWXU);
|
||||
int ret = mkdir(system_folder_.c_str(), S_IRWXU);
|
||||
#endif
|
||||
|
||||
if (ret == -1)
|
||||
@@ -562,7 +573,7 @@ void Director::loadSounds()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds.clear();
|
||||
sounds_.clear();
|
||||
|
||||
for (auto l : list)
|
||||
{
|
||||
@@ -571,7 +582,7 @@ void Director::loadSounds()
|
||||
SoundFile temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadSound(l.c_str()); // Carga el fichero de audio
|
||||
sounds.push_back(temp);
|
||||
sounds_.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,7 +591,7 @@ void Director::loadMusics()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros musicales
|
||||
std::vector<std::string> list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics.clear();
|
||||
musics_.clear();
|
||||
|
||||
for (auto l : list)
|
||||
{
|
||||
@@ -589,7 +600,7 @@ void Director::loadMusics()
|
||||
MusicFile temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadMusic(l.c_str()); // Carga el fichero de audio
|
||||
musics.push_back(temp);
|
||||
musics_.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,7 +615,7 @@ void Director::runLogo()
|
||||
// Ejecuta la sección con la secuencia de introducción
|
||||
void Director::runIntro()
|
||||
{
|
||||
auto intro = new Intro(getMusic(musics, "intro.ogg"));
|
||||
auto intro = new Intro(getMusic(musics_, "intro.ogg"));
|
||||
intro->run();
|
||||
delete intro;
|
||||
}
|
||||
@@ -612,7 +623,7 @@ void Director::runIntro()
|
||||
// Ejecuta la sección con el titulo del juego
|
||||
void Director::runTitle()
|
||||
{
|
||||
auto title = new Title(getMusic(musics, "title.ogg"));
|
||||
auto title = new Title(getMusic(musics_, "title.ogg"));
|
||||
title->run();
|
||||
delete title;
|
||||
}
|
||||
@@ -622,7 +633,7 @@ void Director::runGame()
|
||||
{
|
||||
const auto playerID = section::options == section::OPTIONS_GAME_PLAY_1P ? 1 : 2;
|
||||
constexpr auto currentStage = 0;
|
||||
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics, "playing.ogg"));
|
||||
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
@@ -630,7 +641,7 @@ void Director::runGame()
|
||||
// Ejecuta la sección donde se muestran las instrucciones
|
||||
void Director::runInstructions()
|
||||
{
|
||||
auto instructions = new Instructions(getMusic(musics, "title.ogg"));
|
||||
auto instructions = new Instructions(getMusic(musics_, "title.ogg"));
|
||||
instructions->run();
|
||||
delete instructions;
|
||||
}
|
||||
@@ -638,7 +649,7 @@ void Director::runInstructions()
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void Director::runHiScoreTable()
|
||||
{
|
||||
auto hiScoreTable = new HiScoreTable(getMusic(musics, "title.ogg"));
|
||||
auto hiScoreTable = new HiScoreTable(getMusic(musics_, "title.ogg"));
|
||||
hiScoreTable->run();
|
||||
delete hiScoreTable;
|
||||
}
|
||||
|
||||
@@ -8,21 +8,21 @@
|
||||
#include "utils.h" // for MusicFile, SoundFile
|
||||
|
||||
// Textos
|
||||
#define WINDOW_CAPTION "Coffee Crisis Arcade Edition"
|
||||
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
||||
|
||||
class Director
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window; // La ventana donde dibujamos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Window *window_; // La ventana donde dibujamos
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
|
||||
// Variables
|
||||
std::string executablePath; // Path del ejecutable
|
||||
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||
std::string paramFileArgument; // Argumento para gestionar el fichero con los parametros del programa
|
||||
std::vector<SoundFile> sounds; // Vector con los sonidos
|
||||
std::vector<MusicFile> musics; // Vector con las musicas
|
||||
std::string executable_path_; // Path del ejecutable
|
||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
||||
std::vector<SoundFile> sounds_; // Vector con los sonidos
|
||||
std::vector<MusicFile> musics_; // Vector con las musicas
|
||||
|
||||
// Inicializa jail_audio
|
||||
void initJailAudio();
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
void initInput();
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
void loadParams(std::string filepath);
|
||||
void loadParams(std::string file_path);
|
||||
|
||||
// Crea el indice de ficheros
|
||||
bool setFileList();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,36 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
||||
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
||||
constexpr int NUMBER_OF_ENEMY_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION = 50;
|
||||
|
||||
// Estructuras
|
||||
struct enemyInits_t
|
||||
struct EnemyFormationInit
|
||||
{
|
||||
int x; // Posición en el eje X donde crear al enemigo
|
||||
int y; // Posición en el eje Y donde crear al enemigo
|
||||
float velX; // Velocidad inicial en el eje X
|
||||
int kind; // Tipo de enemigo
|
||||
int creationCounter; // Temporizador para la creación del enemigo
|
||||
int x; // Posición en el eje X donde crear al enemigo
|
||||
int y; // Posición en el eje Y donde crear al enemigo
|
||||
float vel_x; // Velocidad inicial en el eje X
|
||||
int kind; // Tipo de enemigo
|
||||
int creation_counter; // Temporizador para la creación del enemigo
|
||||
};
|
||||
|
||||
struct enemyFormation_t // Contiene la información de una formación enemiga
|
||||
struct EnemyFormationUnit // Contiene la información de una formación enemiga
|
||||
{
|
||||
int numberOfEnemies; // Cantidad de enemigos que forman la formación
|
||||
enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||
int number_of_enemies; // Cantidad de enemigos que forman la formación
|
||||
EnemyFormationInit init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||
};
|
||||
|
||||
struct enemyPool_t
|
||||
struct EnemyFormationPool
|
||||
{
|
||||
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
|
||||
EnemyFormationUnit *set[10]; // Conjunto de formaciones enemigas
|
||||
};
|
||||
|
||||
struct stage_t // Contiene todas las variables relacionadas con una fase
|
||||
struct Stage // Contiene todas las variables relacionadas con una fase
|
||||
{
|
||||
enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase
|
||||
int powerToComplete; // Cantidad de poder que se necesita para completar la fase
|
||||
int maxMenace; // Umbral máximo de amenaza de la fase
|
||||
int minMenace; // Umbral mínimo de amenaza de la fase
|
||||
int number; // Número de fase
|
||||
EnemyFormationPool *enemy_pool; // El conjunto de formaciones enemigas de la fase
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int number; // Número de fase
|
||||
};
|
||||
|
||||
// Clase EnemyFormations, para gestionar las formaciones enemigas
|
||||
@@ -38,9 +38,9 @@ class EnemyFormations
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
stage_t stage[10]; // Variable con los datos de cada pantalla
|
||||
enemyFormation_t enemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
enemyPool_t enemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
Stage stage_[10]; // Variable con los datos de cada pantalla
|
||||
EnemyFormationUnit enemy_formation_[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
EnemyFormationPool enemy_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void initEnemyFormations();
|
||||
@@ -59,5 +59,5 @@ public:
|
||||
~EnemyFormations() = default;
|
||||
|
||||
// Devuelve una fase
|
||||
stage_t getStage(int index) const;
|
||||
Stage getStage(int index) const;
|
||||
};
|
||||
@@ -11,12 +11,12 @@ EnterName::EnterName()
|
||||
void EnterName::init()
|
||||
{
|
||||
// Obtiene el puntero al nombre
|
||||
name = "A";
|
||||
name_ = "A";
|
||||
|
||||
// Inicia la lista de caracteres permitidos
|
||||
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
||||
pos = 0;
|
||||
numCharacters = (int)characterList.size();
|
||||
character_list_ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
||||
pos_ = 0;
|
||||
num_characters_ = (int)character_list_.size();
|
||||
|
||||
// Pone la lista de indices para que refleje el nombre
|
||||
updateCharacterIndex();
|
||||
@@ -28,24 +28,24 @@ void EnterName::init()
|
||||
// Incrementa la posición
|
||||
void EnterName::incPos()
|
||||
{
|
||||
pos++;
|
||||
pos = std::min(pos, NAME_LENGHT - 1);
|
||||
pos_++;
|
||||
pos_ = std::min(pos_, NAME_LENGHT - 1);
|
||||
}
|
||||
|
||||
// Decrementa la posición
|
||||
void EnterName::decPos()
|
||||
{
|
||||
pos--;
|
||||
pos = std::max(pos, 0);
|
||||
pos_--;
|
||||
pos_ = std::max(pos_, 0);
|
||||
}
|
||||
|
||||
// Incrementa el índice
|
||||
void EnterName::incIndex()
|
||||
{
|
||||
++characterIndex[pos];
|
||||
if (characterIndex[pos] >= numCharacters)
|
||||
++character_index_[pos_];
|
||||
if (character_index_[pos_] >= num_characters_)
|
||||
{
|
||||
characterIndex[pos] = 0;
|
||||
character_index_[pos_] = 0;
|
||||
}
|
||||
updateName();
|
||||
}
|
||||
@@ -53,10 +53,10 @@ void EnterName::incIndex()
|
||||
// Decrementa el índice
|
||||
void EnterName::decIndex()
|
||||
{
|
||||
--characterIndex[pos];
|
||||
if (characterIndex[pos] < 0)
|
||||
--character_index_[pos_];
|
||||
if (character_index_[pos_] < 0)
|
||||
{
|
||||
characterIndex[pos] = numCharacters - 1;
|
||||
character_index_[pos_] = num_characters_ - 1;
|
||||
}
|
||||
updateName();
|
||||
}
|
||||
@@ -64,10 +64,10 @@ void EnterName::decIndex()
|
||||
// Actualiza la variable
|
||||
void EnterName::updateName()
|
||||
{
|
||||
name.clear();
|
||||
name_.clear();
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
name.push_back(characterList[characterIndex[i]]);
|
||||
name_.push_back(character_list_[character_index_[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,22 +77,22 @@ void EnterName::updateCharacterIndex()
|
||||
// Rellena de espacios
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
characterIndex[i] = 0;
|
||||
character_index_[i] = 0;
|
||||
}
|
||||
|
||||
// Coloca los índices en funcion de los caracteres que forman el nombre
|
||||
for (int i = 0; i < (int)name.size(); ++i)
|
||||
for (int i = 0; i < (int)name_.size(); ++i)
|
||||
{
|
||||
characterIndex[i] = findIndex(name.at(i));
|
||||
character_index_[i] = findIndex(name_.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Encuentra el indice de un caracter en "characterList"
|
||||
// Encuentra el indice de un caracter en "character_list_"
|
||||
int EnterName::findIndex(char character)
|
||||
{
|
||||
for (int i = 0; i < (int)characterList.size(); ++i)
|
||||
for (int i = 0; i < (int)character_list_.size(); ++i)
|
||||
{
|
||||
if (character == characterList[i])
|
||||
if (character == character_list_[i])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -103,11 +103,11 @@ int EnterName::findIndex(char character)
|
||||
// Obtiene el nombre
|
||||
std::string EnterName::getName() const
|
||||
{
|
||||
return name;
|
||||
return name_;
|
||||
}
|
||||
|
||||
// Obtiene la posición que se está editando
|
||||
int EnterName::getPos() const
|
||||
{
|
||||
return pos;
|
||||
return pos_;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define NAME_LENGHT 8
|
||||
constexpr int NAME_LENGHT = 8;
|
||||
|
||||
/*
|
||||
Un array, "characterList", contiene la lista de caracteres
|
||||
@@ -16,11 +16,11 @@
|
||||
class EnterName
|
||||
{
|
||||
private:
|
||||
std::string characterList; // Lista de todos los caracteres permitidos
|
||||
std::string name; // Nombre introducido
|
||||
int pos; // Posición a editar del nombre
|
||||
int numCharacters; // Cantidad de caracteres de la lista de caracteres
|
||||
int characterIndex[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||
std::string name_; // Nombre introducido
|
||||
int pos_; // Posición a editar del nombre
|
||||
int num_characters_; // Cantidad de caracteres de la lista de caracteres
|
||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
|
||||
// Actualiza la variable
|
||||
void updateName();
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include "explosions.h"
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Explosions::Explosions()
|
||||
{
|
||||
textures.clear();
|
||||
explosions.clear();
|
||||
textures_.clear();
|
||||
explosions_.clear();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Explosions::~Explosions()
|
||||
{
|
||||
explosions.clear();
|
||||
explosions_.clear();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void Explosions::update()
|
||||
{
|
||||
for (auto &explosion : explosions)
|
||||
for (auto &explosion : explosions_)
|
||||
{
|
||||
explosion->update();
|
||||
}
|
||||
@@ -30,7 +30,7 @@ void Explosions::update()
|
||||
// Dibuja el objeto en pantalla
|
||||
void Explosions::render()
|
||||
{
|
||||
for (auto &explosion : explosions)
|
||||
for (auto &explosion : explosions_)
|
||||
{
|
||||
explosion->render();
|
||||
}
|
||||
@@ -39,32 +39,32 @@ void Explosions::render()
|
||||
// Añade texturas al objeto
|
||||
void Explosions::addTexture(int size, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
|
||||
{
|
||||
explosion_texture_t temp;
|
||||
ExplosionTexture temp;
|
||||
temp.size = size;
|
||||
temp.texture = texture;
|
||||
temp.animation = animation;
|
||||
textures.push_back(temp);
|
||||
textures_.push_back(temp);
|
||||
}
|
||||
|
||||
// Añade una explosión
|
||||
void Explosions::add(int x, int y, int size)
|
||||
{
|
||||
const int index = getIndexBySize(size);
|
||||
auto sprite = std::make_unique<AnimatedSprite>(textures[index].texture, "", textures[index].animation);
|
||||
auto sprite = std::make_unique<AnimatedSprite>(textures_[index].texture, "", textures_[index].animation);
|
||||
sprite->setPos(x, y);
|
||||
explosions.push_back(std::move(sprite));
|
||||
explosions_.push_back(std::move(sprite));
|
||||
}
|
||||
|
||||
// Vacia el vector de elementos finalizados
|
||||
void Explosions::freeExplosions()
|
||||
{
|
||||
if (explosions.empty() == false)
|
||||
if (explosions_.empty() == false)
|
||||
{
|
||||
for (int i = explosions.size() - 1; i >= 0; --i)
|
||||
for (int i = explosions_.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (explosions[i]->animationIsCompleted())
|
||||
if (explosions_[i]->animationIsCompleted())
|
||||
{
|
||||
explosions.erase(explosions.begin() + i);
|
||||
explosions_.erase(explosions_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,9 +73,9 @@ void Explosions::freeExplosions()
|
||||
// Busca una textura a partir del tamaño
|
||||
int Explosions::getIndexBySize(int size)
|
||||
{
|
||||
for (int i = 0; i < (int)textures.size();++i)
|
||||
for (int i = 0; i < (int)textures_.size(); ++i)
|
||||
{
|
||||
if (size == textures[i].size)
|
||||
if (size == textures_[i].size)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "animated_sprite.h"
|
||||
#include <memory>
|
||||
#include "texture.h"
|
||||
|
||||
struct explosion_texture_t
|
||||
struct ExplosionTexture
|
||||
{
|
||||
std::shared_ptr<Texture>texture; // Textura para la explosión
|
||||
std::shared_ptr<Texture> texture; // Textura para la explosión
|
||||
std::vector<std::string> *animation; // Animación para la textura
|
||||
int size; // Tamaño de la explosión
|
||||
};
|
||||
@@ -18,8 +18,8 @@ class Explosions
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
std::vector<explosion_texture_t> textures; // Vector con las texturas a utilizar
|
||||
std::vector<std::unique_ptr<AnimatedSprite>> explosions; // Lista con todas las explosiones
|
||||
std::vector<ExplosionTexture> textures_; // Vector con las texturas a utilizar
|
||||
std::vector<std::unique_ptr<AnimatedSprite>> explosions_; // Lista con todas las explosiones
|
||||
|
||||
// Vacia el vector de elementos finalizados
|
||||
void freeExplosions();
|
||||
|
||||
247
source/fade.cpp
247
source/fade.cpp
@@ -7,12 +7,12 @@
|
||||
#include "utils.h" // for Param, ParamGame, ParamFade
|
||||
|
||||
// Constructor
|
||||
Fade::Fade(SDL_Renderer *renderer)
|
||||
: renderer(renderer)
|
||||
Fade::Fade(SDL_Renderer *renderer_)
|
||||
: renderer_(renderer_)
|
||||
{
|
||||
// Crea la textura donde dibujar el fade
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa las variables
|
||||
init();
|
||||
@@ -21,64 +21,65 @@ Fade::Fade(SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Fade::~Fade()
|
||||
{
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
backbuffer = nullptr;
|
||||
SDL_DestroyTexture(backbuffer_);
|
||||
backbuffer_ = nullptr;
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
void Fade::init()
|
||||
{
|
||||
type = FadeType::CENTER;
|
||||
mode = FadeMode::OUT;
|
||||
enabled = false;
|
||||
finished = false;
|
||||
counter = 0;
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
postDuration = 20;
|
||||
postCounter = 0;
|
||||
numSquaresWidth = param.fade.num_squares_width;
|
||||
numSquaresHeight = param.fade.num_squares_height;
|
||||
fadeRandomSquaresDelay = param.fade.random_squares_delay;
|
||||
fadeRandomSquaresMult = param.fade.random_squares_mult;
|
||||
type_ = FadeType::CENTER;
|
||||
mode_ = FadeMode::OUT;
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
counter_ = 0;
|
||||
r_ = 0;
|
||||
g_ = 0;
|
||||
b_ = 0;
|
||||
a_ = 0;
|
||||
post_duration_ = 20;
|
||||
post_counter_ = 0;
|
||||
num_squares_width_ = param.fade.num_squares_width;
|
||||
num_squares_height_ = param.fade.num_squares_height;
|
||||
fade_random_squares_delay_ = param.fade.random_squares_delay;
|
||||
fade_random_squares_mult_ = param.fade.random_squares_mult;
|
||||
}
|
||||
|
||||
// Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros
|
||||
void Fade::reset()
|
||||
{
|
||||
enabled = false;
|
||||
finished = false;
|
||||
counter = 0;
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
counter_ = 0;
|
||||
}
|
||||
|
||||
// Pinta una transición en pantalla
|
||||
void Fade::render()
|
||||
{
|
||||
if (enabled || finished)
|
||||
if (enabled_ || finished_)
|
||||
{
|
||||
SDL_RenderCopy(renderer, backbuffer, nullptr, nullptr);
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables internas
|
||||
void Fade::update()
|
||||
{
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
switch (type)
|
||||
switch (type_)
|
||||
{
|
||||
case FadeType::FULLSCREEN:
|
||||
{
|
||||
// Modifica la transparencia
|
||||
a = mode == FadeMode::OUT ? std::min(counter * 4, 255) : 255 - std::min(counter * 4, 255);
|
||||
a_ = mode_ == FadeMode::OUT ? std::min(counter_ * 4, 255) : 255 - std::min(counter_ * 4, 255);
|
||||
|
||||
SDL_SetTextureAlphaMod(backbuffer, a);
|
||||
SDL_SetTextureAlphaMod(backbuffer_, a_);
|
||||
|
||||
// Comprueba si ha terminado
|
||||
if (counter >= 255 / 4)
|
||||
if (counter_ >= 255 / 4)
|
||||
{
|
||||
finished = true;
|
||||
finished_ = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -86,62 +87,62 @@ void Fade::update()
|
||||
|
||||
case FadeType::CENTER:
|
||||
{
|
||||
// Dibuja sobre el backbuffer
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
// Dibuja sobre el backbuffer_
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||
|
||||
for (int i = 0; i < counter; i++)
|
||||
for (int i = 0; i < counter_; i++)
|
||||
{
|
||||
rect1.h = rect2.h = i * 4;
|
||||
rect2.y = param.game.height - (i * 4);
|
||||
rect1_.h = rect2_.h = i * 4;
|
||||
rect2_.y = param.game.height - (i * 4);
|
||||
|
||||
SDL_RenderFillRect(renderer, &rect1);
|
||||
SDL_RenderFillRect(renderer, &rect2);
|
||||
SDL_RenderFillRect(renderer_, &rect1_);
|
||||
SDL_RenderFillRect(renderer_, &rect2_);
|
||||
}
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
|
||||
// Comprueba si ha terminado
|
||||
if ((counter * 4) > param.game.height)
|
||||
if ((counter_ * 4) > param.game.height)
|
||||
{
|
||||
finished = true;
|
||||
a = 255;
|
||||
finished_ = true;
|
||||
a_ = 255;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FadeType::RANDOM_SQUARE:
|
||||
{
|
||||
if (counter % fadeRandomSquaresDelay == 0)
|
||||
if (counter_ % fade_random_squares_delay_ == 0)
|
||||
{
|
||||
// Dibuja sobre el backbuffer
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
// Dibuja sobre el backbuffer_
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||
|
||||
// Dibuja el cuadrado correspondiente
|
||||
const int index = std::min(counter / fadeRandomSquaresDelay, (numSquaresWidth * numSquaresHeight) - 1);
|
||||
for (int i = 0; i < fadeRandomSquaresMult; ++i)
|
||||
const int index = std::min(counter_ / fade_random_squares_delay_, (num_squares_width_ * num_squares_height_) - 1);
|
||||
for (int i = 0; i < fade_random_squares_mult_; ++i)
|
||||
{
|
||||
const int index2 = std::min(index * fadeRandomSquaresMult + i, (int)square.size() - 1);
|
||||
SDL_RenderFillRect(renderer, &square[index2]);
|
||||
const int index2 = std::min(index * fade_random_squares_mult_ + i, (int)square_.size() - 1);
|
||||
SDL_RenderFillRect(renderer_, &square_[index2]);
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado
|
||||
if (counter * fadeRandomSquaresMult / fadeRandomSquaresDelay >= numSquaresWidth * numSquaresHeight)
|
||||
if (counter_ * fade_random_squares_mult_ / fade_random_squares_delay_ >= num_squares_width_ * num_squares_height_)
|
||||
{
|
||||
finished = true;
|
||||
finished_ = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -150,47 +151,47 @@ void Fade::update()
|
||||
case FadeType::VENETIAN:
|
||||
{
|
||||
// Counter debe ir de 0 a 150
|
||||
if (square.back().h < param.fade.venetian_size)
|
||||
if (square_.back().h < param.fade.venetian_size)
|
||||
{
|
||||
// Dibuja sobre el backbuffer
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
// Dibuja sobre el backbuffer_
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
for (auto rect : square)
|
||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||
for (auto rect : square_)
|
||||
{
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
}
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
|
||||
const auto h = counter / 3;
|
||||
for (int i = 0; i < (int)square.size(); ++i)
|
||||
const auto h = counter_ / 3;
|
||||
for (int i = 0; i < (int)square_.size(); ++i)
|
||||
{
|
||||
// A partir del segundo rectangulo se pinta en función del anterior
|
||||
square[i].h = i == 0 ? h : std::max(square[i - 1].h - 3, 0);
|
||||
square_[i].h = i == 0 ? h : std::max(square_[i - 1].h - 3, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finished = true;
|
||||
finished_ = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (finished)
|
||||
if (finished_)
|
||||
{
|
||||
// Actualiza el contador
|
||||
postCounter == postDuration ? enabled = false : postCounter++;
|
||||
post_counter_ == post_duration_ ? enabled_ = false : post_counter_++;
|
||||
|
||||
// Deja el backbuffer todo del mismo color
|
||||
cleanBackbuffer(r, g, b, a);
|
||||
// Deja el backbuffer_ todo del mismo color
|
||||
cleanBackbuffer(r_, g_, b_, a_);
|
||||
}
|
||||
|
||||
counter++;
|
||||
counter_++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,67 +199,67 @@ void Fade::update()
|
||||
void Fade::activate()
|
||||
{
|
||||
// Si ya está habilitado, no hay que volverlo a activar
|
||||
if (enabled)
|
||||
if (enabled_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = true;
|
||||
finished = false;
|
||||
counter = 0;
|
||||
postCounter = 0;
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
counter_ = 0;
|
||||
post_counter_ = 0;
|
||||
|
||||
switch (type)
|
||||
switch (type_)
|
||||
{
|
||||
case FadeType::FULLSCREEN:
|
||||
{
|
||||
// Pinta el backbuffer de color sólido
|
||||
cleanBackbuffer(r, g, b, 255);
|
||||
// Pinta el backbuffer_ de color sólido
|
||||
cleanBackbuffer(r_, g_, b_, 255);
|
||||
break;
|
||||
}
|
||||
|
||||
case FadeType::CENTER:
|
||||
{
|
||||
rect1 = {0, 0, param.game.width, 0};
|
||||
rect2 = {0, 0, param.game.width, 0};
|
||||
a = 64;
|
||||
rect1_ = {0, 0, param.game.width, 0};
|
||||
rect2_ = {0, 0, param.game.width, 0};
|
||||
a_ = 64;
|
||||
break;
|
||||
}
|
||||
|
||||
case FadeType::RANDOM_SQUARE:
|
||||
{
|
||||
rect1 = {0, 0, param.game.width / numSquaresWidth, param.game.height / numSquaresHeight};
|
||||
square.clear();
|
||||
rect1_ = {0, 0, param.game.width / num_squares_width_, param.game.height / num_squares_height_};
|
||||
square_.clear();
|
||||
|
||||
// Añade los cuadrados al vector
|
||||
for (int i = 0; i < numSquaresWidth * numSquaresHeight; ++i)
|
||||
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i)
|
||||
{
|
||||
rect1.x = (i % numSquaresWidth) * rect1.w;
|
||||
rect1.y = (i / numSquaresWidth) * rect1.h;
|
||||
square.push_back(rect1);
|
||||
rect1_.x = (i % num_squares_width_) * rect1_.w;
|
||||
rect1_.y = (i / num_squares_width_) * rect1_.h;
|
||||
square_.push_back(rect1_);
|
||||
}
|
||||
|
||||
// Desordena el vector de cuadrados
|
||||
auto num = numSquaresWidth * numSquaresHeight;
|
||||
auto num = num_squares_width_ * num_squares_height_;
|
||||
while (num > 1)
|
||||
{
|
||||
auto num_arreu = rand() % num;
|
||||
SDL_Rect temp = square[num_arreu];
|
||||
square[num_arreu] = square[num - 1];
|
||||
square[num - 1] = temp;
|
||||
SDL_Rect temp = square_[num_arreu];
|
||||
square_[num_arreu] = square_[num - 1];
|
||||
square_[num - 1] = temp;
|
||||
num--;
|
||||
}
|
||||
|
||||
// Limpia la textura
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
a = mode == FadeMode::OUT ? 0 : 255;
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
a_ = mode_ == FadeMode::OUT ? 0 : 255;
|
||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
|
||||
// Deja el color listo para usar
|
||||
a = mode == FadeMode::OUT ? 255 : 0;
|
||||
a_ = mode_ == FadeMode::OUT ? 255 : 0;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -266,17 +267,17 @@ void Fade::activate()
|
||||
case FadeType::VENETIAN:
|
||||
{
|
||||
cleanBackbuffer(0, 0, 0, 0);
|
||||
rect1 = {0, 0, param.game.width, 0};
|
||||
square.clear();
|
||||
a = 255;
|
||||
rect1_ = {0, 0, param.game.width, 0};
|
||||
square_.clear();
|
||||
a_ = 255;
|
||||
|
||||
// Añade los cuadrados al vector
|
||||
const int max = param.game.height / param.fade.venetian_size;
|
||||
|
||||
for (int i = 0; i < max; ++i)
|
||||
{
|
||||
rect1.y = i * param.fade.venetian_size;
|
||||
square.push_back(rect1);
|
||||
rect1_.y = i * param.fade.venetian_size;
|
||||
square_.push_back(rect1_);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -287,53 +288,53 @@ void Fade::activate()
|
||||
// Comprueba si está activo
|
||||
bool Fade::isEnabled() const
|
||||
{
|
||||
return enabled;
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la transicion
|
||||
bool Fade::hasEnded() const
|
||||
{
|
||||
// Ha terminado cuando ha finalizado la transición y se ha deshabilitado
|
||||
return !enabled && finished;
|
||||
return !enabled_ && finished_;
|
||||
}
|
||||
|
||||
// Establece el tipo de fade
|
||||
void Fade::setType(FadeType type)
|
||||
void Fade::setType(FadeType type_)
|
||||
{
|
||||
this->type = type;
|
||||
type_ = type_;
|
||||
}
|
||||
|
||||
// Establece el modo de fade
|
||||
void Fade::setMode(FadeMode mode)
|
||||
{
|
||||
this->mode = mode;
|
||||
mode_ = mode;
|
||||
}
|
||||
|
||||
// Establece el color del fade
|
||||
void Fade::setColor(Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
this->r = r;
|
||||
this->g = g;
|
||||
this->b = b;
|
||||
r_ = r;
|
||||
g_ = g;
|
||||
b_ = b;
|
||||
}
|
||||
|
||||
// Establece la duración posterior
|
||||
void Fade::setPost(int value)
|
||||
{
|
||||
postDuration = value;
|
||||
post_duration_ = value;
|
||||
}
|
||||
|
||||
// Limpia el backbuffer
|
||||
void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
// Dibujamos sobre el backbuffer
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
// Dibujamos sobre el backbuffer_
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
// Pintamos la textura con el color del fade
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer_, r, g, b, a);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Vuelve a dejar el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
@@ -26,25 +26,25 @@ class Fade
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer con SDL_TEXTUREACCESS_TARGET
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer con SDL_TEXTUREACCESS_TARGET
|
||||
|
||||
// Variables
|
||||
FadeType type; // Tipo de fade a realizar
|
||||
FadeMode mode; // Modo de fade a realizar
|
||||
Uint16 counter; // Contador interno
|
||||
bool enabled; // Indica si el fade está activo
|
||||
bool finished; // Indica si ha terminado la transición
|
||||
Uint8 r, g, b, a; // Colores para el fade
|
||||
SDL_Rect rect1; // Rectangulo usado para crear los efectos de transición
|
||||
SDL_Rect rect2; // Rectangulo usado para crear los efectos de transición
|
||||
int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
|
||||
int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
|
||||
std::vector<SDL_Rect> square; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE
|
||||
int fadeRandomSquaresDelay; // Duración entre cada pintado de cuadrados
|
||||
int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez
|
||||
int postDuration; // Duración posterior del fade tras finalizar
|
||||
int postCounter; // Contador para la duración posterior
|
||||
FadeType type_; // Tipo de fade a realizar
|
||||
FadeMode mode_; // Modo de fade a realizar
|
||||
Uint16 counter_; // Contador interno
|
||||
bool enabled_; // Indica si el fade está activo
|
||||
bool finished_; // Indica si ha terminado la transición
|
||||
Uint8 r_, g_, b_, a_; // Colores para el fade
|
||||
SDL_Rect rect1_; // Rectangulo usado para crear los efectos de transición
|
||||
SDL_Rect rect2_; // Rectangulo usado para crear los efectos de transición
|
||||
int num_squares_width_; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
|
||||
int num_squares_height_; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
|
||||
std::vector<SDL_Rect> square_; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE
|
||||
int fade_random_squares_delay_; // Duración entre cada pintado de cuadrados
|
||||
int fade_random_squares_mult_; // Cantidad de cuadrados que se pintaran cada vez
|
||||
int post_duration_; // Duración posterior del fade tras finalizar
|
||||
int post_counter_; // Contador para la duración posterior
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "background.h" // for Background
|
||||
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BulletType::LEFT, BulletType::RIGHT
|
||||
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
|
||||
#include "enemy_formations.h" // for Stage, EnemyFormations, enemyIni...
|
||||
#include "explosions.h" // for Explosions
|
||||
#include "fade.h" // for Fade, FadeType::RANDOM_SQUARE, FADE_VEN...
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
@@ -241,7 +241,7 @@ void Game::init(int playerID)
|
||||
// Actualiza el numero de globos explotados según la fase de la demo
|
||||
for (int i = 0; i < currentStage; ++i)
|
||||
{
|
||||
balloonsPopped += enemyFormations->getStage(i).powerToComplete;
|
||||
balloonsPopped += enemyFormations->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Activa o no al otro jugador
|
||||
@@ -277,7 +277,7 @@ void Game::init(int playerID)
|
||||
totalPowerToCompleteGame = 0;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
totalPowerToCompleteGame += enemyFormations->getStage(i).powerToComplete;
|
||||
totalPowerToCompleteGame += enemyFormations->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Modo grabar demo
|
||||
@@ -719,16 +719,16 @@ void Game::deployEnemyFormation()
|
||||
|
||||
lastEnemyDeploy = set;
|
||||
|
||||
const stage_t stage = enemyFormations->getStage(currentStage);
|
||||
const auto numEnemies = stage.enemyPool->set[set]->numberOfEnemies;
|
||||
const Stage stage = enemyFormations->getStage(currentStage);
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemyPool->set[set]->init[i].x,
|
||||
stage.enemyPool->set[set]->init[i].y,
|
||||
stage.enemyPool->set[set]->init[i].kind,
|
||||
stage.enemyPool->set[set]->init[i].velX,
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
enemySpeed,
|
||||
stage.enemyPool->set[set]->init[i].creationCounter);
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
|
||||
enemyDeployCounter = 300;
|
||||
@@ -810,7 +810,7 @@ void Game::renderPlayers()
|
||||
// Comprueba si hay cambio de fase y actualiza las variables
|
||||
void Game::updateStage()
|
||||
{
|
||||
if (currentPower >= enemyFormations->getStage(currentStage).powerToComplete)
|
||||
if (currentPower >= enemyFormations->getStage(currentStage).power_to_complete)
|
||||
{
|
||||
// Cambio de fase
|
||||
currentStage++;
|
||||
@@ -1014,7 +1014,7 @@ void Game::decBalloonSpeed()
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void Game::updateBalloonSpeed()
|
||||
{
|
||||
const float percent = (float)currentPower / (float)enemyFormations->getStage(currentStage).powerToComplete;
|
||||
const float percent = (float)currentPower / (float)enemyFormations->getStage(currentStage).power_to_complete;
|
||||
if (enemySpeed == BALLOON_SPEED_1)
|
||||
{
|
||||
if (percent > 0.2f)
|
||||
@@ -1930,11 +1930,11 @@ void Game::updateMenace()
|
||||
}
|
||||
|
||||
const auto stage = enemyFormations->getStage(currentStage);
|
||||
const float percent = currentPower / stage.powerToComplete;
|
||||
const int difference = stage.maxMenace - stage.minMenace;
|
||||
const float percent = currentPower / stage.power_to_complete;
|
||||
const int difference = stage.max_menace - stage.min_menace;
|
||||
|
||||
// Aumenta el nivel de amenaza en función de la puntuación
|
||||
menaceThreshold = stage.minMenace + (difference * percent);
|
||||
menaceThreshold = stage.min_menace + (difference * percent);
|
||||
|
||||
// Si el nivel de amenza es inferior al umbral
|
||||
if (menaceCurrent < menaceThreshold)
|
||||
@@ -2538,15 +2538,15 @@ void Game::checkEvents()
|
||||
{
|
||||
const auto set = 0;
|
||||
const auto stage = enemyFormations->getStage(0);
|
||||
const auto numEnemies = stage.enemyPool->set[set]->numberOfEnemies;
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemyPool->set[set]->init[i].x,
|
||||
stage.enemyPool->set[set]->init[i].y,
|
||||
stage.enemyPool->set[set]->init[i].kind,
|
||||
stage.enemyPool->set[set]->init[i].velX,
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
enemySpeed,
|
||||
stage.enemyPool->set[set]->init[i].creationCounter);
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2650,7 +2650,7 @@ void Game::updateScoreboard()
|
||||
|
||||
// Resto de marcador
|
||||
scoreboard->setStage(enemyFormations->getStage(currentStage).number);
|
||||
scoreboard->setPower((float)currentPower / (float)enemyFormations->getStage(currentStage).powerToComplete);
|
||||
scoreboard->setPower((float)currentPower / (float)enemyFormations->getStage(currentStage).power_to_complete);
|
||||
scoreboard->setHiScore(hiScore.score);
|
||||
scoreboard->setHiScoreName(hiScore.name);
|
||||
|
||||
|
||||
@@ -13,24 +13,24 @@
|
||||
|
||||
// Constructor
|
||||
GameLogo::GameLogo(int x, int y)
|
||||
: x(x), y(y)
|
||||
: x_(x), y_(y)
|
||||
{
|
||||
// Crea los objetos
|
||||
dustTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
|
||||
coffeeTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
|
||||
crisisTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
|
||||
arcadeEditionTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
|
||||
dust_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
|
||||
coffee_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
|
||||
crisis_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
|
||||
arcade_edition_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
|
||||
|
||||
coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture);
|
||||
crisisSprite = std::make_unique<SmartSprite>(crisisTexture);
|
||||
coffee_sprite_ = std::make_unique<SmartSprite>(coffee_texture_);
|
||||
crisis_sprite_ = std::make_unique<SmartSprite>(crisis_texture_);
|
||||
|
||||
arcadeEditionSprite = std::make_unique<Sprite>((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcade_edition_position, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture);
|
||||
arcade_edition_sprite_ = std::make_unique<Sprite>((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_);
|
||||
|
||||
dustLSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
|
||||
dustRSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
|
||||
dust_left_sprite_ = std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"));
|
||||
dust_right_sprite_ = std::make_unique<AnimatedSprite>(dust_texture_, Asset::get()->get("title_dust.ani"));
|
||||
|
||||
// Sonidos
|
||||
crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str());
|
||||
crash_sound_ = JA_LoadSound(Asset::get()->get("title.wav").c_str());
|
||||
|
||||
// Inicializa las variables
|
||||
init();
|
||||
@@ -39,140 +39,140 @@ GameLogo::GameLogo(int x, int y)
|
||||
// Destructor
|
||||
GameLogo::~GameLogo()
|
||||
{
|
||||
JA_DeleteSound(crashSound);
|
||||
JA_DeleteSound(crash_sound_);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
void GameLogo::init()
|
||||
{
|
||||
const auto xp = x - coffeeSprite->getWidth() / 2;
|
||||
const auto xp = x_ - coffee_sprite_->getWidth() / 2;
|
||||
const auto desp = getInitialVerticalDesp();
|
||||
|
||||
// Variables
|
||||
status = Status::DISABLED;
|
||||
shake.desp = 1;
|
||||
shake.delay = 2;
|
||||
shake.lenght = 8;
|
||||
shake.remaining = shake.lenght;
|
||||
shake.counter = shake.delay;
|
||||
shake.origin = xp;
|
||||
status_ = Status::DISABLED;
|
||||
shake_.desp = 1;
|
||||
shake_.delay = 2;
|
||||
shake_.lenght = 8;
|
||||
shake_.remaining = shake_.lenght;
|
||||
shake_.counter = shake_.delay;
|
||||
shake_.origin = xp;
|
||||
|
||||
// Inicializa el bitmap de 'Coffee'
|
||||
coffeeSprite->init();
|
||||
coffeeSprite->setPosX(xp);
|
||||
coffeeSprite->setPosY(y - coffeeTexture->getHeight() - desp);
|
||||
coffeeSprite->setWidth(coffeeTexture->getWidth());
|
||||
coffeeSprite->setHeight(coffeeTexture->getHeight());
|
||||
coffeeSprite->setVelX(0.0f);
|
||||
coffeeSprite->setVelY(2.5f);
|
||||
coffeeSprite->setAccelX(0.0f);
|
||||
coffeeSprite->setAccelY(0.1f);
|
||||
coffeeSprite->setSpriteClip(0, 0, coffeeTexture->getWidth(), coffeeTexture->getHeight());
|
||||
coffeeSprite->setEnabled(true);
|
||||
coffeeSprite->setFinishedCounter(0);
|
||||
coffeeSprite->setDestX(xp);
|
||||
coffeeSprite->setDestY(y - coffeeTexture->getHeight());
|
||||
coffee_sprite_->init();
|
||||
coffee_sprite_->setPosX(xp);
|
||||
coffee_sprite_->setPosY(y_ - coffee_texture_->getHeight() - desp);
|
||||
coffee_sprite_->setWidth(coffee_texture_->getWidth());
|
||||
coffee_sprite_->setHeight(coffee_texture_->getHeight());
|
||||
coffee_sprite_->setVelX(0.0f);
|
||||
coffee_sprite_->setVelY(2.5f);
|
||||
coffee_sprite_->setAccelX(0.0f);
|
||||
coffee_sprite_->setAccelY(0.1f);
|
||||
coffee_sprite_->setSpriteClip(0, 0, coffee_texture_->getWidth(), coffee_texture_->getHeight());
|
||||
coffee_sprite_->setEnabled(true);
|
||||
coffee_sprite_->setFinishedCounter(0);
|
||||
coffee_sprite_->setDestX(xp);
|
||||
coffee_sprite_->setDestY(y_ - coffee_texture_->getHeight());
|
||||
|
||||
// Inicializa el bitmap de 'Crisis'
|
||||
crisisSprite->init();
|
||||
crisisSprite->setPosX(xp + 15);
|
||||
crisisSprite->setPosY(y + desp);
|
||||
crisisSprite->setWidth(crisisTexture->getWidth());
|
||||
crisisSprite->setHeight(crisisTexture->getHeight());
|
||||
crisisSprite->setVelX(0.0f);
|
||||
crisisSprite->setVelY(-2.5f);
|
||||
crisisSprite->setAccelX(0.0f);
|
||||
crisisSprite->setAccelY(-0.1f);
|
||||
crisisSprite->setSpriteClip(0, 0, crisisTexture->getWidth(), crisisTexture->getHeight());
|
||||
crisisSprite->setEnabled(true);
|
||||
crisisSprite->setFinishedCounter(0);
|
||||
crisisSprite->setDestX(xp + 15);
|
||||
crisisSprite->setDestY(y);
|
||||
crisis_sprite_->init();
|
||||
crisis_sprite_->setPosX(xp + 15);
|
||||
crisis_sprite_->setPosY(y_ + desp);
|
||||
crisis_sprite_->setWidth(crisis_texture_->getWidth());
|
||||
crisis_sprite_->setHeight(crisis_texture_->getHeight());
|
||||
crisis_sprite_->setVelX(0.0f);
|
||||
crisis_sprite_->setVelY(-2.5f);
|
||||
crisis_sprite_->setAccelX(0.0f);
|
||||
crisis_sprite_->setAccelY(-0.1f);
|
||||
crisis_sprite_->setSpriteClip(0, 0, crisis_texture_->getWidth(), crisis_texture_->getHeight());
|
||||
crisis_sprite_->setEnabled(true);
|
||||
crisis_sprite_->setFinishedCounter(0);
|
||||
crisis_sprite_->setDestX(xp + 15);
|
||||
crisis_sprite_->setDestY(y_);
|
||||
|
||||
// Inicializa el bitmap de 'DustRight'
|
||||
dustRSprite->resetAnimation();
|
||||
dustRSprite->setPosX(coffeeSprite->getPosX() + coffeeSprite->getWidth());
|
||||
dustRSprite->setPosY(y);
|
||||
dustRSprite->setWidth(16);
|
||||
dustRSprite->setHeight(16);
|
||||
dustRSprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
dust_right_sprite_->resetAnimation();
|
||||
dust_right_sprite_->setPosX(coffee_sprite_->getPosX() + coffee_sprite_->getWidth());
|
||||
dust_right_sprite_->setPosY(y_);
|
||||
dust_right_sprite_->setWidth(16);
|
||||
dust_right_sprite_->setHeight(16);
|
||||
dust_right_sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
|
||||
// Inicializa el bitmap de 'DustLeft'
|
||||
dustLSprite->resetAnimation();
|
||||
dustLSprite->setPosX(coffeeSprite->getPosX() - 16);
|
||||
dustLSprite->setPosY(y);
|
||||
dustLSprite->setWidth(16);
|
||||
dustLSprite->setHeight(16);
|
||||
dust_left_sprite_->resetAnimation();
|
||||
dust_left_sprite_->setPosX(coffee_sprite_->getPosX() - 16);
|
||||
dust_left_sprite_->setPosY(y_);
|
||||
dust_left_sprite_->setWidth(16);
|
||||
dust_left_sprite_->setHeight(16);
|
||||
}
|
||||
|
||||
// Pinta la clase en pantalla
|
||||
void GameLogo::render()
|
||||
{
|
||||
// Dibuja el logo
|
||||
coffeeSprite->render();
|
||||
crisisSprite->render();
|
||||
coffee_sprite_->render();
|
||||
crisis_sprite_->render();
|
||||
|
||||
if (status == Status::FINISHED)
|
||||
if (status_ == Status::FINISHED)
|
||||
{
|
||||
arcadeEditionSprite->render();
|
||||
arcade_edition_sprite_->render();
|
||||
}
|
||||
|
||||
// Dibuja el polvillo del logo
|
||||
dustRSprite->render();
|
||||
dustLSprite->render();
|
||||
dust_right_sprite_->render();
|
||||
dust_left_sprite_->render();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void GameLogo::update()
|
||||
{
|
||||
if (status == Status::MOVING)
|
||||
if (status_ == Status::MOVING)
|
||||
{
|
||||
coffeeSprite->update();
|
||||
crisisSprite->update();
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
|
||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||
if (coffeeSprite->hasFinished() && crisisSprite->hasFinished())
|
||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished())
|
||||
{
|
||||
status = Status::SHAKING;
|
||||
status_ = Status::SHAKING;
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(crashSound);
|
||||
JA_PlaySound(crash_sound_);
|
||||
}
|
||||
}
|
||||
|
||||
else if (status == Status::SHAKING)
|
||||
else if (status_ == Status::SHAKING)
|
||||
{
|
||||
// Agita el logo
|
||||
if (shake.remaining > 0)
|
||||
if (shake_.remaining > 0)
|
||||
{
|
||||
if (shake.counter > 0)
|
||||
if (shake_.counter > 0)
|
||||
{
|
||||
shake.counter--;
|
||||
shake_.counter--;
|
||||
}
|
||||
else
|
||||
{
|
||||
shake.counter = shake.delay;
|
||||
const auto desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
||||
coffeeSprite->setPosX(shake.origin + desp);
|
||||
crisisSprite->setPosX(shake.origin + desp + 15);
|
||||
shake.remaining--;
|
||||
shake_.counter = shake_.delay;
|
||||
const auto desp = shake_.remaining % 2 == 0 ? shake_.desp * (-1) : shake_.desp;
|
||||
coffee_sprite_->setPosX(shake_.origin + desp);
|
||||
crisis_sprite_->setPosX(shake_.origin + desp + 15);
|
||||
shake_.remaining--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
coffeeSprite->setPosX(shake.origin);
|
||||
crisisSprite->setPosX(shake.origin + 15);
|
||||
status = Status::FINISHED;
|
||||
coffee_sprite_->setPosX(shake_.origin);
|
||||
crisis_sprite_->setPosX(shake_.origin + 15);
|
||||
status_ = Status::FINISHED;
|
||||
}
|
||||
|
||||
dustRSprite->update();
|
||||
dustLSprite->update();
|
||||
dust_right_sprite_->update();
|
||||
dust_left_sprite_->update();
|
||||
}
|
||||
|
||||
else if (status == Status::FINISHED)
|
||||
else if (status_ == Status::FINISHED)
|
||||
{
|
||||
dustRSprite->update();
|
||||
dustLSprite->update();
|
||||
dust_right_sprite_->update();
|
||||
dust_left_sprite_->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,28 +180,28 @@ void GameLogo::update()
|
||||
void GameLogo::enable()
|
||||
{
|
||||
init();
|
||||
status = Status::MOVING;
|
||||
status_ = Status::MOVING;
|
||||
}
|
||||
|
||||
// Indica si ha terminado la animación
|
||||
bool GameLogo::hasFinished() const
|
||||
{
|
||||
return status == Status::FINISHED;
|
||||
return status_ == Status::FINISHED;
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
void GameLogo::reLoad()
|
||||
{
|
||||
dustTexture->reLoad();
|
||||
coffeeTexture->reLoad();
|
||||
crisisTexture->reLoad();
|
||||
dust_texture_->reLoad();
|
||||
coffee_texture_->reLoad();
|
||||
crisis_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Calcula el desplazamiento vertical inicial
|
||||
int GameLogo::getInitialVerticalDesp()
|
||||
{
|
||||
auto despUp = y;
|
||||
auto despDown = param.game.height - y;
|
||||
auto desp_up = y_;
|
||||
auto desp_down = param.game.height - y_;
|
||||
|
||||
return std::max(despUp, despDown);
|
||||
return std::max(desp_up, desp_down);
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <memory>
|
||||
|
||||
#include "texture.h"
|
||||
#include "animated_sprite.h"
|
||||
#include "smart_sprite.h"
|
||||
@@ -15,24 +14,24 @@ class GameLogo
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::shared_ptr<Texture> dustTexture; // Textura con los graficos del polvo
|
||||
std::shared_ptr<Texture> coffeeTexture; // Textura con los graficos de la palabra "COFFEE"
|
||||
std::shared_ptr<Texture> crisisTexture; // Textura con los graficos de la plabra "CRISIS"
|
||||
std::shared_ptr<Texture> arcadeEditionTexture; // Textura con los graficos de "Arcade Edition"
|
||||
std::shared_ptr<Texture> dust_texture_; // Textura con los graficos del polvo
|
||||
std::shared_ptr<Texture> coffee_texture_; // Textura con los graficos de la palabra "COFFEE"
|
||||
std::shared_ptr<Texture> crisis_texture_; // Textura con los graficos de la plabra "CRISIS"
|
||||
std::shared_ptr<Texture> arcade_edition_texture_; // Textura con los graficos de "Arcade Edition"
|
||||
|
||||
std::unique_ptr<AnimatedSprite> dustLSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
std::unique_ptr<AnimatedSprite> dustRSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
std::unique_ptr<AnimatedSprite> dust_left_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
std::unique_ptr<AnimatedSprite> dust_right_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
|
||||
std::unique_ptr<SmartSprite> coffeeSprite; // Sprite con la palabra "COFFEE" para la pantalla de titulo
|
||||
std::unique_ptr<SmartSprite> crisisSprite; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
||||
std::unique_ptr<SmartSprite> coffee_sprite_; // Sprite con la palabra "COFFEE" para la pantalla de titulo
|
||||
std::unique_ptr<SmartSprite> crisis_sprite_; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
||||
|
||||
std::unique_ptr<Sprite> arcadeEditionSprite; // Sprite con los graficos de "Arcade Edition"
|
||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||
|
||||
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
||||
JA_Sound_t *crash_sound_; // Sonido con el impacto del título
|
||||
|
||||
// Variables
|
||||
int x; // Posición donde dibujar el logo
|
||||
int y; // Posición donde dibujar el logo
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
|
||||
enum class Status
|
||||
{
|
||||
@@ -40,7 +39,7 @@ private:
|
||||
MOVING,
|
||||
SHAKING,
|
||||
FINISHED,
|
||||
} status; // Estado en el que se encuentra la clase
|
||||
} status_; // Estado en el que se encuentra la clase
|
||||
|
||||
struct Shake
|
||||
{
|
||||
@@ -50,7 +49,7 @@ private:
|
||||
int lenght; // Cantidad de desplazamientos a realizar
|
||||
int remaining; // Cantidad de desplazamientos pendientes a realizar
|
||||
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||
} shake; // Estructura para generar el efecto de agitación
|
||||
} shake_; // Estructura para generar el efecto de agitación
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
Reference in New Issue
Block a user