La música la tiene ahora la clase Director
This commit is contained in:
@@ -62,6 +62,12 @@ Director::Director(int argc, char *argv[])
|
||||
initInput();
|
||||
|
||||
screen = new Screen(window, renderer, asset, options);
|
||||
|
||||
// Carga los sonidos del juego
|
||||
loadSounds();
|
||||
|
||||
// Carga las musicas del juego
|
||||
loadMusics();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
@@ -76,6 +82,9 @@ Director::~Director()
|
||||
delete param;
|
||||
delete section;
|
||||
|
||||
deleteSounds();
|
||||
deleteMusics();
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
@@ -664,6 +673,62 @@ bool Director::saveConfigFile()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void Director::loadSounds()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros de sonidos
|
||||
std::vector<std::string> list = asset->getListByType(t_sound);
|
||||
sounds.clear();
|
||||
|
||||
for (auto l : list)
|
||||
{
|
||||
const size_t lastIndex = l.find_last_of("/") + 1;
|
||||
const std::string name = l.substr(lastIndex, std::string::npos);
|
||||
sound_file_t temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadSound(l.c_str()); // Carga el fichero de audio
|
||||
sounds.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las musicas del juego
|
||||
void Director::loadMusics()
|
||||
{
|
||||
// Obtiene la lista con las rutas a los ficheros musicales
|
||||
std::vector<std::string> list = asset->getListByType(t_music);
|
||||
musics.clear();
|
||||
|
||||
for (auto l : list)
|
||||
{
|
||||
const size_t lastIndex = l.find_last_of("/") + 1;
|
||||
const std::string name = l.substr(lastIndex, std::string::npos);
|
||||
music_file_t temp;
|
||||
temp.name = name; // Añade el nombre del fichero
|
||||
temp.file = JA_LoadMusic(l.c_str()); // Carga el fichero de audio
|
||||
musics.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Descarga los sonidos del juego
|
||||
void Director::deleteSounds()
|
||||
{
|
||||
for (auto s : sounds)
|
||||
{
|
||||
JA_DeleteSound(s.file);
|
||||
}
|
||||
sounds.clear();
|
||||
}
|
||||
|
||||
// Descarga las músicas del juego
|
||||
void Director::deleteMusics()
|
||||
{
|
||||
for (auto m : musics)
|
||||
{
|
||||
JA_DeleteMusic(m.file);
|
||||
}
|
||||
musics.clear();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego con el logo
|
||||
void Director::runLogo()
|
||||
{
|
||||
@@ -675,7 +740,7 @@ void Director::runLogo()
|
||||
// Ejecuta la seccion de juego de la introducción
|
||||
void Director::runIntro()
|
||||
{
|
||||
intro = new Intro(renderer, screen, asset, input, lang, param, section);
|
||||
intro = new Intro(renderer, screen, asset, input, lang, param, section, getMusic(musics, "intro.ogg"));
|
||||
intro->run();
|
||||
delete intro;
|
||||
}
|
||||
@@ -683,7 +748,7 @@ void Director::runIntro()
|
||||
// Ejecuta la seccion de juego con el titulo y los menus
|
||||
void Director::runTitle()
|
||||
{
|
||||
title = new Title(renderer, screen, input, asset, options, lang, param, section);
|
||||
title = new Title(renderer, screen, input, asset, options, lang, param, section, getMusic(musics, "title.ogg"));
|
||||
title->run();
|
||||
delete title;
|
||||
}
|
||||
@@ -692,7 +757,7 @@ void Director::runTitle()
|
||||
void Director::runGame()
|
||||
{
|
||||
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
||||
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, param, options, section);
|
||||
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
@@ -716,7 +781,7 @@ void Director::runInstructions()
|
||||
// Ejecuta el juego en modo demo
|
||||
void Director::runDemoGame()
|
||||
{
|
||||
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section);
|
||||
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section, nullptr);
|
||||
demoGame->run();
|
||||
delete demoGame;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user