Compare commits
41 Commits
c79a846b29
...
merdes-nov
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e083a8cdb | |||
| cbe4315701 | |||
| 49d561b583 | |||
| 6e56a6fd79 | |||
| 267d9647e0 | |||
| 13b3702d00 | |||
| 4500845dcd | |||
| a4abc02f88 | |||
| a0fb6934b0 | |||
| 19645445b2 | |||
| efe8628a3c | |||
| c98cb0d29f | |||
| c16fc1bae5 | |||
| fa0af1179a | |||
| d1e4a5eb07 | |||
| e18d1b186a | |||
| d056a5e336 | |||
| b9e26aa755 | |||
| b2afef2226 | |||
| c400aa96c0 | |||
| 8818954dcd | |||
| b92e5df98b | |||
| 83871273ec | |||
| 0459b39366 | |||
| 5bb0ff19bc | |||
| a867b3cf4d | |||
| 8a6ce8e66d | |||
| a40f04a739 | |||
| 0c670fd344 | |||
| 35f4bf690c | |||
| abeaf47f96 | |||
| 6498c35628 | |||
| d1c6af02db | |||
| 5edef17d84 | |||
| e4532fcef2 | |||
| 7a8d66c29d | |||
| 54292c9f8f | |||
| 3897553704 | |||
| 308f5c20fb | |||
| 987dcd0205 | |||
| d56f23544c |
1
.gitignore
vendored
@@ -18,3 +18,4 @@ debug.txt
|
|||||||
cppcheck-result*
|
cppcheck-result*
|
||||||
desktop.ini
|
desktop.ini
|
||||||
ccae_release/
|
ccae_release/
|
||||||
|
resources.pack
|
||||||
@@ -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)
|
||||||
|
|||||||
41
Makefile
@@ -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
@@ -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"
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
data/demo/demo3.bin
Normal file
|
After Width: | Height: | Size: 12 KiB |
@@ -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]
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.7 KiB |
@@ -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]
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|
||||||
|
|||||||
BIN
data/music/congratulations.ogg
Normal file
BIN
data/sound/bullet2p.wav
Normal file
BIN
data/sound/name_input_accept.wav
Normal file
BIN
data/sound/voice_game_over.wav
Normal 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
|
||||||
|
|||||||
@@ -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,26 +207,29 @@ 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
|
||||||
auto Asset::parseAssetType(const std::string &type_str) -> Type {
|
auto Asset::parseAssetType(const std::string &type_str) -> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
}
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|||||||
@@ -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(); }
|
||||||
|
|||||||
@@ -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_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,18 +15,38 @@ 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:
|
||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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,7 +15,6 @@ 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 = 10;
|
||||||
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
|
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
|
||||||
constexpr bool HIT_STOP = false;
|
constexpr bool HIT_STOP = false;
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
70
source/demo.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include "demo.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h> // Para SDL_IOStream, SDL_IOFromConstMem, SDL_IOFromFile, SDL_ReadIO, SDL_WriteIO, SDL_CloseIO
|
||||||
|
#include <stdexcept> // Para runtime_error
|
||||||
|
|
||||||
|
#include "resource_helper.h" // Para ResourceHelper
|
||||||
|
#include "utils.h" // Para printWithDots, getFileName
|
||||||
|
|
||||||
|
// Carga el fichero de datos para la demo
|
||||||
|
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
|
||||||
|
DemoData dd;
|
||||||
|
|
||||||
|
SDL_IOStream *file = nullptr;
|
||||||
|
|
||||||
|
// Intentar cargar desde ResourceHelper primero
|
||||||
|
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||||
|
if (!resource_data.empty()) {
|
||||||
|
file = SDL_IOFromConstMem(resource_data.data(), resource_data.size());
|
||||||
|
} else {
|
||||||
|
// Fallback a filesystem directo
|
||||||
|
file = SDL_IOFromFile(file_path.c_str(), "r+b");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file == nullptr) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||||
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
|
}
|
||||||
|
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]");
|
||||||
|
|
||||||
|
// Lee todos los datos del fichero y los deja en el destino
|
||||||
|
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {
|
||||||
|
DemoKeys dk = DemoKeys();
|
||||||
|
SDL_ReadIO(file, &dk, sizeof(DemoKeys));
|
||||||
|
dd.push_back(dk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_CloseIO(file);
|
||||||
|
|
||||||
|
return dd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RECORDING
|
||||||
|
// Guarda el fichero de datos para la demo
|
||||||
|
bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
|
||||||
|
auto success = true;
|
||||||
|
auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
// Guarda los datos
|
||||||
|
for (const auto &data : dd) {
|
||||||
|
if (SDL_WriteIO(file, &data, sizeof(DemoKeys)) != sizeof(DemoKeys)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success) {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file %s", getFileName(file_path).c_str());
|
||||||
|
}
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_CloseIO(file);
|
||||||
|
} else {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Unable to save %s file! %s", getFileName(file_path).c_str(), SDL_GetError());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
#endif // RECORDING
|
||||||
54
source/demo.h
Normal file
@@ -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
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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_; }
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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); }},
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -919,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) {
|
||||||
@@ -1034,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;
|
||||||
}
|
}
|
||||||
|
|||||||
183
source/player.h
@@ -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
|
||||||
@@ -124,9 +131,7 @@ class Player {
|
|||||||
// --- 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 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 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 ---
|
||||||
@@ -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
|
|
||||||
};
|
};
|
||||||
@@ -12,14 +12,13 @@
|
|||||||
|
|
||||||
#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
|
||||||
@@ -317,6 +316,11 @@ auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & {
|
|||||||
|
|
||||||
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +328,6 @@ auto Resource::getDemoData(int index) -> DemoData & {
|
|||||||
|
|
||||||
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) {
|
||||||
@@ -332,13 +335,11 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
|
|||||||
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) {
|
||||||
@@ -346,7 +347,6 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
|||||||
return JA_LoadMusic(audio_path.c_str());
|
return JA_LoadMusic(audio_path.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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();
|
||||||
@@ -448,10 +446,8 @@ void Resource::load() {
|
|||||||
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
|
||||||
@@ -484,12 +480,8 @@ void Resource::loadSounds() {
|
|||||||
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 ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,12 +495,8 @@ void Resource::loadMusics() {
|
|||||||
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 ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,6 +667,7 @@ 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");
|
||||||
@@ -737,9 +727,7 @@ void Resource::createText() {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -750,9 +738,7 @@ void Resource::clearSounds() {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -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_;
|
||||||
|
|
||||||
|
|||||||
@@ -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_
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -206,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
|
||||||
@@ -218,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
|
||||||
|
|||||||
@@ -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));
|
||||||
@@ -293,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) {
|
||||||
@@ -336,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,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);
|
||||||
@@ -487,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;
|
||||||
}
|
}
|
||||||
@@ -515,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_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
|
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
|
||||||
|
|
||||||
#include <algorithm> // Para find, clamp, find_if, min
|
#include <algorithm> // Para find, clamp, find_if, min, std::shuffle, std::iota
|
||||||
#include <array> // Para array
|
#include <array> // Para array
|
||||||
#include <cstdlib> // Para rand, size_t
|
#include <cstdlib> // Para rand, size_t
|
||||||
#include <functional> // Para function
|
#include <functional> // Para function
|
||||||
#include <iterator> // Para size
|
#include <iterator> // Para size
|
||||||
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
|
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
|
||||||
|
#include <random> // std::random_device, std::default_random_engine
|
||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
|
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
#include "background.h" // Para Background
|
#include "background.h" // Para Background
|
||||||
#include "balloon.h" // Para Balloon
|
#include "balloon.h" // Para Balloon
|
||||||
#include "balloon_manager.h" // Para BalloonManager
|
#include "balloon_manager.h" // Para BalloonManager
|
||||||
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
#include "bullet.h" // Para Bullet, Bullet::Type, BulletMoveStatus
|
||||||
#include "color.h" // Para Color, Colors::FLASH
|
#include "color.h" // Para Color, Colors::FLASH
|
||||||
#include "difficulty.h" // Para Code
|
#include "difficulty.h" // Para Code
|
||||||
#include "fade.h" // Para Fade, FadeType, FadeMode
|
#include "fade.h" // Para Fade, FadeType, FadeMode
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(Player::Id player_id, int current_stage, bool demo)
|
Game::Game(Player::Id player_id, int current_stage, bool demo_enabled)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
screen_(Screen::get()),
|
screen_(Screen::get()),
|
||||||
input_(Input::get()),
|
input_(Input::get()),
|
||||||
@@ -62,7 +63,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
tabe_(std::make_unique<Tabe>()),
|
tabe_(std::make_unique<Tabe>()),
|
||||||
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
demo_.enabled = demo;
|
demo_.enabled = demo_enabled;
|
||||||
|
|
||||||
// Otras variables
|
// Otras variables
|
||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::GAME;
|
||||||
@@ -83,7 +84,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
fade_in_->setPostDuration(0);
|
fade_in_->setPostDuration(0);
|
||||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_in_->setMode(Fade::Mode::IN);
|
fade_in_->setMode(Fade::Mode::IN);
|
||||||
|
#ifndef RECORDING
|
||||||
fade_in_->activate();
|
fade_in_->activate();
|
||||||
|
#endif
|
||||||
|
|
||||||
fade_out_->setColor(param.fade.color);
|
fade_out_->setColor(param.fade.color);
|
||||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||||
@@ -109,6 +112,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
pause_manager_->setServiceMenuPause(is_active);
|
pause_manager_->setServiceMenuPause(is_active);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#ifdef RECORDING
|
||||||
|
setState(State::PLAYING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game() {
|
Game::~Game() {
|
||||||
@@ -117,7 +123,14 @@ Game::~Game() {
|
|||||||
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
|
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
|
||||||
manager->saveToFile(Asset::get()->get("score.bin"));
|
manager->saveToFile(Asset::get()->get("score.bin"));
|
||||||
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO;
|
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
if (Options::audio.enabled) {
|
||||||
|
// Musica
|
||||||
Audio::get()->stopMusic();
|
Audio::get()->stopMusic();
|
||||||
|
Audio::get()->setMusicVolume(Options::audio.music.volume);
|
||||||
|
// Sonidos
|
||||||
|
Audio::get()->stopAllSounds();
|
||||||
|
Audio::get()->setSoundVolume(Options::audio.sound.volume, Audio::Group::GAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ServiceMenu::get()->setStateChangeCallback(nullptr);
|
ServiceMenu::get()->setStateChangeCallback(nullptr);
|
||||||
|
|
||||||
@@ -201,10 +214,11 @@ void Game::updateHiScore() {
|
|||||||
hi_score_.score = player->getScore();
|
hi_score_.score = player->getScore();
|
||||||
hi_score_.name.clear();
|
hi_score_.name.clear();
|
||||||
|
|
||||||
// Si se supera la máxima puntuación emite sonido
|
// Si se supera la máxima puntuación
|
||||||
if (!hi_score_achieved_) {
|
if (!hi_score_achieved_) {
|
||||||
hi_score_achieved_ = true;
|
hi_score_achieved_ = true;
|
||||||
playSound("hi_score_achieved.wav");
|
playSound("hi_score_achieved.wav"); // Emite un sonido
|
||||||
|
createMessage({paths_.at(8), paths_.at(9)}, Resource::get()->getTexture("game_text_new_record")); // CRea un mensaje
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,7 +325,7 @@ void Game::updateStage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado de fin de la partida
|
// Actualiza las variables y sistemas durante el estado de fin de partida
|
||||||
void Game::updateGameStateGameOver(float deltaTime) {
|
void Game::updateGameStateGameOver(float deltaTime) {
|
||||||
fade_out_->update();
|
fade_out_->update();
|
||||||
updatePlayers(deltaTime);
|
updatePlayers(deltaTime);
|
||||||
@@ -328,22 +342,15 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
|||||||
cleanVectors();
|
cleanVectors();
|
||||||
|
|
||||||
if (game_over_timer_ < GAME_OVER_DURATION_S) {
|
if (game_over_timer_ < GAME_OVER_DURATION_S) {
|
||||||
handleGameOverEvents(); // Maneja eventos al inicio
|
game_over_timer_ += deltaTime; // Incremento time-based primero
|
||||||
|
handleGameOverEvents(); // Maneja eventos después del incremento
|
||||||
game_over_timer_ += deltaTime; // Incremento time-based
|
|
||||||
|
|
||||||
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5f; // 2.5 segundos antes del final
|
|
||||||
if (game_over_timer_ >= FADE_TRIGGER_S && !fade_out_->isEnabled()) {
|
|
||||||
fade_out_->activate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fade_out_->isEnabled()) {
|
|
||||||
if (Options::audio.enabled) {
|
if (Options::audio.enabled) {
|
||||||
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0F;
|
const float progress = std::min(game_over_timer_ / GAME_OVER_DURATION_S, 1.0f);
|
||||||
|
const float VOL = 64.0f * (1.0f - progress);
|
||||||
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
|
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (fade_out_->hasEnded()) {
|
if (fade_out_->hasEnded()) {
|
||||||
if (game_completed_timer_ > 0) {
|
if (game_completed_timer_ > 0) {
|
||||||
@@ -352,10 +359,6 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
|||||||
Section::name = Section::Name::HI_SCORE_TABLE; // La partida ha terminado con la derrota de los jugadores
|
Section::name = Section::Name::HI_SCORE_TABLE; // La partida ha terminado con la derrota de los jugadores
|
||||||
}
|
}
|
||||||
Section::options = Section::Options::HI_SCORE_AFTER_PLAYING;
|
Section::options = Section::Options::HI_SCORE_AFTER_PLAYING;
|
||||||
if (Options::audio.enabled) {
|
|
||||||
Audio::get()->stopAllSounds();
|
|
||||||
Audio::get()->setSoundVolume(Options::audio.sound.volume, Audio::Group::GAME);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,6 +408,7 @@ void Game::destroyAllItems() {
|
|||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
||||||
|
#ifndef RECORDING
|
||||||
for (auto& balloon : balloon_manager_->getBalloons()) {
|
for (auto& balloon : balloon_manager_->getBalloons()) {
|
||||||
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
||||||
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
||||||
@@ -412,6 +416,7 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return nullptr; // No se ha producido ninguna colisión
|
return nullptr; // No se ha producido ninguna colisión
|
||||||
}
|
}
|
||||||
@@ -561,7 +566,7 @@ auto Game::checkBulletBalloonCollision(const std::shared_ptr<Bullet> &bullet) ->
|
|||||||
|
|
||||||
// Procesa el impacto en un globo
|
// Procesa el impacto en un globo
|
||||||
void Game::processBalloonHit(const std::shared_ptr<Bullet>& bullet, const std::shared_ptr<Balloon>& balloon) {
|
void Game::processBalloonHit(const std::shared_ptr<Bullet>& bullet, const std::shared_ptr<Balloon>& balloon) {
|
||||||
auto player = getPlayer(bullet->getOwner());
|
auto player = getPlayer(static_cast<Player::Id>(bullet->getOwner()));
|
||||||
|
|
||||||
handleItemDrop(balloon, player);
|
handleItemDrop(balloon, player);
|
||||||
handleBalloonDestruction(balloon, player);
|
handleBalloonDestruction(balloon, player);
|
||||||
@@ -599,8 +604,8 @@ void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std:
|
|||||||
// Mueve las balas activas
|
// Mueve las balas activas
|
||||||
void Game::updateBullets(float deltaTime) {
|
void Game::updateBullets(float deltaTime) {
|
||||||
for (auto& bullet : bullets_) {
|
for (auto& bullet : bullets_) {
|
||||||
if (bullet->update(deltaTime) == BulletMoveStatus::OUT) {
|
if (bullet->update(deltaTime) == Bullet::MoveStatus::OUT) {
|
||||||
getPlayer(bullet->getOwner())->decScoreMultiplier();
|
getPlayer(static_cast<Player::Id>(bullet->getOwner()))->decScoreMultiplier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -613,8 +618,8 @@ void Game::renderBullets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner) {
|
void Game::createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner) {
|
||||||
bullets_.emplace_back(std::make_shared<Bullet>(x, y, kind, powered_up, owner));
|
bullets_.emplace_back(std::make_shared<Bullet>(x, y, type, color, owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia el vector de balas
|
// Vacia el vector de balas
|
||||||
@@ -781,8 +786,8 @@ void Game::throwCoffee(int x, int y) {
|
|||||||
|
|
||||||
smart_sprites_.back()->setPosX(x - 8);
|
smart_sprites_.back()->setPosX(x - 8);
|
||||||
smart_sprites_.back()->setPosY(y - 8);
|
smart_sprites_.back()->setPosY(y - 8);
|
||||||
smart_sprites_.back()->setWidth(param.game.item_size);
|
smart_sprites_.back()->setWidth(Item::WIDTH);
|
||||||
smart_sprites_.back()->setHeight(param.game.item_size);
|
smart_sprites_.back()->setHeight(Item::HEIGHT);
|
||||||
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0f); // Convertir a pixels/segundo
|
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0f); // Convertir a pixels/segundo
|
||||||
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
|
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
|
||||||
smart_sprites_.back()->setAccelX(0.0F);
|
smart_sprites_.back()->setAccelX(0.0F);
|
||||||
@@ -791,10 +796,9 @@ void Game::throwCoffee(int x, int y) {
|
|||||||
smart_sprites_.back()->setDestY(param.game.height + 1);
|
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||||
smart_sprites_.back()->setEnabled(true);
|
smart_sprites_.back()->setEnabled(true);
|
||||||
smart_sprites_.back()->setFinishedDelay(0.0F);
|
smart_sprites_.back()->setFinishedDelay(0.0F);
|
||||||
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
|
smart_sprites_.back()->setSpriteClip(0, Item::HEIGHT, Item::WIDTH, Item::HEIGHT);
|
||||||
smart_sprites_.back()->setRotatingCenter({param.game.item_size / 2, param.game.item_size / 2});
|
smart_sprites_.back()->setRotatingCenter({Item::WIDTH / 2, Item::HEIGHT / 2});
|
||||||
smart_sprites_.back()->setRotate(true);
|
smart_sprites_.back()->setRotate(true);
|
||||||
smart_sprites_.back()->setRotateSpeed(10);
|
|
||||||
smart_sprites_.back()->setRotateAmount(90.0);
|
smart_sprites_.back()->setRotateAmount(90.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -869,13 +873,11 @@ void Game::updateTimeStopped(float deltaTime) {
|
|||||||
// Fase de advertencia (últimos 2 segundos)
|
// Fase de advertencia (últimos 2 segundos)
|
||||||
if (time_stopped_timer_ <= WARNING_THRESHOLD_S) {
|
if (time_stopped_timer_ <= WARNING_THRESHOLD_S) {
|
||||||
static float last_sound_time = 0.0f;
|
static float last_sound_time = 0.0f;
|
||||||
static bool color_flash_sound_played = false;
|
|
||||||
static bool warning_phase_started = false;
|
|
||||||
|
|
||||||
// CLAC al entrar en fase de advertencia
|
// CLAC al entrar en fase de advertencia
|
||||||
if (!warning_phase_started) {
|
if (!time_stopped_flags_.warning_phase_started) {
|
||||||
playSound("clock.wav");
|
playSound("clock.wav");
|
||||||
warning_phase_started = true;
|
time_stopped_flags_.warning_phase_started = true;
|
||||||
last_sound_time = 0.0f; // Reset para empezar el ciclo rápido
|
last_sound_time = 0.0f; // Reset para empezar el ciclo rápido
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,11 +887,11 @@ void Game::updateTimeStopped(float deltaTime) {
|
|||||||
balloon_manager_->normalColorsToAllBalloons();
|
balloon_manager_->normalColorsToAllBalloons();
|
||||||
playSound("clock.wav");
|
playSound("clock.wav");
|
||||||
last_sound_time = 0.0f;
|
last_sound_time = 0.0f;
|
||||||
color_flash_sound_played = false; // Reset flag para el próximo intervalo
|
time_stopped_flags_.color_flash_sound_played = false; // Reset flag para el próximo intervalo
|
||||||
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !color_flash_sound_played) {
|
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !time_stopped_flags_.color_flash_sound_played) {
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
playSound("clock.wav");
|
playSound("clock.wav");
|
||||||
color_flash_sound_played = true; // Evita que suene múltiples veces
|
time_stopped_flags_.color_flash_sound_played = true; // Evita que suene múltiples veces
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fase normal - solo sonido ocasional
|
// Fase normal - solo sonido ocasional
|
||||||
@@ -914,9 +916,9 @@ void Game::update(float deltaTime) {
|
|||||||
screen_->update(deltaTime); // Actualiza el objeto screen
|
screen_->update(deltaTime); // Actualiza el objeto screen
|
||||||
Audio::update(); // Actualiza el objeto audio
|
Audio::update(); // Actualiza el objeto audio
|
||||||
|
|
||||||
updateDemo();
|
updateDemo(deltaTime);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
updateRecording();
|
updateRecording(deltaTime);
|
||||||
#endif
|
#endif
|
||||||
updateGameStates(deltaTime);
|
updateGameStates(deltaTime);
|
||||||
fillCanvas();
|
fillCanvas();
|
||||||
@@ -994,6 +996,7 @@ void Game::enableTimeStopItem() {
|
|||||||
balloon_manager_->stopAllBalloons();
|
balloon_manager_->stopAllBalloons();
|
||||||
balloon_manager_->reverseColorsToAllBalloons();
|
balloon_manager_->reverseColorsToAllBalloons();
|
||||||
time_stopped_timer_ = TIME_STOPPED_DURATION_S;
|
time_stopped_timer_ = TIME_STOPPED_DURATION_S;
|
||||||
|
time_stopped_flags_.reset(); // Resetea flags al activar el item
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita el efecto del item de detener el tiempo
|
// Deshabilita el efecto del item de detener el tiempo
|
||||||
@@ -1016,10 +1019,8 @@ void Game::run() {
|
|||||||
last_time_ = SDL_GetTicks();
|
last_time_ = SDL_GetTicks();
|
||||||
|
|
||||||
while (Section::name == Section::Name::GAME) {
|
while (Section::name == Section::Name::GAME) {
|
||||||
#ifndef RECORDING
|
|
||||||
checkInput();
|
|
||||||
#endif
|
|
||||||
const float delta_time = calculateDeltaTime();
|
const float delta_time = calculateDeltaTime();
|
||||||
|
checkInput();
|
||||||
update(delta_time);
|
update(delta_time);
|
||||||
handleEvents(); // Tiene que ir antes del render
|
handleEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
@@ -1036,11 +1037,11 @@ void Game::initPaths() {
|
|||||||
const int X1 = param.game.play_area.center_x - (W / 2);
|
const int X1 = param.game.play_area.center_x - (W / 2);
|
||||||
const int X2 = param.game.play_area.rect.w;
|
const int X2 = param.game.play_area.rect.w;
|
||||||
const int Y = param.game.play_area.center_y;
|
const int Y = param.game.play_area.center_y;
|
||||||
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 0.33f); // 20 frames → segundos
|
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 0.5f);
|
||||||
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recorrido para el texto de "Last Stage!" o de "X stages left" o "Game Over" (2,3)
|
// Recorrido para el texto de "Last Stage!" o de "X stages left" (2,3)
|
||||||
{
|
{
|
||||||
const auto& texture = Resource::get()->getTexture("game_text_last_stage");
|
const auto& texture = Resource::get()->getTexture("game_text_last_stage");
|
||||||
const auto H = texture->getHeight();
|
const auto H = texture->getHeight();
|
||||||
@@ -1048,11 +1049,11 @@ void Game::initPaths() {
|
|||||||
const int Y1 = param.game.play_area.center_y - (H / 2);
|
const int Y1 = param.game.play_area.center_y - (H / 2);
|
||||||
const int Y2 = -H;
|
const int Y2 = -H;
|
||||||
const int X = param.game.play_area.center_x;
|
const int X = param.game.play_area.center_x;
|
||||||
paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 0.33f); // 20 frames → segundos
|
paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 0.5f);
|
||||||
paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0);
|
paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recorrido para el texto de "Congratulations!!" (3,4)
|
// Recorrido para el texto de "Congratulations!!" (4,5)
|
||||||
{
|
{
|
||||||
const auto& texture = Resource::get()->getTexture("game_text_congratulations");
|
const auto& texture = Resource::get()->getTexture("game_text_congratulations");
|
||||||
const auto W = texture->getWidth();
|
const auto W = texture->getWidth();
|
||||||
@@ -1060,12 +1061,12 @@ void Game::initPaths() {
|
|||||||
const int X0 = -W;
|
const int X0 = -W;
|
||||||
const int X1 = param.game.play_area.center_x - (W / 2);
|
const int X1 = param.game.play_area.center_x - (W / 2);
|
||||||
const int X2 = param.game.play_area.rect.w;
|
const int X2 = param.game.play_area.rect.w;
|
||||||
const int Y = param.game.play_area.center_y - (H / 2) - 20;
|
const int Y = param.game.play_area.center_y - (H / 2);
|
||||||
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 6.67f); // 400 frames → segundos
|
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 7.0F);
|
||||||
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recorrido para el texto de "1.000.000 points!" (5,6)
|
// Recorrido para el texto de "1.000.000 points!" (6,7)
|
||||||
{
|
{
|
||||||
const auto& texture = Resource::get()->getTexture("game_text_1000000_points");
|
const auto& texture = Resource::get()->getTexture("game_text_1000000_points");
|
||||||
const auto W = texture->getWidth();
|
const auto W = texture->getWidth();
|
||||||
@@ -1073,10 +1074,35 @@ void Game::initPaths() {
|
|||||||
const int X0 = param.game.play_area.rect.w;
|
const int X0 = param.game.play_area.rect.w;
|
||||||
const int X1 = param.game.play_area.center_x - (W / 2);
|
const int X1 = param.game.play_area.center_x - (W / 2);
|
||||||
const int X2 = -W;
|
const int X2 = -W;
|
||||||
const int Y = param.game.play_area.center_y + (H / 2) - 20;
|
const int Y = param.game.play_area.center_y + (H / 2);
|
||||||
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 6.67f); // 400 frames → segundos
|
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 7.0F);
|
||||||
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recorrido para el texto de "New Record!" (8,9)
|
||||||
|
{
|
||||||
|
const auto& texture = Resource::get()->getTexture("game_text_new_record");
|
||||||
|
const auto W = texture->getWidth();
|
||||||
|
const auto H = texture->getHeight();
|
||||||
|
const int X0 = -W;
|
||||||
|
const int X1 = param.game.play_area.center_x - (W / 2);
|
||||||
|
const int X2 = param.game.play_area.rect.w;
|
||||||
|
const int Y = param.game.play_area.center_y - (H / 2) - (H * 2);
|
||||||
|
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 1.0f);
|
||||||
|
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recorrido para el texto de "Game Over" (10,11)
|
||||||
|
{
|
||||||
|
const auto& texture = Resource::get()->getTexture("game_text_game_over");
|
||||||
|
const auto H = texture->getHeight();
|
||||||
|
const int Y0 = param.game.play_area.rect.h - H;
|
||||||
|
const int Y1 = param.game.play_area.center_y - (H / 2);
|
||||||
|
const int Y2 = -H;
|
||||||
|
const int X = param.game.play_area.center_x;
|
||||||
|
paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 2.0f);
|
||||||
|
paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables de ayuda
|
// Actualiza las variables de ayuda
|
||||||
@@ -1266,19 +1292,16 @@ void Game::demoHandlePassInput() {
|
|||||||
|
|
||||||
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
||||||
void Game::demoHandleInput() {
|
void Game::demoHandleInput() {
|
||||||
int index = 0;
|
|
||||||
for (const auto& player : players_) {
|
for (const auto& player : players_) {
|
||||||
if (player->isPlaying()) {
|
if (player->isPlaying()) {
|
||||||
// Maneja el input específico del jugador en modo demo.
|
demoHandlePlayerInput(player, player->getDemoFile()); // Maneja el input específico del jugador en modo demo.
|
||||||
demoHandlePlayerInput(player, index);
|
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||||
void Game::demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index) {
|
void Game::demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index) {
|
||||||
const auto &demo_data = demo_.data.at(index).at(demo_.counter);
|
const auto& demo_data = demo_.data.at(index).at(demo_.index);
|
||||||
|
|
||||||
if (demo_data.left == 1) {
|
if (demo_data.left == 1) {
|
||||||
player->setInput(Input::Action::LEFT);
|
player->setInput(Input::Action::LEFT);
|
||||||
@@ -1289,30 +1312,30 @@ void Game::demoHandlePlayerInput(const std::shared_ptr<Player> &player, int inde
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (demo_data.fire == 1) {
|
if (demo_data.fire == 1) {
|
||||||
handleFireInput(player, BulletType::UP);
|
handleFireInput(player, Bullet::Type::UP);
|
||||||
} else if (demo_data.fire_left == 1) {
|
} else if (demo_data.fire_left == 1) {
|
||||||
handleFireInput(player, BulletType::LEFT);
|
handleFireInput(player, Bullet::Type::LEFT);
|
||||||
} else if (demo_data.fire_right == 1) {
|
} else if (demo_data.fire_right == 1) {
|
||||||
handleFireInput(player, BulletType::RIGHT);
|
handleFireInput(player, Bullet::Type::RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos.
|
// Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos.
|
||||||
void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bullet_type) {
|
void Game::handleFireInput(const std::shared_ptr<Player>& player, Bullet::Type type) {
|
||||||
if (player->canFire()) {
|
if (player->canFire()) {
|
||||||
SDL_Point bullet = {0, 0};
|
SDL_Point bullet = {0, 0};
|
||||||
switch (bullet_type) {
|
switch (type) {
|
||||||
case BulletType::UP:
|
case Bullet::Type::UP:
|
||||||
player->setInput(Input::Action::FIRE_CENTER);
|
player->setInput(Input::Action::FIRE_CENTER);
|
||||||
bullet.x = 2 + player->getPosX() + (Player::WIDTH - Bullet::WIDTH) / 2;
|
bullet.x = 2 + player->getPosX() + (Player::WIDTH - Bullet::WIDTH) / 2;
|
||||||
bullet.y = player->getPosY() - (Bullet::HEIGHT / 2);
|
bullet.y = player->getPosY() - (Bullet::HEIGHT / 2);
|
||||||
break;
|
break;
|
||||||
case BulletType::LEFT:
|
case Bullet::Type::LEFT:
|
||||||
player->setInput(Input::Action::FIRE_LEFT);
|
player->setInput(Input::Action::FIRE_LEFT);
|
||||||
bullet.x = player->getPosX() - (Bullet::WIDTH / 2);
|
bullet.x = player->getPosX() - (Bullet::WIDTH / 2);
|
||||||
bullet.y = player->getPosY();
|
bullet.y = player->getPosY();
|
||||||
break;
|
break;
|
||||||
case BulletType::RIGHT:
|
case Bullet::Type::RIGHT:
|
||||||
player->setInput(Input::Action::FIRE_RIGHT);
|
player->setInput(Input::Action::FIRE_RIGHT);
|
||||||
bullet.x = player->getPosX() + Player::WIDTH - (Bullet::WIDTH / 2);
|
bullet.x = player->getPosX() + Player::WIDTH - (Bullet::WIDTH / 2);
|
||||||
bullet.y = player->getPosY();
|
bullet.y = player->getPosY();
|
||||||
@@ -1320,8 +1343,8 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
createBullet(bullet.x, bullet.y, bullet_type, player->isPowerUp(), player->getId());
|
createBullet(bullet.x, bullet.y, type, player->getNextBulletColor(), static_cast<int>(player->getId()));
|
||||||
playSound("bullet.wav");
|
playSound(player->getBulletSoundFile());
|
||||||
|
|
||||||
// Establece un tiempo de espera para el próximo disparo.
|
// Establece un tiempo de espera para el próximo disparo.
|
||||||
constexpr int POWERUP_COOLDOWN = 5;
|
constexpr int POWERUP_COOLDOWN = 5;
|
||||||
@@ -1386,7 +1409,7 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
handleFireInput(player, BulletType::UP);
|
handleFireInput(player, Bullet::Type::UP);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire = 1;
|
demo_.keys.fire = 1;
|
||||||
#endif
|
#endif
|
||||||
@@ -1394,7 +1417,7 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
handleFireInput(player, BulletType::LEFT);
|
handleFireInput(player, Bullet::Type::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire_left = 1;
|
demo_.keys.fire_left = 1;
|
||||||
#endif
|
#endif
|
||||||
@@ -1402,7 +1425,7 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) {
|
||||||
handleFireInput(player, BulletType::RIGHT);
|
handleFireInput(player, Bullet::Type::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire_right = 1;
|
demo_.keys.fire_right = 1;
|
||||||
#endif
|
#endif
|
||||||
@@ -1486,28 +1509,50 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
|||||||
}
|
}
|
||||||
player->setInput(Input::Action::START);
|
player->setInput(Input::Action::START);
|
||||||
player->setPlayingState(Player::State::SHOWING_NAME);
|
player->setPlayingState(Player::State::SHOWING_NAME);
|
||||||
playSound("service_menu_select.wav");
|
playSound("name_input_accept.wav");
|
||||||
updateHiScoreName();
|
updateHiScoreName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables para el modo DEMO
|
// Inicializa las variables para el modo DEMO
|
||||||
void Game::initDemo(Player::Id player_id) {
|
void Game::initDemo(Player::Id player_id) {
|
||||||
|
#ifdef RECORDING
|
||||||
|
// En modo grabación, inicializar vector vacío para almacenar teclas
|
||||||
|
demo_.data.emplace_back(); // Vector vacío para grabación
|
||||||
|
demo_.data.at(0).reserve(TOTAL_DEMO_DATA); // Reservar espacio para 2000 elementos
|
||||||
|
#endif
|
||||||
|
|
||||||
if (demo_.enabled) {
|
if (demo_.enabled) {
|
||||||
// Cambia el estado del juego
|
// Cambia el estado del juego
|
||||||
setState(State::PLAYING);
|
setState(State::PLAYING);
|
||||||
|
|
||||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
#ifndef RECORDING
|
||||||
const auto DEMO1 = rand() % 2;
|
// En modo juego: cargar todas las demos y asignar una diferente a cada jugador
|
||||||
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
demo_.data.emplace_back(Resource::get()->getDemoData(num_demo));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crear índices mezclados para asignación aleatoria
|
||||||
|
std::vector<size_t> demo_indices(NUM_DEMOS);
|
||||||
|
std::iota(demo_indices.begin(), demo_indices.end(), 0);
|
||||||
|
std::random_device rd;
|
||||||
|
std::default_random_engine rng(rd());
|
||||||
|
std::shuffle(demo_indices.begin(), demo_indices.end(), rng);
|
||||||
|
|
||||||
|
// Asignar demos a jugadores (round-robin si hay más jugadores que demos)
|
||||||
|
for (size_t i = 0; i < players_.size(); ++i) {
|
||||||
|
size_t demo_index = demo_indices[i % NUM_DEMOS];
|
||||||
|
players_.at(i)->setDemoFile(demo_index);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Selecciona una pantalla al azar
|
// Selecciona una pantalla al azar
|
||||||
constexpr auto NUM_DEMOS = 3;
|
constexpr auto NUM_STAGES = 3;
|
||||||
const auto DEMO = rand() % NUM_DEMOS;
|
const auto STAGE = rand() % NUM_STAGES;
|
||||||
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
|
constexpr std::array<float, NUM_STAGES> STAGES = {0.005F, 0.32F, 0.53F};
|
||||||
stage_manager_->jumpToStage(STAGES.at(DEMO));
|
stage_manager_->setTotalPower(stage_manager_->getTotalPowerNeededToCompleteGame() * STAGES.at(STAGE));
|
||||||
|
background_->setProgress(stage_manager_->getTotalPower());
|
||||||
|
|
||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
if (rand() % 3 != 0) {
|
if (rand() % 3 != 0) {
|
||||||
@@ -1541,7 +1586,7 @@ void Game::initDemo(Player::Id player_id) {
|
|||||||
#else
|
#else
|
||||||
demo_.recording = false;
|
demo_.recording = false;
|
||||||
#endif
|
#endif
|
||||||
demo_.counter = 0;
|
demo_.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el marcador
|
// Inicializa el marcador
|
||||||
@@ -1596,7 +1641,11 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
// Crea al jugador uno y lo pone en modo espera
|
// Crea al jugador uno y lo pone en modo espera
|
||||||
Player::Config config_player1{
|
Player::Config config_player1{
|
||||||
.id = Player::Id::PLAYER1,
|
.id = Player::Id::PLAYER1,
|
||||||
|
#ifdef RECORDING
|
||||||
|
.x = param.game.play_area.center_x - (Player::WIDTH / 2),
|
||||||
|
#else
|
||||||
.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2),
|
.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2),
|
||||||
|
#endif
|
||||||
.y = Y,
|
.y = Y,
|
||||||
.demo = demo_.enabled,
|
.demo = demo_.enabled,
|
||||||
.play_area = ¶m.game.play_area.rect,
|
.play_area = ¶m.game.play_area.rect,
|
||||||
@@ -1607,11 +1656,17 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
.stage_info = stage_manager_.get()};
|
.stage_info = stage_manager_.get()};
|
||||||
|
|
||||||
auto player1 = std::make_unique<Player>(config_player1);
|
auto player1 = std::make_unique<Player>(config_player1);
|
||||||
|
player1->setBulletColors(Bullet::Color::YELLOW, Bullet::Color::GREEN);
|
||||||
|
player1->setBulletSoundFile("bullet1p.wav");
|
||||||
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||||
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||||
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
||||||
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
||||||
|
#ifdef RECORDING
|
||||||
|
player1->setPlayingState(Player::State::PLAYING);
|
||||||
|
#else
|
||||||
player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING);
|
player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Crea al jugador dos y lo pone en modo espera
|
// Crea al jugador dos y lo pone en modo espera
|
||||||
Player::Config config_player2{
|
Player::Config config_player2{
|
||||||
@@ -1627,6 +1682,8 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
.stage_info = stage_manager_.get()};
|
.stage_info = stage_manager_.get()};
|
||||||
|
|
||||||
auto player2 = std::make_unique<Player>(config_player2);
|
auto player2 = std::make_unique<Player>(config_player2);
|
||||||
|
player2->setBulletColors(Bullet::Color::RED, Bullet::Color::PURPLE);
|
||||||
|
player2->setBulletSoundFile("bullet2p.wav");
|
||||||
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||||
player2->setName(Lang::getText("[SCOREBOARD] 2"));
|
player2->setName(Lang::getText("[SCOREBOARD] 2"));
|
||||||
player2->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER2).instance);
|
player2->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER2).instance);
|
||||||
@@ -1645,8 +1702,8 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hace sonar la música
|
// Hace sonar la música
|
||||||
void Game::playMusic() {
|
void Game::playMusic(const std::string& music_file, int loop) {
|
||||||
Audio::get()->playMusic("playing.ogg");
|
Audio::get()->playMusic(music_file, loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pausa la música
|
// Pausa la música
|
||||||
@@ -1667,7 +1724,7 @@ void Game::stopMusic() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables durante el modo demo
|
// Actualiza las variables durante el modo demo
|
||||||
void Game::updateDemo() {
|
void Game::updateDemo(float deltaTime) {
|
||||||
if (demo_.enabled) {
|
if (demo_.enabled) {
|
||||||
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||||
|
|
||||||
@@ -1675,16 +1732,12 @@ void Game::updateDemo() {
|
|||||||
fade_in_->update();
|
fade_in_->update();
|
||||||
fade_out_->update();
|
fade_out_->update();
|
||||||
|
|
||||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
// Actualiza el contador de tiempo y el índice
|
||||||
static float demo_frame_timer = 0.0f;
|
demo_.elapsed_s += deltaTime;
|
||||||
demo_frame_timer += calculateDeltaTime();
|
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||||
if (demo_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
|
||||||
demo_.counter++;
|
|
||||||
demo_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activa el fundido antes de acabar con los datos de la demo
|
// Activa el fundido antes de acabar con los datos de la demo
|
||||||
if (demo_.counter == TOTAL_DEMO_DATA - 200) {
|
if (demo_.index == TOTAL_DEMO_DATA - 200) {
|
||||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
@@ -1700,22 +1753,28 @@ void Game::updateDemo() {
|
|||||||
|
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
// Actualiza las variables durante el modo de grabación
|
// Actualiza las variables durante el modo de grabación
|
||||||
void Game::updateRecording() {
|
void Game::updateRecording(float deltaTime) {
|
||||||
// Solo mira y guarda el input en cada update
|
// Actualiza el contador de tiempo y el índice
|
||||||
checkInput();
|
demo_.elapsed_s += deltaTime;
|
||||||
|
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||||
|
|
||||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
if (demo_.index >= TOTAL_DEMO_DATA) {
|
||||||
static float recording_frame_timer = 0.0f;
|
Section::name = Section::Name::QUIT;
|
||||||
recording_frame_timer += calculateDeltaTime();
|
return;
|
||||||
if (recording_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
|
||||||
demo_.counter++;
|
|
||||||
recording_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se ha llenado el vector con datos, sale del programa
|
// Almacenar las teclas del frame actual en el vector de grabación
|
||||||
else {
|
if (demo_.index < TOTAL_DEMO_DATA && demo_.data.size() > 0) {
|
||||||
section::name = section::Name::QUIT;
|
// Asegurar que el vector tenga el tamaño suficiente
|
||||||
return;
|
if (demo_.data.at(0).size() <= static_cast<size_t>(demo_.index)) {
|
||||||
|
demo_.data.at(0).resize(demo_.index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Almacenar las teclas del frame actual
|
||||||
|
demo_.data.at(0).at(demo_.index) = demo_.keys;
|
||||||
|
|
||||||
|
// Resetear las teclas para el siguiente frame
|
||||||
|
demo_.keys = DemoKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1751,24 +1810,21 @@ void Game::updateGameStateEnteringPlayer(float deltaTime) {
|
|||||||
void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
|
void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
|
||||||
updateGameStatePlaying(deltaTime);
|
updateGameStatePlaying(deltaTime);
|
||||||
|
|
||||||
// Reproducir música después de ~1.67 segundos (100 frames a 60fps)
|
constexpr float MUSIC_START_S = 1.67F;
|
||||||
static bool music_started = false;
|
|
||||||
static float music_timer = 0.0f;
|
static float music_timer = 0.0f;
|
||||||
if (!music_started) {
|
|
||||||
music_timer += deltaTime;
|
music_timer += deltaTime;
|
||||||
if (music_timer >= 1.67f) {
|
if (music_timer >= MUSIC_START_S) {
|
||||||
playMusic();
|
playMusic("playing.ogg");
|
||||||
music_started = true;
|
music_timer = 0.0F;
|
||||||
setState(State::PLAYING);
|
setState(State::PLAYING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables durante el transcurso normal del juego
|
// Actualiza las variables durante el transcurso normal del juego
|
||||||
void Game::updateGameStatePlaying(float deltaTime) {
|
void Game::updateGameStatePlaying(float deltaTime) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (auto_pop_balloons_) {
|
if (auto_pop_balloons_) {
|
||||||
stage_manager_->addPower(1);
|
stage_manager_->addPower(2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
updatePlayers(deltaTime);
|
updatePlayers(deltaTime);
|
||||||
@@ -1861,6 +1917,10 @@ void Game::setState(State state) {
|
|||||||
destroyAllItems(); // Destruye todos los items
|
destroyAllItems(); // Destruye todos los items
|
||||||
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
|
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
|
||||||
tabe_->disableSpawning(); // Deshabilita la creacion de Tabes
|
tabe_->disableSpawning(); // Deshabilita la creacion de Tabes
|
||||||
|
game_completed_flags_.reset(); // Resetea flags de juego completado
|
||||||
|
break;
|
||||||
|
case State::GAME_OVER:
|
||||||
|
game_over_flags_.reset(); // Resetea flags de game over
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1922,12 +1982,11 @@ void Game::onPauseStateChanged(bool is_paused) {
|
|||||||
|
|
||||||
// Maneja eventos del juego completado usando flags para triggers únicos
|
// Maneja eventos del juego completado usando flags para triggers únicos
|
||||||
void Game::handleGameCompletedEvents() {
|
void Game::handleGameCompletedEvents() {
|
||||||
constexpr float START_CELEBRATIONS_S = 6.667f; // 400 frames a 60fps → segundos
|
constexpr float START_CELEBRATIONS_S = 6.0f;
|
||||||
constexpr float END_CELEBRATIONS_S = 11.667f; // 700 frames a 60fps → segundos
|
constexpr float END_CELEBRATIONS_S = 14.0f;
|
||||||
|
|
||||||
// Inicio de celebraciones
|
// Inicio de celebraciones
|
||||||
static bool start_celebrations_triggered = false;
|
if (!game_completed_flags_.start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_S) {
|
||||||
if (!start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_S) {
|
|
||||||
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
||||||
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
||||||
|
|
||||||
@@ -1941,31 +2000,44 @@ void Game::handleGameCompletedEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
start_celebrations_triggered = true;
|
playMusic("congratulations.ogg", 1);
|
||||||
|
game_completed_flags_.start_celebrations_triggered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fin de celebraciones
|
// Fin de celebraciones
|
||||||
static bool end_celebrations_triggered = false;
|
if (!game_completed_flags_.end_celebrations_triggered && game_completed_timer_ >= END_CELEBRATIONS_S) {
|
||||||
if (!end_celebrations_triggered && game_completed_timer_ >= END_CELEBRATIONS_S) {
|
|
||||||
for (auto& player : players_) {
|
for (auto& player : players_) {
|
||||||
if (player->isCelebrating()) {
|
if (player->isCelebrating()) {
|
||||||
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
player->setPlayingState(player->qualifiesForHighScore() ? Player::State::ENTERING_NAME_GAME_COMPLETED : Player::State::LEAVING_SCREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
game_completed_flags_.end_celebrations_triggered = true;
|
||||||
fade_out_->activate();
|
|
||||||
end_celebrations_triggered = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maneja eventos de game over usando flag para trigger único
|
// Maneja eventos discretos basados en tiempo durante el estado game over
|
||||||
void Game::handleGameOverEvents() {
|
void Game::handleGameOverEvents() {
|
||||||
static bool game_over_triggered = false;
|
constexpr float MESSAGE_TRIGGER_S = 1.5f;
|
||||||
if (!game_over_triggered && game_over_timer_ == 0.0f) {
|
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5f;
|
||||||
createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_text_game_over"));
|
|
||||||
|
// Trigger inicial: fade out de música y sonidos de globos
|
||||||
|
if (!game_over_flags_.music_fade_triggered) {
|
||||||
Audio::get()->fadeOutMusic(1000);
|
Audio::get()->fadeOutMusic(1000);
|
||||||
balloon_manager_->setBouncingSounds(true);
|
balloon_manager_->setBouncingSounds(true);
|
||||||
game_over_triggered = true;
|
game_over_flags_.music_fade_triggered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger del mensaje "Game Over"
|
||||||
|
if (!game_over_flags_.message_triggered && game_over_timer_ >= MESSAGE_TRIGGER_S) {
|
||||||
|
createMessage({paths_.at(10), paths_.at(11)}, Resource::get()->getTexture("game_text_game_over"));
|
||||||
|
playSound("voice_game_over.wav");
|
||||||
|
game_over_flags_.message_triggered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger del fade out
|
||||||
|
if (!game_over_flags_.fade_out_triggered && game_over_timer_ >= FADE_TRIGGER_S && !fade_out_->isEnabled()) {
|
||||||
|
fade_out_->activate();
|
||||||
|
game_over_flags_.fade_out_triggered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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
|
||||||
@@ -214,7 +248,7 @@ 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
|
||||||
@@ -228,7 +262,7 @@ class Game {
|
|||||||
// --- 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
|
||||||
|
|
||||||
@@ -250,7 +284,7 @@ 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 ---
|
||||||
@@ -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,7 +335,7 @@ 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
|
||||||
@@ -313,7 +347,7 @@ class Game {
|
|||||||
|
|
||||||
// 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) ---
|
||||||
|
|||||||
@@ -368,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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,40 +79,40 @@ 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_);
|
||||||
@@ -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);
|
||||||
@@ -178,7 +179,7 @@ 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
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -43,7 +43,11 @@ 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(0.0F);
|
tiled_bg_->setSpeed(0.0F);
|
||||||
@@ -141,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) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
@@ -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
|
||||||
@@ -97,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:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -53,7 +52,6 @@ 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
|
||||||
|
|||||||
@@ -324,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);
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -127,12 +88,6 @@ auto stringInVector(const std::vector<std::string> &vec, const std::string &str)
|
|||||||
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3); // Imprime una línea con puntos
|
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
|
||||||
|
|||||||
6
source/version.h.in
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Version {
|
||||||
|
constexpr const char* GIT_HASH = "@GIT_HASH@";
|
||||||
|
constexpr const char* APP_NAME = "Coffee Crisis Arcade Edition";
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||