Compare commits
21 Commits
b92e5df98b
...
merdes-nov
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e083a8cdb | |||
| cbe4315701 | |||
| 49d561b583 | |||
| 6e56a6fd79 | |||
| 267d9647e0 | |||
| 13b3702d00 | |||
| 4500845dcd | |||
| a4abc02f88 | |||
| a0fb6934b0 | |||
| 19645445b2 | |||
| efe8628a3c | |||
| c98cb0d29f | |||
| c16fc1bae5 | |||
| fa0af1179a | |||
| d1e4a5eb07 | |||
| e18d1b186a | |||
| d056a5e336 | |||
| b9e26aa755 | |||
| b2afef2226 | |||
| c400aa96c0 | |||
| 8818954dcd |
@@ -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
|
||||
@@ -79,6 +95,7 @@ set(APP_SOURCES
|
||||
|
||||
# --- Otros ---
|
||||
source/color.cpp
|
||||
source/demo.cpp
|
||||
source/define_buttons.cpp
|
||||
source/difficulty.cpp
|
||||
source/input_types.cpp
|
||||
@@ -92,17 +109,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}")
|
||||
@@ -114,6 +126,7 @@ add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/source"
|
||||
"${CMAKE_SOURCE_DIR}/source/external"
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
)
|
||||
|
||||
# Enlazar la librería SDL3
|
||||
@@ -128,16 +141,9 @@ 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)
|
||||
# Descomentar la siguiente línea para activar el modo grabación de demos
|
||||
# target_compile_definitions(${PROJECT_NAME} PRIVATE RECORDING)
|
||||
|
||||
# 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)
|
||||
|
||||
@@ -20,6 +20,7 @@ DATA|${PREFIX}/config/stages.txt
|
||||
# Archivos con los datos de la demo
|
||||
DEMODATA|${PREFIX}/data/demo/demo1.bin
|
||||
DEMODATA|${PREFIX}/data/demo/demo2.bin
|
||||
DEMODATA|${PREFIX}/data/demo/demo3.bin
|
||||
|
||||
# Música
|
||||
MUSIC|${PREFIX}/data/music/congratulations.ogg
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Formato: PARAMETRO VALOR
|
||||
|
||||
# --- GAME ---
|
||||
game.item_size 20 # Tamaño de los items del juego (en píxeles)
|
||||
game.item_text_outline_color E0E0E0F0 # Color del outline del texto de los items (RGBA hex)
|
||||
game.width 320 # Ancho de la resolución nativa del juego (en píxeles)
|
||||
game.height 240 # Alto de la resolución nativa del juego (en píxeles)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
data/demo/demo3.bin
Normal file
BIN
data/demo/demo3.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
|
||||
|
||||
#include <algorithm> // Para std::sort
|
||||
#include <cstddef> // Para size_t
|
||||
#include <exception> // Para exception
|
||||
#include <filesystem> // Para std::filesystem
|
||||
@@ -299,6 +300,9 @@ auto Asset::getListByType(Type type) const -> std::vector<std::string> {
|
||||
}
|
||||
}
|
||||
|
||||
// Ordenar alfabéticamente para garantizar orden consistente
|
||||
std::sort(list.begin(), list.end());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -122,6 +122,8 @@ class Balloon {
|
||||
|
||||
// --- Setters ---
|
||||
void setVelY(float vel_y) { vy_ = vel_y; }
|
||||
void setVelX(float vel_x) { vx_ = vel_x; }
|
||||
void alterVelX(float percent) {vx_ *= percent; }
|
||||
void setGameTempo(float tempo) { game_tempo_ = tempo; }
|
||||
void setInvulnerable(bool value) { invulnerable_ = value; }
|
||||
void setBouncingSound(bool value) { sound_.bouncing_enabled = value; }
|
||||
|
||||
@@ -208,6 +208,7 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
|
||||
Balloon::Config config = {
|
||||
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
|
||||
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
|
||||
.type = balloon->getType(),
|
||||
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
|
||||
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
|
||||
.game_tempo = balloon_speed_,
|
||||
@@ -216,9 +217,22 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
|
||||
// Crea el globo
|
||||
auto b = createBalloon(config);
|
||||
|
||||
// Establece parametros (deltaTime en segundos - velocidades en pixels/segundo)
|
||||
constexpr float VEL_Y_BALLOON_PER_S = -150.0F; // -2.50 pixels/frame convertido a pixels/segundo (-2.50 * 60 = -150)
|
||||
b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_S : Balloon::VELX_NEGATIVE * 2.0F);
|
||||
// Establece parametros
|
||||
constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
|
||||
switch (b->getType()) {
|
||||
case Balloon::Type::BALLOON: {
|
||||
b->setVelY(VEL_Y_BALLOON_PER_S);
|
||||
break;
|
||||
}
|
||||
case Balloon::Type::FLOATER: {
|
||||
const float MODIFIER = (rand() % 2 == 0) ? 1.0F : 1.0F;
|
||||
b->setVelY(Balloon::VELX_NEGATIVE * 2.0F * MODIFIER);
|
||||
(rand() % 2 == 0) ? b->alterVelX(1.0F) : b->alterVelX(1.0F);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Herencia de estados
|
||||
if (balloon->isStopped()) { b->stop(); }
|
||||
|
||||
@@ -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 {
|
||||
@@ -14,7 +15,6 @@ namespace GameDefaults {
|
||||
namespace Game {
|
||||
constexpr float WIDTH = 320.0F;
|
||||
constexpr float HEIGHT = 256.0F;
|
||||
constexpr float ITEM_SIZE = 20.0F;
|
||||
constexpr int NAME_ENTRY_IDLE_TIME = 10;
|
||||
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
|
||||
constexpr bool HIT_STOP = false;
|
||||
@@ -211,7 +211,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;
|
||||
|
||||
|
||||
70
source/demo.cpp
Normal file
70
source/demo.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "demo.h"
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_IOStream, SDL_IOFromConstMem, SDL_IOFromFile, SDL_ReadIO, SDL_WriteIO, SDL_CloseIO
|
||||
#include <stdexcept> // Para runtime_error
|
||||
|
||||
#include "resource_helper.h" // Para ResourceHelper
|
||||
#include "utils.h" // Para printWithDots, getFileName
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
|
||||
DemoData dd;
|
||||
|
||||
SDL_IOStream *file = nullptr;
|
||||
|
||||
// Intentar cargar desde ResourceHelper primero
|
||||
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||
if (!resource_data.empty()) {
|
||||
file = SDL_IOFromConstMem(resource_data.data(), resource_data.size());
|
||||
} else {
|
||||
// Fallback a filesystem directo
|
||||
file = SDL_IOFromFile(file_path.c_str(), "r+b");
|
||||
}
|
||||
|
||||
if (file == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]");
|
||||
|
||||
// Lee todos los datos del fichero y los deja en el destino
|
||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {
|
||||
DemoKeys dk = DemoKeys();
|
||||
SDL_ReadIO(file, &dk, sizeof(DemoKeys));
|
||||
dd.push_back(dk);
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
|
||||
return dd;
|
||||
}
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
|
||||
auto success = true;
|
||||
auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
|
||||
|
||||
if (file) {
|
||||
// Guarda los datos
|
||||
for (const auto &data : dd) {
|
||||
if (SDL_WriteIO(file, &data, sizeof(DemoKeys)) != sizeof(DemoKeys)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file %s", getFileName(file_path).c_str());
|
||||
}
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Unable to save %s file! %s", getFileName(file_path).c_str(), SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
#endif // RECORDING
|
||||
54
source/demo.h
Normal file
54
source/demo.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para Uint8
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
// --- Constantes ---
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// --- Estructuras ---
|
||||
struct DemoKeys {
|
||||
Uint8 left;
|
||||
Uint8 right;
|
||||
Uint8 no_input;
|
||||
Uint8 fire;
|
||||
Uint8 fire_left;
|
||||
Uint8 fire_right;
|
||||
|
||||
explicit DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
|
||||
: left(l),
|
||||
right(r),
|
||||
no_input(ni),
|
||||
fire(f),
|
||||
fire_left(fl),
|
||||
fire_right(fr) {}
|
||||
};
|
||||
|
||||
// --- Tipos ---
|
||||
using DemoData = std::vector<DemoKeys>;
|
||||
|
||||
struct Demo {
|
||||
bool enabled = false; // Indica si está activo el modo demo
|
||||
bool recording = false; // Indica si está activado el modo para grabar la demo
|
||||
float elapsed_s = 0.0F; // Segundos transcurridos de demo
|
||||
int index = 0; // Contador para el modo demo
|
||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||
|
||||
Demo() = default;
|
||||
|
||||
Demo(bool e, bool r, int c, const DemoKeys& k, const std::vector<DemoData>& d)
|
||||
: enabled(e),
|
||||
recording(r),
|
||||
index(c),
|
||||
keys(k),
|
||||
data(d) {}
|
||||
};
|
||||
|
||||
// --- Funciones ---
|
||||
auto loadDemoDataFromFile(const std::string& file_path) -> DemoData;
|
||||
|
||||
#ifdef RECORDING
|
||||
bool saveDemoFile(const std::string& file_path, const DemoData& dd);
|
||||
#endif
|
||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -26,8 +26,6 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
width_ = param.game.item_size;
|
||||
height_ = param.game.item_size;
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
// 6 velocidades: 3 negativas (-1.0, -0.66, -0.33) y 3 positivas (0.33, 0.66, 1.0)
|
||||
@@ -35,13 +33,17 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha
|
||||
if (direction < 3) {
|
||||
// Velocidades negativas: -1.0, -0.66, -0.33
|
||||
vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP);
|
||||
rotate_speed_ = -720.0F;
|
||||
} else {
|
||||
// Velocidades positivas: 0.33, 0.66, 1.0
|
||||
vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP);
|
||||
rotate_speed_ = 720.0F;
|
||||
}
|
||||
vel_y_ = ITEM_VEL_Y;
|
||||
accel_y_ = ITEM_ACCEL_Y;
|
||||
collider_.r = width_ / 2;
|
||||
sprite_->startRotate();
|
||||
sprite_->setRotateAmount(rotate_speed_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -104,6 +106,7 @@ void Item::move(float deltaTime) {
|
||||
// Si toca el borde lateral
|
||||
if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
|
||||
vel_x_ = -vel_x_; // Invierte la velocidad horizontal
|
||||
sprite_->scaleRotateAmount(-1.0F); // Invierte la rotación
|
||||
}
|
||||
|
||||
// Si colisiona por arriba, rebota (excepto la máquina de café)
|
||||
@@ -117,8 +120,9 @@ void Item::move(float deltaTime) {
|
||||
|
||||
// Si colisiona con la parte inferior
|
||||
if (pos_y_ > play_area_.h - height_) {
|
||||
// Corrige la posición
|
||||
pos_y_ = play_area_.h - height_;
|
||||
pos_y_ = play_area_.h - height_; // Corrige la posición
|
||||
sprite_->scaleRotateAmount(0.5F); // Reduce la rotación
|
||||
sprite_->stopRotate(300.0F); // Detiene la rotacion
|
||||
|
||||
switch (type_) {
|
||||
case ItemType::COFFEE_MACHINE:
|
||||
|
||||
@@ -27,6 +27,8 @@ enum class ItemType : int {
|
||||
class Item {
|
||||
public:
|
||||
// --- Constantes ---
|
||||
static constexpr float WIDTH = 20.0F; // Anchura del item
|
||||
static constexpr float HEIGHT = 20.0F; // ALtura del item
|
||||
static constexpr int COFFEE_MACHINE_WIDTH = 30; // Anchura de la máquina de café
|
||||
static constexpr int COFFEE_MACHINE_HEIGHT = 39; // Altura de la máquina de café
|
||||
static constexpr float LIFETIME_DURATION_S = 10.0f; // Duración de vida del ítem en segundos
|
||||
@@ -76,14 +78,15 @@ class Item {
|
||||
SDL_FRect play_area_; // Rectángulo con la zona de juego
|
||||
Circle collider_; // Círculo de colisión del objeto
|
||||
ItemType type_; // Tipo de objeto
|
||||
float pos_x_; // Posición X del objeto
|
||||
float pos_y_; // Posición Y del objeto
|
||||
float vel_x_; // Velocidad en el eje X
|
||||
float vel_y_; // Velocidad en el eje Y
|
||||
float pos_x_ = 0.0F; // Posición X del objeto
|
||||
float pos_y_ = 0.0F; // Posición Y del objeto
|
||||
float vel_x_ = 0.0F; // Velocidad en el eje X
|
||||
float vel_y_ = 0.0F; // Velocidad en el eje Y
|
||||
float accel_x_ = 0.0F; // Aceleración en el eje X
|
||||
float accel_y_; // Aceleración en el eje Y
|
||||
int width_; // Ancho del objeto
|
||||
int height_; // Alto del objeto
|
||||
float accel_y_ = 0.0F; // Aceleración en el eje Y
|
||||
float width_ = WIDTH; // Ancho del objeto
|
||||
float height_ = HEIGHT; // Alto del objeto
|
||||
float rotate_speed_ = 0.0F; // Velocidad de rotacion
|
||||
float lifetime_timer_ = 0.0f; // Acumulador de tiempo de vida del ítem (segundos)
|
||||
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
||||
bool enabled_ = true; // Indica si el objeto está habilitado
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "moving_sprite.h"
|
||||
|
||||
#include <cmath> // Para std::abs
|
||||
#include <utility>
|
||||
|
||||
#include "texture.h" // Para Texture
|
||||
@@ -90,6 +91,21 @@ void MovingSprite::setRotate(bool enable) {
|
||||
rotate_.enabled = enable;
|
||||
}
|
||||
|
||||
// Habilita la rotación y establece el centro en el centro del sprite
|
||||
void MovingSprite::startRotate() {
|
||||
rotate_.enabled = true;
|
||||
rotate_.center.x = pos_.w / 2.0F;
|
||||
rotate_.center.y = pos_.h / 2.0F;
|
||||
}
|
||||
|
||||
// Detiene la rotación y resetea el ángulo a cero
|
||||
void MovingSprite::stopRotate(float threshold) {
|
||||
if (threshold == 0.0F || std::abs(rotate_.amount) <= threshold) {
|
||||
rotate_.enabled = false;
|
||||
rotate_.angle = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void MovingSprite::setPos(SDL_FRect rect) {
|
||||
x_ = rect.x;
|
||||
|
||||
@@ -15,7 +15,6 @@ class MovingSprite : public Sprite {
|
||||
// --- Estructuras ---
|
||||
struct Rotate {
|
||||
bool enabled{false}; // Indica si ha de rotar
|
||||
int speed{1}; // Velocidad de giro
|
||||
double angle{0.0}; // Ángulo para dibujarlo
|
||||
float amount{0.0F}; // Cantidad de grados a girar en cada iteración
|
||||
SDL_FPoint center{.x = 0.0F, .y = 0.0F}; // Centro de rotación
|
||||
@@ -47,8 +46,10 @@ class MovingSprite : public Sprite {
|
||||
void setAngle(double value) { rotate_.angle = value; } // Establece el ángulo
|
||||
void setRotatingCenter(SDL_FPoint point) { rotate_.center = point; } // Establece el centro de rotación
|
||||
void setRotate(bool enable); // Activa o desactiva el efecto de rotación
|
||||
void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); } // Establece la velocidad de rotación
|
||||
void setRotateAmount(double value) { rotate_.amount = value; } // Establece la cantidad de rotación
|
||||
void startRotate(); // Habilita la rotación con centro automático
|
||||
void stopRotate(float threshold = 0.0F); // Detiene la rotación y resetea ángulo
|
||||
void setRotateAmount(double value) { rotate_.amount = value; } // Establece la velocidad de rotación
|
||||
void scaleRotateAmount(float value) { rotate_.amount *= value; } // Modifica la velocidad de rotacion
|
||||
void switchRotate() { rotate_.amount *= -1; } // Cambia el sentido de la rotación
|
||||
void setFlip(SDL_FlipMode flip) { flip_ = flip; } // Establece el flip
|
||||
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; } // Cambia el flip
|
||||
|
||||
@@ -87,7 +87,6 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> INT_PARAMS = {
|
||||
{"game.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
|
||||
{"game.height", [](const std::string& v) { param.game.height = std::stoi(v); }},
|
||||
{"game.item_size", [](const std::string& v) { param.game.item_size = std::stoi(v); }},
|
||||
{"game.play_area.rect.x", [](const std::string& v) { param.game.play_area.rect.x = std::stoi(v); }},
|
||||
{"game.play_area.rect.y", [](const std::string& v) { param.game.play_area.rect.y = std::stoi(v); }},
|
||||
{"game.play_area.rect.w", [](const std::string& v) { param.game.play_area.rect.w = std::stoi(v); }},
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
struct ParamGame {
|
||||
float width = GameDefaults::Game::WIDTH;
|
||||
float height = GameDefaults::Game::HEIGHT;
|
||||
float item_size = GameDefaults::Game::ITEM_SIZE;
|
||||
Zone play_area{}; // Se inicializa en el constructor de Param
|
||||
Zone game_area{}; // Se inicializa en el constructor de Param
|
||||
int name_entry_idle_time = GameDefaults::Game::NAME_ENTRY_IDLE_TIME;
|
||||
|
||||
@@ -217,6 +217,10 @@ class Player {
|
||||
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
||||
[[nodiscard]] auto getController() const -> int { return controller_index_; }
|
||||
|
||||
// Demo file management
|
||||
[[nodiscard]] auto getDemoFile() const -> size_t { return demo_file_; }
|
||||
void setDemoFile(size_t demo_file) { demo_file_ = demo_file; }
|
||||
|
||||
private:
|
||||
// --- Constantes de física y movimiento ---
|
||||
static constexpr float BASE_SPEED = 90.0f; // Velocidad base del jugador (pixels/segundo)
|
||||
@@ -304,6 +308,7 @@ class Player {
|
||||
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
int continue_counter_ = 10; // Contador para poder continuar
|
||||
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
||||
size_t demo_file_ = 0; // Indice del fichero de datos para el modo demo
|
||||
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
|
||||
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
|
||||
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
||||
@@ -350,16 +355,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,14 +12,13 @@
|
||||
|
||||
#include "asset.h" // Para Asset
|
||||
#include "color.h" // Para Color
|
||||
#ifndef NO_AUDIO
|
||||
#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
|
||||
#include "screen.h" // Para Screen
|
||||
#include "text.h" // Para Text
|
||||
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
|
||||
|
||||
struct JA_Music_t; // lines 11-11
|
||||
struct JA_Sound_t; // lines 12-12
|
||||
@@ -317,6 +316,11 @@ auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & {
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
|
||||
auto Resource::getDemoData(int index) -> DemoData& {
|
||||
if (index < 0 || index >= static_cast<int>(demos_.size())) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index %d out of range for demo data (size: %d)", index, static_cast<int>(demos_.size()));
|
||||
static DemoData empty_demo;
|
||||
return empty_demo;
|
||||
}
|
||||
return demos_.at(index);
|
||||
}
|
||||
|
||||
@@ -324,7 +328,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 +335,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 +347,6 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
||||
return JA_LoadMusic(audio_path.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -425,10 +425,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 +446,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 +480,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 +495,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 ]");
|
||||
}
|
||||
}
|
||||
@@ -555,12 +543,13 @@ void Resource::loadAnimations() {
|
||||
// Carga los datos para el modo demostración
|
||||
void Resource::loadDemoData() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES");
|
||||
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
|
||||
demos_.clear();
|
||||
|
||||
constexpr std::array<const char *, 2> DEMO_FILES = {"demo1.bin", "demo2.bin"};
|
||||
|
||||
for (const auto &file : DEMO_FILES) {
|
||||
updateLoadingProgress(file);
|
||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get(file)));
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
demos_.emplace_back(loadDemoDataFromFile(l));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,9 +727,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 +738,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 +794,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);
|
||||
|
||||
@@ -850,12 +842,11 @@ void Resource::checkEvents() {
|
||||
// Carga los datos para el modo demostración (sin mostrar progreso)
|
||||
void Resource::loadDemoDataQuiet() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES (quiet load)");
|
||||
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
|
||||
demos_.clear();
|
||||
|
||||
constexpr std::array<const char *, 2> DEMO_FILES = {"demo1.bin", "demo2.bin"};
|
||||
|
||||
for (const auto &file : DEMO_FILES) {
|
||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get(file)));
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Demo file loaded: %s", file);
|
||||
for (const auto& l : list) {
|
||||
demos_.emplace_back(loadDemoDataFromFile(l));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "animated_sprite.h" // Para AnimationsFileBuffer
|
||||
#include "text.h" // Para Text, TextFile
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para DemoData
|
||||
#include "demo.h" // Para DemoData
|
||||
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
@@ -217,6 +217,10 @@ void Screen::renderInfo() {
|
||||
// FPS
|
||||
const std::string FPS_TEXT = std::to_string(fps_.last_value) + " FPS";
|
||||
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
#ifdef RECORDING
|
||||
// RECORDING
|
||||
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length("RECORDING"), 2*(1 + debug_info_.text->getCharacterSize()), "RECORDING", 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -296,14 +300,25 @@ auto Screen::initSDLVideo() -> bool {
|
||||
// Obtener información de la pantalla
|
||||
getDisplayInfo();
|
||||
|
||||
// Configurar hint para OpenGL
|
||||
// Configurar hint para renderizado
|
||||
#ifdef __APPLE__
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal")) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Warning: Failed to set Metal hint!");
|
||||
}
|
||||
#else
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl")) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Warning: Failed to set OpenGL hint!");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Crear ventana
|
||||
#ifdef __APPLE__
|
||||
SDL_WindowFlags window_flags = SDL_WINDOW_METAL;
|
||||
#else
|
||||
SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL;
|
||||
#endif
|
||||
if (Options::video.fullscreen) {
|
||||
window_flags |= SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
|
||||
|
||||
#include <algorithm> // Para find, clamp, find_if, min
|
||||
#include <algorithm> // Para find, clamp, find_if, min, std::shuffle, std::iota
|
||||
#include <array> // Para array
|
||||
#include <cstdlib> // Para rand, size_t
|
||||
#include <functional> // Para function
|
||||
#include <iterator> // Para size
|
||||
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
|
||||
#include <random> // std::random_device, std::default_random_engine
|
||||
#include <utility> // Para move
|
||||
|
||||
#include "asset.h" // Para Asset
|
||||
@@ -48,7 +49,7 @@
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
Game::Game(Player::Id player_id, int current_stage, bool demo_enabled)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
screen_(Screen::get()),
|
||||
input_(Input::get()),
|
||||
@@ -62,7 +63,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
tabe_(std::make_unique<Tabe>()),
|
||||
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
||||
// Pasa variables
|
||||
demo_.enabled = demo;
|
||||
demo_.enabled = demo_enabled;
|
||||
|
||||
// Otras variables
|
||||
Section::name = Section::Name::GAME;
|
||||
@@ -83,7 +84,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
fade_in_->setPostDuration(0);
|
||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||
fade_in_->setMode(Fade::Mode::IN);
|
||||
#ifndef RECORDING
|
||||
fade_in_->activate();
|
||||
#endif
|
||||
|
||||
fade_out_->setColor(param.fade.color);
|
||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||
@@ -109,6 +112,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
pause_manager_->setServiceMenuPause(is_active);
|
||||
}
|
||||
});
|
||||
#ifdef RECORDING
|
||||
setState(State::PLAYING);
|
||||
#endif
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
@@ -319,7 +325,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 +342,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) {
|
||||
@@ -408,6 +408,7 @@ void Game::destroyAllItems() {
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
||||
#ifndef RECORDING
|
||||
for (auto& balloon : balloon_manager_->getBalloons()) {
|
||||
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
||||
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
||||
@@ -415,6 +416,7 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return nullptr; // No se ha producido ninguna colisión
|
||||
}
|
||||
@@ -784,8 +786,8 @@ void Game::throwCoffee(int x, int y) {
|
||||
|
||||
smart_sprites_.back()->setPosX(x - 8);
|
||||
smart_sprites_.back()->setPosY(y - 8);
|
||||
smart_sprites_.back()->setWidth(param.game.item_size);
|
||||
smart_sprites_.back()->setHeight(param.game.item_size);
|
||||
smart_sprites_.back()->setWidth(Item::WIDTH);
|
||||
smart_sprites_.back()->setHeight(Item::HEIGHT);
|
||||
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0f); // Convertir a pixels/segundo
|
||||
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
|
||||
smart_sprites_.back()->setAccelX(0.0F);
|
||||
@@ -794,10 +796,9 @@ void Game::throwCoffee(int x, int y) {
|
||||
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||
smart_sprites_.back()->setEnabled(true);
|
||||
smart_sprites_.back()->setFinishedDelay(0.0F);
|
||||
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
|
||||
smart_sprites_.back()->setRotatingCenter({param.game.item_size / 2, param.game.item_size / 2});
|
||||
smart_sprites_.back()->setSpriteClip(0, Item::HEIGHT, Item::WIDTH, Item::HEIGHT);
|
||||
smart_sprites_.back()->setRotatingCenter({Item::WIDTH / 2, Item::HEIGHT / 2});
|
||||
smart_sprites_.back()->setRotate(true);
|
||||
smart_sprites_.back()->setRotateSpeed(10);
|
||||
smart_sprites_.back()->setRotateAmount(90.0);
|
||||
}
|
||||
|
||||
@@ -872,13 +873,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 +887,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
|
||||
@@ -917,9 +916,9 @@ void Game::update(float deltaTime) {
|
||||
screen_->update(deltaTime); // Actualiza el objeto screen
|
||||
Audio::update(); // Actualiza el objeto audio
|
||||
|
||||
updateDemo();
|
||||
updateDemo(deltaTime);
|
||||
#ifdef RECORDING
|
||||
updateRecording();
|
||||
updateRecording(deltaTime);
|
||||
#endif
|
||||
updateGameStates(deltaTime);
|
||||
fillCanvas();
|
||||
@@ -997,6 +996,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
|
||||
@@ -1019,10 +1019,8 @@ void Game::run() {
|
||||
last_time_ = SDL_GetTicks();
|
||||
|
||||
while (Section::name == Section::Name::GAME) {
|
||||
#ifndef RECORDING
|
||||
checkInput();
|
||||
#endif
|
||||
const float delta_time = calculateDeltaTime();
|
||||
checkInput();
|
||||
update(delta_time);
|
||||
handleEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
@@ -1294,19 +1292,16 @@ void Game::demoHandlePassInput() {
|
||||
|
||||
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
||||
void Game::demoHandleInput() {
|
||||
int index = 0;
|
||||
for (const auto& player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
// Maneja el input específico del jugador en modo demo.
|
||||
demoHandlePlayerInput(player, index);
|
||||
demoHandlePlayerInput(player, player->getDemoFile()); // Maneja el input específico del jugador en modo demo.
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||
void Game::demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index) {
|
||||
const auto &demo_data = demo_.data.at(index).at(demo_.counter);
|
||||
const auto& demo_data = demo_.data.at(index).at(demo_.index);
|
||||
|
||||
if (demo_data.left == 1) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
@@ -1521,21 +1516,43 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||
|
||||
// Inicializa las variables para el modo DEMO
|
||||
void Game::initDemo(Player::Id player_id) {
|
||||
#ifdef RECORDING
|
||||
// En modo grabación, inicializar vector vacío para almacenar teclas
|
||||
demo_.data.emplace_back(); // Vector vacío para grabación
|
||||
demo_.data.at(0).reserve(TOTAL_DEMO_DATA); // Reservar espacio para 2000 elementos
|
||||
#endif
|
||||
|
||||
if (demo_.enabled) {
|
||||
// Cambia el estado del juego
|
||||
setState(State::PLAYING);
|
||||
|
||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||
const auto DEMO1 = rand() % 2;
|
||||
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
||||
#ifndef RECORDING
|
||||
// En modo juego: cargar todas las demos y asignar una diferente a cada jugador
|
||||
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(num_demo));
|
||||
}
|
||||
|
||||
// Crear índices mezclados para asignación aleatoria
|
||||
std::vector<size_t> demo_indices(NUM_DEMOS);
|
||||
std::iota(demo_indices.begin(), demo_indices.end(), 0);
|
||||
std::random_device rd;
|
||||
std::default_random_engine rng(rd());
|
||||
std::shuffle(demo_indices.begin(), demo_indices.end(), rng);
|
||||
|
||||
// Asignar demos a jugadores (round-robin si hay más jugadores que demos)
|
||||
for (size_t i = 0; i < players_.size(); ++i) {
|
||||
size_t demo_index = demo_indices[i % NUM_DEMOS];
|
||||
players_.at(i)->setDemoFile(demo_index);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Selecciona una pantalla al azar
|
||||
constexpr auto NUM_DEMOS = 3;
|
||||
const auto DEMO = rand() % NUM_DEMOS;
|
||||
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
|
||||
stage_manager_->jumpToStage(STAGES.at(DEMO));
|
||||
constexpr auto NUM_STAGES = 3;
|
||||
const auto STAGE = rand() % NUM_STAGES;
|
||||
constexpr std::array<float, NUM_STAGES> STAGES = {0.005F, 0.32F, 0.53F};
|
||||
stage_manager_->setTotalPower(stage_manager_->getTotalPowerNeededToCompleteGame() * STAGES.at(STAGE));
|
||||
background_->setProgress(stage_manager_->getTotalPower());
|
||||
|
||||
// Activa o no al otro jugador
|
||||
if (rand() % 3 != 0) {
|
||||
@@ -1569,7 +1586,7 @@ void Game::initDemo(Player::Id player_id) {
|
||||
#else
|
||||
demo_.recording = false;
|
||||
#endif
|
||||
demo_.counter = 0;
|
||||
demo_.index = 0;
|
||||
}
|
||||
|
||||
// Inicializa el marcador
|
||||
@@ -1624,7 +1641,11 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
// Crea al jugador uno y lo pone en modo espera
|
||||
Player::Config config_player1{
|
||||
.id = Player::Id::PLAYER1,
|
||||
#ifdef RECORDING
|
||||
.x = param.game.play_area.center_x - (Player::WIDTH / 2),
|
||||
#else
|
||||
.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2),
|
||||
#endif
|
||||
.y = Y,
|
||||
.demo = demo_.enabled,
|
||||
.play_area = ¶m.game.play_area.rect,
|
||||
@@ -1641,7 +1662,11 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
||||
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
||||
#ifdef RECORDING
|
||||
player1->setPlayingState(Player::State::PLAYING);
|
||||
#else
|
||||
player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING);
|
||||
#endif
|
||||
|
||||
// Crea al jugador dos y lo pone en modo espera
|
||||
Player::Config config_player2{
|
||||
@@ -1699,7 +1724,7 @@ void Game::stopMusic() const {
|
||||
}
|
||||
|
||||
// Actualiza las variables durante el modo demo
|
||||
void Game::updateDemo() {
|
||||
void Game::updateDemo(float deltaTime) {
|
||||
if (demo_.enabled) {
|
||||
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||
|
||||
@@ -1707,16 +1732,12 @@ void Game::updateDemo() {
|
||||
fade_in_->update();
|
||||
fade_out_->update();
|
||||
|
||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
||||
static float demo_frame_timer = 0.0f;
|
||||
demo_frame_timer += calculateDeltaTime();
|
||||
if (demo_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
||||
demo_.counter++;
|
||||
demo_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
||||
}
|
||||
// Actualiza el contador de tiempo y el índice
|
||||
demo_.elapsed_s += deltaTime;
|
||||
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||
|
||||
// Activa el fundido antes de acabar con los datos de la demo
|
||||
if (demo_.counter == TOTAL_DEMO_DATA - 200) {
|
||||
if (demo_.index == TOTAL_DEMO_DATA - 200) {
|
||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||
fade_out_->activate();
|
||||
@@ -1732,22 +1753,28 @@ void Game::updateDemo() {
|
||||
|
||||
#ifdef RECORDING
|
||||
// Actualiza las variables durante el modo de grabación
|
||||
void Game::updateRecording() {
|
||||
// Solo mira y guarda el input en cada update
|
||||
checkInput();
|
||||
void Game::updateRecording(float deltaTime) {
|
||||
// Actualiza el contador de tiempo y el índice
|
||||
demo_.elapsed_s += deltaTime;
|
||||
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||
|
||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
||||
static float recording_frame_timer = 0.0f;
|
||||
recording_frame_timer += calculateDeltaTime();
|
||||
if (recording_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
||||
demo_.counter++;
|
||||
recording_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
||||
if (demo_.index >= TOTAL_DEMO_DATA) {
|
||||
Section::name = Section::Name::QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
// Si se ha llenado el vector con datos, sale del programa
|
||||
else {
|
||||
section::name = section::Name::QUIT;
|
||||
return;
|
||||
// Almacenar las teclas del frame actual en el vector de grabación
|
||||
if (demo_.index < TOTAL_DEMO_DATA && demo_.data.size() > 0) {
|
||||
// Asegurar que el vector tenga el tamaño suficiente
|
||||
if (demo_.data.at(0).size() <= static_cast<size_t>(demo_.index)) {
|
||||
demo_.data.at(0).resize(demo_.index + 1);
|
||||
}
|
||||
|
||||
// Almacenar las teclas del frame actual
|
||||
demo_.data.at(0).at(demo_.index) = demo_.keys;
|
||||
|
||||
// Resetear las teclas para el siguiente frame
|
||||
demo_.keys = DemoKeys();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1890,6 +1917,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 +1982,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 +2001,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;
|
||||
game_over_flags_.music_fade_triggered = true;
|
||||
}
|
||||
|
||||
if (!game_over_trigger2 && game_over_timer_ >= 1.5f) {
|
||||
// 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_trigger2 = true;
|
||||
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
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#include "player.h" // Para Player
|
||||
#include "smart_sprite.h" // Para SmartSprite
|
||||
#include "stage.h" // Para StageManager
|
||||
#include "utils.h" // Para Demo
|
||||
#include "demo.h" // Para Demo
|
||||
#include "utils.h" // Para otras utilidades
|
||||
|
||||
class Background;
|
||||
class Balloon;
|
||||
@@ -56,7 +57,7 @@ class Game {
|
||||
static constexpr bool DEMO_ON = true; // Modo demo activado
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
Game(Player::Id player_id, int current_stage, bool demo); // Constructor principal
|
||||
Game(Player::Id player_id, int current_stage, bool demo_enabled); // Constructor principal
|
||||
~Game(); // Destructor
|
||||
|
||||
// --- Bucle principal ---
|
||||
@@ -165,6 +166,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 +219,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 +284,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 ---
|
||||
@@ -292,7 +326,7 @@ class Game {
|
||||
|
||||
// --- Modo demostración ---
|
||||
void initDemo(Player::Id player_id); // Inicializa variables para el modo demostración
|
||||
void updateDemo(); // Actualiza lógica específica del modo demo
|
||||
void updateDemo(float deltaTime); // Actualiza lógica específica del modo demo
|
||||
|
||||
// --- Recursos y renderizado ---
|
||||
void setResources(); // Asigna texturas y animaciones a los objetos
|
||||
@@ -313,7 +347,7 @@ class Game {
|
||||
|
||||
// SISTEMA DE GRABACIÓN (CONDICIONAL)
|
||||
#ifdef RECORDING
|
||||
void updateRecording(); // Actualiza variables durante modo de grabación
|
||||
void updateRecording(float deltaTime); // Actualiza variables durante modo de grabación
|
||||
#endif
|
||||
|
||||
// --- Depuración (solo en modo DEBUG) ---
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "global_events.h" // Para check
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input
|
||||
#include "item.h" // Para Item
|
||||
#include "lang.h" // Para getText
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamFade, Param...
|
||||
#include "resource.h" // Para Resource
|
||||
@@ -78,40 +79,40 @@ void Instructions::iniSprites() {
|
||||
|
||||
// Inicializa los sprites
|
||||
for (int i = 0; i < (int)item_textures_.size(); ++i) {
|
||||
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
|
||||
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
|
||||
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, Item::WIDTH, Item::HEIGHT);
|
||||
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((Item::HEIGHT + item_space_) * i)});
|
||||
sprites_.push_back(std::move(sprite));
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los sprites
|
||||
void Instructions::updateSprites() {
|
||||
SDL_FRect src_rect = {0, 0, param.game.item_size, param.game.item_size};
|
||||
SDL_FRect src_rect = {0, 0, Item::WIDTH, Item::HEIGHT};
|
||||
|
||||
// Disquito (desplazamiento 12/60 = 0.2s)
|
||||
src_rect.y = param.game.item_size * (static_cast<int>((elapsed_time_ + 0.2f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.2f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
sprites_[0]->setSpriteClip(src_rect);
|
||||
|
||||
// Gavina (desplazamiento 9/60 = 0.15s)
|
||||
src_rect.y = param.game.item_size * (static_cast<int>((elapsed_time_ + 0.15f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.15f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
sprites_[1]->setSpriteClip(src_rect);
|
||||
|
||||
// Pacmar (desplazamiento 6/60 = 0.1s)
|
||||
src_rect.y = param.game.item_size * (static_cast<int>((elapsed_time_ + 0.1f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.1f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
sprites_[2]->setSpriteClip(src_rect);
|
||||
|
||||
// Time Stopper (desplazamiento 3/60 = 0.05s)
|
||||
src_rect.y = param.game.item_size * (static_cast<int>((elapsed_time_ + 0.05f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.05f) / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
sprites_[3]->setSpriteClip(src_rect);
|
||||
|
||||
// Coffee (sin desplazamiento)
|
||||
src_rect.y = param.game.item_size * (static_cast<int>(elapsed_time_ / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
src_rect.y = Item::HEIGHT * (static_cast<int>(elapsed_time_ / SPRITE_ANIMATION_CYCLE_S) % 2);
|
||||
sprites_[4]->setSpriteClip(src_rect);
|
||||
}
|
||||
|
||||
// Rellena la textura de texto
|
||||
void Instructions::fillTexture() {
|
||||
const int X_OFFSET = param.game.item_size + 8;
|
||||
const int X_OFFSET = Item::WIDTH + 8;
|
||||
|
||||
// Modifica el renderizador para pintar en la textura
|
||||
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||
@@ -130,7 +131,7 @@ void Instructions::fillTexture() {
|
||||
constexpr int SPACE_POST_HEADER = 20;
|
||||
constexpr int SPACE_PRE_HEADER = 28;
|
||||
const int SPACE_BETWEEN_LINES = text_->getCharacterSize() * 1.5F;
|
||||
const int SPACE_BETWEEN_ITEM_LINES = param.game.item_size + item_space_;
|
||||
const int SPACE_BETWEEN_ITEM_LINES = Item::HEIGHT + item_space_;
|
||||
const int SPACE_NEW_PARAGRAPH = SPACE_BETWEEN_LINES * 0.5F;
|
||||
|
||||
const int SIZE = (NUM_LINES * SPACE_BETWEEN_LINES) + (NUM_ITEM_LINES * SPACE_BETWEEN_ITEM_LINES) + (NUM_POST_HEADERS * SPACE_POST_HEADER) + (NUM_PRE_HEADERS * SPACE_PRE_HEADER) + (SPACE_NEW_PARAGRAPH);
|
||||
@@ -178,7 +179,7 @@ void Instructions::fillTexture() {
|
||||
|
||||
// Da valor a la variable
|
||||
sprite_pos_.x = ANCHOR_ITEM;
|
||||
sprite_pos_.y = ANCHOR3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
|
||||
sprite_pos_.y = ANCHOR3 - ((Item::HEIGHT - text_->getCharacterSize()) / 2);
|
||||
}
|
||||
|
||||
// Rellena el backbuffer
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -151,6 +151,51 @@ auto StageManager::jumpToStage(size_t target_stage_index) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto StageManager::setTotalPower(int target_total_power) -> bool {
|
||||
if (target_total_power < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int total_power_needed = getTotalPowerNeededToCompleteGame();
|
||||
if (target_total_power > total_power_needed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Calcular en qué fase debería estar y cuánto poder de esa fase
|
||||
int accumulated_power = 0;
|
||||
size_t target_stage_index = 0;
|
||||
int target_current_power = 0;
|
||||
|
||||
for (size_t i = 0; i < stages_.size(); ++i) {
|
||||
int stage_power = stages_[i].getPowerToComplete();
|
||||
|
||||
if (accumulated_power + stage_power > target_total_power) {
|
||||
// El objetivo está dentro de esta fase
|
||||
target_stage_index = i;
|
||||
target_current_power = target_total_power - accumulated_power;
|
||||
break;
|
||||
}
|
||||
|
||||
accumulated_power += stage_power;
|
||||
|
||||
if (accumulated_power == target_total_power) {
|
||||
// El objetivo coincide exactamente con el final de esta fase
|
||||
// Mover a la siguiente fase (si existe) con power 0
|
||||
target_stage_index = (i + 1 < stages_.size()) ? i + 1 : i;
|
||||
target_current_power = (i + 1 < stages_.size()) ? 0 : stage_power;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar estado
|
||||
current_stage_index_ = target_stage_index;
|
||||
current_power_ = target_current_power;
|
||||
total_power_ = target_total_power;
|
||||
|
||||
updateStageStatuses();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto StageManager::subtractPower(int amount) -> bool {
|
||||
if (amount <= 0 || current_power_ < amount) {
|
||||
return false;
|
||||
|
||||
@@ -67,6 +67,7 @@ class StageManager : public IStageInfo {
|
||||
|
||||
// --- Navegación ---
|
||||
auto jumpToStage(size_t target_stage_index) -> bool; // Salta a una fase específica
|
||||
auto setTotalPower(int target_total_power) -> bool; // Establece el poder total y ajusta fase/progreso
|
||||
|
||||
// --- Consultas de estado ---
|
||||
[[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual
|
||||
|
||||
@@ -38,7 +38,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
surface_ = loadSurface(path_);
|
||||
|
||||
// Añade la propia paleta del fichero a la lista
|
||||
addPaletteFromGifFile(path_);
|
||||
addPaletteFromGifFile(path_, true); // Usar modo silencioso
|
||||
|
||||
// Crea la textura, establece el BlendMode y copia la surface a la textura
|
||||
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||
@@ -301,7 +301,7 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) {
|
||||
}
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
||||
auto Texture::loadPaletteFromFile(const std::string &file_path, bool quiet) -> Palette {
|
||||
Palette palette;
|
||||
|
||||
std::vector<Uint8> buffer;
|
||||
@@ -329,7 +329,9 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
||||
}
|
||||
}
|
||||
|
||||
if (!quiet) {
|
||||
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
|
||||
GIF::Gif gif;
|
||||
@@ -349,14 +351,14 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
||||
}
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void Texture::addPaletteFromGifFile(const std::string &path) {
|
||||
palettes_.emplace_back(loadPaletteFromFile(path));
|
||||
void Texture::addPaletteFromGifFile(const std::string &path, bool quiet) {
|
||||
palettes_.emplace_back(loadPaletteFromFile(path, quiet));
|
||||
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
||||
}
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void Texture::addPaletteFromPalFile(const std::string &path) {
|
||||
palettes_.emplace_back(readPalFile(path));
|
||||
palettes_.emplace_back(readPalFile(path, true)); // Usar modo silencioso
|
||||
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
||||
}
|
||||
|
||||
@@ -372,7 +374,7 @@ void Texture::setPalette(size_t palette) {
|
||||
auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; }
|
||||
|
||||
// Carga una paleta desde un archivo .pal
|
||||
auto Texture::readPalFile(const std::string &file_path) -> Palette {
|
||||
auto Texture::readPalFile(const std::string &file_path, bool quiet) -> Palette {
|
||||
Palette palette{};
|
||||
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class Texture {
|
||||
void setAlpha(Uint8 alpha); // Establece el alpha para la modulación
|
||||
|
||||
// --- Paletas ---
|
||||
void addPaletteFromGifFile(const std::string &path); // Añade una paleta a la lista
|
||||
void addPaletteFromGifFile(const std::string &path, bool quiet = false); // Añade una paleta a la lista
|
||||
void addPaletteFromPalFile(const std::string &path); // Añade una paleta a la lista
|
||||
void setPaletteColor(int palette, int index, Uint32 color); // Establece un color de la paleta
|
||||
void setPalette(size_t palette); // Cambia la paleta de la textura
|
||||
@@ -76,8 +76,8 @@ class Texture {
|
||||
// --- Métodos internos ---
|
||||
auto loadSurface(const std::string &file_path) -> std::shared_ptr<Surface>; // Crea una surface desde un fichero .gif
|
||||
void flipSurface(); // Vuelca la surface en la textura
|
||||
static auto loadPaletteFromFile(const std::string &file_path) -> Palette; // Carga una paleta desde un fichero
|
||||
static auto loadPaletteFromFile(const std::string &file_path, bool quiet = false) -> Palette; // Carga una paleta desde un fichero
|
||||
void unloadTexture(); // Libera la memoria de la textura
|
||||
void unloadSurface(); // Libera la surface actual
|
||||
static auto readPalFile(const std::string &file_path) -> Palette; // Carga una paleta desde un archivo .pal
|
||||
static auto readPalFile(const std::string &file_path, bool quiet = false) -> Palette; // Carga una paleta desde un archivo .pal
|
||||
};
|
||||
@@ -320,68 +320,6 @@ void printWithDots(const std::string &text1, const std::string &text2, const std
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s", formatted_text.c_str());
|
||||
}
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
|
||||
DemoData dd;
|
||||
|
||||
SDL_IOStream *file = nullptr;
|
||||
|
||||
// Intentar cargar desde ResourceHelper primero
|
||||
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||
if (!resource_data.empty()) {
|
||||
file = SDL_IOFromConstMem(resource_data.data(), resource_data.size());
|
||||
} else {
|
||||
// Fallback a filesystem directo
|
||||
file = SDL_IOFromFile(file_path.c_str(), "r+b");
|
||||
}
|
||||
|
||||
if (file == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]");
|
||||
|
||||
// Lee todos los datos del fichero y los deja en el destino
|
||||
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {
|
||||
DemoKeys dk = DemoKeys();
|
||||
SDL_ReadIO(file, &dk, sizeof(DemoKeys));
|
||||
dd.push_back(dk);
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
|
||||
return dd;
|
||||
}
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
|
||||
auto success = true;
|
||||
auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
|
||||
|
||||
if (file) {
|
||||
// Guarda los datos
|
||||
for (const auto &data : dd) {
|
||||
if (SDL_RWwrite(file, &data, sizeof(DemoKeys), 1) != 1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file %s", getFileName(file_path).c_str());
|
||||
}
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Unable to save %s file! %s", getFileName(file_path).c_str(), SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
#endif // RECORDING
|
||||
|
||||
// Obtiene el nombre de un fichero a partir de una ruta completa
|
||||
auto getFileName(const std::string &path) -> std::string {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
// --- Constantes ---
|
||||
constexpr int BLOCK = 8;
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// --- Estructuras ---
|
||||
struct Overrides {
|
||||
@@ -32,44 +31,6 @@ struct Circle {
|
||||
r(radius) {}
|
||||
};
|
||||
|
||||
struct DemoKeys {
|
||||
Uint8 left;
|
||||
Uint8 right;
|
||||
Uint8 no_input;
|
||||
Uint8 fire;
|
||||
Uint8 fire_left;
|
||||
Uint8 fire_right;
|
||||
|
||||
explicit DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
|
||||
: left(l),
|
||||
right(r),
|
||||
no_input(ni),
|
||||
fire(f),
|
||||
fire_left(fl),
|
||||
fire_right(fr) {}
|
||||
};
|
||||
|
||||
// --- Tipos ---
|
||||
using DemoData = std::vector<DemoKeys>;
|
||||
|
||||
struct Demo {
|
||||
bool enabled; // Indica si está activo el modo demo
|
||||
bool recording; // Indica si está activado el modo para grabar la demo
|
||||
int counter; // Contador para el modo demo
|
||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||
|
||||
Demo()
|
||||
: enabled(false),
|
||||
recording(false),
|
||||
counter(0) {}
|
||||
Demo(bool e, bool r, int c, const DemoKeys &k, const std::vector<DemoData> &d)
|
||||
: enabled(e),
|
||||
recording(r),
|
||||
counter(c),
|
||||
keys(k),
|
||||
data(d) {}
|
||||
};
|
||||
|
||||
struct Zone {
|
||||
SDL_FRect rect; // Rectangulo que define la zona
|
||||
@@ -127,12 +88,6 @@ auto stringInVector(const std::vector<std::string> &vec, const std::string &str)
|
||||
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3); // Imprime una línea con puntos
|
||||
auto truncateWithEllipsis(const std::string& input, size_t length) -> std::string; // Trunca un string y le añade puntos suspensivos
|
||||
|
||||
// Demo
|
||||
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData;
|
||||
|
||||
#ifdef RECORDING
|
||||
bool saveDemoFile(const std::string &file_path, const DemoData &dd);
|
||||
#endif
|
||||
|
||||
// Ficheros y rutas
|
||||
auto getFileName(const std::string& path) -> std::string; // Obtiene el nombre de un fichero a partir de una ruta
|
||||
|
||||
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