Transició a surface: vaig per title.cpp
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
#include "resource.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_ESCAPE
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawRect, SDL_RenderFillRect
|
||||
#include <stdlib.h> // for exit, size_t
|
||||
#include <algorithm> // for find_if
|
||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include "asset.h" // for AssetType, Asset
|
||||
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
||||
#include "options.h" // for Options, OptionsGame, options
|
||||
#include "screen.h" // for Screen
|
||||
#include "text.h" // for Text, loadTextFile
|
||||
#include "utils.h" // for getFileName, printWithDots, Color
|
||||
struct JA_Music_t; // lines 12-12
|
||||
struct JA_Sound_t; // lines 13-13
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_ESCAPE
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawRect, SDL_RenderFillRect
|
||||
#include <stdlib.h> // for exit, size_t
|
||||
#include <algorithm> // for find_if
|
||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include "asset.h" // for AssetType, Asset
|
||||
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
||||
#include "options.h" // for Options, OptionsGame, options
|
||||
#include "screen.h" // for Screen
|
||||
#include "text.h" // for Text, loadTextFile
|
||||
#include "utils.h" // for getFileName, printWithDots, Color
|
||||
struct JA_Music_t; // lines 12-12
|
||||
struct JA_Sound_t; // lines 13-13
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Resource *Resource::resource_ = nullptr;
|
||||
@@ -48,7 +48,7 @@ void Resource::clear()
|
||||
{
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
textures_.clear();
|
||||
surfaces_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
animations_.clear();
|
||||
@@ -63,7 +63,7 @@ void Resource::load()
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
loadMusics();
|
||||
loadTextures();
|
||||
loadSurfaces();
|
||||
loadTextFiles();
|
||||
loadAnimations();
|
||||
loadTileMaps();
|
||||
@@ -110,14 +110,14 @@ JA_Music_t *Resource::getMusic(const std::string &name)
|
||||
}
|
||||
|
||||
// Obtiene la textura a partir de un nombre
|
||||
std::shared_ptr<Texture> Resource::getTexture(const std::string &name)
|
||||
std::shared_ptr<Surface> Resource::getSurface(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(textures_.begin(), textures_.end(), [&name](const auto &t)
|
||||
auto it = std::find_if(surfaces_.begin(), surfaces_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != textures_.end())
|
||||
if (it != surfaces_.end())
|
||||
{
|
||||
return it->texture;
|
||||
return it->surface;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||
@@ -238,16 +238,16 @@ void Resource::loadMusics()
|
||||
}
|
||||
|
||||
// Carga las texturas
|
||||
void Resource::loadTextures()
|
||||
void Resource::loadSurfaces()
|
||||
{
|
||||
std::cout << "\n>> TEXTURES" << std::endl;
|
||||
std::cout << "\n>> SURFACES" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||
textures_.clear();
|
||||
surfaces_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
|
||||
surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(Screen::get()->getSurface(), l)));
|
||||
updateLoadingProgress();
|
||||
}
|
||||
}
|
||||
@@ -330,16 +330,16 @@ void Resource::createText()
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<ResourceInfo> resources = {
|
||||
{"debug", "debug.png", "debug.txt"},
|
||||
{"gauntlet", "gauntlet.png", "gauntlet.txt"},
|
||||
{"smb2", "smb2.png", "smb2.txt"},
|
||||
{"subatomic", "subatomic.png", "subatomic.txt"},
|
||||
{"8bithud", "8bithud.png", "8bithud.txt"}};
|
||||
{"debug", "debug.gif", "debug.txt"},
|
||||
{"gauntlet", "gauntlet.gif", "gauntlet.txt"},
|
||||
{"smb2", "smb2.gif", "smb2.txt"},
|
||||
{"subatomic", "subatomic.gif", "subatomic.txt"},
|
||||
{"8bithud", "8bithud.gif", "8bithud.txt"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(
|
||||
getTexture(resource.textureFile),
|
||||
getSurface(resource.textureFile),
|
||||
getTextFile(resource.textFile))));
|
||||
printWithDots("Text : ", resource.key, "[ DONE ]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user