treballant en la classe Audio
This commit is contained in:
@@ -22,7 +22,7 @@ enum class AssetType : int
|
|||||||
class Asset
|
class Asset
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto asset privado para Don Melitón
|
// [SINGLETON] Objeto asset privado
|
||||||
static Asset *asset_;
|
static Asset *asset_;
|
||||||
|
|
||||||
// Estructura para definir un item
|
// Estructura para definir un item
|
||||||
|
|||||||
129
source/audio.cpp
Normal file
129
source/audio.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include "audio.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "resource.h"
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
|
Audio *Audio::audio_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto asset con esta función estática
|
||||||
|
void Audio::init()
|
||||||
|
{
|
||||||
|
Audio::audio_ = new Audio();
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto asset con esta función estática
|
||||||
|
void Audio::destroy()
|
||||||
|
{
|
||||||
|
delete Audio::audio_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto asset y podemos trabajar con él
|
||||||
|
Audio *Audio::get()
|
||||||
|
{
|
||||||
|
return Audio::audio_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Audio::Audio()
|
||||||
|
{
|
||||||
|
// Inicializa SDL
|
||||||
|
if (!SDL_Init(SDL_INIT_AUDIO))
|
||||||
|
{
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_AUDIO: INITIALIZING\n");
|
||||||
|
|
||||||
|
JA_Init(48000, SDL_AUDIO_S16LE, 2);
|
||||||
|
enable(options.audio.enabled);
|
||||||
|
setMusicVolume(options.audio.music.volume);
|
||||||
|
setSoundVolume(options.audio.sound.volume);
|
||||||
|
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Audio::~Audio()
|
||||||
|
{
|
||||||
|
JA_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce la música
|
||||||
|
void Audio::playMusic(const std::string &name, const int loop)
|
||||||
|
{
|
||||||
|
if (enabled_ && music_enabled_)
|
||||||
|
{
|
||||||
|
JA_PlayMusic(Resource::get()->getMusic(name), loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pausa la música
|
||||||
|
void Audio::pauseMusic()
|
||||||
|
{
|
||||||
|
if (enabled_ && music_enabled_)
|
||||||
|
{
|
||||||
|
JA_PauseMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detiene la música
|
||||||
|
void Audio::stopMusic()
|
||||||
|
{
|
||||||
|
if (enabled_ && music_enabled_)
|
||||||
|
{
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce un sonido
|
||||||
|
void Audio::playSound(const std::string &name)
|
||||||
|
{
|
||||||
|
if (enabled_ && sound_enabled_)
|
||||||
|
{
|
||||||
|
JA_PlaySound(Resource::get()->getSound(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detiene todos los sonidos
|
||||||
|
void Audio::stopAllSounds()
|
||||||
|
{
|
||||||
|
if (enabled_ && sound_enabled_)
|
||||||
|
{
|
||||||
|
JA_StopChannel(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Realiza un fundido de salida de la música
|
||||||
|
void Audio::fadeOutMusic(int milliseconds)
|
||||||
|
{
|
||||||
|
if (enabled_ && music_enabled_)
|
||||||
|
{
|
||||||
|
JA_FadeOutMusic(milliseconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el volumen de los sonidos
|
||||||
|
void Audio::setSoundVolume(int volume)
|
||||||
|
{
|
||||||
|
if (enabled_ && sound_enabled_)
|
||||||
|
{
|
||||||
|
volume = std::clamp(volume, 0, 100);
|
||||||
|
const int COVERTED_VOLUME = static_cast<int>((volume / 100.0) * 128);
|
||||||
|
JA_SetSoundVolume(COVERTED_VOLUME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el volumen de la música
|
||||||
|
void Audio::setMusicVolume(int volume)
|
||||||
|
{
|
||||||
|
if (enabled_ && music_enabled_)
|
||||||
|
{
|
||||||
|
volume = std::clamp(volume, 0, 100);
|
||||||
|
const int COVERTED_VOLUME = static_cast<int>((volume / 100.0) * 128);
|
||||||
|
JA_SetMusicVolume(COVERTED_VOLUME);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
source/audio.h
Normal file
63
source/audio.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "audio.h"
|
||||||
|
|
||||||
|
class Audio
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto audio privado
|
||||||
|
static Audio *audio_;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Audio(); // Constructor privado para el patrón Singleton
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Audio(); // Destructor privado para el patrón Singleton
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
bool enabled_ = true; // Indica si el audio está habilitado
|
||||||
|
bool sound_enabled_ = true; // Indica si los sonidos están habilitados
|
||||||
|
bool music_enabled_ = true; // Indica si la música está habilitada
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(); // Inicializa el objeto Singleton
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy(); // Destruye el objeto Singleton
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Audio *get(); // Devuelve la instancia del Singleton
|
||||||
|
|
||||||
|
void playMusic(const std::string &name, const int loop = -1); // Reproduce la música
|
||||||
|
void pauseMusic(); // Pausa la música
|
||||||
|
void stopMusic(); // Detiene la música
|
||||||
|
|
||||||
|
void playSound(const std::string &name); // Reproduce un sonido
|
||||||
|
void stopAllSounds(); // Detiene todos los sonidos
|
||||||
|
|
||||||
|
void fadeOutMusic(int milliseconds); // Realiza un fundido de salida de la música
|
||||||
|
|
||||||
|
// Audio
|
||||||
|
void enable() { enabled_ = true; } // Habilita el audio
|
||||||
|
void disable() { enabled_ = false; } // Deshabilita el audio
|
||||||
|
void enable(bool value) { enabled_ = value; } // Habilita o deshabilita el audio
|
||||||
|
void toggleEnabled() { enabled_ = !enabled_; } // Alterna el estado del audio
|
||||||
|
|
||||||
|
// Sound
|
||||||
|
void enableSound() { sound_enabled_ = true; } // Habilita los sonidos
|
||||||
|
void disableSound() { sound_enabled_ = false; } // Deshabilita los sonidos
|
||||||
|
void enableSound(bool value) { sound_enabled_ = value; } // Habilita o deshabilita los sonidos
|
||||||
|
void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alterna el estado de los sonidos
|
||||||
|
|
||||||
|
// Music
|
||||||
|
void enableMusic() { music_enabled_ = true; } // Habilita la música
|
||||||
|
void disableMusic() { music_enabled_ = false; } // Deshabilita la música
|
||||||
|
void enableMusic(bool value) { music_enabled_ = value; } // Habilita o deshabilita la música
|
||||||
|
void toggleMusic() { music_enabled_ = !music_enabled_; } // Alterna el estado de la música
|
||||||
|
|
||||||
|
// Volume
|
||||||
|
void setSoundVolume(int volume); // Establece el volumen de los sonidos
|
||||||
|
void setMusicVolume(int volume); // Establece el volumen de la música
|
||||||
|
};
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "jail_audio.h"
|
#include "audio.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_FRect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_FRect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||||
@@ -414,6 +414,6 @@ void Balloon::playSound()
|
|||||||
{
|
{
|
||||||
if (sound_enabled_)
|
if (sound_enabled_)
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound(sound_));
|
Audio::get()->playSound(sound_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
|
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
|
||||||
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
|
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
|
||||||
#include "explosions.h" // Para Explosions
|
#include "explosions.h" // Para Explosions
|
||||||
#include "jail_audio.h" // Para JA_PlaySound
|
#include "audio.h" // Para JA_PlaySound
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
@@ -320,7 +320,7 @@ int BalloonManager::destroyAllBalloons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
balloon_deploy_counter_ = 300;
|
balloon_deploy_counter_ = 300;
|
||||||
JA_PlaySound(Resource::get()->getSound("power_ball_explosion.wav"));
|
Audio::get()->playSound("power_ball_explosion.wav");
|
||||||
Screen::get()->flash(FLASH_COLOR, 3);
|
Screen::get()->flash(FLASH_COLOR, 3);
|
||||||
Screen::get()->shake();
|
Screen::get()->shake();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "global_events.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
|
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume
|
#include "audio.h" // Para JA_GetMusicState, JA_SetMusicVolume
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "player.h" // Para Player, PlayerState
|
#include "player.h" // Para Player, PlayerState
|
||||||
@@ -71,7 +71,7 @@ Credits::~Credits()
|
|||||||
SDL_DestroyTexture(text_texture_);
|
SDL_DestroyTexture(text_texture_);
|
||||||
SDL_DestroyTexture(canvas_);
|
SDL_DestroyTexture(canvas_);
|
||||||
resetVolume();
|
resetVolume();
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
@@ -438,7 +438,7 @@ void Credits::updateBlackRects()
|
|||||||
{
|
{
|
||||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||||
setVolume(0);
|
setVolume(0);
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
if (counter_pre_fade_ == 400)
|
if (counter_pre_fade_ == 400)
|
||||||
{
|
{
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
@@ -472,10 +472,7 @@ void Credits::updateAllFades()
|
|||||||
fade_in_->update();
|
fade_in_->update();
|
||||||
if (fade_in_->hasEnded())
|
if (fade_in_->hasEnded())
|
||||||
{
|
{
|
||||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
Audio::get()->playMusic("credits.ogg");
|
||||||
{
|
|
||||||
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fade_out_->update();
|
fade_out_->update();
|
||||||
@@ -489,14 +486,14 @@ void Credits::updateAllFades()
|
|||||||
void Credits::setVolume(int amount)
|
void Credits::setVolume(int amount)
|
||||||
{
|
{
|
||||||
options.audio.music.volume = std::clamp(amount, 0, 100);
|
options.audio.music.volume = std::clamp(amount, 0, 100);
|
||||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
Audio::get()->setMusicVolume(options.audio.music.volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reestablece el nivel de volumen
|
// Reestablece el nivel de volumen
|
||||||
void Credits::resetVolume()
|
void Credits::resetVolume()
|
||||||
{
|
{
|
||||||
options.audio.music.volume = initial_volume_;
|
options.audio.music.volume = initial_volume_;
|
||||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
Audio::get()->setMusicVolume(options.audio.music.volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color del fondo
|
// Cambia el color del fondo
|
||||||
|
|||||||
@@ -18,13 +18,13 @@
|
|||||||
#include <string> // Para operator+, allocator, char_traits
|
#include <string> // Para operator+, allocator, char_traits
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
|
#include "audio.h" // Para Audio
|
||||||
#include "credits.h" // Para Credits
|
#include "credits.h" // Para Credits
|
||||||
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_MOD...
|
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_MOD...
|
||||||
#include "hiscore_table.h" // Para HiScoreTable
|
#include "hiscore_table.h" // Para HiScoreTable
|
||||||
#include "input.h" // Para Input, InputAction
|
#include "input.h" // Para Input, InputAction
|
||||||
#include "instructions.h" // Para Instructions
|
#include "instructions.h" // Para Instructions
|
||||||
#include "intro.h" // Para Intro
|
#include "intro.h" // Para Intro
|
||||||
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume
|
|
||||||
#include "lang.h" // Para Code, loadFromFile
|
#include "lang.h" // Para Code, loadFromFile
|
||||||
#include "logo.h" // Para Logo
|
#include "logo.h" // Para Logo
|
||||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
||||||
@@ -93,7 +93,7 @@ void Director::init()
|
|||||||
// Inicializa y crea el resto de objetos
|
// Inicializa y crea el resto de objetos
|
||||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||||
Screen::init();
|
Screen::init();
|
||||||
initJailAudio();
|
Audio::init();
|
||||||
Resource::init();
|
Resource::init();
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||||
bindInputs();
|
bindInputs();
|
||||||
@@ -110,14 +110,13 @@ void Director::close()
|
|||||||
{
|
{
|
||||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||||
|
|
||||||
Asset::destroy();
|
|
||||||
Resource::destroy();
|
|
||||||
Input::destroy();
|
|
||||||
Screen::destroy();
|
|
||||||
Notifier::destroy();
|
|
||||||
OnScreenHelp::destroy();
|
OnScreenHelp::destroy();
|
||||||
|
Notifier::destroy();
|
||||||
JA_Quit();
|
Input::destroy();
|
||||||
|
Resource::destroy();
|
||||||
|
Audio::destroy();
|
||||||
|
Screen::destroy();
|
||||||
|
Asset::destroy();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
@@ -257,34 +256,6 @@ void Director::bindInputs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa JailAudio
|
|
||||||
void Director::initJailAudio()
|
|
||||||
{
|
|
||||||
// Inicializa SDL
|
|
||||||
if (!SDL_Init(SDL_INIT_AUDIO))
|
|
||||||
{
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_AUDIO: INITIALIZING\n");
|
|
||||||
|
|
||||||
JA_Init(48000, SDL_AUDIO_S16LE, 2);
|
|
||||||
if (options.audio.enabled)
|
|
||||||
{
|
|
||||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
|
||||||
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JA_SetMusicVolume(0);
|
|
||||||
JA_SetSoundVolume(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
void Director::setFileList()
|
void Director::setFileList()
|
||||||
{
|
{
|
||||||
@@ -632,8 +603,8 @@ void Director::runDemoGame()
|
|||||||
// Ejecuta la sección init
|
// Ejecuta la sección init
|
||||||
void Director::runInit()
|
void Director::runInit()
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
JA_StopChannel(-1);
|
Audio::get()->stopAllSounds();
|
||||||
if (section::options == section::Options::RELOAD || true)
|
if (section::options == section::Options::RELOAD || true)
|
||||||
{
|
{
|
||||||
Resource::get()->reload();
|
Resource::get()->reload();
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ private:
|
|||||||
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
|
||||||
|
|
||||||
// Inicializa jail_audio
|
|
||||||
void initJailAudio();
|
|
||||||
|
|
||||||
// Asigna los botones y teclas al objeto Input
|
// Asigna los botones y teclas al objeto Input
|
||||||
void bindInputs();
|
void bindInputs();
|
||||||
|
|
||||||
|
|||||||
126
source/game.cpp
126
source/game.cpp
@@ -18,8 +18,7 @@
|
|||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "input.h" // Para InputAction, Input, INPUT_DO_NOT_A...
|
#include "input.h" // Para InputAction, Input, INPUT_DO_NOT_A...
|
||||||
#include "item.h" // Para Item, ItemType
|
#include "item.h" // Para Item, ItemType
|
||||||
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
|
#include "audio.h" // Para Audio::icStateplaynclude "lang.h" // Para getText
|
||||||
#include "lang.h" // Para getText
|
|
||||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
@@ -34,11 +33,13 @@
|
|||||||
#include "tabe.h" // Para Tabe, TabeState
|
#include "tabe.h" // Para Tabe, TabeState
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
|
#include "lang.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int player_id, int current_stage, bool demo)
|
Game::Game(int player_id, int current_stage, bool demo)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
screen_(Screen::get()),
|
screen_(Screen::get()),
|
||||||
|
audio_(Audio::get()),
|
||||||
asset_(Asset::get()),
|
asset_(Asset::get()),
|
||||||
input_(Input::get()),
|
input_(Input::get()),
|
||||||
background_(std::make_unique<Background>()),
|
background_(std::make_unique<Background>()),
|
||||||
@@ -99,19 +100,18 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
// MODO DEMO
|
// [Modo DEMO] Vuelve a activar los sonidos
|
||||||
if (demo_.enabled)
|
if (demo_.enabled)
|
||||||
{
|
{
|
||||||
// Habilita los sonidos
|
audio_->enableSound();
|
||||||
JA_EnableSound(true);
|
|
||||||
}
|
}
|
||||||
// MODO JUEGO
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Guarda las puntuaciones en un fichero
|
// [Modo JUEGO] Guarda puntuaciones y transita a modo título
|
||||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||||
manager->saveToFile(asset_->get("score.bin"));
|
manager->saveToFile(asset_->get("score.bin"));
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
audio_->stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
@@ -203,7 +203,7 @@ void Game::updateHiScore()
|
|||||||
if (hi_score_achieved_ == false)
|
if (hi_score_achieved_ == false)
|
||||||
{
|
{
|
||||||
hi_score_achieved_ = true;
|
hi_score_achieved_ = true;
|
||||||
JA_PlaySound(Resource::get()->getSound("hi_score_achieved.wav"));
|
audio_->playSound("hi_score_achieved.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ void Game::updateStage()
|
|||||||
// Cambio de fase
|
// Cambio de fase
|
||||||
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
|
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
|
||||||
++Stage::number;
|
++Stage::number;
|
||||||
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
|
audio_->playSound("stage_change.wav");
|
||||||
balloon_manager_->resetBalloonSpeed();
|
balloon_manager_->resetBalloonSpeed();
|
||||||
screen_->flash(FLASH_COLOR, 3);
|
screen_->flash(FLASH_COLOR, 3);
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
@@ -313,7 +313,7 @@ void Game::updateGameStateGameOver()
|
|||||||
if (game_over_counter_ == GAME_OVER_COUNTER_)
|
if (game_over_counter_ == GAME_OVER_COUNTER_)
|
||||||
{
|
{
|
||||||
createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_text_game_over"));
|
createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_text_game_over"));
|
||||||
JA_FadeOutMusic(1000);
|
audio_->fadeOutMusic(1000);
|
||||||
balloon_manager_->setSounds(true);
|
balloon_manager_->setSounds(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,8 +329,8 @@ void Game::updateGameStateGameOver()
|
|||||||
{
|
{
|
||||||
if (options.audio.enabled)
|
if (options.audio.enabled)
|
||||||
{
|
{
|
||||||
const float vol = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
|
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
|
||||||
JA_SetSoundVolume(to_JA_volume(static_cast<int>(vol)));
|
audio_->setSoundVolume(static_cast<int>(VOL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,8 +349,8 @@ void Game::updateGameStateGameOver()
|
|||||||
section::options = section::Options::HI_SCORE_AFTER_PLAYING;
|
section::options = section::Options::HI_SCORE_AFTER_PLAYING;
|
||||||
if (options.audio.enabled)
|
if (options.audio.enabled)
|
||||||
{
|
{
|
||||||
JA_StopChannel(-1);
|
audio_->stopAllSounds();
|
||||||
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
|
audio_->setSoundVolume(options.audio.sound.volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,7 +483,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
player->addScore(1000);
|
player->addScore(1000);
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(0));
|
createItemText(x, game_text_textures_.at(0));
|
||||||
JA_PlaySound(Resource::get()->getSound("item_pickup.wav"));
|
audio_->playSound("item_pickup.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::GAVINA:
|
case ItemType::GAVINA:
|
||||||
@@ -491,7 +491,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
player->addScore(2500);
|
player->addScore(2500);
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(1));
|
createItemText(x, game_text_textures_.at(1));
|
||||||
JA_PlaySound(Resource::get()->getSound("item_pickup.wav"));
|
audio_->playSound("item_pickup.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::PACMAR:
|
case ItemType::PACMAR:
|
||||||
@@ -499,7 +499,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
player->addScore(5000);
|
player->addScore(5000);
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(2));
|
createItemText(x, game_text_textures_.at(2));
|
||||||
JA_PlaySound(Resource::get()->getSound("item_pickup.wav"));
|
audio_->playSound("item_pickup.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::DEBIAN:
|
case ItemType::DEBIAN:
|
||||||
@@ -507,7 +507,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
player->addScore(100000);
|
player->addScore(100000);
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(6));
|
createItemText(x, game_text_textures_.at(6));
|
||||||
JA_PlaySound(Resource::get()->getSound("debian_pickup.wav"));
|
audio_->playSound("debian_pickup.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::CLOCK:
|
case ItemType::CLOCK:
|
||||||
@@ -515,7 +515,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
enableTimeStopItem();
|
enableTimeStopItem();
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(5)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(5)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(5));
|
createItemText(x, game_text_textures_.at(5));
|
||||||
JA_PlaySound(Resource::get()->getSound("item_pickup.wav"));
|
audio_->playSound("item_pickup.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::COFFEE:
|
case ItemType::COFFEE:
|
||||||
@@ -532,7 +532,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(4)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(4)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(4));
|
createItemText(x, game_text_textures_.at(4));
|
||||||
}
|
}
|
||||||
JA_PlaySound(Resource::get()->getSound("voice_coffee.wav"));
|
audio_->playSound("voice_coffee.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemType::COFFEE_MACHINE:
|
case ItemType::COFFEE_MACHINE:
|
||||||
@@ -541,7 +541,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player)
|
|||||||
coffee_machine_enabled_ = false;
|
coffee_machine_enabled_ = false;
|
||||||
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(3)->getWidth()) / 2;
|
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(3)->getWidth()) / 2;
|
||||||
createItemText(x, game_text_textures_.at(3));
|
createItemText(x, game_text_textures_.at(3));
|
||||||
JA_PlaySound(Resource::get()->getSound("voice_power_up.wav"));
|
audio_->playSound("voice_power_up.wav");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -570,20 +570,15 @@ void Game::checkBulletCollision()
|
|||||||
if (tabe_->tryToGetBonus())
|
if (tabe_->tryToGetBonus())
|
||||||
{
|
{
|
||||||
createItem(ItemType::DEBIAN, pos.x, pos.y);
|
createItem(ItemType::DEBIAN, pos.x, pos.y);
|
||||||
JA_PlaySound(Resource::get()->getSound("debian_drop.wav"));
|
audio_->playSound("debian_drop.wav");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (rand() % 3 == 0)
|
if (rand() % 3 == 0)
|
||||||
{
|
{
|
||||||
createItem(ItemType::COFFEE, pos.x, pos.y);
|
createItem(ItemType::COFFEE, pos.x, pos.y);
|
||||||
// JA_PlaySound(Resource::get()->getSound("item_drop.wav"));
|
|
||||||
}
|
}
|
||||||
else
|
audio_->playSound("tabe_hit.wav");
|
||||||
{
|
|
||||||
// JA_PlaySound(Resource::get()->getSound("tabe_hit.wav"));
|
|
||||||
}
|
|
||||||
JA_PlaySound(Resource::get()->getSound("tabe_hit.wav"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -605,7 +600,7 @@ void Game::checkBulletCollision()
|
|||||||
if (dropped_item != ItemType::COFFEE_MACHINE)
|
if (dropped_item != ItemType::COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
createItem(dropped_item, balloon->getPosX(), balloon->getPosY());
|
createItem(dropped_item, balloon->getPosX(), balloon->getPosY());
|
||||||
JA_PlaySound(Resource::get()->getSound("item_drop.wav"));
|
audio_->playSound("item_drop.wav");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -627,7 +622,7 @@ void Game::checkBulletCollision()
|
|||||||
updateHiScore();
|
updateHiScore();
|
||||||
|
|
||||||
// Sonido de explosión
|
// Sonido de explosión
|
||||||
JA_PlaySound(Resource::get()->getSound("balloon.wav"));
|
audio_->playSound("balloon.wav");
|
||||||
|
|
||||||
// Deshabilita la bala
|
// Deshabilita la bala
|
||||||
bullet->disable();
|
bullet->disable();
|
||||||
@@ -683,7 +678,7 @@ void Game::updateItems()
|
|||||||
item->update();
|
item->update();
|
||||||
if (item->isOnFloor())
|
if (item->isOnFloor())
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
audio_->playSound("title.wav");
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -910,16 +905,16 @@ 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(Resource::get()->getSound("coffee_out.wav"));
|
audio_->playSound("coffee_out.wav");
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Si no tiene cafes, muere
|
// Si no tiene cafes, muere
|
||||||
balloon_manager_->stopAllBalloons();
|
balloon_manager_->stopAllBalloons();
|
||||||
JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
|
audio_->playSound("player_collision.wav");
|
||||||
screen_->shake();
|
screen_->shake();
|
||||||
JA_PlaySound(Resource::get()->getSound("voice_no.wav"));
|
audio_->playSound("voice_no.wav");
|
||||||
player->setPlayingState(PlayerState::DYING);
|
player->setPlayingState(PlayerState::DYING);
|
||||||
if (allPlayersAreNotPlaying())
|
if (allPlayersAreNotPlaying())
|
||||||
{
|
{
|
||||||
@@ -939,7 +934,7 @@ void Game::updateTimeStopped()
|
|||||||
{
|
{
|
||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
audio_->playSound("clock.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -947,12 +942,12 @@ void Game::updateTimeStopped()
|
|||||||
if (time_stopped_counter_ % 30 == 0)
|
if (time_stopped_counter_ % 30 == 0)
|
||||||
{
|
{
|
||||||
balloon_manager_->normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
audio_->playSound("clock.wav");
|
||||||
}
|
}
|
||||||
else if (time_stopped_counter_ % 30 == 15)
|
else if (time_stopped_counter_ % 30 == 15)
|
||||||
{
|
{
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
JA_PlaySound(Resource::get()->getSound("clock.wav"));
|
audio_->playSound("clock.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1106,9 +1101,6 @@ void Game::run()
|
|||||||
checkEvents(); // Tiene que ir antes del render
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a dejar el sonido como estaba
|
|
||||||
(demo_.enabled) ? JA_EnableSound(options.audio.sound.enabled) : JA_StopMusic();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||||
@@ -1438,7 +1430,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
player->setInput(bulletType == BulletType::UP ? InputAction::FIRE_CENTER : bulletType == BulletType::LEFT ? InputAction::FIRE_LEFT
|
player->setInput(bulletType == BulletType::UP ? InputAction::FIRE_CENTER : bulletType == BulletType::LEFT ? InputAction::FIRE_LEFT
|
||||||
: InputAction::FIRE_RIGHT);
|
: InputAction::FIRE_RIGHT);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId());
|
||||||
JA_PlaySound(Resource::get()->getSound("bullet.wav"));
|
audio_->playSound("bullet.wav");
|
||||||
|
|
||||||
// Establece un tiempo de espera para el próximo disparo.
|
// Establece un tiempo de espera para el próximo disparo.
|
||||||
const int cooldown = player->isPowerUp() ? 5 : options.game.autofire ? 10
|
const int cooldown = player->isPowerUp() ? 5 : options.game.autofire ? 10
|
||||||
@@ -1602,18 +1594,18 @@ void Game::initDemo(int player_id)
|
|||||||
|
|
||||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||||
{
|
{
|
||||||
const auto demo1 = rand() % 2;
|
const auto DEMO1 = rand() % 2;
|
||||||
const auto demo2 = (demo1 == 0) ? 1 : 0;
|
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo1));
|
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(demo2));
|
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selecciona una pantalla al azar
|
// Selecciona una pantalla al azar
|
||||||
{
|
{
|
||||||
constexpr auto demos = 3;
|
constexpr auto NUM_DEMOS = 3;
|
||||||
const auto demo = rand() % demos;
|
const auto DEMO = rand() % NUM_DEMOS;
|
||||||
const int stages[demos] = {0, 3, 5};
|
const int STAGES[NUM_DEMOS] = {0, 3, 5};
|
||||||
Stage::number = stages[demo];
|
Stage::number = STAGES[DEMO];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el numero de globos explotados según la fase del modo demostración
|
// Actualiza el numero de globos explotados según la fase del modo demostración
|
||||||
@@ -1625,8 +1617,8 @@ void Game::initDemo(int player_id)
|
|||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
if (rand() % 3 != 0)
|
if (rand() % 3 != 0)
|
||||||
{
|
{
|
||||||
const auto other_player_id = player_id == 1 ? 2 : 1;
|
const auto OTHER_PLAYER_ID = player_id == 1 ? 2 : 1;
|
||||||
auto other_player = getPlayer(other_player_id);
|
auto other_player = getPlayer(OTHER_PLAYER_ID);
|
||||||
other_player->setPlayingState(PlayerState::PLAYING);
|
other_player->setPlayingState(PlayerState::PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1640,7 +1632,7 @@ void Game::initDemo(int player_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita los sonidos
|
// Deshabilita los sonidos
|
||||||
JA_EnableSound(false);
|
audio_->disableSound();
|
||||||
|
|
||||||
// Configura los marcadores
|
// Configura los marcadores
|
||||||
scoreboard_->setMode(SCOREBOARD_LEFT_PANEL, ScoreboardMode::DEMO);
|
scoreboard_->setMode(SCOREBOARD_LEFT_PANEL, ScoreboardMode::DEMO);
|
||||||
@@ -1739,32 +1731,10 @@ void Game::initPlayers(int player_id)
|
|||||||
player->setInvulnerable(false);
|
player->setInvulnerable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pausa la música
|
|
||||||
void Game::pauseMusic()
|
|
||||||
{
|
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING && !demo_.enabled)
|
|
||||||
{
|
|
||||||
JA_PauseMusic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reanuda la música
|
|
||||||
void Game::resumeMusic()
|
|
||||||
{
|
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PAUSED && !demo_.enabled)
|
|
||||||
{
|
|
||||||
JA_ResumeMusic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hace sonar la música
|
// Hace sonar la música
|
||||||
void Game::playMusic()
|
void Game::playMusic()
|
||||||
{
|
{
|
||||||
// Si la música no está sonando
|
audio_->playMusic("playing.ogg");
|
||||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
|
||||||
{
|
|
||||||
JA_PlayMusic(Resource::get()->getMusic("playing.ogg"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detiene la música
|
// Detiene la música
|
||||||
@@ -1772,7 +1742,7 @@ void Game::stopMusic()
|
|||||||
{
|
{
|
||||||
if (!demo_.enabled)
|
if (!demo_.enabled)
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
audio_->stopMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1856,7 +1826,7 @@ void Game::updateGameStateEnteringPlayer()
|
|||||||
{
|
{
|
||||||
setState(GameState::SHOWING_GET_READY_MESSAGE);
|
setState(GameState::SHOWING_GET_READY_MESSAGE);
|
||||||
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
||||||
JA_PlaySound(Resource::get()->getSound("voice_get_ready.wav"));
|
audio_->playSound("voice_get_ready.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1909,7 +1879,7 @@ void Game::updateGameStatePlaying()
|
|||||||
checkAndUpdateBalloonSpeed();
|
checkAndUpdateBalloonSpeed();
|
||||||
checkState();
|
checkState();
|
||||||
cleanVectors();
|
cleanVectors();
|
||||||
playMusic();
|
//playMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacía los vectores de elementos deshabilitados
|
// Vacía los vectores de elementos deshabilitados
|
||||||
|
|||||||
@@ -10,22 +10,23 @@
|
|||||||
#include "options.h" // Para GameOptions, Options, options
|
#include "options.h" // Para GameOptions, Options, options
|
||||||
#include "player.h" // Para Player
|
#include "player.h" // Para Player
|
||||||
#include "utils.h" // Para Demo
|
#include "utils.h" // Para Demo
|
||||||
class Asset; // lines 14-14
|
class Audio;
|
||||||
class Background; // lines 15-15
|
class Asset; // lines 14-14
|
||||||
class BalloonManager; // lines 16-16
|
class Background; // lines 15-15
|
||||||
class Bullet; // lines 18-18
|
class BalloonManager; // lines 16-16
|
||||||
class Fade; // lines 19-19
|
class Bullet; // lines 18-18
|
||||||
class Input; // lines 20-20
|
class Fade; // lines 19-19
|
||||||
class Item; // lines 21-21
|
class Input; // lines 20-20
|
||||||
class PathSprite; // lines 22-22
|
class Item; // lines 21-21
|
||||||
class Scoreboard; // lines 23-23
|
class PathSprite; // lines 22-22
|
||||||
class Screen; // lines 24-24
|
class Scoreboard; // lines 23-23
|
||||||
class SmartSprite; // lines 25-25
|
class Screen; // lines 24-24
|
||||||
class Tabe; // lines 17-17
|
class SmartSprite; // lines 25-25
|
||||||
class Texture; // lines 26-26
|
class Tabe; // lines 17-17
|
||||||
enum class BulletType : Uint8; // lines 27-27
|
class Texture; // lines 26-26
|
||||||
enum class ItemType; // lines 28-28
|
enum class BulletType : Uint8; // lines 27-27
|
||||||
struct Path; // lines 29-29
|
enum class ItemType; // lines 28-28
|
||||||
|
struct Path; // lines 29-29
|
||||||
|
|
||||||
// Modo demo
|
// Modo demo
|
||||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||||
@@ -122,6 +123,7 @@ private:
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
|
Audio *audio_; // Objeto encargado de gestionar el audio
|
||||||
Asset *asset_; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset_; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Input *input_; // Manejador de entrada
|
Input *input_; // Manejador de entrada
|
||||||
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
||||||
@@ -371,12 +373,6 @@ private:
|
|||||||
// Inicializa los jugadores
|
// Inicializa los jugadores
|
||||||
void initPlayers(int player_id);
|
void initPlayers(int player_id);
|
||||||
|
|
||||||
// Pausa la música
|
|
||||||
void pauseMusic();
|
|
||||||
|
|
||||||
// Reanuda la música
|
|
||||||
void resumeMusic();
|
|
||||||
|
|
||||||
// Hace sonar la música
|
// Hace sonar la música
|
||||||
void playMusic();
|
void playMusic();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
|
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
|
||||||
#include <algorithm> // Para max
|
#include <algorithm> // Para max
|
||||||
#include "animated_sprite.h" // Para AnimatedSprite
|
#include "animated_sprite.h" // Para AnimatedSprite
|
||||||
#include "jail_audio.h" // Para JA_PlaySound
|
#include "audio.h" // Para JA_PlaySound
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
@@ -123,7 +123,7 @@ void GameLogo::update()
|
|||||||
coffee_crisis_status_ = Status::SHAKING;
|
coffee_crisis_status_ = Status::SHAKING;
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
Audio::get()->playSound("title.wav");
|
||||||
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
||||||
Screen::get()->shake();
|
Screen::get()->shake();
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ void GameLogo::update()
|
|||||||
zoom_ = 1.0f;
|
zoom_ = 1.0f;
|
||||||
arcade_edition_sprite_->setZoom(zoom_);
|
arcade_edition_sprite_->setZoom(zoom_);
|
||||||
shake_.init(1, 2, 8, arcade_edition_sprite_->getX());
|
shake_.init(1, 2, 8, arcade_edition_sprite_->getX());
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
Audio::get()->playSound("title.wav");
|
||||||
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
||||||
Screen::get()->shake();
|
Screen::get()->shake();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
#include "input.h" // Para Input, InputAction, InputDeviceToUse
|
#include "input.h" // Para Input, InputAction, InputDeviceToUse
|
||||||
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume
|
#include "audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume
|
||||||
#include "lang.h" // Para getText, Code, getNextLangCode, loadFro...
|
#include "lang.h" // Para getText, Code, getNextLangCode, loadFro...
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
@@ -61,16 +61,7 @@ namespace globalInputs
|
|||||||
void toggleAudio()
|
void toggleAudio()
|
||||||
{
|
{
|
||||||
options.audio.enabled = !options.audio.enabled;
|
options.audio.enabled = !options.audio.enabled;
|
||||||
if (options.audio.enabled)
|
Audio::get()->enable(options.audio.enabled);
|
||||||
{
|
|
||||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
|
||||||
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JA_SetMusicVolume(0);
|
|
||||||
JA_SetSoundVolume(0);
|
|
||||||
}
|
|
||||||
Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)});
|
Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +152,7 @@ namespace globalInputs
|
|||||||
switch (section::name)
|
switch (section::name)
|
||||||
{
|
{
|
||||||
case section::Name::INTRO:
|
case section::Name::INTRO:
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
/* Continua en el case de abajo */
|
/* Continua en el case de abajo */
|
||||||
case section::Name::LOGO:
|
case section::Name::LOGO:
|
||||||
case section::Name::HI_SCORE_TABLE:
|
case section::Name::HI_SCORE_TABLE:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "fade.h" // Para Fade, FadeMode, FadeType
|
#include "fade.h" // Para Fade, FadeMode, FadeType
|
||||||
#include "global_events.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
|
#include "audio.h" // Para JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
#include "options.h" // Para GameOptions, Options, options
|
#include "options.h" // Para GameOptions, Options, options
|
||||||
@@ -62,9 +62,6 @@ void HiScoreTable::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Mantiene la música sonando
|
|
||||||
updateMusic();
|
|
||||||
|
|
||||||
// Actualiza las posiciones de los sprites de texto
|
// Actualiza las posiciones de los sprites de texto
|
||||||
updateSprites();
|
updateSprites();
|
||||||
|
|
||||||
@@ -154,6 +151,7 @@ void HiScoreTable::checkInput()
|
|||||||
// Bucle para la pantalla de instrucciones
|
// Bucle para la pantalla de instrucciones
|
||||||
void HiScoreTable::run()
|
void HiScoreTable::run()
|
||||||
{
|
{
|
||||||
|
Audio::get()->playMusic("title.ogg");
|
||||||
while (section::name == section::Name::HI_SCORE_TABLE)
|
while (section::name == section::Name::HI_SCORE_TABLE)
|
||||||
{
|
{
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -417,19 +415,10 @@ void HiScoreTable::glowEntryNames()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona la musica
|
|
||||||
void HiScoreTable::updateMusic()
|
|
||||||
{
|
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
{
|
|
||||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona el contador
|
// Gestiona el contador
|
||||||
void HiScoreTable::updateCounter()
|
void HiScoreTable::updateCounter()
|
||||||
{
|
{
|
||||||
counter_++;
|
++counter_;
|
||||||
|
|
||||||
if (counter_ == 150)
|
if (counter_ == 150)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,9 +91,6 @@ private:
|
|||||||
// Hace brillar los nombres de la tabla de records
|
// Hace brillar los nombres de la tabla de records
|
||||||
void glowEntryNames();
|
void glowEntryNames();
|
||||||
|
|
||||||
// Gestiona la musica
|
|
||||||
void updateMusic();
|
|
||||||
|
|
||||||
// Gestiona el contador
|
// Gestiona el contador
|
||||||
void updateCounter();
|
void updateCounter();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "fade.h" // Para Fade, FadeMode, FadeType
|
#include "fade.h" // Para Fade, FadeMode, FadeType
|
||||||
#include "global_events.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
|
#include "audio.h" // Para JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
@@ -206,9 +206,6 @@ void Instructions::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Mantiene la música sonando
|
|
||||||
updateMusic();
|
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
@@ -278,6 +275,7 @@ void Instructions::checkInput()
|
|||||||
// Bucle para la pantalla de instrucciones
|
// Bucle para la pantalla de instrucciones
|
||||||
void Instructions::run()
|
void Instructions::run()
|
||||||
{
|
{
|
||||||
|
Audio::get()->playMusic("title.ogg");
|
||||||
while (section::name == section::Name::INSTRUCTIONS)
|
while (section::name == section::Name::INSTRUCTIONS)
|
||||||
{
|
{
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -344,15 +342,6 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona la musica
|
|
||||||
void Instructions::updateMusic()
|
|
||||||
{
|
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
{
|
|
||||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona la textura con los graficos
|
// Gestiona la textura con los graficos
|
||||||
void Instructions::updateBackbuffer()
|
void Instructions::updateBackbuffer()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -96,9 +96,6 @@ private:
|
|||||||
// Método para renderizar las líneas
|
// Método para renderizar las líneas
|
||||||
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines);
|
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines);
|
||||||
|
|
||||||
// Gestiona la musica
|
|
||||||
void updateMusic();
|
|
||||||
|
|
||||||
// Gestiona la textura con los graficos
|
// Gestiona la textura con los graficos
|
||||||
void updateBackbuffer();
|
void updateBackbuffer();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
#include "global_events.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "jail_audio.h" // Para JA_PlayMusic, JA_StopMusic
|
#include "audio.h" // Para JA_PlayMusic, JA_StopMusic
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "path_sprite.h" // Para PathSprite, PathType
|
#include "path_sprite.h" // Para PathSprite, PathType
|
||||||
@@ -284,7 +284,7 @@ void Intro::render()
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void Intro::run()
|
void Intro::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
Audio::get()->playMusic("intro.ogg", 0);
|
||||||
while (section::name == section::Name::INTRO)
|
while (section::name == section::Name::INTRO)
|
||||||
{
|
{
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -516,7 +516,7 @@ void Intro::updatePostState()
|
|||||||
// Finaliza la intro después de 1 segundo
|
// Finaliza la intro después de 1 segundo
|
||||||
if (ELAPSED_TIME >= 1000)
|
if (ELAPSED_TIME >= 1000)
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
section::name = section::Name::TITLE;
|
section::name = section::Name::TITLE;
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,6 @@ void JA_PlayMusic(JA_Music_t *music, const int loop)
|
|||||||
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
|
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
|
||||||
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream))
|
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream))
|
||||||
printf("[ERROR] SDL_BindAudioStream failed!\n");
|
printf("[ERROR] SDL_BindAudioStream failed!\n");
|
||||||
// SDL_ResumeAudioStreamDevice(current_music->stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_PauseMusic()
|
void JA_PauseMusic()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
#include "global_events.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "jail_audio.h" // Para JA_FadeOutMusic, JA_PlaySound, JA_StopC...
|
#include "audio.h" // Para JA_FadeOutMusic, JA_PlaySound, JA_StopC...
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
@@ -60,7 +60,7 @@ Logo::~Logo()
|
|||||||
{
|
{
|
||||||
jail_texture_->setColor(255, 255, 255);
|
jail_texture_->setColor(255, 255, 255);
|
||||||
since_texture_->setColor(255, 255, 255);
|
since_texture_->setColor(255, 255, 255);
|
||||||
JA_StopChannel(-1);
|
Audio::get()->stopAllSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
@@ -84,7 +84,7 @@ void Logo::updateJAILGAMES()
|
|||||||
{
|
{
|
||||||
if (counter_ == 30)
|
if (counter_ == 30)
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("logo.wav"));
|
Audio::get()->playSound("logo.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter_ > 30)
|
if (counter_ > 30)
|
||||||
@@ -184,9 +184,7 @@ void Logo::render()
|
|||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
void Logo::run()
|
void Logo::run()
|
||||||
{
|
{
|
||||||
// Detiene la música
|
Audio::get()->fadeOutMusic(300);
|
||||||
JA_FadeOutMusic(300);
|
|
||||||
|
|
||||||
while (section::name == section::Name::LOGO)
|
while (section::name == section::Name::LOGO)
|
||||||
{
|
{
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
#include "audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
#include "param.h" // Para Param, param, ParamNotification, Par...
|
#include "param.h" // Para Param, param, ParamNotification, Par...
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
@@ -76,7 +76,7 @@ void Notifier::update()
|
|||||||
if (notifications_[i].state == NotificationStatus::RISING)
|
if (notifications_[i].state == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
// Reproduce el sonido de la notificación
|
// Reproduce el sonido de la notificación
|
||||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
Audio::get()->playSound("notify.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ enum class OnScreenHelpStatus
|
|||||||
class OnScreenHelp
|
class OnScreenHelp
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// [SINGLETON] Objeto screen privado
|
||||||
static OnScreenHelp *onScreenHelp;
|
static OnScreenHelp *onScreenHelp;
|
||||||
|
|
||||||
SDL_Texture *texture; // Textura donde dibujar
|
SDL_Texture *texture; // Textura donde dibujar
|
||||||
|
|||||||
@@ -325,13 +325,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
|
||||||
int to_JA_volume(int vol)
|
|
||||||
{
|
|
||||||
vol = vol * 1.28f;
|
|
||||||
return std::clamp(vol, 0, 128);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna el teclado al jugador
|
// Asigna el teclado al jugador
|
||||||
void setKeyboardToPlayer(int player_id)
|
void setKeyboardToPlayer(int player_id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ bool loadOptionsFile(std::string file_path);
|
|||||||
// Guarda el fichero de configuración
|
// Guarda el fichero de configuración
|
||||||
bool saveOptionsFile(std::string file_path);
|
bool saveOptionsFile(std::string file_path);
|
||||||
|
|
||||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
|
||||||
int to_JA_volume(int vol);
|
|
||||||
|
|
||||||
// Asigna el teclado al jugador
|
// Asigna el teclado al jugador
|
||||||
void setKeyboardToPlayer(int player_id);
|
void setKeyboardToPlayer(int player_id);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <array> // Para array
|
#include <array> // Para array
|
||||||
#include "animated_sprite.h" // Para AnimatedSprite
|
#include "animated_sprite.h" // Para AnimatedSprite
|
||||||
#include "input.h" // Para InputAction
|
#include "input.h" // Para InputAction
|
||||||
#include "jail_audio.h" // Para JA_PlaySound
|
#include "audio.h" // Para JA_PlaySound
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
||||||
@@ -221,7 +221,7 @@ void Player::move()
|
|||||||
++step_counter_;
|
++step_counter_;
|
||||||
if (step_counter_ % 10 == 0)
|
if (step_counter_ % 10 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("walk.wav"));
|
Audio::get()->playSound("walk.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (id_)
|
switch (id_)
|
||||||
@@ -252,7 +252,7 @@ void Player::move()
|
|||||||
++step_counter_;
|
++step_counter_;
|
||||||
if (step_counter_ % 10 == 0)
|
if (step_counter_ % 10 == 0)
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("walk.wav"));
|
Audio::get()->playSound("walk.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (id_)
|
switch (id_)
|
||||||
@@ -752,7 +752,7 @@ void Player::decContinueCounter()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("continue_clock.wav"));
|
Audio::get()->playSound("continue_clock.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -798,5 +798,5 @@ void Player::shiftSprite()
|
|||||||
void Player::playRandomBubbleSound()
|
void Player::playRandomBubbleSound()
|
||||||
{
|
{
|
||||||
const std::vector<std::string> sounds = {"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"};
|
const std::vector<std::string> sounds = {"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"};
|
||||||
JA_PlaySound(Resource::get()->getSound(sounds.at(rand() % sounds.size())));
|
Audio::get()->playSound(sounds.at(rand() % sounds.size()));
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <algorithm> // Para find_if
|
#include <algorithm> // Para find_if
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic
|
#include "jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "text.h" // Para Text, loadTextFile
|
#include "text.h" // Para Text, loadTextFile
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ struct ResourceAnimation
|
|||||||
class Resource
|
class Resource
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto resource privado para Don Melitón
|
// [SINGLETON] Objeto resource privado
|
||||||
static Resource *resource_;
|
static Resource *resource_;
|
||||||
|
|
||||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct Panel
|
|||||||
class Scoreboard
|
class Scoreboard
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
// [SINGLETON] Objeto scoreboard privado
|
||||||
static Scoreboard *scoreboard_;
|
static Scoreboard *scoreboard_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
|
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
|
||||||
#include <stdlib.h> // Para rand, abs
|
#include <stdlib.h> // Para rand, abs
|
||||||
#include <algorithm> // Para max
|
#include <algorithm> // Para max
|
||||||
#include "jail_audio.h" // Para JA_PlaySound
|
#include "audio.h" // Para JA_PlaySound
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "utils.h" // Para Zone
|
#include "utils.h" // Para Zone
|
||||||
@@ -131,7 +131,7 @@ void Tabe::setRandomFlyPath(TabeDirection direction, int lenght)
|
|||||||
direction_ = direction;
|
direction_ = direction;
|
||||||
fly_distance_ = lenght;
|
fly_distance_ = lenght;
|
||||||
waiting_counter_ = 5 + rand() % 15;
|
waiting_counter_ = 5 + rand() % 15;
|
||||||
JA_PlaySound(Resource::get()->getSound("tabe.wav"));
|
Audio::get()->playSound("tabe.wav");
|
||||||
|
|
||||||
constexpr float SPEED = 2.0f;
|
constexpr float SPEED = 2.0f;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "game_logo.h" // Para GameLogo
|
#include "game_logo.h" // Para GameLogo
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_R...
|
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_R...
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
|
#include "audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "global_events.h" // Para handleEvent
|
#include "global_events.h" // Para handleEvent
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
@@ -55,7 +55,7 @@ Title::Title()
|
|||||||
Title::~Title()
|
Title::~Title()
|
||||||
{
|
{
|
||||||
Resource::get()->getTexture("smb2.gif")->setPalette(0);
|
Resource::get()->getTexture("smb2.gif")->setPalette(0);
|
||||||
JA_StopChannel(-1);
|
Audio::get()->stopAllSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -203,8 +203,8 @@ void Title::checkInput()
|
|||||||
{
|
{
|
||||||
if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled())
|
if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled())
|
||||||
{
|
{
|
||||||
JA_PlaySound(Resource::get()->getSound("game_start.wav"));
|
Audio::get()->playSound("game_start.wav");
|
||||||
JA_FadeOutMusic(1500);
|
Audio::get()->fadeOutMusic(1500);
|
||||||
switch (CONTROLLER.player_id)
|
switch (CONTROLLER.player_id)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -325,7 +325,7 @@ void Title::updateFade()
|
|||||||
// Se ha pulsado para jugar
|
// Se ha pulsado para jugar
|
||||||
section::name = section::Name::GAME;
|
section::name = section::Name::GAME;
|
||||||
section::options = selection_;
|
section::options = selection_;
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,6 +342,7 @@ void Title::updateState()
|
|||||||
if (game_logo_->hasFinished())
|
if (game_logo_->hasFinished())
|
||||||
{
|
{
|
||||||
state_ = TitleState::LOGO_FINISHED;
|
state_ = TitleState::LOGO_FINISHED;
|
||||||
|
Audio::get()->playMusic("title.ogg");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -350,12 +351,6 @@ void Title::updateState()
|
|||||||
// El contador solo sube si no estamos definiendo botones
|
// El contador solo sube si no estamos definiendo botones
|
||||||
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
|
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
|
||||||
|
|
||||||
// Reproduce la música
|
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
{
|
|
||||||
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
|
||||||
game_logo_->update();
|
game_logo_->update();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user