Compare commits
6 Commits
8818954dcd
...
d1e4a5eb07
| Author | SHA1 | Date | |
|---|---|---|---|
| d1e4a5eb07 | |||
| e18d1b186a | |||
| d056a5e336 | |||
| b9e26aa755 | |||
| b2afef2226 | |||
| c400aa96c0 |
@@ -14,6 +14,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
cmake_policy(SET CMP0072 NEW)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
|
||||
# --- GENERACIÓN DE VERSIÓN AUTOMÁTICA ---
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
else()
|
||||
set(GIT_HASH "unknown")
|
||||
endif()
|
||||
|
||||
# Configurar archivo de versión
|
||||
configure_file(${CMAKE_SOURCE_DIR}/source/version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
|
||||
|
||||
# --- 1. LISTA EXPLÍCITA DE FUENTES ---
|
||||
set(APP_SOURCES
|
||||
@@ -92,17 +108,12 @@ set(APP_SOURCES
|
||||
|
||||
# Fuentes de librerías de terceros
|
||||
set(EXTERNAL_SOURCES
|
||||
source/external/jail_audio.cpp
|
||||
source/external/jail_shader.cpp
|
||||
source/external/json.hpp
|
||||
source/external/gif.cpp
|
||||
)
|
||||
|
||||
# Añadir jail_audio.cpp solo si el audio está habilitado
|
||||
if(NOT DISABLE_AUDIO)
|
||||
list(APPEND EXTERNAL_SOURCES source/external/jail_audio.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
# Configuración de SDL3
|
||||
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
|
||||
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}")
|
||||
@@ -128,16 +139,6 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
|
||||
# Definir _DEBUG en modo Debug
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
|
||||
|
||||
# Opción para habilitar/deshabilitar audio
|
||||
option(DISABLE_AUDIO "Disable audio system" OFF)
|
||||
|
||||
# Definir NO_AUDIO si la opción está activada
|
||||
if(DISABLE_AUDIO)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_AUDIO)
|
||||
message(STATUS "Audio deshabilitado - NO_AUDIO definido")
|
||||
else()
|
||||
message(STATUS "Audio habilitado")
|
||||
endif()
|
||||
|
||||
# Configuración específica para cada plataforma
|
||||
if(WIN32)
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
#include <algorithm> // Para clamp
|
||||
|
||||
#ifndef NO_AUDIO
|
||||
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
|
||||
#endif
|
||||
#include "options.h" // Para AudioOptions, audio, MusicOptions
|
||||
#include "resource.h" // Para Resource
|
||||
|
||||
@@ -27,9 +25,7 @@ Audio::Audio() { initSDLAudio(); }
|
||||
|
||||
// Destructor
|
||||
Audio::~Audio() {
|
||||
#ifndef NO_AUDIO
|
||||
JA_Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Método principal
|
||||
@@ -43,9 +39,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
|
||||
music_.loop = (loop != 0);
|
||||
|
||||
if (music_enabled_ && music_.state != MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PlayMusic(Resource::get()->getMusic(name), loop);
|
||||
#endif
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -53,9 +47,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
|
||||
// Pausa la música
|
||||
void Audio::pauseMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PauseMusic();
|
||||
#endif
|
||||
music_.state = MusicState::PAUSED;
|
||||
}
|
||||
}
|
||||
@@ -63,9 +55,7 @@ void Audio::pauseMusic() {
|
||||
// Continua la música pausada
|
||||
void Audio::resumeMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PAUSED) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_ResumeMusic();
|
||||
#endif
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -73,9 +63,7 @@ void Audio::resumeMusic() {
|
||||
// Detiene la música
|
||||
void Audio::stopMusic() {
|
||||
if (music_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_StopMusic();
|
||||
#endif
|
||||
music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -83,33 +71,26 @@ void Audio::stopMusic() {
|
||||
// Reproduce un sonido
|
||||
void Audio::playSound(const std::string &name, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Detiene todos los sonidos
|
||||
void Audio::stopAllSounds() const {
|
||||
if (sound_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_StopChannel(-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Realiza un fundido de salida de la música
|
||||
void Audio::fadeOutMusic(int milliseconds) const {
|
||||
if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_FadeOutMusic(milliseconds);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Consulta directamente el estado real de la música en jailaudio
|
||||
auto Audio::getRealMusicState() const -> MusicState {
|
||||
#ifndef NO_AUDIO
|
||||
JA_Music_state ja_state = JA_GetMusicState();
|
||||
switch (ja_state) {
|
||||
case JA_MUSIC_PLAYING:
|
||||
@@ -122,19 +103,14 @@ auto Audio::getRealMusicState() const -> MusicState {
|
||||
default:
|
||||
return MusicState::STOPPED;
|
||||
}
|
||||
#else
|
||||
return MusicState::STOPPED;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Establece el volumen de los sonidos
|
||||
void Audio::setSoundVolume(int sound_volume, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
#ifndef NO_AUDIO
|
||||
const float CONVERTED_VOLUME = (sound_volume / 100.0F) * (Options::audio.volume / 100.0F);
|
||||
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,10 +118,8 @@ void Audio::setSoundVolume(int sound_volume, Group group) const {
|
||||
void Audio::setMusicVolume(int music_volume) const {
|
||||
if (music_enabled_) {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
#ifndef NO_AUDIO
|
||||
const float CONVERTED_VOLUME = (music_volume / 100.0F) * (Options::audio.volume / 100.0F);
|
||||
JA_SetMusicVolume(CONVERTED_VOLUME);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +138,6 @@ void Audio::enable(bool value) {
|
||||
|
||||
// Inicializa SDL Audio
|
||||
void Audio::initSDLAudio() {
|
||||
#ifndef NO_AUDIO
|
||||
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
|
||||
} else {
|
||||
@@ -173,7 +146,4 @@ void Audio::initSDLAudio() {
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully");
|
||||
}
|
||||
#else
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system disabled");
|
||||
#endif
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "color.h"
|
||||
#include "ui/notifier.h" // Para Notifier::Position
|
||||
#include "version.h" // Para Version::APP_NAME
|
||||
|
||||
// --- Namespace GameDefaults: configuración centralizada con valores por defecto del juego ---
|
||||
namespace GameDefaults {
|
||||
@@ -211,7 +212,7 @@ constexpr const char* PLAYER1 = "422028FF";
|
||||
// --- OPTIONS ---
|
||||
namespace Options {
|
||||
// Window
|
||||
constexpr const char* WINDOW_CAPTION = "Coffee Crisis Arcade Edition";
|
||||
constexpr const char* WINDOW_CAPTION = Version::APP_NAME;
|
||||
constexpr int WINDOW_ZOOM = 2;
|
||||
constexpr int WINDOW_MAX_ZOOM = 2;
|
||||
|
||||
|
||||
@@ -350,16 +350,11 @@ class Player {
|
||||
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
|
||||
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
|
||||
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones)
|
||||
void startFiring(int cooldown_frames); // Inicia un nuevo disparo en ambas líneas
|
||||
void updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
|
||||
void transitionToRecoilingNew(); // Transición AIMING → RECOILING
|
||||
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
|
||||
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
|
||||
|
||||
// --- Sistema de disparo obsoleto (legacy) ---
|
||||
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar
|
||||
void handleRecoilAndCooling(float deltaTime); // Procesa retroceso y enfriamiento
|
||||
void handleCoolingState(float deltaTime); // Actualiza estado de enfriamiento
|
||||
// --- Manejadores de movimiento ---
|
||||
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento durante el juego
|
||||
void handleRecoverMovement(); // Comprueba si ha acabado la animación de recuperación
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
|
||||
#include "asset.h" // Para Asset
|
||||
#include "color.h" // Para Color
|
||||
#ifndef NO_AUDIO
|
||||
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
|
||||
#include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound
|
||||
#endif
|
||||
#include "lang.h" // Para getText
|
||||
#include "param.h" // Para Param, param, ParamResource, ParamGame
|
||||
#include "resource_helper.h" // Para ResourceHelper
|
||||
@@ -324,7 +323,6 @@ auto Resource::getDemoData(int index) -> DemoData & {
|
||||
|
||||
auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading sound lazily: %s", name.c_str());
|
||||
#ifndef NO_AUDIO
|
||||
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
|
||||
for (const auto &file : sound_list) {
|
||||
if (getFileName(file) == name) {
|
||||
@@ -332,13 +330,11 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
|
||||
return JA_LoadSound(audio_path.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading music lazily: %s", name.c_str());
|
||||
#ifndef NO_AUDIO
|
||||
auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
|
||||
for (const auto &file : music_list) {
|
||||
if (getFileName(file) == name) {
|
||||
@@ -346,7 +342,6 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
||||
return JA_LoadMusic(audio_path.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -425,10 +420,8 @@ auto Resource::loadAnimationLazy(const std::string &name) -> AnimationsFileBuffe
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear() {
|
||||
#ifndef NO_AUDIO
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
#endif
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
@@ -448,10 +441,8 @@ void Resource::load() {
|
||||
screen->setVSync(false);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
|
||||
#ifndef NO_AUDIO
|
||||
loadSounds(); // Carga sonidos
|
||||
loadMusics(); // Carga músicas
|
||||
#endif
|
||||
loadTextures(); // Carga texturas
|
||||
loadTextFiles(); // Carga ficheros de texto
|
||||
loadAnimations(); // Carga animaciones
|
||||
@@ -484,12 +475,8 @@ void Resource::loadSounds() {
|
||||
for (const auto &l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
#ifndef NO_AUDIO
|
||||
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
|
||||
sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str()));
|
||||
#else
|
||||
sounds_.emplace_back(name, nullptr);
|
||||
#endif
|
||||
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
@@ -503,12 +490,8 @@ void Resource::loadMusics() {
|
||||
for (const auto &l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
#ifndef NO_AUDIO
|
||||
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
|
||||
musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str()));
|
||||
#else
|
||||
musics_.emplace_back(name, nullptr);
|
||||
#endif
|
||||
printWithDots("Music : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
@@ -738,9 +721,7 @@ void Resource::createText() {
|
||||
void Resource::clearSounds() {
|
||||
for (auto &sound : sounds_) {
|
||||
if (sound.sound != nullptr) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_DeleteSound(sound.sound);
|
||||
#endif
|
||||
sound.sound = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -751,9 +732,7 @@ void Resource::clearSounds() {
|
||||
void Resource::clearMusics() {
|
||||
for (auto &music : musics_) {
|
||||
if (music.music != nullptr) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_DeleteMusic(music.music);
|
||||
#endif
|
||||
music.music = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -809,20 +788,27 @@ void Resource::renderProgress() {
|
||||
Lang::getText("[RESOURCE] LOADING") + " : " + loading_resource_name_,
|
||||
param.resource.color);
|
||||
|
||||
// Muestra información del monitor alineada con la barra de carga
|
||||
// Muestra nombre de la aplicación y versión
|
||||
loading_text_->writeColored(
|
||||
X_PADDING,
|
||||
Y_PADDING,
|
||||
std::string(Version::APP_NAME) + " (" + Version::GIT_HASH + ")",
|
||||
param.resource.color);
|
||||
|
||||
// Muestra información del monitor desplazada hacia abajo
|
||||
loading_text_->writeColored(
|
||||
X_PADDING,
|
||||
Y_PADDING + 18,
|
||||
screen->getDisplayMonitorName(),
|
||||
param.resource.color);
|
||||
loading_text_->writeColored(
|
||||
X_PADDING,
|
||||
Y_PADDING + 9,
|
||||
Y_PADDING + 27,
|
||||
std::to_string(screen->getDisplayMonitorWidth()) + "x" + std::to_string(screen->getDisplayMonitorHeight()),
|
||||
param.resource.color);
|
||||
loading_text_->writeColored(
|
||||
X_PADDING,
|
||||
Y_PADDING + 18,
|
||||
Y_PADDING + 36,
|
||||
std::to_string(screen->getDisplayMonitorRefreshRate()) + "Hz",
|
||||
param.resource.color);
|
||||
|
||||
|
||||
@@ -293,11 +293,10 @@ void Credits::fillCanvas() {
|
||||
// Actualiza el destino de los rectangulos de las texturas (time-based)
|
||||
void Credits::updateTextureDstRects(float deltaTime) {
|
||||
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
|
||||
static float texture_accumulator = 0.0f;
|
||||
texture_accumulator += deltaTime;
|
||||
credits_state_.texture_accumulator += deltaTime;
|
||||
|
||||
if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
|
||||
texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S;
|
||||
if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
|
||||
credits_state_.texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S;
|
||||
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
|
||||
@@ -336,20 +335,17 @@ void Credits::throwBalloons(float deltaTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
static float balloon_accumulator = 0.0f;
|
||||
static float powerball_accumulator = 0.0f;
|
||||
credits_state_.balloon_accumulator += deltaTime;
|
||||
credits_state_.powerball_accumulator += deltaTime;
|
||||
|
||||
balloon_accumulator += deltaTime;
|
||||
powerball_accumulator += deltaTime;
|
||||
|
||||
if (balloon_accumulator >= BALLOON_INTERVAL_S) {
|
||||
balloon_accumulator -= BALLOON_INTERVAL_S;
|
||||
if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
|
||||
credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
|
||||
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
|
||||
balloon_manager_->deployFormation(SETS.at(INDEX), -60);
|
||||
}
|
||||
|
||||
if (powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
|
||||
powerball_accumulator -= POWERBALL_INTERVAL_S;
|
||||
if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
|
||||
credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S;
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
}
|
||||
@@ -425,13 +421,11 @@ void Credits::initPlayers() {
|
||||
void Credits::updateBlackRects(float deltaTime) {
|
||||
static float current_step_ = static_cast<float>(steps_);
|
||||
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
|
||||
static float black_rect_accumulator = 0.0f;
|
||||
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
|
||||
// Si los rectangulos superior e inferior no han llegado al centro
|
||||
black_rect_accumulator += deltaTime;
|
||||
if (black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
|
||||
black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
|
||||
credits_state_.black_rect_accumulator += deltaTime;
|
||||
if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
|
||||
credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
|
||||
|
||||
// Incrementa la altura del rectangulo superior
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
|
||||
@@ -515,33 +509,33 @@ void Credits::cycleColors() {
|
||||
constexpr int UPPER_LIMIT = 140; // Límite superior
|
||||
constexpr int LOWER_LIMIT = 30; // Límite inferior
|
||||
|
||||
static auto r_ = static_cast<float>(UPPER_LIMIT);
|
||||
static auto g_ = static_cast<float>(LOWER_LIMIT);
|
||||
static auto b_ = static_cast<float>(LOWER_LIMIT);
|
||||
static float step_r_ = -0.5F; // Paso flotante para transiciones suaves
|
||||
static float step_g_ = 0.3F;
|
||||
static float step_b_ = 0.1F;
|
||||
// Inicializar valores RGB si es la primera vez
|
||||
if (credits_state_.r == 255.0f && credits_state_.g == 0.0f && credits_state_.b == 0.0f && credits_state_.step_r == -0.5f) {
|
||||
credits_state_.r = static_cast<float>(UPPER_LIMIT);
|
||||
credits_state_.g = static_cast<float>(LOWER_LIMIT);
|
||||
credits_state_.b = static_cast<float>(LOWER_LIMIT);
|
||||
}
|
||||
|
||||
// Ajustar valores de R
|
||||
r_ += step_r_;
|
||||
if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) {
|
||||
step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites
|
||||
credits_state_.r += credits_state_.step_r;
|
||||
if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) {
|
||||
credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Ajustar valores de G
|
||||
g_ += step_g_;
|
||||
if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) {
|
||||
step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites
|
||||
credits_state_.g += credits_state_.step_g;
|
||||
if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) {
|
||||
credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Ajustar valores de B
|
||||
b_ += step_b_;
|
||||
if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) {
|
||||
step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites
|
||||
credits_state_.b += credits_state_.step_b;
|
||||
if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) {
|
||||
credits_state_.step_b = -credits_state_.step_b; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Aplicar el color, redondeando a enteros antes de usar
|
||||
color_ = Color(static_cast<int>(r_), static_cast<int>(g_), static_cast<int>(b_));
|
||||
color_ = Color(static_cast<int>(credits_state_.r), static_cast<int>(credits_state_.g), static_cast<int>(credits_state_.b));
|
||||
tiled_bg_->setColor(color_);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,20 @@ class Credits {
|
||||
int initial_volume_ = Options::audio.music.volume; // Volumen inicial
|
||||
int steps_ = 0; // Pasos para reducir audio
|
||||
|
||||
// --- Estado de acumuladores para animaciones ---
|
||||
struct CreditsState {
|
||||
float texture_accumulator = 0.0f;
|
||||
float balloon_accumulator = 0.0f;
|
||||
float powerball_accumulator = 0.0f;
|
||||
float black_rect_accumulator = 0.0f;
|
||||
float r = 255.0f; // UPPER_LIMIT
|
||||
float g = 0.0f; // LOWER_LIMIT
|
||||
float b = 0.0f; // LOWER_LIMIT
|
||||
float step_r = -0.5f;
|
||||
float step_g = 0.3f;
|
||||
float step_b = 0.1f;
|
||||
} credits_state_;
|
||||
|
||||
// --- Rectángulos de renderizado ---
|
||||
// Texto de créditos
|
||||
SDL_FRect credits_rect_src_ = param.game.game_area.rect;
|
||||
|
||||
@@ -319,7 +319,7 @@ void Game::updateStage() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de fin de la partida
|
||||
// Actualiza las variables y sistemas durante el estado de fin de partida
|
||||
void Game::updateGameStateGameOver(float deltaTime) {
|
||||
fade_out_->update();
|
||||
updatePlayers(deltaTime);
|
||||
@@ -336,14 +336,8 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
||||
cleanVectors();
|
||||
|
||||
if (game_over_timer_ < GAME_OVER_DURATION_S) {
|
||||
handleGameOverEvents(); // Maneja eventos al inicio
|
||||
|
||||
game_over_timer_ += deltaTime; // Incremento time-based
|
||||
|
||||
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5f; // 2.5 segundos antes del final
|
||||
if (game_over_timer_ >= FADE_TRIGGER_S && !fade_out_->isEnabled()) {
|
||||
fade_out_->activate();
|
||||
}
|
||||
game_over_timer_ += deltaTime; // Incremento time-based primero
|
||||
handleGameOverEvents(); // Maneja eventos después del incremento
|
||||
}
|
||||
|
||||
if (Options::audio.enabled) {
|
||||
@@ -872,13 +866,11 @@ void Game::updateTimeStopped(float deltaTime) {
|
||||
// Fase de advertencia (últimos 2 segundos)
|
||||
if (time_stopped_timer_ <= WARNING_THRESHOLD_S) {
|
||||
static float last_sound_time = 0.0f;
|
||||
static bool color_flash_sound_played = false;
|
||||
static bool warning_phase_started = false;
|
||||
|
||||
// CLAC al entrar en fase de advertencia
|
||||
if (!warning_phase_started) {
|
||||
if (!time_stopped_flags_.warning_phase_started) {
|
||||
playSound("clock.wav");
|
||||
warning_phase_started = true;
|
||||
time_stopped_flags_.warning_phase_started = true;
|
||||
last_sound_time = 0.0f; // Reset para empezar el ciclo rápido
|
||||
}
|
||||
|
||||
@@ -888,11 +880,11 @@ void Game::updateTimeStopped(float deltaTime) {
|
||||
balloon_manager_->normalColorsToAllBalloons();
|
||||
playSound("clock.wav");
|
||||
last_sound_time = 0.0f;
|
||||
color_flash_sound_played = false; // Reset flag para el próximo intervalo
|
||||
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !color_flash_sound_played) {
|
||||
time_stopped_flags_.color_flash_sound_played = false; // Reset flag para el próximo intervalo
|
||||
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !time_stopped_flags_.color_flash_sound_played) {
|
||||
balloon_manager_->reverseColorsToAllBalloons();
|
||||
playSound("clock.wav");
|
||||
color_flash_sound_played = true; // Evita que suene múltiples veces
|
||||
time_stopped_flags_.color_flash_sound_played = true; // Evita que suene múltiples veces
|
||||
}
|
||||
} else {
|
||||
// Fase normal - solo sonido ocasional
|
||||
@@ -997,6 +989,7 @@ void Game::enableTimeStopItem() {
|
||||
balloon_manager_->stopAllBalloons();
|
||||
balloon_manager_->reverseColorsToAllBalloons();
|
||||
time_stopped_timer_ = TIME_STOPPED_DURATION_S;
|
||||
time_stopped_flags_.reset(); // Resetea flags al activar el item
|
||||
}
|
||||
|
||||
// Deshabilita el efecto del item de detener el tiempo
|
||||
@@ -1890,6 +1883,10 @@ void Game::setState(State state) {
|
||||
destroyAllItems(); // Destruye todos los items
|
||||
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
|
||||
tabe_->disableSpawning(); // Deshabilita la creacion de Tabes
|
||||
game_completed_flags_.reset(); // Resetea flags de juego completado
|
||||
break;
|
||||
case State::GAME_OVER:
|
||||
game_over_flags_.reset(); // Resetea flags de game over
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1951,20 +1948,11 @@ void Game::onPauseStateChanged(bool is_paused) {
|
||||
|
||||
// Maneja eventos del juego completado usando flags para triggers únicos
|
||||
void Game::handleGameCompletedEvents() {
|
||||
static bool start_celebrations_triggered = false;
|
||||
static bool end_celebrations_triggered = false;
|
||||
|
||||
// Resetear
|
||||
if (game_completed_timer_ == 0.0f) {
|
||||
start_celebrations_triggered = false;
|
||||
end_celebrations_triggered = false;
|
||||
}
|
||||
|
||||
constexpr float START_CELEBRATIONS_S = 6.0f;
|
||||
constexpr float END_CELEBRATIONS_S = 14.0f;
|
||||
|
||||
// Inicio de celebraciones
|
||||
if (!start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_S) {
|
||||
if (!game_completed_flags_.start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_S) {
|
||||
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
||||
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
||||
|
||||
@@ -1979,43 +1967,44 @@ void Game::handleGameCompletedEvents() {
|
||||
|
||||
updateHiScore();
|
||||
playMusic("congratulations.ogg", 1);
|
||||
start_celebrations_triggered = true;
|
||||
game_completed_flags_.start_celebrations_triggered = true;
|
||||
}
|
||||
|
||||
// Fin de celebraciones
|
||||
if (!end_celebrations_triggered && game_completed_timer_ >= END_CELEBRATIONS_S) {
|
||||
if (!game_completed_flags_.end_celebrations_triggered && game_completed_timer_ >= END_CELEBRATIONS_S) {
|
||||
for (auto &player : players_) {
|
||||
if (player->isCelebrating()) {
|
||||
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
||||
}
|
||||
}
|
||||
end_celebrations_triggered = true;
|
||||
game_completed_flags_.end_celebrations_triggered = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja eventos de game over usando flag para trigger único
|
||||
// Maneja eventos discretos basados en tiempo durante el estado game over
|
||||
void Game::handleGameOverEvents() {
|
||||
static bool game_over_trigger1 = false;
|
||||
static bool game_over_trigger2 = false;
|
||||
constexpr float MESSAGE_TRIGGER_S = 1.5f;
|
||||
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5f;
|
||||
|
||||
// Resetear
|
||||
if (game_over_timer_ == 0.0f) {
|
||||
game_over_trigger1 = false;
|
||||
game_over_trigger2 = false;
|
||||
}
|
||||
|
||||
if (!game_over_trigger1 && game_over_timer_ == 0.0f) {
|
||||
// Trigger inicial: fade out de música y sonidos de globos
|
||||
if (!game_over_flags_.music_fade_triggered) {
|
||||
Audio::get()->fadeOutMusic(1000);
|
||||
balloon_manager_->setBouncingSounds(true);
|
||||
game_over_trigger1 = true;
|
||||
}
|
||||
|
||||
if (!game_over_trigger2 && game_over_timer_ >= 1.5f) {
|
||||
createMessage({paths_.at(10), paths_.at(11)}, Resource::get()->getTexture("game_text_game_over"));
|
||||
playSound("voice_game_over.wav");
|
||||
game_over_trigger2 = true;
|
||||
game_over_flags_.music_fade_triggered = true;
|
||||
}
|
||||
|
||||
// Trigger del mensaje "Game Over"
|
||||
if (!game_over_flags_.message_triggered && game_over_timer_ >= MESSAGE_TRIGGER_S) {
|
||||
createMessage({paths_.at(10), paths_.at(11)}, Resource::get()->getTexture("game_text_game_over"));
|
||||
playSound("voice_game_over.wav");
|
||||
game_over_flags_.message_triggered = true;
|
||||
}
|
||||
|
||||
// Trigger del fade out
|
||||
if (!game_over_flags_.fade_out_triggered && game_over_timer_ >= FADE_TRIGGER_S && !fade_out_->isEnabled()) {
|
||||
fade_out_->activate();
|
||||
game_over_flags_.fade_out_triggered = true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -165,6 +165,39 @@ class Game {
|
||||
std::vector<std::shared_ptr<Player>> players_to_put_at_front_;
|
||||
Hit hit_; // Para representar colisiones en pantalla
|
||||
|
||||
// Estructuras para gestionar flags de eventos basados en tiempo
|
||||
struct GameOverFlags {
|
||||
bool music_fade_triggered = false;
|
||||
bool message_triggered = false;
|
||||
bool fade_out_triggered = false;
|
||||
|
||||
void reset() {
|
||||
music_fade_triggered = false;
|
||||
message_triggered = false;
|
||||
fade_out_triggered = false;
|
||||
}
|
||||
} game_over_flags_;
|
||||
|
||||
struct GameCompletedFlags {
|
||||
bool start_celebrations_triggered = false;
|
||||
bool end_celebrations_triggered = false;
|
||||
|
||||
void reset() {
|
||||
start_celebrations_triggered = false;
|
||||
end_celebrations_triggered = false;
|
||||
}
|
||||
} game_completed_flags_;
|
||||
|
||||
struct TimeStoppedFlags {
|
||||
bool color_flash_sound_played = false;
|
||||
bool warning_phase_started = false;
|
||||
|
||||
void reset() {
|
||||
color_flash_sound_played = false;
|
||||
warning_phase_started = false;
|
||||
}
|
||||
} time_stopped_flags_;
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
|
||||
#endif
|
||||
@@ -185,7 +218,7 @@ class Game {
|
||||
void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado"
|
||||
void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo
|
||||
void updateGameStateCompleted(float deltaTime); // Gestiona el estado de juego completado
|
||||
void updateGameStateGameOver(float deltaTime); // Gestiona el estado de fin de partida
|
||||
void updateGameStateGameOver(float deltaTime); // Gestiona las actualizaciones continuas del estado de fin de partida
|
||||
|
||||
// --- Gestión de jugadores ---
|
||||
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
|
||||
@@ -250,7 +283,7 @@ class Game {
|
||||
void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo
|
||||
void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido
|
||||
void handleGameCompletedEvents(); // Maneja eventos del juego completado
|
||||
void handleGameOverEvents(); // Maneja eventos de game over
|
||||
void handleGameOverEvents(); // Maneja eventos discretos basados en tiempo durante game over
|
||||
void throwCoffee(int x, int y); // Crea efecto de café arrojado al ser golpeado
|
||||
|
||||
// --- Gestión de caída de ítems ---
|
||||
|
||||
@@ -368,17 +368,14 @@ void HiScoreTable::glowEntryNames() {
|
||||
|
||||
// Gestiona el contador
|
||||
void HiScoreTable::updateCounter() {
|
||||
static bool background_changed = false;
|
||||
static bool fade_activated = false;
|
||||
|
||||
if (elapsed_time_ >= BACKGROUND_CHANGE_S && !background_changed) {
|
||||
if (elapsed_time_ >= BACKGROUND_CHANGE_S && !hiscore_flags_.background_changed) {
|
||||
background_->setColor(background_fade_color_.DARKEN());
|
||||
background_->setAlpha(96);
|
||||
background_changed = true;
|
||||
hiscore_flags_.background_changed = true;
|
||||
}
|
||||
|
||||
if (elapsed_time_ >= COUNTER_END_S && !fade_activated) {
|
||||
if (elapsed_time_ >= COUNTER_END_S && !hiscore_flags_.fade_activated) {
|
||||
fade_->activate();
|
||||
fade_activated = true;
|
||||
hiscore_flags_.fade_activated = true;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,17 @@ class HiScoreTable {
|
||||
Color background_fade_color_; // Color de atenuación del fondo
|
||||
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla
|
||||
|
||||
// --- Flags para eventos basados en tiempo ---
|
||||
struct HiScoreFlags {
|
||||
bool background_changed = false;
|
||||
bool fade_activated = false;
|
||||
|
||||
void reset() {
|
||||
background_changed = false;
|
||||
fade_activated = false;
|
||||
}
|
||||
} hiscore_flags_;
|
||||
|
||||
// --- Métodos internos ---
|
||||
void update(float delta_time); // Actualiza las variables
|
||||
void render(); // Pinta en pantalla
|
||||
|
||||
@@ -43,7 +43,11 @@ Title::Title()
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
||||
state_(State::LOGO_ANIMATING),
|
||||
num_controllers_(Input::get()->getNumGamepads()) {
|
||||
num_controllers_(Input::get()->getNumGamepads())
|
||||
#ifdef _DEBUG
|
||||
, debug_color_(param.title.bg_color)
|
||||
#endif
|
||||
{
|
||||
// Configura objetos
|
||||
tiled_bg_->setColor(param.title.bg_color);
|
||||
tiled_bg_->setSpeed(0.0F);
|
||||
@@ -141,13 +145,11 @@ void Title::handleKeyDownEvent(const SDL_Event& event) {
|
||||
|
||||
#ifdef _DEBUG
|
||||
void Title::handleDebugColorKeys(SDL_Keycode key) {
|
||||
static Color color_ = param.title.bg_color;
|
||||
|
||||
adjustColorComponent(key, color_);
|
||||
adjustColorComponent(key, debug_color_);
|
||||
|
||||
counter_time_ = 0.0f;
|
||||
tiled_bg_->setColor(color_);
|
||||
printColorValue(color_);
|
||||
tiled_bg_->setColor(debug_color_);
|
||||
printColorValue(debug_color_);
|
||||
}
|
||||
|
||||
void Title::adjustColorComponent(SDL_Keycode key, Color& color) {
|
||||
|
||||
@@ -99,6 +99,10 @@ class Title {
|
||||
bool player1_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 1
|
||||
bool player2_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 2
|
||||
|
||||
#ifdef _DEBUG
|
||||
Color debug_color_; // Color para depuración en modo debug
|
||||
#endif
|
||||
|
||||
// --- Ciclo de vida del título ---
|
||||
void update(float deltaTime); // Actualiza las variables del objeto
|
||||
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
||||
|
||||
6
source/version.h.in
Normal file
6
source/version.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace Version {
|
||||
constexpr const char* GIT_HASH = "@GIT_HASH@";
|
||||
constexpr const char* APP_NAME = "Coffee Crisis Arcade Edition";
|
||||
}
|
||||
Binary file not shown.
@@ -1,9 +1,10 @@
|
||||
#include "../source/resource_pack.h"
|
||||
#include "../build/version.h" // Para Version::APP_NAME
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
void showHelp() {
|
||||
std::cout << "Coffee Crisis Arcade Edition - Resource Packer" << std::endl;
|
||||
std::cout << Version::APP_NAME << " - Resource Packer" << std::endl;
|
||||
std::cout << "===============================================" << std::endl;
|
||||
std::cout << "Usage: pack_resources [options] [input_dir] [output_file]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
@@ -71,7 +72,7 @@ int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "Coffee Crisis Arcade Edition - Resource Packer" << std::endl;
|
||||
std::cout << Version::APP_NAME << " - Resource Packer" << std::endl;
|
||||
std::cout << "===============================================" << std::endl;
|
||||
std::cout << "Input directory: " << dataDir << std::endl;
|
||||
std::cout << "Output file: " << outputFile << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user