commit de acabar la jornada laboral
This commit is contained in:
@@ -16,9 +16,7 @@ std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, s
|
|||||||
auto frame_height = 0;
|
auto frame_height = 0;
|
||||||
auto max_tiles = 0;
|
auto max_tiles = 0;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif
|
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
@@ -26,9 +24,7 @@ std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, s
|
|||||||
if (file.good())
|
if (file.good())
|
||||||
{
|
{
|
||||||
// Procesa el fichero linea a linea
|
// Procesa el fichero linea a linea
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Animation loaded: " << file_name << std::endl;
|
std::cout << "Animation loaded: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
@@ -86,9 +82,7 @@ std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, s
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (line != "[/animation]");
|
} while (line != "[/animation]");
|
||||||
@@ -123,9 +117,7 @@ std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, s
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normaliza valores
|
// Normaliza valores
|
||||||
@@ -150,9 +142,7 @@ std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, s
|
|||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return animations;
|
return animations;
|
||||||
@@ -204,9 +194,7 @@ int AnimatedSprite::getIndex(const std::string &name)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||||
#endif
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,9 +395,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,9 +431,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +455,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pone un valor por defecto
|
// Pone un valor por defecto
|
||||||
setPos((SDL_Rect){0, 0, frame_width, frame_height});
|
setPosition((SDL_Rect){0, 0, frame_width, frame_height});
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ std::string Asset::get(const std::string &text) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||||
#endif
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,12 +68,10 @@ bool Asset::check() const
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "\n** Checking files" << std::endl;
|
std::cout << "\n** Checking files" << std::endl;
|
||||||
|
|
||||||
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||||
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
||||||
@@ -94,9 +90,7 @@ bool Asset::check() const
|
|||||||
// Si hay ficheros de ese tipo, comprueba si existen
|
// Si hay ficheros de ese tipo, comprueba si existen
|
||||||
if (any)
|
if (any)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
|
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
for (const auto &f : file_list_)
|
for (const auto &f : file_list_)
|
||||||
{
|
{
|
||||||
@@ -108,10 +102,8 @@ bool Asset::check() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resultado
|
// Resultado
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
|
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -130,7 +122,6 @@ bool Asset::checkFile(const std::string &path) const
|
|||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||||
std::cout << "Checking file: ";
|
std::cout << "Checking file: ";
|
||||||
@@ -138,7 +129,6 @@ bool Asset::checkFile(const std::string &path) const
|
|||||||
std::cout.fill('.');
|
std::cout.fill('.');
|
||||||
std::cout << file_name;
|
std::cout << file_name;
|
||||||
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
|
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ Background::Background(SDL_Renderer *renderer)
|
|||||||
bottom_clouds_sprite_b_->setVelX(-bottom_clouds_speed);
|
bottom_clouds_sprite_b_->setVelX(-bottom_clouds_speed);
|
||||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||||
|
|
||||||
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight());
|
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
|
||||||
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight());
|
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura para componer el fondo
|
// Crea la textura para componer el fondo
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ void Balloon::render()
|
|||||||
|
|
||||||
if (kind_ == POWER_BALL && !isBeingCreated())
|
if (kind_ == POWER_BALL && !isBeingCreated())
|
||||||
{
|
{
|
||||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPos());
|
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||||
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
|
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
|
||||||
sp->render();
|
sp->render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ BulletMoveStatus Bullet::move()
|
|||||||
return BulletMoveStatus::OUT;
|
return BulletMoveStatus::OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite_->setPosX(pos_x_);
|
sprite_->setX(pos_x_);
|
||||||
sprite_->setPosY(pos_y_);
|
sprite_->setY(pos_y_);
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
|
|
||||||
return BulletMoveStatus::OK;
|
return BulletMoveStatus::OK;
|
||||||
|
|||||||
@@ -55,9 +55,11 @@ Director::Director(int argc, const char *argv[])
|
|||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef VERBOSE
|
||||||
// Deshabilita todos los std::cout
|
// Deshabilita todos los std::cout
|
||||||
//std::ostream null_stream(nullptr);
|
std::ostream null_stream(nullptr);
|
||||||
//std::streambuf *orig_buf = std::cout.rdbuf(null_stream.rdbuf());
|
std::streambuf *orig_buf = std::cout.rdbuf(null_stream.rdbuf());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
@@ -252,9 +254,7 @@ bool Director::initSDL()
|
|||||||
// Inicializa SDL
|
// Inicializa SDL
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -262,7 +262,6 @@ bool Director::initSDL()
|
|||||||
// Inicia el generador de numeros aleatorios
|
// Inicia el generador de numeros aleatorios
|
||||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
// Muestra información de la pantalla
|
// Muestra información de la pantalla
|
||||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
/*std::cout << "\nDisplay modes list:" << std::endl;
|
||||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||||
@@ -276,30 +275,23 @@ bool Director::initSDL()
|
|||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
||||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Establece el filtro de la textura
|
// Establece el filtro de la textura
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: texture filtering not enabled!\n";
|
std::cout << "Warning: texture filtering not enabled!\n";
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: opengl not enabled!\n";
|
std::cout << "Warning: opengl not enabled!\n";
|
||||||
#endif // VERBOSE
|
|
||||||
}
|
}
|
||||||
#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
|
|
||||||
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;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -318,9 +310,7 @@ bool Director::initSDL()
|
|||||||
|
|
||||||
if (!renderer_)
|
if (!renderer_)
|
||||||
{
|
{
|
||||||
#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;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -338,9 +328,7 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
#endif
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -300,9 +300,7 @@ void Game::init(int player_id)
|
|||||||
// Carga los recursos necesarios para la sección 'Game'
|
// Carga los recursos necesarios para la sección 'Game'
|
||||||
void Game::loadMedia()
|
void Game::loadMedia()
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "\n** LOADING RESOURCES FOR GAME SECTION" << std::endl;
|
std::cout << "\n** LOADING RESOURCES FOR GAME SECTION" << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Limpia
|
// Limpia
|
||||||
{
|
{
|
||||||
@@ -492,10 +490,8 @@ void Game::loadMedia()
|
|||||||
coffee_machine_sound_ = JA_LoadSound(asset_->get("title.wav").c_str());
|
coffee_machine_sound_ = JA_LoadSound(asset_->get("title.wav").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "** RESOURCES FOR GAME SECTION LOADED\n"
|
std::cout << "** RESOURCES FOR GAME SECTION LOADED\n"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera los recursos previamente cargados
|
// Libera los recursos previamente cargados
|
||||||
@@ -537,15 +533,11 @@ bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTA
|
|||||||
{
|
{
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
auto success = true;
|
auto success = true;
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif
|
|
||||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||||
if (!file)
|
if (!file)
|
||||||
{ // El fichero no existe
|
{ // El fichero no existe
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Creamos el fichero para escritura
|
// Creamos el fichero para escritura
|
||||||
file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||||
@@ -553,9 +545,7 @@ bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTA
|
|||||||
// Si ha creado el fichero
|
// Si ha creado el fichero
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "New file (" << file_name.c_str() << ") created!" << std::endl;
|
std::cout << "New file (" << file_name.c_str() << ") created!" << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Inicializas los datos y los guarda en el fichero
|
// Inicializas los datos y los guarda en el fichero
|
||||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
||||||
@@ -576,9 +566,7 @@ bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTA
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Si no puede crear el fichero
|
{ // Si no puede crear el fichero
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Error: Unable to create file " << file_name.c_str() << std::endl;
|
std::cout << "Error: Unable to create file " << file_name.c_str() << std::endl;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -586,9 +574,7 @@ bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTA
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Mensaje de proceder a la carga de los datos
|
// Mensaje de proceder a la carga de los datos
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Lee todos los datos del fichero y los deja en el destino
|
// Lee todos los datos del fichero y los deja en el destino
|
||||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
|
||||||
@@ -610,9 +596,7 @@ bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTA
|
|||||||
bool Game::saveDemoFile(const std::string &file_path)
|
bool Game::saveDemoFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
auto success = true;
|
auto success = true;
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif // VERBOSE
|
|
||||||
|
|
||||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||||
if (file)
|
if (file)
|
||||||
@@ -623,18 +607,14 @@ bool Game::saveDemoFile(const std::string &file_path)
|
|||||||
SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(DemoKeys), 1);
|
SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(DemoKeys), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Writing file " << file_name.c_str() << std::endl;
|
std::cout << "Writing file " << file_name.c_str() << std::endl;
|
||||||
#endif // VERBOSE
|
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||||
#endif // VERBOSE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -1420,7 +1400,7 @@ void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
|
|||||||
|
|
||||||
// Inicializa
|
// Inicializa
|
||||||
smart_sprites_.back()->setPos({0, 0, texture->getWidth(), texture->getHeight()});
|
smart_sprites_.back()->setPos({0, 0, texture->getWidth(), texture->getHeight()});
|
||||||
smart_sprites_.back()->setSpriteClip(smart_sprites_.back()->getPos());
|
smart_sprites_.back()->setSpriteClip(smart_sprites_.back()->getPosition());
|
||||||
smart_sprites_.back()->setPosX(x);
|
smart_sprites_.back()->setPosX(x);
|
||||||
smart_sprites_.back()->setPosY(y);
|
smart_sprites_.back()->setPosY(y);
|
||||||
smart_sprites_.back()->setDestX(x);
|
smart_sprites_.back()->setDestX(x);
|
||||||
@@ -2439,9 +2419,7 @@ void Game::loadAnimations(std::string filePath, std::vector<std::string> *buffer
|
|||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
||||||
#endif
|
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
buffer->push_back(line);
|
buffer->push_back(line);
|
||||||
|
|||||||
@@ -396,11 +396,9 @@ bool Input::discoverGameControllers()
|
|||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
{
|
{
|
||||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
num_joysticks_ = SDL_NumJoysticks();
|
num_joysticks_ = SDL_NumJoysticks();
|
||||||
@@ -418,12 +416,10 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
{
|
{
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
std::cout << "\nChecking for game controllers...\n";
|
||||||
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (num_gamepads_ > 0)
|
if (num_gamepads_ > 0)
|
||||||
{
|
{
|
||||||
@@ -437,20 +433,16 @@ bool Input::discoverGameControllers()
|
|||||||
{
|
{
|
||||||
connected_controllers_.push_back(pad);
|
connected_controllers_.push_back(pad);
|
||||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
#ifdef VERBOSE
|
|
||||||
{
|
{
|
||||||
std::cout << name << std::endl;
|
std::cout << name << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
controller_names_.push_back(name);
|
controller_names_.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
{
|
{
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void Instructions::iniSprites()
|
|||||||
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
||||||
{
|
{
|
||||||
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
|
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
|
||||||
sprite->setPos((SDL_Point){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
|
sprite->setPosition((SDL_Point){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
|
||||||
sprites_.push_back(std::move(sprite));
|
sprites_.push_back(std::move(sprite));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ Logo::Logo()
|
|||||||
ticks_ = 0;
|
ticks_ = 0;
|
||||||
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
||||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||||
since_sprite_->setPosY(dest_.y + jail_texture_->getHeight() + 5);
|
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
||||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||||
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ Logo::Logo()
|
|||||||
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
||||||
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
||||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
||||||
temp->setPosX(posX);
|
temp->setX(posX);
|
||||||
temp->setPosY(dest_.y + i);
|
temp->setY(dest_.y + i);
|
||||||
jail_sprite_.push_back(std::move(temp));
|
jail_sprite_.push_back(std::move(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,22 +115,22 @@ void Logo::updateJAILGAMES()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||||
{
|
{
|
||||||
if (jail_sprite_[i]->getPosX() != dest_.x)
|
if (jail_sprite_[i]->getX() != dest_.x)
|
||||||
{
|
{
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
{
|
{
|
||||||
jail_sprite_[i]->incPosX(-SPEED);
|
jail_sprite_[i]->incX(-SPEED);
|
||||||
if (jail_sprite_[i]->getPosX() < dest_.x)
|
if (jail_sprite_[i]->getX() < dest_.x)
|
||||||
{
|
{
|
||||||
jail_sprite_[i]->setPosX(dest_.x);
|
jail_sprite_[i]->setX(dest_.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jail_sprite_[i]->incPosX(SPEED);
|
jail_sprite_[i]->incX(SPEED);
|
||||||
if (jail_sprite_[i]->getPosX() > dest_.x)
|
if (jail_sprite_[i]->getX() > dest_.x)
|
||||||
{
|
{
|
||||||
jail_sprite_[i]->setPosX(dest_.x);
|
jail_sprite_[i]->setX(dest_.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,10 +66,8 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
|||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
std::cout << "Reading file: " << file_name.c_str() << std::endl;
|
||||||
#endif
|
|
||||||
for (int i = 0; i < (int)table_->size(); ++i)
|
for (int i = 0; i < (int)table_->size(); ++i)
|
||||||
{
|
{
|
||||||
int nameSize = 0;
|
int nameSize = 0;
|
||||||
@@ -115,9 +113,7 @@ bool ManageHiScoreTable::loadFromFile(const std::string &file_path)
|
|||||||
// Guarda la tabla en un fichero
|
// Guarda la tabla en un fichero
|
||||||
bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif
|
|
||||||
auto success = true;
|
auto success = true;
|
||||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||||
|
|
||||||
@@ -132,17 +128,13 @@ bool ManageHiScoreTable::saveToFile(const std::string &file_path)
|
|||||||
SDL_RWwrite(file, table_->at(i).name.c_str(), nameSize, 1);
|
SDL_RWwrite(file, table_->at(i).name.c_str(), nameSize, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
std::cout << "Writing file: " << file_name.c_str() << std::endl;
|
||||||
#endif
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
|
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
|
||||||
: Sprite(texture, pos),
|
: Sprite(texture, pos),
|
||||||
|
x_(pos.x),
|
||||||
|
y_(pos.y),
|
||||||
rotate_(rotate),
|
rotate_(rotate),
|
||||||
zoom_w_(zoom_w),
|
zoom_w_(zoom_w),
|
||||||
zoom_h_(zoom_h),
|
zoom_h_(zoom_h),
|
||||||
@@ -11,6 +13,8 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotat
|
|||||||
|
|
||||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
|
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
|
||||||
: Sprite(texture, pos),
|
: Sprite(texture, pos),
|
||||||
|
x_(pos.x),
|
||||||
|
y_(pos.y),
|
||||||
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
|
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
|
||||||
zoom_w_(1.0f),
|
zoom_w_(1.0f),
|
||||||
zoom_h_(1.0f),
|
zoom_h_(1.0f),
|
||||||
@@ -59,6 +63,8 @@ void MovingSprite::move()
|
|||||||
|
|
||||||
vx_ += ax_;
|
vx_ += ax_;
|
||||||
vy_ += ay_;
|
vy_ += ay_;
|
||||||
|
|
||||||
|
syncPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables internas del objeto
|
// Actualiza las variables internas del objeto
|
||||||
@@ -243,8 +249,7 @@ void MovingSprite::setPos(float x, float y)
|
|||||||
x_ = x;
|
x_ = x;
|
||||||
y_ = y;
|
y_ = y;
|
||||||
|
|
||||||
pos_.x = (int)x;
|
syncPos();
|
||||||
pos_.y = (int)y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -284,3 +289,10 @@ void MovingSprite::setAccelY(float value)
|
|||||||
{
|
{
|
||||||
ay_ = value;
|
ay_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sincroniza la posición
|
||||||
|
void MovingSprite::syncPos()
|
||||||
|
{
|
||||||
|
pos_.x = (int)x_;
|
||||||
|
pos_.y = (int)y_;
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ protected:
|
|||||||
// Rota el sprite
|
// Rota el sprite
|
||||||
void rotate();
|
void rotate();
|
||||||
|
|
||||||
|
// Sincroniza la posición
|
||||||
|
void syncPos();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
|
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ void Notifier::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications_[i].sprite->setPos(notifications_[i].rect);
|
notifications_[i].sprite->setPosition(notifications_[i].rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFinishedNotifications();
|
clearFinishedNotifications();
|
||||||
@@ -278,7 +278,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, std::str
|
|||||||
if (has_icons_ && icon >= 0 && num_texts == 2)
|
if (has_icons_ && icon >= 0 && num_texts == 2)
|
||||||
{
|
{
|
||||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
||||||
sp->setPos({padding_in_h, padding_in_v, icon_size, icon_size});
|
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
||||||
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
|
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
|
||||||
sp->render();
|
sp->render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ auto OnScreenHelp::getLargestStringSize() -> int const
|
|||||||
void OnScreenHelp::renderButton(Sprite *sprite, Text *text, const SDL_Rect &buttonClip, const SDL_Rect &buttonPos, int textId)
|
void OnScreenHelp::renderButton(Sprite *sprite, Text *text, const SDL_Rect &buttonClip, const SDL_Rect &buttonPos, int textId)
|
||||||
{
|
{
|
||||||
sprite->setSpriteClip(buttonClip);
|
sprite->setSpriteClip(buttonClip);
|
||||||
sprite->setPos(buttonPos);
|
sprite->setPosition(buttonPos);
|
||||||
sprite->render();
|
sprite->render();
|
||||||
text->write(buttonPos.x + DESP.x, buttonPos.y + DESP.y, lang::getText(textId));
|
text->write(buttonPos.x + DESP.x, buttonPos.y + DESP.y, lang::getText(textId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,18 +86,14 @@ bool loadOptionsFile(std::string file_path)
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Variables para manejar el fichero
|
// Variables para manejar el fichero
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif
|
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
// Si el fichero se puede abrir
|
// Si el fichero se puede abrir
|
||||||
if (file.good())
|
if (file.good())
|
||||||
{
|
{
|
||||||
// Procesa el fichero linea a linea
|
// Procesa el fichero linea a linea
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Reading file: " << file_name << std::endl;
|
std::cout << "Reading file: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
@@ -109,10 +105,8 @@ bool loadOptionsFile(std::string file_path)
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: file " << file_name << std::endl;
|
std::cout << "Warning: file " << file_name << std::endl;
|
||||||
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
#endif
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,22 +146,16 @@ bool loadOptionsFile(std::string file_path)
|
|||||||
// Guarda el fichero de configuración
|
// Guarda el fichero de configuración
|
||||||
bool saveOptionsFile(std::string file_path)
|
bool saveOptionsFile(std::string file_path)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
#endif
|
|
||||||
std::ofstream file(file_path);
|
std::ofstream file(file_path);
|
||||||
|
|
||||||
if (!file.good())
|
if (!file.good())
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << file_name << " can't be opened" << std::endl;
|
std::cout << file_name << " can't be opened" << std::endl;
|
||||||
#endif
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Writing file: " << file_name << std::endl;
|
std::cout << "Writing file: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Opciones de video
|
// Opciones de video
|
||||||
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
||||||
|
|||||||
107
source/param.cpp
107
source/param.cpp
@@ -65,109 +65,6 @@ void initParam()
|
|||||||
param.notification.color.b = 48;
|
param.notification.color.b = 48;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece valores para los parametros a partir de un fichero de texto
|
|
||||||
/*void loadParamsFromFile(std::string file_path)
|
|
||||||
{
|
|
||||||
// Pone valores por defecto a las variables
|
|
||||||
initParam();
|
|
||||||
|
|
||||||
// Variables para manejar el fichero
|
|
||||||
std::ifstream file(file_path);
|
|
||||||
std::string line;
|
|
||||||
std::string param1;
|
|
||||||
std::string param2;
|
|
||||||
|
|
||||||
// Si el fichero se puede abrir
|
|
||||||
if (file.good())
|
|
||||||
{
|
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
|
||||||
std::cout << "Reading file: " << file_name << std::endl;
|
|
||||||
#endif
|
|
||||||
// Procesa cada linea del fichero
|
|
||||||
while (std::getline(file, line))
|
|
||||||
{
|
|
||||||
// Reinicia variables
|
|
||||||
param1.clear();
|
|
||||||
param2.clear();
|
|
||||||
|
|
||||||
// Elimina los comentarios al final de una linea
|
|
||||||
{
|
|
||||||
// line = line.substr(0, line.find("#"));
|
|
||||||
auto pos = line.find("#");
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
{
|
|
||||||
line.resize(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignora los espacios en blanco
|
|
||||||
int pos = 0;
|
|
||||||
while (pos < (int)line.size() && (int)line[pos] <= 32)
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si no ha llegado al final de la linea, es que hay algo escrito (no es una linea vacía)
|
|
||||||
if (pos < (int)line.size())
|
|
||||||
{
|
|
||||||
// Elimina el espacio en blanco
|
|
||||||
line = line.substr(pos, std::string::npos);
|
|
||||||
|
|
||||||
// Se queda con todo lo que no sean espacios en blanco
|
|
||||||
pos = 1;
|
|
||||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si llega al final de la linea, falta la segunda palabra
|
|
||||||
if (pos < (int)line.size())
|
|
||||||
{
|
|
||||||
// Se queda con la primera palabra
|
|
||||||
param1 = line.substr(0, pos);
|
|
||||||
|
|
||||||
// Y recorta la linea
|
|
||||||
line = line.substr(pos, std::string::npos);
|
|
||||||
|
|
||||||
// Ignora los espacios en blanco
|
|
||||||
pos = 0;
|
|
||||||
while (pos <= (int)line.size() && (int)line[pos] <= 32)
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si llega al final de la linea, falta la segunda palabra
|
|
||||||
if (pos < (int)line.size())
|
|
||||||
{
|
|
||||||
// Elimina el espacio en blanco
|
|
||||||
line = line.substr(pos, std::string::npos);
|
|
||||||
|
|
||||||
// Ignora los espacios en blanco
|
|
||||||
pos = 1;
|
|
||||||
while (pos <= (int)line.size() && (int)line[pos] > 32)
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
// Se queda con la segunda palabra
|
|
||||||
param2 = line.substr(0, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setParams(param1, param2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cierra el fichero
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
else
|
|
||||||
std::cout << "Failed to load file: " << file_path << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
precalculateZones();
|
|
||||||
}*/
|
|
||||||
void loadParamsFromFile(const std::string &file_path)
|
void loadParamsFromFile(const std::string &file_path)
|
||||||
{
|
{
|
||||||
// Inicializa los parámetros con valores por defecto
|
// Inicializa los parámetros con valores por defecto
|
||||||
@@ -177,16 +74,12 @@ void loadParamsFromFile(const std::string &file_path)
|
|||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cerr << "Error: No se pudo abrir el archivo " << file_path << std::endl;
|
std::cerr << "Error: No se pudo abrir el archivo " << file_path << std::endl;
|
||||||
#endif
|
|
||||||
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
|
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
std::cout << "Reading file: " << file_name << std::endl;
|
std::cout << "Reading file: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string line, param1, param2;
|
std::string line, param1, param2;
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
recalculateAnchors();
|
recalculateAnchors();
|
||||||
power_meter_sprite_->setPos({slot4_2_.x - 20, slot4_2_.y, 40, 7});
|
power_meter_sprite_->setPosition({slot4_2_.x - 20, slot4_2_.y, 40, 7});
|
||||||
|
|
||||||
// Crea la textura de fondo
|
// Crea la textura de fondo
|
||||||
background_ = nullptr;
|
background_ = nullptr;
|
||||||
@@ -418,8 +418,8 @@ void Scoreboard::recalculateAnchors()
|
|||||||
// Recoloca los sprites
|
// Recoloca los sprites
|
||||||
if (power_meter_sprite_)
|
if (power_meter_sprite_)
|
||||||
{
|
{
|
||||||
power_meter_sprite_->setPosX(slot4_2_.x - 20);
|
power_meter_sprite_->setX(slot4_2_.x - 20);
|
||||||
power_meter_sprite_->setPosY(slot4_2_.y);
|
power_meter_sprite_->setY(slot4_2_.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ void Sprite::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getPosX() const
|
int Sprite::getX() const
|
||||||
{
|
{
|
||||||
return pos_.x;
|
return pos_.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int Sprite::getPosY() const
|
int Sprite::getY() const
|
||||||
{
|
{
|
||||||
return pos_.y;
|
return pos_.y;
|
||||||
}
|
}
|
||||||
@@ -47,33 +47,33 @@ int Sprite::getHeight() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void Sprite::setPos(int x, int y)
|
void Sprite::setPosition(int x, int y)
|
||||||
{
|
{
|
||||||
pos_.x = x;
|
pos_.x = x;
|
||||||
pos_.y = y;
|
pos_.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void Sprite::setPos(SDL_Point p)
|
void Sprite::setPosition(SDL_Point p)
|
||||||
{
|
{
|
||||||
pos_.x = p.x;
|
pos_.x = p.x;
|
||||||
pos_.y = p.y;
|
pos_.y = p.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void Sprite::setPos(SDL_Rect r)
|
void Sprite::setPosition(SDL_Rect r)
|
||||||
{
|
{
|
||||||
pos_ = r;
|
pos_ = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setPosX(int x)
|
void Sprite::setX(int x)
|
||||||
{
|
{
|
||||||
pos_.x = x;
|
pos_.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setPosY(int y)
|
void Sprite::setY(int y)
|
||||||
{
|
{
|
||||||
pos_.y = y;
|
pos_.y = y;
|
||||||
}
|
}
|
||||||
@@ -121,19 +121,19 @@ void Sprite::setTexture(std::shared_ptr<Texture> texture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo donde está el sprite
|
// Devuelve el rectangulo donde está el sprite
|
||||||
SDL_Rect Sprite::getPos() const
|
SDL_Rect Sprite::getPosition() const
|
||||||
{
|
{
|
||||||
return pos_;
|
return pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa el valor de la variable
|
// Incrementa el valor de la variable
|
||||||
void Sprite::incPosX(int value)
|
void Sprite::incX(int value)
|
||||||
{
|
{
|
||||||
pos_.x += value;
|
pos_.x += value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa el valor de la variable
|
// Incrementa el valor de la variable
|
||||||
void Sprite::incPosY(int value)
|
void Sprite::incY(int value)
|
||||||
{
|
{
|
||||||
pos_.y += value;
|
pos_.y += value;
|
||||||
}
|
}
|
||||||
@@ -26,28 +26,28 @@ public:
|
|||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getPosX() const;
|
int getX() const;
|
||||||
int getPosY() const;
|
int getY() const;
|
||||||
int getWidth() const;
|
int getWidth() const;
|
||||||
int getHeight() const;
|
int getHeight() const;
|
||||||
|
|
||||||
// Devuelve el rectangulo donde está el sprite
|
// Devuelve el rectangulo donde está el sprite
|
||||||
SDL_Rect getPos() const;
|
SDL_Rect getPosition() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(int x);
|
void setX(int x);
|
||||||
void setPosY(int y);
|
void setY(int y);
|
||||||
void setWidth(int w);
|
void setWidth(int w);
|
||||||
void setHeight(int h);
|
void setHeight(int h);
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void setPos(int x, int y);
|
void setPosition(int x, int y);
|
||||||
void setPos(SDL_Point p);
|
void setPosition(SDL_Point p);
|
||||||
void setPos(SDL_Rect r);
|
void setPosition(SDL_Rect r);
|
||||||
|
|
||||||
// Incrementa el valor de la variable
|
// Incrementa el valor de la variable
|
||||||
void incPosX(int value);
|
void incX(int value);
|
||||||
void incPosY(int value);
|
void incY(int value);
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
SDL_Rect getSpriteClip() const;
|
SDL_Rect getSpriteClip() const;
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ TextFile LoadTextFile(std::string file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Abre el fichero para leer los valores
|
// Abre el fichero para leer los valores
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
|
||||||
#endif
|
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
if (file.is_open() && file.good())
|
if (file.is_open() && file.good())
|
||||||
@@ -56,19 +54,15 @@ TextFile LoadTextFile(std::string file_path)
|
|||||||
line_read++;
|
line_read++;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Text loaded: " << file_name << std::endl;
|
std::cout << "Text loaded: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Warning: Unable to open " << file_name << " file" << std::endl;
|
std::cout << "Warning: Unable to open " << file_name << " file" << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||||
@@ -158,14 +152,14 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
|||||||
lenght = text.length();
|
lenght = text.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite_->setPosY(y);
|
sprite_->setY(y);
|
||||||
const auto width = sprite_->getWidth();
|
const auto width = sprite_->getWidth();
|
||||||
const auto height = sprite_->getHeight();
|
const auto height = sprite_->getHeight();
|
||||||
for (int i = 0; i < lenght; ++i)
|
for (int i = 0; i < lenght; ++i)
|
||||||
{
|
{
|
||||||
const auto index = static_cast<int>(text[i]);
|
const auto index = static_cast<int>(text[i]);
|
||||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
||||||
sprite_->setPosX(x + shift);
|
sprite_->setX(x + shift);
|
||||||
sprite_->render();
|
sprite_->render();
|
||||||
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,17 +61,13 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl;
|
std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl;
|
||||||
#endif
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||||
std::cout << "Image loaded: " << file_name << std::endl;
|
std::cout << "Image loaded: " << file_name << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int depth, pitch;
|
int depth, pitch;
|
||||||
@@ -99,9 +95,7 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
|
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
|
||||||
if (loadedSurface == nullptr)
|
if (loadedSurface == nullptr)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Unable to load image " << path << std::endl;
|
std::cout << "Unable to load image " << path << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -109,9 +103,7 @@ bool Texture::loadFromFile(const std::string &path)
|
|||||||
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
|
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
|
||||||
if (newTexture == nullptr)
|
if (newTexture == nullptr)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Unable to create texture from " << path << "! SDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Unable to create texture from " << path << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -137,9 +129,7 @@ bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL
|
|||||||
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
|
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
|
||||||
if (!texture_)
|
if (!texture_)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ void Tiledbg::fillTexture()
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < j_max; ++j)
|
for (int j = 0; j < j_max; ++j)
|
||||||
{
|
{
|
||||||
tile->setPosX(i * tile_width_);
|
tile->setX(i * tile_width_);
|
||||||
tile->setPosY(j * tile_height_);
|
tile->setY(j * tile_height_);
|
||||||
tile->render();
|
tile->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ void Title::render()
|
|||||||
// Mini logo
|
// Mini logo
|
||||||
const int pos1 = (param.game.height / 5 * 4) + BLOCK;
|
const int pos1 = (param.game.height / 5 * 4) + BLOCK;
|
||||||
const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3;
|
const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3;
|
||||||
mini_logo_sprite_->setPosY(pos1);
|
mini_logo_sprite_->setY(pos1);
|
||||||
mini_logo_sprite_->render();
|
mini_logo_sprite_->render();
|
||||||
|
|
||||||
// Texto con el copyright
|
// Texto con el copyright
|
||||||
|
|||||||
Reference in New Issue
Block a user