Creada la classe Resource

Afegida la musica i els sons a Resource
This commit is contained in:
2024-10-19 10:07:14 +02:00
parent b879673bc2
commit f23dcae5b6
19 changed files with 243 additions and 258 deletions

View File

@@ -34,6 +34,7 @@
#include "on_screen_help.h" // for OnScreenHelp
#include "options.h" // for options, loadOptionsFile, saveO...
#include "param.h" // for param, loadParamsFromFile
#include "resource.h" //for Resource
#include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options
#include "title.h" // for Title
@@ -106,6 +107,8 @@ Director::Director(int argc, const char *argv[])
// Crea los objetos
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
Resource::init();
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
initInput();
@@ -115,12 +118,6 @@ Director::Director(int argc, const char *argv[])
OnScreenHelp::init();
// Carga los sonidos del juego
loadSounds();
// Carga las musicas del juego
loadMusics();
globalInputs::init();
}
@@ -129,13 +126,12 @@ Director::~Director()
saveOptionsFile(Asset::get()->get("config.txt"));
Asset::destroy();
Resource::destroy();
Input::destroy();
Screen::destroy();
Notifier::destroy();
OnScreenHelp::destroy();
sounds_.clear();
musics_.clear();
SDL_DestroyRenderer(renderer_);
SDL_DestroyWindow(window_);
@@ -567,38 +563,6 @@ void Director::createSystemFolder(const std::string &folder)
}
}
// Carga los sonidos del juego
void Director::loadSounds()
{
// Obtiene la lista con las rutas a los ficheros de sonidos
auto list = Asset::get()->getListByType(AssetType::SOUND);
sounds_.clear();
for (const auto &l : list)
{
auto last_index = l.find_last_of('/') + 1;
auto name = l.substr(last_index);
sounds_.emplace_back(SoundFile{name, JA_LoadSound(l.c_str())});
}
}
// Carga las musicas del juego
void Director::loadMusics()
{
// Obtiene la lista con las rutas a los ficheros musicales
auto list = Asset::get()->getListByType(AssetType::MUSIC);
musics_.clear();
for (const auto &l : list)
{
auto last_index = l.find_last_of('/') + 1;
auto name = l.substr(last_index);
musics_.emplace_back(MusicFile{name, JA_LoadMusic(l.c_str())});
}
}
// Ejecuta la sección con el logo
void Director::runLogo()
{
@@ -609,14 +573,14 @@ void Director::runLogo()
// Ejecuta la sección con la secuencia de introducción
void Director::runIntro()
{
auto intro = std::make_unique<Intro>(getMusic(musics_, "intro.ogg"));
auto intro = std::make_unique<Intro>();
intro->run();
}
// Ejecuta la sección con el título del juego
void Director::runTitle()
{
auto title = std::make_unique<Title>(getMusic(musics_, "title.ogg"));
auto title = std::make_unique<Title>();
title->run();
}
@@ -625,21 +589,21 @@ void Director::runGame()
{
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
constexpr auto current_stage = 0;
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF);
game->run();
}
// Ejecuta la sección donde se muestran las instrucciones
void Director::runInstructions()
{
auto instructions = std::make_unique<Instructions>(getMusic(musics_, "title.ogg"));
auto instructions = std::make_unique<Instructions>();
instructions->run();
}
// Ejecuta la sección donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable()
{
auto hi_score_table = std::make_unique<HiScoreTable>(getMusic(musics_, "title.ogg"));
auto hi_score_table = std::make_unique<HiScoreTable>();
hi_score_table->run();
}
@@ -648,7 +612,7 @@ void Director::runDemoGame()
{
const auto player_id = (rand() % 2) + 1;
constexpr auto current_stage = 0;
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON, nullptr);
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON);
game->run();
}
@@ -705,7 +669,6 @@ int Director::run()
const auto return_code = (section::options == section::Options::QUIT_NORMAL) ? "keyboard" : "controller";
std::cout << "\nGame end with " << return_code << std::endl;
#ifndef VERBOSE
// Habilita de nuevo los std::cout
std::cout.rdbuf(orig_buf);