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