Compare commits

49 Commits

Author SHA1 Message Date
4e083a8cdb item.cpp: afegida rotació 2025-09-30 14:16:25 +02:00
cbe4315701 moving_sprite.cpp: afegit umbral a stopRotate() 2025-09-30 14:11:58 +02:00
49d561b583 moving_sprite.cpp: afegida funcio per a escalar la velocitat de rotacio 2025-09-30 13:59:13 +02:00
6e56a6fd79 moving_sprite.cpp: afegits nous metodes per controlar la rotació 2025-09-30 13:47:48 +02:00
267d9647e0 moving_sprite.cpp: la variable rotate.speed ja no es gastava 2025-09-30 13:38:06 +02:00
13b3702d00 eliminat param.game.item_size 2025-09-30 13:23:50 +02:00
4500845dcd muguda la logica de demo de utils.cpp a demo.cpp 2025-09-30 12:58:32 +02:00
a4abc02f88 nou: modificat el valor de velocitat en la creació dels globos verds. i tornat a deixar com estava 2025-09-30 12:42:38 +02:00
a0fb6934b0 corregit: en el mode demo no calculava correctament el estat del fondo 2025-09-30 09:56:32 +02:00
19645445b2 corregit: els fills dels globos verds eixien taronja 2025-09-30 08:47:49 +02:00
efe8628a3c corregit: el log de CREATING PLAYER TEXTURES en resource.cpp 2025-09-29 14:22:44 +02:00
c98cb0d29f repensada la forma d'asignar fitxers de demo als jugadors
refets els fitxers de demo i afegit un tercer fitxer
2025-09-29 14:00:10 +02:00
c16fc1bae5 corregit: el mode demo ja funciona correctament 2025-09-29 12:47:13 +02:00
fa0af1179a corregit: no trobava version.h 2025-09-29 07:54:46 +02:00
d1e4a5eb07 eliminat tot el define NO_AUDIO del codi 2025-09-27 00:33:05 +02:00
e18d1b186a player.h: eliminat codi mort 2025-09-27 00:22:46 +02:00
d056a5e336 nou: afegida versió de git en la pantalla de carrega 2025-09-27 00:20:46 +02:00
b9e26aa755 corregit: flags estatics en credits.cpp i title.cpp 2025-09-26 23:48:08 +02:00
b2afef2226 corregit: flags estatics en hiscore_tale.cpp 2025-09-26 23:40:37 +02:00
c400aa96c0 corregit: flags estatics en game.cpp 2025-09-26 23:36:49 +02:00
8818954dcd afegit define rapidet per a renderer metal basic en macos 2025-09-26 22:45:14 +02:00
b92e5df98b nou: sonidos de bala diferent per a cada jugador 2025-09-26 20:48:22 +02:00
83871273ec nou: bales de colors diferents per a cada jugador 2025-09-26 20:37:00 +02:00
0459b39366 screen.cpp: getDisplayInfo()
resource.cpp: afegida info del display en la pantalla de carrega
2025-09-26 19:42:39 +02:00
5bb0ff19bc corregit: asset::checkFile() fallava desde fora del directori 2025-09-26 19:16:25 +02:00
a867b3cf4d integrat empaquetador de recursos en el makefile 2025-09-26 18:16:48 +02:00
8a6ce8e66d organitzat player.h 2025-09-26 17:37:29 +02:00
a40f04a739 nou: musiqueta i veu per al game over i timings ajustats 2025-09-26 17:20:35 +02:00
0c670fd344 novetat: canvi de color de les bales quan queda poc powerUp 2025-09-26 14:13:52 +02:00
35f4bf690c corregit: bug en Audio::fadeOutMusic quan la musica no es reproduia en bucle 2025-09-25 21:21:39 +02:00
abeaf47f96 corregit: timing de les celebracions del final 2025-09-25 19:48:58 +02:00
6498c35628 corregit audio i timing del game over 2025-09-25 19:36:40 +02:00
d1c6af02db corregit: la musica del joc soles sonava la primera volta 2025-09-25 19:19:46 +02:00
5edef17d84 nou: musica al completar el joc 2025-09-25 19:10:46 +02:00
e4532fcef2 nou: ruidet per a quan acabes de posar el nom 2025-09-25 18:18:39 +02:00
7a8d66c29d nou: quan arribes a la maxima puntuació, posa un lletreret 2025-09-25 17:52:49 +02:00
54292c9f8f fix: warning de override 2025-09-25 16:58:01 +02:00
3897553704 eliminat el vector precalculat en tiled_bg per al moviment circular 2025-09-25 08:08:29 +02:00
308f5c20fb corregit en background.cpp la desaceleració final, millorada amb funció de suavitzat i arreglades les velocitats dels nuvols que no variaven amb el pas del joc 2025-09-24 21:54:38 +02:00
987dcd0205 fix: el audio del logo.cpp soles sonava la primera volta 2025-09-24 20:54:45 +02:00
d56f23544c corregit menu_renderer.cpp, de vegades es modificava el ample del menu al canviar les opcions 2025-09-24 20:46:07 +02:00
c79a846b29 migrat service_menu.cpp a deltaTime 2025-09-24 19:34:08 +02:00
ad39d55e79 style: static auto *const SCREEN = Screen::get(); 2025-09-24 18:57:10 +02:00
853ef426f0 corregit el START PROMPT en title.cpp que no resetejava el contador de parpadeig 2025-09-24 18:51:36 +02:00
cadf7de3d8 tiled_bg.cpp, afegit changeSpeedTo() 2025-09-24 18:44:37 +02:00
ec65ff9acb corregit audio de timeStopItem 2025-09-24 18:26:39 +02:00
d077374883 migrat a deltaTime screen.cpp i notifier.cpp 2025-09-24 18:08:50 +02:00
40a2b2cc00 afegit TODO per al proxim dia 2025-09-24 14:02:30 +02:00
b3f3f151da corregits alguns parametres de ms a s 2025-09-24 13:56:12 +02:00
93 changed files with 2037 additions and 1601 deletions

1
.gitignore vendored
View File

@@ -18,3 +18,4 @@ debug.txt
cppcheck-result* cppcheck-result*
desktop.ini desktop.ini
ccae_release/ ccae_release/
resources.pack

View File

@@ -14,6 +14,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
cmake_policy(SET CMP0072 NEW) cmake_policy(SET CMP0072 NEW)
set(OpenGL_GL_PREFERENCE GLVND) 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 --- # --- 1. LISTA EXPLÍCITA DE FUENTES ---
set(APP_SOURCES set(APP_SOURCES
@@ -79,6 +95,7 @@ set(APP_SOURCES
# --- Otros --- # --- Otros ---
source/color.cpp source/color.cpp
source/demo.cpp
source/define_buttons.cpp source/define_buttons.cpp
source/difficulty.cpp source/difficulty.cpp
source/input_types.cpp source/input_types.cpp
@@ -92,17 +109,12 @@ set(APP_SOURCES
# Fuentes de librerías de terceros # Fuentes de librerías de terceros
set(EXTERNAL_SOURCES set(EXTERNAL_SOURCES
source/external/jail_audio.cpp
source/external/jail_shader.cpp source/external/jail_shader.cpp
source/external/json.hpp source/external/json.hpp
source/external/gif.cpp 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 # Configuración de SDL3
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3) find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}") 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 target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_SOURCE_DIR}/source" "${CMAKE_SOURCE_DIR}/source"
"${CMAKE_SOURCE_DIR}/source/external" "${CMAKE_SOURCE_DIR}/source/external"
"${CMAKE_BINARY_DIR}"
) )
# Enlazar la librería SDL3 # Enlazar la librería SDL3
@@ -128,16 +141,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
# Definir _DEBUG en modo Debug # Definir _DEBUG en modo Debug
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>) target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
# Opción para habilitar/deshabilitar audio # Descomentar la siguiente línea para activar el modo grabación de demos
option(DISABLE_AUDIO "Disable audio system" OFF) # 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 # Configuración específica para cada plataforma
if(WIN32) if(WIN32)

View File

@@ -1,81 +0,0 @@
# Plan de Migración DeltaTime - Eliminación de frameFactor
## Problema Identificado
Se están usando `frameFactor` conversions en 7 archivos, lo que indica una migración incompleta a deltaTime.
El patrón `float frameFactor = deltaTime / (1000.0f / 60.0f)` simula frames de 60fps en lugar de usar tiempo real.
## Archivos Afectados y Estado
1. **balloon.cpp** - 9 ocurrencias en métodos: moveX(), moveY(), updateState(), updateCreation()
2. **balloon_manager.cpp** - 2 ocurrencias en updateBalloonDeployment()
3. **bullet.cpp** - 3 ocurrencias en move()
4. **item.cpp** - 6 ocurrencias en move()
5. **moving_sprite.cpp** - 5 ocurrencias en move()
6. **tabe.cpp** - 5 ocurrencias en update() y updateHitEffect()
7. **credits.cpp** - 3 ocurrencias en update() y handleFadeOut()
## Estrategia de Migración
### Opción A: Velocidades ya en pixels/segundo
Si las velocidades están definidas en pixels/segundo:
```cpp
// ANTES (incorrecto)
float frameFactor = deltaTime / (1000.0f / 60.0f);
pos_x_ += vel_x_ * frameFactor;
// DESPUÉS (correcto)
pos_x_ += vel_x_ * (deltaTime / 1000.0f); // deltaTime en ms -> segundos
```
### Opción B: Velocidades en pixels/frame (legacy)
Si las velocidades están en pixels/frame (sistema legacy):
```cpp
// ANTES (incorrecto con deltaTime)
float frameFactor = deltaTime / (1000.0f / 60.0f);
pos_x_ += vel_x_ * frameFactor;
// OPCIÓN 1: Convertir velocidades a pixels/segundo
static constexpr float VEL_X_PER_SECOND = VEL_X_PER_FRAME * 60.0f;
pos_x_ += VEL_X_PER_SECOND * (deltaTime / 1000.0f);
// OPCIÓN 2: Mantener frame-factor pero mejorar claridad
pos_x_ += vel_x_ * (deltaTime / FRAME_TIME_MS); // donde FRAME_TIME_MS = 16.67f
```
## Plan de Ejecución
### Fase 1: Análisis de Velocidades
- [ ] Revisar definiciones de velocidades en cada clase
- [ ] Determinar si están en pixels/frame o pixels/segundo
- [ ] Identificar constantes que necesitan conversión
### Fase 2: Migración por Archivo
- [x] **balloon.cpp**: Migrar velocidades x/y y contadores ✅
- [x] **balloon_manager.cpp**: Migrar balloon_deploy_counter_ ✅
- [x] **bullet.cpp**: Migrar velocidades de bala ✅ (VEL_Y: -3.0F→-0.18F, VEL_X: ±2.0F→±0.12F)
- [x] **item.cpp**: Migrar física de ítems ✅ (vel_x: ±1.0F→±0.06F, vel_y: -4.0F→-0.24F, accel_y: 0.2F→0.012F)
- [ ] **moving_sprite.cpp**: Migrar sistema base de movimiento
- [ ] **tabe.cpp**: Migrar movimiento y efectos
- [ ] **credits.cpp**: Migrar contadores de timing
### Fase 3: Verificación
- [ ] Compilar y probar cada archivo migrado
- [ ] Verificar que el comportamiento se mantiene consistente
- [ ] Eliminar todas las referencias a frameFactor
- [ ] Actualizar comentarios para reflejar unidades correctas
## Criterios de Éxito
1. ✅ Cero ocurrencias de "frameFactor" en el código
2. ✅ Todas las velocidades claramente documentadas (pixels/segundo vs pixels/frame)
3. ✅ Comportamiento del juego idéntico al anterior
4. ✅ Código más limpio y mantenible
## Notas Importantes
- El frameFactor actual simula 60fps: `deltaTime / 16.67ms`
- Esto significa que las velocidades actuales están en "pixels per 16.67ms"
- Para verdadero deltaTime, necesitamos convertir a "pixels per second" o usar factor de frame explícito
- Mantener constantes claras para evitar números mágicos
## Estado: En Progreso
- Análisis iniciado
- Plan documentado
- Próximo paso: Análisis de velocidades en cada archivo

View File

@@ -3,6 +3,7 @@ DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST)))
DIR_SOURCES := $(addsuffix /, $(DIR_ROOT)source) DIR_SOURCES := $(addsuffix /, $(DIR_ROOT)source)
DIR_BIN := $(addsuffix /, $(DIR_ROOT)) DIR_BIN := $(addsuffix /, $(DIR_ROOT))
DIR_BUILD := $(addsuffix /, $(DIR_ROOT)build) DIR_BUILD := $(addsuffix /, $(DIR_ROOT)build)
DIR_TOOLS := $(addsuffix /, $(DIR_ROOT)tools)
# Variables # Variables
TARGET_NAME := coffee_crisis_arcade_edition TARGET_NAME := coffee_crisis_arcade_edition
@@ -12,6 +13,17 @@ RELEASE_FOLDER := ccae_release
RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME) RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME)
RESOURCE_FILE := release/coffee.res RESOURCE_FILE := release/coffee.res
# Variables para herramienta de empaquetado
ifeq ($(OS),Windows_NT)
PACK_TOOL := $(DIR_TOOLS)pack_resources.exe
PACK_CXX := $(CXX)
else
PACK_TOOL := $(DIR_TOOLS)pack_resources
PACK_CXX := $(CXX)
endif
PACK_SOURCES := $(DIR_TOOLS)pack_resources.cpp $(DIR_SOURCES)resource_pack.cpp
PACK_INCLUDES := -I$(DIR_ROOT)
# Versión automática basada en la fecha actual (específica por SO) # Versión automática basada en la fecha actual (específica por SO)
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'") VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'")
@@ -135,6 +147,19 @@ else
endif endif
endif endif
# Reglas para herramienta de empaquetado y resources.pack
$(PACK_TOOL): $(PACK_SOURCES)
@echo "Compilando herramienta de empaquetado..."
$(PACK_CXX) -std=c++17 -Wall -Os $(PACK_INCLUDES) $(PACK_SOURCES) -o $(PACK_TOOL)
@echo "✓ Herramienta de empaquetado lista: $(PACK_TOOL)"
pack_tool: $(PACK_TOOL)
resources.pack: $(PACK_TOOL)
@echo "Generando resources.pack desde directorio data/..."
$(PACK_TOOL) data resources.pack
@echo "✓ resources.pack generado exitosamente"
# Reglas para compilación # Reglas para compilación
windows: windows:
@echo off @echo off
@@ -153,7 +178,7 @@ windows_debug:
@echo Compilando version debug para Windows: "$(APP_NAME)_debug.exe" @echo Compilando version debug para Windows: "$(APP_NAME)_debug.exe"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe" $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe"
windows_release: windows_release: resources.pack
@echo off @echo off
@echo Creando release para Windows - Version: $(VERSION) @echo Creando release para Windows - Version: $(VERSION)
@@ -191,7 +216,7 @@ macos_debug:
@echo "Compilando version debug para macOS: $(TARGET_NAME)_debug" @echo "Compilando version debug para macOS: $(TARGET_NAME)_debug"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug" $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
macos_release: macos_release: resources.pack
@echo "Creando release para macOS - Version: $(VERSION)" @echo "Creando release para macOS - Version: $(VERSION)"
# Elimina datos de compilaciones anteriores # Elimina datos de compilaciones anteriores
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
@@ -258,7 +283,7 @@ linux_debug:
@echo "Compilando version debug para Linux: $(TARGET_NAME)_debug" @echo "Compilando version debug para Linux: $(TARGET_NAME)_debug"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug" $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
linux_release: linux_release: resources.pack
@echo "Creando release para Linux - Version: $(VERSION)" @echo "Creando release para Linux - Version: $(VERSION)"
# Elimina carpetas previas # Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
@@ -284,7 +309,7 @@ linux_release:
# Elimina la carpeta temporal # Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
linux_release_desktop: linux_release_desktop: resources.pack
@echo "Creando release con integracion desktop para Linux - Version: $(VERSION)" @echo "Creando release con integracion desktop para Linux - Version: $(VERSION)"
# Elimina carpetas previas # Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
@@ -389,7 +414,7 @@ raspi_debug:
@echo "Compilando version debug para Raspberry Pi: $(TARGET_NAME)_debug" @echo "Compilando version debug para Raspberry Pi: $(TARGET_NAME)_debug"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DVERBOSE -DDEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug" $(CXX) $(APP_SOURCES) $(INCLUDES) -DVERBOSE -DDEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
raspi_release: raspi_release: resources.pack
@echo "Creando release para Raspberry Pi - Version: $(VERSION)" @echo "Creando release para Raspberry Pi - Version: $(VERSION)"
# Elimina carpetas previas # Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
@@ -415,7 +440,7 @@ raspi_release:
# Elimina la carpeta temporal # Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
anbernic: anbernic: resources.pack
@echo "Compilando para Anbernic: $(TARGET_NAME)" @echo "Compilando para Anbernic: $(TARGET_NAME)"
# Elimina carpetas previas # Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"_anbernic $(RMDIR) "$(RELEASE_FOLDER)"_anbernic
@@ -457,7 +482,9 @@ help:
@echo " raspi_release - Crear release completo para Raspberry Pi" @echo " raspi_release - Crear release completo para Raspberry Pi"
@echo " anbernic - Compilar para Anbernic" @echo " anbernic - Compilar para Anbernic"
@echo " no_audio - Compilar sin sistema de audio" @echo " no_audio - Compilar sin sistema de audio"
@echo " pack_tool - Compilar herramienta de empaquetado"
@echo " resources.pack - Generar pack de recursos desde data/"
@echo " show_version - Mostrar version actual ($(VERSION))" @echo " show_version - Mostrar version actual ($(VERSION))"
@echo " help - Mostrar esta ayuda" @echo " help - Mostrar esta ayuda"
.PHONY: windows windows_rec windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release linux_release_desktop raspi raspi_debug raspi_release anbernic no_audio show_version help .PHONY: windows windows_rec windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release linux_release_desktop raspi raspi_debug raspi_release anbernic no_audio show_version help pack_tool

61
TODO.md Normal file
View File

@@ -0,0 +1,61 @@
# TODO
## Tareas pendientes
- [ ] Revisar todas las variables static de los métodos para ver si se resetean correctamente
## Mejoras arquitecturales (refactoring)
### Eliminar variables static locales y usar patrones profesionales:
**Opción 1: Máquina de Estados**
```cpp
class GameCompletedState {
bool start_celebrations_done = false;
bool end_celebrations_done = false;
float timer = 0.0f;
public:
void reset() {
start_celebrations_done = false;
end_celebrations_done = false;
timer = 0.0f;
}
void update(float deltaTime) {
timer += deltaTime;
// lógica aquí
}
};
```
**Opción 2: Sistema de Eventos/Callbacks**
```cpp
// Al entrar en COMPLETED state
eventSystem.scheduleEvent(6.0f, []{ startCelebrations(); });
eventSystem.scheduleEvent(14.0f, []{ endCelebrations(); });
```
**Opción 3: Flags como miembros privados**
```cpp
class Game {
private:
struct GameOverState {
bool game_over_triggered = false;
bool start_celebrations_triggered = false;
bool end_celebrations_triggered = false;
void reset() {
game_over_triggered = false;
start_celebrations_triggered = false;
end_celebrations_triggered = false;
}
} game_over_state_;
};
```
**Ventajas:**
- Más fáciles de testear
- Más fáciles de debugear
- Más fáciles de entender y mantener
- No tienen "estado oculto"

View File

@@ -20,8 +20,10 @@ DATA|${PREFIX}/config/stages.txt
# Archivos con los datos de la demo # Archivos con los datos de la demo
DEMODATA|${PREFIX}/data/demo/demo1.bin DEMODATA|${PREFIX}/data/demo/demo1.bin
DEMODATA|${PREFIX}/data/demo/demo2.bin DEMODATA|${PREFIX}/data/demo/demo2.bin
DEMODATA|${PREFIX}/data/demo/demo3.bin
# Música # Música
MUSIC|${PREFIX}/data/music/congratulations.ogg
MUSIC|${PREFIX}/data/music/credits.ogg MUSIC|${PREFIX}/data/music/credits.ogg
MUSIC|${PREFIX}/data/music/intro.ogg MUSIC|${PREFIX}/data/music/intro.ogg
MUSIC|${PREFIX}/data/music/playing.ogg MUSIC|${PREFIX}/data/music/playing.ogg
@@ -36,7 +38,8 @@ SOUND|${PREFIX}/data/sound/balloon_pop0.wav
SOUND|${PREFIX}/data/sound/balloon_pop1.wav SOUND|${PREFIX}/data/sound/balloon_pop1.wav
SOUND|${PREFIX}/data/sound/balloon_pop2.wav SOUND|${PREFIX}/data/sound/balloon_pop2.wav
SOUND|${PREFIX}/data/sound/balloon_pop3.wav SOUND|${PREFIX}/data/sound/balloon_pop3.wav
SOUND|${PREFIX}/data/sound/bullet.wav SOUND|${PREFIX}/data/sound/bullet1p.wav
SOUND|${PREFIX}/data/sound/bullet2p.wav
SOUND|${PREFIX}/data/sound/clock.wav SOUND|${PREFIX}/data/sound/clock.wav
SOUND|${PREFIX}/data/sound/coffee_out.wav SOUND|${PREFIX}/data/sound/coffee_out.wav
SOUND|${PREFIX}/data/sound/continue_clock.wav SOUND|${PREFIX}/data/sound/continue_clock.wav
@@ -48,6 +51,7 @@ SOUND|${PREFIX}/data/sound/item_drop.wav
SOUND|${PREFIX}/data/sound/item_pickup.wav SOUND|${PREFIX}/data/sound/item_pickup.wav
SOUND|${PREFIX}/data/sound/jump.wav SOUND|${PREFIX}/data/sound/jump.wav
SOUND|${PREFIX}/data/sound/logo.wav SOUND|${PREFIX}/data/sound/logo.wav
SOUND|${PREFIX}/data/sound/name_input_accept.wav
SOUND|${PREFIX}/data/sound/notify.wav SOUND|${PREFIX}/data/sound/notify.wav
SOUND|${PREFIX}/data/sound/player_collision.wav SOUND|${PREFIX}/data/sound/player_collision.wav
SOUND|${PREFIX}/data/sound/power_ball_explosion.wav SOUND|${PREFIX}/data/sound/power_ball_explosion.wav
@@ -62,6 +66,7 @@ SOUND|${PREFIX}/data/sound/title.wav
SOUND|${PREFIX}/data/sound/voice_aw_aw_aw.wav SOUND|${PREFIX}/data/sound/voice_aw_aw_aw.wav
SOUND|${PREFIX}/data/sound/voice_coffee.wav SOUND|${PREFIX}/data/sound/voice_coffee.wav
SOUND|${PREFIX}/data/sound/voice_credit_thankyou.wav SOUND|${PREFIX}/data/sound/voice_credit_thankyou.wav
SOUND|${PREFIX}/data/sound/voice_game_over.wav
SOUND|${PREFIX}/data/sound/voice_get_ready.wav SOUND|${PREFIX}/data/sound/voice_get_ready.wav
SOUND|${PREFIX}/data/sound/voice_no.wav SOUND|${PREFIX}/data/sound/voice_no.wav
SOUND|${PREFIX}/data/sound/voice_power_up.wav SOUND|${PREFIX}/data/sound/voice_power_up.wav

View File

@@ -2,7 +2,6 @@
# Formato: PARAMETRO VALOR # Formato: PARAMETRO VALOR
# --- GAME --- # --- 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.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.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) game.height 240 # Alto de la resolución nativa del juego (en píxeles)
@@ -10,8 +9,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
game.play_area.rect.y 0 # Posición Y de la zona jugable game.play_area.rect.y 0 # Posición Y de la zona jugable
game.play_area.rect.w 320 # Ancho de la zona jugable game.play_area.rect.w 320 # Ancho de la zona jugable
game.play_area.rect.h 200 # Alto de la zona jugable game.play_area.rect.h 200 # Alto de la zona jugable
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
@@ -40,7 +39,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
# --- TITLE --- # --- TITLE ---
title.press_start_position 180 # Posición Y del texto "Press Start" title.press_start_position 180 # Posición Y del texto "Press Start"
title.title_duration 14000 # Duración de la pantalla de título (milisegundos) title.title_duration 14 # Duración de la pantalla de título (segundos)
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition" title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
title.title_c_c_position 80 # Posición Y del título principal title.title_c_c_position 80 # Posición Y del título principal
title.bg_color 41526F # Color de fondo en la sección titulo title.bg_color 41526F # Color de fondo en la sección titulo

View File

