Integrada la clase asset. Corregidos algunos fallos en el bucle principal
This commit is contained in:
@@ -5,19 +5,49 @@
|
||||
const Uint8 *keystates;
|
||||
|
||||
// Constructor
|
||||
Director::Director(std::string _path)
|
||||
Director::Director(std::string path)
|
||||
{
|
||||
// Arranca SDL y crea la ventana
|
||||
initSDL();
|
||||
|
||||
// Crea todos los objetos del juego
|
||||
initObjects();
|
||||
eventHandler = new SDL_Event();
|
||||
// text.white = new Text("", nullptr, nullptr);
|
||||
screen = new Screen(window, renderer);
|
||||
asset = new Asset(path.substr(0, path.find_last_of("\\/")));
|
||||
|
||||
setFileList();
|
||||
|
||||
// Inicializa todas las variables
|
||||
init(_path);
|
||||
section = NONE;
|
||||
gameControllerFound = false;
|
||||
for (int i = 0; i < 360; i++)
|
||||
sen[i] = sin(i * 3.14 / 180);
|
||||
for (int i = 0; i < TOTAL_SCORE_DATA; i++)
|
||||
scoreData[i] = 0;
|
||||
|
||||
initOptions();
|
||||
initGame();
|
||||
quit = false;
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
{
|
||||
|
||||
quitGame();
|
||||
|
||||
// Borra todos los objetos del juego
|
||||
deleteObjects();
|
||||
delete eventHandler;
|
||||
eventHandler = nullptr;
|
||||
|
||||
// delete text.white;
|
||||
// text.white = nullptr;
|
||||
|
||||
delete screen;
|
||||
screen = nullptr;
|
||||
|
||||
delete asset;
|
||||
asset = nullptr;
|
||||
|
||||
// Destruye la ventana
|
||||
SDL_DestroyRenderer(renderer);
|
||||
@@ -31,21 +61,6 @@ Director::~Director()
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
// Inicializa todas las variables
|
||||
void Director::init(std::string _path)
|
||||
{
|
||||
setPath(_path);
|
||||
section = NONE;
|
||||
gameControllerFound = false;
|
||||
for (int i = 0; i < 360; i++)
|
||||
sen[i] = sin(i * 3.14 / 180);
|
||||
for (int i = 0; i < TOTAL_SCORE_DATA; i++)
|
||||
scoreData[i] = 0;
|
||||
|
||||
initOptions();
|
||||
quit = false;
|
||||
}
|
||||
|
||||
// Inicializa las variables de las opciones
|
||||
void Director::initOptions()
|
||||
{
|
||||
@@ -70,14 +85,7 @@ void Director::initGame()
|
||||
player = new Player(renderer, asset);
|
||||
|
||||
// Map
|
||||
resource.texture[TEXTURE_ACTORS].texture = new LTexture();
|
||||
loadTextureFromFile(resource.texture[TEXTURE_ACTORS].texture, resource.texture[TEXTURE_ACTORS].file, renderer);
|
||||
resource.texture[TEXTURE_BKG_SURFACE].texture = new LTexture();
|
||||
loadTextureFromFile(resource.texture[TEXTURE_BKG_SURFACE].texture, resource.texture[TEXTURE_BKG_SURFACE].file, renderer);
|
||||
resource.texture[TEXTURE_TILES_VOLCANO].texture = new LTexture();
|
||||
loadTextureFromFile(resource.texture[TEXTURE_TILES_VOLCANO].texture, resource.texture[TEXTURE_TILES_VOLCANO].file, renderer);
|
||||
map = new Map(renderer, resource.texture[TEXTURE_TILES_VOLCANO].texture, resource.texture[TEXTURE_ACTORS].texture,
|
||||
resource.texture[TEXTURE_BKG_SURFACE].texture, resource.file[FILE_MAP_VOLCANO].file);
|
||||
map = new Map(renderer, asset->get("volcano.map"), asset);
|
||||
}
|
||||
|
||||
// Limpia las variables del juego
|
||||
@@ -86,18 +94,10 @@ void Director::quitGame()
|
||||
// Player
|
||||
delete player;
|
||||
player = nullptr;
|
||||
delete resource.texture[TEXTURE_PLAYER].texture;
|
||||
resource.texture[TEXTURE_PLAYER].texture = nullptr;
|
||||
|
||||
// Map
|
||||
delete map;
|
||||
map = nullptr;
|
||||
delete resource.texture[TEXTURE_TILES_VOLCANO].texture;
|
||||
resource.texture[TEXTURE_TILES_VOLCANO].texture = nullptr;
|
||||
delete resource.texture[TEXTURE_ACTORS].texture;
|
||||
resource.texture[TEXTURE_ACTORS].texture = nullptr;
|
||||
delete resource.texture[TEXTURE_BKG_SURFACE].texture;
|
||||
resource.texture[TEXTURE_BKG_SURFACE].texture = nullptr;
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
@@ -206,34 +206,12 @@ bool Director::initSDL()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea los objetos del programa
|
||||
void Director::initObjects()
|
||||
{
|
||||
eventHandler = new SDL_Event();
|
||||
text.white = new Text("", nullptr, nullptr);
|
||||
screen = new Screen(window, renderer);
|
||||
asset = new Asset(path);
|
||||
}
|
||||
|
||||
// Borra los objetos del programa
|
||||
void Director::deleteObjects()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text.white;
|
||||
delete screen;
|
||||
delete asset;
|
||||
eventHandler = nullptr;
|
||||
text.white = nullptr;
|
||||
screen = nullptr;
|
||||
asset = nullptr;
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros de recursos
|
||||
bool Director::setFileList()
|
||||
{
|
||||
// Ficheros binarios
|
||||
asset->add("/data/volcano.map", data);
|
||||
asset->add("/data/config.bin", data);
|
||||
asset->add("/data/config.bin", data, false);
|
||||
|
||||
// Texturas
|
||||
asset->add("/media/gfx/actors.png", bitmap);
|
||||
@@ -274,7 +252,7 @@ bool Director::loadMedia(Uint8 section)
|
||||
{
|
||||
case GAME_SECTION_INIT:
|
||||
{
|
||||
p = resource.file[FILE_CONFIG].file.c_str();
|
||||
p = asset->get("config-bin").c_str();
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
|
||||
@@ -322,12 +300,6 @@ bool Director::loadMedia(Uint8 section)
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Texturas
|
||||
|
||||
// Sonidos
|
||||
|
||||
// Musicas
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -386,7 +358,7 @@ bool Director::unLoadMedia(Uint8 section)
|
||||
{
|
||||
case GAME_SECTION_INIT:
|
||||
{
|
||||
p = resource.file[FILE_CONFIG].file;
|
||||
p = asset->get("config-bin");
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
|
||||
// Abre el fichero de puntuación para escribir
|
||||
@@ -454,12 +426,6 @@ bool Director::unLoadMedia(Uint8 section)
|
||||
return success;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Director::setPath(std::string _path)
|
||||
{
|
||||
path = _path.substr(0, _path.find_last_of("\\/"));
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 Director::getGameSection()
|
||||
{
|
||||
@@ -590,33 +556,8 @@ void Director::renderGame()
|
||||
// Bucle principal
|
||||
void Director::run()
|
||||
{
|
||||
bool quit = false;
|
||||
|
||||
// Asigna y comprueba si existen todos los ficheros de recursos
|
||||
if (!setFileList())
|
||||
while (isRunning())
|
||||
{
|
||||
quit = true;
|
||||
runGame();
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
if ((!quit) && (!initSDL()))
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
|
||||
// Inicializa las variables del juego
|
||||
if (!quit)
|
||||
{
|
||||
initGame();
|
||||
}
|
||||
|
||||
// Bucle del juego
|
||||
if (!quit)
|
||||
{
|
||||
while (isRunning())
|
||||
{
|
||||
runGame();
|
||||
}
|
||||
}
|
||||
quitGame();
|
||||
}
|
||||
Reference in New Issue
Block a user