Trabajando en integrar el objeto asset y mejorar los objetos player y map
This commit is contained in:
@@ -67,9 +67,7 @@ void Director::initGame()
|
||||
game.counter = 0;
|
||||
|
||||
// Player
|
||||
resource.texture[TEXTURE_PLAYER].texture = new LTexture();
|
||||
loadTextureFromFile(resource.texture[TEXTURE_PLAYER].texture, resource.texture[TEXTURE_PLAYER].file, renderer);
|
||||
player = new Player(renderer, resource.texture[TEXTURE_PLAYER].texture);
|
||||
player = new Player(renderer, asset);
|
||||
|
||||
// Map
|
||||
resource.texture[TEXTURE_ACTORS].texture = new LTexture();
|
||||
@@ -231,124 +229,38 @@ void Director::deleteObjects()
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros de recursos
|
||||
void Director::setFileList()
|
||||
bool Director::setFileList()
|
||||
{
|
||||
// Ficheros binarios
|
||||
asset->add("/data/volcano.map",data);
|
||||
asset->add("/data/config.bin".data);
|
||||
asset->add("/data/volcano.map", data);
|
||||
asset->add("/data/config.bin", data);
|
||||
|
||||
// Texturas
|
||||
asset->add("/media/gfx/actors.png",bitmap);
|
||||
asset->add("/media/gfx/bkg_surface.png",bitmap);
|
||||
asset->add("/media/gfx/filter.png",bitmap);
|
||||
asset->add("/media/gfx/hud.png",bitmap);
|
||||
asset->add("/media/gfx/menu_animation.png",bitmap);
|
||||
asset->add("/media/gfx/menu.png",bitmap);
|
||||
asset->add("/media/gfx/player.png",bitmap);
|
||||
asset->add("/media/gfx/tiles_surface.png",bitmap);
|
||||
asset->add("/media/gfx/tiles_volcano.png",bitmap);
|
||||
|
||||
asset->add("/media/gfx/actors.png", bitmap);
|
||||
asset->add("/media/gfx/bkg_surface.png", bitmap);
|
||||
asset->add("/media/gfx/filter.png", bitmap);
|
||||
asset->add("/media/gfx/hud.png", bitmap);
|
||||
asset->add("/media/gfx/menu_animation.png", bitmap);
|
||||
asset->add("/media/gfx/menu.png", bitmap);
|
||||
asset->add("/media/gfx/player.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_surface.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_volcano.png", bitmap);
|
||||
|
||||
// Sonidos
|
||||
resource.sound[SOUND_COIN].file = path + "/" + "../media/sound/sound_player_coin.wav";
|
||||
resource.sound[SOUND_DEATH].file = path + "/" + "../media/sound/sound_player_death.wav";
|
||||
resource.sound[SOUND_DROP_ENEMY].file = path + "/" + "../media/sound/sound_drop_enemy.wav";
|
||||
resource.sound[SOUND_DROP_SPLAT].file = path + "/" + "../media/sound/sound_drop_splat.wav";
|
||||
resource.sound[SOUND_JUMP].file = path + "/" + "../media/sound/sound_player_jump.wav";
|
||||
resource.sound[SOUND_MENU_LOGO].file = path + "/" + "../media/sound/sound_menu_logo.wav";
|
||||
resource.sound[SOUND_MENU_START].file = path + "/" + "../media/sound/sound_menu_start.wav";
|
||||
for (Uint8 i = 0; i < TOTAL_SOUND; i++)
|
||||
resource.sound[i].sound = nullptr;
|
||||
asset->add("/media/sound/sound_player_coin.wav", sound);
|
||||
asset->add("/media/sound/sound_player_death.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_enemy.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_splat.wav", sound);
|
||||
asset->add("/media/sound/sound_player_jump.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_logo.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_start.wav", sound);
|
||||
|
||||
// Musicas
|
||||
resource.music[MUSIC_MENU].file = path + "/" + "../media/music/music_menu.ogg";
|
||||
resource.music[MUSIC_SURFACE].file = path + "/" + "../media/music/music_surface.ogg";
|
||||
resource.music[MUSIC_VOLCANO].file = path + "/" + "../media/music/music_volcano.ogg";
|
||||
for (Uint8 i = 0; i < TOTAL_TEXTURE; i++)
|
||||
resource.music[i].music = nullptr;
|
||||
}
|
||||
asset->add("/media/music/music_menu.ogg", music);
|
||||
asset->add("/media/music/music_surface.ogg", music);
|
||||
asset->add("/media/music/music_volcano.ogg", music);
|
||||
|
||||
// Comprueba que todos los ficheros de recursos existen
|
||||
bool Director::checkResourceList()
|
||||
{
|
||||
bool success = true;
|
||||
std::string p;
|
||||
std::string filename;
|
||||
SDL_RWops *file;
|
||||
|
||||
// Comprueba los ficheros de musica
|
||||
printf("\n>> MUSIC FILES\n");
|
||||
for (Uint8 i = 0; i < TOTAL_MUSIC; i++)
|
||||
{
|
||||
p = resource.music[i].file.c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
// Comprueba los ficheros de sonidos
|
||||
printf("\n>> SOUND FILES\n");
|
||||
for (Uint8 i = 0; i < TOTAL_SOUND; i++)
|
||||
{
|
||||
p = resource.sound[i].file.c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
// Comprueba los ficheros con texturas
|
||||
printf("\n>> TEXTURE FILES\n");
|
||||
for (Uint8 i = 0; i < TOTAL_TEXTURE; i++)
|
||||
{
|
||||
p = resource.texture[i].file.c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
{
|
||||
printf("\n** All files OK.\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n** File is missing. Exiting.\n\n");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Inicializa la variable con los ficheros de recursos
|
||||
bool Director::initResourceList()
|
||||
{
|
||||
setResourceList();
|
||||
return checkResourceList();
|
||||
return asset->check();
|
||||
}
|
||||
|
||||
// Carga los recursos necesarios
|
||||
@@ -680,8 +592,8 @@ void Director::run()
|
||||
{
|
||||
bool quit = false;
|
||||
|
||||
// Comprueba si existen todos los ficheros de recursos
|
||||
if (!initResourceList())
|
||||
// Asigna y comprueba si existen todos los ficheros de recursos
|
||||
if (!setFileList())
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user