@@ -10,8 +10,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
game.play_area.rect.y 0 # Posición Y de la zona jugable game.play_area.rect.y 0 # Posición Y de la zona jugable
game.play_area.rect.w 320 # Ancho de la zona jugable game.play_area.rect.w 320 # Ancho de la zona jugable
game.play_area.rect.h 216 # Alto de la zona jugable game.play_area.rect.h 216 # Alto de la zona jugable
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
@@ -40,7 +40,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
# --- TITLE --- # --- TITLE ---
title.press_start_position 180 # Posición Y del texto "Press Start" title.press_start_position 180 # Posición Y del texto "Press Start"
title.title_duration 14000 # Duración de la pantalla de título (milisegundos) title.title_duration 14 # Duración de la pantalla de título (segundos)
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition" title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
title.title_c_c_position 80 # Posición Y del título principal title.title_c_c_position 80 # Posición Y del título principal
title.bg_color 41526F # Color de fondo en la sección titulo title.bg_color 41526F # Color de fondo en la sección titulo

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -2,43 +2,85 @@ frame_width=12
frame_height=12 frame_height=12
[animation] [animation]
name=normal_up name=yellow_up
speed=0.0833 speed=20
loop=0 loop=-1
frames=0,1,2 frames=0
[/animation] [/animation]
[animation] [animation]
name=normal_left name=yellow_left
speed=0.0833 speed=20
loop=0 loop=-1
frames=3,4,5,5,4,3 frames=1
[/animation] [/animation]
[animation] [animation]
name=normal_right name=yellow_right
speed=0.0833 speed=20
loop=0 loop=-1
frames=6,7,8,8,7,6 frames=2
[/animation] [/animation]
[animation] [animation]
name=powered_up name=green_up
speed=0.0833 speed=20
loop=0 loop=-1
frames=9,10,11,11,10,9 frames=3
[/animation] [/animation]
[animation] [animation]
name=powered_left name=green_left
speed=0.0833 speed=20
loop=0 loop=-1
frames=12,13,14,14,13,12 frames=4
[/animation] [/animation]
[animation] [animation]
name=powered_right name=green_right
speed=0.0833 speed=20
loop=0 loop=-1
frames=15,16,17,17,26,15 frames=5
[/animation]
[animation]
name=red_up
speed=20
loop=-1
frames=6
[/animation]
[animation]
name=red_left
speed=20
loop=-1
frames=7
[/animation]
[animation]
name=red_right
speed=20
loop=-1
frames=8
[/animation]
[animation]
name=purple_up
speed=20
loop=-1
frames=9
[/animation]
[animation]
name=purple_left
speed=20
loop=-1
frames=10
[/animation]
[animation]
name=purple_right
speed=20
loop=-1
frames=11
[/animation] [/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -109,7 +109,7 @@ frames=38,39,40,41
[animation] [animation]
name=celebration name=celebration
speed=0.167 speed=0.167
loop=-1 loop=0
frames=42,42,42,42,42,42,43,44,45,46,46,46,46,46,46,45,45,45,46,46,46,45,45,45,44,43,42,42,42 frames=42,42,42,42,42,42,43,44,45,46,46,46,46,46,46,45,45,45,46,46,46,45,45,45,44,43,42,42,42
[/animation] [/animation]

View File

@@ -27,6 +27,7 @@
"[GAME_TEXT] 7": "Endavant!", "[GAME_TEXT] 7": "Endavant!",
"[GAME_TEXT] 8": "1.000.000 de punts!", "[GAME_TEXT] 8": "1.000.000 de punts!",
"[GAME_TEXT] THANK_YOU": "Gracies!", "[GAME_TEXT] THANK_YOU": "Gracies!",
"[GAME_TEXT] NEW_RECORD": "Nou record!",
"[HIGHSCORE_TABLE] CAPTION": "Millors puntuacions", "[HIGHSCORE_TABLE] CAPTION": "Millors puntuacions",

View File

@@ -26,6 +26,7 @@
"[GAME_TEXT] 7": "Get Ready!", "[GAME_TEXT] 7": "Get Ready!",
"[GAME_TEXT] 8": "1,000,000 points!", "[GAME_TEXT] 8": "1,000,000 points!",
"[GAME_TEXT] THANK_YOU": "Thank you!", "[GAME_TEXT] THANK_YOU": "Thank you!",
"[GAME_TEXT] NEW_RECORD": "New record!",
"[HIGHSCORE_TABLE] CAPTION": "Best scores", "[HIGHSCORE_TABLE] CAPTION": "Best scores",

View File

@@ -26,6 +26,7 @@
"[GAME_TEXT] 7": "Adelante!", "[GAME_TEXT] 7": "Adelante!",
"[GAME_TEXT] 8": "1.000.000 de puntos!", "[GAME_TEXT] 8": "1.000.000 de puntos!",
"[GAME_TEXT] THANK_YOU": "Gracias!", "[GAME_TEXT] THANK_YOU": "Gracias!",
"[GAME_TEXT] NEW_RECORD": "Nuevo record!",
"[HIGHSCORE_TABLE] CAPTION": "Mejores puntuaciones", "[HIGHSCORE_TABLE] CAPTION": "Mejores puntuaciones",

Binary file not shown.

BIN
data/sound/bullet2p.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,79 +0,0 @@
# Plan de Limpieza Post-Migración DeltaTime
## Estado Actual
✅ Migración básica completada: bullet.cpp, item.cpp, moving_sprite.cpp, game_logo.cpp
✅ Magic numbers convertidos a constantes en game_logo.cpp
## Tareas Pendientes
### 1. Eliminar Contadores Frame-Based
- [ ] Buscar todos los contadores que usen lógica frame-based
- [ ] Convertir a timers basados en deltaTime
- [ ] Eliminar variables como `counter_`, `frame_counter_`, etc.
- [ ] Patrón: `if (counter-- <= 0)``if (timer >= DURATION_MS)`
- [ ] **IMPORTANTE**: Todos los contadores han de ser crecientes, de cero hasta llegar a la constante que define su tope
### 2. Revisar Inicializaciones de Aceleraciones MovingSprite
- [ ] Buscar todas las llamadas a `setAccelX()`, `setAccelY()`
- [ ] Buscar asignaciones directas a `ax_`, `ay_`
- [ ] Convertir de `pixels/frame²` a `pixels/ms²`
- [ ] Factor de conversión: `valor_original / (16.67)²`
### 3. Problema Detectado: Demo - Creación Incorrecta de Globos
- [ ] Investigar cómo se crean los globos en modo demo
- [ ] Verificar si usan timing frame-based obsoleto
- [ ] Corregir la lógica de creación para deltaTime
### 4. Búsqueda de Patrones Problemáticos
- [ ] Buscar `frameFactor` residual
- [ ] Buscar `1000.0f / 60.0f` hardcodeado
- [ ] Buscar `16.67f` hardcodeado
- [ ] Buscar comentarios con "frame" o "60fps"
- [ ] Localizar magic numbers y convertirlos a constantes con nombres descriptivos
- [ ] **IMPORTANTE**: Modificar speed en ficheros .ani - está en frames, hay que pasarlo a milisegundos (multiplicar speed por 1000/60 = 16.67)
- [ ] **SmartSprite**: Revisar inicialización de SmartSprites en el código - cambiar setFinishedCounter() a setFinishedDelay() y convertir valores de frames a milisegundos
### 5. Cambio de Unidades de Tiempo en sections/*
- [ ] Cambiar el cálculo de deltatime en source/sections/* para que devuelva segundos (float) en lugar de milisegundos
- [ ] Cambiar velocidades de pixeles/ms a pixeles/segundos para evitar valores absurdamente pequeños
- [ ] Cambiar aceleraciones de pixeles/ms² a pixeles/segundos²
- [ ] Actualizar todas las constantes de tiempo en archivos de sections
### 6. Archivos Prioritarios a Revisar
- [ ] **player.cpp** - puede tener aceleraciones
- [ ] **balloon.cpp** - contadores de estado
- [ ] **stage.cpp** - timers de nivel
- [ ] **credits.cpp** - efectos de texto
- [ ] **tabe.cpp** - movimiento del protagonista
- [ ] **sections/*.cpp** - transiciones y efectos
### 7. Validación Final
- [ ] Compilar sin warnings
- [ ] Probar gameplay normal
- [ ] Probar modo demo
- [ ] Verificar que no hay saltos de velocidad
- [ ] Confirmar que el timing es consistente en diferentes framerates
## Comandos Útiles de Búsqueda
```bash
# Buscar contadores frame-based
rg "counter.*--|\+\+.*counter|counter.*\+\+|--.*counter"
# Buscar inicializaciones de aceleración
rg "setAccel|\.ax.*=|\.ay.*="
# Buscar hardcoded framerates
rg "60\.0|16\.67|1000\.0.*60"
```
## DECISIÓN IMPORTANTE: TODO EL CÓDIGO USA SEGUNDOS
- **CAMBIO DE PLAN**: Todo el código del juego debe usar deltaTime en segundos (float)
- **NO** debe haber soporte para frames, milisegundos y segundos simultáneamente
- **SOLO SEGUNDOS** en todo el codebase
- Velocidades en `pixels/segundos`, aceleraciones en `pixels/segundos²`
- Todos los contadores deben ser crecientes (0 → constante_tope)
- Eliminar todos los métodos duales (updateS, setSpeedS, etc.) - solo una versión
- Convertir completamente: path_sprite.cpp, writer.cpp, tiled_bg.cpp, etc.
- Documentar las conversiones en comentarios
- Crear constantes para valores repetidos
- Evitar números mágicos

43
development_guidelines.md Normal file
View File

@@ -0,0 +1,43 @@
# Directrices de Desarrollo - Coffee Crisis Arcade Edition
## Directrices Principales Confirmadas
### 1. **Sistema Temporal**
- **TODO migrado de frame based a time based**
- **Delta time en segundos (float)**
- **Unidades de tiempo: SOLO segundos** (no frames, no milisegundos)
### 2. **Contadores y Timers**
- **CRECIENTES**: para sistemas con múltiples eventos temporales (timeline)
- Patrón: `elapsed_time += deltaTime; if (elapsed_time >= EVENT_TIME) { /* acción */ }`
- **DECRECIENTES**: para contadores con diferentes valores de inicialización
- Patrón: `timer -= deltaTime; if (timer <= 0.0f) { /* acción */ timer = DURATION; }`
### 3. **Números Mágicos**
- **Definidos en constantes**
- **Preferencia**: cabecera de la clase
- **Excepción**: si es algo local a un método específico
## Problemas Pendientes de Reparación (game.cpp)
### ❌ PENDIENTES
1. **param.fade.post_duration_ms verification** (líneas 89, 1671)
2. **setRotateSpeed verification** (línea 797)
3. **TOTAL_DEMO_DATA - 200 magic number** (línea 1669)
4. **Comprehensive magic number search** - Buscar 100, 150, 200, 250, 300, 400, 500, 1000
### 4. **Velocidades y Aceleraciones**
- **Velocidades**: pixels/segundo
- **Aceleraciones**: pixels/segundo²
### 5. **Documentación de Conversiones**
- **Comentarios explicativos** en cambios críticos de timing
- Documentar conversiones frame→tiempo en el código
### 6. **Patrón de Constantes**
- Crear constantes para valores repetidos (evitar duplicación)
- Nombres descriptivos para constantes de tiempo
---
**Estado**: Directrices completas confirmadas

View File

@@ -1,136 +0,0 @@
# Plan de Reparación: game.cpp - Limpieza DeltaTime
## Estado Actual
`calculateDeltaTime()` convertido a segundos
✅ Constantes de tiempo convertidas de `_MS` a `_S`
✅ Eliminados hardcoded `1000.0f / 60.0f`
`throwCoffee()` velocidades convertidas a pixels/segundo
✅ Frame-based counter en `updateGameStateShowingGetReadyMessage()` convertido a timer con flag
## Problemas Detectados Pendientes
### ✅ COMPLETADO
1. **Valores hardcoded frame-based (60, 16.67, 1000/60)** - Solo quedan las conversiones correctas
2. **SmartSprite setFinishedDelay() calls** - Correcto (0.0F está bien)
3. **Velocidades y aceleraciones** - Todas convertidas correctamente
4. **Timer variables** - Todas usan deltaTime correctamente
### ❌ PENDIENTES DE REPARAR
#### ✅ **SOLUCIONADO: Balas no se mueven**
- **Síntoma**: Las balas se crean pero no avanzan en pantalla
- **Causa encontrada**: Velocidades en `bullet.h` seguían en pixels/ms pero `calculateDeltaTime()` ahora devuelve segundos
- **Solución aplicada**:
- `VEL_Y = -0.18F``VEL_Y = -180.0F` (pixels/segundo)
- `VEL_X_LEFT = -0.12F``VEL_X_LEFT = -120.0F` (pixels/segundo)
- `VEL_X_RIGHT = 0.12F``VEL_X_RIGHT = 120.0F` (pixels/segundo)
- Actualizado comentario en `bullet.cpp`: "pixels/ms" → "pixels/segundo"
#### ✅ **SOLUCIONADO: Contadores frame-based (++ o -- operations)**
- **Problema**: `demo_.counter++` en líneas 1665, 1691
- **Ubicación**: `updateDemo()` y `updateRecording()`
- **Contexto**: `demo_.counter` indexa un vector con datos de teclas por frame (ej: 2000 frames = 2000 entradas)
- **Solución aplicada**: Acumulador de tiempo que se incrementa cada 16.67ms (1/60 segundos)
- **Implementación**:
```cpp
// updateDemo()
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
}
// updateRecording()
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
}
```
#### 6. **Fade duration values (milisegundos vs segundos)**
- **Problema 1**: `fade_out_->setPostDuration(500);` línea 234
- **Problema 2**: `fade_out_->setPostDuration(param.fade.post_duration_ms);` líneas 89, 1671
- **Solución**: Verificar si `param.fade.post_duration_ms` debe ser convertido a segundos
### NUEVOS PROBLEMAS A AÑADIR
#### 7. **Verificar param.fade estructura**
- Revisar si `param.fade.post_duration_ms` debe ser convertido a segundos
- Verificar todas las propiedades de `param.fade` relacionadas con tiempo
#### 8. **Revisar constantes TOTAL_DEMO_DATA**
- **Problema**: `TOTAL_DEMO_DATA - 200` en línea 1669
- **Detalle**: 200 frames hardcoded, debería ser tiempo en segundos
#### 9. **Buscar más magic numbers relacionados con tiempo**
- Buscar números como 100, 150, 200, 500 que puedan ser frames
- Verificar contexto de cada uno
#### 10. **Revisar setRotateSpeed() values**
- **Problema**: `setRotateSpeed(10)` línea 797
- **Verificar**: Si debe ser convertido de rotaciones/frame a rotaciones/segundo
#### ✅ **VERIFICADO: SDL_Delay() calls**
- **Problema**: `SDL_Delay(param.game.hit_stop_ms);` línea 847
- **Ubicación**: `handlePlayerCollision()`
- **Contexto**: Pausa el juego al recibir daño (hitStop effect)
- **Resultado**: `param.game.hit_stop_ms` está configurado explícitamente en milisegundos en archivos .txt
- **Conclusión**: Correcto, `SDL_Delay()` espera milisegundos y `hit_stop_ms` ya está en milisegundos
#### ✅ **VERIFICADO: Cooldown de disparos en frames**
- **Problema**: `handleFireInput()` líneas 1312-1314
- **Detalle**: `POWERUP_COOLDOWN = 5`, `AUTOFIRE_COOLDOWN = 10`, `NORMAL_COOLDOWN = 7`
- **Contexto**: Son frames de cooldown, se pasan a `player->startFiringSystem(cant_fire_counter)`
- **Resultado**: `startFiringSystem()` convierte internamente frames a segundos con: `fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f;`
- **Conclusión**: No necesita cambios, la conversión ya está implementada correctamente
#### 12. **Revisar paths y PathSprite durations**
- **Problema**: En `initPaths()` líneas 1024, 1025, 1036, 1037, 1049, 1050, 1062, 1063
- **Detalle**: `createPath(..., 80, ...), 20);` - Los números 80 y 20 son frames
- **Ejemplo**: `paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 20);`
- **Investigar**: Si createPath espera segundos o milisegundos
- **Conversión**: 80 frames = 80/60 = 1.33s, 20 frames = 20/60 = 0.33s
- **Verificar**: Documentación de createPath() y PathSprite para unidades correctas
## Herramientas de Búsqueda Útiles
```bash
# Buscar magic numbers de tiempo
rg "\b(100|150|200|250|300|400|500|1000)\b" --context=2
# Buscar más frame-based operations
rg "setRotateSpeed|SDL_Delay|createPath.*[0-9]+"
# Buscar estructuras param que mencionen tiempo
rg "param\..*\.(duration|time|delay|ms|frames)"
# Buscar comentarios con "frame" or "60fps"
rg "(frame|60fps|milliseconds)" --ignore-case
```
## Prioridad de Reparación
### ✅ COMPLETADAS
1.**CRÍTICA**: Las balas no se desplazan - **SOLUCIONADO**: Velocidades convertidas de pixels/ms a pixels/segundo
2.**ALTA**: demo_.counter system - **SOLUCIONADO**: Implementados acumuladores de tiempo
3.**ALTA**: Fade durations hardcoded - **SOLUCIONADO**: Convertidos a segundos
4.**ALTA**: initPaths() frame values - **SOLUCIONADO**: Convertidos a segundos
5.**MEDIA**: Cooldown de disparos - **VERIFICADO**: Ya convierte internamente frames a segundos
6.**BAJA**: SDL_Delay investigation - **VERIFICADO**: Correcto, usa milisegundos
### ❌ PENDIENTES
7. **MEDIA**: param.fade.post_duration_ms verification (líneas 89, 1671)
8. **MEDIA**: TOTAL_DEMO_DATA - 200 magic number (línea 1669) - Nota: No necesita cambios, lógica correcta
9. **BAJA**: setRotateSpeed verification (línea 797)
10. **BAJA**: Comprehensive magic number search
## Notas Importantes
- **TODOS los contadores deben ser crecientes** (0 → constante_tope)
- **SOLO SEGUNDOS** en todo el codebase, NO frames ni milisegundos simultáneos
- **Documentar conversiones** con comentarios explicativos
- **Crear constantes** para valores repetidos
- **Evitar números mágicos** sin contexto

View File

@@ -55,7 +55,7 @@ class AnimatedSprite : public MovingSprite {
~AnimatedSprite() override = default; ~AnimatedSprite() override = default;
// --- Métodos principales --- // --- Métodos principales ---
void update(float deltaTime); // Actualiza la animación (time-based) void update(float deltaTime) override; // Actualiza la animación (time-based)
// --- Control de animaciones --- // --- Control de animaciones ---
void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre

View File

@@ -2,8 +2,10 @@
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn #include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
#include <algorithm> // Para std::sort
#include <cstddef> // Para size_t #include <cstddef> // Para size_t
#include <exception> // Para exception #include <exception> // Para exception
#include <filesystem> // Para std::filesystem
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream #include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
#include <sstream> // Para basic_istringstream #include <sstream> // Para basic_istringstream
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
@@ -205,25 +207,28 @@ auto Asset::check() const -> bool {
} }
// Comprueba que existe un fichero // Comprueba que existe un fichero
auto Asset::checkFile(const std::string &path) -> bool { auto Asset::checkFile(const std::string &path) const -> bool {
// Intentar primero con ResourceHelper // Construir ruta del pack usando executable_path_
auto data = ResourceHelper::loadFile(path); std::string pack_path = executable_path_ + "resources.pack";
bool success = !data.empty(); bool pack_exists = std::filesystem::exists(pack_path);
// Si no se encuentra en el pack, intentar con filesystem directo if (pack_exists) {
if (!success) { // MODO PACK: Usar ResourceHelper (igual que la carga real)
auto data = ResourceHelper::loadFile(path);
return !data.empty();
} else {
// MODO FILESYSTEM: Verificación directa (modo desarrollo)
std::ifstream file(path); std::ifstream file(path);
success = file.good(); bool success = file.good();
file.close(); file.close();
}
if (!success) { if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Checking file: %s [ ERROR ]", "Error: Could not open file: %s", path.c_str());
getFileName(path).c_str());
} }
return success; return success;
}
} }
// Parsea string a Type // Parsea string a Type
@@ -295,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; return list;
} }

View File

@@ -57,7 +57,7 @@ class Asset {
std::string executable_path_; // Ruta del ejecutable std::string executable_path_; // Ruta del ejecutable
// --- Métodos internos --- // --- Métodos internos ---
[[nodiscard]] static auto checkFile(const std::string &path) -> bool; // Verifica si un archivo existe [[nodiscard]] auto checkFile(const std::string &path) const -> bool; // Verifica si un archivo existe
[[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo [[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo
[[nodiscard]] static auto parseAssetType(const std::string &type_str) -> Type; // Convierte string a tipo [[nodiscard]] static auto parseAssetType(const std::string &type_str) -> Type; // Convierte string a tipo
void addToMap(const std::string &file_path, Type type, bool required, bool absolute); // Añade archivo al mapa void addToMap(const std::string &file_path, Type type, bool required, bool absolute); // Añade archivo al mapa

View File

@@ -4,9 +4,7 @@
#include <algorithm> // Para clamp #include <algorithm> // Para clamp
#ifndef NO_AUDIO
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM... #include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
#endif
#include "options.h" // Para AudioOptions, audio, MusicOptions #include "options.h" // Para AudioOptions, audio, MusicOptions
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
@@ -27,9 +25,7 @@ Audio::Audio() { initSDLAudio(); }
// Destructor // Destructor
Audio::~Audio() { Audio::~Audio() {
#ifndef NO_AUDIO
JA_Quit(); JA_Quit();
#endif
} }
// Método principal // Método principal
@@ -43,9 +39,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
music_.loop = (loop != 0); music_.loop = (loop != 0);
if (music_enabled_ && music_.state != MusicState::PLAYING) { if (music_enabled_ && music_.state != MusicState::PLAYING) {
#ifndef NO_AUDIO
JA_PlayMusic(Resource::get()->getMusic(name), loop); JA_PlayMusic(Resource::get()->getMusic(name), loop);
#endif
music_.state = MusicState::PLAYING; music_.state = MusicState::PLAYING;
} }
} }
@@ -53,9 +47,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
// Pausa la música // Pausa la música
void Audio::pauseMusic() { void Audio::pauseMusic() {
if (music_enabled_ && music_.state == MusicState::PLAYING) { if (music_enabled_ && music_.state == MusicState::PLAYING) {
#ifndef NO_AUDIO
JA_PauseMusic(); JA_PauseMusic();
#endif
music_.state = MusicState::PAUSED; music_.state = MusicState::PAUSED;
} }
} }
@@ -63,9 +55,7 @@ void Audio::pauseMusic() {
// Continua la música pausada // Continua la música pausada
void Audio::resumeMusic() { void Audio::resumeMusic() {
if (music_enabled_ && music_.state == MusicState::PAUSED) { if (music_enabled_ && music_.state == MusicState::PAUSED) {
#ifndef NO_AUDIO
JA_ResumeMusic(); JA_ResumeMusic();
#endif
music_.state = MusicState::PLAYING; music_.state = MusicState::PLAYING;
} }
} }
@@ -73,9 +63,7 @@ void Audio::resumeMusic() {
// Detiene la música // Detiene la música
void Audio::stopMusic() { void Audio::stopMusic() {
if (music_enabled_) { if (music_enabled_) {
#ifndef NO_AUDIO
JA_StopMusic(); JA_StopMusic();
#endif
music_.state = MusicState::STOPPED; music_.state = MusicState::STOPPED;
} }
} }
@@ -83,27 +71,37 @@ void Audio::stopMusic() {
// Reproduce un sonido // Reproduce un sonido
void Audio::playSound(const std::string &name, Group group) const { void Audio::playSound(const std::string &name, Group group) const {
if (sound_enabled_) { if (sound_enabled_) {
#ifndef NO_AUDIO
JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group)); JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group));
#endif
} }
} }
// Detiene todos los sonidos // Detiene todos los sonidos
void Audio::stopAllSounds() const { void Audio::stopAllSounds() const {
if (sound_enabled_) { if (sound_enabled_) {
#ifndef NO_AUDIO
JA_StopChannel(-1); JA_StopChannel(-1);
#endif
} }
} }
// Realiza un fundido de salida de la música // Realiza un fundido de salida de la música
void Audio::fadeOutMusic(int milliseconds) const { void Audio::fadeOutMusic(int milliseconds) const {
if (music_enabled_ && music_.state == MusicState::PLAYING) { if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
#ifndef NO_AUDIO
JA_FadeOutMusic(milliseconds); JA_FadeOutMusic(milliseconds);
#endif }
}
// Consulta directamente el estado real de la música en jailaudio
auto Audio::getRealMusicState() const -> MusicState {
JA_Music_state ja_state = JA_GetMusicState();
switch (ja_state) {
case JA_MUSIC_PLAYING:
return MusicState::PLAYING;
case JA_MUSIC_PAUSED:
return MusicState::PAUSED;
case JA_MUSIC_STOPPED:
case JA_MUSIC_INVALID:
case JA_MUSIC_DISABLED:
default:
return MusicState::STOPPED;
} }
} }
@@ -111,10 +109,8 @@ void Audio::fadeOutMusic(int milliseconds) const {
void Audio::setSoundVolume(int sound_volume, Group group) const { void Audio::setSoundVolume(int sound_volume, Group group) const {
if (sound_enabled_) { if (sound_enabled_) {
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME); 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); const float CONVERTED_VOLUME = (sound_volume / 100.0F) * (Options::audio.volume / 100.0F);
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group)); JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
#endif
} }
} }
@@ -122,10 +118,8 @@ void Audio::setSoundVolume(int sound_volume, Group group) const {
void Audio::setMusicVolume(int music_volume) const { void Audio::setMusicVolume(int music_volume) const {
if (music_enabled_) { if (music_enabled_) {
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME); 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); const float CONVERTED_VOLUME = (music_volume / 100.0F) * (Options::audio.volume / 100.0F);
JA_SetMusicVolume(CONVERTED_VOLUME); JA_SetMusicVolume(CONVERTED_VOLUME);
#endif
} }
} }
@@ -144,7 +138,6 @@ void Audio::enable(bool value) {
// Inicializa SDL Audio // Inicializa SDL Audio
void Audio::initSDLAudio() { void Audio::initSDLAudio() {
#ifndef NO_AUDIO
if (!SDL_Init(SDL_INIT_AUDIO)) { if (!SDL_Init(SDL_INIT_AUDIO)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
} else { } else {
@@ -153,7 +146,4 @@ void Audio::initSDLAudio() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully");
} }
#else
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system disabled");
#endif
} }

View File

@@ -13,6 +13,12 @@ class Audio {
INTERFACE = 1 // Sonidos de la interfaz INTERFACE = 1 // Sonidos de la interfaz
}; };
enum class MusicState {
PLAYING, // Reproduciendo música
PAUSED, // Música pausada
STOPPED, // Música detenida
};
// --- Constantes --- // --- Constantes ---
static constexpr int MAX_VOLUME = 100; // Volumen máximo static constexpr int MAX_VOLUME = 100; // Volumen máximo
static constexpr int MIN_VOLUME = 0; // Volumen mínimo static constexpr int MIN_VOLUME = 0; // Volumen mínimo
@@ -60,14 +66,15 @@ class Audio {
void setSoundVolume(int volume, Group group = Group::ALL) const; // Ajustar volumen de efectos void setSoundVolume(int volume, Group group = Group::ALL) const; // Ajustar volumen de efectos
void setMusicVolume(int volume) const; // Ajustar volumen de música void setMusicVolume(int volume) const; // Ajustar volumen de música
private: // --- Getters para debug ---
// --- Enums privados --- bool isEnabled() const { return enabled_; }
enum class MusicState { bool isSoundEnabled() const { return sound_enabled_; }
PLAYING, // Reproduciendo música bool isMusicEnabled() const { return music_enabled_; }
PAUSED, // Música pausada MusicState getMusicState() const { return music_.state; }
STOPPED, // Música detenida MusicState getRealMusicState() const; // Consulta directamente a jailaudio
}; const std::string& getCurrentMusicName() const { return music_.name; }
private:
// --- Estructuras privadas --- // --- Estructuras privadas ---
struct Music { struct Music {
MusicState state; // Estado actual de la música (reproduciendo, detenido, en pausa) MusicState state; // Estado actual de la música (reproduciendo, detenido, en pausa)

View File

@@ -13,6 +13,7 @@
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para funciones de easing
// Constructor // Constructor
Background::Background(float total_progress_to_complete) Background::Background(float total_progress_to_complete)
@@ -29,6 +30,7 @@ Background::Background(float total_progress_to_complete)
total_progress_to_complete_(total_progress_to_complete), total_progress_to_complete_(total_progress_to_complete),
progress_per_stage_(total_progress_to_complete_ / STAGES), progress_per_stage_(total_progress_to_complete_ / STAGES),
sun_completion_progress_(total_progress_to_complete_ * SUN_COMPLETION_FACTOR), sun_completion_progress_(total_progress_to_complete_ * SUN_COMPLETION_FACTOR),
minimum_completed_progress_(total_progress_to_complete_ * MINIMUM_COMPLETED_PROGRESS_PERCENTAGE),
rect_(SDL_FRect{0, 0, static_cast<float>(gradients_texture_->getWidth() / 2), static_cast<float>(gradients_texture_->getHeight() / 2)}), rect_(SDL_FRect{0, 0, static_cast<float>(gradients_texture_->getWidth() / 2), static_cast<float>(gradients_texture_->getHeight() / 2)}),
src_rect_({.x = 0, .y = 0, .w = 320, .h = 240}), src_rect_({.x = 0, .y = 0, .w = 320, .h = 240}),
@@ -93,20 +95,21 @@ void Background::initializeSprites() {
// Configura las propiedades iniciales de los sprites // Configura las propiedades iniciales de los sprites
void Background::initializeSpriteProperties() { void Background::initializeSpriteProperties() {
constexpr float TOP_CLOUDS_SPEED = 0.1F; // Velocidades iniciales que coinciden con updateCloudsSpeed() cuando progress=0
constexpr float BOTTOM_CLOUDS_SPEED = 0.05F; constexpr float INITIAL_TOP_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (coincide con CLOUDS_INITIAL_SPEED)
constexpr float INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S = 0.05F * 60.0F / 2.0F; // 1.5 píxeles/segundo (mitad de velocidad)
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight()); top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_a_->setVelX(-TOP_CLOUDS_SPEED); top_clouds_sprite_a_->setVelX(-INITIAL_TOP_CLOUDS_SPEED_PX_PER_S);
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight()); top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_b_->setVelX(-TOP_CLOUDS_SPEED); top_clouds_sprite_b_->setVelX(-INITIAL_TOP_CLOUDS_SPEED_PX_PER_S);
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight()); bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_a_->setVelX(-BOTTOM_CLOUDS_SPEED); bottom_clouds_sprite_a_->setVelX(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S);
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight()); bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_b_->setVelX(-BOTTOM_CLOUDS_SPEED); bottom_clouds_sprite_b_->setVelX(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S);
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight()); buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
grass_sprite_->setY(base_ - grass_sprite_->getHeight()); grass_sprite_->setY(base_ - grass_sprite_->getHeight());
@@ -129,7 +132,7 @@ void Background::initializeTextures() {
void Background::update(float delta_time) { void Background::update(float delta_time) {
// Actualiza la progresión y calcula transiciones // Actualiza la progresión y calcula transiciones
if (!manual_mode_) { if (!manual_mode_) {
updateProgression(); updateProgression(delta_time);
} }
// Actualiza el valor de alpha // Actualiza el valor de alpha
@@ -183,6 +186,12 @@ void Background::setProgress(float absolute_progress) {
// Cambia el estado del fondo // Cambia el estado del fondo
void Background::setState(State new_state) { void Background::setState(State new_state) {
// Si entra en estado completado, inicializar variables de transición
if (new_state == State::COMPLETED && state_ != State::COMPLETED) {
completion_initial_progress_ = progress_;
completion_transition_timer_ = 0.0f;
}
state_ = new_state; state_ = new_state;
} }
@@ -197,6 +206,10 @@ void Background::reset() {
sun_index_ = 0; sun_index_ = 0;
moon_index_ = 0; moon_index_ = 0;
// Resetear variables de transición de completado
completion_transition_timer_ = 0.0f;
completion_initial_progress_ = 0.0f;
// Notifica el cambio si hay callback // Notifica el cambio si hay callback
if (progress_callback_ && progress_ != old_progress) { if (progress_callback_ && progress_ != old_progress) {
progress_callback_(progress_); progress_callback_(progress_);
@@ -253,13 +266,24 @@ void Background::setMoonProgression(float progress) {
} }
// Actualiza la progresión y calcula las transiciones // Actualiza la progresión y calcula las transiciones
void Background::updateProgression() { void Background::updateProgression(float delta_time) {
// Si el juego está completado, reduce la progresión gradualmente // Si el juego está completado, hacer transición suave con easing
if (state_ == State::COMPLETED) { if (state_ == State::COMPLETED) {
if (progress_ > MINIMUM_COMPLETED_PROGRESS) { completion_transition_timer_ += delta_time;
progress_ -= COMPLETED_REDUCTION_RATE;
// Calcular progreso normalizado de la transición (0.0 a 1.0)
float t = std::min(completion_transition_timer_ / COMPLETION_TRANSITION_DURATION_S, 1.0f);
if (t < 1.0f) {
// Usar easeOutCubic para transición suave (rápido al inicio, lento al final)
float eased_t = easeOutCubic(static_cast<double>(t));
// Interpolación desde progreso inicial hasta mínimo
float progress_range = completion_initial_progress_ - minimum_completed_progress_;
progress_ = completion_initial_progress_ - (progress_range * eased_t);
} else { } else {
progress_ = MINIMUM_COMPLETED_PROGRESS; // Transición completada, fijar al valor mínimo
progress_ = minimum_completed_progress_;
} }
} }
@@ -284,18 +308,19 @@ void Background::updateProgression() {
// Actualiza la velocidad de las nubes según el estado y progresión // Actualiza la velocidad de las nubes según el estado y progresión
void Background::updateCloudsSpeed() { void Background::updateCloudsSpeed() {
// Cálculo de velocidad según progreso // Cálculo de velocidad según progreso (convertido de frame-based a time-based)
constexpr float CLOUDS_INITIAL_SPEED = 0.05F; constexpr float CLOUDS_INITIAL_SPEED_PX_PER_S = 0.05F * 60.0F; // 3.0 píxeles/segundo (era 0.05 px/frame @ 60fps)
constexpr float CLOUDS_FINAL_SPEED = 2.00F - CLOUDS_INITIAL_SPEED; constexpr float CLOUDS_TOTAL_SPEED_PX_PER_S = 2.00F * 60.0F; // 120.0 píxeles/segundo (era 2.00 px/frame @ 60fps)
constexpr float CLOUDS_FINAL_SPEED_RANGE_PX_PER_S = CLOUDS_TOTAL_SPEED_PX_PER_S - CLOUDS_INITIAL_SPEED_PX_PER_S; // 117.0 píxeles/segundo
// Velocidad base según progreso (de -0.05 a -2.00) // Velocidad base según progreso (de -3.0 a -120.0 píxeles/segundo, igual que la versión original)
float base_clouds_speed = (-CLOUDS_INITIAL_SPEED) + float base_clouds_speed = (-CLOUDS_INITIAL_SPEED_PX_PER_S) +
(-CLOUDS_FINAL_SPEED * (progress_ / total_progress_to_complete_)); (-CLOUDS_FINAL_SPEED_RANGE_PX_PER_S * (progress_ / total_progress_to_complete_));
// En estado completado, las nubes se ralentizan gradualmente // En estado completado, las nubes se ralentizan gradualmente
if (state_ == State::COMPLETED) { if (state_ == State::COMPLETED) {
float completion_factor = (progress_ - MINIMUM_COMPLETED_PROGRESS) / float completion_factor = (progress_ - minimum_completed_progress_) /
(total_progress_to_complete_ - MINIMUM_COMPLETED_PROGRESS); (total_progress_to_complete_ - minimum_completed_progress_);
completion_factor = std::max(0.1F, completion_factor); completion_factor = std::max(0.1F, completion_factor);
base_clouds_speed *= completion_factor; base_clouds_speed *= completion_factor;
} }

View File

@@ -61,9 +61,9 @@ class Background {
private: private:
// --- Constantes --- // --- Constantes ---
static constexpr size_t STAGES = 4; // Número de etapas static constexpr size_t STAGES = 4; // Número de etapas
static constexpr float COMPLETED_REDUCTION_RATE = 25.0F; // Tasa de reducción completada static constexpr float MINIMUM_COMPLETED_PROGRESS_PERCENTAGE = 0.05F; // Porcentaje mínimo completado (10%)
static constexpr float MINIMUM_COMPLETED_PROGRESS = 200.0F; // Progreso mínimo completado
static constexpr float SUN_COMPLETION_FACTOR = 0.5F; // Factor de completado del sol static constexpr float SUN_COMPLETION_FACTOR = 0.5F; // Factor de completado del sol
static constexpr float COMPLETION_TRANSITION_DURATION_S = 3.0F; // Duración de la transición de completado en segundos
// --- Objetos y punteros --- // --- Objetos y punteros ---
SDL_Renderer *renderer_; // Renderizador de la ventana SDL_Renderer *renderer_; // Renderizador de la ventana
@@ -90,6 +90,7 @@ class Background {
const float total_progress_to_complete_; // Progreso total para completar const float total_progress_to_complete_; // Progreso total para completar
const float progress_per_stage_; // Progreso por etapa const float progress_per_stage_; // Progreso por etapa
const float sun_completion_progress_; // Progreso de completado del sol const float sun_completion_progress_; // Progreso de completado del sol
const float minimum_completed_progress_; // Progreso mínimo calculado dinámicamente
ProgressCallback progress_callback_; // Callback para notificar cambios de progreso ProgressCallback progress_callback_; // Callback para notificar cambios de progreso
// --- Variables de estado --- // --- Variables de estado ---
@@ -117,13 +118,17 @@ class Background {
Uint8 alpha_ = 0; // Transparencia entre fases Uint8 alpha_ = 0; // Transparencia entre fases
bool manual_mode_ = false; // Si está en modo manual bool manual_mode_ = false; // Si está en modo manual
// --- Variables para transición suave de completado ---
float completion_transition_timer_ = 0.0f; // Timer para la transición de completado
float completion_initial_progress_ = 0.0f; // Progreso inicial al entrar en estado completado
// --- Métodos internos --- // --- Métodos internos ---
void initializePaths(); // Inicializa las rutas del sol y la luna void initializePaths(); // Inicializa las rutas del sol y la luna
void initializeRects(); // Inicializa los rectángulos de gradientes y nubes void initializeRects(); // Inicializa los rectángulos de gradientes y nubes
void initializeSprites(); // Crea los sprites void initializeSprites(); // Crea los sprites
void initializeSpriteProperties(); // Configura las propiedades iniciales de los sprites void initializeSpriteProperties(); // Configura las propiedades iniciales de los sprites
void initializeTextures(); // Inicializa las texturas de renderizado void initializeTextures(); // Inicializa las texturas de renderizado
void updateProgression(); // Actualiza la progresión y calcula transiciones void updateProgression(float delta_time); // Actualiza la progresión y calcula transiciones
void updateCloudsSpeed(); // Actualiza la velocidad de las nubes según el estado void updateCloudsSpeed(); // Actualiza la velocidad de las nubes según el estado
void renderGradient(); // Dibuja el gradiente de fondo void renderGradient(); // Dibuja el gradiente de fondo
void renderTopClouds(); // Dibuja las nubes superiores void renderTopClouds(); // Dibuja las nubes superiores

View File

@@ -122,6 +122,8 @@ class Balloon {
// --- Setters --- // --- Setters ---
void setVelY(float vel_y) { vy_ = vel_y; } 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 setGameTempo(float tempo) { game_tempo_ = tempo; }
void setInvulnerable(bool value) { invulnerable_ = value; } void setInvulnerable(bool value) { invulnerable_ = value; }
void setBouncingSound(bool value) { sound_.bouncing_enabled = value; } void setBouncingSound(bool value) { sound_.bouncing_enabled = value; }

View File

@@ -16,7 +16,7 @@
#include "utils.h" #include "utils.h"
// Constructor // Constructor
BalloonManager::BalloonManager(IStageInfo *stage_info) BalloonManager::BalloonManager(IStageInfo* stage_info)
: explosions_(std::make_unique<Explosions>()), : explosions_(std::make_unique<Explosions>()),
balloon_formations_(std::make_unique<BalloonFormations>()), balloon_formations_(std::make_unique<BalloonFormations>()),
stage_info_(stage_info) { init(); } stage_info_(stage_info) { init(); }
@@ -64,7 +64,7 @@ void BalloonManager::init() {
// Actualiza (time-based) // Actualiza (time-based)
void BalloonManager::update(float deltaTime) { void BalloonManager::update(float deltaTime) {
for (const auto &balloon : balloons_) { for (const auto& balloon : balloons_) {
balloon->update(deltaTime); balloon->update(deltaTime);
} }
updateBalloonDeployCounter(deltaTime); updateBalloonDeployCounter(deltaTime);
@@ -73,7 +73,7 @@ void BalloonManager::update(float deltaTime) {
// Renderiza los objetos // Renderiza los objetos
void BalloonManager::render() { void BalloonManager::render() {
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->render(); balloon->render();
} }
explosions_->render(); explosions_->render();
@@ -158,7 +158,7 @@ void BalloonManager::deployFormation(int formation_id, float y) {
// Vacia del vector de globos los globos que ya no sirven // Vacia del vector de globos los globos que ya no sirven
void BalloonManager::freeBalloons() { void BalloonManager::freeBalloons() {
auto result = std::ranges::remove_if(balloons_, [](const auto &balloon) { return !balloon->isEnabled(); }); auto result = std::ranges::remove_if(balloons_, [](const auto& balloon) { return !balloon->isEnabled(); });
balloons_.erase(result.begin(), balloons_.end()); balloons_.erase(result.begin(), balloons_.end());
} }
@@ -173,7 +173,7 @@ auto BalloonManager::canPowerBallBeCreated() -> bool { return (!power_ball_enabl
// Calcula el poder actual de los globos en pantalla // Calcula el poder actual de los globos en pantalla
auto BalloonManager::calculateScreenPower() -> int { auto BalloonManager::calculateScreenPower() -> int {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); }); return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto& balloon) { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
} }
// Crea un globo nuevo en el vector de globos // Crea un globo nuevo en el vector de globos
@@ -194,7 +194,7 @@ auto BalloonManager::createBalloon(Balloon::Config config) -> std::shared_ptr<Ba
} }
// Crea un globo a partir de otro globo // Crea un globo a partir de otro globo
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction) { void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& balloon, const std::string& direction) {
if (can_deploy_balloons_) { if (can_deploy_balloons_) {
// Calcula parametros // Calcula parametros
const int PARENT_HEIGHT = balloon->getHeight(); const int PARENT_HEIGHT = balloon->getHeight();
@@ -208,6 +208,7 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
Balloon::Config config = { Balloon::Config config = {
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X), .x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2), .y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
.type = balloon->getType(),
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1), .size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE, .vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
.game_tempo = balloon_speed_, .game_tempo = balloon_speed_,
@@ -216,9 +217,22 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
// Crea el globo // Crea el globo
auto b = createBalloon(config); auto b = createBalloon(config);
// Establece parametros (deltaTime en segundos - velocidades en pixels/segundo) // Establece parametros
constexpr float VEL_Y_BALLOON_PER_S = -150.0F; // -2.50 pixels/frame convertido a pixels/segundo (-2.50 * 60 = -150) constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_S : Balloon::VELX_NEGATIVE * 2.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 // Herencia de estados
if (balloon->isStopped()) { b->stop(); } if (balloon->isStopped()) { b->stop(); }
@@ -266,13 +280,13 @@ void BalloonManager::createPowerBall() {
// Establece la velocidad de los globos // Establece la velocidad de los globos
void BalloonManager::setBalloonSpeed(float speed) { void BalloonManager::setBalloonSpeed(float speed) {
balloon_speed_ = speed; balloon_speed_ = speed;
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->setGameTempo(speed); balloon->setGameTempo(speed);
} }
} }
// Explosiona un globo. Lo destruye y crea otros dos si es el caso // Explosiona un globo. Lo destruye y crea otros dos si es el caso
auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int { auto BalloonManager::popBalloon(const std::shared_ptr<Balloon>& balloon) -> int {
stage_info_->addPower(1); stage_info_->addPower(1);
int score = 0; int score = 0;
@@ -297,7 +311,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
} }
// Explosiona un globo. Lo destruye = no crea otros globos // Explosiona un globo. Lo destruye = no crea otros globos
auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int { auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon>& balloon) -> int {
int score = 0; int score = 0;
// Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos // Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos
@@ -332,12 +346,12 @@ auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int {
// Destruye todos los globos // Destruye todos los globos
auto BalloonManager::destroyAllBalloons() -> int { auto BalloonManager::destroyAllBalloons() -> int {
int score = 0; int score = 0;
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
score += destroyBalloon(balloon); score += destroyBalloon(balloon);
} }
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY; balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY;
Screen::get()->flash(Colors::FLASH, 3); Screen::get()->flash(Colors::FLASH, 0.05F);
Screen::get()->shake(); Screen::get()->shake();
return score; return score;
@@ -345,7 +359,7 @@ auto BalloonManager::destroyAllBalloons() -> int {
// Detiene todos los globos // Detiene todos los globos
void BalloonManager::stopAllBalloons() { void BalloonManager::stopAllBalloons() {
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
if (!balloon->isBeingCreated()) { if (!balloon->isBeingCreated()) {
balloon->stop(); balloon->stop();
} }
@@ -354,7 +368,7 @@ void BalloonManager::stopAllBalloons() {
// Pone en marcha todos los globos // Pone en marcha todos los globos
void BalloonManager::startAllBalloons() { void BalloonManager::startAllBalloons() {
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
if (!balloon->isBeingCreated()) { if (!balloon->isBeingCreated()) {
balloon->start(); balloon->start();
} }
@@ -363,7 +377,7 @@ void BalloonManager::startAllBalloons() {
// Cambia el color de todos los globos // Cambia el color de todos los globos
void BalloonManager::reverseColorsToAllBalloons() { void BalloonManager::reverseColorsToAllBalloons() {
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
if (balloon->isStopped()) { if (balloon->isStopped()) {
balloon->useReverseColor(); balloon->useReverseColor();
} }
@@ -372,7 +386,7 @@ void BalloonManager::reverseColorsToAllBalloons() {
// Cambia el color de todos los globos // Cambia el color de todos los globos
void BalloonManager::normalColorsToAllBalloons() { void BalloonManager::normalColorsToAllBalloons() {
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->useNormalColor(); balloon->useNormalColor();
} }
} }
@@ -384,13 +398,13 @@ void BalloonManager::createTwoBigBalloons() {
// Obtiene el nivel de ameza actual generado por los globos // Obtiene el nivel de ameza actual generado por los globos
auto BalloonManager::getMenace() -> int { auto BalloonManager::getMenace() -> int {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); }); return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto& balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
} }
// Establece el sonido de los globos // Establece el sonido de los globos
void BalloonManager::setSounds(bool value) { void BalloonManager::setSounds(bool value) {
sound_enabled_ = value; sound_enabled_ = value;
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->setSound(value); balloon->setSound(value);
} }
} }
@@ -398,14 +412,14 @@ void BalloonManager::setSounds(bool value) {
// Activa o desactiva los sonidos de rebote los globos // Activa o desactiva los sonidos de rebote los globos
void BalloonManager::setBouncingSounds(bool value) { void BalloonManager::setBouncingSounds(bool value) {
bouncing_sound_enabled_ = value; bouncing_sound_enabled_ = value;
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->setBouncingSound(value); balloon->setBouncingSound(value);
} }
} }
// Activa o desactiva los sonidos de los globos al explotar // Activa o desactiva los sonidos de los globos al explotar
void BalloonManager::setPoppingSounds(bool value) { void BalloonManager::setPoppingSounds(bool value) {
poping_sound_enabled_ = value; poping_sound_enabled_ = value;
for (auto &balloon : balloons_) { for (auto& balloon : balloons_) {
balloon->setPoppingSound(value); balloon->setPoppingSound(value);
} }
} }

View File

@@ -4,46 +4,64 @@
#include <string> // Para char_traits, basic_string, operator+, string #include <string> // Para char_traits, basic_string, operator+, string
#include "param.h" // Para Param, ParamGame, param #include "param.h" // Para Param, ParamGame, param
#include "player.h" // Para Player::Id
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
// Constructor // Constructor
Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, Player::Id owner) Bullet::Bullet(float x, float y, Type type, Color color, int owner)
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("bullet.png"), Resource::get()->getAnimation("bullet.ani"))), : sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("bullet.png"), Resource::get()->getAnimation("bullet.ani"))),
bullet_type_(bullet_type), type_(type),
owner_(owner), owner_(owner),
pos_x_(x), pos_x_(x),
pos_y_(y) { pos_y_(y) {
vel_x_ = calculateVelocity(bullet_type_); vel_x_ = calculateVelocity(type_);
sprite_->setCurrentAnimation(buildAnimationString(bullet_type_, powered)); sprite_->setCurrentAnimation(buildAnimationString(type_, color));
collider_.r = WIDTH / 2; collider_.r = WIDTH / 2;
shiftColliders(); shiftColliders();
} }
// Calcula la velocidad horizontal de la bala basada en su tipo // Calcula la velocidad horizontal de la bala basada en su tipo
auto Bullet::calculateVelocity(BulletType bullet_type) -> float { auto Bullet::calculateVelocity(Type type) -> float {
switch (bullet_type) { switch (type) {
case BulletType::LEFT: case Type::LEFT:
return VEL_X_LEFT; return VEL_X_LEFT;
case BulletType::RIGHT: case Type::RIGHT:
return VEL_X_RIGHT; return VEL_X_RIGHT;
default: default:
return VEL_X_CENTER; return VEL_X_CENTER;
} }
} }
// Construye el string de animación basado en el tipo de bala y si está potenciada // Construye el string de animación basado en el tipo de bala y color específico
auto Bullet::buildAnimationString(BulletType bullet_type, bool powered) -> std::string { auto Bullet::buildAnimationString(Type type, Color color) -> std::string {
std::string animation_string = powered ? "powered_" : "normal_"; std::string animation_string;
switch (bullet_type) { // Mapear color a string específico
case BulletType::UP: switch (color) {
case Color::YELLOW:
animation_string = "yellow_";
break;
case Color::GREEN:
animation_string = "green_";
break;
case Color::RED:
animation_string = "red_";
break;
case Color::PURPLE:
animation_string = "purple_";
break;
}
// Añadir dirección
switch (type) {
case Type::UP:
animation_string += "up"; animation_string += "up";
break; break;
case BulletType::LEFT: case Type::LEFT:
animation_string += "left"; animation_string += "left";
break; break;
case BulletType::RIGHT: case Type::RIGHT:
animation_string += "right"; animation_string += "right";
break; break;
default: default:
@@ -53,49 +71,48 @@ auto Bullet::buildAnimationString(BulletType bullet_type, bool powered) -> std::
return animation_string; return animation_string;
} }
// Implementación de render (llama al render del sprite_) // Implementación de render
void Bullet::render() { void Bullet::render() {
if (bullet_type_ != BulletType::NONE) { if (type_ != Type::NONE) {
sprite_->render(); sprite_->render();
} }
} }
// Actualiza el estado del objeto (time-based) // Actualiza el estado del objeto
auto Bullet::update(float deltaTime) -> BulletMoveStatus { auto Bullet::update(float deltaTime) -> MoveStatus {
sprite_->update(deltaTime); sprite_->update(deltaTime);
return move(deltaTime); return move(deltaTime);
} }
// Implementación del movimiento usando BulletMoveStatus (time-based) // Implementación del movimiento usando MoveStatus
auto Bullet::move(float deltaTime) -> BulletMoveStatus { auto Bullet::move(float deltaTime) -> MoveStatus {
// DeltaTime puro: velocidad (pixels/segundo) * tiempo (segundos)
pos_x_ += vel_x_ * deltaTime; pos_x_ += vel_x_ * deltaTime;
if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) { if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) {
disable(); disable();
return BulletMoveStatus::OUT; return MoveStatus::OUT;
} }
pos_y_ += VEL_Y * deltaTime; pos_y_ += VEL_Y * deltaTime;
if (pos_y_ < param.game.play_area.rect.y - HEIGHT) { if (pos_y_ < param.game.play_area.rect.y - HEIGHT) {
disable(); disable();
return BulletMoveStatus::OUT; return MoveStatus::OUT;
} }
shiftSprite(); shiftSprite();
shiftColliders(); shiftColliders();
return BulletMoveStatus::OK; return MoveStatus::OK;
} }
auto Bullet::isEnabled() const -> bool { auto Bullet::isEnabled() const -> bool {
return bullet_type_ != BulletType::NONE; return type_ != Type::NONE;
} }
void Bullet::disable() { void Bullet::disable() {
bullet_type_ = BulletType::NONE; type_ = Type::NONE;
} }
auto Bullet::getOwner() const -> Player::Id { auto Bullet::getOwner() const -> int {
return owner_; return owner_;
} }

View File

@@ -6,22 +6,8 @@
#include <string> // Para string #include <string> // Para string
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "player.h" // Para Player
#include "utils.h" // Para Circle #include "utils.h" // Para Circle
// --- Enums ---
enum class BulletType : Uint8 {
UP, // Bala hacia arriba
LEFT, // Bala hacia la izquierda
RIGHT, // Bala hacia la derecha
NONE // Sin bala
};
enum class BulletMoveStatus : Uint8 {
OK = 0, // Movimiento normal
OUT = 1 // Fuera de los límites
};
// --- Clase Bullet: representa una bala del jugador --- // --- Clase Bullet: representa una bala del jugador ---
class Bullet { class Bullet {
public: public:
@@ -29,19 +15,39 @@ class Bullet {
static constexpr float WIDTH = 12.0F; // Anchura de la bala static constexpr float WIDTH = 12.0F; // Anchura de la bala
static constexpr float HEIGHT = 12.0F; // Altura de la bala static constexpr float HEIGHT = 12.0F; // Altura de la bala
// --- Enums ---
enum class Type : Uint8 {
UP, // Bala hacia arriba
LEFT, // Bala hacia la izquierda
RIGHT, // Bala hacia la derecha
NONE // Sin bala
};
enum class MoveStatus : Uint8 {
OK = 0, // Movimiento normal
OUT = 1 // Fuera de los límites
};
enum class Color : Uint8 {
YELLOW,
GREEN,
RED,
PURPLE
};
// --- Constructor y destructor --- // --- Constructor y destructor ---
Bullet(float x, float y, BulletType bullet_type, bool powered, Player::Id owner); // Constructor principal Bullet(float x, float y, Type type, Color color, int owner); // Constructor principal
~Bullet() = default; // Destructor ~Bullet() = default; // Destructor
// --- Métodos principales --- // --- Métodos principales ---
void render(); // Dibuja la bala en pantalla void render(); // Dibuja la bala en pantalla
auto update(float deltaTime) -> BulletMoveStatus; // Actualiza el estado del objeto (time-based) auto update(float deltaTime) -> MoveStatus; // Actualiza el estado del objeto (time-based)
void disable(); // Desactiva la bala void disable(); // Desactiva la bala
// --- Getters --- // --- Getters ---
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está activa [[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está activa
[[nodiscard]] auto getOwner() const -> Player::Id; // Devuelve el identificador del dueño [[nodiscard]] auto getOwner() const -> int; // Devuelve el identificador del dueño
auto getCollider() -> Circle &; // Devuelve el círculo de colisión auto getCollider() -> Circle&; // Devuelve el círculo de colisión
private: private:
// --- Constantes --- // --- Constantes ---
@@ -55,8 +61,8 @@ class Bullet {
// --- Variables de estado --- // --- Variables de estado ---
Circle collider_; // Círculo de colisión Circle collider_; // Círculo de colisión
BulletType bullet_type_; // Tipo de bala Type type_; // Tipo de bala
Player::Id owner_; // Identificador del dueño int owner_; // Identificador del jugador
float pos_x_; // Posición en el eje X float pos_x_; // Posición en el eje X
float pos_y_; // Posición en el eje Y float pos_y_; // Posición en el eje Y
float vel_x_; // Velocidad en el eje X float vel_x_; // Velocidad en el eje X
@@ -64,7 +70,7 @@ class Bullet {
// --- Métodos internos --- // --- Métodos internos ---
void shiftColliders(); // Ajusta el círculo de colisión void shiftColliders(); // Ajusta el círculo de colisión
void shiftSprite(); // Ajusta el sprite void shiftSprite(); // Ajusta el sprite
auto move(float deltaTime) -> BulletMoveStatus; // Mueve la bala y devuelve su estado (time-based) auto move(float deltaTime) -> MoveStatus; // Mueve la bala y devuelve su estado (time-based)
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala static auto calculateVelocity(Type type) -> float; // Calcula la velocidad horizontal de la bala
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación static auto buildAnimationString(Type type, Color color) -> std::string; // Construye el string de animación
}; };

View File

@@ -6,6 +6,7 @@
#include "color.h" #include "color.h"
#include "ui/notifier.h" // Para Notifier::Position #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: configuración centralizada con valores por defecto del juego ---
namespace GameDefaults { namespace GameDefaults {
@@ -14,9 +15,8 @@ namespace GameDefaults {
namespace Game { namespace Game {
constexpr float WIDTH = 320.0F; constexpr float WIDTH = 320.0F;
constexpr float HEIGHT = 256.0F; constexpr float HEIGHT = 256.0F;
constexpr float ITEM_SIZE = 20.0F; constexpr int NAME_ENTRY_IDLE_TIME = 10;
constexpr int NAME_ENTRY_IDLE_TIME = 10000; // 10 segundos en milisegundos constexpr int NAME_ENTRY_TOTAL_TIME = 60;
constexpr int NAME_ENTRY_TOTAL_TIME = 60000; // 60 segundos en milisegundos
constexpr bool HIT_STOP = false; constexpr bool HIT_STOP = false;
constexpr int HIT_STOP_MS = 500; constexpr int HIT_STOP_MS = 500;
constexpr const char* ITEM_TEXT_OUTLINE_COLOR = "FFFFFF00"; // 255, 255, 255, 0 constexpr const char* ITEM_TEXT_OUTLINE_COLOR = "FFFFFF00"; // 255, 255, 255, 0
@@ -58,7 +58,7 @@ constexpr int SKIP_COUNTDOWN_VALUE = 8;
// --- TITLE --- // --- TITLE ---
namespace Title { namespace Title {
constexpr int PRESS_START_POSITION = 180; constexpr int PRESS_START_POSITION = 180;
constexpr float DURATION = 14000; constexpr float DURATION_S = 14.0F;
constexpr int ARCADE_EDITION_POSITION = 123; constexpr int ARCADE_EDITION_POSITION = 123;
constexpr int TITLE_C_C_POSITION = 80; constexpr int TITLE_C_C_POSITION = 80;
constexpr const char* BG_COLOR = "41526F"; constexpr const char* BG_COLOR = "41526F";
@@ -211,7 +211,7 @@ constexpr const char* PLAYER1 = "422028FF";
// --- OPTIONS --- // --- OPTIONS ---
namespace Options { namespace Options {
// Window // 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_ZOOM = 2;
constexpr int WINDOW_MAX_ZOOM = 2; constexpr int WINDOW_MAX_ZOOM = 2;

View File

@@ -39,22 +39,22 @@ void DefineButtons::render() {
} }
} }
void DefineButtons::update() { void DefineButtons::update(float delta_time) {
if (!enabled_) { if (!enabled_) {
return; return;
} }
// Actualizar la ventana siempre // Actualizar la ventana siempre
if (window_message_) { if (window_message_) {
window_message_->update(); window_message_->update(delta_time);
} }
// Manejar la secuencia de cierre si ya terminamos // Manejar la secuencia de cierre si ya terminamos
if (finished_ && message_shown_) { if (finished_ && message_shown_) {
message_timer_++; message_timer_ += delta_time;
// Después del delay, iniciar animación de cierre (solo una vez) // Después del delay, iniciar animación de cierre (solo una vez)
if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) { if (message_timer_ >= MESSAGE_DISPLAY_DURATION_S && !closing_) {
if (window_message_) { if (window_message_) {
window_message_->hide(); // Iniciar animación de cierre window_message_->hide(); // Iniciar animación de cierre
} }
@@ -234,7 +234,7 @@ void DefineButtons::checkEnd() {
// Solo marcar que ya mostramos el mensaje // Solo marcar que ya mostramos el mensaje
message_shown_ = true; message_shown_ = true;
message_timer_ = 0; message_timer_ = 0.0f;
} }
} }

View File

@@ -36,7 +36,7 @@ class DefineButtons {
// --- Métodos principales --- // --- Métodos principales ---
void render(); void render();
void update(); void update(float delta_time);
void handleEvents(const SDL_Event &event); void handleEvents(const SDL_Event &event);
auto enable(Options::Gamepad *options_gamepad) -> bool; auto enable(Options::Gamepad *options_gamepad) -> bool;
void disable(); void disable();
@@ -48,7 +48,7 @@ class DefineButtons {
private: private:
// --- Constantes --- // --- Constantes ---
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 120; // Cuánto tiempo mostrar el mensaje (en frames) ~2 segundos a 60fps static constexpr float MESSAGE_DISPLAY_DURATION_S = 2.0f; // Cuánto tiempo mostrar el mensaje en segundos
// --- Objetos y punteros --- // --- Objetos y punteros ---
Input *input_ = nullptr; // Entrada del usuario Input *input_ = nullptr; // Entrada del usuario
@@ -59,7 +59,7 @@ class DefineButtons {
std::vector<Button> buttons_; // Lista de botones std::vector<Button> buttons_; // Lista de botones
std::vector<std::string> controller_names_; // Nombres de los controladores std::vector<std::string> controller_names_; // Nombres de los controladores
size_t index_button_ = 0; // Índice del botón seleccionado size_t index_button_ = 0; // Índice del botón seleccionado
size_t message_timer_ = 0; // Contador de frames para el mensaje float message_timer_ = 0.0f; // Timer en segundos para el mensaje
bool enabled_ = false; // Flag para indicar si está activo bool enabled_ = false; // Flag para indicar si está activo
bool finished_ = false; // Flag para indicar si ha terminado bool finished_ = false; // Flag para indicar si ha terminado
bool closing_ = false; // Flag para indicar que está cerrando bool closing_ = false; // Flag para indicar que está cerrando

70
source/demo.cpp Normal file
View 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
View 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

View File

@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
Section::name = Section::Name::GAME; Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P; Section::options = Section::Options::GAME_PLAY_1P;
#elif _DEBUG #elif _DEBUG
Section::name = Section::Name::GAME; Section::name = Section::Name::TITLE;
Section::options = Section::Options::GAME_PLAY_1P; Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME #else // NORMAL GAME
Section::name = Section::Name::LOGO; Section::name = Section::Name::LOGO;
@@ -80,9 +80,9 @@ void Director::init() {
Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos
#ifdef MACOS_BUNDLE #ifdef MACOS_BUNDLE
ResourceHelper::initializeResourceSystem(executable_path_ + "/../Resources/resources.pack"); ResourceHelper::initializeResourceSystem(executable_path_ + "../Resources/resources.pack");
#else #else
ResourceHelper::initializeResourceSystem("resources.pack"); ResourceHelper::initializeResourceSystem(executable_path_ + "resources.pack");
#endif #endif
loadAssets(); // Crea el índice de archivos loadAssets(); // Crea el índice de archivos
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
@@ -174,8 +174,14 @@ void Director::loadAssets() {
// Comprueba los parametros del programa // Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, std::span<char *> argv) { void Director::checkProgramArguments(int argc, std::span<char *> argv) {
// Establece la ruta del programa // Obtener la ruta absoluta del ejecutable
executable_path_ = getPath(argv[0]); std::filesystem::path exe_path = std::filesystem::absolute(argv[0]);
executable_path_ = exe_path.parent_path().string();
// Asegurar que termine con separador de directorio
if (!executable_path_.empty() && executable_path_.back() != '/' && executable_path_.back() != '\\') {
executable_path_ += "/";
}
// Comprueba el resto de parámetros // Comprueba el resto de parámetros
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {

View File

@@ -48,8 +48,8 @@ class Fade {
void setColor(Color color); // Establece el color del fade void setColor(Color color); // Establece el color del fade
void setType(Type type) { type_ = type; } // Establece el tipo de fade void setType(Type type) { type_ = type; } // Establece el tipo de fade
void setMode(Mode mode) { mode_ = mode; } // Establece el modo de fade void setMode(Mode mode) { mode_ = mode; } // Establece el modo de fade
void setPostDuration(int value) { post_duration_ = value; } // Duración posterior al fade en milisegundos void setPostDuration(int milliseconds) { post_duration_ = milliseconds; } // Duración posterior al fade en milisegundos
void setPreDuration(int value) { pre_duration_ = value; } // Duración previa al fade en milisegundos void setPreDuration(int milliseconds) { pre_duration_ = milliseconds; } // Duración previa al fade en milisegundos
// --- Getters --- // --- Getters ---
[[nodiscard]] auto getValue() const -> int { return value_; } [[nodiscard]] auto getValue() const -> int { return value_; }

View File

@@ -15,8 +15,9 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
constexpr int ZOOM_FACTOR = 5; constexpr int ZOOM_FACTOR = 5;
constexpr int FLASH_DELAY = 3; constexpr float FLASH_DELAY_S = 0.05f; // 3 frames → 0.05s
constexpr int FLASH_LENGTH = FLASH_DELAY + 3; constexpr float FLASH_DURATION_S = 0.1f; // 6 frames → 0.1s (3 + 3)
constexpr Color FLASH_COLOR = Color(0xFF, 0xFF, 0xFF); // Color blanco para el flash
// Constructor // Constructor
GameLogo::GameLogo(int x, int y) GameLogo::GameLogo(int x, int y)
@@ -242,7 +243,7 @@ void GameLogo::finishArcadeEditionMoving() {
void GameLogo::playTitleEffects() { void GameLogo::playTitleEffects() {
Audio::get()->playSound("title.wav"); Audio::get()->playSound("title.wav");
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGTH, FLASH_DELAY); Screen::get()->flash(FLASH_COLOR, FLASH_DURATION_S, FLASH_DELAY_S);
Screen::get()->shake(); Screen::get()->shake();
} }

View File

@@ -9,7 +9,7 @@
class Texture; // lines 6-6 class Texture; // lines 6-6
Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation) Item::Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation)
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)), : sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
play_area_(play_area), play_area_(play_area),
type_(type) { type_(type) {
@@ -26,8 +26,6 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha
break; break;
} }
default: { default: {
width_ = param.game.item_size;
height_ = param.game.item_size;
pos_x_ = x; pos_x_ = x;
pos_y_ = y; pos_y_ = y;
// 6 velocidades: 3 negativas (-1.0, -0.66, -0.33) y 3 positivas (0.33, 0.66, 1.0) // 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) { if (direction < 3) {
// Velocidades negativas: -1.0, -0.66, -0.33 // Velocidades negativas: -1.0, -0.66, -0.33
vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP); vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP);
rotate_speed_ = -720.0F;
} else { } else {
// Velocidades positivas: 0.33, 0.66, 1.0 // Velocidades positivas: 0.33, 0.66, 1.0
vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP); vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP);
rotate_speed_ = 720.0F;
} }
vel_y_ = ITEM_VEL_Y; vel_y_ = ITEM_VEL_Y;
accel_y_ = ITEM_ACCEL_Y; accel_y_ = ITEM_ACCEL_Y;
collider_.r = width_ / 2; collider_.r = width_ / 2;
sprite_->startRotate();
sprite_->setRotateAmount(rotate_speed_);
break; break;
} }
} }
@@ -104,6 +106,7 @@ void Item::move(float deltaTime) {
// Si toca el borde lateral // Si toca el borde lateral
if (pos_x_ == MIN_X || pos_x_ == MAX_X) { if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
vel_x_ = -vel_x_; // Invierte la velocidad horizontal 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é) // 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 // Si colisiona con la parte inferior
if (pos_y_ > play_area_.h - height_) { if (pos_y_ > play_area_.h - height_) {
// Corrige la posición pos_y_ = play_area_.h - height_; // Corrige la posición
pos_y_ = play_area_.h - height_; sprite_->scaleRotateAmount(0.5F); // Reduce la rotación
sprite_->stopRotate(300.0F); // Detiene la rotacion
switch (type_) { switch (type_) {
case ItemType::COFFEE_MACHINE: case ItemType::COFFEE_MACHINE:

View File

@@ -27,6 +27,8 @@ enum class ItemType : int {
class Item { class Item {
public: public:
// --- Constantes --- // --- 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_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 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 static constexpr float LIFETIME_DURATION_S = 10.0f; // Duración de vida del ítem en segundos
@@ -49,7 +51,7 @@ class Item {
static constexpr float HORIZONTAL_DAMPING = 0.75F; // Factor de amortiguación horizontal static constexpr float HORIZONTAL_DAMPING = 0.75F; // Factor de amortiguación horizontal
// --- Constructor y destructor --- // --- Constructor y destructor ---
Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Constructor principal Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation); // Constructor principal
~Item() = default; // Destructor ~Item() = default; // Destructor
// --- Métodos principales --- // --- Métodos principales ---
@@ -66,7 +68,7 @@ class Item {
[[nodiscard]] auto getType() const -> ItemType { return type_; } // Obtiene el tipo [[nodiscard]] auto getType() const -> ItemType { return type_; } // Obtiene el tipo
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; } // Verifica si está habilitado [[nodiscard]] auto isEnabled() const -> bool { return enabled_; } // Verifica si está habilitado
[[nodiscard]] auto isOnFloor() const -> bool { return floor_collision_; } // Verifica si está en el suelo [[nodiscard]] auto isOnFloor() const -> bool { return floor_collision_; } // Verifica si está en el suelo
auto getCollider() -> Circle & { return collider_; } // Obtiene el colisionador auto getCollider() -> Circle& { return collider_; } // Obtiene el colisionador
private: private:
// --- Objetos y punteros --- // --- Objetos y punteros ---
@@ -76,14 +78,15 @@ class Item {
SDL_FRect play_area_; // Rectángulo con la zona de juego SDL_FRect play_area_; // Rectángulo con la zona de juego
Circle collider_; // Círculo de colisión del objeto Circle collider_; // Círculo de colisión del objeto
ItemType type_; // Tipo de objeto ItemType type_; // Tipo de objeto
float pos_x_; // Posición X del objeto float pos_x_ = 0.0F; // Posición X del objeto
float pos_y_; // Posición Y del objeto float pos_y_ = 0.0F; // Posición Y del objeto
float vel_x_; // Velocidad en el eje X float vel_x_ = 0.0F; // Velocidad en el eje X
float vel_y_; // Velocidad en el eje Y float vel_y_ = 0.0F; // Velocidad en el eje Y
float accel_x_ = 0.0F; // Aceleración en el eje X float accel_x_ = 0.0F; // Aceleración en el eje X
float accel_y_; // Aceleración en el eje Y float accel_y_ = 0.0F; // Aceleración en el eje Y
int width_; // Ancho del objeto float width_ = WIDTH; // Ancho del objeto
int height_; // Alto 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) 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 floor_collision_ = false; // Indica si el objeto colisiona con el suelo
bool enabled_ = true; // Indica si el objeto está habilitado bool enabled_ = true; // Indica si el objeto está habilitado

View File

@@ -24,6 +24,32 @@ void ManageHiScoreTable::clear() {
table_.emplace_back("PACMQ", 200); table_.emplace_back("PACMQ", 200);
table_.emplace_back("PELEC", 100); table_.emplace_back("PELEC", 100);
/*
table_.emplace_back("BRY", 1000);
table_.emplace_back("USUFO", 500);
table_.emplace_back("GLUCA", 100);
table_.emplace_back("PARRA", 50);
table_.emplace_back("CAGAM", 10);
table_.emplace_back("PEPE", 5);
table_.emplace_back("ROSIT", 4);
table_.emplace_back("SAM", 3);
table_.emplace_back("PACMQ", 2);
table_.emplace_back("PELEC", 1);
*/
/*
table_.emplace_back("BRY", 5000000);
table_.emplace_back("USUFO", 5000000);
table_.emplace_back("GLUCA", 5000000);
table_.emplace_back("PARRA", 5000000);
table_.emplace_back("CAGAM", 5000000);
table_.emplace_back("PEPE", 5000000);
table_.emplace_back("ROSIT", 5000000);
table_.emplace_back("SAM", 5000000);
table_.emplace_back("PACMQ", 5000000);
table_.emplace_back("PELEC", 5000000);
*/
sort(); sort();
} }

View File

@@ -1,5 +1,6 @@
#include "moving_sprite.h" #include "moving_sprite.h"
#include <cmath> // Para std::abs
#include <utility> #include <utility>
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
@@ -90,6 +91,21 @@ void MovingSprite::setRotate(bool enable) {
rotate_.enabled = 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 // Establece la posición y_ el tamaño del objeto
void MovingSprite::setPos(SDL_FRect rect) { void MovingSprite::setPos(SDL_FRect rect) {
x_ = rect.x; x_ = rect.x;

View File

@@ -15,7 +15,6 @@ class MovingSprite : public Sprite {
// --- Estructuras --- // --- Estructuras ---
struct Rotate { struct Rotate {
bool enabled{false}; // Indica si ha de rotar bool enabled{false}; // Indica si ha de rotar
int speed{1}; // Velocidad de giro
double angle{0.0}; // Ángulo para dibujarlo double angle{0.0}; // Ángulo para dibujarlo
float amount{0.0F}; // Cantidad de grados a girar en cada iteración 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 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 setAngle(double value) { rotate_.angle = value; } // Establece el ángulo
void setRotatingCenter(SDL_FPoint point) { rotate_.center = point; } // Establece el centro de rotación 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 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 startRotate(); // Habilita la rotación con centro automático
void setRotateAmount(double value) { rotate_.amount = value; } // Establece la cantidad de rotación 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 switchRotate() { rotate_.amount *= -1; } // Cambia el sentido de la rotación
void setFlip(SDL_FlipMode flip) { flip_ = flip; } // Establece el flip 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 void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; } // Cambia el flip

View File

@@ -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 = { 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.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
{"game.height", [](const std::string& v) { param.game.height = 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.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.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); }}, {"game.play_area.rect.w", [](const std::string& v) { param.game.play_area.rect.w = std::stoi(v); }},

View File

@@ -14,7 +14,6 @@
struct ParamGame { struct ParamGame {
float width = GameDefaults::Game::WIDTH; float width = GameDefaults::Game::WIDTH;
float height = GameDefaults::Game::HEIGHT; float height = GameDefaults::Game::HEIGHT;
float item_size = GameDefaults::Game::ITEM_SIZE;
Zone play_area{}; // Se inicializa en el constructor de Param Zone play_area{}; // Se inicializa en el constructor de Param
Zone game_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; int name_entry_idle_time = GameDefaults::Game::NAME_ENTRY_IDLE_TIME;
@@ -38,7 +37,7 @@ struct ParamFade {
// --- Parámetros de la pantalla de título --- // --- Parámetros de la pantalla de título ---
struct ParamTitle { struct ParamTitle {
int press_start_position = GameDefaults::Title::PRESS_START_POSITION; int press_start_position = GameDefaults::Title::PRESS_START_POSITION;
float title_duration = GameDefaults::Title::DURATION; float title_duration = GameDefaults::Title::DURATION_S;
int arcade_edition_position = GameDefaults::Title::ARCADE_EDITION_POSITION; int arcade_edition_position = GameDefaults::Title::ARCADE_EDITION_POSITION;
int title_c_c_position = GameDefaults::Title::TITLE_C_C_POSITION; int title_c_c_position = GameDefaults::Title::TITLE_C_C_POSITION;
Color bg_color = Color::fromHex(GameDefaults::Title::BG_COLOR); Color bg_color = Color::fromHex(GameDefaults::Title::BG_COLOR);

View File

@@ -22,7 +22,7 @@
#endif #endif
// Constructor // Constructor
Player::Player(const Config &config) Player::Player(const Config& config)
: player_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(0), config.animations.at(0))), : player_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(0), config.animations.at(0))),
power_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(4), config.animations.at(1))), power_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(4), config.animations.at(1))),
enter_name_(std::make_unique<EnterName>()), enter_name_(std::make_unique<EnterName>()),
@@ -149,7 +149,7 @@ void Player::setInputEnteringName(Input::Action action) {
name_entry_idle_time_accumulator_ = 0.0f; name_entry_idle_time_accumulator_ = 0.0f;
} }
// Fase 1: Sistema de movimiento time-based // Sistema de movimiento
void Player::move(float deltaTime) { void Player::move(float deltaTime) {
switch (playing_state_) { switch (playing_state_) {
case State::PLAYING: case State::PLAYING:
@@ -396,24 +396,8 @@ void Player::updateStepCounter(float deltaTime) {
// Pinta el jugador en pantalla // Pinta el jugador en pantalla
void Player::render() { void Player::render() {
if (power_up_ && isPlaying()) { if (power_sprite_visible_ && isPlaying()) {
// Convertir lógica de parpadeo a deltaTime en segundos
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Total time in seconds
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f; // 25% del tiempo total
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
// En los primeros 75% del tiempo, siempre visible
power_sprite_->render(); power_sprite_->render();
} else {
// En el último 25%, parpadea cada 20 frames (≈0.333s)
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f; // 20 frames in seconds
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f; // 4 frames visible de 20 total
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
if (cycle_position >= VISIBLE_PROPORTION) {
power_sprite_->render();
}
}
} }
if (isRenderable()) { if (isRenderable()) {
@@ -475,11 +459,10 @@ auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
return {anim_name, flip_mode}; return {anim_name, flip_mode};
} }
// Fase 1: Establece la animación correspondiente al estado (time-based) // Establece la animación correspondiente al estado
void Player::setAnimation(float deltaTime) { void Player::setAnimation(float deltaTime) {
switch (playing_state_) { switch (playing_state_) {
case State::PLAYING: case State::PLAYING:
case State::ENTERING_NAME_GAME_COMPLETED:
case State::ENTERING_SCREEN: case State::ENTERING_SCREEN:
case State::LEAVING_SCREEN: case State::LEAVING_SCREEN:
case State::TITLE_ANIMATION: case State::TITLE_ANIMATION:
@@ -505,6 +488,7 @@ void Player::setAnimation(float deltaTime) {
case State::CONTINUE: case State::CONTINUE:
player_sprite_->setCurrentAnimation("dizzy"); player_sprite_->setCurrentAnimation("dizzy");
break; break;
case State::ENTERING_NAME_GAME_COMPLETED:
case State::CELEBRATING: case State::CELEBRATING:
player_sprite_->setCurrentAnimation("celebration"); player_sprite_->setCurrentAnimation("celebration");
break; break;
@@ -679,8 +663,8 @@ void Player::setPlayingState(State state) {
break; break;
} }
case State::ENTERING_NAME_GAME_COMPLETED: { case State::ENTERING_NAME_GAME_COMPLETED: {
setWalkingState(State::WALKING_STOP); // setWalkingState(State::WALKING_STOP);
setFiringState(State::FIRING_NONE); // setFiringState(State::FIRING_NONE);
setScoreboardMode(Scoreboard::Mode::ENTER_NAME); setScoreboardMode(Scoreboard::Mode::ENTER_NAME);
break; break;
} }
@@ -774,6 +758,9 @@ void Player::setPowerUp() {
power_up_ = true; power_up_ = true;
power_up_counter_ = POWERUP_COUNTER; power_up_counter_ = POWERUP_COUNTER;
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds
power_sprite_visible_ = true; // Inicialmente visible cuando se activa el power-up
in_power_up_ending_phase_ = false; // Empezar en fase normal
bullet_color_toggle_ = false; // Resetear toggle
} }
// Actualiza el valor de la variable (time-based) // Actualiza el valor de la variable (time-based)
@@ -784,8 +771,34 @@ void Player::updatePowerUp(float deltaTime) {
power_up_ = power_up_time_accumulator_ > 0; power_up_ = power_up_time_accumulator_ > 0;
if (!power_up_) { if (!power_up_) {
power_up_time_accumulator_ = 0; power_up_time_accumulator_ = 0;
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
// Los colores ahora se manejan dinámicamente en getNextBulletColor()
} else {
// Calcular visibilidad del power sprite
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f;
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f;
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
// En los primeros 75% del tiempo, siempre visible
power_sprite_visible_ = true;
in_power_up_ending_phase_ = false;
} else {
// En el último 25%, parpadea cada 20 frames (≈0.333s)
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f;
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f;
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
power_sprite_visible_ = cycle_position >= VISIBLE_PROPORTION;
in_power_up_ending_phase_ = true; // Activar modo alternancia de colores de balas
} }
} }
} else {
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
}
} }
} }
@@ -816,7 +829,7 @@ void Player::shiftColliders() {
} }
// Pone las texturas del jugador // Pone las texturas del jugador
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture) { void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture) {
player_sprite_->setTexture(texture[0]); player_sprite_->setTexture(texture[0]);
power_sprite_->setTexture(texture[1]); power_sprite_->setTexture(texture[1]);
} }
@@ -875,12 +888,8 @@ void Player::decNameEntryCounter() {
name_entry_idle_time_accumulator_ += 1.0f; name_entry_idle_time_accumulator_ += 1.0f;
name_entry_total_time_accumulator_ += 1.0f; name_entry_total_time_accumulator_ += 1.0f;
// Convierte límites de param (milisegundos) a segundos para comparación if ((name_entry_total_time_accumulator_ >= param.game.name_entry_total_time) ||
const float NAME_ENTRY_TOTAL_TIME_S = param.game.name_entry_total_time / 1000.0f; (name_entry_idle_time_accumulator_ >= param.game.name_entry_idle_time)) {
const float NAME_ENTRY_IDLE_TIME_S = param.game.name_entry_idle_time / 1000.0f;
if ((name_entry_total_time_accumulator_ >= NAME_ENTRY_TOTAL_TIME_S) ||
(name_entry_idle_time_accumulator_ >= NAME_ENTRY_IDLE_TIME_S)) {
name_entry_total_time_accumulator_ = 0.0f; name_entry_total_time_accumulator_ = 0.0f;
name_entry_idle_time_accumulator_ = 0.0f; name_entry_idle_time_accumulator_ = 0.0f;
if (playing_state_ == State::ENTERING_NAME) { if (playing_state_ == State::ENTERING_NAME) {
@@ -909,12 +918,12 @@ void Player::shiftSprite() {
} }
// Hace sonar un sonido // Hace sonar un sonido
void Player::playSound(const std::string &name) const { void Player::playSound(const std::string& name) const {
if (demo_) { if (demo_) {
return; return;
} }
static auto *audio_ = Audio::get(); static auto* audio_ = Audio::get();
audio_->playSound(name); audio_->playSound(name);
} }
@@ -923,6 +932,33 @@ auto Player::isRenderable() const -> bool {
return !isTitleHidden(); return !isTitleHidden();
}; };
// Devuelve el color actual de bala según el estado
auto Player::getBulletColor() const -> Bullet::Color {
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Devuelve el color para la próxima bala (alterna si está en modo toggle)
auto Player::getNextBulletColor() -> Bullet::Color {
if (in_power_up_ending_phase_) {
// En fase final: alternar entre colores powered y normal
bullet_color_toggle_ = !bullet_color_toggle_;
return bullet_color_toggle_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Modo normal: sin power-up = normal_color, con power-up = powered_color
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Establece los colores de bala para este jugador
void Player::setBulletColors(Bullet::Color normal, Bullet::Color powered) {
bullet_colors_.normal_color = normal;
bullet_colors_.powered_color = powered;
}
// Establece el archivo de sonido de bala para este jugador
void Player::setBulletSoundFile(const std::string& filename) {
bullet_sound_file_ = filename;
}
// Añade una puntuación a la tabla de records // Añade una puntuación a la tabla de records
void Player::addScoreToScoreBoard() const { void Player::addScoreToScoreBoard() const {
if (hi_score_table_ == nullptr) { if (hi_score_table_ == nullptr) {
@@ -1038,19 +1074,35 @@ void Player::updateFiringStateFromVisual() {
case VisualFireState::RECOILING: case VisualFireState::RECOILING:
switch (base_state) { switch (base_state) {
case State::FIRING_LEFT: firing_state_ = State::RECOILING_LEFT; break; case State::FIRING_LEFT:
case State::FIRING_RIGHT: firing_state_ = State::RECOILING_RIGHT; break; firing_state_ = State::RECOILING_LEFT;
case State::FIRING_UP: firing_state_ = State::RECOILING_UP; break; break;
default: firing_state_ = State::RECOILING_UP; break; case State::FIRING_RIGHT:
firing_state_ = State::RECOILING_RIGHT;
break;
case State::FIRING_UP:
firing_state_ = State::RECOILING_UP;
break;
default:
firing_state_ = State::RECOILING_UP;
break;
} }
break; break;
case VisualFireState::THREAT_POSE: case VisualFireState::THREAT_POSE:
switch (base_state) { switch (base_state) {
case State::FIRING_LEFT: firing_state_ = State::COOLING_LEFT; break; case State::FIRING_LEFT:
case State::FIRING_RIGHT: firing_state_ = State::COOLING_RIGHT; break; firing_state_ = State::COOLING_LEFT;
case State::FIRING_UP: firing_state_ = State::COOLING_UP; break; break;
default: firing_state_ = State::COOLING_UP; break; case State::FIRING_RIGHT:
firing_state_ = State::COOLING_RIGHT;
break;
case State::FIRING_UP:
firing_state_ = State::COOLING_UP;
break;
default:
firing_state_ = State::COOLING_UP;
break;
} }
break; break;
} }

View File

@@ -8,6 +8,7 @@
#include <vector> // Para vector #include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "bullet.h" // Para Bullet
#include "enter_name.h" // Para EnterName #include "enter_name.h" // Para EnterName
#include "input.h" // Para Input #include "input.h" // Para Input
#include "manage_hiscore_table.h" // Para Table #include "manage_hiscore_table.h" // Para Table
@@ -38,6 +39,12 @@ class Player {
static constexpr int WIDTH = 32; // Anchura static constexpr int WIDTH = 32; // Anchura
static constexpr int HEIGHT = 32; // Altura static constexpr int HEIGHT = 32; // Altura
// --- Estructuras ---
struct BulletColorPair {
Bullet::Color normal_color; // Color de bala sin power-up
Bullet::Color powered_color; // Color de bala con power-up
};
// --- Enums --- // --- Enums ---
enum class Id : int { enum class Id : int {
NO_PLAYER = -1, // Sin jugador NO_PLAYER = -1, // Sin jugador
@@ -95,16 +102,16 @@ class Player {
float x; // Posición X inicial float x; // Posición X inicial
int y; // Posición Y inicial int y; // Posición Y inicial
bool demo; // Modo demo bool demo; // Modo demo
SDL_FRect *play_area; // Área de juego (puntero para mantener referencia) SDL_FRect* play_area; // Área de juego (puntero para mantener referencia)
std::vector<std::shared_ptr<Texture>> texture; // Texturas del jugador std::vector<std::shared_ptr<Texture>> texture; // Texturas del jugador
std::vector<std::vector<std::string>> animations; // Animaciones del jugador std::vector<std::vector<std::string>> animations; // Animaciones del jugador
Table *hi_score_table; // Tabla de puntuaciones (puntero para referencia) Table* hi_score_table; // Tabla de puntuaciones (puntero para referencia)
int *glowing_entry; // Entrada brillante (puntero para mantener referencia) int* glowing_entry; // Entrada brillante (puntero para mantener referencia)
IStageInfo *stage_info; // Gestor de pantallas (puntero) IStageInfo* stage_info; // Gestor de pantallas (puntero)
}; };
// --- Constructor y destructor --- // --- Constructor y destructor ---
Player(const Config &config); Player(const Config& config);
~Player() = default; ~Player() = default;
// --- Inicialización y ciclo de vida --- // --- Inicialización y ciclo de vida ---
@@ -122,11 +129,9 @@ class Player {
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based) void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
// --- Texturas y animaciones --- // --- Texturas y animaciones ---
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); // Cambia las texturas del jugador void setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture); // Cambia las texturas del jugador
// --- Estados y contadores --- // --- Gameplay: Puntuación y power-ups ---
// --- Puntuación y marcador ---
void addScore(int score, int lowest_hi_score_entry); // Añade puntos void addScore(int score, int lowest_hi_score_entry); // Añade puntos
void incScoreMultiplier(); // Incrementa el multiplicador void incScoreMultiplier(); // Incrementa el multiplicador
void decScoreMultiplier(); // Decrementa el multiplicador void decScoreMultiplier(); // Decrementa el multiplicador
@@ -135,15 +140,17 @@ class Player {
void setPlayingState(State state); // Cambia el estado de juego void setPlayingState(State state); // Cambia el estado de juego
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
void setPowerUp(); // Activa el modo PowerUp void setPowerUp(); // Activa el modo PowerUp
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp (time-based) void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp
void giveExtraHit(); // Concede un toque extra al jugador void giveExtraHit(); // Concede un toque extra al jugador
void removeExtraHit(); // Quita el toque extra al jugador void removeExtraHit(); // Quita el toque extra al jugador
void decContinueCounter(); // Decrementa el contador de continuar void decContinueCounter(); // Decrementa el contador de continuar
void setWalkingState(State state) { walking_state_ = state; } // Establece el estado de caminar
void startFiringSystem(int cooldown_frames); // Inicia el sistema de disparo
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; } // Establece el panel del marcador
void addCredit();
void passShowingName();
// --- Getters y comprobaciones de estado --- // --- Estado del juego: Consultas (is* methods) ---
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
// Comprobación de playing_state
[[nodiscard]] auto isLyingOnTheFloorForever() const -> bool { return playing_state_ == State::LYING_ON_THE_FLOOR_FOREVER; } [[nodiscard]] auto isLyingOnTheFloorForever() const -> bool { return playing_state_ == State::LYING_ON_THE_FLOOR_FOREVER; }
[[nodiscard]] auto isCelebrating() const -> bool { return playing_state_ == State::CELEBRATING; } [[nodiscard]] auto isCelebrating() const -> bool { return playing_state_ == State::CELEBRATING; }
[[nodiscard]] auto isContinue() const -> bool { return playing_state_ == State::CONTINUE; } [[nodiscard]] auto isContinue() const -> bool { return playing_state_ == State::CONTINUE; }
@@ -157,7 +164,7 @@ class Player {
[[nodiscard]] auto isWaiting() const -> bool { return playing_state_ == State::WAITING; } [[nodiscard]] auto isWaiting() const -> bool { return playing_state_ == State::WAITING; }
[[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; } [[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; }
// Getters // --- Estados específicos: Consultas adicionales ---
[[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema [[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; } [[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; } [[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
@@ -165,45 +172,54 @@ class Player {
[[nodiscard]] auto qualifiesForHighScore() const -> bool { return qualifies_for_high_score_; } [[nodiscard]] auto qualifiesForHighScore() const -> bool { return qualifies_for_high_score_; }
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; } [[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
[[nodiscard]] auto isPowerUp() const -> bool { return power_up_; } [[nodiscard]] auto isPowerUp() const -> bool { return power_up_; }
auto getCollider() -> Circle & { return collider_; } [[nodiscard]] auto isInBulletColorToggleMode() const -> bool { return in_power_up_ending_phase_; }
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
[[nodiscard]] auto getCoffees() const -> int { return coffees_; } // --- Getters: Propiedades y valores ---
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; } // Posición y dimensiones
[[nodiscard]] auto getController() const -> int { return controller_index_; }
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
[[nodiscard]] auto getPosX() const -> int { return static_cast<int>(pos_x_); } [[nodiscard]] auto getPosX() const -> int { return static_cast<int>(pos_x_); }
[[nodiscard]] auto getPosY() const -> int { return pos_y_; } [[nodiscard]] auto getPosY() const -> int { return pos_y_; }
[[nodiscard]] static auto getWidth() -> int { return WIDTH; }
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
// Jugador y identificación
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
[[nodiscard]] auto getName() const -> const std::string& { return name_; }
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
auto getCollider() -> Circle& { return collider_; }
// Puntuación y juego
[[nodiscard]] auto getScore() const -> int { return score_; }
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
[[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; }
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
// Power-ups y estado especial
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
[[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; } [[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; }
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
[[nodiscard]] auto getBulletColor() const -> Bullet::Color; // Devuelve el color actual de bala según el estado
auto getNextBulletColor() -> Bullet::Color; // Devuelve el color para la próxima bala (alterna si está en modo toggle)
void setBulletColors(Bullet::Color normal, Bullet::Color powered); // Establece los colores de bala para este jugador
[[nodiscard]] auto getBulletSoundFile() const -> std::string { return bullet_sound_file_; } // Devuelve el archivo de sonido de bala
void setBulletSoundFile(const std::string& filename); // Establece el archivo de sonido de bala para este jugador
// Contadores y timers
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
[[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; } [[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; }
[[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; } [[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; }
[[nodiscard]] auto getScore() const -> int { return score_; }
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
[[nodiscard]] static auto getWidth() -> int { return WIDTH; }
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
[[nodiscard]] auto getName() const -> const std::string & { return name_; }
[[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; }
[[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; } [[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; }
// Setters inline // --- Configuración e interfaz externa ---
void setController(int index) { controller_index_ = index; } void setName(const std::string& name) { name_ = name; }
void startFiringSystem(int cooldown_frames); // Método público para iniciar disparo
void setFiringState(State state) { firing_state_ = state; }
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
void setName(const std::string &name) { name_ = name; }
void setPowerUpCounter(int value) { power_up_counter_ = value; }
void setScore(int score) { score_ = score; }
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; }
void setScoreMultiplier(float value) { score_multiplier_ = value; }
void setWalkingState(State state) { walking_state_ = state; }
void addCredit();
void passShowingName();
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = std::move(gamepad); } void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = std::move(gamepad); }
[[nodiscard]] auto getGamepad() const -> std::shared_ptr<Input::Gamepad> { return gamepad_; } [[nodiscard]] auto getGamepad() const -> std::shared_ptr<Input::Gamepad> { return gamepad_; }
void setUsesKeyboard(bool value) { uses_keyboard_ = value; } void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; } [[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: private:
// --- Constantes de física y movimiento --- // --- Constantes de física y movimiento ---
@@ -232,9 +248,9 @@ class Player {
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
Table *hi_score_table_ = nullptr; // Tabla de máximas puntuaciones Table* hi_score_table_ = nullptr; // Tabla de máximas puntuaciones
int *glowing_entry_ = nullptr; // Entrada de la tabla de puntuaciones para hacerla brillar int* glowing_entry_ = nullptr; // Entrada de la tabla de puntuaciones para hacerla brillar
IStageInfo *stage_info_; // Informacion de la pantalla actual IStageInfo* stage_info_; // Informacion de la pantalla actual
// --- Variables de estado --- // --- Variables de estado ---
SDL_FRect play_area_; // Rectángulo con la zona de juego SDL_FRect play_area_; // Rectángulo con la zona de juego
@@ -246,6 +262,8 @@ class Player {
State walking_state_ = State::WALKING_STOP; // Estado del jugador al moverse State walking_state_ = State::WALKING_STOP; // Estado del jugador al moverse
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
State playing_state_ = State::WAITING; // Estado del jugador en el juego State playing_state_ = State::WAITING; // Estado del jugador en el juego
BulletColorPair bullet_colors_ = {Bullet::Color::YELLOW, Bullet::Color::GREEN}; // Par de colores de balas para este jugador
std::string bullet_sound_file_ = "bullet1p.wav"; // Archivo de sonido de bala para este jugador
float pos_x_ = 0.0F; // Posición en el eje X float pos_x_ = 0.0F; // Posición en el eje X
float default_pos_x_; // Posición inicial para el jugador float default_pos_x_; // Posición inicial para el jugador
@@ -283,7 +301,6 @@ class Player {
float aiming_duration_ = 0.0f; // Duración del estado AIMING float aiming_duration_ = 0.0f; // Duración del estado AIMING
float recoiling_duration_ = 0.0f; // Duración del estado RECOILING float recoiling_duration_ = 0.0f; // Duración del estado RECOILING
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
int score_ = 0; // Puntos del jugador int score_ = 0; // Puntos del jugador
int coffees_ = 0; // Indica cuántos cafés lleva acumulados int coffees_ = 0; // Indica cuántos cafés lleva acumulados
@@ -291,6 +308,7 @@ class Player {
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador 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 continue_counter_ = 10; // Contador para poder continuar
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse 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_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) 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 int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
@@ -300,6 +318,9 @@ class Player {
bool invulnerable_ = true; // Indica si el jugador es invulnerable bool invulnerable_ = true; // Indica si el jugador es invulnerable
bool extra_hit_ = false; // Indica si el jugador tiene un toque extra bool extra_hit_ = false; // Indica si el jugador tiene un toque extra
bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp
bool power_sprite_visible_ = false; // Indica si el sprite de power-up debe ser visible
bool in_power_up_ending_phase_ = false; // Indica si está en la fase final del power-up (alternando colores)
bool bullet_color_toggle_ = false; // Para alternar entre verde y amarillo en fase final
bool demo_ = false; // Para que el jugador sepa si está en el modo demostración bool demo_ = false; // Para que el jugador sepa si está en el modo demostración
bool game_completed_ = false; // Indica si ha completado el juego bool game_completed_ = false; // Indica si ha completado el juego
bool uses_keyboard_ = false; // Indica si usa el teclado como dispositivo de control bool uses_keyboard_ = false; // Indica si usa el teclado como dispositivo de control
@@ -307,60 +328,66 @@ class Player {
// --- Métodos internos --- // --- Métodos internos ---
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
void shiftSprite(); // Recoloca el sprite void shiftSprite(); // Recoloca el sprite
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad (time-based)
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue (time-based) // --- Setters internos ---
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre (time-based) void setController(int index) { controller_index_ = index; }
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME (time-based) void setFiringState(State state) { firing_state_ = state; }
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
void setPowerUpCounter(int value) { power_up_counter_ = value; }
void setScore(int score) { score_ = score; }
void setScoreMultiplier(float value) { score_multiplier_ = value; }
// --- Actualizadores de estado (time-based) ---
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME
void decNameEntryCounter(); // Decrementa el contador de entrar nombre void decNameEntryCounter(); // Decrementa el contador de entrar nombre
// --- Utilidades generales ---
void updateScoreboard(); // Actualiza el panel del marcador void updateScoreboard(); // Actualiza el panel del marcador
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
void playSound(const std::string &name) const; // Hace sonar un sonido void playSound(const std::string& name) const; // Hace sonar un sonido
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto [[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
// --- Métodos del sistema de disparo de dos líneas --- // --- Sistema de disparo (nuevo - dos líneas) ---
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire) void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones) 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 updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
void transitionToRecoilingNew(); // Transición AIMING → RECOILING void transitionToRecoilingNew(); // Transición AIMING → RECOILING
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
// --- Métodos del sistema de disparo obsoleto --- // --- Manejadores de movimiento ---
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar (frame-based) void handlePlayingMovement(float deltaTime); // Gestiona el movimiento durante el juego
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar (time-based) void handleRecoverMovement(); // Comprueba si ha acabado la animación de recuperación
void handleRecoilAndCooling(); // Procesa retroceso y enfriamiento (frame-based) void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos
void handleRecoilAndCooling(float deltaTime); // Procesa retroceso y enfriamiento (time-based) void setInputBasedOnPlayerId(); // Asocia las entradas de control según el jugador
void handleCoolingState(); // Actualiza estado de enfriamiento (frame-based)
void handleCoolingState(float deltaTime); // Actualiza estado de enfriamiento (time-based) // --- Manejadores de estados especiales ---
void transitionToRecoiling(); // Transición a retroceso (sistema obsoleto) void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar"
void transitionToCooling(); // Transición a enfriamiento (sistema obsoleto) void handleRollingBoundaryCollision(); // Detecta colisiones con límites durante rodamiento
void completeCooling(); // Finaliza enfriamiento (sistema obsoleto) void handleRollingGroundCollision(); // Gestiona interacción con el suelo durante rodamiento
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (frame-based) void handleRollingStop(); // Detiene el movimiento del objeto rodante
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (time-based) void handleRollingBounce(); // Aplica lógica de rebote durante rodamiento
void handleRecoverMovement(); // Comprueba si ha acabado la animación void handleContinueTimeOut(); // Gestiona tiempo de espera en pantalla "Continuar"
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla // --- Manejadores de transiciones de pantalla ---
void handleRollingGroundCollision(); // Gestiona la interacción del objeto rodante con el suelo (rebotes, frenado, etc.) void handleTitleAnimation(float deltaTime); // Ejecuta animación del título
void handleRollingStop(); // Detiene el movimiento del objeto rodante cuando se cumplen las condiciones necesarias void handleLeavingScreen(float deltaTime); // Lógica para salir de pantalla
void handleRollingBounce(); // Aplica una lógica de rebote al colisionar con superficies durante el rodamiento void handleEnteringScreen(float deltaTime); // Lógica para entrar en pantalla
void handleTitleAnimation(float deltaTime); // Ejecuta la animación del título en pantalla (ej. entrada, parpadeo o desplazamiento) void handlePlayer1Entering(float deltaTime); // Entrada del Jugador 1
void handleContinueTimeOut(); // Gestiona el tiempo de espera en la pantalla de "Continuar" y decide si pasar a otro estado void handlePlayer2Entering(float deltaTime); // Entrada del Jugador 2
void handleLeavingScreen(float deltaTime); // Lógica para salir de la pantalla actual (transición visual o cambio de escena)
void handleEnteringScreen(float deltaTime); // Lógica para entrar en una nueva pantalla, posiblemente con animación o retraso // --- Manejadores de pantallas especiales ---
void handlePlayer1Entering(float deltaTime); // Controla la animación o posición de entrada del Jugador 1 en pantalla void handleCreditsMovement(float deltaTime); // Movimiento en pantalla de créditos
void handlePlayer2Entering(float deltaTime); // Controla la animación o posición de entrada del Jugador 2 en pantalla void handleCreditsRightMovement(); // Movimiento hacia la derecha en créditos
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (frame-based) void handleCreditsLeftMovement(); // Movimiento hacia la izquierda en créditos
void handleCreditsMovement(float deltaTime); // Movimiento general en la pantalla de créditos (time-based) void handleWaitingMovement(float deltaTime); // Animación del jugador saludando
void handleCreditsRightMovement(); // Lógica específica para mover los créditos hacia la derecha void updateWalkingStateForCredits(); // Actualiza estado de caminata en créditos
void handleCreditsLeftMovement(); // Lógica específica para mover los créditos hacia la izquierda
void handleWaitingMovement(); // Controla la animación del jugador saludando (frame-based) // --- Utilidades de animación ---
void handleWaitingMovement(float deltaTime); // Controla la animación del jugador saludando (time-based) [[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula animación de movimiento y disparo
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
void updateStepCounter(); // Incrementa o ajusta el contador de pasos (frame-based)
void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos (time-based)
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula la animacion de moverse y disparar del jugador
}; };

View File

@@ -12,21 +12,20 @@
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "color.h" // Para Color #include "color.h" // Para Color
#ifndef NO_AUDIO
#include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound #include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound
#endif
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamResource, ParamGame #include "param.h" // Para Param, param, ParamResource, ParamGame
#include "resource_helper.h" // Para ResourceHelper #include "resource_helper.h" // Para ResourceHelper
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "text.h" // Para Text #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_Music_t; // lines 11-11
struct JA_Sound_t; // lines 12-12 struct JA_Sound_t; // lines 12-12
// Helper para cargar archivos de audio desde pack o filesystem // Helper para cargar archivos de audio desde pack o filesystem
namespace { namespace {
std::string createTempAudioFile(const std::string &file_path, std::vector<std::string> &temp_files_tracker) { std::string createTempAudioFile(const std::string& file_path, std::vector<std::string>& temp_files_tracker) {
auto resource_data = ResourceHelper::loadFile(file_path); auto resource_data = ResourceHelper::loadFile(file_path);
if (!resource_data.empty()) { if (!resource_data.empty()) {
// Crear archivo temporal // Crear archivo temporal
@@ -42,7 +41,7 @@ std::string createTempAudioFile(const std::string &file_path, std::vector<std::s
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Cannot create temp file %s", temp_path.c_str()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Cannot create temp file %s", temp_path.c_str());
return file_path; return file_path;
} }
temp_file.write(reinterpret_cast<const char *>(resource_data.data()), resource_data.size()); temp_file.write(reinterpret_cast<const char*>(resource_data.data()), resource_data.size());
temp_file.close(); temp_file.close();
// Agregar a la lista de archivos temporales para limpieza posterior // Agregar a la lista de archivos temporales para limpieza posterior
@@ -57,7 +56,7 @@ std::string createTempAudioFile(const std::string &file_path, std::vector<std::s
// Declaraciones de funciones que necesitas implementar en otros archivos // Declaraciones de funciones que necesitas implementar en otros archivos
// Singleton // Singleton
Resource *Resource::instance = nullptr; Resource* Resource::instance = nullptr;
// Inicializa la instancia única del singleton con modo de carga // Inicializa la instancia única del singleton con modo de carga
void Resource::init(LoadingMode mode) { void Resource::init(LoadingMode mode) {
@@ -71,7 +70,7 @@ void Resource::destroy() {
} }
// Obtiene la instancia // Obtiene la instancia
auto Resource::get() -> Resource * { return Resource::instance; } auto Resource::get() -> Resource* { return Resource::instance; }
// Constructor con modo de carga // Constructor con modo de carga
Resource::Resource(LoadingMode mode) Resource::Resource(LoadingMode mode)
@@ -112,10 +111,10 @@ void Resource::loadTextFilesQuiet() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES (quiet load)"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES (quiet load)");
auto list = Asset::get()->getListByType(Asset::Type::FONT); auto list = Asset::get()->getListByType(Asset::Type::FONT);
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
// Buscar en nuestra lista y cargar directamente // Buscar en nuestra lista y cargar directamente
auto it = std::ranges::find_if(text_files_, [&name](const auto &t) { return t.name == name; }); auto it = std::ranges::find_if(text_files_, [&name](const auto& t) { return t.name == name; });
if (it != text_files_.end()) { if (it != text_files_.end()) {
it->text_file = Text::loadFile(l); it->text_file = Text::loadFile(l);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Text file loaded: %s", name.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Text file loaded: %s", name.c_str());
@@ -141,12 +140,12 @@ void Resource::loadEssentialTextures() {
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP); auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
for (const auto &file : texture_list) { for (const auto& file : texture_list) {
auto name = getFileName(file); auto name = getFileName(file);
// Solo cargar texturas esenciales // Solo cargar texturas esenciales
if (std::ranges::find(ESSENTIAL_TEXTURES, name) != ESSENTIAL_TEXTURES.end()) { if (std::ranges::find(ESSENTIAL_TEXTURES, name) != ESSENTIAL_TEXTURES.end()) {
// Buscar en nuestra lista y cargar // Buscar en nuestra lista y cargar
auto it = std::ranges::find_if(textures_, [&name](const auto &t) { return t.name == name; }); auto it = std::ranges::find_if(textures_, [&name](const auto& t) { return t.name == name; });
if (it != textures_.end()) { if (it != textures_.end()) {
it->texture = std::make_shared<Texture>(Screen::get()->getRenderer(), file); it->texture = std::make_shared<Texture>(Screen::get()->getRenderer(), file);
} }
@@ -161,35 +160,35 @@ void Resource::initResourceLists() {
// Inicializa lista de sonidos // Inicializa lista de sonidos
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND); auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
sounds_.clear(); sounds_.clear();
for (const auto &file : sound_list) { for (const auto& file : sound_list) {
sounds_.emplace_back(getFileName(file)); sounds_.emplace_back(getFileName(file));
} }
// Inicializa lista de músicas // Inicializa lista de músicas
auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC); auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
musics_.clear(); musics_.clear();
for (const auto &file : music_list) { for (const auto& file : music_list) {
musics_.emplace_back(getFileName(file)); musics_.emplace_back(getFileName(file));
} }
// Inicializa lista de texturas // Inicializa lista de texturas
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP); auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
textures_.clear(); textures_.clear();
for (const auto &file : texture_list) { for (const auto& file : texture_list) {
textures_.emplace_back(getFileName(file)); textures_.emplace_back(getFileName(file));
} }
// Inicializa lista de ficheros de texto // Inicializa lista de ficheros de texto
auto text_file_list = Asset::get()->getListByType(Asset::Type::FONT); auto text_file_list = Asset::get()->getListByType(Asset::Type::FONT);
text_files_.clear(); text_files_.clear();
for (const auto &file : text_file_list) { for (const auto& file : text_file_list) {
text_files_.emplace_back(getFileName(file)); text_files_.emplace_back(getFileName(file));
} }
// Inicializa lista de animaciones // Inicializa lista de animaciones
auto animation_list = Asset::get()->getListByType(Asset::Type::ANIMATION); auto animation_list = Asset::get()->getListByType(Asset::Type::ANIMATION);
animations_.clear(); animations_.clear();
for (const auto &file : animation_list) { for (const auto& file : animation_list) {
animations_.emplace_back(getFileName(file)); animations_.emplace_back(getFileName(file));
} }
@@ -212,7 +211,7 @@ void Resource::initResourceLists() {
"smb2_grad"}; "smb2_grad"};
texts_.clear(); texts_.clear();
for (const auto &text_name : TEXT_OBJECTS) { for (const auto& text_name : TEXT_OBJECTS) {
texts_.emplace_back(text_name); // Constructor con nullptr por defecto texts_.emplace_back(text_name); // Constructor con nullptr por defecto
} }
@@ -220,8 +219,8 @@ void Resource::initResourceLists() {
} }
// Obtiene el sonido a partir de un nombre (con carga perezosa) // Obtiene el sonido a partir de un nombre (con carga perezosa)
auto Resource::getSound(const std::string &name) -> JA_Sound_t * { auto Resource::getSound(const std::string& name) -> JA_Sound_t* {
auto it = std::ranges::find_if(sounds_, [&name](const auto &s) { return s.name == name; }); auto it = std::ranges::find_if(sounds_, [&name](const auto& s) { return s.name == name; });
if (it != sounds_.end()) { if (it != sounds_.end()) {
// Si está en modo lazy y no se ha cargado aún, lo carga ahora // Si está en modo lazy y no se ha cargado aún, lo carga ahora
@@ -236,8 +235,8 @@ auto Resource::getSound(const std::string &name) -> JA_Sound_t * {
} }
// Obtiene la música a partir de un nombre (con carga perezosa) // Obtiene la música a partir de un nombre (con carga perezosa)
auto Resource::getMusic(const std::string &name) -> JA_Music_t * { auto Resource::getMusic(const std::string& name) -> JA_Music_t* {
auto it = std::ranges::find_if(musics_, [&name](const auto &m) { return m.name == name; }); auto it = std::ranges::find_if(musics_, [&name](const auto& m) { return m.name == name; });
if (it != musics_.end()) { if (it != musics_.end()) {
// Si está en modo lazy y no se ha cargado aún, lo carga ahora // Si está en modo lazy y no se ha cargado aún, lo carga ahora
@@ -252,8 +251,8 @@ auto Resource::getMusic(const std::string &name) -> JA_Music_t * {
} }
// Obtiene la textura a partir de un nombre (con carga perezosa) // Obtiene la textura a partir de un nombre (con carga perezosa)
auto Resource::getTexture(const std::string &name) -> std::shared_ptr<Texture> { auto Resource::getTexture(const std::string& name) -> std::shared_ptr<Texture> {
auto it = std::ranges::find_if(textures_, [&name](const auto &t) { return t.name == name; }); auto it = std::ranges::find_if(textures_, [&name](const auto& t) { return t.name == name; });
if (it != textures_.end()) { if (it != textures_.end()) {
// Si está en modo lazy y no se ha cargado aún, lo carga ahora // Si está en modo lazy y no se ha cargado aún, lo carga ahora
@@ -268,8 +267,8 @@ auto Resource::getTexture(const std::string &name) -> std::shared_ptr<Texture> {
} }
// Obtiene el fichero de texto a partir de un nombre (con carga perezosa) // Obtiene el fichero de texto a partir de un nombre (con carga perezosa)
auto Resource::getTextFile(const std::string &name) -> std::shared_ptr<Text::File> { auto Resource::getTextFile(const std::string& name) -> std::shared_ptr<Text::File> {
auto it = std::ranges::find_if(text_files_, [&name](const auto &t) { return t.name == name; }); auto it = std::ranges::find_if(text_files_, [&name](const auto& t) { return t.name == name; });
if (it != text_files_.end()) { if (it != text_files_.end()) {
// Si está en modo lazy y no se ha cargado aún, lo carga ahora // Si está en modo lazy y no se ha cargado aún, lo carga ahora
@@ -284,8 +283,8 @@ auto Resource::getTextFile(const std::string &name) -> std::shared_ptr<Text::Fil
} }
// Obtiene el objeto de texto a partir de un nombre (con carga perezosa) // Obtiene el objeto de texto a partir de un nombre (con carga perezosa)
auto Resource::getText(const std::string &name) -> std::shared_ptr<Text> { auto Resource::getText(const std::string& name) -> std::shared_ptr<Text> {
auto it = std::ranges::find_if(texts_, [&name](const auto &t) { return t.name == name; }); auto it = std::ranges::find_if(texts_, [&name](const auto& t) { return t.name == name; });
if (it != texts_.end()) { if (it != texts_.end()) {
// Si está en modo lazy y no se ha cargado aún, lo carga ahora // Si está en modo lazy y no se ha cargado aún, lo carga ahora
@@ -300,8 +299,8 @@ auto Resource::getText(const std::string &name) -> std::shared_ptr<Text> {
} }
// Obtiene la animación a partir de un nombre (con carga perezosa) // Obtiene la animación a partir de un nombre (con carga perezosa)
auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & { auto Resource::getAnimation(const std::string& name) -> AnimationsFileBuffer& {
auto it = std::ranges::find_if(animations_, [&name](const auto &a) { return a.name == name; }); auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
if (it != animations_.end()) { if (it != animations_.end()) {
// Si está en modo lazy y no se ha cargado aún (vector vacío), lo carga ahora // Si está en modo lazy y no se ha cargado aún (vector vacío), lo carga ahora
@@ -316,44 +315,45 @@ auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & {
} }
// Obtiene el fichero con los datos para el modo demostración a partir de un índice // Obtiene el fichero con los datos para el modo demostración a partir de un índice
auto Resource::getDemoData(int index) -> DemoData & { 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); return demos_.at(index);
} }
// --- Métodos de carga perezosa --- // --- Métodos de carga perezosa ---
auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * { auto Resource::loadSoundLazy(const std::string& name) -> JA_Sound_t* {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading sound lazily: %s", name.c_str()); 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); auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
for (const auto &file : sound_list) { for (const auto& file : sound_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
std::string audio_path = createTempAudioFile(file, Resource::get()->temp_audio_files_); std::string audio_path = createTempAudioFile(file, Resource::get()->temp_audio_files_);
return JA_LoadSound(audio_path.c_str()); return JA_LoadSound(audio_path.c_str());
} }
} }
#endif
return nullptr; return nullptr;
} }
auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * { auto Resource::loadMusicLazy(const std::string& name) -> JA_Music_t* {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading music lazily: %s", name.c_str()); 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); auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
for (const auto &file : music_list) { for (const auto& file : music_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
std::string audio_path = createTempAudioFile(file, Resource::get()->temp_audio_files_); std::string audio_path = createTempAudioFile(file, Resource::get()->temp_audio_files_);
return JA_LoadMusic(audio_path.c_str()); return JA_LoadMusic(audio_path.c_str());
} }
} }
#endif
return nullptr; return nullptr;
} }
auto Resource::loadTextureLazy(const std::string &name) -> std::shared_ptr<Texture> { auto Resource::loadTextureLazy(const std::string& name) -> std::shared_ptr<Texture> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading texture lazily: %s", name.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading texture lazily: %s", name.c_str());
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP); auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
for (const auto &file : texture_list) { for (const auto& file : texture_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
return std::make_shared<Texture>(Screen::get()->getRenderer(), file); return std::make_shared<Texture>(Screen::get()->getRenderer(), file);
} }
@@ -361,10 +361,10 @@ auto Resource::loadTextureLazy(const std::string &name) -> std::shared_ptr<Textu
return nullptr; return nullptr;
} }
auto Resource::loadTextFileLazy(const std::string &name) -> std::shared_ptr<Text::File> { auto Resource::loadTextFileLazy(const std::string& name) -> std::shared_ptr<Text::File> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text file lazily: %s", name.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text file lazily: %s", name.c_str());
auto text_file_list = Asset::get()->getListByType(Asset::Type::FONT); auto text_file_list = Asset::get()->getListByType(Asset::Type::FONT);
for (const auto &file : text_file_list) { for (const auto& file : text_file_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
return Text::loadFile(file); return Text::loadFile(file);
} }
@@ -372,7 +372,7 @@ auto Resource::loadTextFileLazy(const std::string &name) -> std::shared_ptr<Text
return nullptr; return nullptr;
} }
auto Resource::loadTextLazy(const std::string &name) -> std::shared_ptr<Text> { auto Resource::loadTextLazy(const std::string& name) -> std::shared_ptr<Text> {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text object lazily: %s", name.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading text object lazily: %s", name.c_str());
// Mapeo de objetos de texto a sus recursos // Mapeo de objetos de texto a sus recursos
@@ -396,7 +396,7 @@ auto Resource::loadTextLazy(const std::string &name) -> std::shared_ptr<Text> {
{.key = "smb2", .texture_file = "smb2.png", .text_file = "smb2.txt"}, {.key = "smb2", .texture_file = "smb2.png", .text_file = "smb2.txt"},
{.key = "smb2_grad", .texture_file = "smb2_grad.png", .text_file = "smb2.txt"}}; {.key = "smb2_grad", .texture_file = "smb2_grad.png", .text_file = "smb2.txt"}};
for (const auto &mapping : TEXT_MAPPINGS) { for (const auto& mapping : TEXT_MAPPINGS) {
if (mapping.key == name) { if (mapping.key == name) {
// Cargar las dependencias automáticamente // Cargar las dependencias automáticamente
auto texture = getTexture(mapping.texture_file); // Esto cargará la textura si no está cargada auto texture = getTexture(mapping.texture_file); // Esto cargará la textura si no está cargada
@@ -411,10 +411,10 @@ auto Resource::loadTextLazy(const std::string &name) -> std::shared_ptr<Text> {
return nullptr; return nullptr;
} }
auto Resource::loadAnimationLazy(const std::string &name) -> AnimationsFileBuffer { auto Resource::loadAnimationLazy(const std::string& name) -> AnimationsFileBuffer {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading animation lazily: %s", name.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading animation lazily: %s", name.c_str());
auto animation_list = Asset::get()->getListByType(Asset::Type::ANIMATION); auto animation_list = Asset::get()->getListByType(Asset::Type::ANIMATION);
for (const auto &file : animation_list) { for (const auto& file : animation_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
return loadAnimationsFromFile(file); return loadAnimationsFromFile(file);
} }
@@ -425,10 +425,8 @@ auto Resource::loadAnimationLazy(const std::string &name) -> AnimationsFileBuffe
// Vacia todos los vectores de recursos // Vacia todos los vectores de recursos
void Resource::clear() { void Resource::clear() {
#ifndef NO_AUDIO
clearSounds(); clearSounds();
clearMusics(); clearMusics();
#endif
textures_.clear(); textures_.clear();
text_files_.clear(); text_files_.clear();
texts_.clear(); texts_.clear();
@@ -443,15 +441,13 @@ void Resource::load() {
initProgressBar(); initProgressBar();
// Muerstra la ventana y desactiva el sincronismo vertical // Muerstra la ventana y desactiva el sincronismo vertical
auto *screen = Screen::get(); auto* screen = Screen::get();
auto vsync = Screen::getVSync(); auto vsync = Screen::getVSync();
screen->setVSync(false); screen->setVSync(false);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
#ifndef NO_AUDIO
loadSounds(); // Carga sonidos loadSounds(); // Carga sonidos
loadMusics(); // Carga músicas loadMusics(); // Carga músicas
#endif
loadTextures(); // Carga texturas loadTextures(); // Carga texturas
loadTextFiles(); // Carga ficheros de texto loadTextFiles(); // Carga ficheros de texto
loadAnimations(); // Carga animaciones loadAnimations(); // Carga animaciones
@@ -481,15 +477,11 @@ void Resource::loadSounds() {
auto list = Asset::get()->getListByType(Asset::Type::SOUND); auto list = Asset::get()->getListByType(Asset::Type::SOUND);
sounds_.clear(); sounds_.clear();
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
#ifndef NO_AUDIO
std::string audio_path = createTempAudioFile(l, temp_audio_files_); std::string audio_path = createTempAudioFile(l, temp_audio_files_);
sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str())); sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str()));
#else
sounds_.emplace_back(name, nullptr);
#endif
printWithDots("Sound : ", name, "[ LOADED ]"); printWithDots("Sound : ", name, "[ LOADED ]");
} }
} }
@@ -500,15 +492,11 @@ void Resource::loadMusics() {
auto list = Asset::get()->getListByType(Asset::Type::MUSIC); auto list = Asset::get()->getListByType(Asset::Type::MUSIC);
musics_.clear(); musics_.clear();
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
#ifndef NO_AUDIO
std::string audio_path = createTempAudioFile(l, temp_audio_files_); std::string audio_path = createTempAudioFile(l, temp_audio_files_);
musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str())); musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str()));
#else
musics_.emplace_back(name, nullptr);
#endif
printWithDots("Music : ", name, "[ LOADED ]"); printWithDots("Music : ", name, "[ LOADED ]");
} }
} }
@@ -519,7 +507,7 @@ void Resource::loadTextures() {
auto list = Asset::get()->getListByType(Asset::Type::BITMAP); auto list = Asset::get()->getListByType(Asset::Type::BITMAP);
textures_.clear(); textures_.clear();
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
textures_.emplace_back(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)); textures_.emplace_back(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l));
@@ -532,7 +520,7 @@ void Resource::loadTextFiles() {
auto list = Asset::get()->getListByType(Asset::Type::FONT); auto list = Asset::get()->getListByType(Asset::Type::FONT);
text_files_.clear(); text_files_.clear();
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
text_files_.emplace_back(name, Text::loadFile(l)); text_files_.emplace_back(name, Text::loadFile(l));
@@ -545,7 +533,7 @@ void Resource::loadAnimations() {
auto list = Asset::get()->getListByType(Asset::Type::ANIMATION); auto list = Asset::get()->getListByType(Asset::Type::ANIMATION);
animations_.clear(); animations_.clear();
for (const auto &l : list) { for (const auto& l : list) {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
animations_.emplace_back(name, loadAnimationsFromFile(l)); animations_.emplace_back(name, loadAnimationsFromFile(l));
@@ -555,12 +543,13 @@ void Resource::loadAnimations() {
// Carga los datos para el modo demostración // Carga los datos para el modo demostración
void Resource::loadDemoData() { void Resource::loadDemoData() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES"); 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& l : list) {
auto name = getFileName(l);
for (const auto &file : DEMO_FILES) { updateLoadingProgress(name);
updateLoadingProgress(file); demos_.emplace_back(loadDemoDataFromFile(l));
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get(file)));
} }
} }
@@ -581,12 +570,12 @@ void Resource::createPlayerTextures() {
// Bucle principal // Bucle principal
for (size_t player_idx = 0; player_idx < players.size(); ++player_idx) { for (size_t player_idx = 0; player_idx < players.size(); ++player_idx) {
const auto &player = players[player_idx]; // Obtenemos el jugador actual const auto& player = players[player_idx]; // Obtenemos el jugador actual
// Encontrar el archivo original de la textura // Encontrar el archivo original de la textura
std::string texture_file_path; std::string texture_file_path;
auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP); auto texture_list = Asset::get()->getListByType(Asset::Type::BITMAP);
for (const auto &file : texture_list) { for (const auto& file : texture_list) {
if (getFileName(file) == player.base_texture) { if (getFileName(file) == player.base_texture) {
texture_file_path = file; texture_file_path = file;
break; break;
@@ -667,7 +656,7 @@ void Resource::createTextTextures() {
{"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")}}; {"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")}};
auto text1 = getText("04b_25_enhanced"); auto text1 = getText("04b_25_enhanced");
for (const auto &s : strings1) { for (const auto& s : strings1) {
textures_.emplace_back(s.name, text1->writeDXToTexture(Text::STROKE, s.text, -2, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color)); textures_.emplace_back(s.name, text1->writeDXToTexture(Text::STROKE, s.text, -2, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color));
printWithDots("Texture : ", s.name, "[ DONE ]"); printWithDots("Texture : ", s.name, "[ DONE ]");
} }
@@ -678,10 +667,11 @@ void Resource::createTextTextures() {
{"game_text_get_ready", Lang::getText("[GAME_TEXT] 7")}, {"game_text_get_ready", Lang::getText("[GAME_TEXT] 7")},
{"game_text_last_stage", Lang::getText("[GAME_TEXT] 3")}, {"game_text_last_stage", Lang::getText("[GAME_TEXT] 3")},
{"game_text_congratulations", Lang::getText("[GAME_TEXT] 1")}, {"game_text_congratulations", Lang::getText("[GAME_TEXT] 1")},
{"game_text_new_record", Lang::getText("[GAME_TEXT] NEW_RECORD")},
{"game_text_game_over", "Game Over"}}; {"game_text_game_over", "Game Over"}};
auto text2 = getText("04b_25_2x_enhanced"); auto text2 = getText("04b_25_2x_enhanced");
for (const auto &s : strings2) { for (const auto& s : strings2) {
textures_.emplace_back(s.name, text2->writeDXToTexture(Text::STROKE, s.text, -4, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color)); textures_.emplace_back(s.name, text2->writeDXToTexture(Text::STROKE, s.text, -4, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color));
printWithDots("Texture : ", s.name, "[ DONE ]"); printWithDots("Texture : ", s.name, "[ DONE ]");
} }
@@ -721,7 +711,7 @@ void Resource::createText() {
{"smb2", "smb2.png", "smb2.txt"}, {"smb2", "smb2.png", "smb2.txt"},
{"smb2_grad", "smb2_grad.png", "smb2.txt"}}; {"smb2_grad", "smb2_grad.png", "smb2.txt"}};
for (const auto &resource : resources) { for (const auto& resource : resources) {
if (!resource.white_texture_file.empty()) { if (!resource.white_texture_file.empty()) {
// Crear texto con textura blanca // Crear texto con textura blanca
texts_.emplace_back(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTexture(resource.white_texture_file), getTextFile(resource.text_file))); texts_.emplace_back(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTexture(resource.white_texture_file), getTextFile(resource.text_file)));
@@ -735,11 +725,9 @@ void Resource::createText() {
// Vacía el vector de sonidos y libera la memoria asociada // Vacía el vector de sonidos y libera la memoria asociada
void Resource::clearSounds() { void Resource::clearSounds() {
for (auto &sound : sounds_) { for (auto& sound : sounds_) {
if (sound.sound != nullptr) { if (sound.sound != nullptr) {
#ifndef NO_AUDIO
JA_DeleteSound(sound.sound); JA_DeleteSound(sound.sound);
#endif
sound.sound = nullptr; sound.sound = nullptr;
} }
} }
@@ -748,11 +736,9 @@ void Resource::clearSounds() {
// Vacía el vector de músicas y libera la memoria asociada // Vacía el vector de músicas y libera la memoria asociada
void Resource::clearMusics() { void Resource::clearMusics() {
for (auto &music : musics_) { for (auto& music : musics_) {
if (music.music != nullptr) { if (music.music != nullptr) {
#ifndef NO_AUDIO
JA_DeleteMusic(music.music); JA_DeleteMusic(music.music);
#endif
music.music = nullptr; music.music = nullptr;
} }
} }
@@ -770,7 +756,7 @@ void Resource::calculateTotalResources() {
Asset::Type::DEMODATA}; Asset::Type::DEMODATA};
size_t total = 0; size_t total = 0;
for (const auto &asset_type : ASSET_TYPES) { for (const auto& asset_type : ASSET_TYPES) {
auto list = Asset::get()->getListByType(asset_type); auto list = Asset::get()->getListByType(asset_type);
total += list.size(); total += list.size();
} }
@@ -781,8 +767,8 @@ void Resource::calculateTotalResources() {
// Muestra el progreso de carga en pantalla (barra y texto) // Muestra el progreso de carga en pantalla (barra y texto)
void Resource::renderProgress() { void Resource::renderProgress() {
// Obtiene la pantalla y el renderer // Obtiene la pantalla y el renderer
auto *screen = Screen::get(); auto* screen = Screen::get();
auto *renderer = screen->getRenderer(); auto* renderer = screen->getRenderer();
// Actualiza la lógica principal de la pantalla (input, etc.) // Actualiza la lógica principal de la pantalla (input, etc.)
screen->coreUpdate(); screen->coreUpdate();
@@ -808,6 +794,30 @@ void Resource::renderProgress() {
Lang::getText("[RESOURCE] LOADING") + " : " + loading_resource_name_, Lang::getText("[RESOURCE] LOADING") + " : " + loading_resource_name_,
param.resource.color); param.resource.color);
// 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 + 27,
std::to_string(screen->getDisplayMonitorWidth()) + "x" + std::to_string(screen->getDisplayMonitorHeight()),
param.resource.color);
loading_text_->writeColored(
X_PADDING,
Y_PADDING + 36,
std::to_string(screen->getDisplayMonitorRefreshRate()) + "Hz",
param.resource.color);
// Renderiza el frame en pantalla // Renderiza el frame en pantalla
screen->coreRender(); screen->coreRender();
} }
@@ -832,20 +842,16 @@ void Resource::checkEvents() {
// Carga los datos para el modo demostración (sin mostrar progreso) // Carga los datos para el modo demostración (sin mostrar progreso)
void Resource::loadDemoDataQuiet() { void Resource::loadDemoDataQuiet() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES (quiet load)"); 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& l : list) {
demos_.emplace_back(loadDemoDataFromFile(l));
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);
} }
} }
// Inicializa los rectangulos que definen la barra de progreso // Inicializa los rectangulos que definen la barra de progreso
void Resource::initProgressBar() { void Resource::initProgressBar() {
constexpr float X_PADDING = 20.0F;
constexpr float Y_PADDING = 20.0F;
constexpr float BAR_HEIGHT = 10.0F;
const float BAR_Y_POSITION = param.game.height - BAR_HEIGHT - Y_PADDING; const float BAR_Y_POSITION = param.game.height - BAR_HEIGHT - Y_PADDING;
const float WIRED_BAR_WIDTH = param.game.width - (X_PADDING * 2); const float WIRED_BAR_WIDTH = param.game.width - (X_PADDING * 2);
@@ -871,13 +877,13 @@ void Resource::updateProgressBar() {
// Limpia archivos temporales de audio // Limpia archivos temporales de audio
void Resource::cleanupTempAudioFiles() { void Resource::cleanupTempAudioFiles() {
for (const auto &temp_path : temp_audio_files_) { for (const auto& temp_path : temp_audio_files_) {
try { try {
if (std::filesystem::exists(temp_path)) { if (std::filesystem::exists(temp_path)) {
std::filesystem::remove(temp_path); std::filesystem::remove(temp_path);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Removed temp audio file: %s", temp_path.c_str()); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Removed temp audio file: %s", temp_path.c_str());
} }
} catch (const std::exception &e) { } catch (const std::exception& e) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to remove temp audio file %s: %s", temp_path.c_str(), e.what()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to remove temp audio file %s: %s", temp_path.c_str(), e.what());
} }
} }

View File

@@ -11,7 +11,7 @@
#include "animated_sprite.h" // Para AnimationsFileBuffer #include "animated_sprite.h" // Para AnimationsFileBuffer
#include "text.h" // Para Text, TextFile #include "text.h" // Para Text, TextFile
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para DemoData #include "demo.h" // Para DemoData
struct JA_Music_t; struct JA_Music_t;
struct JA_Sound_t; struct JA_Sound_t;
@@ -120,6 +120,11 @@ class Resource {
} }
}; };
// --- Constantes para la barra de progreso ---
static constexpr float X_PADDING = 20.0F;
static constexpr float Y_PADDING = 20.0F;
static constexpr float BAR_HEIGHT = 10.0F;
// --- Modo de carga --- // --- Modo de carga ---
LoadingMode loading_mode_; LoadingMode loading_mode_;

View File

@@ -86,10 +86,10 @@ void Screen::render() {
// Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes // Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes
void Screen::coreRender() { void Screen::coreRender() {
fps_.increment(); /*fps_.increment();
#ifdef _DEBUG #ifdef _DEBUG
renderInfo(); renderInfo();
#endif #endif*/
renderPresent(); // Renderiza el contenido del game_canvas_ renderPresent(); // Renderiza el contenido del game_canvas_
} }
@@ -155,16 +155,16 @@ auto Screen::incWindowSize() -> bool {
return false; return false;
} }
// Actualiza la lógica de la clase // Recibe deltaTime de las secciones y actualiza la lógica
void Screen::update() { void Screen::update(float delta_time) {
fps_.calculate(SDL_GetTicks()); fps_.calculate(SDL_GetTicks());
shake_effect_.update(src_rect_, dst_rect_); shake_effect_.update(src_rect_, dst_rect_, delta_time);
flash_effect_.update(); flash_effect_.update(delta_time);
if (service_menu_ != nullptr) { if (service_menu_ != nullptr) {
service_menu_->update(); service_menu_->update(delta_time);
} }
if (notifier_ != nullptr) { if (notifier_ != nullptr) {
notifier_->update(); notifier_->update(delta_time);
} }
Mouse::updateCursorVisibility(); Mouse::updateCursorVisibility();
} }
@@ -217,6 +217,10 @@ void Screen::renderInfo() {
// FPS // FPS
const std::string FPS_TEXT = std::to_string(fps_.last_value) + " 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)); 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 #endif
@@ -296,14 +300,25 @@ auto Screen::initSDLVideo() -> bool {
// Obtener información de la pantalla // Obtener información de la pantalla
getDisplayInfo(); 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")) { if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl")) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Warning: Failed to set OpenGL hint!"); "Warning: Failed to set OpenGL hint!");
} }
#endif
// Crear ventana // Crear ventana
#ifdef __APPLE__
SDL_WindowFlags window_flags = SDL_WINDOW_METAL;
#else
SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL; SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL;
#endif
if (Options::video.fullscreen) { if (Options::video.fullscreen) {
window_flags |= SDL_WINDOW_FULLSCREEN; window_flags |= SDL_WINDOW_FULLSCREEN;
} }
@@ -358,6 +373,13 @@ void Screen::getDisplayInfo() {
const auto *dm = SDL_GetCurrentDisplayMode(displays[0]); const auto *dm = SDL_GetCurrentDisplayMode(displays[0]);
// Guarda información del monitor en display_monitor_
const char *first_display_name = SDL_GetDisplayName(displays[0]);
display_monitor_.name = (first_display_name != nullptr) ? first_display_name : "Unknown";
display_monitor_.width = static_cast<int>(dm->w);
display_monitor_.height = static_cast<int>(dm->h);
display_monitor_.refresh_rate = static_cast<int>(dm->refresh_rate);
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla // Calcula el máximo factor de zoom que se puede aplicar a la pantalla
Options::window.max_zoom = std::min(dm->w / param.game.width, dm->h / param.game.height); Options::window.max_zoom = std::min(dm->w / param.game.width, dm->h / param.game.height);
Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom); Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);

View File

@@ -21,7 +21,7 @@ class Screen {
static auto get() -> Screen *; // Obtiene el puntero al objeto Screen static auto get() -> Screen *; // Obtiene el puntero al objeto Screen
// --- Métodos principales --- // --- Métodos principales ---
void update(); // Actualiza la lógica de la clase void update(float delta_time); // Recibe deltaTime de las secciones y actualiza la lógica
void coreUpdate(); // Actualiza los elementos mínimos void coreUpdate(); // Actualiza los elementos mínimos
void clean(Color color = Color(0x00, 0x00, 0x00)); // Limpia la pantalla void clean(Color color = Color(0x00, 0x00, 0x00)); // Limpia la pantalla
void start(); // Prepara para empezar a dibujar en la textura de juego void start(); // Prepara para empezar a dibujar en la textura de juego
@@ -38,8 +38,8 @@ class Screen {
void initShaders(); // Inicializa los shaders void initShaders(); // Inicializa los shaders
// --- Efectos visuales --- // --- Efectos visuales ---
void shake(int desp = 2, int delay = 3, int length = 8) { shake_effect_.enable(src_rect_, dst_rect_, desp, delay, length); } // Agita la pantalla void shake(int desp = 2, float delay_s = 0.05f, float duration_s = 0.133f) { shake_effect_.enable(src_rect_, dst_rect_, desp, delay_s, duration_s); } // Agita la pantalla (tiempo en segundos)
void flash(Color color, int length = 10, int delay = 0) { flash_effect_ = FlashEffect(true, length, delay, color); } // Pone la pantalla de color void flash(Color color, float duration_s = 0.167f, float delay_s = 0.0f) { flash_effect_ = FlashEffect(true, duration_s, delay_s, color); } // Pone la pantalla de color (tiempo en segundos)
void toggleShaders(); // Alterna entre activar y desactivar los shaders void toggleShaders(); // Alterna entre activar y desactivar los shaders
void toggleIntegerScale(); // Alterna entre activar y desactivar el escalado entero void toggleIntegerScale(); // Alterna entre activar y desactivar el escalado entero
void toggleVSync(); // Alterna entre activar y desactivar el V-Sync void toggleVSync(); // Alterna entre activar y desactivar el V-Sync
@@ -54,6 +54,12 @@ class Screen {
[[nodiscard]] static auto getVSync() -> bool { return Options::video.vsync; } // Obtiene el valor de V-Sync [[nodiscard]] static auto getVSync() -> bool { return Options::video.vsync; } // Obtiene el valor de V-Sync
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen [[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen
// --- Display Monitor getters ---
[[nodiscard]] auto getDisplayMonitorName() const -> std::string { return display_monitor_.name; }
[[nodiscard]] auto getDisplayMonitorWidth() const -> int { return display_monitor_.width; }
[[nodiscard]] auto getDisplayMonitorHeight() const -> int { return display_monitor_.height; }
[[nodiscard]] auto getDisplayMonitorRefreshRate() const -> int { return display_monitor_.refresh_rate; }
#ifdef _DEBUG #ifdef _DEBUG
// --- Debug --- // --- Debug ---
void toggleDebugInfo() { debug_info_.show = !debug_info_.show; } void toggleDebugInfo() { debug_info_.show = !debug_info_.show; }
@@ -65,6 +71,12 @@ class Screen {
static constexpr int WINDOWS_DECORATIONS = 35; // Decoraciones de la ventana static constexpr int WINDOWS_DECORATIONS = 35; // Decoraciones de la ventana
// --- Estructuras privadas --- // --- Estructuras privadas ---
struct DisplayMonitor {
std::string name;
int width;
int height;
int refresh_rate;
};
struct FPS { struct FPS {
Uint32 ticks{0}; // Tiempo en milisegundos desde que se comenzó a contar. Uint32 ticks{0}; // Tiempo en milisegundos desde que se comenzó a contar.
int frame_count{0}; // Número acumulado de frames en el intervalo. int frame_count{0}; // Número acumulado de frames en el intervalo.
@@ -82,48 +94,55 @@ class Screen {
} }
}; };
// Efecto de flash en pantalla: pinta la pantalla de un color durante unos frames // Efecto de flash en pantalla: pinta la pantalla de un color durante un tiempo
struct FlashEffect { struct FlashEffect {
bool enabled; // Indica si el efecto está activo bool enabled; // Indica si el efecto está activo
int length; // Duración total del efecto en frames float duration_s; // Duración total del efecto en segundos
int delay; // Retraso antes de mostrar el flash float delay_s; // Retraso antes de mostrar el flash en segundos
int counter; // Contador de frames restantes float timer_s; // Timer en segundos (contador decreciente)
Color color; // Color del flash Color color; // Color del flash
explicit FlashEffect(bool enabled = false, int length = 0, int delay = 0, Color color = Color(0xFF, 0xFF, 0xFF)) explicit FlashEffect(bool enabled = false, float duration_s = 0.0f, float delay_s = 0.0f, Color color = Color(0xFF, 0xFF, 0xFF))
: enabled(enabled), : enabled(enabled),
length(length), duration_s(duration_s),
delay(delay), delay_s(delay_s),
counter(length), timer_s(duration_s),
color(color) {} color(color) {}
void update() { (enabled && counter > 0) ? counter-- : static_cast<int>(enabled = false); } void update(float delta_time) {
[[nodiscard]] auto isRendarable() const -> bool { return enabled && counter < length - delay; } if (enabled && timer_s > 0.0f) {
timer_s -= delta_time;
if (timer_s <= 0.0f) {
enabled = false;
}
}
}
[[nodiscard]] auto isRendarable() const -> bool { return enabled && timer_s < duration_s - delay_s; }
}; };
// Efecto de sacudida/agitación de pantalla: mueve la imagen para simular un temblor // Efecto de sacudida/agitación de pantalla: mueve la imagen para simular un temblor
struct ShakeEffect { struct ShakeEffect {
int desp; // Desplazamiento máximo de la sacudida (en píxeles) int desp; // Desplazamiento máximo de la sacudida (en píxeles)
int delay; // Frames entre cada movimiento de sacudida float delay_s; // Segundos entre cada movimiento de sacudida
int counter; // Contador de frames para el siguiente movimiento float counter_s; // Timer para el siguiente movimiento (decreciente)
int length; // Duración total del efecto en frames float duration_s; // Duración total del efecto en segundos
int remaining; // Frames restantes de sacudida float remaining_s; // Tiempo restante de sacudida
int original_pos; // Posición original de la imagen (x) int original_pos; // Posición original de la imagen (x)
int original_width; // Ancho original de la imagen int original_width; // Ancho original de la imagen
bool enabled; // Indica si el efecto está activo bool enabled; // Indica si el efecto está activo
explicit ShakeEffect(bool en = false, int dp = 2, int dl = 3, int cnt = 0, int len = 8, int rem = 0, int orig_pos = 0, int orig_width = 800) explicit ShakeEffect(bool en = false, int dp = 2, float dl_s = 0.05f, float cnt_s = 0.0f, float len_s = 0.133f, float rem_s = 0.0f, int orig_pos = 0, int orig_width = 800)
: desp(dp), : desp(dp),
delay(dl), delay_s(dl_s),
counter(cnt), counter_s(cnt_s),
length(len), duration_s(len_s),
remaining(rem), remaining_s(rem_s),
original_pos(orig_pos), original_pos(orig_pos),
original_width(orig_width), original_width(orig_width),
enabled(en) {} enabled(en) {}
// Activa el efecto de sacudida y guarda la posición y tamaño originales // Activa el efecto de sacudida y guarda la posición y tamaño originales
void enable(SDL_FRect &src_rect, SDL_FRect &dst_rect, int new_desp = -1, int new_delay = -1, int new_length = -1) { void enable(SDL_FRect &src_rect, SDL_FRect &dst_rect, int new_desp = -1, float new_delay_s = -1.0f, float new_duration_s = -1.0f) {
if (!enabled) { if (!enabled) {
enabled = true; enabled = true;
original_pos = src_rect.x; original_pos = src_rect.x;
@@ -133,33 +152,35 @@ class Screen {
if (new_desp != -1) { if (new_desp != -1) {
desp = new_desp; desp = new_desp;
} }
if (new_delay != -1) { if (new_delay_s >= 0.0f) {
delay = new_delay; delay_s = new_delay_s;
} }
if (new_length != -1) { if (new_duration_s >= 0.0f) {
length = new_length; duration_s = new_duration_s;
} }
src_rect.w -= desp; src_rect.w -= desp;
dst_rect.w = src_rect.w; dst_rect.w = src_rect.w;
} }
remaining = length; remaining_s = duration_s;
counter = delay; counter_s = delay_s;
} }
// Actualiza el estado del efecto de sacudida // Actualiza el estado del efecto de sacudida
void update(SDL_FRect &src_rect, SDL_FRect &dst_rect) { void update(SDL_FRect &src_rect, SDL_FRect &dst_rect, float delta_time) {
if (enabled) { if (enabled) {
if (counter > 0) { counter_s -= delta_time;
counter--; if (counter_s <= 0.0f) {
} else { counter_s = delay_s;
counter = delay; // Alternar desplazamiento basado en tiempo restante
const auto SRC_DESP = (remaining % 2 == 0) ? 0 : desp; const bool SHAKE_LEFT = static_cast<int>(remaining_s * 30.0f) % 2 == 0; // ~30 cambios por segundo
const auto DST_DESP = (remaining % 2 == 1) ? 0 : desp; const auto SRC_DESP = SHAKE_LEFT ? 0 : desp;
const auto DST_DESP = SHAKE_LEFT ? desp : 0;
src_rect.x = original_pos + SRC_DESP; src_rect.x = original_pos + SRC_DESP;
dst_rect.x = original_pos + DST_DESP; dst_rect.x = original_pos + DST_DESP;
remaining--;
if (remaining == -1) { remaining_s -= delay_s;
if (remaining_s <= 0.0f) {
enabled = false; enabled = false;
src_rect.x = original_pos; src_rect.x = original_pos;
src_rect.w = original_width; src_rect.w = original_width;
@@ -197,6 +218,7 @@ class Screen {
FlashEffect flash_effect_; // Efecto de flash en pantalla FlashEffect flash_effect_; // Efecto de flash en pantalla
ShakeEffect shake_effect_; // Efecto de agitar la pantalla ShakeEffect shake_effect_; // Efecto de agitar la pantalla
bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada
DisplayMonitor display_monitor_; // Información del monitor actual
#ifdef _DEBUG #ifdef _DEBUG
Debug debug_info_; // Información de debug Debug debug_info_; // Información de debug
#endif #endif
@@ -209,7 +231,7 @@ class Screen {
void renderPresent(); // Selecciona y ejecuta el método de renderizado adecuado void renderPresent(); // Selecciona y ejecuta el método de renderizado adecuado
void loadShaders(); // Carga el contenido del archivo GLSL void loadShaders(); // Carga el contenido del archivo GLSL
void adjustWindowSize(); // Calcula el tamaño de la ventana void adjustWindowSize(); // Calcula el tamaño de la ventana
static void getDisplayInfo(); // Obtiene información sobre la pantalla void getDisplayInfo(); // Obtiene información sobre la pantalla
void renderOverlays(); // Renderiza todos los overlays y efectos void renderOverlays(); // Renderiza todos los overlays y efectos
void renderAttenuate(); // Atenúa la pantalla void renderAttenuate(); // Atenúa la pantalla
void createText(); // Crea el objeto de texto void createText(); // Crea el objeto de texto

View File

@@ -49,13 +49,13 @@ Credits::Credits()
fade_in_->setColor(param.fade.color); fade_in_->setColor(param.fade.color);
fade_in_->setType(Fade::Type::FULLSCREEN); fade_in_->setType(Fade::Type::FULLSCREEN);
fade_in_->setPostDuration(static_cast<int>(50 * (1000.0f / 60.0f))); // 50 frames = ~833ms fade_in_->setPostDuration(800);
fade_in_->setMode(Fade::Mode::IN); fade_in_->setMode(Fade::Mode::IN);
fade_in_->activate(); fade_in_->activate();
fade_out_->setColor(0, 0, 0); fade_out_->setColor(0, 0, 0);
fade_out_->setType(Fade::Type::FULLSCREEN); fade_out_->setType(Fade::Type::FULLSCREEN);
fade_out_->setPostDuration(static_cast<int>(400 * (1000.0f / 60.0f))); // 400 frames = ~6667ms fade_out_->setPostDuration(7000);
updateRedRect(); updateRedRect();
tiled_bg_->setColor(Color(255, 96, 96)); tiled_bg_->setColor(Color(255, 96, 96));
@@ -105,6 +105,10 @@ void Credits::update(float deltaTime) {
const float multiplier = want_to_pass_ ? 4.0f : 1.0f; const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
const float adjusted_delta_time = deltaTime * multiplier; const float adjusted_delta_time = deltaTime * multiplier;
static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
tiled_bg_->update(adjusted_delta_time); tiled_bg_->update(adjusted_delta_time);
cycleColors(); cycleColors();
balloon_manager_->update(adjusted_delta_time); balloon_manager_->update(adjusted_delta_time);
@@ -117,9 +121,7 @@ void Credits::update(float deltaTime) {
const float frameFactor = adjusted_delta_time * 60.0f; const float frameFactor = adjusted_delta_time * 60.0f;
counter_ += frameFactor; counter_ += frameFactor;
Screen::get()->update();
fillCanvas(); fillCanvas();
Audio::update();
} }
// Dibuja Credits::en patalla // Dibuja Credits::en patalla
@@ -291,11 +293,10 @@ void Credits::fillCanvas() {
// Actualiza el destino de los rectangulos de las texturas (time-based) // Actualiza el destino de los rectangulos de las texturas (time-based)
void Credits::updateTextureDstRects(float deltaTime) { void Credits::updateTextureDstRects(float deltaTime) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames) constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
static float texture_accumulator = 0.0f; credits_state_.texture_accumulator += deltaTime;
texture_accumulator += deltaTime;
if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) { if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
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 // Comprueba la posición de la textura con los titulos de credito
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) { if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
@@ -334,20 +335,17 @@ void Credits::throwBalloons(float deltaTime) {
return; return;
} }
static float balloon_accumulator = 0.0f; credits_state_.balloon_accumulator += deltaTime;
static float powerball_accumulator = 0.0f; credits_state_.powerball_accumulator += deltaTime;
balloon_accumulator += deltaTime; if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
powerball_accumulator += deltaTime; credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
if (balloon_accumulator >= BALLOON_INTERVAL_S) {
balloon_accumulator -= BALLOON_INTERVAL_S;
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size(); const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
balloon_manager_->deployFormation(SETS.at(INDEX), -60); balloon_manager_->deployFormation(SETS.at(INDEX), -60);
} }
if (powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) { if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
powerball_accumulator -= POWERBALL_INTERVAL_S; credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S;
balloon_manager_->createPowerBall(); balloon_manager_->createPowerBall();
} }
} }
@@ -423,13 +421,11 @@ void Credits::initPlayers() {
void Credits::updateBlackRects(float deltaTime) { void Credits::updateBlackRects(float deltaTime) {
static float current_step_ = static_cast<float>(steps_); static float current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames) 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) { 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 // Si los rectangulos superior e inferior no han llegado al centro
black_rect_accumulator += deltaTime; credits_state_.black_rect_accumulator += deltaTime;
if (black_rect_accumulator >= BLACK_RECT_INTERVAL_S) { if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
black_rect_accumulator -= BLACK_RECT_INTERVAL_S; credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
// Incrementa la altura del rectangulo superior // Incrementa la altura del rectangulo superior
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1); top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
@@ -485,12 +481,12 @@ void Credits::updateAllFades(float deltaTime) {
updateRedRect(); updateRedRect();
} }
fade_in_->update(); // Fade ya usa tiempo interno fade_in_->update();
if (fade_in_->hasEnded()) { if (fade_in_->hasEnded() && Audio::get()->getMusicState() != Audio::MusicState::PLAYING) {
Audio::get()->playMusic("credits.ogg"); Audio::get()->playMusic("credits.ogg");
} }
fade_out_->update(); // Fade ya usa tiempo interno fade_out_->update();
if (fade_out_->hasEnded()) { if (fade_out_->hasEnded()) {
Section::name = Section::Name::HI_SCORE_TABLE; Section::name = Section::Name::HI_SCORE_TABLE;
} }
@@ -513,33 +509,33 @@ void Credits::cycleColors() {
constexpr int UPPER_LIMIT = 140; // Límite superior constexpr int UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior constexpr int LOWER_LIMIT = 30; // Límite inferior
static auto r_ = static_cast<float>(UPPER_LIMIT); // Inicializar valores RGB si es la primera vez
static auto g_ = static_cast<float>(LOWER_LIMIT); if (credits_state_.r == 255.0f && credits_state_.g == 0.0f && credits_state_.b == 0.0f && credits_state_.step_r == -0.5f) {
static auto b_ = static_cast<float>(LOWER_LIMIT); credits_state_.r = static_cast<float>(UPPER_LIMIT);
static float step_r_ = -0.5F; // Paso flotante para transiciones suaves credits_state_.g = static_cast<float>(LOWER_LIMIT);
static float step_g_ = 0.3F; credits_state_.b = static_cast<float>(LOWER_LIMIT);
static float step_b_ = 0.1F; }
// Ajustar valores de R // Ajustar valores de R
r_ += step_r_; credits_state_.r += credits_state_.step_r;
if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) { if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) {
step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites
} }
// Ajustar valores de G // Ajustar valores de G
g_ += step_g_; credits_state_.g += credits_state_.step_g;
if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) { if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) {
step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites
} }
// Ajustar valores de B // Ajustar valores de B
b_ += step_b_; credits_state_.b += credits_state_.step_b;
if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) { if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) {
step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites 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 // 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_); tiled_bg_->setColor(color_);
} }

View File

@@ -65,6 +65,20 @@ class Credits {
int initial_volume_ = Options::audio.music.volume; // Volumen inicial int initial_volume_ = Options::audio.music.volume; // Volumen inicial
int steps_ = 0; // Pasos para reducir audio 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 --- // --- Rectángulos de renderizado ---
// Texto de créditos // Texto de créditos
SDL_FRect credits_rect_src_ = param.game.game_area.rect; SDL_FRect credits_rect_src_ = param.game.game_area.rect;

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
#include "bullet.h" // Para Bullet
#include "hit.h" // Para Hit #include "hit.h" // Para Hit
#include "item.h" // Para Item, ItemType #include "item.h" // Para Item, ItemType
#include "manage_hiscore_table.h" // Para HiScoreEntry #include "manage_hiscore_table.h" // Para HiScoreEntry
@@ -14,7 +15,8 @@
#include "player.h" // Para Player #include "player.h" // Para Player
#include "smart_sprite.h" // Para SmartSprite #include "smart_sprite.h" // Para SmartSprite
#include "stage.h" // Para StageManager #include "stage.h" // Para StageManager
#include "utils.h" // Para Demo #include "demo.h" // Para Demo
#include "utils.h" // Para otras utilidades
class Background; class Background;
class Balloon; class Balloon;
@@ -27,7 +29,6 @@ class Scoreboard;
class Screen; class Screen;
class Tabe; class Tabe;
class Texture; class Texture;
enum class BulletType : Uint8;
namespace Difficulty { namespace Difficulty {
enum class Code; enum class Code;
@@ -56,7 +57,7 @@ class Game {
static constexpr bool DEMO_ON = true; // Modo demo activado static constexpr bool DEMO_ON = true; // Modo demo activado
// --- Constructor y destructor --- // --- 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 ~Game(); // Destructor
// --- Bucle principal --- // --- Bucle principal ---
@@ -77,9 +78,9 @@ class Game {
static constexpr float HELP_COUNTER_S = 16.667f; // Contador de ayuda (1000 frames a 60fps → segundos) static constexpr float HELP_COUNTER_S = 16.667f; // Contador de ayuda (1000 frames a 60fps → segundos)
static constexpr float GAME_COMPLETED_START_FADE_S = 8.333f; // Inicio del fade al completar (500 frames → segundos) static constexpr float GAME_COMPLETED_START_FADE_S = 8.333f; // Inicio del fade al completar (500 frames → segundos)
static constexpr float GAME_COMPLETED_END_S = 11.667f; // Fin del juego completado (700 frames → segundos) static constexpr float GAME_COMPLETED_END_S = 11.667f; // Fin del juego completado (700 frames → segundos)
static constexpr float GAME_OVER_DURATION_S = 5.833f; // Duración game over (350 frames → segundos) static constexpr float GAME_OVER_DURATION_S = 8.5f;
static constexpr float TIME_STOPPED_DURATION_S = 6.0f; // Duración del tiempo detenido (360 frames → segundos) static constexpr float TIME_STOPPED_DURATION_S = 6.0f;
static constexpr float DEMO_FADE_PRE_DURATION_S = 0.5f; // Pre-duración del fade en modo demo static constexpr float DEMO_FADE_PRE_DURATION_S = 0.5f;
static constexpr int ITEM_POINTS_1_DISK_ODDS = 10; static constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
static constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6; static constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
static constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3; static constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
@@ -112,12 +113,12 @@ class Game {
}; };
// --- Objetos y punteros --- // --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer* renderer_; // El renderizador de la ventana
Screen *screen_; // Objeto encargado de dibujar en pantalla Screen* screen_; // Objeto encargado de dibujar en pantalla
Input *input_; // Manejador de entrada Input* input_; // Manejador de entrada
Scoreboard *scoreboard_; // Objeto para dibujar el marcador Scoreboard* scoreboard_; // Objeto para dibujar el marcador
SDL_Texture *canvas_; // Textura para dibujar la zona de juego SDL_Texture* canvas_; // Textura para dibujar la zona de juego
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
std::vector<std::shared_ptr<Bullet>> bullets_; // Vector con las balas std::vector<std::shared_ptr<Bullet>> bullets_; // Vector con las balas
@@ -165,6 +166,39 @@ class Game {
std::vector<std::shared_ptr<Player>> players_to_put_at_front_; std::vector<std::shared_ptr<Player>> players_to_put_at_front_;
Hit hit_; // Para representar colisiones en pantalla 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 #ifdef _DEBUG
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
#endif #endif
@@ -185,7 +219,7 @@ class Game {
void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado" void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado"
void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo
void updateGameStateCompleted(float deltaTime); // Gestiona el estado de juego completado 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 --- // --- Gestión de jugadores ---
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
@@ -203,9 +237,9 @@ class Game {
auto allPlayersAreNotPlaying() -> bool; // Verifica si ningún jugador está activo auto allPlayersAreNotPlaying() -> bool; // Verifica si ningún jugador está activo
// --- Colisiones de jugadores --- // --- Colisiones de jugadores ---
void handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_ptr<Balloon> &balloon); // Procesa colisión de jugador con globo void handlePlayerCollision(std::shared_ptr<Player>& player, std::shared_ptr<Balloon>& balloon); // Procesa colisión de jugador con globo
auto checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon>; // Detecta colisión jugador-globo auto checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon>; // Detecta colisión jugador-globo
void checkPlayerItemCollision(std::shared_ptr<Player> &player); // Detecta colisión jugador-ítem void checkPlayerItemCollision(std::shared_ptr<Player>& player); // Detecta colisión jugador-ítem
// --- Sistema de entrada (input) --- // --- Sistema de entrada (input) ---
void checkInput(); // Gestiona toda la entrada durante el juego void checkInput(); // Gestiona toda la entrada durante el juego
@@ -213,29 +247,29 @@ class Game {
// --- Entrada de jugadores normales --- // --- Entrada de jugadores normales ---
void handlePlayersInput(); // Gestiona entrada de todos los jugadores void handlePlayersInput(); // Gestiona entrada de todos los jugadores
void handleNormalPlayerInput(const std::shared_ptr<Player> &player); // Procesa entrada de un jugador específico void handleNormalPlayerInput(const std::shared_ptr<Player>& player); // Procesa entrada de un jugador específico
void handleFireInput(const std::shared_ptr<Player> &player, BulletType bullet_type); // Gestiona disparo de jugador void handleFireInput(const std::shared_ptr<Player>& player, Bullet::Type type); // Gestiona disparo de jugador
void handleFireInputs(const std::shared_ptr<Player> &player, bool autofire); // Procesa disparos automáticos void handleFireInputs(const std::shared_ptr<Player>& player, bool autofire); // Procesa disparos automáticos
void handlePlayerContinueInput(const std::shared_ptr<Player> &player); // Permite continuar al jugador void handlePlayerContinueInput(const std::shared_ptr<Player>& player); // Permite continuar al jugador
void handlePlayerWaitingInput(const std::shared_ptr<Player> &player); // Permite (re)entrar al jugador void handlePlayerWaitingInput(const std::shared_ptr<Player>& player); // Permite (re)entrar al jugador
void handleNameInput(const std::shared_ptr<Player> &player); // Gestiona entrada de nombre del jugador void handleNameInput(const std::shared_ptr<Player>& player); // Gestiona entrada de nombre del jugador
// --- Entrada en modo demo --- // --- Entrada en modo demo ---
void demoHandleInput(); // Gestiona entrada durante el modo demostración void demoHandleInput(); // Gestiona entrada durante el modo demostración
void demoHandlePassInput(); // Permite saltar la demostración void demoHandlePassInput(); // Permite saltar la demostración
void demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa entrada de jugador en demo void demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index); // Procesa entrada de jugador en demo
// --- Sistema de balas y proyectiles --- // --- Sistema de balas y proyectiles ---
void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based) void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based)
void renderBullets(); // Renderiza todas las balas activas void renderBullets(); // Renderiza todas las balas activas
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala void createBullet(int x, int y, Bullet::Type kind, Bullet::Color color, int owner); // Crea una nueva bala
void checkBulletCollision(); // Verifica colisiones de todas las balas void checkBulletCollision(); // Verifica colisiones de todas las balas
void freeBullets(); // Libera memoria del vector de balas void freeBullets(); // Libera memoria del vector de balas
// --- Colisiones específicas de balas --- // --- Colisiones específicas de balas ---
auto checkBulletTabeCollision(const std::shared_ptr<Bullet> &bullet) -> bool; // Detecta colisión bala-Tabe auto checkBulletTabeCollision(const std::shared_ptr<Bullet>& bullet) -> bool; // Detecta colisión bala-Tabe
auto checkBulletBalloonCollision(const std::shared_ptr<Bullet> &bullet) -> bool; // Detecta colisión bala-globo auto checkBulletBalloonCollision(const std::shared_ptr<Bullet>& bullet) -> bool; // Detecta colisión bala-globo
void processBalloonHit(const std::shared_ptr<Bullet> &bullet, const std::shared_ptr<Balloon> &balloon); // Procesa impacto en globo void processBalloonHit(const std::shared_ptr<Bullet>& bullet, const std::shared_ptr<Balloon>& balloon); // Procesa impacto en globo
// --- Sistema de ítems y power-ups --- // --- Sistema de ítems y power-ups ---
void updateItems(float deltaTime); // Actualiza posición y estado de todos los ítems void updateItems(float deltaTime); // Actualiza posición y estado de todos los ítems
@@ -250,11 +284,11 @@ class Game {
void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo
void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido
void handleGameCompletedEvents(); // Maneja eventos del juego completado 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 void throwCoffee(int x, int y); // Crea efecto de café arrojado al ser golpeado
// --- Gestión de caída de ítems --- // --- Gestión de caída de ítems ---
void handleItemDrop(const std::shared_ptr<Balloon> &balloon, const std::shared_ptr<Player> &player); // Gestiona caída de ítem desde globo void handleItemDrop(const std::shared_ptr<Balloon>& balloon, const std::shared_ptr<Player>& player); // Gestiona caída de ítem desde globo
// --- Sprites inteligentes (smartsprites) --- // --- Sprites inteligentes (smartsprites) ---
void updateSmartSprites(float deltaTime); // Actualiza todos los sprites con lógica propia (time-based) void updateSmartSprites(float deltaTime); // Actualiza todos los sprites con lógica propia (time-based)
@@ -268,11 +302,11 @@ class Game {
void initPaths(); // Inicializa rutas predefinidas para animaciones void initPaths(); // Inicializa rutas predefinidas para animaciones
// --- Creación de sprites especiales --- // --- Creación de sprites especiales ---
void createItemText(int x, const std::shared_ptr<Texture> &texture); // Crea texto animado para ítems void createItemText(int x, const std::shared_ptr<Texture>& texture); // Crea texto animado para ítems
void createMessage(const std::vector<Path> &paths, const std::shared_ptr<Texture> &texture); // Crea mensaje con animación por ruta void createMessage(const std::vector<Path>& paths, const std::shared_ptr<Texture>& texture); // Crea mensaje con animación por ruta
// --- Sistema de globos y enemigos --- // --- Sistema de globos y enemigos ---
void handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std::shared_ptr<Player> &player); // Procesa destrucción de globo void handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std::shared_ptr<Player>& player); // Procesa destrucción de globo
void handleTabeHitEffects(); // Gestiona efectos al golpear a Tabe void handleTabeHitEffects(); // Gestiona efectos al golpear a Tabe
void checkAndUpdateBalloonSpeed(); // Ajusta velocidad de globos según progreso void checkAndUpdateBalloonSpeed(); // Ajusta velocidad de globos según progreso
@@ -292,7 +326,7 @@ class Game {
// --- Modo demostración --- // --- Modo demostración ---
void initDemo(Player::Id player_id); // Inicializa variables para el 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 --- // --- Recursos y renderizado ---
void setResources(); // Asigna texturas y animaciones a los objetos void setResources(); // Asigna texturas y animaciones a los objetos
@@ -301,23 +335,23 @@ class Game {
void updateHelper(); // Actualiza variables auxiliares de renderizado void updateHelper(); // Actualiza variables auxiliares de renderizado
// --- Sistema de audio --- // --- Sistema de audio ---
static void playMusic(); // Reproduce la música de fondo static void playMusic(const std::string& music_file, int loop = -1); // Reproduce la música de fondo
void stopMusic() const; // Detiene la reproducción de música void stopMusic() const; // Detiene la reproducción de música
static void pauseMusic(); // Pausa la música static void pauseMusic(); // Pausa la música
static void resumeMusic(); // Retoma la música que eestaba pausada static void resumeMusic(); // Retoma la música que eestaba pausada
void playSound(const std::string &name) const; // Reproduce un efecto de sonido específico void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
void sendPlayerToTheBack(const std::shared_ptr<Player> &player); // Mueve el jugador para pintarlo al fondo de la lista de jugadores void sendPlayerToTheBack(const std::shared_ptr<Player>& player); // Mueve el jugador para pintarlo al fondo de la lista de jugadores
void sendPlayerToTheFront(const std::shared_ptr<Player> &player); // Mueve el jugador para pintarlo el primero de la lista de jugadores void sendPlayerToTheFront(const std::shared_ptr<Player>& player); // Mueve el jugador para pintarlo el primero de la lista de jugadores
void onPauseStateChanged(bool is_paused); void onPauseStateChanged(bool is_paused);
// SISTEMA DE GRABACIÓN (CONDICIONAL) // SISTEMA DE GRABACIÓN (CONDICIONAL)
#ifdef RECORDING #ifdef RECORDING
void updateRecording(); // Actualiza variables durante modo de grabación void updateRecording(float deltaTime); // Actualiza variables durante modo de grabación
#endif #endif
// --- Depuración (solo en modo DEBUG) --- // --- Depuración (solo en modo DEBUG) ---
#ifdef _DEBUG #ifdef _DEBUG
void handleDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos en el modo DEBUG
#endif #endif
}; };

View File

@@ -55,15 +55,16 @@ HiScoreTable::~HiScoreTable() {
// Actualiza las variables // Actualiza las variables
void HiScoreTable::update(float delta_time) { void HiScoreTable::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto
background_->update(delta_time); // Actualiza el fondo background_->update(delta_time); // Actualiza el fondo
updateFade(delta_time); // Gestiona el fade updateFade(delta_time); // Gestiona el fade
updateCounter(); // Gestiona el contador y sus eventos updateCounter(); // Gestiona el contador y sus eventos
fillTexture(); // Dibuja los sprites en la textura fillTexture(); // Dibuja los sprites en la textura
Audio::update();
} }
// Pinta en pantalla // Pinta en pantalla
@@ -367,17 +368,14 @@ void HiScoreTable::glowEntryNames() {
// Gestiona el contador // Gestiona el contador
void HiScoreTable::updateCounter() { void HiScoreTable::updateCounter() {
static bool background_changed = false; if (elapsed_time_ >= BACKGROUND_CHANGE_S && !hiscore_flags_.background_changed) {
static bool fade_activated = false;
if (elapsed_time_ >= BACKGROUND_CHANGE_S && !background_changed) {
background_->setColor(background_fade_color_.DARKEN()); background_->setColor(background_fade_color_.DARKEN());
background_->setAlpha(96); 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_->activate();
fade_activated = true; hiscore_flags_.fade_activated = true;
} }
} }

View File

@@ -56,6 +56,17 @@ class HiScoreTable {
Color background_fade_color_; // Color de atenuación del fondo Color background_fade_color_; // Color de atenuación del fondo
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla 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 --- // --- Métodos internos ---
void update(float delta_time); // Actualiza las variables void update(float delta_time); // Actualiza las variables
void render(); // Pinta en pantalla void render(); // Pinta en pantalla

View File

@@ -14,6 +14,7 @@
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "input.h" // Para Input #include "input.h" // Para Input
#include "item.h" // Para Item
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade, Param... #include "param.h" // Para Param, param, ParamGame, ParamFade, Param...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
@@ -78,43 +79,43 @@ void Instructions::iniSprites() {
// Inicializa los sprites // Inicializa los sprites
for (int i = 0; i < (int)item_textures_.size(); ++i) { for (int i = 0; i < (int)item_textures_.size(); ++i) {
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size); 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 + ((param.game.item_size + item_space_) * i)}); sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((Item::HEIGHT + item_space_) * i)});
sprites_.push_back(std::move(sprite)); sprites_.push_back(std::move(sprite));
} }
} }
// Actualiza los sprites // Actualiza los sprites
void Instructions::updateSprites() { 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) // 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); sprites_[0]->setSpriteClip(src_rect);
// Gavina (desplazamiento 9/60 = 0.15s) // 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); sprites_[1]->setSpriteClip(src_rect);
// Pacmar (desplazamiento 6/60 = 0.1s) // 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); sprites_[2]->setSpriteClip(src_rect);
// Time Stopper (desplazamiento 3/60 = 0.05s) // 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); sprites_[3]->setSpriteClip(src_rect);
// Coffee (sin desplazamiento) // 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); sprites_[4]->setSpriteClip(src_rect);
} }
// Rellena la textura de texto // Rellena la textura de texto
void Instructions::fillTexture() { 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 // Modifica el renderizador para pintar en la textura
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_); SDL_SetRenderTarget(renderer_, texture_);
// Limpia la textura // Limpia la textura
@@ -130,7 +131,7 @@ void Instructions::fillTexture() {
constexpr int SPACE_POST_HEADER = 20; constexpr int SPACE_POST_HEADER = 20;
constexpr int SPACE_PRE_HEADER = 28; constexpr int SPACE_PRE_HEADER = 28;
const int SPACE_BETWEEN_LINES = text_->getCharacterSize() * 1.5F; 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 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); 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);
@@ -144,7 +145,7 @@ void Instructions::fillTexture() {
Lang::getText("[INSTRUCTIONS] 09"), Lang::getText("[INSTRUCTIONS] 09"),
Lang::getText("[INSTRUCTIONS] 10"), Lang::getText("[INSTRUCTIONS] 10"),
Lang::getText("[INSTRUCTIONS] 11")}; Lang::getText("[INSTRUCTIONS] 11")};
for (const auto &desc : ITEM_DESCRIPTIONS) { for (const auto& desc : ITEM_DESCRIPTIONS) {
const int L = text_->length(desc); const int L = text_->length(desc);
length = L > length ? L : length; length = L > length ? L : length;
} }
@@ -178,13 +179,13 @@ void Instructions::fillTexture() {
// Da valor a la variable // Da valor a la variable
sprite_pos_.x = ANCHOR_ITEM; 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 // Rellena el backbuffer
void Instructions::fillBackbuffer() { void Instructions::fillBackbuffer() {
// Modifica el renderizador para pintar en la textura // Modifica el renderizador para pintar en la textura
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// Limpia la textura // Limpia la textura
@@ -195,7 +196,7 @@ void Instructions::fillBackbuffer() {
SDL_RenderTexture(renderer_, texture_, nullptr, nullptr); SDL_RenderTexture(renderer_, texture_, nullptr, nullptr);
// Dibuja los sprites // Dibuja los sprites
for (auto &sprite : sprites_) { for (auto& sprite : sprites_) {
sprite->render(); sprite->render();
} }
@@ -206,20 +207,21 @@ void Instructions::fillBackbuffer() {
// Actualiza las variables // Actualiza las variables
void Instructions::update(float delta_time) { void Instructions::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen
static auto* const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(); // Actualiza los sprites updateSprites(); // Actualiza los sprites
updateBackbuffer(delta_time); // Gestiona la textura con los graficos updateBackbuffer(delta_time); // Gestiona la textura con los graficos
tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo
fade_->update(delta_time); // Actualiza el objeto "fade" fade_->update(delta_time); // Actualiza el objeto "fade"
fillBackbuffer(); // Rellena el backbuffer fillBackbuffer(); // Rellena el backbuffer
Audio::update();
} }
// Pinta en pantalla // Pinta en pantalla
void Instructions::render() { void Instructions::render() {
static auto *const SCREEN = Screen::get(); static auto* const SCREEN = Screen::get();
SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego
SCREEN->clean(); // Limpia la pantalla SCREEN->clean(); // Limpia la pantalla
@@ -286,11 +288,11 @@ auto Instructions::initializeLines(int height) -> std::vector<Line> {
} }
// Método para mover las líneas con suavizado // Método para mover las líneas con suavizado
auto Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool { auto Instructions::moveLines(std::vector<Line>& lines, int width, float duration, Uint32 start_delay) -> bool {
Uint32 current_time = SDL_GetTicks(); Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true; bool all_lines_off_screen = true;
for (auto &line : lines) { for (auto& line : lines) {
// Establecer start_time en el primer cuadro de animación // Establecer start_time en el primer cuadro de animación
if (line.start_time == 0) { if (line.start_time == 0) {
line.start_time = current_time + line.y * start_delay; line.start_time = current_time + line.y * start_delay;
@@ -315,8 +317,8 @@ auto Instructions::moveLines(std::vector<Line> &lines, int width, float duration
} }
// Método para renderizar las líneas // Método para renderizar las líneas
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines) { void Instructions::renderLines(SDL_Renderer* renderer, SDL_Texture* texture, const std::vector<Line>& lines) {
for (const auto &line : lines) { for (const auto& line : lines) {
SDL_FRect src_rect = {0, static_cast<float>(line.y), 320, 1}; SDL_FRect src_rect = {0, static_cast<float>(line.y), 320, 1};
SDL_FRect dst_rect = {static_cast<float>(line.x), static_cast<float>(line.y), 320, 1}; SDL_FRect dst_rect = {static_cast<float>(line.x), static_cast<float>(line.y), 320, 1};
SDL_RenderTexture(renderer, texture, &src_rect, &dst_rect); SDL_RenderTexture(renderer, texture, &src_rect, &dst_rect);

View File

@@ -208,7 +208,9 @@ void Intro::switchText(int from_index, int to_index) {
// Actualiza las variables del objeto // Actualiza las variables del objeto
void Intro::update(float delta_time) { void Intro::update(float delta_time) {
Screen::get()->update(); // Actualiza el objeto screen static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto Audio
tiled_bg_->update(delta_time); // Actualiza el fondo tiled_bg_->update(delta_time); // Actualiza el fondo
@@ -223,8 +225,6 @@ void Intro::update(float delta_time) {
updatePostState(); updatePostState();
break; break;
} }
Audio::update();
} }
// Dibuja el objeto en pantalla // Dibuja el objeto en pantalla

View File

@@ -80,11 +80,9 @@ void Logo::checkInput() {
// Maneja la reproducción del sonido del logo // Maneja la reproducción del sonido del logo
void Logo::handleSound() { void Logo::handleSound() {
static bool sound_triggered = false; if (!sound_triggered_ && elapsed_time_s_ >= SOUND_TRIGGER_TIME_S) {
if (!sound_triggered && elapsed_time_s_ >= SOUND_TRIGGER_TIME_S) {
Audio::get()->playSound("logo.wav"); Audio::get()->playSound("logo.wav");
sound_triggered = true; sound_triggered_ = true;
} }
} }
@@ -140,7 +138,8 @@ void Logo::updateTextureColors(float delta_time) {
void Logo::update(float delta_time) { void Logo::update(float delta_time) {
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio Audio::update(); // Actualiza el objeto audio
handleSound(); // Maneja la reproducción del sonido handleSound(); // Maneja la reproducción del sonido

View File

@@ -76,6 +76,7 @@ class Logo {
float elapsed_time_s_ = 0.0f; // Tiempo transcurrido en segundos float elapsed_time_s_ = 0.0f; // Tiempo transcurrido en segundos
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
SDL_FPoint dest_; // Posición donde dibujar el logo SDL_FPoint dest_; // Posición donde dibujar el logo
bool sound_triggered_ = false; // Indica si el sonido del logo ya se reprodujo
// --- Métodos internos --- // --- Métodos internos ---
void update(float delta_time); // Actualiza las variables void update(float delta_time); // Actualiza las variables

View File

@@ -43,10 +43,14 @@ Title::Title()
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)), 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"))), mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
state_(State::LOGO_ANIMATING), 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 // Configura objetos
tiled_bg_->setColor(param.title.bg_color); tiled_bg_->setColor(param.title.bg_color);
tiled_bg_->setSpeed(60.0F); // Set appropriate speed for seconds-based deltaTime tiled_bg_->setSpeed(0.0F);
game_logo_->enable(); game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2)); mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
fade_->setColor(param.fade.color); fade_->setColor(param.fade.color);
@@ -80,7 +84,10 @@ Title::~Title() {
// Actualiza las variables del objeto // Actualiza las variables del objeto
void Title::update(float deltaTime) { void Title::update(float deltaTime) {
Screen::get()->update(); static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateFade(); updateFade();
updateState(deltaTime); updateState(deltaTime);
updateStartPrompt(deltaTime); updateStartPrompt(deltaTime);
@@ -88,8 +95,6 @@ void Title::update(float deltaTime) {
for (auto& player : players_) { for (auto& player : players_) {
player->update(deltaTime); player->update(deltaTime);
} }
Audio::update();
} }
// Calcula el tiempo transcurrido desde el último frame // Calcula el tiempo transcurrido desde el último frame
@@ -140,13 +145,11 @@ void Title::handleKeyDownEvent(const SDL_Event& event) {
#ifdef _DEBUG #ifdef _DEBUG
void Title::handleDebugColorKeys(SDL_Keycode key) { void Title::handleDebugColorKeys(SDL_Keycode key) {
static Color color_ = param.title.bg_color; adjustColorComponent(key, debug_color_);
adjustColorComponent(key, color_);
counter_time_ = 0.0f; counter_time_ = 0.0f;
tiled_bg_->setColor(color_); tiled_bg_->setColor(debug_color_);
printColorValue(color_); printColorValue(debug_color_);
} }
void Title::adjustColorComponent(SDL_Keycode key, Color& color) { void Title::adjustColorComponent(SDL_Keycode key, Color& color) {
@@ -492,9 +495,12 @@ void Title::setState(State state) {
break; break;
case State::LOGO_FINISHED: case State::LOGO_FINISHED:
Audio::get()->playMusic("title.ogg"); Audio::get()->playMusic("title.ogg");
tiled_bg_->changeSpeedTo(60.0F, 0.5F);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break; break;
case State::START_HAS_BEEN_PRESSED: case State::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS); Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break; break;
} }
} }

View File

@@ -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 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 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 --- // --- Ciclo de vida del título ---
void update(float deltaTime); // Actualiza las variables del objeto void update(float deltaTime); // Actualiza las variables del objeto
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame

View File

@@ -151,6 +151,51 @@ auto StageManager::jumpToStage(size_t target_stage_index) -> bool {
return true; 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 { auto StageManager::subtractPower(int amount) -> bool {
if (amount <= 0 || current_power_ < amount) { if (amount <= 0 || current_power_ < amount) {
return false; return false;

View File

@@ -67,6 +67,7 @@ class StageManager : public IStageInfo {
// --- Navegación --- // --- Navegación ---
auto jumpToStage(size_t target_stage_index) -> bool; // Salta a una fase específica 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 --- // --- Consultas de estado ---
[[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual [[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual

View File

@@ -38,7 +38,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
surface_ = loadSurface(path_); surface_ = loadSurface(path_);
// Añade la propia paleta del fichero a la lista // 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 // Crea la textura, establece el BlendMode y copia la surface a la textura
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); 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 // 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; Palette palette;
std::vector<Uint8> buffer; 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 ]"); printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
}
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t> // Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
GIF::Gif gif; GIF::Gif gif;
@@ -349,14 +351,14 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
} }
// Añade una paleta a la lista // Añade una paleta a la lista
void Texture::addPaletteFromGifFile(const std::string &path) { void Texture::addPaletteFromGifFile(const std::string &path, bool quiet) {
palettes_.emplace_back(loadPaletteFromFile(path)); palettes_.emplace_back(loadPaletteFromFile(path, quiet));
setPaletteColor(palettes_.size() - 1, 0, 0x00000000); setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
} }
// Añade una paleta a la lista // Añade una paleta a la lista
void Texture::addPaletteFromPalFile(const std::string &path) { 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); setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
} }
@@ -372,7 +374,7 @@ void Texture::setPalette(size_t palette) {
auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; } auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; }
// Carga una paleta desde un archivo .pal // 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 palette{};
palette.fill(0); // Inicializar todo con 0 (transparente por defecto) palette.fill(0); // Inicializar todo con 0 (transparente por defecto)

View File

@@ -49,7 +49,7 @@ class Texture {
void setAlpha(Uint8 alpha); // Establece el alpha para la modulación void setAlpha(Uint8 alpha); // Establece el alpha para la modulación
// --- Paletas --- // --- 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 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 setPaletteColor(int palette, int index, Uint32 color); // Establece un color de la paleta
void setPalette(size_t palette); // Cambia la paleta de la textura void setPalette(size_t palette); // Cambia la paleta de la textura
@@ -76,8 +76,8 @@ class Texture {
// --- Métodos internos --- // --- Métodos internos ---
auto loadSurface(const std::string &file_path) -> std::shared_ptr<Surface>; // Crea una surface desde un fichero .gif 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 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 unloadTexture(); // Libera la memoria de la textura
void unloadSurface(); // Libera la surface actual 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
}; };

View File

@@ -40,10 +40,6 @@ TiledBG::TiledBG(SDL_FRect pos, TiledBGMode mode)
break; break;
} }
// Inicializa los valores del vector con los valores del seno
for (int i = 0; i < 360; ++i) {
sin_[i] = std::sin(i * std::numbers::pi / 180.0); // Convierte grados a radianes y calcula el seno
}
} }
// Destructor // Destructor
@@ -83,6 +79,7 @@ void TiledBG::render() {
// Actualiza la lógica de la clase (time-based) // Actualiza la lógica de la clase (time-based)
void TiledBG::update(float delta_time) { void TiledBG::update(float delta_time) {
updateSpeedChange(delta_time);
updateDesp(delta_time); updateDesp(delta_time);
updateStop(delta_time); updateStop(delta_time);
@@ -96,10 +93,10 @@ void TiledBG::update(float delta_time) {
} }
case TiledBGMode::CIRCLE: { case TiledBGMode::CIRCLE: {
// El tileado de fondo se desplaza en circulo // El tileado de fondo se desplaza en circulo
const int INDEX = static_cast<int>(desp_) % 360; const float angle_rad = (desp_ * std::numbers::pi / 180.0F);
window_.x = 128 + (static_cast<int>(sin_[(INDEX + 270) % 360] * 128)); window_.x = 128 + static_cast<int>(std::cos(angle_rad) * 128);
window_.y = 128 + (static_cast<int>(sin_[(360 - INDEX) % 360] * 96)); window_.y = 128 + static_cast<int>(std::sin(-angle_rad) * 96);
break; break;
} }
default: default:
@@ -130,3 +127,39 @@ void TiledBG::updateStop(float delta_time) {
} }
} }
} }
// Cambia la velocidad gradualmente en X segundos
void TiledBG::changeSpeedTo(float target_speed, float duration_s) {
if (duration_s <= 0.0f) {
// Si la duración es 0 o negativa, cambia inmediatamente
speed_ = target_speed;
changing_speed_ = false;
return;
}
// Configurar el cambio gradual
changing_speed_ = true;
initial_speed_ = speed_;
target_speed_ = target_speed;
change_duration_s_ = duration_s;
change_timer_s_ = 0.0f;
}
// Actualiza el cambio gradual de velocidad (time-based)
void TiledBG::updateSpeedChange(float delta_time) {
if (!changing_speed_) {
return;
}
change_timer_s_ += delta_time;
if (change_timer_s_ >= change_duration_s_) {
// Cambio completado
speed_ = target_speed_;
changing_speed_ = false;
} else {
// Interpolación lineal entre velocidad inicial y objetivo
float progress = change_timer_s_ / change_duration_s_;
speed_ = initial_speed_ + (target_speed_ - initial_speed_) * progress;
}
}

View File

@@ -2,7 +2,6 @@
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetTextureColorMod, SDL_Renderer, SDL_Texture #include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetTextureColorMod, SDL_Renderer, SDL_Texture
#include <array> // Para array
#include "color.h" // Para Color #include "color.h" // Para Color
@@ -29,11 +28,13 @@ class TiledBG {
// --- Configuración --- // --- Configuración ---
void setSpeed(float speed) { speed_ = speed; } // Establece la velocidad void setSpeed(float speed) { speed_ = speed; } // Establece la velocidad
void changeSpeedTo(float target_speed, float duration_s); // Cambia la velocidad gradualmente en X segundos
void stopGracefully() { stopping_ = true; } // Detiene el desplazamiento de forma ordenada void stopGracefully() { stopping_ = true; } // Detiene el desplazamiento de forma ordenada
void setColor(Color color) { SDL_SetTextureColorMod(canvas_, color.r, color.g, color.b); } // Cambia el color de la textura void setColor(Color color) { SDL_SetTextureColorMod(canvas_, color.r, color.g, color.b); } // Cambia el color de la textura
// --- Getters --- // --- Getters ---
[[nodiscard]] auto isStopped() const -> bool { return speed_ == 0.0F; } // Indica si está parado [[nodiscard]] auto isStopped() const -> bool { return speed_ == 0.0F; } // Indica si está parado
[[nodiscard]] auto isChangingSpeed() const -> bool { return changing_speed_; } // Indica si está cambiando velocidad gradualmente
private: private:
// --- Constantes --- // --- Constantes ---
@@ -51,13 +52,20 @@ class TiledBG {
SDL_FRect pos_; // Posición y tamaño del mosaico SDL_FRect pos_; // Posición y tamaño del mosaico
SDL_FRect window_; // Ventana visible para la textura de fondo del título SDL_FRect window_; // Ventana visible para la textura de fondo del título
TiledBGMode mode_; // Tipo de movimiento del mosaico TiledBGMode mode_; // Tipo de movimiento del mosaico
std::array<double, 360> sin_; // Vector con los valores del seno precalculados
float desp_ = 0.0F; // Desplazamiento aplicado float desp_ = 0.0F; // Desplazamiento aplicado
float speed_ = 1.0F; // Incremento que se añade al desplazamiento a cada bucle float speed_ = 1.0F; // Incremento que se añade al desplazamiento a cada bucle
bool stopping_ = false; // Indica si se está deteniendo bool stopping_ = false; // Indica si se está deteniendo
// --- Variables para cambio gradual de velocidad ---
bool changing_speed_ = false; // Indica si está cambiando velocidad gradualmente
float initial_speed_ = 0.0F; // Velocidad inicial del cambio
float target_speed_ = 0.0F; // Velocidad objetivo del cambio
float change_duration_s_ = 0.0F; // Duración total del cambio en segundos
float change_timer_s_ = 0.0F; // Tiempo transcurrido del cambio
// --- Métodos internos --- // --- Métodos internos ---
void fillTexture(); // Rellena la textura con el contenido void fillTexture(); // Rellena la textura con el contenido
void updateDesp(float delta_time) { desp_ += speed_ * delta_time; } // Actualiza el desplazamiento (time-based) void updateDesp(float delta_time) { desp_ += speed_ * delta_time; } // Actualiza el desplazamiento (time-based)
void updateStop(float delta_time); // Detiene el desplazamiento de forma ordenada (time-based) void updateStop(float delta_time); // Detiene el desplazamiento de forma ordenada (time-based)
void updateSpeedChange(float delta_time); // Actualiza el cambio gradual de velocidad (time-based)
}; };

View File

@@ -107,8 +107,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
} }
} }
void MenuRenderer::update(const ServiceMenu *menu_state) { void MenuRenderer::update(const ServiceMenu *menu_state, float delta_time) {
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
updateAnimations(delta_time); updateAnimations(delta_time);
if (visible_) { if (visible_) {
@@ -325,8 +324,17 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
} }
max_option_width = std::max(max_option_width, element_text_->length(option->getCaption(), -2)); max_option_width = std::max(max_option_width, element_text_->length(option->getCaption(), -2));
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) { if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
// Usar getMaxValueWidth() para considerar TODOS los valores posibles de la opción
int option_max_value_width = option->getMaxValueWidth(element_text_.get());
int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) - ServiceMenu::MIN_GAP_OPTION_VALUE; int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) - ServiceMenu::MIN_GAP_OPTION_VALUE;
max_value_width = std::max(max_value_width, getTruncatedValueWidth(option->getValueAsString(), max_available_value_width));
if (option_max_value_width <= max_available_value_width) {
// Si el valor más largo cabe, usar su ancho real
max_value_width = std::max(max_value_width, option_max_value_width);
} else {
// Si no cabe, usar el ancho disponible (será truncado)
max_value_width = std::max(max_value_width, max_available_value_width);
}
} }
} }
size_t total_width = max_option_width + (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2); size_t total_width = max_option_width + (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);

View File

@@ -26,7 +26,7 @@ class MenuRenderer {
// --- Métodos principales de la vista --- // --- Métodos principales de la vista ---
void render(const ServiceMenu *menu_state); void render(const ServiceMenu *menu_state);
void update(const ServiceMenu *menu_state); void update(const ServiceMenu *menu_state, float delta_time);
// --- Nuevos: Métodos de control de visibilidad y animación --- // --- Nuevos: Métodos de control de visibilidad y animación ---
void show(const ServiceMenu *menu_state); void show(const ServiceMenu *menu_state);

View File

@@ -2,7 +2,7 @@
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_FRect, SDL_RenderClear #include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_FRect, SDL_RenderClear
#include <algorithm> // Para remove_if #include <algorithm> // Para remove_if, min
#include <string> // Para basic_string, string #include <string> // Para basic_string, string
#include <utility> #include <utility>
#include <vector> // Para vector #include <vector> // Para vector
@@ -32,7 +32,6 @@ Notifier::Notifier(const std::string& icon_file, std::shared_ptr<Text> text)
icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr), icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr),
text_(std::move(text)), text_(std::move(text)),
bg_color_(param.notification.color), bg_color_(param.notification.color),
wait_time_(150),
stack_(false), stack_(false),
has_icons_(!icon_file.empty()) {} has_icons_(!icon_file.empty()) {}
@@ -43,13 +42,13 @@ void Notifier::render() {
} }
} }
// Actualiza el estado de las notificaiones // Actualiza el estado de las notificaciones
void Notifier::update() { void Notifier::update(float delta_time) {
for (int i = 0; i < (int)notifications_.size(); ++i) { for (int i = 0; i < (int)notifications_.size(); ++i) {
if (!shouldProcessNotification(i)) { if (!shouldProcessNotification(i)) {
break; break;
} }
processNotification(i); processNotification(i, delta_time);
} }
clearFinishedNotifications(); clearFinishedNotifications();
} }
@@ -59,52 +58,54 @@ auto Notifier::shouldProcessNotification(int index) const -> bool {
return index <= 0 || notifications_[index - 1].state != State::RISING; return index <= 0 || notifications_[index - 1].state != State::RISING;
} }
void Notifier::processNotification(int index) { void Notifier::processNotification(int index, float delta_time) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
notification.counter++; notification.timer += delta_time;
playNotificationSoundIfNeeded(notification); playNotificationSoundIfNeeded(notification);
updateNotificationState(index); updateNotificationState(index, delta_time);
notification.sprite->setPosition(notification.rect); notification.sprite->setPosition(notification.rect);
} }
void Notifier::playNotificationSoundIfNeeded(const Notification& notification) { void Notifier::playNotificationSoundIfNeeded(const Notification& notification) {
// Hace sonar la notificación en el primer frame // Hace sonar la notificación al inicio
if (notification.counter == 1 && if (notification.timer <= 0.016f &&
param.notification.sound && param.notification.sound &&
notification.state == State::RISING) { notification.state == State::RISING) {
Audio::get()->playSound("notify.wav", Audio::Group::INTERFACE); Audio::get()->playSound("notify.wav", Audio::Group::INTERFACE);
} }
} }
void Notifier::updateNotificationState(int index) { void Notifier::updateNotificationState(int index, float delta_time) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
switch (notification.state) { switch (notification.state) {
case State::RISING: case State::RISING:
handleRisingState(index); handleRisingState(index, delta_time);
break; break;
case State::STAY: case State::STAY:
handleStayState(index); handleStayState(index);
break; break;
case State::VANISHING: case State::VANISHING:
handleVanishingState(index); handleVanishingState(index, delta_time);
break; break;
default: default:
break; break;
} }
} }
void Notifier::handleRisingState(int index) { void Notifier::handleRisingState(int index, float delta_time) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
const float STEP = (float)notification.counter / notification.travel_dist; const float PIXELS_TO_MOVE = ANIMATION_SPEED_PX_PER_S * delta_time;
const int ALPHA = 255 * STEP; const float PROGRESS = notification.timer * ANIMATION_SPEED_PX_PER_S / notification.travel_dist;
const int ALPHA = static_cast<int>(255 * std::min(PROGRESS, 1.0f));
moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? 1 : -1); moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? PIXELS_TO_MOVE : -PIXELS_TO_MOVE);
notification.texture->setAlpha(ALPHA); notification.texture->setAlpha(ALPHA);
if (notification.rect.y == notification.y) { if ((param.notification.pos_v == Position::TOP && notification.rect.y >= notification.y) ||
(param.notification.pos_v == Position::BOTTOM && notification.rect.y <= notification.y)) {
transitionToStayState(index); transitionToStayState(index);
} }
} }
@@ -112,35 +113,37 @@ void Notifier::handleRisingState(int index) {
void Notifier::handleStayState(int index) { void Notifier::handleStayState(int index) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
if (notification.counter == wait_time_) { if (notification.timer >= STAY_DURATION_S) {
notification.state = State::VANISHING; notification.state = State::VANISHING;
notification.counter = 0; notification.timer = 0.0f;
} }
} }
void Notifier::handleVanishingState(int index) { void Notifier::handleVanishingState(int index, float delta_time) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
const float STEP = notification.counter / (float)notification.travel_dist; const float PIXELS_TO_MOVE = ANIMATION_SPEED_PX_PER_S * delta_time;
const int ALPHA = 255 * (1 - STEP); const float PROGRESS = notification.timer * ANIMATION_SPEED_PX_PER_S / notification.travel_dist;
const int ALPHA = static_cast<int>(255 * (1 - std::min(PROGRESS, 1.0f)));
moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? -1 : 1); moveNotificationVertically(notification, param.notification.pos_v == Position::TOP ? -PIXELS_TO_MOVE : PIXELS_TO_MOVE);
notification.texture->setAlpha(ALPHA); notification.texture->setAlpha(ALPHA);
if (notification.rect.y == notification.y - notification.travel_dist) { if (PROGRESS >= 1.0f) {
notification.state = State::FINISHED; notification.state = State::FINISHED;
} }
} }
void Notifier::moveNotificationVertically(Notification& notification, int direction) { void Notifier::moveNotificationVertically(Notification& notification, float pixels_to_move) {
notification.rect.y += direction; notification.rect.y += pixels_to_move;
} }
void Notifier::transitionToStayState(int index) { void Notifier::transitionToStayState(int index) {
auto& notification = notifications_[index]; auto& notification = notifications_[index];
notification.state = State::STAY; notification.state = State::STAY;
notification.texture->setAlpha(255); notification.texture->setAlpha(255);
notification.counter = 0; notification.rect.y = static_cast<float>(notification.y); // Asegurar posición exacta
notification.timer = 0.0f;
} }
// Elimina las notificaciones finalizadas // Elimina las notificaciones finalizadas

View File

@@ -32,7 +32,7 @@ class Notifier {
// --- Métodos principales --- // --- Métodos principales ---
void render(); // Dibuja las notificaciones por pantalla void render(); // Dibuja las notificaciones por pantalla
void update(); // Actualiza el estado de las notificaciones void update(float delta_time); // Actualiza el estado de las notificaciones
// --- Gestión de notificaciones --- // --- Gestión de notificaciones ---
void show(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string()); // Muestra una notificación de texto por pantalla void show(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string()); // Muestra una notificación de texto por pantalla
@@ -41,6 +41,10 @@ class Notifier {
auto checkCode(const std::string &code) -> bool { return stringInVector(getCodes(), code); } // Comprueba si hay alguna notificación con un código concreto auto checkCode(const std::string &code) -> bool { return stringInVector(getCodes(), code); } // Comprueba si hay alguna notificación con un código concreto
private: private:
// --- Constantes de tiempo (en segundos) ---
static constexpr float STAY_DURATION_S = 2.5f; // Tiempo que se ve la notificación (150 frames @ 60fps)
static constexpr float ANIMATION_SPEED_PX_PER_S = 60.0f; // Velocidad de animación (1 pixel/frame @ 60fps)
// --- Enums privados --- // --- Enums privados ---
enum class State { enum class State {
RISING, // Apareciendo RISING, // Apareciendo
@@ -63,7 +67,7 @@ class Notifier {
std::string code; // Código identificador de la notificación std::string code; // Código identificador de la notificación
State state{State::RISING}; // Estado de la notificación State state{State::RISING}; // Estado de la notificación
Shape shape{Shape::SQUARED}; // Forma de la notificación Shape shape{Shape::SQUARED}; // Forma de la notificación
int counter{0}; // Contador de tiempo float timer{0.0f}; // Timer en segundos
int y{0}; // Posición vertical int y{0}; // Posición vertical
int travel_dist{0}; // Distancia a recorrer int travel_dist{0}; // Distancia a recorrer
@@ -82,7 +86,7 @@ class Notifier {
// --- Variables de estado --- // --- Variables de estado ---
std::vector<Notification> notifications_; // Lista de notificaciones activas std::vector<Notification> notifications_; // Lista de notificaciones activas
Color bg_color_; // Color de fondo de las notificaciones Color bg_color_; // Color de fondo de las notificaciones
int wait_time_; // Tiempo que se ve la notificación // Nota: wait_time_ eliminado, ahora se usa STAY_DURATION_S
bool stack_; // Indica si las notificaciones se apilan bool stack_; // Indica si las notificaciones se apilan
bool has_icons_; // Indica si el notificador tiene textura para iconos bool has_icons_; // Indica si el notificador tiene textura para iconos
@@ -90,13 +94,13 @@ class Notifier {
void clearFinishedNotifications(); // Elimina las notificaciones cuyo estado es FINISHED void clearFinishedNotifications(); // Elimina las notificaciones cuyo estado es FINISHED
void clearAllNotifications(); // Elimina todas las notificaciones activas, sin importar el estado void clearAllNotifications(); // Elimina todas las notificaciones activas, sin importar el estado
[[nodiscard]] auto shouldProcessNotification(int index) const -> bool; // Determina si una notificación debe ser procesada (según su estado y posición) [[nodiscard]] auto shouldProcessNotification(int index) const -> bool; // Determina si una notificación debe ser procesada (según su estado y posición)
void processNotification(int index); // Procesa una notificación en la posición dada: actualiza su estado y comportamiento visual void processNotification(int index, float delta_time); // Procesa una notificación en la posición dada: actualiza su estado y comportamiento visual
static void playNotificationSoundIfNeeded(const Notification &notification); // Reproduce sonido asociado si es necesario (dependiendo del estado o contenido) static void playNotificationSoundIfNeeded(const Notification &notification); // Reproduce sonido asociado si es necesario (dependiendo del estado o contenido)
void updateNotificationState(int index); // Actualiza el estado interno de una notificación (ej. de RISING a STAY) void updateNotificationState(int index, float delta_time); // Actualiza el estado interno de una notificación (ej. de RISING a STAY)
void handleRisingState(int index); // Lógica de animación para el estado RISING (apareciendo) void handleRisingState(int index, float delta_time); // Lógica de animación para el estado RISING (apareciendo)
void handleStayState(int index); // Lógica para mantener una notificación visible en el estado STAY void handleStayState(int index); // Lógica para mantener una notificación visible en el estado STAY
void handleVanishingState(int index); // Lógica de animación para el estado VANISHING (desapareciendo) void handleVanishingState(int index, float delta_time); // Lógica de animación para el estado VANISHING (desapareciendo)
static void moveNotificationVertically(Notification &notification, int direction); // Mueve verticalmente una notificación en una dirección dada (útil para animación en apilamiento) static void moveNotificationVertically(Notification &notification, float pixels_to_move); // Mueve verticalmente una notificación con la cantidad de pixels especificada
void transitionToStayState(int index); // Cambia el estado de una notificación de RISING a STAY cuando ha alcanzado su posición final void transitionToStayState(int index); // Cambia el estado de una notificación de RISING a STAY cuando ha alcanzado su posición final
// --- Constructores y destructor privados (singleton) --- // --- Constructores y destructor privados (singleton) ---

View File

@@ -84,9 +84,9 @@ void ServiceMenu::render() {
} }
} }
void ServiceMenu::update() { void ServiceMenu::update(float delta_time) {
// El renderer siempre se actualiza para manejar sus animaciones // El renderer siempre se actualiza para manejar sus animaciones
renderer_->update(this); renderer_->update(this, delta_time);
if (!enabled_) { if (!enabled_) {
return; return;
@@ -98,10 +98,10 @@ void ServiceMenu::update() {
now_pending ? restart_message_ui_->show() : restart_message_ui_->hide(); now_pending ? restart_message_ui_->show() : restart_message_ui_->hide();
last_pending_changes_ = now_pending; last_pending_changes_ = now_pending;
} }
restart_message_ui_->update(); restart_message_ui_->update(delta_time);
if (define_buttons_) { if (define_buttons_) {
define_buttons_->update(); define_buttons_->update(delta_time);
if (define_buttons_->isEnabled() && define_buttons_->isReadyToClose()) { if (define_buttons_->isEnabled() && define_buttons_->isReadyToClose()) {
define_buttons_->disable(); define_buttons_->disable();
} }

View File

@@ -47,7 +47,7 @@ class ServiceMenu {
// --- Métodos principales --- // --- Métodos principales ---
void toggle(); void toggle();
void render(); void render();
void update(); void update(float delta_time);
void reset(); void reset();
// --- Lógica de navegación --- // --- Lógica de navegación ---

View File

@@ -20,7 +20,7 @@ void UIMessage::show() {
start_y_ = DESP; // Empieza 8 píxeles arriba de la posición base start_y_ = DESP; // Empieza 8 píxeles arriba de la posición base
target_y_ = 0.0F; // La posición final es la base target_y_ = 0.0F; // La posición final es la base
y_offset_ = start_y_; y_offset_ = start_y_;
anim_step_ = 0; animation_timer_ = 0.0f;
animating_ = true; animating_ = true;
visible_ = true; visible_ = true;
} }
@@ -33,21 +33,26 @@ void UIMessage::hide() {
start_y_ = y_offset_; // Comienza desde la posición actual start_y_ = y_offset_; // Comienza desde la posición actual
target_y_ = DESP; // Termina 8 píxeles arriba de la base target_y_ = DESP; // Termina 8 píxeles arriba de la base
anim_step_ = 0; animation_timer_ = 0.0f;
animating_ = true; animating_ = true;
} }
// Actualiza el estado de la animación (debe llamarse cada frame) // Actualiza el estado de la animación (debe llamarse cada frame)
void UIMessage::update() { void UIMessage::update(float delta_time) {
if (animating_) { if (animating_) {
updateAnimation(); updateAnimation(delta_time);
} }
} }
// Interpola la posición vertical del mensaje usando ease out cubic // Interpola la posición vertical del mensaje usando ease out cubic
void UIMessage::updateAnimation() { void UIMessage::updateAnimation(float delta_time) {
anim_step_++; animation_timer_ += delta_time;
float t = static_cast<float>(anim_step_) / ANIMATION_STEPS; float t = animation_timer_ / ANIMATION_DURATION_S;
// Clamp t entre 0 y 1
if (t > 1.0f) {
t = 1.0f;
}
if (target_y_ > start_y_) { if (target_y_ > start_y_) {
// Animación de entrada (ease out cubic) // Animación de entrada (ease out cubic)
@@ -59,9 +64,10 @@ void UIMessage::updateAnimation() {
y_offset_ = start_y_ + (target_y_ - start_y_) * t; y_offset_ = start_y_ + (target_y_ - start_y_) * t;
if (anim_step_ >= ANIMATION_STEPS) { if (animation_timer_ >= ANIMATION_DURATION_S) {
y_offset_ = target_y_; y_offset_ = target_y_;
animating_ = false; animating_ = false;
animation_timer_ = 0.0f; // Reset timer
if (target_y_ < 0.0F) { if (target_y_ < 0.0F) {
visible_ = false; visible_ = false;
} }

View File

@@ -20,7 +20,7 @@ class UIMessage {
void hide(); void hide();
// Actualiza el estado de la animación (debe llamarse cada frame) // Actualiza el estado de la animación (debe llamarse cada frame)
void update(); void update(float delta_time);
// Dibuja el mensaje en pantalla si está visible // Dibuja el mensaje en pantalla si está visible
void render(); void render();
@@ -47,10 +47,10 @@ class UIMessage {
// --- Animación --- // --- Animación ---
float start_y_ = 0.0F; // Posición Y inicial de la animación float start_y_ = 0.0F; // Posición Y inicial de la animación
float target_y_ = 0.0F; // Posición Y objetivo de la animación float target_y_ = 0.0F; // Posición Y objetivo de la animación
int anim_step_ = 0; // Paso actual de la animación float animation_timer_ = 0.0F; // Timer actual de la animación en segundos
static constexpr int ANIMATION_STEPS = 8; // Número total de pasos de la animación static constexpr float ANIMATION_DURATION_S = 0.133f; // Duración total de la animación (8 frames @ 60fps)
static constexpr float DESP = -8.0F; // Distancia a desplazarse static constexpr float DESP = -8.0F; // Distancia a desplazarse
// Actualiza la interpolación de la animación (ease out/in cubic) // Actualiza la interpolación de la animación (ease out/in cubic)
void updateAnimation(); void updateAnimation(float delta_time);
}; };

View File

@@ -76,12 +76,9 @@ void WindowMessage::render() {
} }
} }
void WindowMessage::update() { void WindowMessage::update(float delta_time) {
// Actualizar animaciones // Actualizar animaciones
if (show_hide_animation_.active || resize_animation_.active) { if (show_hide_animation_.active || resize_animation_.active) {
// Aquí necesitarías el delta_time del game loop
// Por ahora usamos un valor fijo, pero idealmente se pasaría como parámetro
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
updateAnimation(delta_time); updateAnimation(delta_time);
} }
} }

View File

@@ -73,7 +73,7 @@ class WindowMessage {
// Métodos principales // Métodos principales
void render(); void render();
void update(); void update(float delta_time);
// Control de visibilidad // Control de visibilidad
void show(); void show();

View File

@@ -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()); 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 // Obtiene el nombre de un fichero a partir de una ruta completa
auto getFileName(const std::string &path) -> std::string { auto getFileName(const std::string &path) -> std::string {

View File

@@ -10,7 +10,6 @@
// --- Constantes --- // --- Constantes ---
constexpr int BLOCK = 8; constexpr int BLOCK = 8;
constexpr int TOTAL_DEMO_DATA = 2000;
// --- Estructuras --- // --- Estructuras ---
struct Overrides { struct Overrides {
@@ -32,44 +31,6 @@ struct Circle {
r(radius) {} 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 { struct Zone {
SDL_FRect rect; // Rectangulo que define la zona SDL_FRect rect; // Rectangulo que define la zona
@@ -88,21 +49,21 @@ extern Overrides overrides; // Configuración global de overrides
// Colisiones y geometría // Colisiones y geometría
auto distanceSquared(int x1, int y1, int x2, int y2) -> double; auto distanceSquared(int x1, int y1, int x2, int y2) -> double;
auto getCollisionPoint(const Circle &a, const Circle &b) -> SDL_FPoint; auto getCollisionPoint(const Circle& a, const Circle& b) -> SDL_FPoint;
auto checkCollision(const Circle &a, const Circle &b) -> bool; auto checkCollision(const Circle& a, const Circle& b) -> bool;
auto checkCollision(const Circle &a, const SDL_FRect &b) -> bool; auto checkCollision(const Circle& a, const SDL_FRect& b) -> bool;
auto checkCollision(const SDL_FRect &a, const SDL_FRect &b) -> bool; auto checkCollision(const SDL_FRect& a, const SDL_FRect& b) -> bool;
auto checkCollision(const SDL_FPoint &p, const SDL_FRect &r) -> bool; auto checkCollision(const SDL_FPoint& p, const SDL_FRect& r) -> bool;
// Conversión y manipulación de cadenas // Conversión y manipulación de cadenas
auto stringToBool(const std::string &str) -> bool; auto stringToBool(const std::string& str) -> bool;
auto boolToString(bool value) -> std::string; auto boolToString(bool value) -> std::string;
auto boolToOnOff(bool value) -> std::string; auto boolToOnOff(bool value) -> std::string;
auto toLower(const std::string &str) -> std::string; auto toLower(const std::string& str) -> std::string;
auto trim(const std::string &str) -> std::string; auto trim(const std::string& str) -> std::string;
// Dibujo // Dibujo
void drawCircle(SDL_Renderer *renderer, int32_t center_x, int32_t center_y, int32_t radius); void drawCircle(SDL_Renderer* renderer, int32_t center_x, int32_t center_y, int32_t radius);
// Funciones de suavizado (easing) // Funciones de suavizado (easing)
auto easeOutQuint(double time) -> double; auto easeOutQuint(double time) -> double;
@@ -123,17 +84,11 @@ auto easeOutCubic(double time) -> double;
auto easeInCubic(double time) -> double; auto easeInCubic(double time) -> double;
// Utilidades varias // Utilidades varias
auto stringInVector(const std::vector<std::string> &vec, const std::string &str) -> bool; // Comprueba si un vector contiene una cadena auto stringInVector(const std::vector<std::string>& vec, const std::string& str) -> bool; // Comprueba si un vector contiene una cadena
void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3); // Imprime una línea con puntos 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 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 // Ficheros y rutas
auto getFileName(const std::string &path) -> std::string; // Obtiene el nombre de un fichero a partir de una ruta auto getFileName(const std::string& path) -> std::string; // Obtiene el nombre de un fichero a partir de una ruta
auto getPath(const std::string &full_path) -> std::string; // Obtiene la ruta eliminando el nombre del fichero auto getPath(const std::string& full_path) -> std::string; // Obtiene la ruta eliminando el nombre del fichero

6
source/version.h.in Normal file
View 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.

View File

@@ -1,9 +1,10 @@
#include "../source/resource_pack.h" #include "../source/resource_pack.h"
#include "../build/version.h" // Para Version::APP_NAME
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
void showHelp() { 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 << "===============================================" << std::endl;
std::cout << "Usage: pack_resources [options] [input_dir] [output_file]" << std::endl; std::cout << "Usage: pack_resources [options] [input_dir] [output_file]" << std::endl;
std::cout << std::endl; std::cout << std::endl;
@@ -43,6 +44,7 @@ int main(int argc, char* argv[]) {
std::string dataDir = "data"; std::string dataDir = "data";
std::string outputFile = "resources.pack"; std::string outputFile = "resources.pack";
bool listMode = false; bool listMode = false;
bool dataDirSet = false;
// Parse arguments // Parse arguments
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
@@ -56,8 +58,9 @@ int main(int argc, char* argv[]) {
outputFile = argv[++i]; // Next argument is pack file to list outputFile = argv[++i]; // Next argument is pack file to list
} }
} else if (!arg.empty() && arg[0] != '-') { } else if (!arg.empty() && arg[0] != '-') {
if (dataDir == "data") { if (!dataDirSet) {
dataDir = arg; dataDir = arg;
dataDirSet = true;
} else { } else {
outputFile = arg; outputFile = arg;
} }
@@ -69,7 +72,7 @@ int main(int argc, char* argv[]) {
return 0; 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 << "===============================================" << std::endl;
std::cout << "Input directory: " << dataDir << std::endl; std::cout << "Input directory: " << dataDir << std::endl;
std::cout << "Output file: " << outputFile << std::endl; std::cout << "Output file: " << outputFile << std::endl;