Creada la classe Resource
Afegida la musica i els sons a Resource
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include "on_screen_help.h" // for OnScreenHelp
|
#include "on_screen_help.h" // for OnScreenHelp
|
||||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||||
#include "param.h" // for param, loadParamsFromFile
|
#include "param.h" // for param, loadParamsFromFile
|
||||||
|
#include "resource.h" //for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "title.h" // for Title
|
#include "title.h" // for Title
|
||||||
@@ -106,6 +107,8 @@ Director::Director(int argc, const char *argv[])
|
|||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
||||||
|
|
||||||
|
Resource::init();
|
||||||
|
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||||
initInput();
|
initInput();
|
||||||
|
|
||||||
@@ -115,12 +118,6 @@ Director::Director(int argc, const char *argv[])
|
|||||||
|
|
||||||
OnScreenHelp::init();
|
OnScreenHelp::init();
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
|
||||||
loadSounds();
|
|
||||||
|
|
||||||
// Carga las musicas del juego
|
|
||||||
loadMusics();
|
|
||||||
|
|
||||||
globalInputs::init();
|
globalInputs::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,13 +126,12 @@ Director::~Director()
|
|||||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||||
|
|
||||||
Asset::destroy();
|
Asset::destroy();
|
||||||
|
Resource::destroy();
|
||||||
Input::destroy();
|
Input::destroy();
|
||||||
Screen::destroy();
|
Screen::destroy();
|
||||||
Notifier::destroy();
|
Notifier::destroy();
|
||||||
OnScreenHelp::destroy();
|
OnScreenHelp::destroy();
|
||||||
|
|
||||||
sounds_.clear();
|
|
||||||
musics_.clear();
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer_);
|
SDL_DestroyRenderer(renderer_);
|
||||||
SDL_DestroyWindow(window_);
|
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
|
// Ejecuta la sección con el logo
|
||||||
void Director::runLogo()
|
void Director::runLogo()
|
||||||
{
|
{
|
||||||
@@ -609,14 +573,14 @@ void Director::runLogo()
|
|||||||
// Ejecuta la sección con la secuencia de introducción
|
// Ejecuta la sección con la secuencia de introducción
|
||||||
void Director::runIntro()
|
void Director::runIntro()
|
||||||
{
|
{
|
||||||
auto intro = std::make_unique<Intro>(getMusic(musics_, "intro.ogg"));
|
auto intro = std::make_unique<Intro>();
|
||||||
intro->run();
|
intro->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección con el título del juego
|
// Ejecuta la sección con el título del juego
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
auto title = std::make_unique<Title>(getMusic(musics_, "title.ogg"));
|
auto title = std::make_unique<Title>();
|
||||||
title->run();
|
title->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,21 +589,21 @@ void Director::runGame()
|
|||||||
{
|
{
|
||||||
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||||
constexpr auto current_stage = 0;
|
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();
|
game->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección donde se muestran las instrucciones
|
// Ejecuta la sección donde se muestran las instrucciones
|
||||||
void Director::runInstructions()
|
void Director::runInstructions()
|
||||||
{
|
{
|
||||||
auto instructions = std::make_unique<Instructions>(getMusic(musics_, "title.ogg"));
|
auto instructions = std::make_unique<Instructions>();
|
||||||
instructions->run();
|
instructions->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||||
void Director::runHiScoreTable()
|
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();
|
hi_score_table->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +612,7 @@ void Director::runDemoGame()
|
|||||||
{
|
{
|
||||||
const auto player_id = (rand() % 2) + 1;
|
const auto player_id = (rand() % 2) + 1;
|
||||||
constexpr auto current_stage = 0;
|
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();
|
game->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,7 +669,6 @@ int Director::run()
|
|||||||
const auto return_code = (section::options == section::Options::QUIT_NORMAL) ? "keyboard" : "controller";
|
const auto return_code = (section::options == section::Options::QUIT_NORMAL) ? "keyboard" : "controller";
|
||||||
std::cout << "\nGame end with " << return_code << std::endl;
|
std::cout << "\nGame end with " << return_code << std::endl;
|
||||||
|
|
||||||
|
|
||||||
#ifndef VERBOSE
|
#ifndef VERBOSE
|
||||||
// Habilita de nuevo los std::cout
|
// Habilita de nuevo los std::cout
|
||||||
std::cout.rdbuf(orig_buf);
|
std::cout.rdbuf(orig_buf);
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ namespace lang
|
|||||||
{
|
{
|
||||||
enum class Code : int;
|
enum class Code : int;
|
||||||
}
|
}
|
||||||
struct MusicFile;
|
struct ResourceMusic;
|
||||||
struct SoundFile;
|
struct ResourceSound;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
constexpr char WINDOW_CAPTION[] = "Coffee Crisis Arcade Edition";
|
||||||
@@ -18,16 +18,14 @@ class Director
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window_; // La ventana donde dibujamos
|
SDL_Window *window_; // La ventana donde dibujamos
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
std::streambuf *orig_buf; ///< Puntero al buffer de flujo original para restaurar std::cout
|
std::streambuf *orig_buf; ///< Puntero al buffer de flujo original para restaurar std::cout
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string executable_path_; // Path del ejecutable
|
std::string executable_path_; // Path del ejecutable
|
||||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||||
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
std::string param_file_argument_; // Argumento para gestionar el fichero con los parametros del programa
|
||||||
std::vector<SoundFile> sounds_; // Vector con los sonidos
|
|
||||||
std::vector<MusicFile> musics_; // Vector con las musicas
|
|
||||||
|
|
||||||
// Inicializa jail_audio
|
// Inicializa jail_audio
|
||||||
void initJailAudio();
|
void initJailAudio();
|
||||||
@@ -44,12 +42,6 @@ private:
|
|||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool setFileList();
|
bool setFileList();
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
|
||||||
void loadSounds();
|
|
||||||
|
|
||||||
// Carga las musicas del juego
|
|
||||||
void loadMusics();
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, const char *argv[]);
|
void checkProgramArguments(int argc, const char *argv[]);
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,14 @@
|
|||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
||||||
#include "item.h" // for Item, ItemType::COFFEE_MACHINE, ItemType::CLOCK
|
#include "item.h" // for Item, ItemType::COFFEE_MACHINE, ItemType::CLOCK
|
||||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
#include "jail_audio.h" // for JA_PlaySound
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // for Notifier
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "player.h" // for Player, PlayerStatus
|
#include "player.h" // for Player, PlayerStatus
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
@@ -39,9 +40,8 @@ struct JA_Music_t; // lines 35-35
|
|||||||
struct JA_Sound_t; // lines 36-36
|
struct JA_Sound_t; // lines 36-36
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
Game::Game(int player_id, int current_stage, bool demo)
|
||||||
: music_(music),
|
: current_stage_(current_stage)
|
||||||
current_stage_(current_stage)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
asset_ = Asset::get();
|
asset_ = Asset::get();
|
||||||
@@ -429,25 +429,6 @@ void Game::loadMedia()
|
|||||||
text_nokia2_big_ = std::make_unique<Text>(asset_->get("nokia_big2.png"), asset_->get("nokia_big2.txt"), renderer_);
|
text_nokia2_big_ = std::make_unique<Text>(asset_->get("nokia_big2.png"), asset_->get("nokia_big2.txt"), renderer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sonidos
|
|
||||||
{
|
|
||||||
balloon_sound_ = JA_LoadSound(asset_->get("balloon.wav").c_str());
|
|
||||||
bubble1_sound_ = JA_LoadSound(asset_->get("bubble1.wav").c_str());
|
|
||||||
bubble2_sound_ = JA_LoadSound(asset_->get("bubble2.wav").c_str());
|
|
||||||
bubble3_sound_ = JA_LoadSound(asset_->get("bubble3.wav").c_str());
|
|
||||||
bubble4_sound_ = JA_LoadSound(asset_->get("bubble4.wav").c_str());
|
|
||||||
bullet_sound_ = JA_LoadSound(asset_->get("bullet.wav").c_str());
|
|
||||||
clock_sound_ = JA_LoadSound(asset_->get("clock.wav").c_str());
|
|
||||||
coffee_out_sound_ = JA_LoadSound(asset_->get("coffeeout.wav").c_str());
|
|
||||||
hi_score_sound_ = JA_LoadSound(asset_->get("hiscore.wav").c_str());
|
|
||||||
item_drop_sound_ = JA_LoadSound(asset_->get("itemdrop.wav").c_str());
|
|
||||||
item_pick_up_sound_ = JA_LoadSound(asset_->get("itempickup.wav").c_str());
|
|
||||||
player_collision_sound_ = JA_LoadSound(asset_->get("player_collision.wav").c_str());
|
|
||||||
power_ball_sound_ = JA_LoadSound(asset_->get("powerball.wav").c_str());
|
|
||||||
stage_change_sound_ = JA_LoadSound(asset_->get("stage_change.wav").c_str());
|
|
||||||
coffee_machine_sound_ = JA_LoadSound(asset_->get("title.wav").c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "** RESOURCES FOR GAME SECTION LOADED\n"
|
std::cout << "** RESOURCES FOR GAME SECTION LOADED\n"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
@@ -467,23 +448,6 @@ void Game::unloadMedia()
|
|||||||
balloon_animations_.clear();
|
balloon_animations_.clear();
|
||||||
explosions_animations_.clear();
|
explosions_animations_.clear();
|
||||||
item_animations_.clear();
|
item_animations_.clear();
|
||||||
|
|
||||||
// Sonidos
|
|
||||||
JA_DeleteSound(balloon_sound_);
|
|
||||||
JA_DeleteSound(bullet_sound_);
|
|
||||||
JA_DeleteSound(player_collision_sound_);
|
|
||||||
JA_DeleteSound(hi_score_sound_);
|
|
||||||
JA_DeleteSound(item_drop_sound_);
|
|
||||||
JA_DeleteSound(item_pick_up_sound_);
|
|
||||||
JA_DeleteSound(coffee_out_sound_);
|
|
||||||
JA_DeleteSound(stage_change_sound_);
|
|
||||||
JA_DeleteSound(bubble1_sound_);
|
|
||||||
JA_DeleteSound(bubble2_sound_);
|
|
||||||
JA_DeleteSound(bubble3_sound_);
|
|
||||||
JA_DeleteSound(bubble4_sound_);
|
|
||||||
JA_DeleteSound(clock_sound_);
|
|
||||||
JA_DeleteSound(power_ball_sound_);
|
|
||||||
JA_DeleteSound(coffee_machine_sound_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de datos para la demo
|
// Carga el fichero de datos para la demo
|
||||||
@@ -649,7 +613,7 @@ void Game::updateHiScore()
|
|||||||
if (hi_score_achieved_ == false)
|
if (hi_score_achieved_ == false)
|
||||||
{
|
{
|
||||||
hi_score_achieved_ = true;
|
hi_score_achieved_ = true;
|
||||||
JA_PlaySound(hi_score_sound_);
|
JA_PlaySound(Resource::get()->getSound("hiscore.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -725,7 +689,7 @@ void Game::updateStage()
|
|||||||
updateHiScore();
|
updateHiScore();
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
}
|
}
|
||||||
JA_PlaySound(stage_change_sound_);
|
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
||||||
stage_bitmap_counter_ = 0;
|
stage_bitmap_counter_ = 0;
|
||||||
balloon_speed_ = default_balloon_speed_;
|
balloon_speed_ = default_balloon_speed_;
|
||||||
setBalloonSpeed(balloon_speed_);
|
setBalloonSpeed(balloon_speed_);
|
||||||
@@ -763,7 +727,11 @@ void Game::updateGameOver()
|
|||||||
{
|
{
|
||||||
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
||||||
const auto index = rand() % 4;
|
const auto index = rand() % 4;
|
||||||
JA_Sound_t *sound[4] = {bubble1_sound_, bubble2_sound_, bubble3_sound_, bubble4_sound_};
|
JA_Sound_t *sound[4] = {
|
||||||
|
Resource::get()->getSound("bubble1.wav"),
|
||||||
|
Resource::get()->getSound("bubble2.wav"),
|
||||||
|
Resource::get()->getSound("bubble3.wav"),
|
||||||
|
Resource::get()->getSound("bubble4.wav")};
|
||||||
JA_PlaySound(sound[index], 0);
|
JA_PlaySound(sound[index], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -991,7 +959,7 @@ void Game::destroyAllBalloons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
balloon_deploy_counter_ = 300;
|
balloon_deploy_counter_ = 300;
|
||||||
JA_PlaySound(power_ball_sound_);
|
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
||||||
screen_->flash(flash_color, 5);
|
screen_->flash(flash_color, 5);
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
@@ -1119,7 +1087,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
JA_PlaySound(item_pick_up_sound_);
|
JA_PlaySound(Resource::get()->getSound("itempickup.wav"));
|
||||||
item->disable();
|
item->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1154,7 +1122,7 @@ void Game::checkBulletBalloonCollision()
|
|||||||
if (droppeditem != ItemType::COFFEE_MACHINE)
|
if (droppeditem != ItemType::COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
||||||
JA_PlaySound(item_drop_sound_);
|
JA_PlaySound(Resource::get()->getSound("itemdrop.wav"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1167,7 +1135,7 @@ void Game::checkBulletBalloonCollision()
|
|||||||
popBalloon(balloon);
|
popBalloon(balloon);
|
||||||
|
|
||||||
// Sonido de explosión
|
// Sonido de explosión
|
||||||
JA_PlaySound(balloon_sound_);
|
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
||||||
|
|
||||||
// Deshabilita la bala
|
// Deshabilita la bala
|
||||||
bullet->disable();
|
bullet->disable();
|
||||||
@@ -1209,8 +1177,7 @@ void Game::renderBullets()
|
|||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
|
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
|
||||||
{
|
{
|
||||||
auto b = std::make_unique<Bullet>(x, y, kind, powered_up, owner, &(param.game.play_area.rect), bullet_texture_);
|
bullets_.emplace_back(std::make_unique<Bullet>(x, y, kind, powered_up, owner, &(param.game.play_area.rect), bullet_texture_));
|
||||||
bullets_.push_back(std::move(b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia el vector de balas
|
// Vacia el vector de balas
|
||||||
@@ -1238,7 +1205,7 @@ void Game::updateItems()
|
|||||||
item->update();
|
item->update();
|
||||||
if (item->isOnFloor())
|
if (item->isOnFloor())
|
||||||
{
|
{
|
||||||
JA_PlaySound(coffee_machine_sound_);
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1439,7 +1406,7 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
|
|||||||
// Lo pierde
|
// Lo pierde
|
||||||
player->removeExtraHit();
|
player->removeExtraHit();
|
||||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||||
JA_PlaySound(coffee_out_sound_);
|
JA_PlaySound(Resource::get()->getSound("coffeeout.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1450,9 +1417,9 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
|
|||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
}
|
}
|
||||||
stopAllBalloons(10);
|
stopAllBalloons(10);
|
||||||
JA_PlaySound(player_collision_sound_);
|
JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
JA_PlaySound(coffee_out_sound_);
|
JA_PlaySound(Resource::get()->getSound("coffeeout.wav"));
|
||||||
player->setStatusPlaying(PlayerStatus::DYING);
|
player->setStatusPlaying(PlayerStatus::DYING);
|
||||||
if (!demo_.enabled)
|
if (!demo_.enabled)
|
||||||
{
|
{
|
||||||
@@ -1772,14 +1739,14 @@ void Game::renderMessages()
|
|||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(clock_sound_);
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 15 == 0)
|
if (time_stopped_counter_ % 15 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(clock_sound_);
|
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1843,7 +1810,7 @@ void Game::checkMusicStatus()
|
|||||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||||
{
|
{
|
||||||
// Si se ha completado el juego o los jugadores han terminado, detiene la música
|
// Si se ha completado el juego o los jugadores han terminado, detiene la música
|
||||||
game_completed_ || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(music_);
|
game_completed_ || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(Resource::get()->getMusic("playing.ogg"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2352,6 +2319,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
player->setInput(bulletType == BulletType::UP ? InputType::FIRE_CENTER : bulletType == BulletType::LEFT ? InputType::FIRE_LEFT
|
player->setInput(bulletType == BulletType::UP ? InputType::FIRE_CENTER : bulletType == BulletType::LEFT ? InputType::FIRE_LEFT
|
||||||
: InputType::FIRE_RIGHT);
|
: InputType::FIRE_RIGHT);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
||||||
|
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
|
||||||
player->setFireCooldown(10); // Establece un tiempo de espera para el próximo disparo.
|
player->setFireCooldown(10); // Establece un tiempo de espera para el próximo disparo.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,24 +145,6 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
|
|
||||||
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
|
||||||
JA_Sound_t *bullet_sound_; // Sonido para los disparos
|
|
||||||
JA_Sound_t *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
|
||||||
JA_Sound_t *hi_score_sound_; // Sonido para cuando se alcanza la máxima puntuación
|
|
||||||
JA_Sound_t *item_drop_sound_; // Sonido para cuando se genera un item
|
|
||||||
JA_Sound_t *item_pick_up_sound_; // Sonido para cuando se recoge un item
|
|
||||||
JA_Sound_t *coffee_out_sound_; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
|
||||||
JA_Sound_t *stage_change_sound_; // Sonido para cuando se cambia de fase
|
|
||||||
JA_Sound_t *bubble1_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble2_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble3_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *bubble4_sound_; // Sonido para cuando el jugador muere
|
|
||||||
JA_Sound_t *clock_sound_; // Sonido para cuando se detiene el tiempo con el item reloj
|
|
||||||
JA_Sound_t *power_ball_sound_; // Sonido para cuando se explota una Power Ball
|
|
||||||
JA_Sound_t *coffee_machine_sound_; // Sonido para cuando la máquina de café toca el suelo
|
|
||||||
|
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||||
@@ -468,7 +450,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int playerID, int current_stage, bool demo, JA_Music_t *music);
|
Game(int playerID, int current_stage, bool demo);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
#include "animated_sprite.h" // for SpriteAnimated
|
#include "animated_sprite.h" // for SpriteAnimated
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
#include "jail_audio.h" // JA_PlaySound
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "smart_sprite.h" // for SpriteSmart
|
#include "smart_sprite.h" // for SpriteSmart
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
@@ -26,7 +27,6 @@ GameLogo::GameLogo(int x, int y)
|
|||||||
|
|
||||||
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
||||||
|
|
||||||
crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())),
|
|
||||||
|
|
||||||
x_(x),
|
x_(x),
|
||||||
y_(y)
|
y_(y)
|
||||||
@@ -35,12 +35,6 @@ GameLogo::GameLogo(int x, int y)
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
GameLogo::~GameLogo()
|
|
||||||
{
|
|
||||||
JA_DeleteSound(crash_sound_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
void GameLogo::init()
|
void GameLogo::init()
|
||||||
{
|
{
|
||||||
@@ -137,7 +131,7 @@ void GameLogo::update()
|
|||||||
status_ = Status::SHAKING;
|
status_ = Status::SHAKING;
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(crash_sound_);
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory> // for unique_ptr, shared_ptr
|
#include <memory> // for unique_ptr, shared_ptr
|
||||||
class AnimatedSprite;
|
#include "animated_sprite.h"
|
||||||
class SmartSprite;
|
#include "smart_sprite.h"
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
struct JA_Sound_t; // lines 10-10
|
struct JA_Sound_t; // lines 10-10
|
||||||
@@ -43,8 +43,6 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||||
|
|
||||||
JA_Sound_t *crash_sound_; // Sonido con el impacto del título
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int x_; // Posición donde dibujar el logo
|
int x_; // Posición donde dibujar el logo
|
||||||
int y_; // Posición donde dibujar el logo
|
int y_; // Posición donde dibujar el logo
|
||||||
@@ -63,7 +61,7 @@ public:
|
|||||||
GameLogo(int x, int y);
|
GameLogo(int x, int y);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~GameLogo();
|
~GameLogo() = default;
|
||||||
|
|
||||||
// Pinta la clase en pantalla
|
// Pinta la clase en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|||||||
@@ -15,14 +15,14 @@
|
|||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
|
#include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT...
|
||||||
#include "utils.h" // for Param, ParamGame, Color, HiScoreEntry
|
#include "utils.h" // for Param, ParamGame, Color, HiScoreEntry
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
HiScoreTable::HiScoreTable()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
renderer_ = Screen::get()->getRenderer();
|
renderer_ = Screen::get()->getRenderer();
|
||||||
@@ -78,7 +78,7 @@ void HiScoreTable::update()
|
|||||||
// Mantiene la música sonando
|
// Mantiene la música sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class Background; // lines 8-8
|
|||||||
class Fade; // lines 9-9
|
class Fade; // lines 9-9
|
||||||
class Text; // lines 10-10
|
class Text; // lines 10-10
|
||||||
enum class FadeMode : Uint8; // lines 11-11
|
enum class FadeMode : Uint8; // lines 11-11
|
||||||
struct JA_Music_t; // lines 12-12
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
|
||||||
@@ -28,7 +27,6 @@ private:
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
|
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||||
@@ -68,7 +66,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit HiScoreTable(JA_Music_t *music);
|
HiScoreTable();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~HiScoreTable();
|
~HiScoreTable();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
@@ -23,8 +24,7 @@
|
|||||||
struct JA_Music_t; // lines 22-22
|
struct JA_Music_t; // lines 22-22
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions(JA_Music_t *music)
|
Instructions::Instructions()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
renderer_ = Screen::get()->getRenderer();
|
renderer_ = Screen::get()->getRenderer();
|
||||||
@@ -80,21 +80,12 @@ Instructions::~Instructions()
|
|||||||
void Instructions::iniSprites()
|
void Instructions::iniSprites()
|
||||||
{
|
{
|
||||||
// Inicializa las texturas
|
// Inicializa las texturas
|
||||||
auto item1 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points1_disk.png"));
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, Asset::get()->get("item_points1_disk.png")));
|
||||||
item_textures_.push_back(item1);
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, Asset::get()->get("item_points2_gavina.png")));
|
||||||
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, Asset::get()->get("item_points3_pacmar.png")));
|
||||||
auto item2 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points2_gavina.png"));
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, Asset::get()->get("item_clock.png")));
|
||||||
item_textures_.push_back(item2);
|
item_textures_.emplace_back(std::make_shared<Texture>(renderer_, Asset::get()->get("item_coffee.png")));
|
||||||
|
|
||||||
auto item3 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_points3_pacmar.png"));
|
|
||||||
item_textures_.push_back(item3);
|
|
||||||
|
|
||||||
auto item4 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_clock.png"));
|
|
||||||
item_textures_.push_back(item4);
|
|
||||||
|
|
||||||
auto item5 = std::make_shared<Texture>(renderer_, Asset::get()->get("item_coffee.png"));
|
|
||||||
item_textures_.push_back(item5);
|
|
||||||
|
|
||||||
// Inicializa los sprites
|
// Inicializa los sprites
|
||||||
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
for (int i = 0; i < (int)item_textures_.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -231,7 +222,7 @@ void Instructions::update()
|
|||||||
|
|
||||||
// Mantiene la música sonando
|
// Mantiene la música sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ private:
|
|||||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||||
|
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
JA_Music_t *music_; // Musica de fondo
|
|
||||||
SDL_Texture *texture_; // Textura fija con el texto
|
SDL_Texture *texture_; // Textura fija con el texto
|
||||||
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Instructions(JA_Music_t *music);
|
Instructions();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Instructions();
|
~Instructions();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // for Name, name, Options, options
|
||||||
#include "smart_sprite.h" // for SpriteSmart
|
#include "smart_sprite.h" // for SpriteSmart
|
||||||
@@ -19,8 +20,7 @@
|
|||||||
struct JA_Music_t; // lines 19-19
|
struct JA_Music_t; // lines 19-19
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro(JA_Music_t *music)
|
Intro::Intro()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
auto renderer = Screen::get()->getRenderer();
|
auto renderer = Screen::get()->getRenderer();
|
||||||
@@ -425,7 +425,7 @@ void Intro::render()
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void Intro::run()
|
void Intro::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_, 0);
|
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
||||||
|
|
||||||
while (section::name == section::Name::INTRO)
|
while (section::name == section::Name::INTRO)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ private:
|
|||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||||
JA_Music_t *music_; // Musica para la intro
|
|
||||||
int scene_; // Indica que escena está activa
|
int scene_; // Indica que escena está activa
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -51,7 +50,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Intro(JA_Music_t *music);
|
Intro();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Intro() = default;
|
~Intro() = default;
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
|||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||||
{
|
{
|
||||||
if (!JA_soundEnabled) return 0;
|
if (!JA_soundEnabled || !sound) return 0;
|
||||||
|
|
||||||
int channel = 0;
|
int channel = 0;
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
|
|||||||
101
source/resource.cpp
Normal file
101
source/resource.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#include "resource.h"
|
||||||
|
#include "asset.h"
|
||||||
|
|
||||||
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
|
Resource *Resource::resource_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
|
void Resource::init()
|
||||||
|
{
|
||||||
|
Resource::resource_ = new Resource();
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
|
void Resource::destroy()
|
||||||
|
{
|
||||||
|
delete Resource::resource_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||||
|
Resource *Resource::get()
|
||||||
|
{
|
||||||
|
return Resource::resource_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Resource::Resource()
|
||||||
|
{
|
||||||
|
loadSounds();
|
||||||
|
loadMusics();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Resource::~Resource()
|
||||||
|
{
|
||||||
|
sounds_.clear();
|
||||||
|
musics_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el fichero de sonido a partir de un nombre
|
||||||
|
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &s : sounds_)
|
||||||
|
{
|
||||||
|
if (s.name == name)
|
||||||
|
{
|
||||||
|
return s.sound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el fichero de música a partir de un nombre
|
||||||
|
JA_Music_t *Resource::getMusic(const std::string &name)
|
||||||
|
{
|
||||||
|
for (const auto &m : musics_)
|
||||||
|
{
|
||||||
|
if (m.name == name)
|
||||||
|
{
|
||||||
|
return m.music;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los sonidos del juego
|
||||||
|
void Resource::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)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
sounds_.emplace_back(ResourceSound{name, JA_LoadSound(l.c_str())});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga las musicas del juego
|
||||||
|
void Resource::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)
|
||||||
|
{
|
||||||
|
// Encuentra el último índice de '/'
|
||||||
|
auto last_index = l.find_last_of('/') + 1;
|
||||||
|
|
||||||
|
// Obtiene la subcadena desde el último '/'
|
||||||
|
auto name = l.substr(last_index);
|
||||||
|
|
||||||
|
musics_.emplace_back(ResourceMusic{name, JA_LoadMusic(l.c_str())});
|
||||||
|
}
|
||||||
|
}
|
||||||
60
source/resource.h
Normal file
60
source/resource.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "jail_audio.h"
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros de sonido y su nombre
|
||||||
|
struct ResourceSound
|
||||||
|
{
|
||||||
|
std::string name; // Nombre del sonido
|
||||||
|
JA_Sound_t *sound; // Fichero con el sonido
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar ficheros musicales y su nombre
|
||||||
|
struct ResourceMusic
|
||||||
|
{
|
||||||
|
std::string name; // Nombre de la musica
|
||||||
|
JA_Music_t *music; // Fichero con la música
|
||||||
|
};
|
||||||
|
|
||||||
|
class Resource
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto resource privado para Don Melitón
|
||||||
|
static Resource *resource_;
|
||||||
|
|
||||||
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
|
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||||
|
|
||||||
|
// Carga los sonidos del juego
|
||||||
|
void loadSounds();
|
||||||
|
|
||||||
|
// Carga las musicas del juego
|
||||||
|
void loadMusics();
|
||||||
|
|
||||||
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Resource();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Resource();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto resource con esta función estática
|
||||||
|
static void init();
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
|
||||||
|
static Resource *get();
|
||||||
|
|
||||||
|
// Obtiene el fichero de sonido a partir de un nombre
|
||||||
|
JA_Sound_t *getSound(const std::string &name);
|
||||||
|
|
||||||
|
// Obtiene el fichero de música a partir de un nombre
|
||||||
|
JA_Music_t *getMusic(const std::string &name);
|
||||||
|
};
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // for Notifier
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for Options, options, Name, name
|
#include "section.h" // for Options, options, Name, name
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
@@ -22,13 +23,10 @@
|
|||||||
struct JA_Music_t; // lines 17-17
|
struct JA_Music_t; // lines 17-17
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(JA_Music_t *music)
|
Title::Title()
|
||||||
: music_(music)
|
|
||||||
{
|
{
|
||||||
// Copia las direcciones de los punteros y objetos
|
// Copia las direcciones de los punteros y objetos
|
||||||
input_ = Input::get();
|
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||||
screen_ = Screen::get();
|
|
||||||
SDL_Renderer *renderer = screen_->getRenderer();
|
|
||||||
|
|
||||||
// Reserva memoria y crea los objetos
|
// Reserva memoria y crea los objetos
|
||||||
fade_ = std::make_unique<Fade>(renderer);
|
fade_ = std::make_unique<Fade>(renderer);
|
||||||
@@ -66,7 +64,7 @@ void Title::init()
|
|||||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||||
fade_->setPost(param.fade.post_duration);
|
fade_->setPost(param.fade.post_duration);
|
||||||
demo_ = true;
|
demo_ = true;
|
||||||
num_controllers_ = input_->getNumControllers();
|
num_controllers_ = Input::get()->getNumControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -79,7 +77,7 @@ void Title::update()
|
|||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen_->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
// Comprueba el fade_ y si se ha acabado
|
// Comprueba el fade_ y si se ha acabado
|
||||||
fade_->update();
|
fade_->update();
|
||||||
@@ -116,7 +114,7 @@ void Title::update()
|
|||||||
// Reproduce la música
|
// Reproduce la música
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music_);
|
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el logo con el título del juego
|
// Actualiza el logo con el título del juego
|
||||||
@@ -138,10 +136,10 @@ void Title::update()
|
|||||||
void Title::render()
|
void Title::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen_->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen_->clean(bg_color);
|
Screen::get()->clean(bg_color);
|
||||||
|
|
||||||
// Dibuja el mosacico de fondo
|
// Dibuja el mosacico de fondo
|
||||||
tiled_bg_->render();
|
tiled_bg_->render();
|
||||||
@@ -176,7 +174,7 @@ void Title::render()
|
|||||||
fade_->render();
|
fade_->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen_->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
@@ -241,7 +239,7 @@ void Title::checkInput()
|
|||||||
if (!define_buttons_->isEnabled())
|
if (!define_buttons_->isEnabled())
|
||||||
{
|
{
|
||||||
// Comprueba el teclado para empezar a jugar
|
// Comprueba el teclado para empezar a jugar
|
||||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
{
|
{
|
||||||
@@ -251,27 +249,27 @@ void Title::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||||
if (input_->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si algun mando quiere ser configurado
|
// Comprueba si algun mando quiere ser configurado
|
||||||
if (input_->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
define_buttons_->enable(i);
|
define_buttons_->enable(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el botón de START de los mandos
|
// Comprueba el botón de START de los mandos
|
||||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
// Si no está el botón de servicio activo
|
// Si no está el botón de servicio activo
|
||||||
if (!input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (!Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
{
|
{
|
||||||
@@ -285,7 +283,7 @@ void Title::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen_->checkInput();
|
Screen::get()->checkInput();
|
||||||
define_buttons_->checkInput();
|
define_buttons_->checkInput();
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
@@ -320,7 +318,7 @@ void Title::resetCounter()
|
|||||||
// Intercambia la asignación de mandos a los jugadores
|
// Intercambia la asignación de mandos a los jugadores
|
||||||
void Title::swapControllers()
|
void Title::swapControllers()
|
||||||
{
|
{
|
||||||
const auto num_controllers = input_->getNumControllers();
|
const auto num_controllers = Input::get()->getNumControllers();
|
||||||
|
|
||||||
if (num_controllers == 0)
|
if (num_controllers == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ class Title
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
|
||||||
Input *input_; // Objeto para leer las entradas de teclado o mando
|
|
||||||
std::unique_ptr<Tiledbg> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
std::unique_ptr<Tiledbg> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||||
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||||
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
||||||
@@ -52,8 +50,6 @@ private:
|
|||||||
std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
||||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
||||||
|
|
||||||
JA_Music_t *music_; // Musica para el titulo
|
|
||||||
|
|
||||||
// Variable
|
// Variable
|
||||||
int counter_; // Temporizador para la pantalla de titulo
|
int counter_; // Temporizador para la pantalla de titulo
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
@@ -89,7 +85,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Title(JA_Music_t *music);
|
Title();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Title() = default;
|
~Title() = default;
|
||||||
|
|||||||
@@ -104,38 +104,6 @@ std::string toLower(const std::string &str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el fichero de sonido a partir de un nombre
|
|
||||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name)
|
|
||||||
{
|
|
||||||
for (const auto &s : sounds)
|
|
||||||
{
|
|
||||||
if (s.name == name)
|
|
||||||
{
|
|
||||||
return s.file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el fichero de música a partir de un nombre
|
|
||||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name)
|
|
||||||
{
|
|
||||||
for (const auto &m : music)
|
|
||||||
{
|
|
||||||
if (m.name == name)
|
|
||||||
{
|
|
||||||
return m.file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ordena las entradas de la tabla de records
|
|
||||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2)
|
|
||||||
{
|
|
||||||
return (entry1.score > entry2.score) ? entry1 : entry2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja un circulo
|
// Dibuja un circulo
|
||||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
|
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -215,19 +215,6 @@ struct Param
|
|||||||
ParamNotification notification; // Opciones para las notificaciones
|
ParamNotification notification; // Opciones para las notificaciones
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para almacenar ficheros de sonido y su nombre
|
|
||||||
struct SoundFile
|
|
||||||
{
|
|
||||||
std::string name; // Nombre del sonido
|
|
||||||
JA_Sound_t *file; // Fichero con el sonido
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para almacenar ficheros musicales y su nombre
|
|
||||||
struct MusicFile
|
|
||||||
{
|
|
||||||
std::string name; // Nombre de la musica
|
|
||||||
JA_Music_t *file; // Fichero con la música
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||||
@@ -256,15 +243,6 @@ std::string boolToOnOff(bool value);
|
|||||||
// Convierte una cadena a minusculas
|
// Convierte una cadena a minusculas
|
||||||
std::string toLower(const std::string &str);
|
std::string toLower(const std::string &str);
|
||||||
|
|
||||||
// Obtiene el fichero de sonido a partir de un nombre
|
|
||||||
JA_Sound_t *getSound(const std::vector<SoundFile> &sounds, const std::string &name);
|
|
||||||
|
|
||||||
// Obtiene el fichero de música a partir de un nombre
|
|
||||||
JA_Music_t *getMusic(const std::vector<MusicFile> &music, const std::string &name);
|
|
||||||
|
|
||||||
// Ordena las entradas de la tabla de records
|
|
||||||
HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2);
|
|
||||||
|
|
||||||
// Dibuja un circulo
|
// Dibuja un circulo
|
||||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user