97 Commits

Author SHA1 Message Date
c610065fe0 Actualizar README.md 2025-11-01 20:09:34 +01:00
d2be113c4e corregit makefile 2025-10-25 09:29:01 +02:00
052bb063df Corregit resource_helper i millora DMG amb create-dmg 2025-10-25 00:20:35 +02:00
9d974438b3 millorat makefile per a que el dmg es veja millor 2025-10-24 23:31:30 +02:00
b9fe376f2a eliminat el fallback a disc en les versions de release 2025-10-24 23:21:27 +02:00
0c05f6d5b6 corregida la versio release de macos per a funcionar correctament amb resources.pack 2025-10-24 23:11:48 +02:00
39125ee57c nou icon 2025-10-24 21:17:29 +02:00
7ebeeebaaf arreglat include en pack_resources.cpp 2025-10-24 18:38:02 +02:00
c6c7b63f6d ultim linter 2025-10-24 18:36:00 +02:00
7959baeed9 linter 2025-10-24 18:22:15 +02:00
5d1c6c6d99 linter 2025-10-24 18:11:51 +02:00
145d1e3fc0 canvis en run_clang-tidy.sh 2025-10-24 17:58:53 +02:00
4679255d60 linter 2025-10-24 17:50:31 +02:00
3cfb65320c linter: opengl_shader.cpp 2025-10-24 17:21:17 +02:00
636e4d932a linter: varios 2025-10-24 17:12:57 +02:00
9979f31b4a linter: manage_hiscore_table 2025-10-24 14:10:38 +02:00
6190b35349 integrat jail_audio en la carrega de resources.pack 2025-10-24 13:59:03 +02:00
fd4136a882 linter: varios 2025-10-24 13:45:56 +02:00
5362c5b022 linter; manage_hiscore i resource_loader 2025-10-24 12:06:53 +02:00
357b5d5977 linter: renombrar variables 2025-10-24 10:33:18 +02:00
f50ad68f10 linter: resource_pack 2025-10-24 10:27:56 +02:00
155a7d038d ajustades constants en credits.cpp 2025-10-24 10:13:10 +02:00
4b732c189c migrat correctament a delta_time credits.cpp i eliminat un bug que feia que si no pasaves a ma el final, no acabara mai 2025-10-24 10:10:55 +02:00
1c3d59d678 migrat hiscore_table a delta_time de manera correcta
corregida deformació subpixel de la textura en instructions i hiscore_table
2025-10-24 08:49:09 +02:00
1acbe1d097 migrat instructions a delta_time pur 2025-10-23 18:59:37 +02:00
245524c021 fix: detecta fitxers de puntuació corruptes 2025-10-23 18:47:38 +02:00
b4624a9223 arreglos en makefiles i cmakes 2025-10-23 18:32:17 +02:00
28e3e1ee0a style: si ja havies posat nom, el carrusel apareix directament en el caracter d'acabar 2025-10-23 17:46:06 +02:00
e250ca048f calibrats els pulsos al gust 2025-10-23 14:56:33 +02:00
5bf96b9aba afegit "pulsos" a scoreboard 2025-10-23 14:44:51 +02:00
ac6f521288 fix: la logica de Rects dels credits 2025-10-22 21:02:09 +02:00
5a5c06efd1 fix: si vas a posar nom i el nom ja està ple, ja aplica les restriccions i posa el carrusel com toca 2025-10-22 19:58:47 +02:00
ef1a514c9b style: ja pots mouret pel carrusel de posar nom mantenint la direccio apretada (ja no vas lletra a lletra) 2025-10-22 19:55:02 +02:00
ce54b10abb afegida classe Cooldown 2025-10-22 19:54:27 +02:00
40538eaa28 el carrusel ja s'anima supersucosetment cap al OK de manera automática 2025-10-22 18:56:59 +02:00
88d814f371 Visualment, el carrusel ja salta al ultim caracter (instantani)
Si no hi ha lletres per a borrar, no fa roidet
2025-10-22 18:47:42 +02:00
b933ceee63 Traslladada logica de clavar nom de game a player
Si no caben mes lletres, salta a l'ultim caracter i bloqueja el carrusel
2025-10-22 18:36:32 +02:00
75ccddbaa1 style: ja hi ha un caracter per acabar de posar el nom 2025-10-22 18:17:58 +02:00
fde77affdf fix: ja no s'escolta el time stopper al passar-se el joc
style: ja no ix el lletrero de gameover al passar-se el joc
2025-10-22 17:05:38 +02:00
52a387463d fix: Fade Type::FULLSCREEN no iniciava correctament i el primer frame de un fade_in mostrava el contingut 2025-10-22 15:40:17 +02:00
5a0fc9330d fix: splash.png corregit 2025-10-22 15:25:57 +02:00
66661036a4 fix: en Player::handleRecoverMovement() es reproduía voice_recover.wav constantment 2025-10-22 15:17:05 +02:00
bb132aade2 afegit caracter de acabar de posar el nom (no en us encara)
corregida la logica de animacio i desplaçament del carrusel de posar nom
2025-10-22 15:05:57 +02:00
d4e09e1e88 gameplay: canviat text de SuperPoder per Automatic 2025-10-22 13:03:16 +02:00
866f464d37 gameplay: la maquina de café ja no tapa els globos (al reves) 2025-10-22 12:58:53 +02:00
da9f3c1e02 refeta la classe Fade perque nomes havia un tipo de fade migrat a time based. ara ja estan tots correctes 2025-10-21 21:12:29 +02:00
9b8fdf289f animacions noves per al jugador2,
cada jugador te el seu fitxer d'animacions per separat
2025-10-21 20:42:17 +02:00
bf12c1664a fix: nou metode per ordenar i dibuixar els jugadors ordenats en l'eix Z
codi: eliminat tot el codi mort de Hit
2025-10-21 09:30:31 +02:00
d7836eedd7 canvi de pc (treballant en el z-order dels jugadors per evitar reordenar el vector) 2025-10-20 21:41:23 +02:00
4bac816e37 style: meeees retocs a la pantalla de càrrega 2025-10-20 21:07:22 +02:00
67f9103b96 fix: updateAlphaColorTexture() en Background class per a utilitzar delta_time 2025-10-20 20:54:34 +02:00
8ddee66304 fix: el cicle de color de credits.cpp 2025-10-20 20:36:33 +02:00
4fb6a9999f animacions noves dels jugadors per al final 2025-10-20 20:06:32 +02:00
794dcf83f6 style: toquejant mes la pantalla de carrega 2025-10-20 18:11:39 +02:00
9fe73ed8e4 style: toquejant la pantalla de càrrega 2025-10-20 14:07:14 +02:00
e99b2abd7d style: canviat un ifndef per un pragma once 2025-10-20 13:18:09 +02:00
b128b285ed fix: alguns logs de consola
fix: alguns .h s'havien canviat a .hpp per error
2025-10-20 12:43:43 +02:00
c8bf9640cf corregits bugs de toquetechar vectors i merdes i passats a lists 2025-10-20 12:29:37 +02:00
2b4523d644 linter 2025-10-19 22:01:31 +02:00
16306f2325 els items començen a parpadejar quan ja estan quets a terra 2025-10-19 19:51:07 +02:00
d7c3ea7f69 corregit el pixelart dels logos de JAILGAMES 2025-10-19 18:25:00 +02:00
413c3c30a6 afegit el namespace Logger 2025-10-19 18:10:55 +02:00
df6e7e5155 eliminat el cadaver que havia de jail_shader.cpp per ahi 2025-10-17 21:58:12 +02:00
46974ef2eb renombrades extensions .h a .hpp 2025-10-17 21:45:19 +02:00
50ccb2ccc2 commit pollós 2025-10-17 21:09:08 +02:00
9b966a260c fix: el fitxer de config el trobava i despres deia que no el trobava 2025-10-17 20:48:47 +02:00
49ea56f5e2 fix: WARNING: Parámetro desconocido: game.item_size 2025-10-17 20:33:02 +02:00
300edc90b5 PathSprite: ja permet createPath amb temps o frames 2025-10-17 14:02:40 +02:00
5ff33ca6ca fix: ja es mou la herbeta 2025-10-16 20:43:48 +02:00
6dc6d8fc24 fix: Dejar que SDL elija OpenGL automáticamente en Linux
- Windows: opengl + 3.3 Core Profile explícito
- Linux: opengl sin atributos, SDL elige:
  * Desktop 3.3 en PC con GPU normal
  * ES 3.0 en RPi automáticamente

Resuelve problema de colores invertidos (azul->naranja) causado
por forzar opengles2.
2025-10-02 22:05:18 +02:00
8d94ed516c fix: Renderizar textura antes de inicializar shaders
En constructor: SDL_RenderTexture() antes de initShaders()
Esto asegura que la textura tiene contenido válido.

Revertido lazy initialization que no funcionaba.
Vuelta a la solución original que sí funcionaba.
2025-10-02 22:00:30 +02:00
ba0b0930b0 fix: Mejorar obtención de texture ID en OpenGL ES
- Probar SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER para ES
- Probar SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER para Desktop
- Añadir logs detallados para debug
- No intentar bind si texture_id es 0 (prevenir GL_INVALID_ENUM)

Refs: Error 0x500 en glBindTexture en RPi
2025-10-02 21:55:49 +02:00
29e76b1ddd feat: Forzar OpenGL ES en Linux/RPi mediante SDL hint
- Windows: hint 'opengl' + OpenGL 3.3 Core Profile
- Linux/RPi: hint 'opengles2,opengl' (intenta ES, fallback a Desktop)
- SDL_WINDOW_OPENGL flag es genérico, funciona con ambos

También lazy initialization de shaders para evitar textura vacía.
2025-10-02 21:48:57 +02:00
54ceaa3042 debug: Añadir logs en inicialización de shaders
Para debuggear problema de pantalla negra en RPi al iniciar con shaders activos.
Logs muestran tamaños de ventana/textura y configuración de uniforms.
2025-10-02 21:40:12 +02:00
dcc223d287 fix: Cambiar shaders ES de 3.1 a 3.0 para Raspberry Pi
RPi 5 solo soporta OpenGL ES 3.0, no 3.1.
Cambiada versión de #version 310 es a #version 300 es
2025-10-02 21:22:14 +02:00
7187412a45 feat: Soporte OpenGL ES 3.1 para Raspberry Pi
- Creados shaders GLSL ES 3.1 (crtpi_*_es.glsl)
- Detección automática: intenta cargar ES primero, fallback a Desktop
- Windows: pide OpenGL 3.3 Core Profile explícitamente
- Linux/RPi: deja que SDL elija (usará OpenGL ES si está disponible)
- assets.txt actualizado con shaders ES como opcionales

Resuelve problema en RPi 5 donde OpenGL 3.3 Core no está soportado
pero OpenGL ES 3.1 sí lo está mediante drivers Mesa/VideoCore.
2025-10-02 21:12:08 +02:00
ff7aef827c migracio a OpenGL 3.3 Core Profile completada 2025-10-02 18:24:18 +02:00
6ff7ccf69a migrat a OpenGL 3.3 Core Profile 2025-10-02 18:15:39 +02:00
e347e04d33 fix: arreglat bug en jail_shader.cpp que no aplicava be el tamany de la textura amb filtros al canviar el tamany de la finestra si arrancaves el joc sense filtros activats 2025-10-02 17:24:40 +02:00
7946ea54a6 unificats els shaders glsl en un sol fitxer
corregida la inicialització de opengl i shaders
2025-10-02 17:11:38 +02:00
79033346c0 migrat fitxer de config a v2 2025-10-02 16:35:11 +02:00
62b73d6f41 bug fix: si desapareixia la maquina de cafe, ja no eixia mes 2025-10-02 12:04:17 +02:00
218ddabb5e bug fix: no eixien pacos 2025-10-02 08:28:15 +02:00
427f40632a scoreboard.cpp: animació de SCORE a ENTER_NAME 2025-10-01 21:31:42 +02:00
a29b4d4379 scoreboard.cpp: modificada la easing function de desplaçament vertical a easeInOutSine 2025-10-01 20:10:42 +02:00
d851cdd2fe scoreboard.cpp: afegit un setMode() com deu mana 2025-10-01 20:06:08 +02:00
3354d00814 Transició acabada, encara que hi ha un desfase de 1 pixel 2025-10-01 19:34:23 +02:00
7bd7ba84e0 scoreboard.cpp: treballant en transicio de ENTER_NAME a SHOW_NAME 2025-10-01 19:11:58 +02:00
6ad34eaf57 finalitzada la implementació del carrusel 2025-10-01 18:49:11 +02:00
b4f2251508 animacio al pixel del carrusel feta, falla el color que no transiciona 2025-10-01 18:36:14 +02:00
473a52f986 treballant en la animacio alpixel del carrusel 2025-10-01 18:05:00 +02:00
bcdd48d622 carrusel funcional i acabat 2025-10-01 17:49:29 +02:00
6985569573 el carrusel ara es mou amb esquerra i dreta en lloc de amb amunt i avall 2025-10-01 17:13:52 +02:00
5db43e674d Color: afegit metode LERP() 2025-10-01 14:11:32 +02:00
34baa3c97d treballan en el carrusel per a posar el nom 2025-10-01 14:00:56 +02:00
bddb790fe2 creat bullet_manager.cpp 2025-09-30 20:41:35 +02:00
6fae12ba02 fix: la ultima tarjeta de la intro no tenia temps de repos 2025-09-30 19:59:38 +02:00
199 changed files with 7454 additions and 5435 deletions

5
.gitignore vendored
View File

@@ -18,4 +18,9 @@ debug.txt
cppcheck-result* cppcheck-result*
desktop.ini desktop.ini
ccae_release/ ccae_release/
Frameworks/
resources.pack resources.pack
# Herramienta pack_resources (todas las plataformas)
tools/pack_resources
tools/pack_resources.exe

View File

@@ -64,6 +64,7 @@ set(APP_SOURCES
source/balloon_manager.cpp source/balloon_manager.cpp
source/balloon.cpp source/balloon.cpp
source/bullet.cpp source/bullet.cpp
source/bullet_manager.cpp
source/enter_name.cpp source/enter_name.cpp
source/explosions.cpp source/explosions.cpp
source/game_logo.cpp source/game_logo.cpp
@@ -110,22 +111,27 @@ 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_audio.cpp
source/external/jail_shader.cpp
source/external/json.hpp source/external/json.hpp
source/external/gif.cpp source/external/gif.cpp
) )
# Fuentes del sistema de renderizado
set(RENDERING_SOURCES
source/rendering/opengl/opengl_shader.cpp
)
# 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}")
# --- 2. AÑADIR EJECUTABLE --- # --- 2. AÑADIR EJECUTABLE ---
add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES}) add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES} ${RENDERING_SOURCES})
# --- 3. DIRECTORIOS DE INCLUSIÓN --- # --- 3. DIRECTORIOS DE INCLUSIÓN ---
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_SOURCE_DIR}/source/rendering"
"${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}"
) )

171
Makefile
View File

@@ -22,7 +22,7 @@ else
PACK_CXX := $(CXX) PACK_CXX := $(CXX)
endif endif
PACK_SOURCES := $(DIR_TOOLS)pack_resources.cpp $(DIR_SOURCES)resource_pack.cpp PACK_SOURCES := $(DIR_TOOLS)pack_resources.cpp $(DIR_SOURCES)resource_pack.cpp
PACK_INCLUDES := -I$(DIR_ROOT) PACK_INCLUDES := -I$(DIR_ROOT) -I$(DIR_BUILD)
# 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)
@@ -49,45 +49,41 @@ RASPI_RELEASE := $(TARGET_FILE)-$(VERSION)-raspberry.tar.gz
# Lista completa de archivos fuente (basada en CMakeLists.txt) # Lista completa de archivos fuente (basada en CMakeLists.txt)
APP_SOURCES := \ APP_SOURCES := \
source/animated_sprite.cpp \
source/asset.cpp \ source/asset.cpp \
source/audio.cpp \ source/audio.cpp \
source/background.cpp \
source/balloon_formations.cpp \
source/balloon_manager.cpp \
source/balloon.cpp \
source/bullet.cpp \
source/color.cpp \
source/define_buttons.cpp \
source/difficulty.cpp \
source/director.cpp \ source/director.cpp \
source/enter_name.cpp \
source/explosions.cpp \
source/external/gif.cpp \
source/external/jail_audio.cpp \
source/external/jail_shader.cpp \
source/fade.cpp \
source/game_logo.cpp \
source/global_events.cpp \ source/global_events.cpp \
source/global_inputs.cpp \ source/global_inputs.cpp \
source/input_types.cpp \
source/input.cpp \ source/input.cpp \
source/item.cpp \
source/lang.cpp \ source/lang.cpp \
source/main.cpp \ source/main.cpp \
source/manage_hiscore_table.cpp \
source/mouse.cpp \
source/moving_sprite.cpp \
source/options.cpp \
source/param.cpp \ source/param.cpp \
source/path_sprite.cpp \
source/player.cpp \
source/resource.cpp \ source/resource.cpp \
source/resource_helper.cpp \ source/resource_helper.cpp \
source/resource_loader.cpp \ source/resource_loader.cpp \
source/resource_pack.cpp \ source/resource_pack.cpp \
source/scoreboard.cpp \
source/screen.cpp \ source/screen.cpp \
source/text.cpp \
source/writer.cpp \
source/ui/menu_option.cpp \
source/ui/menu_renderer.cpp \
source/ui/notifier.cpp \
source/ui/service_menu.cpp \
source/ui/ui_message.cpp \
source/ui/window_message.cpp \
source/balloon_formations.cpp \
source/balloon_manager.cpp \
source/balloon.cpp \
source/bullet.cpp \
source/bullet_manager.cpp \
source/enter_name.cpp \
source/explosions.cpp \
source/game_logo.cpp \
source/item.cpp \
source/manage_hiscore_table.cpp \
source/player.cpp \
source/scoreboard.cpp \
source/tabe.cpp \
source/sections/credits.cpp \ source/sections/credits.cpp \
source/sections/game.cpp \ source/sections/game.cpp \
source/sections/hiscore_table.cpp \ source/sections/hiscore_table.cpp \
@@ -95,26 +91,32 @@ APP_SOURCES := \
source/sections/intro.cpp \ source/sections/intro.cpp \
source/sections/logo.cpp \ source/sections/logo.cpp \
source/sections/title.cpp \ source/sections/title.cpp \
source/shutdown.cpp \ source/animated_sprite.cpp \
source/background.cpp \
source/fade.cpp \
source/moving_sprite.cpp \
source/path_sprite.cpp \
source/smart_sprite.cpp \ source/smart_sprite.cpp \
source/sprite.cpp \ source/sprite.cpp \
source/stage.cpp \
source/system_utils.cpp \
source/tabe.cpp \
source/text.cpp \
source/texture.cpp \ source/texture.cpp \
source/tiled_bg.cpp \ source/tiled_bg.cpp \
source/ui/menu_option.cpp \ source/color.cpp \
source/ui/menu_renderer.cpp \ source/demo.cpp \
source/ui/notifier.cpp \ source/define_buttons.cpp \
source/ui/service_menu.cpp \ source/difficulty.cpp \
source/ui/ui_message.cpp \ source/input_types.cpp \
source/ui/window_message.cpp \ source/mouse.cpp \
source/options.cpp \
source/shutdown.cpp \
source/stage.cpp \
source/system_utils.cpp \
source/utils.cpp \ source/utils.cpp \
source/writer.cpp source/external/jail_audio.cpp \
source/external/gif.cpp \
source/rendering/opengl/opengl_shader.cpp
# Includes # Includes
INCLUDES := -Isource -Isource/external INCLUDES := -Isource -Isource/external -Isource/rendering -I$(DIR_BUILD)
# Variables según el sistema operativo # Variables según el sistema operativo
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
@@ -148,9 +150,9 @@ else
endif endif
# Reglas para herramienta de empaquetado y resources.pack # Reglas para herramienta de empaquetado y resources.pack
$(PACK_TOOL): $(PACK_SOURCES) $(PACK_TOOL): FORCE
@echo "Compilando herramienta de empaquetado..." @echo "Compilando herramienta de empaquetado..."
$(PACK_CXX) -std=c++17 -Wall -Os $(PACK_INCLUDES) $(PACK_SOURCES) -o $(PACK_TOOL) $(PACK_CXX) -std=c++20 -Wall -Os $(PACK_INCLUDES) $(PACK_SOURCES) -o $(PACK_TOOL)
@echo "✓ Herramienta de empaquetado lista: $(PACK_TOOL)" @echo "✓ Herramienta de empaquetado lista: $(PACK_TOOL)"
pack_tool: $(PACK_TOOL) pack_tool: $(PACK_TOOL)
@@ -178,7 +180,9 @@ 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: resources.pack windows_release:
@$(MAKE) pack_tool
@$(MAKE) resources.pack
@echo off @echo off
@echo Creando release para Windows - Version: $(VERSION) @echo Creando release para Windows - Version: $(VERSION)
@@ -197,7 +201,7 @@ windows_release: resources.pack
# Compila # Compila
windres release/coffee.rc -O coff -o $(RESOURCE_FILE) windres release/coffee.rc -O coff -o $(RESOURCE_FILE)
$(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe" $(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe"
strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded
# Crea el fichero .zip # Crea el fichero .zip
@@ -216,8 +220,14 @@ 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: resources.pack macos_release:
@$(MAKE) pack_tool
@$(MAKE) resources.pack
@echo "Creando release para macOS - Version: $(VERSION)" @echo "Creando release para macOS - Version: $(VERSION)"
# Verificar e instalar create-dmg si es necesario
@which create-dmg > /dev/null || (echo "Instalando create-dmg..." && brew install create-dmg)
# Elimina datos de compilaciones anteriores # Elimina datos de compilaciones anteriores
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
$(RMDIR) Frameworks $(RMDIR) Frameworks
@@ -241,33 +251,52 @@ macos_release: resources.pack
cp LICENSE "$(RELEASE_FOLDER)" cp LICENSE "$(RELEASE_FOLDER)"
cp README.md "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)"
# Crea enlaces
ln -s /Applications "$(RELEASE_FOLDER)"/Applications
# Compila la versión para procesadores Intel # Compila la versión para procesadores Intel
ifdef ENABLE_MACOS_X86_64 ifdef ENABLE_MACOS_X86_64
$(CXX) $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.15 $(CXX) $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.15
# Firma la aplicación # Firma la aplicación
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app" codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Empaqueta el .dmg de la versión Intel # Empaqueta el .dmg de la versión Intel con create-dmg
hdiutil create tmp.dmg -ov -volname "$(APP_NAME)" -fs HFS+ -srcfolder "$(RELEASE_FOLDER)" @echo "Creando DMG Intel con iconos de 96x96..."
hdiutil convert tmp.dmg -format UDZO -o "$(MACOS_INTEL_RELEASE)" create-dmg \
$(RMFILE) tmp.dmg --volname "$(APP_NAME)" \
--window-pos 200 120 \
--window-size 720 300 \
--icon-size 96 \
--text-size 12 \
--icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \
--app-drop-link 115 102 \
--hide-extension "$(APP_NAME).app" \
"$(MACOS_INTEL_RELEASE)" \
"$(RELEASE_FOLDER)" || true
@echo "Release Intel creado: $(MACOS_INTEL_RELEASE)" @echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"
endif endif
# Compila la versión para procesadores Apple Silicon # Compila la versión para procesadores Apple Silicon
$(CXX) $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DSDL_DISABLE_IMMINTRIN_H $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11 $(CXX) $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD -DSDL_DISABLE_IMMINTRIN_H $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
# Firma la aplicación # Firma la aplicación
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app" codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Empaqueta el .dmg de la versión Apple Silicon # Empaqueta el .dmg de la versión Apple Silicon con create-dmg
hdiutil create tmp.dmg -ov -volname "$(APP_NAME)" -fs HFS+ -srcfolder "$(RELEASE_FOLDER)" @echo "Creando DMG Apple Silicon con iconos de 96x96..."
hdiutil convert tmp.dmg -format UDZO -o "$(MACOS_APPLE_SILICON_RELEASE)" create-dmg \
$(RMFILE) tmp.dmg --volname "$(APP_NAME)" \
--window-pos 200 120 \
--window-size 720 300 \
--icon-size 96 \
--text-size 12 \
--icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \
--app-drop-link 115 102 \
--hide-extension "$(APP_NAME).app" \
"$(MACOS_APPLE_SILICON_RELEASE)" \
"$(RELEASE_FOLDER)" || true
@echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)" @echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)"
# Elimina las carpetas temporales # Elimina las carpetas temporales
@@ -283,7 +312,9 @@ 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: resources.pack linux_release:
@$(MAKE) pack_tool
@$(MAKE) 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)"
@@ -298,7 +329,7 @@ linux_release: resources.pack
cp README.md "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)"
# Compila # Compila
$(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)" $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)"
strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded
# Empaqueta ficheros # Empaqueta ficheros
@@ -309,7 +340,9 @@ linux_release: resources.pack
# Elimina la carpeta temporal # Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
linux_release_desktop: resources.pack linux_release_desktop:
@$(MAKE) pack_tool
@$(MAKE) 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)"
@@ -328,7 +361,7 @@ linux_release_desktop: resources.pack
cp README.md "$(RELEASE_FOLDER)/$(TARGET_NAME)/" cp README.md "$(RELEASE_FOLDER)/$(TARGET_NAME)/"
# Compila el ejecutable # Compila el ejecutable
$(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)" $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)"
strip -s -R .comment -R .gnu.version "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)" --strip-unneeded strip -s -R .comment -R .gnu.version "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)" --strip-unneeded
# Crea el archivo .desktop # Crea el archivo .desktop
@@ -414,7 +447,9 @@ 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: resources.pack raspi_release:
@$(MAKE) pack_tool
@$(MAKE) 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)"
@@ -429,7 +464,7 @@ raspi_release: resources.pack
cp README.md "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)"
# Compila # Compila
$(CXX) $(APP_SOURCES) $(INCLUDES) -DVERBOSE $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)" $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD -DVERBOSE $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)"
strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded
# Empaqueta ficheros # Empaqueta ficheros
@@ -440,7 +475,9 @@ raspi_release: resources.pack
# Elimina la carpeta temporal # Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)" $(RMDIR) "$(RELEASE_FOLDER)"
anbernic: resources.pack anbernic:
@$(MAKE) pack_tool
@$(MAKE) 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
@@ -453,7 +490,7 @@ anbernic: resources.pack
cp resources.pack "$(RELEASE_FOLDER)"_anbernic cp resources.pack "$(RELEASE_FOLDER)"_anbernic
# Compila # Compila
$(CXX) $(APP_SOURCES) $(INCLUDES) -DANBERNIC -DNO_SHADERS -DARCADE -DVERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME) $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD -DANBERNIC -DNO_SHADERS -DARCADE -DVERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME)
# Opción para deshabilitar audio (equivalente a la opción DISABLE_AUDIO de CMake) # Opción para deshabilitar audio (equivalente a la opción DISABLE_AUDIO de CMake)
no_audio: no_audio:
@@ -487,4 +524,6 @@ help:
@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 pack_tool .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 resources.pack
FORCE:

View File

@@ -1,6 +1,8 @@
# Coffee Crisis Arcade Edition <div align="center">
<img src="https://php.sustancia.synology.me/images/ccae/coffee_crisis_arcade_edition_cover_web.png" width="600" alt="Coffee Crisis Cover">
</div>
<img src="https://php.sustancia.synology.me/images/ccae/coffee_crisis_arcade_edition_cover_web.png" width="300" align="left" style="margin-right: 20px; margin-bottom: 10px;" alt="Coffee Crisis Cover"> # Coffee Crisis Arcade Edition
## ¡La batalla definitiva pel cafè està ací! ## ¡La batalla definitiva pel cafè està ací!
@@ -35,10 +37,7 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
> Nota: El joc suporta nomes un jugador amb teclat. > Nota: El joc suporta nomes un jugador amb teclat.
<p align="center"> ![Coffee Crisis Arcade Edition - Gameplay](https://php.sustancia.synology.me/images/ccae/ccae1.png)
<img src="https://php.sustancia.synology.me/images/ccae/ccae1.png" alt="Joc" width="45%" />
<img src="https://php.sustancia.synology.me/images/ccae/ccae3.png" alt="Joc" width="45%" />
</p>
## Altres tecles ## Altres tecles
@@ -64,6 +63,8 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
2. Descomprimix i executa l'arxiu `coffee_crisis_arcade_edition.exe`. 2. Descomprimix i executa l'arxiu `coffee_crisis_arcade_edition.exe`.
3. Gaudeix del joc! 3. Gaudeix del joc!
![Coffee Crisis Arcade Edition - Gameplay](https://php.sustancia.synology.me/images/ccae/ccae3.png)
## Agraïments ## Agraïments
Vull expressar la meua gratitud a **ChatGPT** i **GitHub Copilot**. Gràcies per ser un suport constant en el desenvolupament d'aquest joc! Vull expressar la meua gratitud a **ChatGPT** i **GitHub Copilot**. Gràcies per ser un suport constant en el desenvolupament d'aquest joc!

61
TODO.md
View File

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

View File

@@ -4,7 +4,7 @@
# Variables: ${PREFIX}, ${SYSTEM_FOLDER} # Variables: ${PREFIX}, ${SYSTEM_FOLDER}
# Archivos de configuración del sistema (absolutos y opcionales) # Archivos de configuración del sistema (absolutos y opcionales)
DATA|${SYSTEM_FOLDER}/config.txt|optional,absolute DATA|${SYSTEM_FOLDER}/config_v2.txt|optional,absolute
DATA|${SYSTEM_FOLDER}/controllers.json|optional,absolute DATA|${SYSTEM_FOLDER}/controllers.json|optional,absolute
DATA|${SYSTEM_FOLDER}/score.bin|optional,absolute DATA|${SYSTEM_FOLDER}/score.bin|optional,absolute
@@ -18,188 +18,191 @@ DATA|${PREFIX}/config/pools.txt
DATA|${PREFIX}/config/stages.txt 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|/data/demo/demo1.bin
DEMODATA|${PREFIX}/data/demo/demo2.bin DEMODATA|/data/demo/demo2.bin
DEMODATA|${PREFIX}/data/demo/demo3.bin DEMODATA|/data/demo/demo3.bin
# Música # Música
MUSIC|${PREFIX}/data/music/congratulations.ogg MUSIC|/data/music/congratulations.ogg
MUSIC|${PREFIX}/data/music/credits.ogg MUSIC|/data/music/credits.ogg
MUSIC|${PREFIX}/data/music/intro.ogg MUSIC|/data/music/intro.ogg
MUSIC|${PREFIX}/data/music/playing.ogg MUSIC|/data/music/playing.ogg
MUSIC|${PREFIX}/data/music/title.ogg MUSIC|/data/music/title.ogg
# Sonidos # Sonidos
SOUND|${PREFIX}/data/sound/balloon_bounce0.wav SOUND|/data/sound/balloon_bounce0.wav
SOUND|${PREFIX}/data/sound/balloon_bounce1.wav SOUND|/data/sound/balloon_bounce1.wav
SOUND|${PREFIX}/data/sound/balloon_bounce2.wav SOUND|/data/sound/balloon_bounce2.wav
SOUND|${PREFIX}/data/sound/balloon_bounce3.wav SOUND|/data/sound/balloon_bounce3.wav
SOUND|${PREFIX}/data/sound/balloon_pop0.wav SOUND|/data/sound/balloon_pop0.wav
SOUND|${PREFIX}/data/sound/balloon_pop1.wav SOUND|/data/sound/balloon_pop1.wav
SOUND|${PREFIX}/data/sound/balloon_pop2.wav SOUND|/data/sound/balloon_pop2.wav
SOUND|${PREFIX}/data/sound/balloon_pop3.wav SOUND|/data/sound/balloon_pop3.wav
SOUND|${PREFIX}/data/sound/bullet1p.wav SOUND|/data/sound/bullet1p.wav
SOUND|${PREFIX}/data/sound/bullet2p.wav SOUND|/data/sound/bullet2p.wav
SOUND|${PREFIX}/data/sound/clock.wav SOUND|/data/sound/clock.wav
SOUND|${PREFIX}/data/sound/coffee_out.wav SOUND|/data/sound/coffee_out.wav
SOUND|${PREFIX}/data/sound/continue_clock.wav SOUND|/data/sound/continue_clock.wav
SOUND|${PREFIX}/data/sound/credit.wav SOUND|/data/sound/credit.wav
SOUND|${PREFIX}/data/sound/debian_drop.wav SOUND|/data/sound/debian_drop.wav
SOUND|${PREFIX}/data/sound/debian_pickup.wav SOUND|/data/sound/debian_pickup.wav
SOUND|${PREFIX}/data/sound/hi_score_achieved.wav SOUND|/data/sound/hi_score_achieved.wav
SOUND|${PREFIX}/data/sound/item_drop.wav SOUND|/data/sound/item_drop.wav
SOUND|${PREFIX}/data/sound/item_pickup.wav SOUND|/data/sound/item_pickup.wav
SOUND|${PREFIX}/data/sound/jump.wav SOUND|/data/sound/jump.wav
SOUND|${PREFIX}/data/sound/logo.wav SOUND|/data/sound/logo.wav
SOUND|${PREFIX}/data/sound/name_input_accept.wav SOUND|/data/sound/name_input_accept.wav
SOUND|${PREFIX}/data/sound/notify.wav SOUND|/data/sound/notify.wav
SOUND|${PREFIX}/data/sound/player_collision.wav SOUND|/data/sound/player_collision.wav
SOUND|${PREFIX}/data/sound/power_ball_explosion.wav SOUND|/data/sound/power_ball_explosion.wav
SOUND|${PREFIX}/data/sound/service_menu_adjust.wav SOUND|/data/sound/service_menu_adjust.wav
SOUND|${PREFIX}/data/sound/service_menu_back.wav SOUND|/data/sound/service_menu_back.wav
SOUND|${PREFIX}/data/sound/service_menu_move.wav SOUND|/data/sound/service_menu_move.wav
SOUND|${PREFIX}/data/sound/service_menu_select.wav SOUND|/data/sound/service_menu_select.wav
SOUND|${PREFIX}/data/sound/stage_change.wav SOUND|/data/sound/stage_change.wav
SOUND|${PREFIX}/data/sound/tabe_hit.wav SOUND|/data/sound/tabe_hit.wav
SOUND|${PREFIX}/data/sound/tabe.wav SOUND|/data/sound/tabe.wav
SOUND|${PREFIX}/data/sound/title.wav SOUND|/data/sound/title.wav
SOUND|${PREFIX}/data/sound/voice_aw_aw_aw.wav SOUND|/data/sound/voice_aw_aw_aw.wav
SOUND|${PREFIX}/data/sound/voice_coffee.wav SOUND|/data/sound/voice_coffee.wav
SOUND|${PREFIX}/data/sound/voice_credit_thankyou.wav SOUND|/data/sound/voice_credit_thankyou.wav
SOUND|${PREFIX}/data/sound/voice_game_over.wav SOUND|/data/sound/voice_game_over.wav
SOUND|${PREFIX}/data/sound/voice_get_ready.wav SOUND|/data/sound/voice_get_ready.wav
SOUND|${PREFIX}/data/sound/voice_no.wav SOUND|/data/sound/voice_no.wav
SOUND|${PREFIX}/data/sound/voice_power_up.wav SOUND|/data/sound/voice_power_up.wav
SOUND|${PREFIX}/data/sound/voice_recover.wav SOUND|/data/sound/voice_recover.wav
SOUND|${PREFIX}/data/sound/voice_thankyou.wav SOUND|/data/sound/voice_thankyou.wav
SOUND|${PREFIX}/data/sound/walk.wav SOUND|/data/sound/walk.wav
# Shaders # Shaders OpenGL Desktop 3.3 (Windows/Linux)
DATA|${PREFIX}/data/shaders/crtpi_240.glsl DATA|/data/shaders/crtpi_vertex.glsl
DATA|${PREFIX}/data/shaders/crtpi_256.glsl DATA|/data/shaders/crtpi_fragment.glsl
# Shaders OpenGL ES 3.0 (Raspberry Pi) - opcionales
DATA|/data/shaders/crtpi_vertex_es.glsl|optional
DATA|/data/shaders/crtpi_fragment_es.glsl|optional
# Texturas - Balloons # Texturas - Balloons
ANIMATION|${PREFIX}/data/gfx/balloon/balloon0.ani ANIMATION|/data/gfx/balloon/balloon0.ani
ANIMATION|${PREFIX}/data/gfx/balloon/balloon1.ani ANIMATION|/data/gfx/balloon/balloon1.ani
ANIMATION|${PREFIX}/data/gfx/balloon/balloon2.ani ANIMATION|/data/gfx/balloon/balloon2.ani
ANIMATION|${PREFIX}/data/gfx/balloon/balloon3.ani ANIMATION|/data/gfx/balloon/balloon3.ani
BITMAP|${PREFIX}/data/gfx/balloon/balloon0.png BITMAP|/data/gfx/balloon/balloon0.png
BITMAP|${PREFIX}/data/gfx/balloon/balloon1.png BITMAP|/data/gfx/balloon/balloon1.png
BITMAP|${PREFIX}/data/gfx/balloon/balloon2.png BITMAP|/data/gfx/balloon/balloon2.png
BITMAP|${PREFIX}/data/gfx/balloon/balloon3.png BITMAP|/data/gfx/balloon/balloon3.png
# Texturas - Explosiones # Texturas - Explosiones
ANIMATION|${PREFIX}/data/gfx/balloon/explosion0.ani ANIMATION|/data/gfx/balloon/explosion0.ani
ANIMATION|${PREFIX}/data/gfx/balloon/explosion1.ani ANIMATION|/data/gfx/balloon/explosion1.ani
ANIMATION|${PREFIX}/data/gfx/balloon/explosion2.ani ANIMATION|/data/gfx/balloon/explosion2.ani
ANIMATION|${PREFIX}/data/gfx/balloon/explosion3.ani ANIMATION|/data/gfx/balloon/explosion3.ani
BITMAP|${PREFIX}/data/gfx/balloon/explosion0.png BITMAP|/data/gfx/balloon/explosion0.png
BITMAP|${PREFIX}/data/gfx/balloon/explosion1.png BITMAP|/data/gfx/balloon/explosion1.png
BITMAP|${PREFIX}/data/gfx/balloon/explosion2.png BITMAP|/data/gfx/balloon/explosion2.png
BITMAP|${PREFIX}/data/gfx/balloon/explosion3.png BITMAP|/data/gfx/balloon/explosion3.png
# Texturas - Power Ball # Texturas - Power Ball
ANIMATION|${PREFIX}/data/gfx/balloon/powerball.ani ANIMATION|/data/gfx/balloon/powerball.ani
BITMAP|${PREFIX}/data/gfx/balloon/powerball.png BITMAP|/data/gfx/balloon/powerball.png
# Texturas - Bala # Texturas - Bala
ANIMATION|${PREFIX}/data/gfx/bullet/bullet.ani ANIMATION|/data/gfx/bullet/bullet.ani
BITMAP|${PREFIX}/data/gfx/bullet/bullet.png BITMAP|/data/gfx/bullet/bullet.png
# Texturas - Tabe # Texturas - Tabe
ANIMATION|${PREFIX}/data/gfx/tabe/tabe.ani ANIMATION|/data/gfx/tabe/tabe.ani
BITMAP|${PREFIX}/data/gfx/tabe/tabe.png BITMAP|/data/gfx/tabe/tabe.png
# Texturas - Juego # Texturas - Juego
BITMAP|${PREFIX}/data/gfx/game/game_buildings.png BITMAP|/data/gfx/game/game_buildings.png
BITMAP|${PREFIX}/data/gfx/game/game_clouds1.png BITMAP|/data/gfx/game/game_clouds1.png
BITMAP|${PREFIX}/data/gfx/game/game_clouds2.png BITMAP|/data/gfx/game/game_clouds2.png
BITMAP|${PREFIX}/data/gfx/game/game_grass.png ANIMATION|/data/gfx/game/game_grass.ani
BITMAP|${PREFIX}/data/gfx/game/game_moon.png BITMAP|/data/gfx/game/game_grass.png
BITMAP|${PREFIX}/data/gfx/game/game_power_meter.png BITMAP|/data/gfx/game/game_moon.png
BITMAP|${PREFIX}/data/gfx/game/game_sky_colors.png BITMAP|/data/gfx/game/game_power_meter.png
BITMAP|${PREFIX}/data/gfx/game/game_sun.png BITMAP|/data/gfx/game/game_sky_colors.png
BITMAP|/data/gfx/game/game_sun.png
# Texturas - Intro # Texturas - Intro
BITMAP|${PREFIX}/data/gfx/intro/intro1.png BITMAP|/data/gfx/intro/intro1.png
BITMAP|${PREFIX}/data/gfx/intro/intro2.png BITMAP|/data/gfx/intro/intro2.png
BITMAP|${PREFIX}/data/gfx/intro/intro3.png BITMAP|/data/gfx/intro/intro3.png
BITMAP|${PREFIX}/data/gfx/intro/intro4.png BITMAP|/data/gfx/intro/intro4.png
BITMAP|${PREFIX}/data/gfx/intro/intro5.png BITMAP|/data/gfx/intro/intro5.png
BITMAP|${PREFIX}/data/gfx/intro/intro6.png BITMAP|/data/gfx/intro/intro6.png
# Texturas - Logo # Texturas - Logo
BITMAP|${PREFIX}/data/gfx/logo/logo_jailgames_mini.png BITMAP|/data/gfx/logo/logo_jailgames_mini.png
BITMAP|${PREFIX}/data/gfx/logo/logo_jailgames.png BITMAP|/data/gfx/logo/logo_jailgames.png
BITMAP|${PREFIX}/data/gfx/logo/logo_since_1998.png BITMAP|/data/gfx/logo/logo_since_1998.png
# Texturas - Items # Texturas - Items
ANIMATION|${PREFIX}/data/gfx/item/item_clock.ani ANIMATION|/data/gfx/item/item_clock.ani
ANIMATION|${PREFIX}/data/gfx/item/item_coffee_machine.ani ANIMATION|/data/gfx/item/item_coffee_machine.ani
ANIMATION|${PREFIX}/data/gfx/item/item_coffee.ani ANIMATION|/data/gfx/item/item_coffee.ani
ANIMATION|${PREFIX}/data/gfx/item/item_debian.ani ANIMATION|/data/gfx/item/item_debian.ani
ANIMATION|${PREFIX}/data/gfx/item/item_points1_disk.ani ANIMATION|/data/gfx/item/item_points1_disk.ani
ANIMATION|${PREFIX}/data/gfx/item/item_points2_gavina.ani ANIMATION|/data/gfx/item/item_points2_gavina.ani
ANIMATION|${PREFIX}/data/gfx/item/item_points3_pacmar.ani ANIMATION|/data/gfx/item/item_points3_pacmar.ani
BITMAP|${PREFIX}/data/gfx/item/item_clock.png BITMAP|/data/gfx/item/item_clock.png
BITMAP|${PREFIX}/data/gfx/item/item_coffee_machine.png BITMAP|/data/gfx/item/item_coffee_machine.png
BITMAP|${PREFIX}/data/gfx/item/item_coffee.png BITMAP|/data/gfx/item/item_coffee.png
BITMAP|${PREFIX}/data/gfx/item/item_debian.png BITMAP|/data/gfx/item/item_debian.png
BITMAP|${PREFIX}/data/gfx/item/item_points1_disk.png BITMAP|/data/gfx/item/item_points1_disk.png
BITMAP|${PREFIX}/data/gfx/item/item_points2_gavina.png BITMAP|/data/gfx/item/item_points2_gavina.png
BITMAP|${PREFIX}/data/gfx/item/item_points3_pacmar.png BITMAP|/data/gfx/item/item_points3_pacmar.png
# Texturas - Titulo # Texturas - Titulo
ANIMATION|${PREFIX}/data/gfx/title/title_dust.ani ANIMATION|/data/gfx/title/title_dust.ani
BITMAP|${PREFIX}/data/gfx/title/title_arcade_edition.png BITMAP|/data/gfx/title/title_arcade_edition.png
BITMAP|${PREFIX}/data/gfx/title/title_bg_tile.png BITMAP|/data/gfx/title/title_bg_tile.png
BITMAP|${PREFIX}/data/gfx/title/title_coffee.png BITMAP|/data/gfx/title/title_coffee.png
BITMAP|${PREFIX}/data/gfx/title/title_crisis.png BITMAP|/data/gfx/title/title_crisis.png
BITMAP|${PREFIX}/data/gfx/title/title_dust.png BITMAP|/data/gfx/title/title_dust.png
# Texturas - Jugador 1 # Texturas - Jugador 1
BITMAP|${PREFIX}/data/gfx/player/player1_power.png BITMAP|/data/gfx/player/player1_power.png
BITMAP|${PREFIX}/data/gfx/player/player1.gif BITMAP|/data/gfx/player/player1.gif
PALETTE|${PREFIX}/data/gfx/player/player1_coffee1.pal PALETTE|/data/gfx/player/player1_coffee1.pal
PALETTE|${PREFIX}/data/gfx/player/player1_coffee2.pal PALETTE|/data/gfx/player/player1_coffee2.pal
PALETTE|${PREFIX}/data/gfx/player/player1_invencible.pal PALETTE|/data/gfx/player/player1_invencible.pal
# Texturas - Jugador 2 # Texturas - Jugador 2
BITMAP|${PREFIX}/data/gfx/player/player2_power.png BITMAP|/data/gfx/player/player2_power.png
BITMAP|${PREFIX}/data/gfx/player/player2.gif BITMAP|/data/gfx/player/player2.gif
PALETTE|${PREFIX}/data/gfx/player/player2_coffee1.pal PALETTE|/data/gfx/player/player2_coffee1.pal
PALETTE|${PREFIX}/data/gfx/player/player2_coffee2.pal PALETTE|/data/gfx/player/player2_coffee2.pal
PALETTE|${PREFIX}/data/gfx/player/player2_invencible.pal PALETTE|/data/gfx/player/player2_invencible.pal
# Animaciones del jugador # Animaciones del jugador
ANIMATION|${PREFIX}/data/gfx/player/player_power.ani ANIMATION|/data/gfx/player/player_power.ani
ANIMATION|${PREFIX}/data/gfx/player/player.ani ANIMATION|/data/gfx/player/player1.ani
ANIMATION|/data/gfx/player/player2.ani
# Texturas - Golpe del jugador
BITMAP|${PREFIX}/data/gfx/player/hit.png
# Fuentes de texto # Fuentes de texto
BITMAP|${PREFIX}/data/font/04b_25_2x.png BITMAP|/data/font/04b_25_2x.png
BITMAP|${PREFIX}/data/font/04b_25_2x_white.png BITMAP|/data/font/04b_25_2x_white.png
BITMAP|${PREFIX}/data/font/04b_25_flat_2x.png BITMAP|/data/font/04b_25_flat_2x.png
BITMAP|${PREFIX}/data/font/04b_25_flat.png BITMAP|/data/font/04b_25_flat.png
BITMAP|${PREFIX}/data/font/04b_25_grey.png BITMAP|/data/font/04b_25_grey.png
BITMAP|${PREFIX}/data/font/04b_25_metal.png BITMAP|/data/font/04b_25_metal.png
BITMAP|${PREFIX}/data/font/04b_25_reversed_2x.png BITMAP|/data/font/04b_25_reversed_2x.png
BITMAP|${PREFIX}/data/font/04b_25_reversed.png BITMAP|/data/font/04b_25_reversed.png
BITMAP|${PREFIX}/data/font/04b_25_white.png BITMAP|/data/font/04b_25_white.png
BITMAP|${PREFIX}/data/font/04b_25.png BITMAP|/data/font/04b_25.png
BITMAP|${PREFIX}/data/font/8bithud.png BITMAP|/data/font/8bithud.png
BITMAP|${PREFIX}/data/font/aseprite.png BITMAP|/data/font/aseprite.png
BITMAP|${PREFIX}/data/font/smb2_grad.png BITMAP|/data/font/smb2_grad.png
BITMAP|${PREFIX}/data/font/smb2.png BITMAP|/data/font/smb2.png
FONT|${PREFIX}/data/font/04b_25_2x.txt FONT|/data/font/04b_25_2x.txt
FONT|${PREFIX}/data/font/04b_25.txt FONT|/data/font/04b_25.txt
FONT|${PREFIX}/data/font/8bithud.txt FONT|/data/font/8bithud.txt
FONT|${PREFIX}/data/font/aseprite.txt FONT|/data/font/aseprite.txt
FONT|${PREFIX}/data/font/smb2.txt FONT|/data/font/smb2.txt
# Idiomas # Idiomas
LANG|${PREFIX}/data/lang/ba_BA.json LANG|/data/lang/ba_BA.json
LANG|${PREFIX}/data/lang/en_UK.json LANG|/data/lang/en_UK.json
LANG|${PREFIX}/data/lang/es_ES.json LANG|/data/lang/es_ES.json

View File

@@ -11,8 +11,6 @@ game.play_area.rect.w 320 # Ancho de la zona jugable
game.play_area.rect.h 200 # Alto de la zona jugable game.play_area.rect.h 200 # Alto de la zona jugable
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
# --- FADE --- # --- FADE ---
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido fade.color 1F2B30 # Color hexadecimal para el efecto de fundido

View File

@@ -2,7 +2,6 @@
# Formato: PARAMETRO VALOR # Formato: PARAMETRO VALOR
# --- GAME --- # --- GAME ---
game.item_size 20 # Tamaño de los items del juego (en píxeles)
game.item_text_outline_color E0E0E0F0 # Color del outline del texto de los items (RGBA hex) game.item_text_outline_color E0E0E0F0 # Color del outline del texto de los items (RGBA hex)
game.width 320 # Ancho de la resolución nativa del juego (en píxeles) game.width 320 # Ancho de la resolución nativa del juego (en píxeles)
game.height 256 # Alto de la resolución nativa del juego (en píxeles) game.height 256 # Alto de la resolución nativa del juego (en píxeles)
@@ -12,8 +11,6 @@ game.play_area.rect.w 320 # Ancho de la zona jugable
game.play_area.rect.h 216 # Alto de la zona jugable game.play_area.rect.h 216 # Alto de la zona jugable
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
# --- FADE --- # --- FADE ---
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido fade.color 1F2B30 # Color hexadecimal para el efecto de fundido

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -185,7 +185,7 @@
# 122 z # 122 z
5 5
# 123 { # 123 {
3 7
# 124 | # 124 |
2 2
# 125 } # 125 }

View File

@@ -0,0 +1,9 @@
frame_width=320
frame_height=10
[animation]
name=default
speed=0.2
loop=0
frames=0,1,2,1
[/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

View File

@@ -2,8 +2,15 @@ frame_width=20
frame_height=20 frame_height=20
[animation] [animation]
name=default name=blink
speed=0.1333 speed=0.2
loop=0 loop=0
frames=0,0,1 frames=0,1
[/animation]
[animation]
name=no-blink
speed=0
loop=-1
frames=1
[/animation] [/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

After

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 B

View File

@@ -110,26 +110,26 @@ frames=38,39,40,41
name=celebration name=celebration
speed=0.167 speed=0.167
loop=0 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,43,44,45,44,43,42,43,44,45,44,43,42,43,44,45,44,43,42,46,46,46,46,46,46,47,48,49,50,50,50,50,50,50,49,49,49,50,50,50,49,49,49,48,47,46,46,46
[/animation] [/animation]
[animation] [animation]
name=dizzy name=dizzy
speed=0.0833 speed=0.0833
loop=0 loop=0
frames=47,48,49,50,51,52,53 frames=51,52,53,54,55,56,57
[/animation] [/animation]
[animation] [animation]
name=recover name=recover
speed=0.05 speed=0.05
loop=-1 loop=-1
frames=54,54,54,54,55,56,57,58,58,58,59,60,61,58,59,60,61,58,59,60,61,62,62,62,62 frames=58,58,58,58,59,60,61,62,62,62,63,64,65,62,63,64,65,62,63,64,65,66,66,66,66
[/animation] [/animation]
[animation] [animation]
name=hello name=hello
speed=0.05 speed=0.05
loop=-1 loop=-1
frames=63,64,65,66,67,68,69,70,71,72,73,73,73,73,73,73,73,73,73,73,73,73,73,74,75,76,77,78,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63 frames=67,68,69,70,71,72,73,74,75,76,77,77,77,77,77,77,77,77,77,77,77,77,77,78,79,80,81,82,83,84,85,86,86,85,84,83,83,84,85,86,86,85,84,83,83,84,85,86,86,85,84,83,83,84,85,86,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67
[/animation] [/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

135
data/gfx/player/player2.ani Normal file
View File

@@ -0,0 +1,135 @@
frame_width=32
frame_height=32
[animation]
name=walk
speed=0.0833
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand
speed=0.167
loop=0
frames=4,5,6,7
[/animation]
[animation]
name=walk-fire-side
speed=0.0833
loop=0
frames=8,9,10,11
[/animation]
[animation]
name=walk-recoil-side
speed=0.0833
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk-cool-side
speed=0.0833
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand-fire-side
speed=0.0833
loop=0
frames=20
[/animation]
[animation]
name=stand-recoil-side
speed=0.0833
loop=0
frames=21
[/animation]
[animation]
name=stand-cool-side
speed=0.0833
loop=0
frames=22
[/animation]
[animation]
name=walk-fire-center
speed=0.0833
loop=0
frames=23,24,25,26
[/animation]
[animation]
name=walk-recoil-center
speed=0.0833
loop=0
frames=27,28,29,30
[/animation]
[animation]
name=walk-cool-center
speed=0.0833
loop=0
frames=31,32,33,34
[/animation]
[animation]
name=stand-fire-center
speed=0.0833
loop=0
frames=35
[/animation]
[animation]
name=stand-recoil-center
speed=0.0833
loop=0
frames=36
[/animation]
[animation]
name=stand-cool-center
speed=0.0833
loop=0
frames=37
[/animation]
[animation]
name=rolling
speed=0.167
loop=0
frames=38,39,40,41
[/animation]
[animation]
name=celebration
speed=0.167
loop=0
frames=47,47,47,47,47,47,48,49,50,51,51,51,51,51,51,50,50,50,51,51,51,50,50,50,49,48,47,47,47,42,42,42,43,44,45,46,45,46,45,46,45,46,45,46,45,46,45,44,43,42
[/animation]
[animation]
name=dizzy
speed=0.0833
loop=0
frames=52,53,54,55,56,57,58
[/animation]
[animation]
name=recover
speed=0.05
loop=-1
frames=59,59,59,59,60,61,62,63,63,63,64,65,66,63,64,65,66,63,64,65,66,67,67,67,67
[/animation]
[animation]
name=hello
speed=0.05
loop=-1
frames=68,69,70,71,72,73,74,75,76,77,78,78,78,78,78,78,78,78,78,78,78,78,78,79,80,81,82,83,84,85,86,87,87,86,85,84,84,85,86,87,87,86,85,84,84,85,86,87,87,86,85,84,84,85,86,87,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68
[/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -21,7 +21,7 @@
"[GAME_TEXT] 2": "Queden ", "[GAME_TEXT] 2": "Queden ",
"[GAME_TEXT] 2A": " fases mes!", "[GAME_TEXT] 2A": " fases mes!",
"[GAME_TEXT] 3": "Ultima fase!", "[GAME_TEXT] 3": "Ultima fase!",
"[GAME_TEXT] 4": "SuperPoder!", "[GAME_TEXT] 4": "Automatic!",
"[GAME_TEXT] 5": "+1 Colp", "[GAME_TEXT] 5": "+1 Colp",
"[GAME_TEXT] 6": "Temps!", "[GAME_TEXT] 6": "Temps!",
"[GAME_TEXT] 7": "Endavant!", "[GAME_TEXT] 7": "Endavant!",

View File

@@ -20,7 +20,7 @@
"[GAME_TEXT] 2": "", "[GAME_TEXT] 2": "",
"[GAME_TEXT] 2A": " stages left!", "[GAME_TEXT] 2A": " stages left!",
"[GAME_TEXT] 3": "Last stage!", "[GAME_TEXT] 3": "Last stage!",
"[GAME_TEXT] 4": "PowerUp", "[GAME_TEXT] 4": "AutoFire!",
"[GAME_TEXT] 5": "+1 Hit", "[GAME_TEXT] 5": "+1 Hit",
"[GAME_TEXT] 6": "Stop!", "[GAME_TEXT] 6": "Stop!",
"[GAME_TEXT] 7": "Get Ready!", "[GAME_TEXT] 7": "Get Ready!",

View File

@@ -20,7 +20,7 @@
"[GAME_TEXT] 2": "!Quedan ", "[GAME_TEXT] 2": "!Quedan ",
"[GAME_TEXT] 2A": " fases!", "[GAME_TEXT] 2A": " fases!",
"[GAME_TEXT] 3": "Ultima fase!", "[GAME_TEXT] 3": "Ultima fase!",
"[GAME_TEXT] 4": "Potenciador", "[GAME_TEXT] 4": "Automatico!",
"[GAME_TEXT] 5": "+1 Golpe", "[GAME_TEXT] 5": "+1 Golpe",
"[GAME_TEXT] 6": "Tiempo!", "[GAME_TEXT] 6": "Tiempo!",
"[GAME_TEXT] 7": "Adelante!", "[GAME_TEXT] 7": "Adelante!",

View File

@@ -1,234 +0,0 @@
/*
crt-pi - A Raspberry Pi friendly CRT shader.
Copyright (C) 2015-2016 davej
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
Notes:
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
BLOOM_FACTOR controls the increase in width for bright scanlines.
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
*/
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
// Haven't put these as parameters as it would slow the code down.
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
#define MASK_TYPE 2
#ifdef GL_ES
#define COMPAT_PRECISION mediump
precision mediump float;
#else
#define COMPAT_PRECISION
#endif
#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float CURVATURE_X;
uniform COMPAT_PRECISION float CURVATURE_Y;
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
uniform COMPAT_PRECISION float BLOOM_FACTOR;
uniform COMPAT_PRECISION float INPUT_GAMMA;
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
#else
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
#endif
/* COMPATIBILITY
- GLSL compilers
*/
//uniform vec2 TextureSize;
#if defined(CURVATURE)
varying vec2 screenScale;
#endif
varying vec2 TEX0;
varying float filterWidth;
#if defined(VERTEX)
//uniform mat4 MVPMatrix;
//attribute vec4 VertexCoord;
//attribute vec2 TexCoord;
//uniform vec2 InputSize;
//uniform vec2 OutputSize;
void main()
{
#if defined(CURVATURE)
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
#endif
filterWidth = (768.0 / 240.0) / 3.0;
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#elif defined(FRAGMENT)
uniform sampler2D Texture;
#if defined(CURVATURE)
vec2 Distort(vec2 coord)
{
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
coord *= screenScale;
coord -= vec2(0.5);
float rsq = coord.x * coord.x + coord.y * coord.y;
coord += coord * (CURVATURE_DISTORTION * rsq);
coord *= barrelScale;
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
coord = vec2(-1.0); // If out of bounds, return an invalid value.
else
{
coord += vec2(0.5);
coord /= screenScale;
}
return coord;
}
#endif
float CalcScanLineWeight(float dist)
{
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
}
float CalcScanLine(float dy)
{
float scanLineWeight = CalcScanLineWeight(dy);
#if defined(MULTISAMPLE)
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
scanLineWeight *= 0.3333333;
#endif
return scanLineWeight;
}
void main()
{
vec2 TextureSize = vec2(320.0, 240.0);
#if defined(CURVATURE)
vec2 texcoord = Distort(TEX0);
if (texcoord.x < 0.0)
gl_FragColor = vec4(0.0);
else
#else
vec2 texcoord = TEX0;
#endif
{
vec2 texcoordInPixels = texcoord * TextureSize;
#if defined(SHARPER)
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
vec2 coord = tempCoord / TextureSize;
vec2 deltas = texcoordInPixels - tempCoord;
float scanLineWeight = CalcScanLine(deltas.y);
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= TextureSize;
deltas *= signs;
vec2 tc = coord + deltas;
#else
float tempY = floor(texcoordInPixels.y) + 0.5;
float yCoord = tempY / TextureSize.y;
float dy = texcoordInPixels.y - tempY;
float scanLineWeight = CalcScanLine(dy);
float signY = sign(dy);
dy = dy * dy;
dy = dy * dy;
dy *= 8.0;
dy /= TextureSize.y;
dy *= signY;
vec2 tc = vec2(texcoord.x, yCoord + dy);
#endif
vec3 colour = texture2D(Texture, tc).rgb;
#if defined(SCANLINES)
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = colour * colour;
#else
colour = pow(colour, vec3(INPUT_GAMMA));
#endif
#endif
scanLineWeight *= BLOOM_FACTOR;
colour *= scanLineWeight;
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = sqrt(colour);
#else
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
#endif
#endif
#endif
#if MASK_TYPE == 0
gl_FragColor = vec4(colour, 1.0);
#else
#if MASK_TYPE == 1
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
vec3 mask;
if (whichMask < 0.5)
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
else
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
#elif MASK_TYPE == 2
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
if (whichMask < 0.3333333)
mask.x = 1.0;
else if (whichMask < 0.6666666)
mask.y = 1.0;
else
mask.z = 1.0;
#endif
gl_FragColor = vec4(colour * mask, 1.0);
#endif
}
}
#endif

View File

@@ -1,234 +0,0 @@
/*
crt-pi - A Raspberry Pi friendly CRT shader.
Copyright (C) 2015-2016 davej
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
Notes:
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
BLOOM_FACTOR controls the increase in width for bright scanlines.
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
*/
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
// Haven't put these as parameters as it would slow the code down.
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
#define MASK_TYPE 2
#ifdef GL_ES
#define COMPAT_PRECISION mediump
precision mediump float;
#else
#define COMPAT_PRECISION
#endif
#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float CURVATURE_X;
uniform COMPAT_PRECISION float CURVATURE_Y;
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
uniform COMPAT_PRECISION float BLOOM_FACTOR;
uniform COMPAT_PRECISION float INPUT_GAMMA;
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
#else
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
#endif
/* COMPATIBILITY
- GLSL compilers
*/
//uniform vec2 TextureSize;
#if defined(CURVATURE)
varying vec2 screenScale;
#endif
varying vec2 TEX0;
varying float filterWidth;
#if defined(VERTEX)
//uniform mat4 MVPMatrix;
//attribute vec4 VertexCoord;
//attribute vec2 TexCoord;
//uniform vec2 InputSize;
//uniform vec2 OutputSize;
void main()
{
#if defined(CURVATURE)
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
#endif
filterWidth = (768.0 / 256.0) / 3.0;
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#elif defined(FRAGMENT)
uniform sampler2D Texture;
#if defined(CURVATURE)
vec2 Distort(vec2 coord)
{
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
coord *= screenScale;
coord -= vec2(0.5);
float rsq = coord.x * coord.x + coord.y * coord.y;
coord += coord * (CURVATURE_DISTORTION * rsq);
coord *= barrelScale;
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
coord = vec2(-1.0); // If out of bounds, return an invalid value.
else
{
coord += vec2(0.5);
coord /= screenScale;
}
return coord;
}
#endif
float CalcScanLineWeight(float dist)
{
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
}
float CalcScanLine(float dy)
{
float scanLineWeight = CalcScanLineWeight(dy);
#if defined(MULTISAMPLE)
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
scanLineWeight *= 0.3333333;
#endif
return scanLineWeight;
}
void main()
{
vec2 TextureSize = vec2(320.0, 256.0);
#if defined(CURVATURE)
vec2 texcoord = Distort(TEX0);
if (texcoord.x < 0.0)
gl_FragColor = vec4(0.0);
else
#else
vec2 texcoord = TEX0;
#endif
{
vec2 texcoordInPixels = texcoord * TextureSize;
#if defined(SHARPER)
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
vec2 coord = tempCoord / TextureSize;
vec2 deltas = texcoordInPixels - tempCoord;
float scanLineWeight = CalcScanLine(deltas.y);
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= TextureSize;
deltas *= signs;
vec2 tc = coord + deltas;
#else
float tempY = floor(texcoordInPixels.y) + 0.5;
float yCoord = tempY / TextureSize.y;
float dy = texcoordInPixels.y - tempY;
float scanLineWeight = CalcScanLine(dy);
float signY = sign(dy);
dy = dy * dy;
dy = dy * dy;
dy *= 8.0;
dy /= TextureSize.y;
dy *= signY;
vec2 tc = vec2(texcoord.x, yCoord + dy);
#endif
vec3 colour = texture2D(Texture, tc).rgb;
#if defined(SCANLINES)
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = colour * colour;
#else
colour = pow(colour, vec3(INPUT_GAMMA));
#endif
#endif
scanLineWeight *= BLOOM_FACTOR;
colour *= scanLineWeight;
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = sqrt(colour);
#else
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
#endif
#endif
#endif
#if MASK_TYPE == 0
gl_FragColor = vec4(colour, 1.0);
#else
#if MASK_TYPE == 1
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
vec3 mask;
if (whichMask < 0.5)
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
else
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
#elif MASK_TYPE == 2
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
if (whichMask < 0.3333333)
mask.x = 1.0;
else if (whichMask < 0.6666666)
mask.y = 1.0;
else
mask.z = 1.0;
#endif
gl_FragColor = vec4(colour * mask, 1.0);
#endif
}
}
#endif

View File

@@ -0,0 +1,157 @@
#version 330 core
// Configuración
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
#define MASK_TYPE 2
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
// Inputs desde vertex shader
in vec2 vTexCoord;
in float vFilterWidth;
#if defined(CURVATURE)
in vec2 vScreenScale;
#endif
// Output
out vec4 FragColor;
// Uniforms
uniform sampler2D Texture;
uniform vec2 TextureSize;
#if defined(CURVATURE)
vec2 Distort(vec2 coord)
{
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
coord *= vScreenScale;
coord -= vec2(0.5);
float rsq = coord.x * coord.x + coord.y * coord.y;
coord += coord * (CURVATURE_DISTORTION * rsq);
coord *= barrelScale;
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
coord = vec2(-1.0);
else
{
coord += vec2(0.5);
coord /= vScreenScale;
}
return coord;
}
#endif
float CalcScanLineWeight(float dist)
{
return max(1.0 - dist * dist * SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
}
float CalcScanLine(float dy)
{
float scanLineWeight = CalcScanLineWeight(dy);
#if defined(MULTISAMPLE)
scanLineWeight += CalcScanLineWeight(dy - vFilterWidth);
scanLineWeight += CalcScanLineWeight(dy + vFilterWidth);
scanLineWeight *= 0.3333333;
#endif
return scanLineWeight;
}
void main()
{
#if defined(CURVATURE)
vec2 texcoord = Distort(vTexCoord);
if (texcoord.x < 0.0) {
FragColor = vec4(0.0);
return;
}
#else
vec2 texcoord = vTexCoord;
#endif
vec2 texcoordInPixels = texcoord * TextureSize;
#if defined(SHARPER)
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
vec2 coord = tempCoord / TextureSize;
vec2 deltas = texcoordInPixels - tempCoord;
float scanLineWeight = CalcScanLine(deltas.y);
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= TextureSize;
deltas *= signs;
vec2 tc = coord + deltas;
#else
float tempY = floor(texcoordInPixels.y) + 0.5;
float yCoord = tempY / TextureSize.y;
float dy = texcoordInPixels.y - tempY;
float scanLineWeight = CalcScanLine(dy);
float signY = sign(dy);
dy = dy * dy;
dy = dy * dy;
dy *= 8.0;
dy /= TextureSize.y;
dy *= signY;
vec2 tc = vec2(texcoord.x, yCoord + dy);
#endif
vec3 colour = texture(Texture, tc).rgb;
#if defined(SCANLINES)
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = colour * colour;
#else
colour = pow(colour, vec3(INPUT_GAMMA));
#endif
#endif
scanLineWeight *= BLOOM_FACTOR;
colour *= scanLineWeight;
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = sqrt(colour);
#else
colour = pow(colour, vec3(1.0 / OUTPUT_GAMMA));
#endif
#endif
#endif
#if MASK_TYPE == 0
FragColor = vec4(colour, 1.0);
#elif MASK_TYPE == 1
float whichMask = fract(gl_FragCoord.x * 0.5);
vec3 mask;
if (whichMask < 0.5)
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
else
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
FragColor = vec4(colour * mask, 1.0);
#elif MASK_TYPE == 2
float whichMask = fract(gl_FragCoord.x * 0.3333333);
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
if (whichMask < 0.3333333)
mask.x = 1.0;
else if (whichMask < 0.6666666)
mask.y = 1.0;
else
mask.z = 1.0;
FragColor = vec4(colour * mask, 1.0);
#endif
}

View File

@@ -0,0 +1,160 @@
#version 300 es
// OpenGL ES 3.0 - Compatible con Raspberry Pi 5
precision highp float;
// Configuración
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
#define MASK_TYPE 2
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
// Inputs desde vertex shader
in vec2 vTexCoord;
in float vFilterWidth;
#if defined(CURVATURE)
in vec2 vScreenScale;
#endif
// Output
out vec4 FragColor;
// Uniforms
uniform sampler2D Texture;
uniform vec2 TextureSize;
#if defined(CURVATURE)
vec2 Distort(vec2 coord)
{
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
vec2 barrelScale = vec2(1.0) - (0.23 * CURVATURE_DISTORTION);
coord *= vScreenScale;
coord -= vec2(0.5);
float rsq = coord.x * coord.x + coord.y * coord.y;
coord += coord * (CURVATURE_DISTORTION * rsq);
coord *= barrelScale;
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
coord = vec2(-1.0);
else
{
coord += vec2(0.5);
coord /= vScreenScale;
}
return coord;
}
#endif
float CalcScanLineWeight(float dist)
{
return max(1.0 - dist * dist * SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
}
float CalcScanLine(float dy)
{
float scanLineWeight = CalcScanLineWeight(dy);
#if defined(MULTISAMPLE)
scanLineWeight += CalcScanLineWeight(dy - vFilterWidth);
scanLineWeight += CalcScanLineWeight(dy + vFilterWidth);
scanLineWeight *= 0.3333333;
#endif
return scanLineWeight;
}
void main()
{
#if defined(CURVATURE)
vec2 texcoord = Distort(vTexCoord);
if (texcoord.x < 0.0) {
FragColor = vec4(0.0);
return;
}
#else
vec2 texcoord = vTexCoord;
#endif
vec2 texcoordInPixels = texcoord * TextureSize;
#if defined(SHARPER)
vec2 tempCoord = floor(texcoordInPixels) + vec2(0.5);
vec2 coord = tempCoord / TextureSize;
vec2 deltas = texcoordInPixels - tempCoord;
float scanLineWeight = CalcScanLine(deltas.y);
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= TextureSize;
deltas *= signs;
vec2 tc = coord + deltas;
#else
float tempY = floor(texcoordInPixels.y) + 0.5;
float yCoord = tempY / TextureSize.y;
float dy = texcoordInPixels.y - tempY;
float scanLineWeight = CalcScanLine(dy);
float signY = sign(dy);
dy = dy * dy;
dy = dy * dy;
dy *= 8.0;
dy /= TextureSize.y;
dy *= signY;
vec2 tc = vec2(texcoord.x, yCoord + dy);
#endif
vec3 colour = texture(Texture, tc).rgb;
#if defined(SCANLINES)
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = colour * colour;
#else
colour = pow(colour, vec3(INPUT_GAMMA));
#endif
#endif
scanLineWeight *= BLOOM_FACTOR;
colour *= scanLineWeight;
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = sqrt(colour);
#else
colour = pow(colour, vec3(1.0 / OUTPUT_GAMMA));
#endif
#endif
#endif
#if MASK_TYPE == 0
FragColor = vec4(colour, 1.0);
#elif MASK_TYPE == 1
float whichMask = fract(gl_FragCoord.x * 0.5);
vec3 mask;
if (whichMask < 0.5)
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
else
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
FragColor = vec4(colour * mask, 1.0);
#elif MASK_TYPE == 2
float whichMask = fract(gl_FragCoord.x * 0.3333333);
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
if (whichMask < 0.3333333)
mask.x = 1.0;
else if (whichMask < 0.6666666)
mask.y = 1.0;
else
mask.z = 1.0;
FragColor = vec4(colour * mask, 1.0);
#endif
}

View File

@@ -0,0 +1,48 @@
#version 330 core
// Configuración
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
#define MASK_TYPE 2
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
// Inputs (desde VAO)
layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord;
// Outputs al fragment shader
out vec2 vTexCoord;
out float vFilterWidth;
#if defined(CURVATURE)
out vec2 vScreenScale;
#endif
// Uniforms
uniform vec2 TextureSize;
void main()
{
#if defined(CURVATURE)
vScreenScale = vec2(1.0, 1.0);
#endif
// Calcula filterWidth dinámicamente basándose en la altura de la textura
vFilterWidth = (768.0 / TextureSize.y) / 3.0;
// Pasar coordenadas de textura (invertir Y para SDL)
vTexCoord = vec2(aTexCoord.x, 1.0 - aTexCoord.y) * 1.0001;
// Posición del vértice (ya en espacio de clip [-1, 1])
gl_Position = vec4(aPosition, 0.0, 1.0);
}

View File

@@ -0,0 +1,51 @@
#version 300 es
// OpenGL ES 3.0 - Compatible con Raspberry Pi 5
precision highp float;
// Configuración
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
//#define CURVATURE
//#define SHARPER
#define MASK_TYPE 2
#define CURVATURE_X 0.05
#define CURVATURE_Y 0.1
#define MASK_BRIGHTNESS 0.80
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 3.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
// Inputs (desde VAO)
layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord;
// Outputs al fragment shader
out vec2 vTexCoord;
out float vFilterWidth;
#if defined(CURVATURE)
out vec2 vScreenScale;
#endif
// Uniforms
uniform vec2 TextureSize;
void main()
{
#if defined(CURVATURE)
vScreenScale = vec2(1.0, 1.0);
#endif
// Calcula filterWidth dinámicamente basándose en la altura de la textura
vFilterWidth = (768.0 / TextureSize.y) / 3.0;
// Pasar coordenadas de textura (invertir Y para SDL)
vTexCoord = vec2(aTexCoord.x, 1.0 - aTexCoord.y) * 1.0001;
// Posición del vértice (ya en espacio de clip [-1, 1])
gl_Position = vec4(aPosition, 0.0, 1.0);
}

View File

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

553
linux_utils/iwyu_tool.py Executable file
View File

@@ -0,0 +1,553 @@
#!/usr/bin/env python3
##===--- iwyu_tool.py -----------------------------------------------------===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
""" Driver to consume a Clang compilation database and invoke IWYU.
Example usage with CMake:
# Unix systems
$ mkdir build && cd build
$ CC="clang" CXX="clang++" cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ...
$ iwyu_tool.py -p .
# Windows systems
$ mkdir build && cd build
$ cmake -DCMAKE_CXX_COMPILER="%VCINSTALLDIR%/bin/cl.exe" \
-DCMAKE_C_COMPILER="%VCINSTALLDIR%/VC/bin/cl.exe" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-G Ninja ...
$ python3 iwyu_tool.py -p .
See iwyu_tool.py -h for more details on command-line arguments.
"""
from __future__ import print_function
import os
import re
import sys
import json
import time
import shlex
import shutil
import argparse
import tempfile
import subprocess
CORRECT_RE = re.compile(r'^\((.*?) has correct #includes/fwd-decls\)$')
SHOULD_ADD_RE = re.compile(r'^(.*?) should add these lines:$')
ADD_RE = re.compile('^(.*?) +// (.*)$')
SHOULD_REMOVE_RE = re.compile(r'^(.*?) should remove these lines:$')
FULL_LIST_RE = re.compile(r'The full include-list for (.*?):$')
END_RE = re.compile(r'^---$')
LINES_RE = re.compile(r'^- (.*?) // lines ([0-9]+)-[0-9]+$')
GENERAL, ADD, REMOVE, LIST = range(4)
def clang_formatter(output, style):
""" Process iwyu's output into something clang-like. """
formatted = []
state = (GENERAL, None)
for line in output.splitlines():
match = CORRECT_RE.match(line)
if match:
# See PR#1806 for more info
continue
match = SHOULD_ADD_RE.match(line)
if match:
state = (ADD, match.group(1))
continue
match = SHOULD_REMOVE_RE.match(line)
if match:
state = (REMOVE, match.group(1))
continue
match = FULL_LIST_RE.match(line)
if match:
state = (LIST, match.group(1))
elif END_RE.match(line):
state = (GENERAL, None)
elif not line.strip():
continue
elif state[0] == GENERAL:
formatted.append(line)
elif state[0] == ADD:
match = ADD_RE.match(line)
if match:
formatted.append("%s:1:1: %s: add '%s' (%s)" %
(state[1],
style,
match.group(1),
match.group(2)))
else:
formatted.append("%s:1:1: %s: add '%s'" %
(state[1], style, line))
elif state[0] == REMOVE:
match = LINES_RE.match(line)
line_no = match.group(2) if match else '1'
formatted.append("%s:%s:1: %s: superfluous '%s'" %
(state[1], line_no, style, match.group(1)))
return os.linesep.join(formatted)
DEFAULT_FORMAT = 'iwyu'
FORMATTERS = {
'iwyu': lambda output: output,
'clang': lambda output: clang_formatter(output, style="error"),
'clang-warning': lambda output: clang_formatter(output, style="warning"),
}
if sys.platform.startswith('win'):
# Case-insensitive match on Windows
def normcase(s):
return s.lower()
else:
def normcase(s):
return s
def is_subpath_of(path, parent):
""" Return True if path is equal to or fully contained within parent.
Assumes both paths are canonicalized with os.path.realpath.
"""
parent = normcase(parent)
path = normcase(path)
if path == parent:
return True
if not path.startswith(parent):
return False
# Now we know parent is a prefix of path, but they only share lineage if the
# difference between them starts with a path separator, e.g. /a/b/c/file
# is not a parent of /a/b/c/file.cpp, but /a/b/c and /a/b/c/ are.
parent = parent.rstrip(os.path.sep)
suffix = path[len(parent):]
return suffix.startswith(os.path.sep)
def is_msvc_driver(compile_command):
""" Return True if compile_command matches an MSVC CL-style driver. """
compile_command = normcase(compile_command)
if compile_command.endswith('cl.exe'):
# Native MSVC compiler or clang-cl.exe
return True
if compile_command.endswith('clang-cl'):
# Cross clang-cl on non-Windows
return True
return False
def win_split(cmdline):
""" Minimal implementation of shlex.split for Windows following
https://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft.aspx.
"""
def split_iter(cmdline):
in_quotes = False
backslashes = 0
arg = ''
for c in cmdline:
if c == '\\':
# MSDN: Backslashes are interpreted literally, unless they
# immediately precede a double quotation mark.
# Buffer them until we know what comes next.
backslashes += 1
elif c == '"':
# Quotes can either be an escaped quote or the start of a quoted
# string. Paraphrasing MSDN:
# Before quotes, place one backslash in the arg for every pair
# of leading backslashes. If the number of backslashes is odd,
# retain the double quotation mark, otherwise interpret it as a
# string delimiter and switch state.
arg += '\\' * (backslashes // 2)
if backslashes % 2 == 1:
arg += c
else:
in_quotes = not in_quotes
backslashes = 0
elif c in (' ', '\t') and not in_quotes:
# MSDN: Arguments are delimited by white space, which is either
# a space or a tab [but only outside of a string].
# Flush any buffered backslashes and yield arg, unless empty.
arg += '\\' * backslashes
if arg:
yield arg
arg = ''
backslashes = 0
else:
# Flush buffered backslashes and append.
arg += '\\' * backslashes
arg += c
backslashes = 0
if arg:
arg += '\\' * backslashes
yield arg
return list(split_iter(cmdline))
def split_command(cmdstr):
""" Split a command string into a list, respecting shell quoting. """
if sys.platform.startswith('win'):
# shlex.split does not work for Windows command-lines, so special-case
# to our own implementation.
cmd = win_split(cmdstr)
else:
cmd = shlex.split(cmdstr)
return cmd
def find_include_what_you_use():
""" Find IWYU executable and return its full pathname. """
env_iwyu_path = os.environ.get('IWYU_BINARY')
if env_iwyu_path:
return os.path.realpath(env_iwyu_path)
# Search in same dir as this script.
iwyu_path = shutil.which('include-what-you-use',
path=os.path.dirname(__file__))
if iwyu_path:
return os.path.realpath(iwyu_path)
# Search the system PATH.
iwyu_path = shutil.which('include-what-you-use')
if iwyu_path:
return os.path.realpath(iwyu_path)
return None
IWYU_EXECUTABLE = find_include_what_you_use()
class Process(object):
""" Manages an IWYU process in flight """
def __init__(self, proc, outfile):
self.proc = proc
self.outfile = outfile
self.output = None
def poll(self):
""" Return the exit code if the process has completed, None otherwise.
"""
return self.proc.poll()
@property
def returncode(self):
return self.proc.returncode
def get_output(self):
""" Return stdout+stderr output of the process.
This call blocks until the process is complete, then returns the output.
"""
if not self.output:
self.proc.wait()
self.outfile.seek(0)
self.output = self.outfile.read().decode("utf-8")
self.outfile.close()
return self.output
@classmethod
def start(cls, invocation):
""" Start a Process for the invocation and capture stdout+stderr. """
outfile = tempfile.TemporaryFile(prefix='iwyu')
process = subprocess.Popen(
invocation.command,
cwd=invocation.cwd,
stdout=outfile,
stderr=subprocess.STDOUT)
return cls(process, outfile)
KNOWN_COMPILER_WRAPPERS=frozenset([
"ccache"
])
class Invocation(object):
""" Holds arguments of an IWYU invocation. """
def __init__(self, command, cwd):
self.command = command
self.cwd = cwd
def __str__(self):
return ' '.join(self.command)
@classmethod
def from_compile_command(cls, entry, extra_args):
""" Parse a JSON compilation database entry into new Invocation. """
if 'arguments' in entry:
# arguments is a command-line in list form.
command = entry['arguments']
elif 'command' in entry:
# command is a command-line in string form, split to list.
command = split_command(entry['command'])
else:
raise ValueError('Invalid compilation database entry: %s' % entry)
if command[0] in KNOWN_COMPILER_WRAPPERS:
# Remove the compiler wrapper from the command.
command = command[1:]
# Rewrite the compile command for IWYU
compile_command, compile_args = command[0], command[1:]
if is_msvc_driver(compile_command):
# If the compiler is cl-compatible, let IWYU be cl-compatible.
extra_args = ['--driver-mode=cl'] + extra_args
command = [IWYU_EXECUTABLE] + extra_args + compile_args
return cls(command, entry['directory'])
def start(self, verbose):
""" Run invocation and collect output. """
if verbose:
print('# %s' % self, file=sys.stderr)
return Process.start(self)
def fixup_compilation_db(compilation_db):
""" Canonicalize paths in JSON compilation database. """
for entry in compilation_db:
# Convert relative paths to absolute ones if possible, based on the entry's directory.
if 'directory' in entry and not os.path.isabs(entry['file']):
entry['file'] = os.path.join(entry['directory'], entry['file'])
# Expand relative paths and symlinks
entry['file'] = os.path.realpath(entry['file'])
return compilation_db
def select_compilation_db(compilation_db, selection):
""" Return a new compilation database reduced to the paths in selection. """
if not selection:
return compilation_db
# Canonicalize selection paths to match compilation database.
selection = [os.path.realpath(p) for p in selection]
new_db = []
for path in selection:
if not os.path.exists(path):
print('warning: \'%s\' not found on disk.' % path, file=sys.stderr)
continue
found = [e for e in compilation_db if is_subpath_of(e['file'], path)]
if not found:
print('warning: \'%s\' not found in compilation database.' % path,
file=sys.stderr)
continue
new_db.extend(found)
return new_db
def slice_compilation_db(compilation_db, selection, exclude):
""" Return a new compilation database with filtered entries. """
new_db = select_compilation_db(compilation_db, selection)
# Canonicalize selection paths to match compilation database.
exclude = [os.path.realpath(p) for p in exclude]
for path in exclude:
if not os.path.exists(path):
print('warning: excluded path \'%s\' not found on disk.' % path,
file=sys.stderr)
continue
new_db = [e for e in new_db if not is_subpath_of(e['file'], path)]
return new_db
def worst_exit_code(worst, cur):
"""Return the most extreme exit code of two.
Negative exit codes occur if the program exits due to a signal (Unix) or
structured exception (Windows). If we've seen a negative one before, keep
it, as it usually indicates a critical error.
Otherwise return the biggest positive exit code.
"""
if cur < 0:
# Negative results take precedence, return the minimum
return min(worst, cur)
elif worst < 0:
# We know cur is non-negative, negative worst must be minimum
return worst
else:
# We know neither are negative, return the maximum
return max(worst, cur)
def execute(invocations, verbose, formatter, jobs, max_load_average=0):
""" Launch processes described by invocations. """
exit_code = 0
if jobs == 1:
for invocation in invocations:
proc = invocation.start(verbose)
print(formatter(proc.get_output()))
exit_code = worst_exit_code(exit_code, proc.returncode)
return exit_code
pending = []
while invocations or pending:
# Collect completed IWYU processes and print results.
complete = [proc for proc in pending if proc.poll() is not None]
for proc in complete:
pending.remove(proc)
print(formatter(proc.get_output()))
exit_code = worst_exit_code(exit_code, proc.returncode)
# Schedule new processes if there's room.
capacity = jobs - len(pending)
if max_load_average > 0:
one_min_load_average, _, _ = os.getloadavg()
load_capacity = max_load_average - one_min_load_average
if load_capacity < 0:
load_capacity = 0
if load_capacity < capacity:
capacity = int(load_capacity)
if not capacity and not pending:
# Ensure there is at least one job running.
capacity = 1
pending.extend(i.start(verbose) for i in invocations[:capacity])
invocations = invocations[capacity:]
# Yield CPU.
time.sleep(0.0001)
return exit_code
def main(compilation_db_path, source_files, exclude, verbose, formatter, jobs,
max_load_average, extra_args):
""" Entry point. """
if not IWYU_EXECUTABLE:
print('error: include-what-you-use executable not found',
file=sys.stderr)
return 1
try:
if os.path.isdir(compilation_db_path):
compilation_db_path = os.path.join(compilation_db_path,
'compile_commands.json')
# Read compilation db from disk.
compilation_db_path = os.path.realpath(compilation_db_path)
with open(compilation_db_path, 'r') as fileobj:
compilation_db = json.load(fileobj)
except IOError as why:
print('error: failed to parse compilation database: %s' % why,
file=sys.stderr)
return 1
compilation_db = fixup_compilation_db(compilation_db)
compilation_db = slice_compilation_db(compilation_db, source_files, exclude)
# Transform compilation db entries into a list of IWYU invocations.
invocations = [
Invocation.from_compile_command(e, extra_args) for e in compilation_db
]
return execute(invocations, verbose, formatter, jobs, max_load_average)
def _bootstrap(sys_argv):
""" Parse arguments and dispatch to main(). """
# This hackery is necessary to add the forwarded IWYU args to the
# usage and help strings.
def customize_usage(parser):
""" Rewrite the parser's format_usage. """
original_format_usage = parser.format_usage
parser.format_usage = lambda: original_format_usage().rstrip() + \
' -- [<IWYU args>]' + os.linesep
def customize_help(parser):
""" Rewrite the parser's format_help. """
original_format_help = parser.format_help
def custom_help():
""" Customized help string, calls the adjusted format_usage. """
helpmsg = original_format_help()
helplines = helpmsg.splitlines()
helplines[0] = parser.format_usage().rstrip()
return os.linesep.join(helplines) + os.linesep
parser.format_help = custom_help
# Parse arguments.
parser = argparse.ArgumentParser(
description='Include-what-you-use compilation database driver.',
epilog='Assumes include-what-you-use is available on the PATH.')
customize_usage(parser)
customize_help(parser)
parser.add_argument('-v', '--verbose', action='store_true',
help='Print IWYU commands')
parser.add_argument('-o', '--output-format', type=str,
choices=FORMATTERS.keys(), default=DEFAULT_FORMAT,
help='Output format (default: %s)' % DEFAULT_FORMAT)
parser.add_argument('-j', '--jobs', type=int, default=1,
nargs='?', const=0,
help=('Number of concurrent subprocesses. If zero, '
'will try to match the logical cores of the '
'system.'))
parser.add_argument('-l', '--load', type=float, default=0,
help=('Do not start new jobs if the 1min load average '
'is greater than the provided value'))
parser.add_argument('-p', metavar='<build-path>', required=True,
help='Compilation database path', dest='dbpath')
parser.add_argument('-e', '--exclude', action='append', default=[],
help=('Do not run IWYU on source files (or directories) '
'below this path.'))
parser.add_argument('source', nargs='*',
help=('Zero or more source files (or directories) to '
'run IWYU on. Defaults to all in compilation '
'database.'))
def partition_args(argv):
""" Split around '--' into driver args and IWYU args. """
try:
double_dash = argv.index('--')
return argv[:double_dash], argv[double_dash+1:]
except ValueError:
return argv, []
argv, extra_args = partition_args(sys_argv[1:])
args = parser.parse_args(argv)
jobs = args.jobs
if jobs == 0:
jobs = os.cpu_count() or 1
return main(args.dbpath, args.source, args.exclude, args.verbose,
FORMATTERS[args.output_format], jobs, args.load, extra_args)
if __name__ == '__main__':
sys.exit(_bootstrap(sys.argv))

View File

@@ -1,11 +1,24 @@
#!/bin/bash #!/bin/bash
# Script para ejecutar clang-tidy en múltiples directorios # Script para ejecutar clang-tidy en múltiples directorios
# Uso: ./run_clang-tidy.sh # Uso: ./run_clang-tidy.sh [--fix]
# --fix: Aplica las correcciones automáticamente (opcional)
# Detectar si se pasó el parámetro --fix
FIX_FLAG=""
if [[ "$1" == "--fix" ]]; then
FIX_FLAG="--fix"
echo "Modo: Aplicando correcciones automáticamente (--fix)"
else
echo "Modo: Solo análisis (sin --fix)"
fi
echo
# Lista de rutas donde ejecutar clang-tidy # Lista de rutas donde ejecutar clang-tidy
PATHS=( PATHS=(
"/home/sergio/gitea/coffee_crisis_arcade_edition/source" "/home/sergio/gitea/coffee_crisis_arcade_edition/source"
"/home/sergio/gitea/coffee_crisis_arcade_edition/source/rendering"
"/home/sergio/gitea/coffee_crisis_arcade_edition/source/rendering/opengl"
"/home/sergio/gitea/coffee_crisis_arcade_edition/source/sections" "/home/sergio/gitea/coffee_crisis_arcade_edition/source/sections"
"/home/sergio/gitea/coffee_crisis_arcade_edition/source/ui" "/home/sergio/gitea/coffee_crisis_arcade_edition/source/ui"
) )
@@ -29,8 +42,8 @@ process_directory() {
cd "$dir" || return 1 cd "$dir" || return 1
# Buscar archivos .cpp, .h, .hpp solo en el nivel actual (no subdirectorios) # Buscar archivos .cpp, .h, .hpp solo en el nivel actual (no subdirectorios)
find . -maxdepth 1 \( -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) | \ find . -maxdepth 1 \( -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | \
xargs -P4 -I{} bash -c 'echo "Procesando: {}"; clang-tidy {} -p '"$BUILD_DIR"' --fix' xargs -0 -P4 -I{} bash -c 'echo "Procesando: {}"; clang-tidy {} -p '"$BUILD_DIR"' '"$FIX_FLAG"
echo "=== Completado: $dir ===" echo "=== Completado: $dir ==="
echo echo

View File

@@ -15,8 +15,8 @@ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S "$BASE_DIR" -B "$BUILD_DIR"
# 🛠️ Ejecutar IWYU con fix_includes.py # 🛠️ Ejecutar IWYU con fix_includes.py
echo "🚀 Ejecutando IWYU..." echo "🚀 Ejecutando IWYU..."
iwyu_tool.py -p "$BUILD_DIR" -- -Xiwyu --mapping_file="$MAPPING_FILE" -Xiwyu --verbose=3 \ ./iwyu_tool.py -p "$BUILD_DIR" -- -Xiwyu --mapping_file="$MAPPING_FILE" -Xiwyu --verbose=3 \
| python3 /usr/bin/fix_includes.py --update_comments --reorder --nosafe_headers | fix_include --update_comments --reorder --nosafe_headers
# 🧹 Reemplazar // for por // Para en líneas de #include # 🧹 Reemplazar // for por // Para en líneas de #include
echo "✍️ Corrigiendo comentarios en includes..." echo "✍️ Corrigiendo comentarios en includes..."

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 438 KiB

After

Width:  |  Height:  |  Size: 504 KiB

View File

@@ -1,17 +1,17 @@
#include "animated_sprite.h" #include "animated_sprite.hpp"
#include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError, SDL_FRect #include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError, SDL_FRect
#include <algorithm> // Para min, max #include <algorithm> // Para min
#include <cstddef> // Para size_t #include <cstddef> // Para size_t
#include <fstream> // Para basic_istream, basic_ifstream, basic_ios, ifstream, stringstream #include <fstream> // Para basic_istream, basic_ifstream, istream, basic_ios, ifstream, istringstream, stringstream
#include <sstream> // Para basic_stringstream #include <sstream> // Para basic_istringstream, basic_stringstream
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include <utility> // Para pair #include <utility> // Para move, pair
#include "resource_helper.h" // Para ResourceHelper #include "resource_helper.hpp" // Para loadFile
#include "texture.h" // Para Texture #include "texture.hpp" // Para Texture
#include "utils.h" // Para printWithDots #include "ui/logger.hpp" // Para dots
// Carga las animaciones en un vector(Animations) desde un fichero // Carga las animaciones en un vector(Animations) desde un fichero
auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffer { auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffer {
@@ -38,7 +38,7 @@ auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffe
std::istream& input_stream = using_resource_data ? stream : static_cast<std::istream&>(file); std::istream& input_stream = using_resource_data ? stream : static_cast<std::istream&>(file);
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); Logger::dots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
std::vector<std::string> buffer; std::vector<std::string> buffer;
std::string line; std::string line;
@@ -87,13 +87,13 @@ auto AnimatedSprite::getAnimationIndex(const std::string& name) -> int {
} }
// Calcula el frame correspondiente a la animación (time-based) // Calcula el frame correspondiente a la animación (time-based)
void AnimatedSprite::animate(float deltaTime) { void AnimatedSprite::animate(float delta_time) {
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) { if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
return; return;
} }
// Acumular tiempo transcurrido // Acumular tiempo transcurrido
animations_[current_animation_].time_accumulator += deltaTime; animations_[current_animation_].time_accumulator += delta_time;
// Verificar si es momento de cambiar frame // Verificar si es momento de cambiar frame
if (animations_[current_animation_].time_accumulator >= animations_[current_animation_].speed) { if (animations_[current_animation_].time_accumulator >= animations_[current_animation_].speed) {
@@ -106,7 +106,7 @@ void AnimatedSprite::animate(float deltaTime) {
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size() - 1; animations_[current_animation_].current_frame = animations_[current_animation_].frames.size() - 1;
animations_[current_animation_].completed = true; animations_[current_animation_].completed = true;
} else { // Si hay loop, vuelve al frame indicado } else { // Si hay loop, vuelve al frame indicado
animations_[current_animation_].time_accumulator = 0.0f; animations_[current_animation_].time_accumulator = 0.0F;
animations_[current_animation_].current_frame = animations_[current_animation_].loop; animations_[current_animation_].current_frame = animations_[current_animation_].loop;
} }
} }
@@ -129,7 +129,7 @@ void AnimatedSprite::setCurrentAnimation(const std::string& name, bool reset) {
current_animation_ = NEW_ANIMATION; current_animation_ = NEW_ANIMATION;
if (reset) { if (reset) {
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].time_accumulator = 0.0f; animations_[current_animation_].time_accumulator = 0.0F;
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
} else { } else {
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size() - 1); animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size() - 1);
@@ -148,7 +148,7 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
current_animation_ = NEW_ANIMATION; current_animation_ = NEW_ANIMATION;
if (reset) { if (reset) {
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].time_accumulator = 0.0f; animations_[current_animation_].time_accumulator = 0.0F;
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
} else { } else {
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size()); animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
@@ -160,15 +160,15 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
} }
// Actualiza las variables del objeto (time-based) // Actualiza las variables del objeto (time-based)
void AnimatedSprite::update(float deltaTime) { void AnimatedSprite::update(float delta_time) {
animate(deltaTime); animate(delta_time);
MovingSprite::update(deltaTime); MovingSprite::update(delta_time);
} }
// Reinicia la animación // Reinicia la animación
void AnimatedSprite::resetAnimation() { void AnimatedSprite::resetAnimation() {
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].time_accumulator = 0.0f; animations_[current_animation_].time_accumulator = 0.0F;
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
animations_[current_animation_].paused = false; animations_[current_animation_].paused = false;
updateSpriteClip(); updateSpriteClip();

View File

@@ -2,15 +2,14 @@
#include <SDL3/SDL.h> // Para SDL_FRect #include <SDL3/SDL.h> // Para SDL_FRect
#include <algorithm> // Para max
#include <cstddef> // Para size_t #include <cstddef> // Para size_t
#include <memory> // Para allocator, shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string, hash #include <string> // Para basic_string, string, hash
#include <unordered_map> // Para unordered_map #include <unordered_map> // Para unordered_map
#include <utility> #include <utility> // Para move
#include <vector> // Para vector #include <vector> // Para vector
#include "moving_sprite.h" // Para MovingSprite #include "moving_sprite.hpp" // for MovingSprite
// Declaración adelantada // Declaración adelantada
class Texture; class Texture;
@@ -25,7 +24,7 @@ struct Animation {
int loop{0}; // Frame de vuelta al terminar (-1 para no repetir) int loop{0}; // Frame de vuelta al terminar (-1 para no repetir)
bool completed{false}; // Indica si la animación ha finalizado bool completed{false}; // Indica si la animación ha finalizado
size_t current_frame{0}; // Frame actual en reproducción size_t current_frame{0}; // Frame actual en reproducción
float time_accumulator{0.0f}; // Acumulador de tiempo para animaciones time-based float time_accumulator{0.0F}; // Acumulador de tiempo para animaciones time-based
bool paused{false}; // La animación no avanza bool paused{false}; // La animación no avanza
Animation() = default; Animation() = default;
@@ -55,7 +54,7 @@ class AnimatedSprite : public MovingSprite {
~AnimatedSprite() override = default; ~AnimatedSprite() override = default;
// --- Métodos principales --- // --- Métodos principales ---
void update(float deltaTime) override; // Actualiza la animación (time-based) void update(float delta_time) 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
@@ -78,7 +77,7 @@ class AnimatedSprite : public MovingSprite {
int current_animation_ = 0; // Índice de la animación activa int current_animation_ = 0; // Índice de la animación activa
// --- Métodos internos --- // --- Métodos internos ---
void animate(float deltaTime); // Calcula el frame correspondiente a la animación (time-based) void animate(float delta_time); // Calcula el frame correspondiente a la animación (time-based)
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source); // Carga la animación desde un vector de cadenas void loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source); // Carga la animación desde un vector de cadenas
void processConfigLine(const std::string& line, AnimationConfig& config); // Procesa una línea de configuración void processConfigLine(const std::string& line, AnimationConfig& config); // Procesa una línea de configuración
void updateFrameCalculations(AnimationConfig& config); // Actualiza los cálculos basados en las dimensiones del frame void updateFrameCalculations(AnimationConfig& config); // Actualiza los cálculos basados en las dimensiones del frame

View File

@@ -1,22 +1,24 @@
#include "asset.h" #include "asset.hpp"
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn #include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError
#include <algorithm> // Para std::sort #include <algorithm> // Para 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 <filesystem> // Para exists, path
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream #include <fstream> // Para basic_ifstream, basic_istream, basic_ostream, operator<<, ifstream, istringstream, endl
#include <iostream> // Para cout
#include <sstream> // Para basic_istringstream #include <sstream> // Para basic_istringstream
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "resource_helper.h" // Para ResourceHelper #include "resource_helper.hpp" // Para loadFile
#include "utils.h" // Para getFileName #include "ui/logger.hpp" // Para info, section, CYAN
#include "utils.hpp" // Para getFileName
// Singleton // Singleton
Asset *Asset::instance = nullptr; Asset* Asset::instance = nullptr;
void Asset::init(const std::string &executable_path) { void Asset::init(const std::string& executable_path) {
Asset::instance = new Asset(executable_path); Asset::instance = new Asset(executable_path);
} }
@@ -24,12 +26,12 @@ void Asset::destroy() {
delete Asset::instance; delete Asset::instance;
} }
auto Asset::get() -> Asset * { auto Asset::get() -> Asset* {
return Asset::instance; return Asset::instance;
} }
// Añade un elemento al mapa (función auxiliar) // Añade un elemento al mapa (función auxiliar)
void Asset::addToMap(const std::string &file_path, Type type, bool required, bool absolute) { void Asset::addToMap(const std::string& file_path, Type type, bool required, bool absolute) {
std::string full_path = absolute ? file_path : executable_path_ + file_path; std::string full_path = absolute ? file_path : executable_path_ + file_path;
std::string filename = getFileName(full_path); std::string filename = getFileName(full_path);
@@ -44,13 +46,12 @@ void Asset::addToMap(const std::string &file_path, Type type, bool required, boo
} }
// Añade un elemento a la lista // Añade un elemento a la lista
void Asset::add(const std::string &file_path, Type type, bool required, bool absolute) { void Asset::add(const std::string& file_path, Type type, bool required, bool absolute) {
addToMap(file_path, type, required, absolute); addToMap(file_path, type, required, absolute);
} }
// Carga recursos desde un archivo de configuración con soporte para variables // Carga recursos desde un archivo de configuración con soporte para variables
// Carga recursos desde un archivo de configuración con soporte para variables void Asset::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
void Asset::loadFromFile(const std::string &config_file_path, const std::string &prefix, const std::string &system_folder) {
std::ifstream file(config_file_path); std::ifstream file(config_file_path);
if (!file.is_open()) { if (!file.is_open()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -95,7 +96,7 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
} }
try { try {
const std::string &type_str = parts[0]; const std::string& type_str = parts[0];
std::string path = parts[1]; std::string path = parts[1];
// Valores por defecto // Valores por defecto
@@ -116,7 +117,7 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
// Añadir al mapa // Añadir al mapa
addToMap(path, type, required, absolute); addToMap(path, type, required, absolute);
} catch (const std::exception &e) { } catch (const std::exception& e) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error parsing line %d in config file: %s", "Error parsing line %d in config file: %s",
line_number, line_number,
@@ -124,15 +125,12 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
} }
} }
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, std::cout << "Loaded " << file_list_.size() << " assets from config file" << '\n';
"Loaded %d assets from config file",
static_cast<int>(file_list_.size()));
file.close(); file.close();
} }
// Devuelve la ruta completa a un fichero (búsqueda O(1)) // Devuelve la ruta completa a un fichero (búsqueda O(1))
auto Asset::get(const std::string &filename) const -> std::string { auto Asset::get(const std::string& filename) const -> std::string {
auto it = file_list_.find(filename); auto it = file_list_.find(filename);
if (it != file_list_.end()) { if (it != file_list_.end()) {
return it->second.file; return it->second.file;
@@ -143,7 +141,7 @@ auto Asset::get(const std::string &filename) const -> std::string {
} }
// Carga datos del archivo usando ResourceHelper // Carga datos del archivo usando ResourceHelper
auto Asset::loadData(const std::string &filename) const -> std::vector<uint8_t> { auto Asset::loadData(const std::string& filename) const -> std::vector<uint8_t> {
auto it = file_list_.find(filename); auto it = file_list_.find(filename);
if (it != file_list_.end()) { if (it != file_list_.end()) {
return ResourceHelper::loadFile(it->second.file); return ResourceHelper::loadFile(it->second.file);
@@ -154,7 +152,7 @@ auto Asset::loadData(const std::string &filename) const -> std::vector<uint8_t>
} }
// Verifica si un recurso existe // Verifica si un recurso existe
auto Asset::exists(const std::string &filename) const -> bool { auto Asset::exists(const std::string& filename) const -> bool {
return file_list_.find(filename) != file_list_.end(); return file_list_.find(filename) != file_list_.end();
} }
@@ -162,12 +160,13 @@ auto Asset::exists(const std::string &filename) const -> bool {
auto Asset::check() const -> bool { auto Asset::check() const -> bool {
bool success = true; bool success = true;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES"); // SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
Logger::section("CHECKING FILES", Logger::CYAN);
// Agrupar por tipo para mostrar organizado // Agrupar por tipo para mostrar organizado
std::unordered_map<Type, std::vector<const Item *>> by_type; std::unordered_map<Type, std::vector<const Item*>> by_type;
for (const auto &[filename, item] : file_list_) { for (const auto& [filename, item] : file_list_) {
if (item.required) { if (item.required) {
by_type[item.type].push_back(&item); by_type[item.type].push_back(&item);
} }
@@ -178,12 +177,10 @@ auto Asset::check() const -> bool {
Type asset_type = static_cast<Type>(type); Type asset_type = static_cast<Type>(type);
if (by_type.find(asset_type) != by_type.end()) { if (by_type.find(asset_type) != by_type.end()) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, Logger::info(getTypeName(asset_type) + " FILES");
"\n>> %s FILES",
getTypeName(asset_type).c_str());
bool type_success = true; bool type_success = true;
for (const auto *item : by_type[asset_type]) { for (const auto* item : by_type[asset_type]) {
if (!checkFile(item->file)) { if (!checkFile(item->file)) {
success = false; success = false;
type_success = false; type_success = false;
@@ -191,48 +188,43 @@ auto Asset::check() const -> bool {
} }
if (type_success) { if (type_success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " All files are OK."); Logger::info("All files are OK.\n");
} }
} }
} }
// Resultado
if (success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES COMPLETED.\n");
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES FAILED.\n");
}
return success; return success;
} }
// Comprueba que existe un fichero // Comprueba que existe un fichero
auto Asset::checkFile(const std::string &path) const -> bool { auto Asset::checkFile(const std::string& path) const -> bool {
// Construir ruta del pack usando executable_path_ // Construir ruta del pack usando executable_path_ (misma lógica que Director::init)
#ifdef MACOS_BUNDLE
std::string pack_path = executable_path_ + "../Resources/resources.pack";
#else
std::string pack_path = executable_path_ + "resources.pack"; std::string pack_path = executable_path_ + "resources.pack";
#endif
bool pack_exists = std::filesystem::exists(pack_path); bool pack_exists = std::filesystem::exists(pack_path);
if (pack_exists) { if (pack_exists) {
// MODO PACK: Usar ResourceHelper (igual que la carga real) // MODO PACK: Usar ResourceHelper (igual que la carga real)
auto data = ResourceHelper::loadFile(path); auto data = ResourceHelper::loadFile(path);
return !data.empty(); return !data.empty();
} else { } // MODO FILESYSTEM: Verificación directa (modo desarrollo)
// MODO FILESYSTEM: Verificación directa (modo desarrollo)
std::ifstream file(path); std::ifstream file(path);
bool 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,
"Error: Could not open file: %s", path.c_str()); "Error: Could not open file: %s",
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 {
if (type_str == "BITMAP") { if (type_str == "BITMAP") {
return Type::BITMAP; return Type::BITMAP;
} }
@@ -294,20 +286,20 @@ auto Asset::getTypeName(Type type) -> std::string {
auto Asset::getListByType(Type type) const -> std::vector<std::string> { auto Asset::getListByType(Type type) const -> std::vector<std::string> {
std::vector<std::string> list; std::vector<std::string> list;
for (const auto &[filename, item] : file_list_) { for (const auto& [filename, item] : file_list_) {
if (item.type == type) { if (item.type == type) {
list.push_back(item.file); list.push_back(item.file);
} }
} }
// Ordenar alfabéticamente para garantizar orden consistente // Ordenar alfabéticamente para garantizar orden consistente
std::sort(list.begin(), list.end()); std::ranges::sort(list);
return list; return list;
} }
// Reemplaza variables en las rutas // Reemplaza variables en las rutas
auto Asset::replaceVariables(const std::string &path, const std::string &prefix, const std::string &system_folder) -> std::string { auto Asset::replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string {
std::string result = path; std::string result = path;
// Reemplazar ${PREFIX} // Reemplazar ${PREFIX}
@@ -328,7 +320,7 @@ auto Asset::replaceVariables(const std::string &path, const std::string &prefix,
} }
// Parsea las opciones de una línea de configuración // Parsea las opciones de una línea de configuración
auto Asset::parseOptions(const std::string &options, bool &required, bool &absolute) -> void { auto Asset::parseOptions(const std::string& options, bool& required, bool& absolute) -> void {
if (options.empty()) { if (options.empty()) {
return; return;
} }

View File

@@ -24,20 +24,20 @@ class Asset {
}; };
// --- Métodos de singleton --- // --- Métodos de singleton ---
static void init(const std::string &executable_path); static void init(const std::string& executable_path);
static void destroy(); static void destroy();
static auto get() -> Asset *; static auto get() -> Asset*;
Asset(const Asset &) = delete; Asset(const Asset&) = delete;
auto operator=(const Asset &) -> Asset & = delete; auto operator=(const Asset&) -> Asset& = delete;
// --- Métodos para la gestión de recursos --- // --- Métodos para la gestión de recursos ---
void add(const std::string &file_path, Type type, bool required = true, bool absolute = false); void add(const std::string& file_path, Type type, bool required = true, bool absolute = false);
void loadFromFile(const std::string &config_file_path, const std::string &prefix = "", const std::string &system_folder = ""); // Con soporte para variables void loadFromFile(const std::string& config_file_path, const std::string& prefix = "", const std::string& system_folder = ""); // Con soporte para variables
[[nodiscard]] auto get(const std::string &filename) const -> std::string; // Mantener nombre original [[nodiscard]] auto get(const std::string& filename) const -> std::string; // Mantener nombre original
[[nodiscard]] auto loadData(const std::string &filename) const -> std::vector<uint8_t>; // Carga datos del archivo [[nodiscard]] auto loadData(const std::string& filename) const -> std::vector<uint8_t>; // Carga datos del archivo
[[nodiscard]] auto check() const -> bool; [[nodiscard]] auto check() const -> bool;
[[nodiscard]] auto getListByType(Type type) const -> std::vector<std::string>; [[nodiscard]] auto getListByType(Type type) const -> std::vector<std::string>;
[[nodiscard]] auto exists(const std::string &filename) const -> bool; // Nueva función para verificar existencia [[nodiscard]] auto exists(const std::string& filename) const -> bool; // Nueva función para verificar existencia
private: private:
// --- Estructuras privadas --- // --- Estructuras privadas ---
@@ -57,12 +57,12 @@ class Asset {
std::string executable_path_; // Ruta del ejecutable std::string executable_path_; // Ruta del ejecutable
// --- Métodos internos --- // --- Métodos internos ---
[[nodiscard]] auto checkFile(const std::string &path) const -> 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
[[nodiscard]] static auto replaceVariables(const std::string &path, const std::string &prefix, const std::string &system_folder) -> std::string; // Reemplaza variables en la ruta [[nodiscard]] static auto replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string; // Reemplaza variables en la ruta
static auto parseOptions(const std::string &options, bool &required, bool &absolute) -> void; // Parsea opciones static auto parseOptions(const std::string& options, bool& required, bool& absolute) -> void; // Parsea opciones
// --- Constructores y destructor privados (singleton) --- // --- Constructores y destructor privados (singleton) ---
explicit Asset(std::string executable_path) // Constructor privado explicit Asset(std::string executable_path) // Constructor privado
@@ -70,5 +70,5 @@ class Asset {
~Asset() = default; // Destructor privado ~Asset() = default; // Destructor privado
// --- Instancia singleton --- // --- Instancia singleton ---
static Asset *instance; // Instancia única de Asset static Asset* instance; // Instancia única de Asset
}; };

View File

@@ -1,42 +1,42 @@
#include "asset_integrated.h" #include "asset_integrated.hpp"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
bool AssetIntegrated::resource_pack_enabled_ = false; bool AssetIntegrated::resource_pack_enabled = false;
void AssetIntegrated::initWithResourcePack(const std::string &executable_path, void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
const std::string &resource_pack_path) { const std::string& resource_pack_path) {
// Inicializar Asset normal // Inicializar Asset normal
Asset::init(executable_path); Asset::init(executable_path);
// Inicializar ResourceLoader // Inicializar ResourceLoader
auto &loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
if (loader.initialize(resource_pack_path, true)) { if (loader.initialize(resource_pack_path, true)) {
resource_pack_enabled_ = true; resource_pack_enabled = true;
std::cout << "Asset system initialized with resource pack: " << resource_pack_path << std::endl; std::cout << "Asset system initialized with resource pack: " << resource_pack_path << '\n';
} else { } else {
resource_pack_enabled_ = false; resource_pack_enabled = false;
std::cout << "Asset system initialized in fallback mode (filesystem)" << std::endl; std::cout << "Asset system initialized in fallback mode (filesystem)" << '\n';
} }
} }
std::vector<uint8_t> AssetIntegrated::loadFile(const std::string &filename) { auto AssetIntegrated::loadFile(const std::string& filename) -> std::vector<uint8_t> {
if (shouldUseResourcePack(filename) && resource_pack_enabled_) { if (shouldUseResourcePack(filename) && resource_pack_enabled) {
// Intentar cargar del pack de recursos // Intentar cargar del pack de recursos
auto &loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
// Convertir ruta completa a ruta relativa para el pack // Convertir ruta completa a ruta relativa para el pack
std::string relativePath = filename; std::string relative_path = filename;
// Si la ruta contiene "data/", extraer la parte relativa // Si la ruta contiene "data/", extraer la parte relativa
size_t dataPos = filename.find("data/"); size_t data_pos = filename.find("data/");
if (dataPos != std::string::npos) { if (data_pos != std::string::npos) {
relativePath = filename.substr(dataPos + 5); // +5 para saltar "data/" relative_path = filename.substr(data_pos + 5); // +5 para saltar "data/"
} }
auto data = loader.loadResource(relativePath); auto data = loader.loadResource(relative_path);
if (!data.empty()) { if (!data.empty()) {
return data; return data;
} }
@@ -45,34 +45,34 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string &filename) {
// Fallback: cargar del filesystem // Fallback: cargar del filesystem
std::ifstream file(filename, std::ios::binary | std::ios::ate); std::ifstream file(filename, std::ios::binary | std::ios::ate);
if (!file) { if (!file) {
std::cerr << "Error: Could not open file: " << filename << std::endl; std::cerr << "Error: Could not open file: " << filename << '\n';
return {}; return {};
} }
std::streamsize fileSize = file.tellg(); std::streamsize file_size = file.tellg();
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
std::vector<uint8_t> data(fileSize); std::vector<uint8_t> data(file_size);
if (!file.read(reinterpret_cast<char *>(data.data()), fileSize)) { if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
std::cerr << "Error: Could not read file: " << filename << std::endl; std::cerr << "Error: Could not read file: " << filename << '\n';
return {}; return {};
} }
return data; return data;
} }
bool AssetIntegrated::fileExists(const std::string &filename) const { auto AssetIntegrated::fileExists(const std::string& filename) -> bool {
if (shouldUseResourcePack(filename) && resource_pack_enabled_) { if (shouldUseResourcePack(filename) && resource_pack_enabled) {
auto &loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
// Convertir ruta completa a ruta relativa para el pack // Convertir ruta completa a ruta relativa para el pack
std::string relativePath = filename; std::string relative_path = filename;
size_t dataPos = filename.find("data/"); size_t data_pos = filename.find("data/");
if (dataPos != std::string::npos) { if (data_pos != std::string::npos) {
relativePath = filename.substr(dataPos + 5); relative_path = filename.substr(data_pos + 5);
} }
if (loader.resourceExists(relativePath)) { if (loader.resourceExists(relative_path)) {
return true; return true;
} }
} }
@@ -81,24 +81,24 @@ bool AssetIntegrated::fileExists(const std::string &filename) const {
return std::filesystem::exists(filename); return std::filesystem::exists(filename);
} }
std::string AssetIntegrated::getSystemPath(const std::string &filename) const { auto AssetIntegrated::getSystemPath(const std::string& filename) -> std::string {
// Los archivos de sistema/config siempre van al filesystem // Los archivos de sistema/config siempre van al filesystem
return filename; return filename;
} }
bool AssetIntegrated::shouldUseResourcePack(const std::string &filepath) const { auto AssetIntegrated::shouldUseResourcePack(const std::string& filepath) -> bool {
// Los archivos que NO van al pack: // Los archivos que NO van al pack:
// - Archivos de config/ (ahora están fuera de data/) // - Archivos de config/ (ahora están fuera de data/)
// - Archivos con absolute=true en assets.txt // - Archivos con absolute=true en assets.txt
// - Archivos de sistema (${SYSTEM_FOLDER}) // - Archivos de sistema (${SYSTEM_FOLDER})
if (filepath.find("/config/") != std::string::npos || if (filepath.find("/config/") != std::string::npos ||
filepath.find("config/") == 0) { filepath.starts_with("config/")) {
return false; return false;
} }
if (filepath.find("/data/") != std::string::npos || if (filepath.find("/data/") != std::string::npos ||
filepath.find("data/") == 0) { filepath.starts_with("data/")) {
return true; return true;
} }

View File

@@ -1,29 +0,0 @@
#pragma once
#include <memory>
#include "asset.h"
#include "resource_loader.h"
// Extensión de Asset que integra ResourceLoader
class AssetIntegrated : public Asset {
public:
// Inicializa Asset con ResourceLoader
static void initWithResourcePack(const std::string &executable_path,
const std::string &resource_pack_path = "resources.pack");
// Carga un archivo usando ResourceLoader como primera opción
std::vector<uint8_t> loadFile(const std::string &filename);
// Verifica si un archivo existe (pack o filesystem)
bool fileExists(const std::string &filename) const;
// Obtiene la ruta completa para archivos del sistema/config
std::string getSystemPath(const std::string &filename) const;
private:
static bool resource_pack_enabled_;
// Determina si un archivo debe cargarse del pack o del filesystem
bool shouldUseResourcePack(const std::string &filepath) const;
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <memory>
#include "asset.hpp"
#include "resource_loader.hpp"
// Extensión de Asset que integra ResourceLoader
class AssetIntegrated : public Asset {
public:
// Inicializa Asset con ResourceLoader
static void initWithResourcePack(const std::string& executable_path,
const std::string& resource_pack_path = "resources.pack");
// Carga un archivo usando ResourceLoader como primera opción
static auto loadFile(const std::string& filename) -> std::vector<uint8_t>;
// Verifica si un archivo existe (pack o filesystem)
static auto fileExists(const std::string& filename) -> bool;
// Obtiene la ruta completa para archivos del sistema/config
static auto getSystemPath(const std::string& filename) -> std::string;
private:
static bool resource_pack_enabled;
// Determina si un archivo debe cargarse del pack o del filesystem
static auto shouldUseResourcePack(const std::string& filepath) -> bool;
};

View File

@@ -1,15 +1,16 @@
#include "audio.h" #include "audio.hpp"
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_G... #include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_G...
#include <algorithm> // Para clamp #include <algorithm> // Para clamp
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM... #include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
#include "options.h" // Para AudioOptions, audio, MusicOptions #include "options.hpp" // Para AudioOptions, audio, MusicOptions
#include "resource.h" // Para Resource #include "resource.hpp" // Para Resource
#include "ui/logger.hpp" // Para logger
// Singleton // Singleton
Audio *Audio::instance = nullptr; Audio* Audio::instance = nullptr;
// Inicializa la instancia única del singleton // Inicializa la instancia única del singleton
void Audio::init() { Audio::instance = new Audio(); } void Audio::init() { Audio::instance = new Audio(); }
@@ -18,7 +19,7 @@ void Audio::init() { Audio::instance = new Audio(); }
void Audio::destroy() { delete Audio::instance; } void Audio::destroy() { delete Audio::instance; }
// Obtiene la instancia // Obtiene la instancia
auto Audio::get() -> Audio * { return Audio::instance; } auto Audio::get() -> Audio* { return Audio::instance; }
// Constructor // Constructor
Audio::Audio() { initSDLAudio(); } Audio::Audio() { initSDLAudio(); }
@@ -34,7 +35,7 @@ void Audio::update() {
} }
// Reproduce la música // Reproduce la música
void Audio::playMusic(const std::string &name, const int loop) { void Audio::playMusic(const std::string& name, const int loop) {
music_.name = name; music_.name = name;
music_.loop = (loop != 0); music_.loop = (loop != 0);
@@ -69,7 +70,7 @@ 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_) {
JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group)); JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group));
} }
@@ -90,7 +91,7 @@ void Audio::fadeOutMusic(int milliseconds) const {
} }
// Consulta directamente el estado real de la música en jailaudio // Consulta directamente el estado real de la música en jailaudio
auto Audio::getRealMusicState() const -> MusicState { auto Audio::getRealMusicState() -> MusicState {
JA_Music_state ja_state = JA_GetMusicState(); JA_Music_state ja_state = JA_GetMusicState();
switch (ja_state) { switch (ja_state) {
case JA_MUSIC_PLAYING: case JA_MUSIC_PLAYING:
@@ -144,6 +145,6 @@ void Audio::initSDLAudio() {
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2); JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
enable(Options::audio.enabled); enable(Options::audio.enabled);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully"); Logger::info("Audio system initialized successfully");
} }
} }

View File

@@ -27,22 +27,22 @@ class Audio {
// --- Métodos de singleton --- // --- Métodos de singleton ---
static void init(); // Inicializa el objeto Audio static void init(); // Inicializa el objeto Audio
static void destroy(); // Libera el objeto Audio static void destroy(); // Libera el objeto Audio
static auto get() -> Audio *; // Obtiene el puntero al objeto Audio static auto get() -> Audio*; // Obtiene el puntero al objeto Audio
Audio(const Audio &) = delete; // Evitar copia Audio(const Audio&) = delete; // Evitar copia
auto operator=(const Audio &) -> Audio & = delete; // Evitar asignación auto operator=(const Audio&) -> Audio& = delete; // Evitar asignación
// --- Método principal --- // --- Método principal ---
static void update(); static void update();
// --- Control de Música --- // --- Control de Música ---
void playMusic(const std::string &name, int loop = -1); // Reproducir música en bucle void playMusic(const std::string& name, int loop = -1); // Reproducir música en bucle
void pauseMusic(); // Pausar reproducción de música void pauseMusic(); // Pausar reproducción de música
void resumeMusic(); // Continua la música pausada void resumeMusic(); // Continua la música pausada
void stopMusic(); // Detener completamente la música void stopMusic(); // Detener completamente la música
void fadeOutMusic(int milliseconds) const; // Fundido de salida de la música void fadeOutMusic(int milliseconds) const; // Fundido de salida de la música
// --- Control de Sonidos --- // --- Control de Sonidos ---
void playSound(const std::string &name, Group group = Group::GAME) const; // Reproducir sonido puntual void playSound(const std::string& name, Group group = Group::GAME) const; // Reproducir sonido puntual
void stopAllSounds() const; // Detener todos los sonidos void stopAllSounds() const; // Detener todos los sonidos
// --- Configuración General --- // --- Configuración General ---
@@ -67,12 +67,12 @@ class Audio {
void setMusicVolume(int volume) const; // Ajustar volumen de música void setMusicVolume(int volume) const; // Ajustar volumen de música
// --- Getters para debug --- // --- Getters para debug ---
bool isEnabled() const { return enabled_; } [[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
bool isSoundEnabled() const { return sound_enabled_; } [[nodiscard]] auto isSoundEnabled() const -> bool { return sound_enabled_; }
bool isMusicEnabled() const { return music_enabled_; } [[nodiscard]] auto isMusicEnabled() const -> bool { return music_enabled_; }
MusicState getMusicState() const { return music_.state; } [[nodiscard]] auto getMusicState() const -> MusicState { return music_.state; }
MusicState getRealMusicState() const; // Consulta directamente a jailaudio [[nodiscard]] static auto getRealMusicState() -> MusicState; // Consulta directamente a jailaudio
const std::string& getCurrentMusicName() const { return music_.name; } [[nodiscard]] auto getCurrentMusicName() const -> const std::string& { return music_.name; }
private: private:
// --- Estructuras privadas --- // --- Estructuras privadas ---
@@ -107,5 +107,5 @@ class Audio {
~Audio(); // Destructor privado ~Audio(); // Destructor privado
// --- Instancia singleton --- // --- Instancia singleton ---
static Audio *instance; // Instancia única de Audio static Audio* instance; // Instancia única de Audio
}; };

View File

@@ -1,19 +1,21 @@
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include "background.h" #include "background.hpp"
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetRenderTarget, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetRenderTarget, SDL_RenderTexture, SDL_SetTextureAlphaMod, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_RenderClear, SDL_SetRenderDrawColor, SDL_TextureAccess, SDL_FPoint #include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetRenderTarget, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetRenderTarget, SDL_RenderTexture, SDL_SetTextureAlphaMod, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_RenderClear, SDL_SetRenderDrawColor, SDL_TextureAccess, SDL_FPoint
#include <algorithm> // Para clamp, max #include <algorithm> // Para clamp, min, max
#include <cmath> // Para M_PI, cos, sin #include <cmath> // Para M_PI, cos, sin
#include <utility> #include <string> // Para basic_string
#include <utility> // Para move
#include "moving_sprite.h" // Para MovingSprite #include "animated_sprite.hpp" // Para AnimatedSprite
#include "param.h" // Para Param, ParamBackground, param #include "moving_sprite.hpp" // Para MovingSprite
#include "resource.h" // Para Resource #include "param.hpp" // Para Param, ParamBackground, param
#include "screen.h" // Para Screen #include "resource.hpp" // Para Resource
#include "sprite.h" // Para Sprite #include "screen.hpp" // Para Screen
#include "texture.h" // Para Texture #include "sprite.hpp" // Para Sprite
#include "utils.h" // Para funciones de easing #include "texture.hpp" // Para Texture
#include "utils.hpp" // Para easeOutCubic
// Constructor // Constructor
Background::Background(float total_progress_to_complete) Background::Background(float total_progress_to_complete)
@@ -22,10 +24,10 @@ Background::Background(float total_progress_to_complete)
buildings_texture_(Resource::get()->getTexture("game_buildings.png")), buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")), top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")), bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
grass_texture_(Resource::get()->getTexture("game_grass.png")),
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")), gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
sun_texture_(Resource::get()->getTexture("game_sun.png")), sun_texture_(Resource::get()->getTexture("game_sun.png")),
moon_texture_(Resource::get()->getTexture("game_moon.png")), moon_texture_(Resource::get()->getTexture("game_moon.png")),
grass_sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("game_grass.png"), Resource::get()->getAnimation("game_grass.ani"))),
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),
@@ -88,7 +90,6 @@ void Background::initializeSprites() {
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_); buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h); gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
sun_sprite_ = std::make_unique<Sprite>(sun_texture_); sun_sprite_ = std::make_unique<Sprite>(sun_texture_);
moon_sprite_ = std::make_unique<Sprite>(moon_texture_); moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
} }
@@ -111,8 +112,14 @@ void Background::initializeSpriteProperties() {
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(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S); bottom_clouds_sprite_b_->setVelX(-INITIAL_BOTTOM_CLOUDS_SPEED_PX_PER_S);
// grass_sprite_->setY(base_ - grass_sprite_->getHeight());
// grass_sprite_->resetAnimation();
grass_sprite_->setPos(0.0F, base_ - 10.0F);
grass_sprite_->setWidth(320.0F);
grass_sprite_->setHeight(10.0F);
// grass_sprite_->setCurrentAnimation(0);
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight()); buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
sun_sprite_->setPosition(sun_path_.front()); sun_sprite_->setPosition(sun_path_.front());
moon_sprite_->setPosition(moon_path_.front()); moon_sprite_->setPosition(moon_path_.front());
} }
@@ -136,17 +143,13 @@ void Background::update(float delta_time) {
} }
// Actualiza el valor de alpha // Actualiza el valor de alpha
updateAlphaColorTexture(); updateAlphaColorTexture(delta_time);
// Actualiza las nubes // Actualiza las nubes
updateClouds(delta_time); updateClouds(delta_time);
// Actualiza timer de hierba // Actualiza el sprite con la hierba
grass_timer_ += delta_time; grass_sprite_->update(delta_time);
// Calcula el frame de la hierba (alterna cada GRASS_FRAME_DURATION ms)
int grass_frame = static_cast<int>(grass_timer_ / GRASS_FRAME_DURATION) % 2;
grass_sprite_->setSpriteClip(0, (10 * grass_frame), 320, 10);
// Calcula el valor de alpha // Calcula el valor de alpha
alpha_ = std::max((255 - (int)(255 * transition_)), 0); alpha_ = std::max((255 - (int)(255 * transition_)), 0);
@@ -189,7 +192,7 @@ void Background::setState(State new_state) {
// Si entra en estado completado, inicializar variables de transición // Si entra en estado completado, inicializar variables de transición
if (new_state == State::COMPLETED && state_ != State::COMPLETED) { if (new_state == State::COMPLETED && state_ != State::COMPLETED) {
completion_initial_progress_ = progress_; completion_initial_progress_ = progress_;
completion_transition_timer_ = 0.0f; completion_transition_timer_ = 0.0F;
} }
state_ = new_state; state_ = new_state;
@@ -207,8 +210,8 @@ void Background::reset() {
moon_index_ = 0; moon_index_ = 0;
// Resetear variables de transición de completado // Resetear variables de transición de completado
completion_transition_timer_ = 0.0f; completion_transition_timer_ = 0.0F;
completion_initial_progress_ = 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) {
@@ -272,9 +275,9 @@ void Background::updateProgression(float delta_time) {
completion_transition_timer_ += delta_time; completion_transition_timer_ += delta_time;
// Calcular progreso normalizado de la transición (0.0 a 1.0) // 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); float t = std::min(completion_transition_timer_ / COMPLETION_TRANSITION_DURATION_S, 1.0F);
if (t < 1.0f) { if (t < 1.0F) {
// Usar easeOutCubic para transición suave (rápido al inicio, lento al final) // Usar easeOutCubic para transición suave (rápido al inicio, lento al final)
float eased_t = easeOutCubic(static_cast<double>(t)); float eased_t = easeOutCubic(static_cast<double>(t));
@@ -340,12 +343,12 @@ void Background::updateCloudsSpeed() {
} }
// Actualiza las nubes // Actualiza las nubes
void Background::updateClouds(float deltaTime) { void Background::updateClouds(float delta_time) {
// Mueve las nubes // Mueve las nubes
top_clouds_sprite_a_->update(deltaTime); top_clouds_sprite_a_->update(delta_time);
top_clouds_sprite_b_->update(deltaTime); top_clouds_sprite_b_->update(delta_time);
bottom_clouds_sprite_a_->update(deltaTime); bottom_clouds_sprite_a_->update(delta_time);
bottom_clouds_sprite_b_->update(deltaTime); bottom_clouds_sprite_b_->update(delta_time);
// Calcula el offset de las nubes // Calcula el offset de las nubes
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) { if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
@@ -415,7 +418,7 @@ void Background::renderBottomClouds() {
// Compone todos los elementos del fondo en la textura // Compone todos los elementos del fondo en la textura
void Background::fillCanvas() { void Background::fillCanvas() {
// Cambia el destino del renderizador // Cambia el destino del renderizador
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, canvas_); SDL_SetRenderTarget(renderer_, canvas_);
// Dibuja el gradiente de fondo // Dibuja el gradiente de fondo
@@ -466,7 +469,7 @@ void Background::setColor(Color color) {
attenuate_color_ = color; attenuate_color_ = color;
// Colorea la textura // Colorea la textura
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, color_texture_); SDL_SetRenderTarget(renderer_, color_texture_);
SDL_SetRenderDrawColor(renderer_, attenuate_color_.r, attenuate_color_.g, attenuate_color_.b, 255); SDL_SetRenderDrawColor(renderer_, attenuate_color_.r, attenuate_color_.g, attenuate_color_.b, 255);
@@ -485,13 +488,39 @@ void Background::setAlpha(int alpha) {
alpha_color_texture_ = alpha; alpha_color_texture_ = alpha;
} }
// Actualiza el valor de alpha // Actualiza el valor de alpha (time-based)
void Background::updateAlphaColorTexture() { void Background::updateAlphaColorTexture(float delta_time) {
// 1. Si ya hemos llegado al destino, no hacemos nada.
if (alpha_color_texture_ == previous_alpha_color_texture_) { if (alpha_color_texture_ == previous_alpha_color_texture_) {
return; return;
} }
alpha_color_texture_ > previous_alpha_color_texture_ ? ++previous_alpha_color_texture_ : --previous_alpha_color_texture_;
SDL_SetTextureAlphaMod(color_texture_, previous_alpha_color_texture_); // 2. Define la velocidad del cambio (p. ej., 150 unidades de alfa por segundo).
// Puedes ajustar este valor para que la transición sea más rápida o lenta.
constexpr float ALPHA_TRANSITION_SPEED = 150.0F;
// 3. Determina la dirección del cambio (subir o bajar el alfa)
if (alpha_color_texture_ > previous_alpha_color_texture_) {
// Aumentar el alfa
current_alpha_float_ += ALPHA_TRANSITION_SPEED * delta_time;
// Nos aseguramos de no pasarnos del objetivo
current_alpha_float_ = std::min(current_alpha_float_, static_cast<float>(alpha_color_texture_));
} else {
// Disminuir el alfa
current_alpha_float_ -= ALPHA_TRANSITION_SPEED * delta_time;
// Nos aseguramos de no quedarnos cortos del objetivo
current_alpha_float_ = std::max(current_alpha_float_, static_cast<float>(alpha_color_texture_));
}
// 4. Actualiza el valor entero solo si ha cambiado lo suficiente
// Usamos std::round para un redondeo más natural.
const auto NEW_ALPHA = static_cast<size_t>(std::round(current_alpha_float_));
if (NEW_ALPHA != previous_alpha_color_texture_) {
previous_alpha_color_texture_ = NEW_ALPHA;
// SDL espera un Uint8 (0-255), así que hacemos un cast seguro.
SDL_SetTextureAlphaMod(color_texture_, static_cast<Uint8>(previous_alpha_color_texture_));
}
} }
// Precalcula el vector con el recorrido del sol // Precalcula el vector con el recorrido del sol

View File

@@ -8,11 +8,12 @@
#include <memory> // Para unique_ptr, shared_ptr #include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector #include <vector> // Para vector
#include "color.h" // Para Color #include "color.hpp" // Para Color
class MovingSprite; class MovingSprite;
class Sprite; class Sprite;
class Texture; class Texture;
class AnimatedSprite;
// --- Clase Background: gestiona el fondo de la sección jugable --- // --- Clase Background: gestiona el fondo de la sección jugable ---
class Background { class Background {
@@ -66,13 +67,12 @@ class Background {
static constexpr float COMPLETION_TRANSITION_DURATION_S = 3.0F; // Duración de la transición de completado en segundos 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
SDL_Texture *canvas_; // Textura para componer el fondo SDL_Texture* canvas_; // Textura para componer el fondo
SDL_Texture *color_texture_; // Textura para atenuar el fondo SDL_Texture* color_texture_; // Textura para atenuar el fondo
std::shared_ptr<Texture> buildings_texture_; // Textura de edificios std::shared_ptr<Texture> buildings_texture_; // Textura de edificios
std::shared_ptr<Texture> top_clouds_texture_; // Textura de nubes superiores std::shared_ptr<Texture> top_clouds_texture_; // Textura de nubes superiores
std::shared_ptr<Texture> bottom_clouds_texture_; // Textura de nubes inferiores std::shared_ptr<Texture> bottom_clouds_texture_; // Textura de nubes inferiores
std::shared_ptr<Texture> grass_texture_; // Textura de hierba
std::shared_ptr<Texture> gradients_texture_; // Textura de gradientes std::shared_ptr<Texture> gradients_texture_; // Textura de gradientes
std::shared_ptr<Texture> sun_texture_; // Textura del sol std::shared_ptr<Texture> sun_texture_; // Textura del sol
std::shared_ptr<Texture> moon_texture_; // Textura de la luna std::shared_ptr<Texture> moon_texture_; // Textura de la luna
@@ -82,9 +82,9 @@ class Background {
std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite de nubes inferiores B std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite de nubes inferiores B
std::unique_ptr<Sprite> buildings_sprite_; // Sprite de edificios std::unique_ptr<Sprite> buildings_sprite_; // Sprite de edificios
std::unique_ptr<Sprite> gradient_sprite_; // Sprite de gradiente std::unique_ptr<Sprite> gradient_sprite_; // Sprite de gradiente
std::unique_ptr<Sprite> grass_sprite_; // Sprite de hierba
std::unique_ptr<Sprite> sun_sprite_; // Sprite del sol std::unique_ptr<Sprite> sun_sprite_; // Sprite del sol
std::unique_ptr<Sprite> moon_sprite_; // Sprite de la luna std::unique_ptr<Sprite> moon_sprite_; // Sprite de la luna
std::unique_ptr<AnimatedSprite> grass_sprite_; // Sprite con la hierba
// --- Variables de configuración --- // --- Variables de configuración ---
const float total_progress_to_complete_; // Progreso total para completar const float total_progress_to_complete_; // Progreso total para completar
@@ -107,9 +107,8 @@ class Background {
float progress_ = 0.0F; // Progresión interna float progress_ = 0.0F; // Progresión interna
float clouds_speed_ = 0; // Velocidad de las nubes float clouds_speed_ = 0; // Velocidad de las nubes
float transition_ = 0; // Porcentaje de transición float transition_ = 0; // Porcentaje de transición
float current_alpha_float_ = 0.0F; // Acumulador para el valor alfa preciso
size_t gradient_number_ = 0; // Índice de fondo degradado size_t gradient_number_ = 0; // Índice de fondo degradado
float grass_timer_ = 0.0f; // Timer para animación de hierba (ms)
static constexpr float GRASS_FRAME_DURATION = 333.34f; // Duración por frame de hierba (20 frames * 16.67ms)
size_t alpha_color_texture_ = 0; // Transparencia de atenuación size_t alpha_color_texture_ = 0; // Transparencia de atenuación
size_t previous_alpha_color_texture_ = 0; // Transparencia anterior size_t previous_alpha_color_texture_ = 0; // Transparencia anterior
size_t sun_index_ = 0; // Índice del recorrido del sol size_t sun_index_ = 0; // Índice del recorrido del sol
@@ -119,8 +118,8 @@ class Background {
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 --- // --- Variables para transición suave de completado ---
float completion_transition_timer_ = 0.0f; // Timer para la transición 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 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
@@ -134,8 +133,8 @@ class Background {
void renderTopClouds(); // Dibuja las nubes superiores void renderTopClouds(); // Dibuja las nubes superiores
void renderBottomClouds(); // Dibuja las nubes inferiores void renderBottomClouds(); // Dibuja las nubes inferiores
void fillCanvas(); // Compone todos los elementos en la textura void fillCanvas(); // Compone todos los elementos en la textura
void updateAlphaColorTexture(); // Actualiza el alpha de la textura de atenuación void updateAlphaColorTexture(float delta_time); // Actualiza el alpha de la textura de atenuación
void updateClouds(float deltaTime); // Actualiza el movimiento de las nubes (time-based) void updateClouds(float delta_time); // Actualiza el movimiento de las nubes (time-based)
void createSunPath(); // Precalcula el recorrido del sol void createSunPath(); // Precalcula el recorrido del sol
void createMoonPath(); // Precalcula el recorrido de la luna void createMoonPath(); // Precalcula el recorrido de la luna
}; };

View File

@@ -1,14 +1,14 @@
#include "balloon.h" #include "balloon.hpp"
#include <algorithm> // Para clamp #include <algorithm> // Para clamp
#include <array> // Para array #include <array> // Para array
#include <cmath> // Para fabs #include <cmath> // Para fabs
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.hpp" // Para AnimatedSprite
#include "audio.h" // Para Audio #include "audio.hpp" // Para Audio
#include "param.h" // Para Param, ParamBalloon, param #include "param.hpp" // Para Param, ParamBalloon, param
#include "sprite.h" // Para Sprite #include "sprite.hpp" // Para Sprite
#include "texture.h" // Para Texture #include "texture.hpp" // Para Texture
// Constructor // Constructor
Balloon::Balloon(const Config& config) Balloon::Balloon(const Config& config)
@@ -131,7 +131,7 @@ void Balloon::render() {
// Renderizado para el resto de globos // Renderizado para el resto de globos
if (isBeingCreated()) { if (isBeingCreated()) {
// Renderizado con transparencia // Renderizado con transparencia
sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0F / (float)creation_counter_ini_))); sprite_->getTexture()->setAlpha(255 - (int)(creation_counter_ * (255.0F / creation_counter_ini_)));
sprite_->render(); sprite_->render();
sprite_->getTexture()->setAlpha(255); sprite_->getTexture()->setAlpha(255);
} else { } else {
@@ -142,19 +142,19 @@ void Balloon::render() {
} }
// Actualiza la posición y estados del globo (time-based) // Actualiza la posición y estados del globo (time-based)
void Balloon::move(float deltaTime) { void Balloon::move(float delta_time) {
if (isStopped()) { if (isStopped()) {
return; return;
} }
handleHorizontalMovement(deltaTime); handleHorizontalMovement(delta_time);
handleVerticalMovement(deltaTime); handleVerticalMovement(delta_time);
applyGravity(deltaTime); applyGravity(delta_time);
} }
void Balloon::handleHorizontalMovement(float deltaTime) { void Balloon::handleHorizontalMovement(float delta_time) {
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s) // DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
x_ += vx_ * game_tempo_ * deltaTime; x_ += vx_ * game_tempo_ * delta_time;
const int CLIP = 2; const int CLIP = 2;
const float MIN_X = play_area_.x - CLIP; const float MIN_X = play_area_.x - CLIP;
@@ -165,9 +165,9 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
} }
} }
void Balloon::handleVerticalMovement(float deltaTime) { void Balloon::handleVerticalMovement(float delta_time) {
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s) // DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
y_ += vy_ * game_tempo_ * deltaTime; y_ += vy_ * game_tempo_ * delta_time;
if (shouldCheckTopCollision()) { if (shouldCheckTopCollision()) {
handleTopCollision(); handleTopCollision();
@@ -222,37 +222,37 @@ void Balloon::handleBottomCollision() {
} }
} }
void Balloon::applyGravity(float deltaTime) { void Balloon::applyGravity(float delta_time) {
// DeltaTime en segundos: aceleración (pixels/s²) * tempo * tiempo (s) // DeltaTime en segundos: aceleración (pixels/s²) * tempo * tiempo (s)
vy_ += gravity_ * game_tempo_ * deltaTime; vy_ += gravity_ * game_tempo_ * delta_time;
} }
void Balloon::playBouncingSound() { void Balloon::playBouncingSound() const {
if (sound_.enabled && sound_.bouncing_enabled) { if (sound_.enabled && sound_.bouncing_enabled) {
Audio::get()->playSound(sound_.bouncing_file); Audio::get()->playSound(sound_.bouncing_file);
} }
} }
void Balloon::playPoppingSound() { void Balloon::playPoppingSound() const {
if (sound_.enabled && sound_.poping_enabled) { if (sound_.enabled && sound_.poping_enabled) {
Audio::get()->playSound(sound_.popping_file); Audio::get()->playSound(sound_.popping_file);
} }
} }
// Actualiza al globo a su posicion, animación y controla los contadores (time-based) // Actualiza al globo a su posicion, animación y controla los contadores (time-based)
void Balloon::update(float deltaTime) { void Balloon::update(float delta_time) {
move(deltaTime); move(delta_time);
updateState(deltaTime); updateState(delta_time);
updateBounceEffect(); updateBounceEffect();
shiftSprite(); shiftSprite();
shiftColliders(); shiftColliders();
sprite_->update(deltaTime); sprite_->update(delta_time);
// Contador interno con deltaTime en segundos // Contador interno con deltaTime en segundos
counter_ += deltaTime; counter_ += delta_time;
} }
// Actualiza los estados del globo (time-based) // Actualiza los estados del globo (time-based)
void Balloon::updateState(float deltaTime) { void Balloon::updateState(float delta_time) {
// Si se está creando // Si se está creando
if (isBeingCreated()) { if (isBeingCreated()) {
// Actualiza el valor de las variables // Actualiza el valor de las variables
@@ -262,13 +262,13 @@ void Balloon::updateState(float deltaTime) {
if (creation_counter_ > 0) { if (creation_counter_ > 0) {
// Desplaza lentamente el globo hacia abajo y hacia un lado // Desplaza lentamente el globo hacia abajo y hacia un lado
// Cada 10/60 segundos (equivalente a 10 frames a 60fps) // Cada 10/60 segundos (equivalente a 10 frames a 60fps)
movement_accumulator_ += deltaTime; movement_accumulator_ += delta_time;
constexpr float MOVEMENT_INTERVAL_S = 10.0f / 60.0f; // 10 frames = ~0.167s constexpr float MOVEMENT_INTERVAL_S = 10.0F / 60.0F; // 10 frames = ~0.167s
if (movement_accumulator_ >= MOVEMENT_INTERVAL_S) { if (movement_accumulator_ >= MOVEMENT_INTERVAL_S) {
movement_accumulator_ -= MOVEMENT_INTERVAL_S; movement_accumulator_ -= MOVEMENT_INTERVAL_S;
y_++; y_++;
x_ += vx_ / 60.0f; // Convierte de pixels/segundo a pixels/frame para movimiento discreto x_ += vx_ / 60.0F; // Convierte de pixels/segundo a pixels/frame para movimiento discreto
// Comprueba no se salga por los laterales // Comprueba no se salga por los laterales
const int MIN_X = play_area_.x; const int MIN_X = play_area_.x;
@@ -276,12 +276,12 @@ void Balloon::updateState(float deltaTime) {
if (x_ < MIN_X || x_ > MAX_X) { if (x_ < MIN_X || x_ > MAX_X) {
// Corrige y cambia el sentido de la velocidad // Corrige y cambia el sentido de la velocidad
x_ -= vx_ / 60.0f; x_ -= vx_ / 60.0F;
vx_ = -vx_; vx_ = -vx_;
} }
} }
creation_counter_ -= deltaTime; creation_counter_ -= delta_time;
if (creation_counter_ < 0) creation_counter_ = 0; creation_counter_ = std::max<float>(creation_counter_, 0);
} }
else { else {

View File

@@ -8,8 +8,8 @@
#include <string_view> // Para string_view #include <string_view> // Para string_view
#include <vector> // Para vector #include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.hpp" // Para AnimatedSprite
#include "utils.h" // Para Circle #include "utils.hpp" // Para Circle
class Texture; class Texture;
@@ -77,7 +77,7 @@ class Balloon {
Size size = Size::EXTRALARGE; Size size = Size::EXTRALARGE;
float vel_x = VELX_POSITIVE; float vel_x = VELX_POSITIVE;
float game_tempo = GAME_TEMPO.at(0); float game_tempo = GAME_TEMPO.at(0);
float creation_counter = 0.0f; float creation_counter = 0.0F;
SDL_FRect play_area = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F}; SDL_FRect play_area = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
std::shared_ptr<Texture> texture = nullptr; std::shared_ptr<Texture> texture = nullptr;
std::vector<std::string> animation; std::vector<std::string> animation;
@@ -91,8 +91,8 @@ class Balloon {
// --- Métodos principales --- // --- Métodos principales ---
void alignTo(int x); // Centra el globo en la posición X void alignTo(int x); // Centra el globo en la posición X
void render(); // Pinta el globo en la pantalla void render(); // Pinta el globo en la pantalla
void move(float deltaTime); // Actualiza la posición y estados del globo (time-based) void move(float delta_time); // Actualiza la posición y estados del globo (time-based)
void update(float deltaTime); // Actualiza el globo (posición, animación, contadores) (time-based) void update(float delta_time); // Actualiza el globo (posición, animación, contadores) (time-based)
void stop(); // Detiene el globo void stop(); // Detiene el globo
void start(); // Pone el globo en movimiento void start(); // Pone el globo en movimiento
void pop(bool should_sound = false); // Explota el globo void pop(bool should_sound = false); // Explota el globo
@@ -123,7 +123,7 @@ 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 setVelX(float vel_x) { vx_ = vel_x; }
void alterVelX(float percent) {vx_ *= percent; } 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; }
@@ -268,7 +268,7 @@ class Balloon {
Uint8 menace_; // Amenaza que genera el globo Uint8 menace_; // Amenaza que genera el globo
Uint32 counter_ = 0; // Contador interno Uint32 counter_ = 0; // Contador interno
float game_tempo_; // Multiplicador de tempo del juego float game_tempo_; // Multiplicador de tempo del juego
float movement_accumulator_ = 0.0f; // Acumulador para movimiento durante creación (deltaTime) float movement_accumulator_ = 0.0F; // Acumulador para movimiento durante creación (deltaTime)
Uint8 power_; // Poder que alberga el globo Uint8 power_; // Poder que alberga el globo
SDL_FRect play_area_; // Zona de movimiento del globo SDL_FRect play_area_; // Zona de movimiento del globo
Sound sound_; // Configuración de sonido del globo Sound sound_; // Configuración de sonido del globo
@@ -280,13 +280,13 @@ class Balloon {
// --- Animación y sonido --- // --- Animación y sonido ---
void setAnimation(); // Establece la animación correspondiente void setAnimation(); // Establece la animación correspondiente
void playBouncingSound(); // Reproduce el sonido de rebote void playBouncingSound() const; // Reproduce el sonido de rebote
void playPoppingSound(); // Reproduce el sonido de reventar void playPoppingSound() const; // Reproduce el sonido de reventar
// --- Movimiento y física --- // --- Movimiento y física ---
void handleHorizontalMovement(float deltaTime); // Maneja el movimiento horizontal (time-based) void handleHorizontalMovement(float delta_time); // Maneja el movimiento horizontal (time-based)
void handleVerticalMovement(float deltaTime); // Maneja el movimiento vertical (time-based) void handleVerticalMovement(float delta_time); // Maneja el movimiento vertical (time-based)
void applyGravity(float deltaTime); // Aplica la gravedad al objeto (time-based) void applyGravity(float delta_time); // Aplica la gravedad al objeto (time-based)
// --- Rebote --- // --- Rebote ---
void enableBounceEffect(); // Activa el efecto de rebote void enableBounceEffect(); // Activa el efecto de rebote
@@ -301,5 +301,5 @@ class Balloon {
void handleBottomCollision(); // Maneja la colisión inferior void handleBottomCollision(); // Maneja la colisión inferior
// --- Lógica de estado --- // --- Lógica de estado ---
void updateState(float deltaTime); // Actualiza los estados del globo (time-based) void updateState(float delta_time); // Actualiza los estados del globo (time-based)
}; };

View File

@@ -1,4 +1,4 @@
#include "balloon_formations.h" #include "balloon_formations.hpp"
#include <algorithm> // Para max, min, copy #include <algorithm> // Para max, min, copy
#include <array> // Para array #include <array> // Para array
@@ -11,10 +11,10 @@
#include <sstream> // Para basic_istringstream #include <sstream> // Para basic_istringstream
#include <string> // Para string, char_traits, allocator, operator==, stoi, getline, operator<=>, basic_string #include <string> // Para string, char_traits, allocator, operator==, stoi, getline, operator<=>, basic_string
#include "asset.h" // Para Asset #include "asset.hpp" // Para Asset
#include "balloon.h" // Para Balloon #include "balloon.hpp" // Para Balloon
#include "param.h" // Para Param, ParamGame, param #include "param.hpp" // Para Param, ParamGame, param
#include "utils.h" // Para Zone, BLOCK #include "utils.hpp" // Para Zone, BLOCK
void BalloonFormations::initFormations() { void BalloonFormations::initFormations() {
// Calcular posiciones base // Calcular posiciones base
@@ -235,10 +235,10 @@ void BalloonFormations::createFloaterVariants() {
#ifdef _DEBUG #ifdef _DEBUG
void BalloonFormations::addTestFormation() { void BalloonFormations::addTestFormation() {
std::vector<SpawnParams> test_params = { std::vector<SpawnParams> test_params = {
{10, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SMALL, 3.334f}, // 200 frames ÷ 60fps = 3.334s {10, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SMALL, 3.334F}, // 200 frames ÷ 60fps = 3.334s
{50, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::MEDIUM, 3.334f}, // 200 frames ÷ 60fps = 3.334s {50, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::MEDIUM, 3.334F}, // 200 frames ÷ 60fps = 3.334s
{90, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::LARGE, 3.334f}, // 200 frames ÷ 60fps = 3.334s {90, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::LARGE, 3.334F}, // 200 frames ÷ 60fps = 3.334s
{140, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::EXTRALARGE, 3.334f}}; // 200 frames ÷ 60fps = 3.334s {140, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::EXTRALARGE, 3.334F}}; // 200 frames ÷ 60fps = 3.334s
formations_.at(99) = Formation(test_params); formations_.at(99) = Formation(test_params);
} }

View File

@@ -1,14 +1,14 @@
#pragma once #pragma once
#include <algorithm> // Para copy, max
#include <cstddef> // Para size_t #include <cstddef> // Para size_t
#include <iterator> // Para pair
#include <map> // Para map #include <map> // Para map
#include <optional> // Para optional #include <optional> // Para optional
#include <string> // Para string #include <string> // Para string
#include <utility> // Para pair #include <utility> // Para pair
#include <vector> // Para vector #include <vector> // Para vector
#include "balloon.h" // Para Balloon #include "balloon.hpp" // for Balloon
// --- Clase BalloonFormations --- // --- Clase BalloonFormations ---
class BalloonFormations { class BalloonFormations {
@@ -20,7 +20,7 @@ class BalloonFormations {
float vel_x = 0.0F; // Velocidad inicial en el eje X float vel_x = 0.0F; // Velocidad inicial en el eje X
Balloon::Type type = Balloon::Type::BALLOON; // Tipo de globo Balloon::Type type = Balloon::Type::BALLOON; // Tipo de globo
Balloon::Size size = Balloon::Size::SMALL; // Tamaño de globo Balloon::Size size = Balloon::Size::SMALL; // Tamaño de globo
float creation_counter = 0.0f; // Temporizador para la creación del globo float creation_counter = 0.0F; // Temporizador para la creación del globo
// Constructor por defecto // Constructor por defecto
SpawnParams() = default; SpawnParams() = default;
@@ -82,8 +82,8 @@ class BalloonFormations {
private: private:
// --- Constantes --- // --- Constantes ---
static constexpr int BALLOON_SPAWN_HEIGHT = 208; // Altura desde el suelo en la que aparecen los globos static constexpr int BALLOON_SPAWN_HEIGHT = 208; // Altura desde el suelo en la que aparecen los globos
static constexpr float CREATION_TIME = 5.0f; // Tiempo base de creación de los globos en segundos (300 frames ÷ 60fps = 5.0s) static constexpr float CREATION_TIME = 5.0F; // Tiempo base de creación de los globos en segundos (300 frames ÷ 60fps = 5.0s)
static constexpr float DEFAULT_CREATION_TIME = 3.334f; // Tiempo base de creación de los globos en segundos (200 frames ÷ 60fps = 3.334s) static constexpr float DEFAULT_CREATION_TIME = 3.334F; // Tiempo base de creación de los globos en segundos (200 frames ÷ 60fps = 3.334s)
// --- Variables --- // --- Variables ---
std::vector<Formation> formations_; // Vector con todas las formaciones disponibles std::vector<Formation> formations_; // Vector con todas las formaciones disponibles

View File

@@ -1,19 +1,19 @@
#include "balloon_manager.h" #include "balloon_manager.hpp"
#include <algorithm> // Para remove_if #include <algorithm> // Para remove_if
#include <array> #include <array>
#include <cstdlib> // Para rand #include <cstdlib> // Para rand
#include <numeric> // Para accumulate #include <numeric> // Para accumulate
#include "balloon.h" // Para Balloon, Balloon::SCORE.at( )ALLOON_VELX... #include "balloon.hpp" // Para Balloon, Balloon::SCORE.at( )ALLOON_VELX...
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma... #include "balloon_formations.hpp" // Para BalloonFormationParams, BalloonForma...
#include "color.h" // Para Zone, Color, flash_color #include "color.hpp" // Para Zone, Color, flash_color
#include "explosions.h" // Para Explosions #include "explosions.hpp" // Para Explosions
#include "param.h" // Para Param, ParamGame, param #include "param.hpp" // Para Param, ParamGame, param
#include "resource.h" // Para Resource #include "resource.hpp" // Para Resource
#include "screen.h" // Para Screen #include "screen.hpp" // Para Screen
#include "stage_interface.h" // Para IStageInfo #include "stage_interface.hpp" // Para IStageInfo
#include "utils.h" #include "utils.hpp"
// Constructor // Constructor
BalloonManager::BalloonManager(IStageInfo* stage_info) BalloonManager::BalloonManager(IStageInfo* stage_info)
@@ -63,12 +63,12 @@ void BalloonManager::init() {
} }
// Actualiza (time-based) // Actualiza (time-based)
void BalloonManager::update(float deltaTime) { void BalloonManager::update(float delta_time) {
for (const auto& balloon : balloons_) { for (const auto& balloon : balloons_) {
balloon->update(deltaTime); balloon->update(delta_time);
} }
updateBalloonDeployCounter(deltaTime); updateBalloonDeployCounter(delta_time);
explosions_->update(deltaTime); explosions_->update(delta_time);
} }
// Renderiza los objetos // Renderiza los objetos
@@ -82,7 +82,7 @@ void BalloonManager::render() {
// Crea una formación de globos // Crea una formación de globos
void BalloonManager::deployRandomFormation(int stage) { void BalloonManager::deployRandomFormation(int stage) {
// Solo despliega una formación enemiga si el timer ha llegado a cero // Solo despliega una formación enemiga si el timer ha llegado a cero
if (balloon_deploy_counter_ <= 0.0f) { if (balloon_deploy_counter_ <= 0.0F) {
// En este punto se decide entre crear una powerball o una formación enemiga // En este punto se decide entre crear una powerball o una formación enemiga
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) { if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
createPowerBall(); // Crea una powerball createPowerBall(); // Crea una powerball
@@ -114,7 +114,7 @@ void BalloonManager::deployRandomFormation(int stage) {
.size = balloon.size, .size = balloon.size,
.vel_x = balloon.vel_x, .vel_x = balloon.vel_x,
.game_tempo = balloon_speed_, .game_tempo = balloon_speed_,
.creation_counter = creation_time_enabled_ ? balloon.creation_counter : 0.0f}; .creation_counter = creation_time_enabled_ ? balloon.creation_counter : 0.0F};
createBalloon(config); createBalloon(config);
} }
@@ -158,14 +158,15 @@ void BalloonManager::deployFormation(int formation_id, float y) {
// Vacia del vector de globos los globos que ya no sirven // Vacia del vector de globos los globos que ya no sirven
void BalloonManager::freeBalloons() { void BalloonManager::freeBalloons() {
auto result = std::ranges::remove_if(balloons_, [](const auto& balloon) { return !balloon->isEnabled(); }); std::erase_if(balloons_, [](const auto& balloon) {
balloons_.erase(result.begin(), balloons_.end()); return !balloon->isEnabled();
});
} }
// Actualiza el timer de despliegue de globos (time-based) // Actualiza el timer de despliegue de globos (time-based)
void BalloonManager::updateBalloonDeployCounter(float deltaTime) { void BalloonManager::updateBalloonDeployCounter(float delta_time) {
// DeltaTime en segundos - timer decrementa hasta llegar a cero // DeltaTime en segundos - timer decrementa hasta llegar a cero
balloon_deploy_counter_ -= deltaTime; balloon_deploy_counter_ -= delta_time;
} }
// Indica si se puede crear una powerball // Indica si se puede crear una powerball
@@ -194,40 +195,40 @@ auto BalloonManager::createBalloon(Balloon::Config config) -> std::shared_ptr<Ba
} }
// Crea un globo a partir de otro globo // Crea un globo a partir de otro globo
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& balloon, const std::string& direction) { void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& parent_balloon, const std::string& direction) {
if (can_deploy_balloons_) { if (can_deploy_balloons_) {
// Calcula parametros // Calcula parametros
const int PARENT_HEIGHT = balloon->getHeight(); const int PARENT_HEIGHT = parent_balloon->getHeight();
const int CHILD_HEIGHT = Balloon::WIDTH.at(static_cast<int>(balloon->getSize()) - 1); const int CHILD_HEIGHT = Balloon::WIDTH.at(static_cast<size_t>(parent_balloon->getSize()) - 1);
const int CHILD_WIDTH = CHILD_HEIGHT; const int CHILD_WIDTH = CHILD_HEIGHT;
const float X = direction == "LEFT" ? balloon->getPosX() + (balloon->getWidth() / 3) : balloon->getPosX() + (2 * (balloon->getWidth() / 3)); const float X = direction == "LEFT" ? parent_balloon->getPosX() + (parent_balloon->getWidth() / 3) : parent_balloon->getPosX() + (2 * (parent_balloon->getWidth() / 3));
const float MIN_X = play_area_.x; const float MIN_X = play_area_.x;
const float MAX_X = play_area_.w - CHILD_WIDTH; const float MAX_X = play_area_.w - CHILD_WIDTH;
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 = parent_balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
.type = balloon->getType(), .type = parent_balloon->getType(),
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1), .size = static_cast<Balloon::Size>(static_cast<int>(parent_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_,
.creation_counter = 0}; .creation_counter = 0};
// Crea el globo // Crea el globo hijo
auto b = createBalloon(config); auto child_balloon = createBalloon(config);
// Configura el globo hijo
if (child_balloon != nullptr) {
// Establece parametros // Establece parametros
constexpr float VEL_Y_BALLOON_PER_S = -150.0F; constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
switch (b->getType()) { switch (child_balloon->getType()) {
case Balloon::Type::BALLOON: { case Balloon::Type::BALLOON: {
b->setVelY(VEL_Y_BALLOON_PER_S); child_balloon->setVelY(VEL_Y_BALLOON_PER_S);
break; break;
} }
case Balloon::Type::FLOATER: { case Balloon::Type::FLOATER: {
const float MODIFIER = (rand() % 2 == 0) ? 1.0F : 1.0F; child_balloon->setVelY(Balloon::VELX_NEGATIVE * 2.0F);
b->setVelY(Balloon::VELX_NEGATIVE * 2.0F * MODIFIER);
(rand() % 2 == 0) ? b->alterVelX(1.0F) : b->alterVelX(1.0F);
break; break;
} }
default: default:
@@ -235,8 +236,9 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& balloon,
} }
// Herencia de estados // Herencia de estados
if (balloon->isStopped()) { b->stop(); } if (parent_balloon->isStopped()) { child_balloon->stop(); }
if (balloon->isUsingReversedColor()) { b->useReverseColor(); } if (parent_balloon->isUsingReversedColor()) { child_balloon->useReverseColor(); }
}
} }
} }

View File

@@ -2,33 +2,33 @@
#include <SDL3/SDL.h> // Para SDL_FRect #include <SDL3/SDL.h> // Para SDL_FRect
#include <algorithm> // Para max
#include <array> // Para array #include <array> // Para array
#include <list> // Para list
#include <memory> // Para shared_ptr, unique_ptr #include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string #include <string> // Para basic_string, string
#include <vector> // Para vector #include <vector> // Para vector
#include "balloon.h" // Para BALLOON_SPEED, Balloon, Balloon::Size (ptr only), Balloon::Type (ptr only) #include "balloon.hpp" // for Balloon
#include "balloon_formations.h" // Para BalloonFormations #include "balloon_formations.hpp" // for BalloonFormations
#include "explosions.h" // Para Explosions #include "explosions.hpp" // for Explosions
#include "param.h" // Para Param, ParamGame, param #include "param.hpp" // for Param, ParamGame, param
#include "stage_interface.h" // Para IStageInfo #include "utils.hpp" // for Zone
#include "utils.h" // Para Zone
class IStageInfo;
class Texture; class Texture;
// --- Types --- // --- Types ---
using Balloons = std::vector<std::shared_ptr<Balloon>>; using Balloons = std::list<std::shared_ptr<Balloon>>;
// --- Clase BalloonManager: gestiona todos los globos del juego --- // --- Clase BalloonManager: gestiona todos los globos del juego ---
class BalloonManager { class BalloonManager {
public: public:
// --- Constructor y destructor --- // --- Constructor y destructor ---
BalloonManager(IStageInfo *stage_info); BalloonManager(IStageInfo* stage_info);
~BalloonManager() = default; ~BalloonManager() = default;
// --- Métodos principales --- // --- Métodos principales ---
void update(float deltaTime); // Actualiza el estado de los globos (time-based) void update(float delta_time); // Actualiza el estado de los globos (time-based)
void render(); // Renderiza los globos en pantalla void render(); // Renderiza los globos en pantalla
// --- Gestión de globos --- // --- Gestión de globos ---
@@ -41,7 +41,7 @@ class BalloonManager {
// --- Creación de globos --- // --- Creación de globos ---
auto createBalloon(Balloon::Config config) -> std::shared_ptr<Balloon>; // Crea un nuevo globo auto createBalloon(Balloon::Config config) -> std::shared_ptr<Balloon>; // Crea un nuevo globo
void createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction); // Crea un globo a partir de otro void createChildBalloon(const std::shared_ptr<Balloon>& balloon, const std::string& direction); // Crea un globo a partir de otro
void createPowerBall(); // Crea una PowerBall void createPowerBall(); // Crea una PowerBall
void createTwoBigBalloons(); // Crea dos globos grandes void createTwoBigBalloons(); // Crea dos globos grandes
@@ -49,13 +49,13 @@ class BalloonManager {
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based) void updateBalloonDeployCounter(float delta_time); // Actualiza el contador de despliegue (time-based)
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
// --- Manipulación de globos existentes --- // --- Manipulación de globos existentes ---
auto popBalloon(const std::shared_ptr<Balloon> &balloon) -> int; // Explosiona un globo, creando otros si aplica auto popBalloon(const std::shared_ptr<Balloon>& balloon) -> int; // Explosiona un globo, creando otros si aplica
auto destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int; // Explosiona un globo sin crear otros auto destroyBalloon(std::shared_ptr<Balloon>& balloon) -> int; // Explosiona un globo sin crear otros
auto destroyAllBalloons() -> int; // Destruye todos los globos auto destroyAllBalloons() -> int; // Destruye todos los globos
void stopAllBalloons(); // Detiene el movimiento de los globos void stopAllBalloons(); // Detiene el movimiento de los globos
void startAllBalloons(); // Reactiva el movimiento de los globos void startAllBalloons(); // Reactiva el movimiento de los globos
@@ -77,14 +77,14 @@ class BalloonManager {
// --- Getters --- // --- Getters ---
auto getMenace() -> int; // Obtiene el nivel de amenaza generado por los globos auto getMenace() -> int; // Obtiene el nivel de amenaza generado por los globos
[[nodiscard]] auto getBalloonSpeed() const -> float { return balloon_speed_; } [[nodiscard]] auto getBalloonSpeed() const -> float { return balloon_speed_; }
auto getBalloons() -> Balloons & { return balloons_; } auto getBalloons() -> Balloons& { return balloons_; }
[[nodiscard]] auto getNumBalloons() const -> int { return balloons_.size(); } [[nodiscard]] auto getNumBalloons() const -> int { return balloons_.size(); }
private: private:
// --- Constantes --- // --- Constantes ---
static constexpr float DEFAULT_BALLOON_DEPLOY_DELAY = 5.0f; // 300 frames = 5 segundos static constexpr float DEFAULT_BALLOON_DEPLOY_DELAY = 5.0F; // 300 frames = 5 segundos
static constexpr float POWERBALL_DEPLOY_DELAY = 0.167f; // 10 frames = 0.167 segundos static constexpr float POWERBALL_DEPLOY_DELAY = 0.167F; // 10 frames = 0.167 segundos
static constexpr float BALLOON_POP_DELAY = 0.333f; // 20 frames = 0.333 segundos static constexpr float BALLOON_POP_DELAY = 0.333F; // 20 frames = 0.333 segundos
// --- Objetos y punteros --- // --- Objetos y punteros ---
Balloons balloons_; // Vector con los globos activos Balloons balloons_; // Vector con los globos activos
@@ -94,7 +94,7 @@ class BalloonManager {
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Texturas de explosiones std::vector<std::shared_ptr<Texture>> explosions_textures_; // Texturas de explosiones
std::vector<std::vector<std::string>> balloon_animations_; // Animaciones de los globos std::vector<std::vector<std::string>> balloon_animations_; // Animaciones de los globos
std::vector<std::vector<std::string>> explosions_animations_; // Animaciones de las explosiones std::vector<std::vector<std::string>> explosions_animations_; // Animaciones de las explosiones
IStageInfo *stage_info_; // Informacion de la pantalla actual IStageInfo* stage_info_; // Informacion de la pantalla actual
// --- Variables de estado --- // --- Variables de estado ---
SDL_FRect play_area_ = param.game.play_area.rect; SDL_FRect play_area_ = param.game.play_area.rect;

View File

@@ -1,11 +1,10 @@
#include "bullet.h" #include "bullet.hpp"
#include <memory> // Para allocator, unique_ptr, make_unique #include <memory> // Para unique_ptr, make_unique
#include <string> // Para char_traits, basic_string, operator+, string #include <string> // Para basic_string, string
#include "param.h" // Para Param, ParamGame, param #include "param.hpp" // Para Param, ParamGame, param
#include "player.h" // Para Player::Id #include "resource.hpp" // Para Resource
#include "resource.h" // Para Resource
// Constructor // Constructor
Bullet::Bullet(float x, float y, Type type, Color color, int owner) Bullet::Bullet(float x, float y, Type type, Color color, int owner)
@@ -79,20 +78,20 @@ void Bullet::render() {
} }
// Actualiza el estado del objeto // Actualiza el estado del objeto
auto Bullet::update(float deltaTime) -> MoveStatus { auto Bullet::update(float delta_time) -> MoveStatus {
sprite_->update(deltaTime); sprite_->update(delta_time);
return move(deltaTime); return move(delta_time);
} }
// Implementación del movimiento usando MoveStatus // Implementación del movimiento usando MoveStatus
auto Bullet::move(float deltaTime) -> MoveStatus { auto Bullet::move(float delta_time) -> MoveStatus {
pos_x_ += vel_x_ * deltaTime; pos_x_ += vel_x_ * delta_time;
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 MoveStatus::OUT; return MoveStatus::OUT;
} }
pos_y_ += VEL_Y * deltaTime; pos_y_ += VEL_Y * delta_time;
if (pos_y_ < param.game.play_area.rect.y - HEIGHT) { if (pos_y_ < param.game.play_area.rect.y - HEIGHT) {
disable(); disable();
return MoveStatus::OUT; return MoveStatus::OUT;

View File

@@ -5,8 +5,8 @@
#include <memory> // Para unique_ptr #include <memory> // Para unique_ptr
#include <string> // Para string #include <string> // Para string
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.hpp" // Para AnimatedSprite
#include "utils.h" // Para Circle #include "utils.hpp" // Para Circle
// --- Clase Bullet: representa una bala del jugador --- // --- Clase Bullet: representa una bala del jugador ---
class Bullet { class Bullet {
@@ -41,7 +41,7 @@ class Bullet {
// --- Métodos principales --- // --- Métodos principales ---
void render(); // Dibuja la bala en pantalla void render(); // Dibuja la bala en pantalla
auto update(float deltaTime) -> MoveStatus; // Actualiza el estado del objeto (time-based) auto update(float delta_time) -> MoveStatus; // Actualiza el estado del objeto (time-based)
void disable(); // Desactiva la bala void disable(); // Desactiva la bala
// --- Getters --- // --- Getters ---
@@ -70,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) -> MoveStatus; // Mueve la bala y devuelve su estado (time-based) auto move(float delta_time) -> MoveStatus; // Mueve la bala y devuelve su estado (time-based)
static auto calculateVelocity(Type 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(Type type, Color color) -> std::string; // Construye el string de animación static auto buildAnimationString(Type type, Color color) -> std::string; // Construye el string de animación
}; };

104
source/bullet_manager.cpp Normal file
View File

@@ -0,0 +1,104 @@
#include "bullet_manager.hpp"
#include <algorithm> // Para remove_if
#include <utility>
#include "bullet.hpp" // Para Bullet
#include "param.hpp" // Para Param, ParamGame, param
#include "utils.hpp" // Para Circle, Zone
// Constructor
BulletManager::BulletManager()
: play_area_(param.game.play_area.rect) {
}
// Actualiza el estado de todas las balas
void BulletManager::update(float delta_time) {
for (auto& bullet : bullets_) {
if (bullet->isEnabled()) {
processBulletUpdate(bullet, delta_time);
}
}
}
// Renderiza todas las balas activas
void BulletManager::render() {
for (auto& bullet : bullets_) {
if (bullet->isEnabled()) {
bullet->render();
}
}
}
// Crea una nueva bala
void BulletManager::createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner) {
bullets_.emplace_back(std::make_shared<Bullet>(x, y, type, color, owner));
}
// Libera balas que ya no están habilitadas
void BulletManager::freeBullets() {
std::erase_if(bullets_, [](const std::shared_ptr<Bullet>& bullet) {
return !bullet->isEnabled();
});
}
// Elimina todas las balas
void BulletManager::clearAllBullets() {
bullets_.clear();
}
// Verifica colisiones de todas las balas
void BulletManager::checkCollisions() {
for (auto& bullet : bullets_) {
if (!bullet->isEnabled()) {
continue;
}
// Verifica colisión con Tabe
if (tabe_collision_callback_ && tabe_collision_callback_(bullet)) {
break; // Sale del bucle si hubo colisión
}
// Verifica colisión con globos
if (balloon_collision_callback_ && balloon_collision_callback_(bullet)) {
break; // Sale del bucle si hubo colisión
}
}
}
// Establece el callback para colisión con Tabe
void BulletManager::setTabeCollisionCallback(CollisionCallback callback) {
tabe_collision_callback_ = std::move(callback);
}
// Establece el callback para colisión con globos
void BulletManager::setBalloonCollisionCallback(CollisionCallback callback) {
balloon_collision_callback_ = std::move(callback);
}
// Establece el callback para balas fuera de límites
void BulletManager::setOutOfBoundsCallback(OutOfBoundsCallback callback) {
out_of_bounds_callback_ = std::move(callback);
}
// --- Métodos privados ---
// Procesa la actualización individual de una bala
void BulletManager::processBulletUpdate(const std::shared_ptr<Bullet>& bullet, float delta_time) {
auto status = bullet->update(delta_time);
// Si la bala salió de los límites, llama al callback
if (status == Bullet::MoveStatus::OUT && out_of_bounds_callback_) {
out_of_bounds_callback_(bullet);
}
}
// Verifica si la bala está fuera de los límites del área de juego
auto BulletManager::isBulletOutOfBounds(const std::shared_ptr<Bullet>& bullet) const -> bool {
auto collider = bullet->getCollider();
return (collider.x < play_area_.x ||
collider.x > play_area_.x + play_area_.w ||
collider.y < play_area_.y ||
collider.y > play_area_.y + play_area_.h);
}

76
source/bullet_manager.hpp Normal file
View File

@@ -0,0 +1,76 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FRect
#include <functional> // Para function
#include <list> // Para list
#include <memory> // Para shared_ptr
#include <vector> // Para vector
#include "bullet.hpp" // for Bullet
// --- Types ---
using Bullets = std::list<std::shared_ptr<Bullet>>;
// --- Clase BulletManager: gestiona todas las balas del juego ---
//
// Esta clase se encarga de la gestión completa de las balas del juego,
// incluyendo su creación, actualización, renderizado y colisiones.
//
// Funcionalidades principales:
// • Gestión del ciclo de vida: creación, actualización y destrucción de balas
// • Renderizado: dibuja todas las balas activas en pantalla
// • Detección de colisiones: mediante sistema de callbacks
// • Limpieza automática: elimina balas deshabilitadas del contenedor
// • Configuración flexible: permite ajustar parámetros de las balas
//
// La clase utiliza un sistema de callbacks para manejar las colisiones,
// permitiendo que la lógica específica del juego permanezca en Game.
class BulletManager {
public:
// --- Types para callbacks ---
using CollisionCallback = std::function<bool(const std::shared_ptr<Bullet>&)>;
using OutOfBoundsCallback = std::function<void(const std::shared_ptr<Bullet>&)>;
// --- Constructor y destructor ---
BulletManager();
~BulletManager() = default;
// --- Métodos principales ---
void update(float delta_time); // Actualiza el estado de las balas (time-based)
void render(); // Renderiza las balas en pantalla
// --- Gestión de balas ---
void createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner); // Crea una nueva bala
void freeBullets(); // Libera balas que ya no sirven
void clearAllBullets(); // Elimina todas las balas
// --- Detección de colisiones ---
void checkCollisions(); // Verifica colisiones de todas las balas
void setTabeCollisionCallback(CollisionCallback callback); // Establece callback para colisión con Tabe
void setBalloonCollisionCallback(CollisionCallback callback); // Establece callback para colisión con globos
void setOutOfBoundsCallback(OutOfBoundsCallback callback); // Establece callback para balas fuera de límites
// --- Configuración ---
void setPlayArea(SDL_FRect play_area) { play_area_ = play_area; }; // Define el área de juego
// --- Getters ---
auto getBullets() -> Bullets& { return bullets_; } // Obtiene referencia al vector de balas
[[nodiscard]] auto getNumBullets() const -> int { return bullets_.size(); } // Obtiene el número de balas activas
private:
// --- Objetos y punteros ---
Bullets bullets_; // Vector con las balas activas
// --- Variables de configuración ---
SDL_FRect play_area_; // Área de juego para límites
// --- Callbacks para colisiones ---
CollisionCallback tabe_collision_callback_; // Callback para colisión con Tabe
CollisionCallback balloon_collision_callback_; // Callback para colisión con globos
OutOfBoundsCallback out_of_bounds_callback_; // Callback para balas fuera de límites
// --- Métodos internos ---
void processBulletUpdate(const std::shared_ptr<Bullet>& bullet, float delta_time); // Procesa actualización individual
[[nodiscard]] auto isBulletOutOfBounds(const std::shared_ptr<Bullet>& bullet) const -> bool; // Verifica si la bala está fuera de límites
};

View File

@@ -1,5 +1,5 @@
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include "color.h" #include "color.hpp"
#include <cctype> // Para isxdigit #include <cctype> // Para isxdigit
#include <cmath> // Para sinf, fmaxf, fminf, M_PI, fmodf, roundf, fmod #include <cmath> // Para sinf, fmaxf, fminf, M_PI, fmodf, roundf, fmod
@@ -8,7 +8,7 @@
#include <string> // Para basic_string, stoi, string #include <string> // Para basic_string, stoi, string
// Método estático para crear Color desde string hexadecimal // Método estático para crear Color desde string hexadecimal
auto Color::fromHex(const std::string &hex_str) -> Color { auto Color::fromHex(const std::string& hex_str) -> Color {
std::string hex = hex_str; std::string hex = hex_str;
// Quitar '#' si existe // Quitar '#' si existe
@@ -43,7 +43,7 @@ auto Color::fromHex(const std::string &hex_str) -> Color {
} }
// Implementaciones de métodos estáticos de Color // Implementaciones de métodos estáticos de Color
constexpr auto Color::rgbToHsv(Color color) -> HSV { constexpr auto Color::RGB_TO_HSV(Color color) -> HSV {
float r = color.r / 255.0F; float r = color.r / 255.0F;
float g = color.g / 255.0F; float g = color.g / 255.0F;
float b = color.b / 255.0F; float b = color.b / 255.0F;
@@ -73,7 +73,7 @@ constexpr auto Color::rgbToHsv(Color color) -> HSV {
return {.h = h, .s = s, .v = v}; return {.h = h, .s = s, .v = v};
} }
constexpr auto Color::hsvToRgb(HSV hsv) -> Color { constexpr auto Color::HSV_TO_RGB(HSV hsv) -> Color {
float c = hsv.v * hsv.s; float c = hsv.v * hsv.s;
float x = c * (1 - std::abs(std::fmod(hsv.h / 60.0F, 2) - 1)); float x = c * (1 - std::abs(std::fmod(hsv.h / 60.0F, 2) - 1));
float m = hsv.v - c; float m = hsv.v - c;
@@ -117,7 +117,7 @@ constexpr auto Color::hsvToRgb(HSV hsv) -> Color {
// Implementaciones del namespace Colors // Implementaciones del namespace Colors
namespace Colors { namespace Colors {
// Obtiene un color del vector de colores imitando al Coche Fantástico // Obtiene un color del vector de colores imitando al Coche Fantástico
auto getColorLikeKnightRider(const std::vector<Color> &colors, int counter) -> Color { auto getColorLikeKnightRider(const std::vector<Color>& colors, int counter) -> Color {
int cycle_length = (colors.size() * 2) - 2; int cycle_length = (colors.size() * 2) - 2;
size_t n = counter % cycle_length; size_t n = counter % cycle_length;
@@ -133,7 +133,7 @@ auto getColorLikeKnightRider(const std::vector<Color> &colors, int counter) -> C
auto generateMirroredCycle(Color base, ColorCycleStyle style) -> Cycle { auto generateMirroredCycle(Color base, ColorCycleStyle style) -> Cycle {
Cycle result{}; Cycle result{};
HSV base_hsv = Color::rgbToHsv(base); HSV base_hsv = Color::RGB_TO_HSV(base);
for (size_t i = 0; i < CYCLE_SIZE; ++i) { for (size_t i = 0; i < CYCLE_SIZE; ++i) {
float t = static_cast<float>(i) / (CYCLE_SIZE - 1); // 0 → 1 float t = static_cast<float>(i) / (CYCLE_SIZE - 1); // 0 → 1
@@ -176,7 +176,7 @@ auto generateMirroredCycle(Color base, ColorCycleStyle style) -> Cycle {
.s = fminf(1.0F, fmaxf(0.0F, base_hsv.s + sat_shift)), .s = fminf(1.0F, fmaxf(0.0F, base_hsv.s + sat_shift)),
.v = fminf(1.0F, fmaxf(0.0F, base_hsv.v + val_shift))}; .v = fminf(1.0F, fmaxf(0.0F, base_hsv.v + val_shift))};
Color c = Color::hsvToRgb(adjusted); Color c = Color::HSV_TO_RGB(adjusted);
result[i] = c; result[i] = c;
result[(2 * CYCLE_SIZE) - 1 - i] = c; // espejo result[(2 * CYCLE_SIZE) - 1 - i] = c; // espejo
} }

View File

@@ -69,17 +69,17 @@ struct Color {
} }
// Método estático para crear Color desde string hexadecimal // Método estático para crear Color desde string hexadecimal
static auto fromHex(const std::string &hex_str) -> Color; static auto fromHex(const std::string& hex_str) -> Color;
// Conversiones de formato de color // Conversiones de formato de color
[[nodiscard]] constexpr static auto rgbToHsv(Color color) -> HSV; [[nodiscard]] constexpr static auto RGB_TO_HSV(Color color) -> HSV;
[[nodiscard]] constexpr static auto hsvToRgb(HSV hsv) -> Color; [[nodiscard]] constexpr static auto HSV_TO_RGB(HSV hsv) -> Color;
[[nodiscard]] constexpr auto IS_EQUAL_TO(const Color &other) const -> bool { [[nodiscard]] constexpr auto IS_EQUAL_TO(const Color& other) const -> bool {
return r == other.r && g == other.g && b == other.b && a == other.a; return r == other.r && g == other.g && b == other.b && a == other.a;
} }
[[nodiscard]] constexpr auto APPROACH_TO(const Color &target, int step = DEFAULT_APPROACH_STEP) const -> Color { [[nodiscard]] constexpr auto APPROACH_TO(const Color& target, int step = DEFAULT_APPROACH_STEP) const -> Color {
auto approach_component = [step](Uint8 current, Uint8 target_val) -> Uint8 { auto approach_component = [step](Uint8 current, Uint8 target_val) -> Uint8 {
if (std::abs(current - target_val) <= step) { if (std::abs(current - target_val) <= step) {
return target_val; return target_val;
@@ -95,6 +95,28 @@ struct Color {
return Color(new_r, new_g, new_b, new_a); return Color(new_r, new_g, new_b, new_a);
} }
// Interpolación lineal hacia otro color (t=0.0: this, t=1.0: target)
[[nodiscard]] constexpr auto LERP(const Color& target, float t) const -> Color {
// Asegurar que t esté en el rango [0.0, 1.0]
t = std::clamp(t, 0.0F, 1.0F);
// Interpolación lineal para cada componente
auto lerp_component = [t](Uint8 start, Uint8 end) -> Uint8 {
return static_cast<Uint8>(start + ((end - start) * t));
};
return Color(
lerp_component(r, target.r),
lerp_component(g, target.g),
lerp_component(b, target.b),
lerp_component(a, target.a));
}
// Sobrecarga para aceptar componentes RGBA directamente
[[nodiscard]] constexpr auto LERP(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, float t) const -> Color {
return LERP(Color(red, green, blue, alpha), t);
}
// Convierte el color a un entero de 32 bits en formato RGBA // Convierte el color a un entero de 32 bits en formato RGBA
[[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 { [[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 {
return (static_cast<Uint32>(r) << 24) | return (static_cast<Uint32>(r) << 24) |
@@ -134,6 +156,6 @@ constexpr Color PINK_SKY = Color(0XFF, 0X6B, 0X97);
constexpr Color GREEN_SKY = Color(0X00, 0X79, 0X6B); constexpr Color GREEN_SKY = Color(0X00, 0X79, 0X6B);
// --- Funciones --- // --- Funciones ---
auto getColorLikeKnightRider(const std::vector<Color> &colors, int counter) -> Color; auto getColorLikeKnightRider(const std::vector<Color>& colors, int counter) -> Color;
auto generateMirroredCycle(Color base, ColorCycleStyle style = ColorCycleStyle::SUBTLE_PULSE) -> Cycle; auto generateMirroredCycle(Color base, ColorCycleStyle style = ColorCycleStyle::SUBTLE_PULSE) -> Cycle;
} // namespace Colors } // namespace Colors

48
source/cooldown.hpp Normal file
View File

@@ -0,0 +1,48 @@
#pragma once
#include <algorithm> // Para std::max
class Cooldown {
public:
Cooldown(float first_delay_s = 0.0F, float repeat_delay_s = 0.0F)
: first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s) {}
// Llamar cada frame con delta en segundos (float)
void update(float delta_s) {
if (remaining_s_ <= 0.0F) {
remaining_s_ = 0.0F;
return;
}
remaining_s_ -= delta_s;
remaining_s_ = std::max(remaining_s_, 0.0F);
}
// Llamar cuando el input está activo. Devuelve true si debe ejecutarse la acción ahora.
auto tryConsumeOnHeld() -> bool {
if (remaining_s_ > 0.0F) {
return false;
}
float delay = held_before_ ? repeat_delay_s_ : first_delay_s_;
remaining_s_ = delay;
held_before_ = true;
return true;
}
// Llamar cuando el input se suelta
void onReleased() {
held_before_ = false;
remaining_s_ = 0.0F;
}
[[nodiscard]] auto empty() const -> bool { return remaining_s_ == 0.0F; }
// Fuerza un valor en segundos (útil para tests o resets)
void forceSet(float seconds) { remaining_s_ = seconds > 0.0F ? seconds : 0.0F; }
private:
float first_delay_s_;
float repeat_delay_s_;
float remaining_s_{0.0F};
bool held_before_{false};
};

View File

@@ -4,8 +4,8 @@
#include <array> #include <array>
#include "color.h" #include "color.hpp"
#include "ui/notifier.h" // Para Notifier::Position #include "ui/notifier.hpp" // Para Notifier::Position
#include "version.h" // Para Version::APP_NAME #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 ---

View File

@@ -1,25 +1,23 @@
#include "define_buttons.h" #include "define_buttons.hpp"
#include <algorithm> // Para __all_of_fn, all_of #include <algorithm> // Para __all_of_fn, all_of
#include <functional> // Para identity #include <memory> // Para unique_ptr, allocator, shared_ptr, operator==, make_unique
#include <memory> // Para allocator, unique_ptr, shared_ptr, make_unique, operator==
#include "color.h" // Para Color #include "input.hpp" // Para Input
#include "input.h" // Para Input #include "input_types.hpp" // Para InputAction
#include "input_types.h" // Para InputAction #include "lang.hpp" // Para getText
#include "lang.h" // Para getText #include "options.hpp" // Para Gamepad
#include "options.h" // Para Gamepad #include "param.hpp" // Para Param, param, ParamGame, ParamServiceMenu
#include "param.h" // Para Param, ParamGame, param #include "resource.hpp" // Para Resource
#include "resource.h" // Para Resource #include "ui/window_message.hpp" // Para WindowMessage
#include "ui/window_message.h" // Para WindowMessage #include "utils.hpp" // Para Zone
#include "utils.h" // Para Zone
DefineButtons::DefineButtons() DefineButtons::DefineButtons()
: input_(Input::get()) { : input_(Input::get()) {
clearButtons(); clearButtons();
auto gamepads = input_->getGamepads(); auto gamepads = input_->getGamepads();
for (const auto &gamepad : gamepads) { for (const auto& gamepad : gamepads) {
controller_names_.emplace_back(Input::getControllerName(gamepad)); controller_names_.emplace_back(Input::getControllerName(gamepad));
} }
@@ -63,7 +61,7 @@ void DefineButtons::update(float delta_time) {
} }
} }
void DefineButtons::handleEvents(const SDL_Event &event) { void DefineButtons::handleEvents(const SDL_Event& event) {
if (enabled_) { if (enabled_) {
switch (event.type) { switch (event.type) {
case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
@@ -81,7 +79,7 @@ void DefineButtons::handleEvents(const SDL_Event &event) {
} }
} }
auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool { auto DefineButtons::enable(Options::Gamepad* options_gamepad) -> bool {
if (options_gamepad != nullptr) { if (options_gamepad != nullptr) {
options_gamepad_ = options_gamepad; options_gamepad_ = options_gamepad;
enabled_ = true; enabled_ = true;
@@ -117,7 +115,7 @@ void DefineButtons::disable() {
} }
} }
void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event) { void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent& event) {
auto gamepad = input_->getGamepad(event.which); auto gamepad = input_->getGamepad(event.which);
if (!gamepad || gamepad != options_gamepad_->instance) { if (!gamepad || gamepad != options_gamepad_->instance) {
@@ -132,7 +130,7 @@ void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event)
} }
} }
void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) { void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent& event) {
auto gamepad = input_->getGamepad(event.which); auto gamepad = input_->getGamepad(event.which);
if (!gamepad || gamepad != options_gamepad_->instance) { if (!gamepad || gamepad != options_gamepad_->instance) {
@@ -182,8 +180,8 @@ void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) {
} }
} }
void DefineButtons::bindButtons(Options::Gamepad *options_gamepad) { void DefineButtons::bindButtons(Options::Gamepad* options_gamepad) {
for (const auto &button : buttons_) { for (const auto& button : buttons_) {
Input::bindGameControllerButton(options_gamepad->instance, button.action, static_cast<SDL_GamepadButton>(button.button)); Input::bindGameControllerButton(options_gamepad->instance, button.action, static_cast<SDL_GamepadButton>(button.button));
} }
@@ -200,13 +198,13 @@ void DefineButtons::incIndexButton() {
} }
auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool { auto DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) -> bool {
return std::ranges::all_of(buttons_, [button](const auto &b) { return std::ranges::all_of(buttons_, [button](const auto& b) {
return b.button != button; return b.button != button;
}); });
} }
auto DefineButtons::checkTriggerNotInUse(int trigger_button) -> bool { auto DefineButtons::checkTriggerNotInUse(int trigger_button) -> bool {
return std::ranges::all_of(buttons_, [trigger_button](const auto &b) { return std::ranges::all_of(buttons_, [trigger_button](const auto& b) {
return b.button != trigger_button; return b.button != trigger_button;
}); });
} }
@@ -234,7 +232,7 @@ void DefineButtons::checkEnd() {
// Solo marcar que ya mostramos el mensaje // Solo marcar que ya mostramos el mensaje
message_shown_ = true; message_shown_ = true;
message_timer_ = 0.0f; message_timer_ = 0.0F;
} }
} }

View File

@@ -8,8 +8,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "input.h" #include "input.hpp"
#include "ui/window_message.h" #include "ui/window_message.hpp"
namespace Options { namespace Options {
struct Gamepad; struct Gamepad;
@@ -37,8 +37,8 @@ class DefineButtons {
// --- Métodos principales --- // --- Métodos principales ---
void render(); void render();
void update(float delta_time); void update(float delta_time);
void handleEvents(const SDL_Event &event); void handleEvents(const SDL_Event& event);
auto enable(Options::Gamepad *options_gamepad) -> bool; auto enable(Options::Gamepad* options_gamepad) -> bool;
void disable(); void disable();
// --- Getters --- // --- Getters ---
@@ -48,18 +48,18 @@ class DefineButtons {
private: private:
// --- Constantes --- // --- Constantes ---
static constexpr float MESSAGE_DISPLAY_DURATION_S = 2.0f; // Cuánto tiempo mostrar el mensaje en segundos static constexpr float MESSAGE_DISPLAY_DURATION_S = 2.0F; // Cuánto tiempo mostrar el mensaje en segundos
// --- Objetos y punteros --- // --- Objetos y punteros ---
Input *input_ = nullptr; // Entrada del usuario Input* input_ = nullptr; // Entrada del usuario
Options::Gamepad *options_gamepad_ = nullptr; // Opciones del gamepad Options::Gamepad* options_gamepad_ = nullptr; // Opciones del gamepad
std::unique_ptr<WindowMessage> window_message_; // Mensaje de ventana std::unique_ptr<WindowMessage> window_message_; // Mensaje de ventana
// --- Variables de estado --- // --- Variables de estado ---
std::vector<Button> buttons_; // Lista de botones std::vector<Button> buttons_; // Lista de botones
std::vector<std::string> controller_names_; // Nombres de los controladores std::vector<std::string> controller_names_; // Nombres de los controladores
size_t index_button_ = 0; // Índice del botón seleccionado size_t index_button_ = 0; // Índice del botón seleccionado
float message_timer_ = 0.0f; // Timer en segundos para el mensaje float message_timer_ = 0.0F; // Timer en segundos para el mensaje
bool enabled_ = false; // Flag para indicar si está activo bool enabled_ = false; // Flag para indicar si está activo
bool finished_ = false; // Flag para indicar si ha terminado bool finished_ = false; // Flag para indicar si ha terminado
bool closing_ = false; // Flag para indicar que está cerrando bool closing_ = false; // Flag para indicar que está cerrando
@@ -69,9 +69,9 @@ class DefineButtons {
// --- Métodos internos --- // --- Métodos internos ---
void incIndexButton(); void incIndexButton();
void doControllerButtonDown(const SDL_GamepadButtonEvent &event); void doControllerButtonDown(const SDL_GamepadButtonEvent& event);
void doControllerAxisMotion(const SDL_GamepadAxisEvent &event); void doControllerAxisMotion(const SDL_GamepadAxisEvent& event);
void bindButtons(Options::Gamepad *options_gamepad); void bindButtons(Options::Gamepad* options_gamepad);
auto checkButtonNotInUse(SDL_GamepadButton button) -> bool; auto checkButtonNotInUse(SDL_GamepadButton button) -> bool;
auto checkTriggerNotInUse(int trigger_button) -> bool; auto checkTriggerNotInUse(int trigger_button) -> bool;
void clearButtons(); void clearButtons();

View File

@@ -1,16 +1,18 @@
#include "demo.h" #include "demo.hpp"
#include <SDL3/SDL.h> // Para SDL_IOStream, SDL_IOFromConstMem, SDL_IOFromFile, SDL_ReadIO, SDL_WriteIO, SDL_CloseIO #include <SDL3/SDL.h> // Para SDL_IOStream, SDL_IOFromConstMem, SDL_IOFromFile, SDL_ReadIO, SDL_WriteIO, SDL_CloseIO
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "resource_helper.h" // Para ResourceHelper #include "resource_helper.hpp" // Para ResourceHelper
#include "utils.h" // Para printWithDots, getFileName #include "ui/logger.hpp"
#include "utils.hpp" // Para printWithDots, getFileName
// Carga el fichero de datos para la demo // Carga el fichero de datos para la demo
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData { auto loadDemoDataFromFile(const std::string& file_path) -> DemoData {
DemoData dd; DemoData dd;
SDL_IOStream *file = nullptr; SDL_IOStream* file = nullptr;
// Intentar cargar desde ResourceHelper primero // Intentar cargar desde ResourceHelper primero
auto resource_data = ResourceHelper::loadFile(file_path); auto resource_data = ResourceHelper::loadFile(file_path);
@@ -25,7 +27,7 @@ auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
throw std::runtime_error("Fichero no encontrado: " + file_path); throw std::runtime_error("Fichero no encontrado: " + file_path);
} }
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]"); Logger::dots("DemoData : ", getFileName(file_path), "[ LOADED ]");
// Lee todos los datos del fichero y los deja en el destino // Lee todos los datos del fichero y los deja en el destino
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {
@@ -42,13 +44,13 @@ auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
#ifdef RECORDING #ifdef RECORDING
// Guarda el fichero de datos para la demo // Guarda el fichero de datos para la demo
bool saveDemoFile(const std::string &file_path, const DemoData &dd) { bool saveDemoFile(const std::string& file_path, const DemoData& dd) {
auto success = true; auto success = true;
auto file = SDL_IOFromFile(file_path.c_str(), "w+b"); auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
if (file) { if (file) {
// Guarda los datos // Guarda los datos
for (const auto &data : dd) { for (const auto& data : dd) {
if (SDL_WriteIO(file, &data, sizeof(DemoKeys)) != sizeof(DemoKeys)) { 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()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
success = false; success = false;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL3/SDL.h> // Para Uint8 #include <SDL3/SDL.h> // Para Uint8
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,4 +1,4 @@
#include "difficulty.h" #include "difficulty.hpp"
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,48 +1,50 @@
// IWYU pragma: no_include <bits/chrono.h> // IWYU pragma: no_include <bits/chrono.h>
#include "director.h" #include "director.hpp"
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_SetLogPriority, SDL_LogPriority, SDL_Quit #include <SDL3/SDL.h> // Para SDL_SetLogPriority, SDL_LogCategory, SDL_LogPriority, SDL_Quit
#include <cstdlib> // Para srand, exit, rand, EXIT_FAILURE #include <cstdlib> // Para srand, exit, rand, EXIT_FAILURE
#include <ctime> // Para time #include <ctime> // Para time
#include <iostream> // Para basic_ostream, operator<<, cerr, endl #include <filesystem> // Para path, absolute
#include <iostream> // Para basic_ostream, operator<<, cerr
#include <memory> // Para make_unique, unique_ptr #include <memory> // Para make_unique, unique_ptr
#include <span> // Para span #include <span> // Para span
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include <string> // Para allocator, char_traits, operator==, string, basic_string, operator+ #include <string> // Para allocator, basic_string, char_traits, operator+, string, operator==
#include "asset.h" // Para Asset #include "asset.hpp" // Para Asset
#include "audio.h" // Para Audio #include "audio.hpp" // Para Audio
#include "input.h" // Para Input #include "input.hpp" // Para Input
#include "lang.h" // Para setLanguage #include "lang.hpp" // Para setLanguage
#include "manage_hiscore_table.h" // Para ManageHiScoreTable #include "manage_hiscore_table.hpp" // Para ManageHiScoreTable
#include "options.h" // Para loadFromFile, saveToFile, Settings, settings, setConfigFile, setControllersFile #include "options.hpp" // Para Settings, loadFromFile, saveToFile, settings, setConfigFile, setControllersFile
#include "param.h" // Para loadParamsFromFile #include "param.hpp" // Para loadParamsFromFile
#include "player.h" // Para Player #include "player.hpp" // Para Player
#include "resource.h" // Para Resource #include "resource.hpp" // Para Resource
#include "resource_helper.h" // Para ResourceHelper #include "resource_helper.hpp" // Para initializeResourceSystem
#include "screen.h" // Para Screen #include "screen.hpp" // Para Screen
#include "section.hpp" // Para Name, Options, name, options, AttractMode, attract_mode #include "section.hpp" // Para Name, Options, name, options, AttractMode, attract_mode
#include "sections/credits.h" // Para Credits #include "sections/credits.hpp" // Para Credits
#include "sections/game.h" // Para Game #include "sections/game.hpp" // Para Game
#include "sections/hiscore_table.h" // Para HiScoreTable #include "sections/hiscore_table.hpp" // Para HiScoreTable
#include "sections/instructions.h" // Para Instructions #include "sections/instructions.hpp" // Para Instructions
#include "sections/intro.h" // Para Intro #include "sections/intro.hpp" // Para Intro
#include "sections/logo.h" // Para Logo #include "sections/logo.hpp" // Para Logo
#include "sections/title.h" // Para Title #include "sections/title.hpp" // Para Title
#include "shutdown.h" // Para resultToString, shutdownSystem, ShutdownResult #include "shutdown.hpp" // Para resultToString, shutdownSystem, ShutdownResult
#include "system_utils.h" // Para createApplicationFolder, resultToString, Result #include "system_utils.hpp" // Para createApplicationFolder, resultToString, Result
#include "ui/notifier.h" // Para Notifier #include "ui/logger.hpp" // Para section, put
#include "ui/service_menu.h" // Para ServiceMenu #include "ui/notifier.hpp" // Para Notifier
#include "utils.h" // Para Overrides, overrides, getPath #include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.hpp" // Para Overrides, overrides
// Constructor // Constructor
Director::Director(int argc, std::span<char *> argv) { Director::Director(int argc, std::span<char*> argv) {
#ifdef RECORDING #ifdef RECORDING
Section::name = Section::Name::GAME; Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P; Section::options = Section::Options::GAME_PLAY_1P;
#elif _DEBUG #elif _DEBUG
Section::name = Section::Name::TITLE; Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P; Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME #else // NORMAL GAME
Section::name = Section::Name::LOGO; Section::name = Section::Name::LOGO;
@@ -54,7 +56,7 @@ Director::Director(int argc, std::span<char *> argv) {
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR); SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Game start"); Logger::put("Game start\n");
// Inicia la semilla aleatoria usando el tiempo actual en segundos // Inicia la semilla aleatoria usando el tiempo actual en segundos
std::srand(static_cast<unsigned int>(std::time(nullptr))); std::srand(static_cast<unsigned int>(std::time(nullptr)));
@@ -71,7 +73,7 @@ Director::Director(int argc, std::span<char *> argv) {
Director::~Director() { Director::~Director() {
close(); close();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!"); Logger::put("\nBye!");
} }
// Inicializa todo // Inicializa todo
@@ -79,14 +81,29 @@ void Director::init() {
// Configuración inicial de parametros // Configuración inicial de parametros
Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos
// Determinar ruta del pack según la plataforma
#ifdef MACOS_BUNDLE #ifdef MACOS_BUNDLE
ResourceHelper::initializeResourceSystem(executable_path_ + "../Resources/resources.pack"); std::string pack_path = executable_path_ + "../Resources/resources.pack";
#else #else
ResourceHelper::initializeResourceSystem(executable_path_ + "resources.pack"); std::string pack_path = executable_path_ + "resources.pack";
#endif #endif
// Inicializar sistema de recursos con o sin fallback según el tipo de build
#ifdef RELEASE_BUILD
// Release: Sin fallback - Solo resources.pack (estricto)
ResourceHelper::initializeResourceSystem(pack_path, false);
#else
// Desarrollo: Con fallback - Puede usar data/ si falta el pack (flexible)
ResourceHelper::initializeResourceSystem(pack_path, true);
#endif
loadAssets(); // Crea el índice de archivos loadAssets(); // Crea el índice de archivos
Logger::section("INIT INPUT");
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
Options::setConfigFile(Asset::get()->get("config.txt")); // Establece el fichero de configuración
Logger::section("INIT CONFIG");
Options::setConfigFile(Asset::get()->get("config_v2.txt")); // Establece el fichero de configuración
Options::setControllersFile(Asset::get()->get("controllers.json")); // Establece el fichero de configuración de mandos Options::setControllersFile(Asset::get()->get("controllers.json")); // Establece el fichero de configuración de mandos
Options::loadFromFile(); // Carga el archivo de configuración Options::loadFromFile(); // Carga el archivo de configuración
loadParams(); // Carga los parámetros del programa loadParams(); // Carga los parámetros del programa
@@ -94,8 +111,14 @@ void Director::init() {
// Inicialización de subsistemas principales // Inicialización de subsistemas principales
Lang::setLanguage(Options::settings.language); // Carga el archivo de idioma Lang::setLanguage(Options::settings.language); // Carga el archivo de idioma
Logger::section("INIT VIDEO");
Screen::init(); // Inicializa la pantalla y el sistema de renderizado Screen::init(); // Inicializa la pantalla y el sistema de renderizado
Logger::section("INIT AUDIO");
Audio::init(); // Activa el sistema de audio Audio::init(); // Activa el sistema de audio
Logger::section("INIT RESOURCES");
#ifdef _DEBUG #ifdef _DEBUG
Resource::init(Resource::LoadingMode::PRELOAD); // Inicializa el sistema de gestión de recursos Resource::init(Resource::LoadingMode::PRELOAD); // Inicializa el sistema de gestión de recursos
#else #else
@@ -104,6 +127,8 @@ void Director::init() {
ServiceMenu::init(); // Inicializa el menú de servicio ServiceMenu::init(); // Inicializa el menú de servicio
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
Logger::section("GAME LOG");
} }
// Cierra todo y libera recursos del sistema y de los singletons // Cierra todo y libera recursos del sistema y de los singletons
@@ -164,7 +189,7 @@ void Director::loadAssets() {
std::string config_path = executable_path_ + PREFIX + "/config/assets.txt"; std::string config_path = executable_path_ + PREFIX + "/config/assets.txt";
Asset::get()->loadFromFile(config_path, PREFIX, system_folder_); Asset::get()->loadFromFile(config_path, PREFIX, system_folder_);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Assets configuration loaded successfully"); Logger::put("Assets configuration loaded successfully");
// Si falta algun fichero, sale del programa // Si falta algun fichero, sale del programa
if (!Asset::get()->check()) { if (!Asset::get()->check()) {
@@ -173,7 +198,7 @@ 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) {
// Obtener la ruta absoluta del ejecutable // Obtener la ruta absoluta del ejecutable
std::filesystem::path exe_path = std::filesystem::absolute(argv[0]); std::filesystem::path exe_path = std::filesystem::absolute(argv[0]);
executable_path_ = exe_path.parent_path().string(); executable_path_ = exe_path.parent_path().string();
@@ -196,7 +221,7 @@ void Director::checkProgramArguments(int argc, std::span<char *> argv) {
} }
// Crea la carpeta del sistema donde guardar datos // Crea la carpeta del sistema donde guardar datos
void Director::createSystemFolder(const std::string &folder) { void Director::createSystemFolder(const std::string& folder) {
auto result = SystemUtils::createApplicationFolder(folder, system_folder_); auto result = SystemUtils::createApplicationFolder(folder, system_folder_);
if (result != SystemUtils::Result::SUCCESS) { if (result != SystemUtils::Result::SUCCESS) {

View File

@@ -11,7 +11,7 @@ enum class Code : int;
class Director { class Director {
public: public:
// --- Constructor y destructor --- // --- Constructor y destructor ---
Director(int argc, std::span<char *> argv); Director(int argc, std::span<char*> argv);
~Director(); ~Director();
// --- Bucle principal --- // --- Bucle principal ---
@@ -29,11 +29,11 @@ class Director {
// --- Configuración inicial --- // --- Configuración inicial ---
static void loadParams(); // Carga los parámetros del programa static void loadParams(); // Carga los parámetros del programa
static void loadScoreFile(); // Carga el fichero de puntuaciones static void loadScoreFile(); // Carga el fichero de puntuaciones
void createSystemFolder(const std::string &folder); // Crea la carpeta del sistema void createSystemFolder(const std::string& folder); // Crea la carpeta del sistema
// --- Gestión de entrada y archivos --- // --- Gestión de entrada y archivos ---
void loadAssets(); // Crea el índice de archivos disponibles void loadAssets(); // Crea el índice de archivos disponibles
void checkProgramArguments(int argc, std::span<char *> argv); // Verifica los parámetros del programa // NOLINT(modernize-avoid-c-arrays) void checkProgramArguments(int argc, std::span<char*> argv); // Verifica los parámetros del programa // NOLINT(modernize-avoid-c-arrays)
// --- Secciones del programa --- // --- Secciones del programa ---
static void runLogo(); // Ejecuta la pantalla con el logo static void runLogo(); // Ejecuta la pantalla con el logo

View File

@@ -1,147 +1,107 @@
#include "enter_name.h" #include "enter_name.hpp"
#include <cstddef> // Para size_t #include <array> // Para array
#include <cstdlib> // Para rand #include <cstdlib> // Para rand
#include <string_view> // Para basic_string_view, string_view #include <string_view> // Para basic_string_view, string_view
#include "utils.h" // Para trim
// Constructor // Constructor
EnterName::EnterName() EnterName::EnterName()
: character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789."), : character_list_("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{") {}
character_index_{0} {}
// Inicializa el objeto // Inicializa el objeto
void EnterName::init(const std::string &name) { void EnterName::init(const std::string& name) {
// No se pasa ningún nombre name_ = sanitizeName(name);
if (name.empty()) { selected_index_ = 0;
name_ = "A";
position_ = 0;
position_overflow_ = false;
}
// Se pasa un nombre
else {
name_ = name;
position_ = name_.length();
position_overflow_ = position_ >= NAME_SIZE;
}
// Inicializa el vector de indices con el nombre y espacios // Si el nombre está completo, cambia el caracter seleccionado a el caracter de finalizar
initCharacterIndex(name_); if (!nameIsEmpty()) {
forceEndCharSelected();
}
} }
// Incrementa la posición // Incrementa el índice del carácter seleccionado
void EnterName::incPosition() {
if (position_overflow_) {
// Si ya estamos en overflow, no incrementamos más.
return;
}
++position_;
if (position_ >= NAME_SIZE) {
position_ = NAME_SIZE; // Mantenemos en el índice máximo válido.
position_overflow_ = true; // Activamos el flag de overflow.
} else if (position_ > 0) // No es necesario verificar position_ < MAX_NAME_LENGTH
{
// Copiamos el índice del carácter anterior si es posible.
// character_index_[position_] = character_index_[position_ - 1];
// Ponemos el caracter "espacio"
character_index_[position_] = 0;
} else {
// Si position_ es 0, inicializamos el carácter actual.
character_index_[position_] = 0;
}
updateNameFromCharacterIndex();
}
// Decrementa la posición
void EnterName::decPosition() {
if (position_overflow_) {
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
position_overflow_ = false;
position_ = NAME_SIZE - 1;
} else {
if (position_ > 0) {
--position_;
// Limpiamos el carácter siguiente si el índice es válido.
if (position_ + 1 < NAME_SIZE) {
character_index_[position_ + 1] = 0;
}
} else {
// Si position_ es 0, aseguramos que no vaya a ser negativo y limpiamos el carácter actual.
position_ = 0;
// character_index_[position_] = 0;
}
// Si position_ es menor que NAME_LENGTH, aseguramos que el overflow esté desactivado.
if (position_ < NAME_SIZE) {
position_overflow_ = false;
}
}
updateNameFromCharacterIndex();
}
// Incrementa el índice
void EnterName::incIndex() { void EnterName::incIndex() {
if (position_overflow_) { ++selected_index_;
return; if (selected_index_ >= character_list_.size()) {
selected_index_ = 0;
} }
++character_index_[position_];
if (character_index_[position_] >= static_cast<int>(character_list_.size())) {
character_index_[position_] = 0;
}
updateNameFromCharacterIndex();
} }
// Decrementa el índice // Decrementa el índice del carácter seleccionado
void EnterName::decIndex() { void EnterName::decIndex() {
if (position_overflow_) { if (selected_index_ == 0) {
return; selected_index_ = character_list_.size() - 1;
} } else {
--selected_index_;
--character_index_[position_];
if (character_index_[position_] < 0) {
character_index_[position_] = character_list_.size() - 1;
}
updateNameFromCharacterIndex();
}
// Actualiza el nombre a partir de la lista de índices
void EnterName::updateNameFromCharacterIndex() {
name_.clear();
for (size_t i = 0; i < NAME_SIZE; ++i) {
name_.push_back(character_list_[character_index_[i]]);
}
name_ = trim(name_);
}
// Actualiza la variable
void EnterName::initCharacterIndex(const std::string &name) {
// Rellena de espacios
for (size_t i = 0; i < NAME_SIZE; ++i) {
character_index_[i] = 0;
}
// Coloca los índices en función de los caracteres que forman el nombre
for (size_t i = 0; i < name.substr(0, NAME_SIZE).size(); ++i) {
character_index_[i] = findIndex(name.at(i));
} }
} }
// Encuentra el indice de un caracter en "character_list_" // Añade el carácter seleccionado al nombre
auto EnterName::findIndex(char character) const -> int { void EnterName::addCharacter() {
for (size_t i = 0; i < character_list_.size(); ++i) { // Si no es el ultimo caracter, lo añade
if (character == character_list_.at(i)) { if (name_.length() < MAX_NAME_SIZE) {
return i; name_.push_back(character_list_[selected_index_]);
}
// Si el nombre está completo, cambia el caracter seleccionado a el caracter de finalizar
if (nameIsFull()) {
forceEndCharSelected();
}
}
// Elimina el último carácter del nombre
void EnterName::removeLastCharacter() {
if (!name_.empty()) {
name_.pop_back();
}
}
// Devuelve el carácter seleccionado con offset relativo como string
auto EnterName::getSelectedCharacter(int offset) const -> std::string {
// Calcular el índice con offset, con wrap-around circular
int size = static_cast<int>(character_list_.size());
int index = (selected_index_ + offset) % size;
// Manejar índices negativos (hacer wrap-around hacia atrás)
if (index < 0) {
index += size;
}
return {1, character_list_[index]};
}
// Devuelve el carrusel completo de caracteres centrado en el seleccionado
auto EnterName::getCarousel(int size) const -> std::string {
// Asegurar que el tamaño sea impar para tener un centro claro
if (size % 2 == 0) {
++size;
}
std::string carousel;
carousel.reserve(size); // Optimización: reservar memoria de antemano
int half = size / 2;
// Construir desde -half hasta +half (inclusive)
for (int offset = -half; offset <= half; ++offset) {
carousel += getSelectedCharacter(offset);
}
return carousel;
}
// Valida y limpia el nombre: solo caracteres legales y longitud máxima
auto EnterName::sanitizeName(const std::string& name) const -> std::string {
std::string sanitized;
for (size_t i = 0; i < name.length() && sanitized.length() < MAX_NAME_SIZE; ++i) {
// Verifica si el carácter está en la lista permitida
if (character_list_.find(name[i]) != std::string::npos) {
sanitized.push_back(name[i]);
} }
} }
return 0;
return sanitized;
} }
// Devuelve un nombre al azar // Devuelve un nombre al azar
@@ -157,12 +117,11 @@ auto EnterName::getRandomName() -> std::string {
"PEPE"}; "PEPE"};
return std::string(NAMES[rand() % NAMES.size()]); return std::string(NAMES[rand() % NAMES.size()]);
} }
// Obtiene el nombre final introducido // Obtiene el nombre final introducido
auto EnterName::getFinalName() -> std::string { auto EnterName::getFinalName() -> std::string {
auto name = trim(name_.substr(0, position_ + 1)); // Devuelve el texto intruducido incluyendo el del selector if (name_.empty()) {
if (name.empty()) { name_ = getRandomName();
name = getRandomName();
} }
name_ = name;
return name_; return name_;
} }

View File

@@ -1,43 +0,0 @@
#pragma once
#include <array> // Para array
#include <cstddef> // Para size_t
#include <string> // Para allocator, string
#include "utils.h" // Para trim
// --- Constantes ---
constexpr size_t NAME_SIZE = 5; // Tamaño máximo del nombre
// --- Clase EnterName: gestor de entrada de nombre del jugador ---
class EnterName {
public:
EnterName();
~EnterName() = default;
void init(const std::string &name = ""); // Inicializa con un nombre opcional
void incPosition(); // Incrementa la posición del carácter actual
void decPosition(); // Decrementa la posición del carácter actual
void incIndex(); // Incrementa el índice del carácter en la lista
void decIndex(); // Decrementa el índice del carácter en la lista
auto getFinalName() -> std::string; // Obtiene el nombre final introducido
[[nodiscard]] auto getCurrentName() const -> std::string { return trim(name_); } // Obtiene el nombre actual en proceso
[[nodiscard]] auto getPosition() const -> int { return position_; } // Posición actual del carácter editado
[[nodiscard]] auto getPositionOverflow() const -> bool { return position_overflow_; } // Indica si la posición excede el límite
private:
// --- Variables de estado ---
std::string character_list_; // Lista de caracteres permitidos
std::string name_; // Nombre en proceso
std::array<int, NAME_SIZE> character_index_; // Índices a "character_list_"
size_t position_ = 0; // Índice del carácter que se edita
bool position_overflow_ = false; // Flag para exceder límite
void updateNameFromCharacterIndex(); // Actualiza "name_" según "character_index_"
void initCharacterIndex(const std::string &name); // Inicializa índices desde el nombre
[[nodiscard]] auto findIndex(char character) const -> int; // Busca el índice de un carácter en "character_list_"
static auto getRandomName() -> std::string; // Devuelve un nombre al azar
};

42
source/enter_name.hpp Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <cstddef> // Para size_t
#include <string> // Para allocator, string
// --- Clase EnterName: gestor de entrada de nombre del jugador ---
class EnterName {
public:
// --- Constantes ---
static constexpr size_t MAX_NAME_SIZE = 6; // Tamaño máximo del nombre
EnterName();
~EnterName() = default;
void init(const std::string& name = ""); // Inicializa con nombre opcional (vacío por defecto)
void incIndex(); // Incrementa el índice del carácter seleccionado en la lista
void decIndex(); // Decrementa el índice del carácter seleccionado en la lista
void addCharacter(); // Añade el carácter seleccionado al nombre
void removeLastCharacter(); // Elimina el último carácter del nombre
auto getFinalName() -> std::string; // Obtiene el nombre final (o aleatorio si vacío)
[[nodiscard]] auto getCurrentName() const -> std::string { return name_; } // Obtiene el nombre actual en proceso
[[nodiscard]] auto getSelectedCharacter(int offset = 0) const -> std::string; // Devuelve el carácter seleccionado con offset relativo
[[nodiscard]] auto getCarousel(int size) const -> std::string; // Devuelve el carrusel de caracteres (size debe ser impar)
[[nodiscard]] auto getSelectedIndex() const -> int { return selected_index_; } // Obtiene el índice del carácter seleccionado
[[nodiscard]] auto getCharacterList() const -> const std::string& { return character_list_; } // Obtiene la lista completa de caracteres
[[nodiscard]] auto nameIsFull() const -> bool { return name_.size() == MAX_NAME_SIZE; } // Informa de si el nombre ha alcanzado su limite
[[nodiscard]] auto nameIsEmpty() const -> bool { return name_.empty(); } // Informa de si el nombre está vacío
[[nodiscard]] auto endCharSelected() const -> bool { return selected_index_ == character_list_.size() - 1; } // Informa de si está seleccionado el caracter de terminar
private:
// --- Variables de estado ---
std::string character_list_; // Lista de caracteres permitidos
std::string name_; // Nombre en proceso
size_t selected_index_ = 0; // Índice del carácter seleccionado en "character_list_"
[[nodiscard]] auto sanitizeName(const std::string& name) const -> std::string; // Valida y limpia el nombre
static auto getRandomName() -> std::string; // Devuelve un nombre al azar
void forceEndCharSelected() { selected_index_ = character_list_.size() - 1; } // Establece como seleccionado el caracter de terminar
};

View File

@@ -1,15 +1,13 @@
#include "explosions.h" #include "explosions.hpp"
#include <algorithm> // Para max #include "animated_sprite.hpp" // Para AnimatedSprite
#include "animated_sprite.h" // Para AnimatedSprite
class Texture; // lines 4-4 class Texture; // lines 4-4
// Actualiza la lógica de la clase (time-based) // Actualiza la lógica de la clase (time-based)
void Explosions::update(float deltaTime) { void Explosions::update(float delta_time) {
for (auto &explosion : explosions_) { for (auto& explosion : explosions_) {
explosion->update(deltaTime); explosion->update(delta_time);
} }
// Vacia el vector de elementos finalizados // Vacia el vector de elementos finalizados
@@ -18,13 +16,13 @@ void Explosions::update(float deltaTime) {
// Dibuja el objeto en pantalla // Dibuja el objeto en pantalla
void Explosions::render() { void Explosions::render() {
for (auto &explosion : explosions_) { for (auto& explosion : explosions_) {
explosion->render(); explosion->render();
} }
} }
// Añade texturas al objeto // Añade texturas al objeto
void Explosions::addTexture(int size, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation) { void Explosions::addTexture(int size, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation) {
textures_.emplace_back(size, texture, animation); textures_.emplace_back(size, texture, animation);
} }

View File

@@ -5,7 +5,7 @@
#include <utility> // Para move #include <utility> // Para move
#include <vector> // Para vector #include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.hpp" // Para AnimatedSprite
class Texture; class Texture;
@@ -15,7 +15,7 @@ struct ExplosionTexture {
std::shared_ptr<Texture> texture; // Textura para la explosión std::shared_ptr<Texture> texture; // Textura para la explosión
std::vector<std::string> animation; // Animación para la textura std::vector<std::string> animation; // Animación para la textura
ExplosionTexture(int sz, std::shared_ptr<Texture> tex, const std::vector<std::string> &anim) ExplosionTexture(int sz, std::shared_ptr<Texture> tex, const std::vector<std::string>& anim)
: size(sz), : size(sz),
texture(std::move(tex)), texture(std::move(tex)),
animation(anim) {} animation(anim) {}
@@ -29,11 +29,11 @@ class Explosions {
~Explosions() = default; // Destructor por defecto ~Explosions() = default; // Destructor por defecto
// --- Métodos principales --- // --- Métodos principales ---
void update(float deltaTime); // Actualiza la lógica de la clase (time-based) void update(float delta_time); // Actualiza la lógica de la clase (time-based)
void render(); // Dibuja el objeto en pantalla void render(); // Dibuja el objeto en pantalla
// --- Configuración --- // --- Configuración ---
void addTexture(int size, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Añade texturas al objeto void addTexture(int size, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation); // Añade texturas al objeto
void add(int x, int y, int size); // Añade una explosión void add(int x, int y, int size); // Añade una explosión
private: private:

View File

@@ -1,4 +1,4 @@
#include "gif.h" #include "gif.hpp"
#include <SDL3/SDL.h> // Para SDL_LogError, SDL_LogCategory, SDL_LogInfo #include <SDL3/SDL.h> // Para SDL_LogError, SDL_LogCategory, SDL_LogInfo
#include <cstring> // Para memcpy, size_t #include <cstring> // Para memcpy, size_t

View File

@@ -118,21 +118,16 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channel
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif #endif
SDL_Log("Iniciant JailAudio...");
JA_audioSpec = {format, num_channels, freq }; JA_audioSpec = {format, num_channels, freq };
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice); if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec); sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
SDL_Log( (sdlAudioDevice==0) ? "Failed to initialize SDL audio!\n" : "OK!\n"); if (sdlAudioDevice==0) SDL_Log("Failed to initialize SDL audio!");
for (int i=0; i<JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE; for (int i=0; i<JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
for (int i=0; i<JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f; for (int i=0; i<JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
//SDL_PauseAudioDevice(sdlAudioDevice);
//JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
} }
void JA_Quit() void JA_Quit()
{ {
//if (JA_timerID) SDL_RemoveTimer(JA_timerID);
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice); if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = 0; sdlAudioDevice = 0;
} }

View File

@@ -1,415 +0,0 @@
#include "jail_shader.h"
#include <SDL3/SDL.h> // Para SDL_GL_GetProcAddress, SDL_LogError
#include <stdint.h> // Para uintptr_t
#include <cstring> // Para strncmp
#include <stdexcept> // Para runtime_error
#include <vector> // Para vector
#ifdef __APPLE__
#include <OpenGL/OpenGL.h> // Para OpenGL en macOS
#include "CoreFoundation/CoreFoundation.h" // Para Core Foundation en macOS
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
#include <OpenGL/gl3.h> // Para OpenGL 3 en macOS
#else // NO ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
#include <OpenGL/gl.h> // Para OpenGL (compatibilidad) en macOS
#endif // ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
#else // SI NO ES __APPLE__
#include <SDL3/SDL_opengl.h> // Para GLuint, GLint, glTexCoord2f, glVertex2f
#endif // __APPLE__
namespace shader {
// Constantes
const GLuint INVALID_SHADER_ID = 0;
const GLuint INVALID_PROGRAM_ID = 0;
const GLuint DEFAULT_TEXTURE_ID = 1;
// Variables globales
SDL_Window *win = nullptr;
SDL_Renderer *renderer = nullptr;
GLuint programId = 0;
SDL_Texture *backBuffer = nullptr;
SDL_Point win_size = {320 * 4, 256 * 4};
SDL_FPoint tex_size = {320, 256};
bool usingOpenGL = false;
#ifndef __APPLE__
// Declaración de funciones de extensión de OpenGL (evitando GLEW)
PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLDELETESHADERPROC glDeleteShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLVALIDATEPROGRAMPROC glValidateProgram;
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLDELETEPROGRAMPROC glDeleteProgram;
bool initGLExtensions() {
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog");
glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader");
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram");
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram");
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
glUseProgram && glDeleteProgram;
}
#endif
// Función para verificar errores de OpenGL
void checkGLError(const char *operation) {
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error OpenGL en %s: 0x%x",
operation,
error);
}
}
// Función para compilar un shader a partir de un std::string
GLuint compileShader(const std::string &source, GLuint shader_type) {
if (source.empty()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ERROR FATAL: El código fuente del shader está vacío.");
throw std::runtime_error("ERROR FATAL: El código fuente del shader está vacío.");
}
// Crear identificador del shader
GLuint shader_id = glCreateShader(shader_type);
if (shader_id == INVALID_SHADER_ID) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al crear el shader.");
checkGLError("glCreateShader");
return INVALID_SHADER_ID;
}
// Agregar una directiva según el tipo de shader
std::string directive = (shader_type == GL_VERTEX_SHADER)
? "#define VERTEX\n"
: "#define FRAGMENT\n";
const char *sources[2] = {directive.c_str(), source.c_str()};
// Especificar el código fuente del shader
glShaderSource(shader_id, 2, sources, nullptr);
checkGLError("glShaderSource");
// Compilar el shader
glCompileShader(shader_id);
checkGLError("glCompileShader");
// Verificar si la compilación fue exitosa
GLint compiled_ok = GL_FALSE;
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &compiled_ok);
if (compiled_ok != GL_TRUE) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error en la compilación del shader (%d)!", shader_id);
GLint log_length;
glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &log_length);
if (log_length > 0) {
std::vector<GLchar> log(log_length);
glGetShaderInfoLog(shader_id, log_length, &log_length, log.data());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Registro de compilación del shader: %s", log.data());
}
glDeleteShader(shader_id);
return INVALID_SHADER_ID;
}
return shader_id;
}
// Función para compilar un programa de shaders (vertex y fragment) a partir de std::string
GLuint compileProgram(const std::string &vertex_shader_source, const std::string &fragment_shader_source) {
GLuint program_id = glCreateProgram();
if (program_id == INVALID_PROGRAM_ID) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al crear el programa de shaders.");
checkGLError("glCreateProgram");
return INVALID_PROGRAM_ID;
}
// Si el fragment shader está vacío, reutilizamos el código del vertex shader
GLuint vertex_shader_id = compileShader(vertex_shader_source, GL_VERTEX_SHADER);
GLuint fragment_shader_id = compileShader(fragment_shader_source.empty() ? vertex_shader_source : fragment_shader_source, GL_FRAGMENT_SHADER);
if (vertex_shader_id != INVALID_SHADER_ID && fragment_shader_id != INVALID_SHADER_ID) {
// Asociar los shaders al programa
glAttachShader(program_id, vertex_shader_id);
checkGLError("glAttachShader vertex");
glAttachShader(program_id, fragment_shader_id);
checkGLError("glAttachShader fragment");
glLinkProgram(program_id);
checkGLError("glLinkProgram");
// Verificar el estado del enlace
GLint isLinked = GL_FALSE;
glGetProgramiv(program_id, GL_LINK_STATUS, &isLinked);
if (isLinked == GL_FALSE) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al enlazar el programa de shaders.");
GLint log_length;
glGetProgramiv(program_id, GL_INFO_LOG_LENGTH, &log_length);
if (log_length > 0) {
std::vector<char> log(log_length);
glGetProgramInfoLog(program_id, log_length, &log_length, log.data());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Registro de enlace del programa: %s", log.data());
}
glDeleteProgram(program_id);
program_id = INVALID_PROGRAM_ID;
} else {
glValidateProgram(program_id);
checkGLError("glValidateProgram");
// Log de información del programa (solo si hay información)
GLint log_length;
glGetProgramiv(program_id, GL_INFO_LOG_LENGTH, &log_length);
if (log_length > 1) // > 1 porque algunos drivers devuelven 1 para cadena vacía
{
std::vector<char> log(log_length);
glGetProgramInfoLog(program_id, log_length, &log_length, log.data());
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Registro de información del programa:\n%s", log.data());
}
}
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudieron compilar los shaders.");
glDeleteProgram(program_id);
program_id = INVALID_PROGRAM_ID;
}
// Limpiar los shaders (ya no son necesarios después del enlace)
if (vertex_shader_id != INVALID_SHADER_ID) {
glDeleteShader(vertex_shader_id);
}
if (fragment_shader_id != INVALID_SHADER_ID) {
glDeleteShader(fragment_shader_id);
}
return program_id;
}
// Función para obtener el ID de textura OpenGL desde SDL3
GLuint getTextureID(SDL_Texture *texture) {
if (!texture)
return DEFAULT_TEXTURE_ID;
// Intentar obtener el ID de textura OpenGL desde las propiedades de SDL3
SDL_PropertiesID props = SDL_GetTextureProperties(texture);
GLuint textureId = 0;
// Intentar diferentes nombres de propiedades según la versión de SDL3
textureId = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "SDL.texture.opengl.texture", nullptr);
// Si la primera no funciona, intentar con el nombre alternativo
if (textureId == 0) {
textureId = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "texture.opengl.texture", nullptr);
}
// Si aún no funciona, intentar obtener como número
if (textureId == 0) {
textureId = (GLuint)SDL_GetNumberProperty(props, "SDL.texture.opengl.texture", DEFAULT_TEXTURE_ID);
}
// Si ninguna funciona, usar el método manual de bindeo de textura
if (textureId == 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"No se pudo obtener el ID de textura OpenGL, usando ID por defecto (%d)",
DEFAULT_TEXTURE_ID);
textureId = DEFAULT_TEXTURE_ID;
}
return textureId;
}
bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::string &vertex_shader, const std::string &fragment_shader) {
shader::win = window;
shader::renderer = SDL_GetRenderer(window);
shader::backBuffer = back_buffer_texture;
if (!shader::renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo obtener el renderer de la ventana.");
return false;
}
SDL_GetWindowSize(window, &win_size.x, &win_size.y);
SDL_GetTextureSize(back_buffer_texture, &tex_size.x, &tex_size.y);
const auto render_name = SDL_GetRendererName(renderer);
if (!render_name) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo obtener el nombre del renderer.");
return false;
}
// Verificar que el renderer sea OpenGL
if (!strncmp(render_name, "opengl", 6)) {
#ifndef __APPLE__
if (!initGLExtensions()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ERROR: No se han podido inicializar las extensiones de OpenGL.");
usingOpenGL = false;
return false;
}
#endif
// Compilar el programa de shaders utilizando std::string
programId = compileProgram(vertex_shader, fragment_shader);
if (programId == INVALID_PROGRAM_ID) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ERROR: No se pudo compilar el programa de shaders.");
usingOpenGL = false;
return false;
}
} else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "ADVERTENCIA: El driver del renderer no es OpenGL (%s).", render_name);
usingOpenGL = false;
return false;
}
usingOpenGL = true;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Shader system initialized successfully");
return true;
}
void render() {
// Establece el color de fondo
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_SetRenderTarget(renderer, nullptr);
SDL_RenderClear(renderer);
if (usingOpenGL && programId != INVALID_PROGRAM_ID) {
// Guardar estados de OpenGL
GLint oldProgramId;
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
GLint oldViewport[4];
glGetIntegerv(GL_VIEWPORT, oldViewport);
GLboolean wasTextureEnabled = glIsEnabled(GL_TEXTURE_2D);
GLint oldTextureId;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTextureId);
// Obtener y bindear la textura
GLuint textureId = getTextureID(backBuffer);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);
checkGLError("glBindTexture");
// Usar nuestro programa de shaders
glUseProgram(programId);
checkGLError("glUseProgram");
// Recupera el tamaño lógico configurado con SDL_RenderSetLogicalSize
int logicalW, logicalH;
SDL_RendererLogicalPresentation mode;
SDL_GetRenderLogicalPresentation(renderer, &logicalW, &logicalH, &mode);
if (logicalW == 0 || logicalH == 0) {
logicalW = win_size.x;
logicalH = win_size.y;
}
// Cálculo del viewport
int viewportX = 0, viewportY = 0, viewportW = win_size.x, viewportH = win_size.y;
const bool USE_INTEGER_SCALE = mode == SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
if (USE_INTEGER_SCALE) {
// Calcula el factor de escalado entero máximo que se puede aplicar
int scaleX = win_size.x / logicalW;
int scaleY = win_size.y / logicalH;
int scale = (scaleX < scaleY ? scaleX : scaleY);
if (scale < 1) {
scale = 1;
}
viewportW = logicalW * scale;
viewportH = logicalH * scale;
viewportX = (win_size.x - viewportW) / 2;
viewportY = (win_size.y - viewportH) / 2;
} else {
// Letterboxing: preserva la relación de aspecto usando una escala flotante
float windowAspect = static_cast<float>(win_size.x) / win_size.y;
float logicalAspect = static_cast<float>(logicalW) / logicalH;
if (windowAspect > logicalAspect) {
viewportW = static_cast<int>(logicalAspect * win_size.y);
viewportX = (win_size.x - viewportW) / 2;
} else {
viewportH = static_cast<int>(win_size.x / logicalAspect);
viewportY = (win_size.y - viewportH) / 2;
}
}
glViewport(viewportX, viewportY, viewportW, viewportH);
checkGLError("glViewport");
// Configurar la proyección ortográfica usando el espacio lógico
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Queremos que el origen esté en la esquina superior izquierda del espacio lógico.
glOrtho(0, static_cast<GLdouble>(logicalW), static_cast<GLdouble>(logicalH), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Dibuja el quad con las coordenadas ajustadas.
// Se asignan las coordenadas de textura "normales" para que no quede espejado horizontalmente,
// y se mantiene el flip vertical para que la imagen no aparezca volteada.
glBegin(GL_TRIANGLE_STRIP);
// Vértice superior izquierdo
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, 0.0f);
// Vértice superior derecho
glTexCoord2f(1.0f, 1.0f);
glVertex2f(static_cast<GLfloat>(logicalW), 0.0f);
// Vértice inferior izquierdo
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, static_cast<GLfloat>(logicalH));
// Vértice inferior derecho
glTexCoord2f(1.0f, 0.0f);
glVertex2f(static_cast<GLfloat>(logicalW), static_cast<GLfloat>(logicalH));
glEnd();
checkGLError("render quad");
SDL_GL_SwapWindow(win);
// Restaurar estados de OpenGL
glUseProgram(oldProgramId);
glBindTexture(GL_TEXTURE_2D, oldTextureId);
if (!wasTextureEnabled) {
glDisable(GL_TEXTURE_2D);
}
glViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
} else {
// Fallback a renderizado normal de SDL
SDL_RenderTexture(renderer, backBuffer, nullptr, nullptr);
SDL_RenderPresent(renderer);
}
}
void cleanup() {
if (programId != INVALID_PROGRAM_ID) {
glDeleteProgram(programId);
programId = INVALID_PROGRAM_ID;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Programa de shaders liberado.");
}
// Reinicializar variables
win = nullptr;
renderer = nullptr;
backBuffer = nullptr;
usingOpenGL = false;
}
bool isUsingOpenGL() {
return usingOpenGL;
}
GLuint getProgramId() {
return programId;
}
} // namespace shader

View File

@@ -1,9 +0,0 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Texture, SDL_Window
#include <string> // Para basic_string, string
namespace shader {
bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const std::string &vertexShader, const std::string &fragmentShader = "");
void render();
} // namespace shader

View File

@@ -10,7 +10,7 @@
#include ... #include ...
#include ... #include ...
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.hpp"
You can #define STBI_ASSERT(x) before the #include to avoid using assert.h. You can #define STBI_ASSERT(x) before the #include to avoid using assert.h.
And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free And #define STBI_MALLOC, STBI_REALLOC, and STBI_FREE to avoid using malloc,realloc,free

View File

@@ -1,13 +1,13 @@
#include "fade.h" #include "fade.hpp"
#include <SDL3/SDL.h> // Para SDL_SetRenderTarget, SDL_FRect, SDL_GetRenderTarget, SDL_RenderFillRect, SDL_SetRenderDrawBlendMode, SDL_SetRenderDrawColor, Uint8, SDL_GetRenderDrawBlendMode, SDL_BLENDMODE_NONE, SDL_BlendMode, SDL_CreateTexture, SDL_DestroyTexture, SDL_RenderClear, SDL_RenderTexture, SDL_SetTextureAlphaMod, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_TextureAccess #include <SDL3/SDL.h>
#include <algorithm> // Para min, max #include <algorithm>
#include <cstdlib> // Para rand, size_t #include <cstdlib>
#include "color.h" // Para Color #include "color.hpp"
#include "param.h" // Para Param, param, ParamGame, ParamFade #include "param.hpp"
#include "screen.h" // Para Screen #include "screen.hpp"
// Constructor // Constructor
Fade::Fade() Fade::Fade()
@@ -29,7 +29,6 @@ Fade::~Fade() {
void Fade::init() { void Fade::init() {
type_ = Type::CENTER; type_ = Type::CENTER;
mode_ = Mode::OUT; mode_ = Mode::OUT;
counter_ = 0;
r_ = 0; r_ = 0;
g_ = 0; g_ = 0;
b_ = 0; b_ = 0;
@@ -38,19 +37,21 @@ void Fade::init() {
post_start_time_ = 0; post_start_time_ = 0;
pre_duration_ = 0; pre_duration_ = 0;
pre_start_time_ = 0; pre_start_time_ = 0;
fading_duration_ = param.fade.random_squares_duration_ms; // Duración por defecto para FADING
fading_start_time_ = 0;
num_squares_width_ = param.fade.num_squares_width; num_squares_width_ = param.fade.num_squares_width;
num_squares_height_ = param.fade.num_squares_height; num_squares_height_ = param.fade.num_squares_height;
random_squares_duration_ = param.fade.random_squares_duration_ms; // Usar como duración en ms square_transition_duration_ = fading_duration_ / 4; // 25% del tiempo total para la transición individual
square_transition_duration_ = random_squares_duration_ / 4; // 25% del tiempo total para la transición individual
random_squares_start_time_ = 0;
} }
// Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros // Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros
void Fade::reset() { void Fade::reset() {
state_ = State::NOT_ENABLED; state_ = State::NOT_ENABLED;
counter_ = 0;
post_start_time_ = 0; post_start_time_ = 0;
pre_start_time_ = 0; pre_start_time_ = 0;
fading_start_time_ = 0;
value_ = 0;
// La duración del fade se mantiene, se puede cambiar con setDuration()
} }
// Pinta una transición en pantalla // Pinta una transición en pantalla
@@ -66,7 +67,7 @@ void Fade::render() {
} }
// Actualiza las variables internas // Actualiza las variables internas
void Fade::update() { void Fade::update(float delta_time) {
switch (state_) { switch (state_) {
case State::PRE: case State::PRE:
updatePreState(); updatePreState();
@@ -82,21 +83,12 @@ void Fade::update() {
} }
} }
// Compatibilidad delta-time (ignora el parámetro ya que usa SDL_GetTicks)
void Fade::update(float delta_time) {
update(); // Llama al método original
}
void Fade::updatePreState() { void Fade::updatePreState() {
// Sistema basado en tiempo únicamente
Uint32 elapsed_time = SDL_GetTicks() - pre_start_time_; Uint32 elapsed_time = SDL_GetTicks() - pre_start_time_;
if (elapsed_time >= static_cast<Uint32>(pre_duration_)) { if (elapsed_time >= static_cast<Uint32>(pre_duration_)) {
state_ = State::FADING; state_ = State::FADING;
// CRÍTICO: Reinicializar tiempo de inicio para tipos que usan random_squares_start_time_ fading_start_time_ = SDL_GetTicks(); // Inicia el temporizador del fade AQUI
if (type_ == Type::RANDOM_SQUARE2 || type_ == Type::DIAGONAL) {
random_squares_start_time_ = SDL_GetTicks();
}
} }
} }
@@ -123,7 +115,6 @@ void Fade::updateFadingState() {
default: default:
break; break;
} }
counter_++;
} }
void Fade::changeToPostState() { void Fade::changeToPostState() {
@@ -132,194 +123,154 @@ void Fade::changeToPostState() {
} }
void Fade::updatePostState() { void Fade::updatePostState() {
// Sistema basado en tiempo únicamente
Uint32 elapsed_time = SDL_GetTicks() - post_start_time_; Uint32 elapsed_time = SDL_GetTicks() - post_start_time_;
if (elapsed_time >= static_cast<Uint32>(post_duration_)) { if (elapsed_time >= static_cast<Uint32>(post_duration_)) {
state_ = State::FINISHED; state_ = State::FINISHED;
} }
// Mantener el alpha final correcto para cada tipo de fade // Mantener el estado final del fade
Uint8 post_alpha = a_; Uint8 post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
if (type_ == Type::RANDOM_SQUARE2 || type_ == Type::DIAGONAL) {
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
}
cleanBackbuffer(r_, g_, b_, post_alpha); cleanBackbuffer(r_, g_, b_, post_alpha);
} }
void Fade::updateFullscreenFade() { void Fade::updateFullscreenFade() {
// Modifica la transparencia Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
a_ = mode_ == Mode::OUT ? std::min(counter_ * 4, 255) : 255 - std::min(counter_ * 4, 255); float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Modifica la transparencia basada en el progreso
auto current_alpha = static_cast<Uint8>(progress * 255.0F);
a_ = (mode_ == Mode::OUT) ? current_alpha : 255 - current_alpha;
SDL_SetTextureAlphaMod(backbuffer_, a_); SDL_SetTextureAlphaMod(backbuffer_, a_);
value_ = static_cast<int>(progress * 100);
// Comprueba si ha terminado // Comprueba si ha terminado
if (counter_ >= 255 / 4) { if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
changeToPostState(); changeToPostState();
} }
} }
void Fade::updateCenterFade() { void Fade::updateCenterFade() {
Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Calcula la altura de las barras
float rect_height = progress * (param.game.height / 2.0F);
if (mode_ == Mode::IN) {
rect_height = (param.game.height / 2.0F) - rect_height;
}
rect1_.h = rect_height;
rect2_.h = rect_height;
rect2_.y = param.game.height - rect_height;
drawCenterFadeRectangles(); drawCenterFadeRectangles();
value_ = static_cast<int>(progress * 100);
// Comprueba si ha terminado // Comprueba si ha terminado
if ((counter_ * 4) > param.game.height) { if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
a_ = 255; a_ = (mode_ == Mode::OUT) ? 255 : 0;
changeToPostState(); changeToPostState();
} }
} }
void Fade::drawCenterFadeRectangles() { void Fade::drawCenterFadeRectangles() {
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_); cleanBackbuffer(r_, g_, b_, 0); // Limpiar para modo IN
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, 255);
for (int i = 0; i < counter_; i++) {
rect1_.h = rect2_.h = i * 4;
rect2_.y = param.game.height - (i * 4);
SDL_RenderFillRect(renderer_, &rect1_); SDL_RenderFillRect(renderer_, &rect1_);
SDL_RenderFillRect(renderer_, &rect2_); SDL_RenderFillRect(renderer_, &rect2_);
value_ = calculateValue(0, counter_, i);
}
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(renderer_, temp);
} }
void Fade::updateRandomSquareFade() { void Fade::updateRandomSquareFade() {
Uint32 elapsed_time = SDL_GetTicks() - random_squares_start_time_; Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
float progress = static_cast<float>(elapsed_time) / random_squares_duration_; float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Calcula cuántos cuadrados deberían estar activos // Calcula cuántos cuadrados deberían estar activos
int total_squares = num_squares_width_ * num_squares_height_; int total_squares = num_squares_width_ * num_squares_height_;
int active_squares = static_cast<int>(progress * total_squares); int active_squares = static_cast<int>(progress * total_squares);
active_squares = std::min(active_squares, total_squares);
// Dibuja los cuadrados activos
drawRandomSquares(active_squares); drawRandomSquares(active_squares);
value_ = calculateValue(0, total_squares, active_squares); value_ = static_cast<int>(progress * 100);
// Comprueba si ha terminado // Comprueba si ha terminado
if (elapsed_time >= static_cast<Uint32>(random_squares_duration_)) { if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
changeToPostState(); changeToPostState();
} }
} }
void Fade::updateRandomSquare2Fade() { void Fade::updateRandomSquare2Fade() {
Uint32 elapsed_time = SDL_GetTicks() - random_squares_start_time_; Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
int total_squares = num_squares_width_ * num_squares_height_; int total_squares = num_squares_width_ * num_squares_height_;
// Calcula el tiempo de activación: total - tiempo que necesitan los últimos cuadrados int activation_time = fading_duration_ - square_transition_duration_;
int activation_time = random_squares_duration_ - square_transition_duration_; activation_time = std::max(activation_time, square_transition_duration_);
activation_time = std::max(activation_time, square_transition_duration_); // Mínimo igual a la duración de transición
// Lógica diferente según el modo
int squares_to_activate = 0; int squares_to_activate = 0;
if (mode_ == Mode::OUT) { if (mode_ == Mode::OUT) {
// OUT: Activa cuadrados gradualmente
if (elapsed_time < static_cast<Uint32>(activation_time)) { if (elapsed_time < static_cast<Uint32>(activation_time)) {
float activation_progress = static_cast<float>(elapsed_time) / activation_time; float activation_progress = static_cast<float>(elapsed_time) / activation_time;
squares_to_activate = static_cast<int>(activation_progress * total_squares); squares_to_activate = static_cast<int>(activation_progress * total_squares);
} else { } else {
squares_to_activate = total_squares; // Activar todos squares_to_activate = total_squares;
}
// Activa nuevos cuadrados y guarda su tiempo de activación
for (int i = 0; i < squares_to_activate && i < total_squares; ++i) {
if (square_age_[i] == -1) {
square_age_[i] = elapsed_time; // Guarda el tiempo de activación
} }
for (int i = 0; i < squares_to_activate; ++i) {
if (square_age_[i] == -1) {square_age_[i] = elapsed_time;}
} }
} else { } else {
// IN: Todos los cuadrados empiezan activos desde el inicio
squares_to_activate = total_squares; squares_to_activate = total_squares;
// Activa cuadrados gradualmente con tiempo de inicio escalonado
float activation_progress = static_cast<float>(elapsed_time) / activation_time; float activation_progress = static_cast<float>(elapsed_time) / activation_time;
int squares_starting_transition = static_cast<int>(activation_progress * total_squares); int squares_starting_transition = std::min(total_squares, std::max(1, static_cast<int>(activation_progress * total_squares)));
// Asegurar que al menos 1 cuadrado se active desde el primer frame
squares_starting_transition = std::max(squares_starting_transition, 1);
squares_starting_transition = std::min(squares_starting_transition, total_squares);
for (int i = 0; i < squares_starting_transition; ++i) { for (int i = 0; i < squares_starting_transition; ++i) {
if (square_age_[i] == -1) { if (square_age_[i] == -1) {square_age_[i] = elapsed_time;}
square_age_[i] = elapsed_time; // Empieza la transición a transparente
}
} }
} }
drawRandomSquares2(); drawRandomSquares2();
value_ = calculateValue(0, total_squares, squares_to_activate); value_ = calculateValue(0, total_squares, squares_to_activate);
// Comprueba si ha terminado - todos los cuadrados han completado su transición if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
bool all_completed = (squares_to_activate >= total_squares);
if (all_completed) {
// Verificar que todos han completado su transición individual
for (int i = 0; i < total_squares; ++i) {
if (square_age_[i] >= 0) { // Cuadrado activado
Uint32 square_elapsed = elapsed_time - square_age_[i];
if (square_elapsed < static_cast<Uint32>(square_transition_duration_)) {
all_completed = false;
break;
}
}
}
if (all_completed) {
// Pintar textura final: OUT opaca, IN transparente
Uint8 final_alpha = (mode_ == Mode::OUT) ? 255 : 0; Uint8 final_alpha = (mode_ == Mode::OUT) ? 255 : 0;
cleanBackbuffer(r_, g_, b_, final_alpha); cleanBackbuffer(r_, g_, b_, final_alpha);
changeToPostState(); changeToPostState();
} }
}
} }
void Fade::updateDiagonalFade() { void Fade::updateDiagonalFade() {
Uint32 elapsed_time = SDL_GetTicks() - random_squares_start_time_; Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
int total_squares = num_squares_width_ * num_squares_height_; int activation_time = fading_duration_ - square_transition_duration_;
// Calcula el tiempo de activación: total - tiempo que necesitan los últimos cuadrados
int activation_time = random_squares_duration_ - square_transition_duration_;
activation_time = std::max(activation_time, square_transition_duration_); activation_time = std::max(activation_time, square_transition_duration_);
// Calcula cuántas diagonales deberían estar activas int max_diagonal = num_squares_width_ + num_squares_height_ - 1;
int max_diagonal = num_squares_width_ + num_squares_height_ - 1; // Número total de diagonales
int active_diagonals = 0; int active_diagonals = 0;
if (mode_ == Mode::OUT) { if (mode_ == Mode::OUT) {
// OUT: Activa diagonales gradualmente desde esquina superior izquierda
if (elapsed_time < static_cast<Uint32>(activation_time)) { if (elapsed_time < static_cast<Uint32>(activation_time)) {
float activation_progress = static_cast<float>(elapsed_time) / activation_time; float activation_progress = static_cast<float>(elapsed_time) / activation_time;
active_diagonals = static_cast<int>(activation_progress * max_diagonal); active_diagonals = static_cast<int>(activation_progress * max_diagonal);
} else { } else {
active_diagonals = max_diagonal; // Activar todas active_diagonals = max_diagonal;
} }
// Activa cuadrados por diagonales
for (int diagonal = 0; diagonal < active_diagonals; ++diagonal) { for (int diagonal = 0; diagonal < active_diagonals; ++diagonal) {
activateDiagonal(diagonal, elapsed_time); activateDiagonal(diagonal, elapsed_time);
} }
} else { } else {
// IN: Todas las diagonales empiezan activas, van desapareciendo
active_diagonals = max_diagonal; active_diagonals = max_diagonal;
// Activa diagonales gradualmente para transición
if (elapsed_time < static_cast<Uint32>(activation_time)) { if (elapsed_time < static_cast<Uint32>(activation_time)) {
float activation_progress = static_cast<float>(elapsed_time) / activation_time; float activation_progress = static_cast<float>(elapsed_time) / activation_time;
int diagonals_starting_transition = static_cast<int>(activation_progress * max_diagonal); int diagonals_starting_transition = static_cast<int>(activation_progress * max_diagonal);
for (int diagonal = 0; diagonal < diagonals_starting_transition; ++diagonal) { for (int diagonal = 0; diagonal < diagonals_starting_transition; ++diagonal) {
activateDiagonal(diagonal, elapsed_time); activateDiagonal(diagonal, elapsed_time);
} }
} else { } else {
// Activar transición en todas las diagonales restantes
for (int diagonal = 0; diagonal < max_diagonal; ++diagonal) { for (int diagonal = 0; diagonal < max_diagonal; ++diagonal) {
activateDiagonal(diagonal, elapsed_time); activateDiagonal(diagonal, elapsed_time);
} }
@@ -327,93 +278,46 @@ void Fade::updateDiagonalFade() {
} }
drawDiagonal(); drawDiagonal();
value_ = calculateValue(0, max_diagonal, active_diagonals);
value_ = calculateValue(0, total_squares, active_diagonals * (total_squares / max_diagonal)); if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
// Comprueba si ha terminado - todas las diagonales activadas y último cuadrado completó transición
bool all_completed = (active_diagonals >= max_diagonal);
if (all_completed) {
// Verificar que todos han completado su transición individual
for (int i = 0; i < total_squares; ++i) {
if (square_age_[i] >= 0) { // Cuadrado activado
Uint32 square_elapsed = elapsed_time - square_age_[i];
if (square_elapsed < static_cast<Uint32>(square_transition_duration_)) {
all_completed = false;
break;
}
}
}
if (all_completed) {
// Pintar textura final: OUT opaca, IN transparente
Uint8 final_alpha = (mode_ == Mode::OUT) ? 255 : 0; Uint8 final_alpha = (mode_ == Mode::OUT) ? 255 : 0;
cleanBackbuffer(r_, g_, b_, final_alpha); cleanBackbuffer(r_, g_, b_, final_alpha);
changeToPostState(); changeToPostState();
} }
}
} }
void Fade::activateDiagonal(int diagonal_index, Uint32 current_time) { void Fade::activateDiagonal(int diagonal_index, Uint32 current_time) {
// Para cada diagonal, activamos los cuadrados que pertenecen a esa diagonal
// Diagonal 0: (0,0)
// Diagonal 1: (1,0), (0,1)
// Diagonal 2: (2,0), (1,1), (0,2)
// etc.
for (int x = 0; x < num_squares_width_; ++x) { for (int x = 0; x < num_squares_width_; ++x) {
int y = diagonal_index - x; int y = diagonal_index - x;
// Verificar que y está dentro de los límites
if (y >= 0 && y < num_squares_height_) { if (y >= 0 && y < num_squares_height_) {
// Convertir coordenadas (x,y) a índice en el vector int index = (y * num_squares_width_) + x;
int index = y * num_squares_width_ + x; if (index >= 0 && index < static_cast<int>(square_age_.size()) && square_age_[index] == -1) {
square_age_[index] = current_time;
if (index >= 0 && index < static_cast<int>(square_age_.size())) {
if (square_age_[index] == -1) {
square_age_[index] = current_time; // Guarda el tiempo de activación
}
} }
} }
} }
} }
void Fade::drawDiagonal() { void Fade::drawDiagonal() {
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// CRÍTICO: Limpiar la textura antes de dibujar
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
SDL_BlendMode blend_mode; SDL_BlendMode blend_mode;
SDL_GetRenderDrawBlendMode(renderer_, &blend_mode); SDL_GetRenderDrawBlendMode(renderer_, &blend_mode);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); // Usar BLEND para alpha SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
Uint32 current_time = SDL_GetTicks() - random_squares_start_time_; Uint32 current_time = SDL_GetTicks() - fading_start_time_;
// Lógica unificada: sobre textura transparente, pintar cuadrados según su estado
for (size_t i = 0; i < square_.size(); ++i) { for (size_t i = 0; i < square_.size(); ++i) {
Uint8 current_alpha = 0; Uint8 current_alpha = 0;
if (square_age_[i] == -1) { if (square_age_[i] == -1) {
// Cuadrado no activado current_alpha = (mode_ == Mode::OUT) ? 0 : a_;
if (mode_ == Mode::OUT) {
current_alpha = 0; // OUT: transparente si no activado
} else { } else {
current_alpha = a_; // IN: opaco si no activado
}
} else {
// Cuadrado activado - calculamos progreso
Uint32 square_elapsed = current_time - square_age_[i]; Uint32 square_elapsed = current_time - square_age_[i];
float progress = std::min(static_cast<float>(square_elapsed) / square_transition_duration_, 1.0f); float progress = std::min(static_cast<float>(square_elapsed) / square_transition_duration_, 1.0F);
current_alpha = (mode_ == Mode::OUT) ? static_cast<Uint8>(progress * a_) : static_cast<Uint8>((1.0F - progress) * a_);
if (mode_ == Mode::OUT) {
current_alpha = static_cast<Uint8>(progress * a_); // 0 → 255
} else {
current_alpha = static_cast<Uint8>((1.0f - progress) * a_); // 255 → 0
} }
}
if (current_alpha > 0) { if (current_alpha > 0) {
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, current_alpha); SDL_SetRenderDrawColor(renderer_, r_, g_, b_, current_alpha);
SDL_RenderFillRect(renderer_, &square_[i]); SDL_RenderFillRect(renderer_, &square_[i]);
@@ -425,9 +329,10 @@ void Fade::drawDiagonal() {
} }
void Fade::drawRandomSquares(int active_count) { void Fade::drawRandomSquares(int active_count) {
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// El fondo se prepara en activate()
SDL_BlendMode blend_mode; SDL_BlendMode blend_mode;
SDL_GetRenderDrawBlendMode(renderer_, &blend_mode); SDL_GetRenderDrawBlendMode(renderer_, &blend_mode);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
@@ -443,42 +348,24 @@ void Fade::drawRandomSquares(int active_count) {
} }
void Fade::drawRandomSquares2() { void Fade::drawRandomSquares2() {
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// CRÍTICO: Limpiar la textura antes de dibujar
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
SDL_BlendMode blend_mode; SDL_BlendMode blend_mode;
SDL_GetRenderDrawBlendMode(renderer_, &blend_mode); SDL_GetRenderDrawBlendMode(renderer_, &blend_mode);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); // Usar BLEND para alpha SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
Uint32 current_time = SDL_GetTicks() - random_squares_start_time_; Uint32 current_time = SDL_GetTicks() - fading_start_time_;
// Lógica unificada: sobre textura transparente, pintar cuadrados según su estado
for (size_t i = 0; i < square_.size(); ++i) { for (size_t i = 0; i < square_.size(); ++i) {
Uint8 current_alpha = 0; Uint8 current_alpha = 0;
if (square_age_[i] == -1) { if (square_age_[i] == -1) {
// Cuadrado no activado current_alpha = (mode_ == Mode::OUT) ? 0 : a_;
if (mode_ == Mode::OUT) {
current_alpha = 0; // OUT: transparente si no activado
} else { } else {
current_alpha = a_; // IN: opaco si no activado
}
} else {
// Cuadrado activado - calculamos progreso
Uint32 square_elapsed = current_time - square_age_[i]; Uint32 square_elapsed = current_time - square_age_[i];
float progress = std::min(static_cast<float>(square_elapsed) / square_transition_duration_, 1.0f); float progress = std::min(static_cast<float>(square_elapsed) / square_transition_duration_, 1.0F);
current_alpha = (mode_ == Mode::OUT) ? static_cast<Uint8>(progress * a_) : static_cast<Uint8>((1.0F - progress) * a_);
if (mode_ == Mode::OUT) {
current_alpha = static_cast<Uint8>(progress * a_); // 0 → 255
} else {
current_alpha = static_cast<Uint8>((1.0f - progress) * a_); // 255 → 0
} }
}
if (current_alpha > 0) { if (current_alpha > 0) {
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, current_alpha); SDL_SetRenderDrawColor(renderer_, r_, g_, b_, current_alpha);
SDL_RenderFillRect(renderer_, &square_[i]); SDL_RenderFillRect(renderer_, &square_[i]);
@@ -490,25 +377,45 @@ void Fade::drawRandomSquares2() {
} }
void Fade::updateVenetianFade() { void Fade::updateVenetianFade() {
if (square_.back().h < param.fade.venetian_size) { Uint32 elapsed_time = SDL_GetTicks() - fading_start_time_;
float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Calcula la altura de las persianas
float rect_height = progress * param.fade.venetian_size;
if (mode_ == Mode::IN) {
rect_height = param.fade.venetian_size - rect_height;
}
for (auto& rect : square_) {
rect.h = rect_height;
}
drawVenetianBlinds(); drawVenetianBlinds();
updateVenetianRectangles(); value_ = static_cast<int>(progress * 100);
calculateVenetianProgress();
} else { // Comprueba si ha terminado
if (elapsed_time >= static_cast<Uint32>(fading_duration_)) {
changeToPostState(); changeToPostState();
} }
} }
void Fade::drawVenetianBlinds() { void Fade::drawVenetianBlinds() {
auto *temp = SDL_GetRenderTarget(renderer_); auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// Limpia la textura con el color base (transparente para OUT, opaco para IN)
Uint8 initial_alpha = (mode_ == Mode::OUT) ? 0 : 255;
cleanBackbuffer(r_, g_, b_, initial_alpha);
SDL_BlendMode blend_mode; SDL_BlendMode blend_mode;
SDL_GetRenderDrawBlendMode(renderer_, &blend_mode); SDL_GetRenderDrawBlendMode(renderer_, &blend_mode);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
for (const auto &rect : square_) { // Dibuja las persianas con el color opuesto al fondo
Uint8 draw_alpha = (mode_ == Mode::OUT) ? 255 : 0;
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, draw_alpha);
for (const auto& rect : square_) {
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(renderer_, &rect);
} }
@@ -516,172 +423,99 @@ void Fade::drawVenetianBlinds() {
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(renderer_, temp);
} }
void Fade::updateVenetianRectangles() {
const auto H = counter_ / 2;
for (size_t i = 0; i < square_.size(); ++i) {
square_.at(i).h = i == 0 ? H : std::max(static_cast<int>(square_.at(i - 1).h) - 2, 0);
}
}
void Fade::calculateVenetianProgress() {
int completed = 0;
for (const auto &square : square_) {
if (square.h >= param.fade.venetian_size) {
++completed;
}
}
value_ = calculateValue(0, square_.size() - 1, completed);
}
// Activa el fade // Activa el fade
void Fade::activate() { void Fade::activate() {
// Si ya está habilitado, no hay que volverlo a activar
if (state_ != State::NOT_ENABLED) { if (state_ != State::NOT_ENABLED) {
return; return;
} }
state_ = State::PRE; state_ = State::PRE;
counter_ = 0;
pre_start_time_ = SDL_GetTicks(); pre_start_time_ = SDL_GetTicks();
value_ = 0;
// Preparación inicial de cada tipo
switch (type_) { switch (type_) {
/*case Type::FULLSCREEN:
cleanBackbuffer(r_, g_, b_, (mode_ == Mode::OUT) ? 0 : 255);
SDL_SetTextureAlphaMod(backbuffer_, (mode_ == Mode::OUT) ? 255 : 0);
break;*/
case Type::FULLSCREEN: { case Type::FULLSCREEN: {
// Pinta el backbuffer_ de color sólido // La textura en sí siempre debe ser de un color sólido y opaco.
// La transparencia se gestionará con la modulación de alfa.
cleanBackbuffer(r_, g_, b_, 255); cleanBackbuffer(r_, g_, b_, 255);
// Ahora, inicializamos la modulación de alfa correctamente:
// - IN: Empieza opaco (255) y se desvanece a transparente.
// - OUT: Empieza transparente (0) y se desvanece a opaco.
const Uint8 INITIAL_ALPHA = (mode_ == Mode::IN) ? 255 : 0;
SDL_SetTextureAlphaMod(backbuffer_, INITIAL_ALPHA);
break; break;
} }
case Type::CENTER: { case Type::CENTER:
rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = 0}; rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = 0};
rect2_ = {.x = 0, .y = 0, .w = param.game.width, .h = 0}; rect2_ = {.x = 0, .y = param.game.height, .w = param.game.width, .h = 0};
a_ = 64; a_ = 255;
break; break;
}
case Type::RANDOM_SQUARE: { case Type::RANDOM_SQUARE: {
rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)}; rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)};
square_.clear(); square_.clear();
// Añade los cuadrados al vector
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) { for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) {
rect1_.x = (i % num_squares_width_) * rect1_.w; rect1_.x = (i % num_squares_width_) * rect1_.w;
rect1_.y = (i / num_squares_width_) * rect1_.h; rect1_.y = (i / num_squares_width_) * rect1_.h;
square_.push_back(rect1_); square_.push_back(rect1_);
} }
auto num = square_.size();
// Desordena el vector de cuadrados
auto num = num_squares_width_ * num_squares_height_;
while (num > 1) { while (num > 1) {
auto num_arreu = rand() % num; auto num_arreu = rand() % num;
SDL_FRect temp = square_[num_arreu]; std::swap(square_[num_arreu], square_[--num]);
square_[num_arreu] = square_[num - 1];
square_[num - 1] = temp;
num--;
} }
a_ = (mode_ == Mode::OUT) ? 255 : 0;
// Limpia la textura cleanBackbuffer(r_, g_, b_, (mode_ == Mode::OUT) ? 0 : 255);
a_ = mode_ == Mode::OUT ? 0 : 255;
cleanBackbuffer(r_, g_, b_, a_);
// Deja el color listo para usar
a_ = mode_ == Mode::OUT ? 255 : 0;
// Inicializa el tiempo de inicio
random_squares_start_time_ = SDL_GetTicks();
break;
}
case Type::RANDOM_SQUARE2: {
rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)};
square_.clear();
square_age_.clear();
// Añade los cuadrados al vector
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) {
rect1_.x = (i % num_squares_width_) * rect1_.w;
rect1_.y = (i / num_squares_width_) * rect1_.h;
square_.push_back(rect1_);
square_age_.push_back(-1); // -1 indica cuadrado no activado aún
}
// Desordena el vector de cuadrados y edades
auto num = num_squares_width_ * num_squares_height_;
while (num > 1) {
auto num_arreu = rand() % num;
SDL_FRect temp_rect = square_[num_arreu];
int temp_age = square_age_[num_arreu];
square_[num_arreu] = square_[num - 1];
square_age_[num_arreu] = square_age_[num - 1];
square_[num - 1] = temp_rect;
square_age_[num - 1] = temp_age;
num--;
}
// Textura inicial: OUT transparente, IN opaca
Uint8 initial_alpha = (mode_ == Mode::OUT) ? 0 : 255;
cleanBackbuffer(r_, g_, b_, initial_alpha);
// Deja el color listo para usar (alpha target para los cuadrados)
a_ = 255; // Siempre usar 255 como alpha target
// Inicializa el tiempo de inicio y recalcula la duración de transición
random_squares_start_time_ = SDL_GetTicks();
square_transition_duration_ = std::max(random_squares_duration_ / 4, 100); // Mínimo 100ms
break; break;
} }
case Type::RANDOM_SQUARE2:
case Type::DIAGONAL: { case Type::DIAGONAL: {
rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)}; rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)};
square_.clear(); square_.clear();
square_age_.clear(); square_age_.assign(num_squares_width_ * num_squares_height_, -1);
// Añade los cuadrados al vector en orden (sin desordenar)
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) { for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) {
rect1_.x = (i % num_squares_width_) * rect1_.w; rect1_.x = (i % num_squares_width_) * rect1_.w;
rect1_.y = (i / num_squares_width_) * rect1_.h; rect1_.y = (i / num_squares_width_) * rect1_.h;
square_.push_back(rect1_); square_.push_back(rect1_);
square_age_.push_back(-1); // -1 indica cuadrado no activado aún
} }
// Textura inicial: OUT transparente, IN opaca if (type_ == Type::RANDOM_SQUARE2) {
auto num = square_.size();
while (num > 1) {
auto num_arreu = rand() % num;
std::swap(square_[num_arreu], square_[--num]);
// No es necesario desordenar square_age_ ya que todos son -1
}
}
Uint8 initial_alpha = (mode_ == Mode::OUT) ? 0 : 255; Uint8 initial_alpha = (mode_ == Mode::OUT) ? 0 : 255;
cleanBackbuffer(r_, g_, b_, initial_alpha); cleanBackbuffer(r_, g_, b_, initial_alpha);
a_ = 255;
// Deja el color listo para usar (alpha target para los cuadrados) square_transition_duration_ = std::max(fading_duration_ / 4, 100);
a_ = 255; // Siempre usar 255 como alpha target
// Inicializa el tiempo de inicio y recalcula la duración de transición
random_squares_start_time_ = SDL_GetTicks();
square_transition_duration_ = std::max(random_squares_duration_ / 4, 100); // Mínimo 100ms
break; break;
} }
case Type::VENETIAN: { case Type::VENETIAN: {
// Limpia la textura
a_ = mode_ == Mode::OUT ? 0 : 255;
cleanBackbuffer(r_, g_, b_, a_);
// Deja el color listo para usar
a_ = mode_ == Mode::OUT ? 255 : 0;
// Añade los cuadrados al vector
square_.clear(); square_.clear();
rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = 0}; rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = (mode_ == Mode::OUT) ? 0.0F : param.fade.venetian_size};
const int MAX = param.game.height / param.fade.venetian_size; const int MAX = param.game.height / param.fade.venetian_size;
for (int i = 0; i < MAX; ++i) { for (int i = 0; i < MAX; ++i) {
rect1_.y = i * param.fade.venetian_size; rect1_.y = i * param.fade.venetian_size;
square_.push_back(rect1_); square_.push_back(rect1_);
} }
break; break;
} }
} }
} }
// Establece el color del fade // Establece el color del fade
void Fade::setColor(Uint8 r, Uint8 g, Uint8 b) { void Fade::setColor(Uint8 r, Uint8 g, Uint8 b) {
r_ = r; r_ = r;
@@ -698,27 +532,20 @@ void Fade::setColor(Color color) {
// Limpia el backbuffer // Limpia el backbuffer
void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
// Dibujamos sobre el backbuffer_ auto* temp = SDL_GetRenderTarget(renderer_);
auto *temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
// Pintamos la textura con el color del fade
SDL_SetRenderDrawColor(renderer_, r, g, b, a); SDL_SetRenderDrawColor(renderer_, r, g, b, a);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
// Vuelve a dejar el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(renderer_, temp);
} }
// Calcula el valor del estado del fade // Calcula el valor del estado del fade
auto Fade::calculateValue(int min, int max, int current) -> int { auto Fade::calculateValue(int min, int max, int current) -> int {
if (current < min) { if (current <= min) {
return 0; return 0;
} }
if (current >= max) {
if (current > max) {
return 100; return 100;
} }
return static_cast<int>(100.0 * (current - min) / (max - min)); return static_cast<int>(100.0 * (current - min) / (max - min));
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL.h> // Para Uint8, SDL_FRect, SDL_Renderer, SDL_Texture, Uint16 #include <SDL3/SDL.h> // Para Uint8, SDL_FRect, SDL_Renderer, SDL_Texture, Uint32
#include <vector> // Para vector #include <vector> // Para vector
@@ -39,8 +39,7 @@ class Fade {
// --- Métodos principales --- // --- Métodos principales ---
void reset(); // Resetea variables para reutilizar el fade void reset(); // Resetea variables para reutilizar el fade
void render(); // Dibuja la transición en pantalla void render(); // Dibuja la transición en pantalla
void update(); // Actualiza el estado interno (ya usa tiempo real) void update(float delta_time = 0.0F); // Actualiza el estado interno
void update(float delta_time); // Compatibilidad delta-time (ignora el parámetro)
void activate(); // Activa el fade void activate(); // Activa el fade
// --- Configuración --- // --- Configuración ---
@@ -48,6 +47,7 @@ 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 setDuration(int milliseconds) { fading_duration_ = milliseconds; } // Duración del estado FADING en milisegundos
void setPostDuration(int milliseconds) { post_duration_ = milliseconds; } // Duración posterior al fade en milisegundos void setPostDuration(int milliseconds) { post_duration_ = milliseconds; } // Duración posterior al fade en milisegundos
void setPreDuration(int milliseconds) { pre_duration_ = milliseconds; } // Duración previa al fade en milisegundos void setPreDuration(int milliseconds) { pre_duration_ = milliseconds; } // Duración previa al fade en milisegundos
@@ -58,23 +58,22 @@ class Fade {
private: private:
// --- Objetos y punteros --- // --- Objetos y punteros ---
SDL_Renderer *renderer_; // Renderizador de la ventana SDL_Renderer* renderer_; // Renderizador de la ventana
SDL_Texture *backbuffer_; // Backbuffer para efectos SDL_Texture* backbuffer_; // Backbuffer para efectos
// --- Variables de estado --- // --- Variables de estado ---
std::vector<SDL_FRect> square_; // Vector de cuadrados std::vector<SDL_FRect> square_; // Vector de cuadrados
std::vector<int> square_age_; // Edad de cada cuadrado (para RANDOM_SQUARE2) std::vector<int> square_age_; // Edad de cada cuadrado (para RANDOM_SQUARE2 y DIAGONAL)
SDL_FRect rect1_, rect2_; // Rectángulos para efectos SDL_FRect rect1_, rect2_; // Rectángulos para efectos
Type type_; // Tipo de fade Type type_; // Tipo de fade
Mode mode_; // Modo de fade Mode mode_; // Modo de fade
State state_ = State::NOT_ENABLED; // Estado actual State state_ = State::NOT_ENABLED; // Estado actual
Uint16 counter_; // Contador interno
Uint8 r_, g_, b_, a_; // Color del fade (RGBA) Uint8 r_, g_, b_, a_; // Color del fade (RGBA)
int num_squares_width_; // Cuadrados en horizontal int num_squares_width_; // Cuadrados en horizontal
int num_squares_height_; // Cuadrados en vertical int num_squares_height_; // Cuadrados en vertical
Uint32 random_squares_start_time_; // Tiempo de inicio del fade de cuadrados
int random_squares_duration_; // Duración total en milisegundos
int square_transition_duration_; // Duración de transición de cada cuadrado en ms int square_transition_duration_; // Duración de transición de cada cuadrado en ms
int fading_duration_; // Duración del estado FADING en milisegundos
Uint32 fading_start_time_ = 0; // Tiempo de inicio del estado FADING
int post_duration_ = 0; // Duración posterior en milisegundos int post_duration_ = 0; // Duración posterior en milisegundos
Uint32 post_start_time_ = 0; // Tiempo de inicio del estado POST Uint32 post_start_time_ = 0; // Tiempo de inicio del estado POST
int pre_duration_ = 0; // Duración previa en milisegundos int pre_duration_ = 0; // Duración previa en milisegundos
@@ -101,12 +100,10 @@ class Fade {
void updateRandomSquare2Fade(); // Actualiza el fundido con cuadrados aleatorios (variante 2) void updateRandomSquare2Fade(); // Actualiza el fundido con cuadrados aleatorios (variante 2)
void updateDiagonalFade(); // Actualiza el fundido diagonal void updateDiagonalFade(); // Actualiza el fundido diagonal
void updateVenetianFade(); // Actualiza el fundido tipo persiana veneciana void updateVenetianFade(); // Actualiza el fundido tipo persiana veneciana
void updateVenetianRectangles(); // Actualiza los rectángulos del efecto veneciano
void calculateVenetianProgress(); // Calcula el progreso del efecto veneciano
// --- Dibujo de efectos visuales --- // --- Dibujo de efectos visuales ---
void drawCenterFadeRectangles(); // Dibuja los rectángulos del fundido central void drawCenterFadeRectangles(); // Dibuja los rectángulos del fundido central
void drawRandomSquares(int active_count = -1); // Dibuja los cuadrados aleatorios del fundido void drawRandomSquares(int active_count); // Dibuja los cuadrados aleatorios del fundido
void drawRandomSquares2(); // Dibuja los cuadrados con transición de color (RANDOM_SQUARE2) void drawRandomSquares2(); // Dibuja los cuadrados con transición de color (RANDOM_SQUARE2)
void drawDiagonal(); // Dibuja los cuadrados con patrón diagonal void drawDiagonal(); // Dibuja los cuadrados con patrón diagonal
void activateDiagonal(int diagonal_index, Uint32 current_time); // Activa una diagonal específica void activateDiagonal(int diagonal_index, Uint32 current_time); // Activa una diagonal específica

View File

@@ -1,22 +1,23 @@
#include "game_logo.h" #include "game_logo.hpp"
#include <SDL3/SDL.h> // Para SDL_SetTextureScaleMode, SDL_FlipMode, SDL_ScaleMode #include <SDL3/SDL.h> // Para SDL_SetTextureScaleMode, SDL_FlipMode, SDL_ScaleMode
#include <algorithm> // Para max #include <algorithm> // Para max
#include <string> // Para basic_string
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.hpp" // Para AnimatedSprite
#include "audio.h" // Para Audio #include "audio.hpp" // Para Audio
#include "color.h" // Para Color #include "color.hpp" // Para Color
#include "param.h" // Para Param, param, ParamGame, ParamTitle #include "param.hpp" // Para Param, param, ParamGame, ParamTitle
#include "resource.h" // Para Resource #include "resource.hpp" // Para Resource
#include "screen.h" // Para Screen #include "screen.hpp" // Para Screen
#include "smart_sprite.h" // Para SmartSprite #include "smart_sprite.hpp" // Para SmartSprite
#include "sprite.h" // Para Sprite #include "sprite.hpp" // Para Sprite
#include "texture.h" // Para Texture #include "texture.hpp" // Para Texture
constexpr int ZOOM_FACTOR = 5; constexpr int ZOOM_FACTOR = 5;
constexpr float FLASH_DELAY_S = 0.05f; // 3 frames → 0.05s constexpr float FLASH_DELAY_S = 0.05F; // 3 frames → 0.05s
constexpr float FLASH_DURATION_S = 0.1f; // 6 frames → 0.1s (3 + 3) constexpr float FLASH_DURATION_S = 0.1F; // 6 frames → 0.1s (3 + 3)
constexpr Color FLASH_COLOR = Color(0xFF, 0xFF, 0xFF); // Color blanco para el flash constexpr Color FLASH_COLOR = Color(0xFF, 0xFF, 0xFF); // Color blanco para el flash
// Constructor // Constructor
@@ -46,7 +47,7 @@ void GameLogo::init() {
arcade_edition_status_ = Status::DISABLED; arcade_edition_status_ = Status::DISABLED;
shake_.init(1, 2, 8, XP); shake_.init(1, 2, 8, XP);
zoom_ = 3.0F * ZOOM_FACTOR; zoom_ = 3.0F * ZOOM_FACTOR;
post_finished_timer_ = 0.0f; post_finished_timer_ = 0.0F;
// Inicializa el bitmap de 'Coffee' // Inicializa el bitmap de 'Coffee'
coffee_sprite_->setPosX(XP); coffee_sprite_->setPosX(XP);
@@ -59,7 +60,7 @@ void GameLogo::init() {
coffee_sprite_->setAccelY(COFFEE_ACCEL_Y); coffee_sprite_->setAccelY(COFFEE_ACCEL_Y);
coffee_sprite_->setSpriteClip(0, 0, coffee_texture_->getWidth(), coffee_texture_->getHeight()); coffee_sprite_->setSpriteClip(0, 0, coffee_texture_->getWidth(), coffee_texture_->getHeight());
coffee_sprite_->setEnabled(true); coffee_sprite_->setEnabled(true);
coffee_sprite_->setFinishedDelay(0.0f); coffee_sprite_->setFinishedDelay(0.0F);
coffee_sprite_->setDestX(XP); coffee_sprite_->setDestX(XP);
coffee_sprite_->setDestY(y_ - coffee_texture_->getHeight()); coffee_sprite_->setDestY(y_ - coffee_texture_->getHeight());
@@ -74,7 +75,7 @@ void GameLogo::init() {
crisis_sprite_->setAccelY(CRISIS_ACCEL_Y); crisis_sprite_->setAccelY(CRISIS_ACCEL_Y);
crisis_sprite_->setSpriteClip(0, 0, crisis_texture_->getWidth(), crisis_texture_->getHeight()); crisis_sprite_->setSpriteClip(0, 0, crisis_texture_->getWidth(), crisis_texture_->getHeight());
crisis_sprite_->setEnabled(true); crisis_sprite_->setEnabled(true);
crisis_sprite_->setFinishedDelay(0.0f); crisis_sprite_->setFinishedDelay(0.0F);
crisis_sprite_->setDestX(XP + CRISIS_OFFSET_X); crisis_sprite_->setDestX(XP + CRISIS_OFFSET_X);
crisis_sprite_->setDestY(y_); crisis_sprite_->setDestY(y_);
@@ -115,44 +116,44 @@ void GameLogo::render() {
} }
// Actualiza la lógica de la clase (time-based) // Actualiza la lógica de la clase (time-based)
void GameLogo::update(float deltaTime) { void GameLogo::update(float delta_time) {
updateCoffeeCrisis(deltaTime); updateCoffeeCrisis(delta_time);
updateArcadeEdition(deltaTime); updateArcadeEdition(delta_time);
updatePostFinishedCounter(deltaTime); updatePostFinishedCounter(delta_time);
} }
void GameLogo::updateCoffeeCrisis(float deltaTime) { void GameLogo::updateCoffeeCrisis(float delta_time) {
switch (coffee_crisis_status_) { switch (coffee_crisis_status_) {
case Status::MOVING: case Status::MOVING:
handleCoffeeCrisisMoving(deltaTime); handleCoffeeCrisisMoving(delta_time);
break; break;
case Status::SHAKING: case Status::SHAKING:
handleCoffeeCrisisShaking(deltaTime); handleCoffeeCrisisShaking(delta_time);
break; break;
case Status::FINISHED: case Status::FINISHED:
handleCoffeeCrisisFinished(deltaTime); handleCoffeeCrisisFinished(delta_time);
break; break;
default: default:
break; break;
} }
} }
void GameLogo::updateArcadeEdition(float deltaTime) { void GameLogo::updateArcadeEdition(float delta_time) {
switch (arcade_edition_status_) { switch (arcade_edition_status_) {
case Status::MOVING: case Status::MOVING:
handleArcadeEditionMoving(deltaTime); handleArcadeEditionMoving(delta_time);
break; break;
case Status::SHAKING: case Status::SHAKING:
handleArcadeEditionShaking(deltaTime); handleArcadeEditionShaking(delta_time);
break; break;
default: default:
break; break;
} }
} }
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) { void GameLogo::handleCoffeeCrisisMoving(float delta_time) {
coffee_sprite_->update(deltaTime); coffee_sprite_->update(delta_time);
crisis_sprite_->update(deltaTime); crisis_sprite_->update(delta_time);
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) { if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) {
coffee_crisis_status_ = Status::SHAKING; coffee_crisis_status_ = Status::SHAKING;
@@ -160,23 +161,23 @@ void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
} }
} }
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) { void GameLogo::handleCoffeeCrisisShaking(float delta_time) {
if (shake_.remaining > 0) { if (shake_.remaining > 0) {
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime); processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), delta_time);
} else { } else {
finishCoffeeCrisisShaking(); finishCoffeeCrisisShaking();
} }
updateDustSprites(deltaTime); updateDustSprites(delta_time);
} }
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) { void GameLogo::handleCoffeeCrisisFinished(float delta_time) {
updateDustSprites(deltaTime); updateDustSprites(delta_time);
} }
void GameLogo::handleArcadeEditionMoving(float deltaTime) { void GameLogo::handleArcadeEditionMoving(float delta_time) {
// DeltaTime en segundos: decremento por segundo // DeltaTime en segundos: decremento por segundo
zoom_ -= (ZOOM_DECREMENT_PER_S * ZOOM_FACTOR) * deltaTime; zoom_ -= (ZOOM_DECREMENT_PER_S * ZOOM_FACTOR) * delta_time;
arcade_edition_sprite_->setZoom(zoom_); arcade_edition_sprite_->setZoom(zoom_);
if (zoom_ <= 1.0F) { if (zoom_ <= 1.0F) {
@@ -184,18 +185,17 @@ void GameLogo::handleArcadeEditionMoving(float deltaTime) {
} }
} }
void GameLogo::handleArcadeEditionShaking(float deltaTime) { void GameLogo::handleArcadeEditionShaking(float delta_time) {
if (shake_.remaining > 0) { if (shake_.remaining > 0) {
processArcadeEditionShake(deltaTime); processArcadeEditionShake(delta_time);
} else { } else {
arcade_edition_sprite_->setX(shake_.origin); arcade_edition_sprite_->setX(shake_.origin);
arcade_edition_status_ = Status::FINISHED; arcade_edition_status_ = Status::FINISHED;
} }
} }
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float delta_time) {
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime) { shake_.time_accumulator += delta_time;
shake_.time_accumulator += deltaTime;
if (shake_.time_accumulator >= SHAKE_DELAY_S) { if (shake_.time_accumulator >= SHAKE_DELAY_S) {
shake_.time_accumulator -= SHAKE_DELAY_S; shake_.time_accumulator -= SHAKE_DELAY_S;
@@ -208,14 +208,14 @@ void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* seco
} }
} }
void GameLogo::processArcadeEditionShake(float deltaTime) { void GameLogo::processArcadeEditionShake(float delta_time) {
// Delay fijo en segundos (shake_.delay era frames, ahora usamos constante) // Delay fijo en segundos (shake_.delay era frames, ahora usamos constante)
float delayTime = SHAKE_DELAY_S; float delay_time = SHAKE_DELAY_S;
shake_.time_accumulator += deltaTime; shake_.time_accumulator += delta_time;
if (shake_.time_accumulator >= delayTime) { if (shake_.time_accumulator >= delay_time) {
shake_.time_accumulator -= delayTime; shake_.time_accumulator -= delay_time;
const auto DISPLACEMENT = calculateShakeDisplacement(); const auto DISPLACEMENT = calculateShakeDisplacement();
arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT); arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT);
shake_.remaining--; shake_.remaining--;
@@ -247,16 +247,15 @@ void GameLogo::playTitleEffects() {
Screen::get()->shake(); Screen::get()->shake();
} }
void GameLogo::updateDustSprites(float deltaTime) { void GameLogo::updateDustSprites(float delta_time) {
dust_right_sprite_->update(deltaTime); dust_right_sprite_->update(delta_time);
dust_left_sprite_->update(deltaTime); dust_left_sprite_->update(delta_time);
} }
void GameLogo::updatePostFinishedCounter(float deltaTime) { void GameLogo::updatePostFinishedCounter(float delta_time) {
if (coffee_crisis_status_ == Status::FINISHED && if (coffee_crisis_status_ == Status::FINISHED &&
arcade_edition_status_ == Status::FINISHED) { arcade_edition_status_ == Status::FINISHED) {
post_finished_timer_ += delta_time;
post_finished_timer_ += deltaTime;
} }
} }

View File

@@ -1,125 +0,0 @@
#pragma once
#include <memory> // Para unique_ptr, shared_ptr
#include "animated_sprite.h" // Para AnimatedSprite
#include "smart_sprite.h" // Para SmartSprite
#include "sprite.h" // Para Sprite
class Texture;
// --- Clase GameLogo: gestor del logo del juego ---
class GameLogo {
public:
// --- Constantes ---
static constexpr float COFFEE_VEL_Y = 0.15F * 1000.0F; // Velocidad Y de coffee sprite (pixels/s) - 0.15F * 1000 = 150 pixels/s
static constexpr float COFFEE_ACCEL_Y = 0.00036F * 1000000.0F; // Aceleración Y de coffee sprite (pixels/s²) - 0.00036F * 1000000 = 360 pixels/s²
static constexpr float CRISIS_VEL_Y = -0.15F * 1000.0F; // Velocidad Y de crisis sprite (pixels/s) - -0.15F * 1000 = -150 pixels/s
static constexpr float CRISIS_ACCEL_Y = -0.00036F * 1000000.0F; // Aceleración Y de crisis sprite (pixels/s²) - -0.00036F * 1000000 = -360 pixels/s²
static constexpr int CRISIS_OFFSET_X = 15; // Desplazamiento X de crisis sprite
static constexpr int DUST_SIZE = 16; // Tamaño de dust sprites
static constexpr float ZOOM_DECREMENT_PER_S = 0.006F * 1000.0F; // Decremento de zoom por segundo (0.006F * 1000 = 6.0F per second)
static constexpr float SHAKE_DELAY_S = 33.34F / 1000.0F; // Delay de shake en segundos (33.34ms / 1000 = 0.03334s)
static constexpr float POST_FINISHED_FRAME_TIME_S = 16.67F / 1000.0F; // Tiempo entre decrementos del counter (16.67ms / 1000 = 0.01667s)
// --- Constructores y destructor ---
GameLogo(int x, int y);
~GameLogo() = default;
// --- Métodos principales ---
void render(); // Pinta la clase en pantalla
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
void enable(); // Activa la clase
// --- Getters ---
[[nodiscard]] auto hasFinished() const -> bool; // Indica si ha terminado la animación
private:
// --- Enums ---
enum class Status {
DISABLED, // Deshabilitado
MOVING, // En movimiento
SHAKING, // Temblando
FINISHED, // Terminado
};
// --- Estructuras privadas ---
struct Shake {
int desp = 1; // Pixels de desplazamiento para agitar la pantalla en el eje x
int delay = 2; // Retraso entre cada desplazamiento de la pantalla al agitarse (frame-based)
int length = 8; // Cantidad de desplazamientos a realizar
int remaining = length; // Cantidad de desplazamientos pendientes a realizar
int counter = delay; // Contador para el retraso (frame-based)
float time_accumulator = 0.0f; // Acumulador de tiempo para deltaTime
int origin = 0; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
Shake() = default;
Shake(int d, int de, int l, int o)
: desp(d),
delay(de),
length(l),
remaining(l),
counter(de),
origin(o) {}
void init(int d, int de, int l, int o) {
desp = d;
delay = de;
length = l;
remaining = l;
counter = de;
time_accumulator = 0.0f;
origin = o;
}
};
// --- Objetos y punteros ---
std::shared_ptr<Texture> dust_texture_; // Textura con los graficos del polvo
std::shared_ptr<Texture> coffee_texture_; // Textura con los graficos de la palabra "COFFEE"
std::shared_ptr<Texture> crisis_texture_; // Textura con los graficos de la palabra "CRISIS"
std::shared_ptr<Texture> arcade_edition_texture_; // Textura con los graficos de "Arcade Edition"
std::unique_ptr<AnimatedSprite> dust_left_sprite_; // Sprite del polvo (izquierda)
std::unique_ptr<AnimatedSprite> dust_right_sprite_; // Sprite del polvo (derecha)
std::unique_ptr<SmartSprite> coffee_sprite_; // Sprite de "COFFEE"
std::unique_ptr<SmartSprite> crisis_sprite_; // Sprite de "CRISIS"
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite de "Arcade Edition"
// --- Variables de estado ---
Shake shake_; // Efecto de agitación
Status coffee_crisis_status_ = Status::DISABLED; // Estado de "COFFEE CRISIS"
Status arcade_edition_status_ = Status::DISABLED; // Estado de "ARCADE EDITION"
float x_; // Posición X del logo
float y_; // Posición Y del logo
float zoom_ = 1.0F; // Zoom aplicado al texto "ARCADE EDITION"
float post_finished_delay_s_ = POST_FINISHED_FRAME_TIME_S; // Retraso final tras animaciones (s)
float post_finished_timer_ = 0.0f; // Timer acumulado para retraso final (s)
// --- Inicialización ---
void init(); // Inicializa las variables
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
// --- Actualización de estados específicos ---
void updateCoffeeCrisis(float deltaTime); // Actualiza el estado de "Coffee Crisis" (time-based)
void updateArcadeEdition(float deltaTime); // Actualiza el estado de "Arcade Edition" (time-based)
void updatePostFinishedCounter(float deltaTime); // Actualiza el contador tras finalizar una animación (time-based)
// --- Efectos visuales: movimiento y sacudidas ---
void handleCoffeeCrisisMoving(float deltaTime); // Maneja el movimiento de "Coffee Crisis" (time-based)
void handleCoffeeCrisisShaking(float deltaTime); // Maneja la sacudida de "Coffee Crisis" (time-based)
void handleArcadeEditionMoving(float deltaTime); // Maneja el movimiento de "Arcade Edition" (time-based)
void handleArcadeEditionShaking(float deltaTime); // Maneja la sacudida de "Arcade Edition" (time-based)
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites (frame-based)
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime); // Procesa el efecto de sacudida en sprites (time-based)
void processArcadeEditionShake(float deltaTime); // Procesa la sacudida específica de "Arcade Edition" (time-based)
[[nodiscard]] auto calculateShakeDisplacement() const -> int; // Calcula el desplazamiento de la sacudida
// --- Gestión de finalización de efectos ---
void handleCoffeeCrisisFinished(float deltaTime); // Maneja el final de la animación "Coffee Crisis" (time-based)
void finishCoffeeCrisisShaking(); // Finaliza la sacudida de "Coffee Crisis"
void finishArcadeEditionMoving(); // Finaliza el movimiento de "Arcade Edition"
// --- Utilidades ---
static void playTitleEffects(); // Reproduce efectos visuales/sonoros del título
void updateDustSprites(float deltaTime); // Actualiza los sprites de polvo (time-based)
};

125
source/game_logo.hpp Normal file
View File

@@ -0,0 +1,125 @@
#pragma once
#include <memory> // Para unique_ptr, shared_ptr
#include "animated_sprite.hpp" // Para AnimatedSprite
#include "smart_sprite.hpp" // Para SmartSprite
#include "sprite.hpp" // Para Sprite
class Texture;
// --- Clase GameLogo: gestor del logo del juego ---
class GameLogo {
public:
// --- Constantes ---
static constexpr float COFFEE_VEL_Y = 0.15F * 1000.0F; // Velocidad Y de coffee sprite (pixels/s) - 0.15F * 1000 = 150 pixels/s
static constexpr float COFFEE_ACCEL_Y = 0.00036F * 1000000.0F; // Aceleración Y de coffee sprite (pixels/s²) - 0.00036F * 1000000 = 360 pixels/s²
static constexpr float CRISIS_VEL_Y = -0.15F * 1000.0F; // Velocidad Y de crisis sprite (pixels/s) - -0.15F * 1000 = -150 pixels/s
static constexpr float CRISIS_ACCEL_Y = -0.00036F * 1000000.0F; // Aceleración Y de crisis sprite (pixels/s²) - -0.00036F * 1000000 = -360 pixels/s²
static constexpr int CRISIS_OFFSET_X = 15; // Desplazamiento X de crisis sprite
static constexpr int DUST_SIZE = 16; // Tamaño de dust sprites
static constexpr float ZOOM_DECREMENT_PER_S = 0.006F * 1000.0F; // Decremento de zoom por segundo (0.006F * 1000 = 6.0F per second)
static constexpr float SHAKE_DELAY_S = 33.34F / 1000.0F; // Delay de shake en segundos (33.34ms / 1000 = 0.03334s)
static constexpr float POST_FINISHED_FRAME_TIME_S = 16.67F / 1000.0F; // Tiempo entre decrementos del counter (16.67ms / 1000 = 0.01667s)
// --- Constructores y destructor ---
GameLogo(int x, int y);
~GameLogo() = default;
// --- Métodos principales ---
void render(); // Pinta la clase en pantalla
void update(float delta_time); // Actualiza la lógica de la clase (time-based)
void enable(); // Activa la clase
// --- Getters ---
[[nodiscard]] auto hasFinished() const -> bool; // Indica si ha terminado la animación
private:
// --- Enums ---
enum class Status {
DISABLED, // Deshabilitado
MOVING, // En movimiento
SHAKING, // Temblando
FINISHED, // Terminado
};
// --- Estructuras privadas ---
struct Shake {
int desp = 1; // Pixels de desplazamiento para agitar la pantalla en el eje x
int delay = 2; // Retraso entre cada desplazamiento de la pantalla al agitarse (frame-based)
int length = 8; // Cantidad de desplazamientos a realizar
int remaining = length; // Cantidad de desplazamientos pendientes a realizar
int counter = delay; // Contador para el retraso (frame-based)
float time_accumulator = 0.0F; // Acumulador de tiempo para deltaTime
int origin = 0; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
Shake() = default;
Shake(int d, int de, int l, int o)
: desp(d),
delay(de),
length(l),
remaining(l),
counter(de),
origin(o) {}
void init(int d, int de, int l, int o) {
desp = d;
delay = de;
length = l;
remaining = l;
counter = de;
time_accumulator = 0.0F;
origin = o;
}
};
// --- Objetos y punteros ---
std::shared_ptr<Texture> dust_texture_; // Textura con los graficos del polvo
std::shared_ptr<Texture> coffee_texture_; // Textura con los graficos de la palabra "COFFEE"
std::shared_ptr<Texture> crisis_texture_; // Textura con los graficos de la palabra "CRISIS"
std::shared_ptr<Texture> arcade_edition_texture_; // Textura con los graficos de "Arcade Edition"
std::unique_ptr<AnimatedSprite> dust_left_sprite_; // Sprite del polvo (izquierda)
std::unique_ptr<AnimatedSprite> dust_right_sprite_; // Sprite del polvo (derecha)
std::unique_ptr<SmartSprite> coffee_sprite_; // Sprite de "COFFEE"
std::unique_ptr<SmartSprite> crisis_sprite_; // Sprite de "CRISIS"
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite de "Arcade Edition"
// --- Variables de estado ---
Shake shake_; // Efecto de agitación
Status coffee_crisis_status_ = Status::DISABLED; // Estado de "COFFEE CRISIS"
Status arcade_edition_status_ = Status::DISABLED; // Estado de "ARCADE EDITION"
float x_; // Posición X del logo
float y_; // Posición Y del logo
float zoom_ = 1.0F; // Zoom aplicado al texto "ARCADE EDITION"
float post_finished_delay_s_ = POST_FINISHED_FRAME_TIME_S; // Retraso final tras animaciones (s)
float post_finished_timer_ = 0.0F; // Timer acumulado para retraso final (s)
// --- Inicialización ---
void init(); // Inicializa las variables
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
// --- Actualización de estados específicos ---
void updateCoffeeCrisis(float delta_time); // Actualiza el estado de "Coffee Crisis" (time-based)
void updateArcadeEdition(float delta_time); // Actualiza el estado de "Arcade Edition" (time-based)
void updatePostFinishedCounter(float delta_time); // Actualiza el contador tras finalizar una animación (time-based)
// --- Efectos visuales: movimiento y sacudidas ---
void handleCoffeeCrisisMoving(float delta_time); // Maneja el movimiento de "Coffee Crisis" (time-based)
void handleCoffeeCrisisShaking(float delta_time); // Maneja la sacudida de "Coffee Crisis" (time-based)
void handleArcadeEditionMoving(float delta_time); // Maneja el movimiento de "Arcade Edition" (time-based)
void handleArcadeEditionShaking(float delta_time); // Maneja la sacudida de "Arcade Edition" (time-based)
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites (frame-based)
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float delta_time); // Procesa el efecto de sacudida en sprites (time-based)
void processArcadeEditionShake(float delta_time); // Procesa la sacudida específica de "Arcade Edition" (time-based)
[[nodiscard]] auto calculateShakeDisplacement() const -> int; // Calcula el desplazamiento de la sacudida
// --- Gestión de finalización de efectos ---
void handleCoffeeCrisisFinished(float delta_time); // Maneja el final de la animación "Coffee Crisis" (time-based)
void finishCoffeeCrisisShaking(); // Finaliza la sacudida de "Coffee Crisis"
void finishArcadeEditionMoving(); // Finaliza el movimiento de "Arcade Edition"
// --- Utilidades ---
static void playTitleEffects(); // Reproduce efectos visuales/sonoros del título
void updateDustSprites(float delta_time); // Actualiza los sprites de polvo (time-based)
};

View File

@@ -6,7 +6,7 @@
#include <vector> #include <vector>
#include "external/json.hpp" #include "external/json.hpp"
#include "input_types.h" // Solo incluimos los tipos compartidos #include "input_types.hpp" // Solo incluimos los tipos compartidos
// --- Estructuras --- // --- Estructuras ---
struct GamepadConfig { struct GamepadConfig {

View File

@@ -1,4 +1,4 @@
#include "global_events.h" #include "global_events.hpp"
#include <SDL3/SDL.h> // Para SDL_EventType, SDL_Event, SDL_LogInfo, SDL_LogCategory #include <SDL3/SDL.h> // Para SDL_EventType, SDL_Event, SDL_LogInfo, SDL_LogCategory
@@ -6,19 +6,19 @@
#include <string> // Para allocator, operator+, string #include <string> // Para allocator, operator+, string
#include <vector> // Para vector #include <vector> // Para vector
#include "input.h" // Para Input #include "input.hpp" // Para Input
#include "lang.h" // Para getText #include "lang.hpp" // Para getText
#include "mouse.h" // Para handleEvent #include "mouse.hpp" // Para handleEvent
#include "options.h" // Para GamepadManager, gamepad_manager #include "options.hpp" // Para GamepadManager, gamepad_manager
#include "screen.h" // Para Screen #include "screen.hpp" // Para Screen
#include "section.hpp" // Para Name, Options, name, options #include "section.hpp" // Para Name, Options, name, options
#include "ui/notifier.h" // Para Notifier #include "ui/notifier.hpp" // Para Notifier
#include "ui/service_menu.h" // Para ServiceMenu #include "ui/service_menu.hpp" // Para ServiceMenu
namespace GlobalEvents { namespace GlobalEvents {
// Comprueba los eventos de Input y muestra notificaciones // Comprueba los eventos de Input y muestra notificaciones
void handleInputEvents(const SDL_Event &event) { void handleInputEvents(const SDL_Event& event) {
static auto *input_ = Input::get(); static auto* input_ = Input::get();
auto message = input_->handleEvent(event); auto message = input_->handleEvent(event);
if (message.empty()) { if (message.empty()) {
@@ -41,7 +41,7 @@ void handleInputEvents(const SDL_Event &event) {
} }
// Comprueba los eventos que se pueden producir en cualquier sección del juego // Comprueba los eventos que se pueden producir en cualquier sección del juego
void handle(const SDL_Event &event) { void handle(const SDL_Event& event) {
switch (event.type) { switch (event.type) {
case SDL_EVENT_QUIT: // Evento de salida de la aplicación case SDL_EVENT_QUIT: // Evento de salida de la aplicación
Section::name = Section::Name::QUIT; Section::name = Section::Name::QUIT;

View File

@@ -5,5 +5,5 @@
// --- Namespace GlobalEvents: maneja eventos globales del juego --- // --- Namespace GlobalEvents: maneja eventos globales del juego ---
namespace GlobalEvents { namespace GlobalEvents {
// --- Funciones --- // --- Funciones ---
void handle(const SDL_Event &event); // Comprueba los eventos que se pueden producir en cualquier sección del juego void handle(const SDL_Event& event); // Comprueba los eventos que se pueden producir en cualquier sección del juego
} // namespace GlobalEvents } // namespace GlobalEvents

View File

@@ -1,22 +1,22 @@
#include "global_inputs.h" #include "global_inputs.hpp"
#include <algorithm> // Para std::ranges::any_of #include <algorithm> // Para __any_of_fn, any_of
#include <functional> // Para function #include <functional> // Para function
#include <memory> // Para allocator, shared_ptr #include <iterator> // Para pair
#include <string> // Para operator+, char_traits, string, to_string #include <string> // Para basic_string, operator+, allocator, char_traits, string, to_string
#include <utility> // Para pair #include <utility> // Para pair
#include <vector> // Para vector #include <vector> // Para vector
#include "audio.h" // Para Audio #include "audio.hpp" // Para Audio
#include "input.h" // Para Input #include "input.hpp" // Para Input
#include "input_types.h" // Para InputAction #include "input_types.hpp" // Para InputAction
#include "lang.h" // Para getText, getLangFile, getLangName, getNextLangCode, loadFromFile #include "lang.hpp" // Para getText, getLangFile, getLangName, getNextLangCode, loadFromFile
#include "options.h" // Para Video, video, Settings, settings, Audio, audio, Window, window #include "options.hpp" // Para Video, video, Settings, settings, Audio, audio, Window, window
#include "screen.h" // Para Screen #include "screen.hpp" // Para Screen
#include "section.hpp" // Para Name, name, Options, options, AttractMode, attract_mode #include "section.hpp" // Para Name, name, Options, options, AttractMode, attract_mode
#include "ui/notifier.h" // Para Notifier #include "ui/notifier.hpp" // Para Notifier
#include "ui/service_menu.h" // Para ServiceMenu #include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.h" // Para boolToOnOff #include "utils.hpp" // Para boolToOnOff
namespace GlobalInputs { namespace GlobalInputs {
// Termina // Termina

View File

@@ -1,50 +0,0 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FPoint
#include <memory> // Para std::unique_ptr y std::shared_ptr
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
// --- Estructura Hit: representa una colisión o impacto visual ---
struct Hit {
public:
// --- Constructor ---
Hit() = delete; // Elimina el constructor por defecto para obligar a pasar una textura
explicit Hit(const std::shared_ptr<Texture>& texture) // Constructor con textura obligatoria
: sprite_(std::make_unique<Sprite>(texture)) {}
// --- Métodos principales ---
void create(SDL_FPoint position) { // Crea un "Hit" en la posición especificada
setPos(position);
enable(true);
}
void render() { // Dibuja el hit
if (enabled_) {
sprite_->render();
}
}
void disable() { // Deshabilita el hit
enabled_ = false;
}
// --- Configuración ---
void setPos(SDL_FPoint position) { // Establece la posición del Sprite en el espacio
SDL_FPoint centered_position = {position.x - (sprite_->getWidth() / 2), position.y - (sprite_->getHeight() / 2)};
sprite_->setPosition(centered_position);
}
void enable(bool value) { // Activa o desactiva el Hit
enabled_ = value;
}
// --- Getters ---
[[nodiscard]] auto isEnabled() const -> bool { // Consulta si el Hit está activo
return enabled_;
}
private:
// --- Variables de estado ---
std::unique_ptr<Sprite> sprite_; // Sprite asociado al Hit
bool enabled_{false}; // Indica si el Hit está activo
};

View File

@@ -1,18 +1,20 @@
#include "input.h" #include "input.hpp"
#include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_GetGamepadAxis, SDL_GetError, SDL_GamepadAxis, SDL_JoystickID, SDL_AddGamepadMappingsFromFile, SDL_Event, SDL_EventType, SDL_GetGamepadButton, SDL_GetKeyboardState, SDL_INIT_GAMEPAD, SDL_InitSubSystem, SDL_LogCategory, SDL_LogError, SDL_LogInfo, SDL_OpenGamepad, SDL_PollEvent, SDL_WasInit, SDL_Gamepad, SDL_Scancode #include <SDL3/SDL.h> // Para SDL_GetGamepadAxis, SDL_GamepadAxis, SDL_GamepadButton, SDL_GetError, SDL_JoystickID, SDL_AddGamepadMappingsFromFile, SDL_Event, SDL_EventType, SDL_GetGamepadButton, SDL_GetKeyboardState, SDL_INIT_GAMEPAD, SDL_InitSubSystem, SDL_LogError, SDL_OpenGamepad, SDL_PollEvent, SDL_WasInit, Sint16, SDL_Gamepad, SDL_LogCategory, SDL_Scancode
#include <algorithm> // Para find_if, remove_if #include <iostream> // Para basic_ostream, operator<<, cout, cerr
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
#include <memory> // Para shared_ptr, __shared_ptr_access, allocator, operator==, make_shared #include <memory> // Para shared_ptr, __shared_ptr_access, allocator, operator==, make_shared
#include <unordered_map> // Para unordered_map, operator==, _Node_iterator_base, _Node_iterator, _Node_const_iterator #include <ranges> // Para __find_if_fn, find_if
#include <unordered_map> // Para unordered_map, _Node_iterator, operator==, _Node_iterator_base, _Node_const_iterator
#include <utility> // Para pair, move #include <utility> // Para pair, move
#include "ui/logger.hpp" // Para info
// Singleton // Singleton
Input *Input::instance = nullptr; Input* Input::instance = nullptr;
// Inicializa la instancia única del singleton // Inicializa la instancia única del singleton
void Input::init(const std::string &game_controller_db_path, const std::string &gamepad_configs_file) { void Input::init(const std::string& game_controller_db_path, const std::string& gamepad_configs_file) {
Input::instance = new Input(game_controller_db_path, gamepad_configs_file); Input::instance = new Input(game_controller_db_path, gamepad_configs_file);
} }
@@ -20,7 +22,7 @@ void Input::init(const std::string &game_controller_db_path, const std::string &
void Input::destroy() { delete Input::instance; } void Input::destroy() { delete Input::instance; }
// Obtiene la instancia // Obtiene la instancia
auto Input::get() -> Input * { return Input::instance; } auto Input::get() -> Input* { return Input::instance; }
// Constructor // Constructor
Input::Input(std::string game_controller_db_path, std::string gamepad_configs_file) Input::Input(std::string game_controller_db_path, std::string gamepad_configs_file)
@@ -36,21 +38,21 @@ void Input::bindKey(Action action, SDL_Scancode code) {
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(const std::shared_ptr<Gamepad> &gamepad, Action action, SDL_GamepadButton button) { void Input::bindGameControllerButton(const std::shared_ptr<Gamepad>& gamepad, Action action, SDL_GamepadButton button) {
if (gamepad != nullptr) { if (gamepad != nullptr) {
gamepad->bindings[action].button = button; gamepad->bindings[action].button = button;
} }
} }
// Asigna inputs a botones del mando // Asigna inputs a botones del mando
void Input::bindGameControllerButton(const std::shared_ptr<Gamepad> &gamepad, Action action_target, Action action_source) { void Input::bindGameControllerButton(const std::shared_ptr<Gamepad>& gamepad, Action action_target, Action action_source) {
if (gamepad != nullptr) { if (gamepad != nullptr) {
gamepad->bindings[action_target].button = gamepad->bindings[action_source].button; gamepad->bindings[action_target].button = gamepad->bindings[action_source].button;
} }
} }
// Comprueba si alguna acción está activa // Comprueba si alguna acción está activa
auto Input::checkAction(Action action, bool repeat, bool check_keyboard, const std::shared_ptr<Gamepad> &gamepad) -> bool { auto Input::checkAction(Action action, bool repeat, bool check_keyboard, const std::shared_ptr<Gamepad>& gamepad) -> bool {
bool success_keyboard = false; bool success_keyboard = false;
bool success_controller = false; bool success_controller = false;
@@ -82,12 +84,12 @@ auto Input::checkAction(Action action, bool repeat, bool check_keyboard, const s
} }
// Comprueba si hay almenos una acción activa // Comprueba si hay almenos una acción activa
auto Input::checkAnyInput(bool check_keyboard, const std::shared_ptr<Gamepad> &gamepad) -> bool { auto Input::checkAnyInput(bool check_keyboard, const std::shared_ptr<Gamepad>& gamepad) -> bool {
// Obtenemos el número total de acciones posibles para iterar sobre ellas. // Obtenemos el número total de acciones posibles para iterar sobre ellas.
// --- Comprobación del Teclado --- // --- Comprobación del Teclado ---
if (check_keyboard) { if (check_keyboard) {
for (const auto &pair : keyboard_.bindings) { for (const auto& pair : keyboard_.bindings) {
// Simplemente leemos el estado pre-calculado por Input::update(). // Simplemente leemos el estado pre-calculado por Input::update().
// Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'. // Ya no se llama a SDL_GetKeyboardState ni se modifica el estado '.active'.
if (pair.second.just_pressed) { if (pair.second.just_pressed) {
@@ -100,7 +102,7 @@ auto Input::checkAnyInput(bool check_keyboard, const std::shared_ptr<Gamepad> &g
// Comprobamos si hay mandos y si el índice solicitado es válido. // Comprobamos si hay mandos y si el índice solicitado es válido.
if (gamepad != nullptr) { if (gamepad != nullptr) {
// Iteramos sobre todas las acciones, no sobre el número de mandos. // Iteramos sobre todas las acciones, no sobre el número de mandos.
for (const auto &pair : gamepad->bindings) { for (const auto& pair : gamepad->bindings) {
// Leemos el estado pre-calculado para el mando y la acción específicos. // Leemos el estado pre-calculado para el mando y la acción específicos.
if (pair.second.just_pressed) { if (pair.second.just_pressed) {
return true; // Se encontró una acción recién pulsada en el mando. return true; // Se encontró una acción recién pulsada en el mando.
@@ -122,7 +124,7 @@ auto Input::checkAnyButton(bool repeat) -> bool {
} }
// Comprueba los mandos // Comprueba los mandos
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
if (checkAction(bi, repeat, DO_NOT_CHECK_KEYBOARD, gamepad)) { if (checkAction(bi, repeat, DO_NOT_CHECK_KEYBOARD, gamepad)) {
return true; return true;
} }
@@ -136,14 +138,14 @@ auto Input::checkAnyButton(bool repeat) -> bool {
auto Input::gameControllerFound() const -> bool { return !gamepads_.empty(); } auto Input::gameControllerFound() const -> bool { return !gamepads_.empty(); }
// Obten el nombre de un mando de juego // Obten el nombre de un mando de juego
auto Input::getControllerName(const std::shared_ptr<Gamepad> &gamepad) -> std::string { auto Input::getControllerName(const std::shared_ptr<Gamepad>& gamepad) -> std::string {
return gamepad == nullptr ? std::string() : gamepad->name; return gamepad == nullptr ? std::string() : gamepad->name;
} }
// Obtiene la lista de nombres de mandos // Obtiene la lista de nombres de mandos
auto Input::getControllerNames() const -> std::vector<std::string> { auto Input::getControllerNames() const -> std::vector<std::string> {
std::vector<std::string> names; std::vector<std::string> names;
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
names.push_back(gamepad->name); names.push_back(gamepad->name);
} }
return names; return names;
@@ -154,7 +156,7 @@ auto Input::getNumGamepads() const -> int { return gamepads_.size(); }
// Obtiene el gamepad a partir de un event.id // Obtiene el gamepad a partir de un event.id
auto Input::getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Input::Gamepad> { auto Input::getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Input::Gamepad> {
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
if (gamepad->instance_id == id) { if (gamepad->instance_id == id) {
return gamepad; return gamepad;
} }
@@ -162,8 +164,8 @@ auto Input::getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Input::Gamepa
return nullptr; return nullptr;
} }
auto Input::getGamepadByName(const std::string &name) const -> std::shared_ptr<Input::Gamepad> { auto Input::getGamepadByName(const std::string& name) const -> std::shared_ptr<Input::Gamepad> {
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
if (gamepad && gamepad->name == name) { if (gamepad && gamepad->name == name) {
return gamepad; return gamepad;
} }
@@ -172,7 +174,7 @@ auto Input::getGamepadByName(const std::string &name) const -> std::shared_ptr<I
} }
// Obtiene el SDL_GamepadButton asignado a un action // Obtiene el SDL_GamepadButton asignado a un action
auto Input::getControllerBinding(const std::shared_ptr<Gamepad> &gamepad, Action action) -> SDL_GamepadButton { auto Input::getControllerBinding(const std::shared_ptr<Gamepad>& gamepad, Action action) -> SDL_GamepadButton {
return static_cast<SDL_GamepadButton>(gamepad->bindings[action].button); return static_cast<SDL_GamepadButton>(gamepad->bindings[action].button);
} }
@@ -195,7 +197,7 @@ auto Input::inputToString(Action action) -> std::string {
} }
// Convierte un std::string a InputAction // Convierte un std::string a InputAction
auto Input::stringToInput(const std::string &name) -> Action { auto Input::stringToInput(const std::string& name) -> Action {
static const std::unordered_map<std::string, Action> INPUT_MAP = { static const std::unordered_map<std::string, Action> INPUT_MAP = {
{"input_fire_left", Action::FIRE_LEFT}, {"input_fire_left", Action::FIRE_LEFT},
{"input_fire_center", Action::FIRE_CENTER}, {"input_fire_center", Action::FIRE_CENTER},
@@ -208,7 +210,7 @@ auto Input::stringToInput(const std::string &name) -> Action {
} }
// Comprueba el eje del mando // Comprueba el eje del mando
auto Input::checkAxisInput(Action action, const std::shared_ptr<Gamepad> &gamepad, bool repeat) -> bool { auto Input::checkAxisInput(Action action, const std::shared_ptr<Gamepad>& gamepad, bool repeat) -> bool {
// Umbral para considerar el eje como activo // Umbral para considerar el eje como activo
bool axis_active_now = false; bool axis_active_now = false;
@@ -230,7 +232,7 @@ auto Input::checkAxisInput(Action action, const std::shared_ptr<Gamepad> &gamepa
} }
// Referencia al binding correspondiente // Referencia al binding correspondiente
auto &binding = gamepad->bindings[action]; auto& binding = gamepad->bindings[action];
if (repeat) { if (repeat) {
// Si se permite repetir, simplemente devolvemos el estado actual // Si se permite repetir, simplemente devolvemos el estado actual
@@ -250,7 +252,7 @@ auto Input::checkAxisInput(Action action, const std::shared_ptr<Gamepad> &gamepa
} }
// Comprueba los triggers del mando como botones digitales // Comprueba los triggers del mando como botones digitales
auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad> &gamepad, bool repeat) -> bool { auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad>& gamepad, bool repeat) -> bool {
// Solo manejamos botones específicos que pueden ser triggers // Solo manejamos botones específicos que pueden ser triggers
if (gamepad->bindings[action].button != static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)) { if (gamepad->bindings[action].button != static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)) {
// Solo procesamos L2 y R2 como triggers // Solo procesamos L2 y R2 como triggers
@@ -272,7 +274,7 @@ auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad> &gam
} }
// Referencia al binding correspondiente // Referencia al binding correspondiente
auto &binding = gamepad->bindings[action]; auto& binding = gamepad->bindings[action];
if (repeat) { if (repeat) {
// Si se permite repetir, simplemente devolvemos el estado actual // Si se permite repetir, simplemente devolvemos el estado actual
@@ -318,20 +320,20 @@ void Input::initSDLGamePad() {
addGamepadMappingsFromFile(); addGamepadMappingsFromFile();
loadGamepadConfigs(); loadGamepadConfigs();
discoverGamepads(); discoverGamepads();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Input System initialized successfully\n"); Logger::info("Input System initialized successfully");
} }
} }
} }
void Input::resetInputStates() { void Input::resetInputStates() {
// Resetear todos los KeyBindings.active a false // Resetear todos los KeyBindings.active a false
for (auto &key : keyboard_.bindings) { for (auto& key : keyboard_.bindings) {
key.second.is_held = false; key.second.is_held = false;
key.second.just_pressed = false; key.second.just_pressed = false;
} }
// Resetear todos los ControllerBindings.active a false // Resetear todos los ControllerBindings.active a false
for (auto &gamepad : gamepads_) { for (auto& gamepad : gamepads_) {
for (auto &binding : gamepad->bindings) { for (auto& binding : gamepad->bindings) {
binding.second.is_held = false; binding.second.is_held = false;
binding.second.just_pressed = false; binding.second.just_pressed = false;
binding.second.trigger_active = false; binding.second.trigger_active = false;
@@ -341,9 +343,9 @@ void Input::resetInputStates() {
void Input::update() { void Input::update() {
// --- TECLADO --- // --- TECLADO ---
const bool *key_states = SDL_GetKeyboardState(nullptr); const bool* key_states = SDL_GetKeyboardState(nullptr);
for (auto &binding : keyboard_.bindings) { for (auto& binding : keyboard_.bindings) {
bool key_is_down_now = key_states[binding.second.scancode]; bool key_is_down_now = key_states[binding.second.scancode];
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo // El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
@@ -352,8 +354,8 @@ void Input::update() {
} }
// --- MANDOS --- // --- MANDOS ---
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
for (auto &binding : gamepad->bindings) { for (auto& binding : gamepad->bindings) {
bool button_is_down_now = static_cast<int>(SDL_GetGamepadButton(gamepad->pad, static_cast<SDL_GamepadButton>(binding.second.button))) != 0; bool button_is_down_now = static_cast<int>(SDL_GetGamepadButton(gamepad->pad, static_cast<SDL_GamepadButton>(binding.second.button))) != 0;
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo // El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
@@ -363,7 +365,7 @@ void Input::update() {
} }
} }
auto Input::handleEvent(const SDL_Event &event) -> std::string { auto Input::handleEvent(const SDL_Event& event) -> std::string {
switch (event.type) { switch (event.type) {
case SDL_EVENT_GAMEPAD_ADDED: case SDL_EVENT_GAMEPAD_ADDED:
return addGamepad(event.gdevice.which); return addGamepad(event.gdevice.which);
@@ -374,7 +376,7 @@ auto Input::handleEvent(const SDL_Event &event) -> std::string {
} }
auto Input::addGamepad(int device_index) -> std::string { auto Input::addGamepad(int device_index) -> std::string {
SDL_Gamepad *pad = SDL_OpenGamepad(device_index); SDL_Gamepad* pad = SDL_OpenGamepad(device_index);
if (pad == nullptr) { if (pad == nullptr) {
std::cerr << "Error al abrir el gamepad: " << SDL_GetError() << '\n'; std::cerr << "Error al abrir el gamepad: " << SDL_GetError() << '\n';
return {}; return {};
@@ -390,7 +392,7 @@ auto Input::addGamepad(int device_index) -> std::string {
} }
auto Input::removeGamepad(SDL_JoystickID id) -> std::string { auto Input::removeGamepad(SDL_JoystickID id) -> std::string {
auto it = std::ranges::find_if(gamepads_, [id](const std::shared_ptr<Gamepad> &gamepad) { auto it = std::ranges::find_if(gamepads_, [id](const std::shared_ptr<Gamepad>& gamepad) {
return gamepad->instance_id == id; return gamepad->instance_id == id;
}); });
@@ -411,7 +413,7 @@ void Input::printConnectedGamepads() const {
} }
std::cout << "Gamepads conectados:\n"; std::cout << "Gamepads conectados:\n";
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
std::string name = gamepad->name.empty() ? "Desconocido" : gamepad->name; std::string name = gamepad->name.empty() ? "Desconocido" : gamepad->name;
std::cout << " - ID: " << gamepad->instance_id std::cout << " - ID: " << gamepad->instance_id
<< ", Nombre: " << name << ")" << '\n'; << ", Nombre: " << name << ")" << '\n';
@@ -434,14 +436,14 @@ void Input::applyGamepadConfig(std::shared_ptr<Gamepad> gamepad) {
} }
// --- Buscar configuración por RUTA (path) --- // --- Buscar configuración por RUTA (path) ---
auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad](const GamepadConfig &config) { auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad](const GamepadConfig& config) {
return config.path == gamepad->path; return config.path == gamepad->path;
}); });
if (config_it != gamepad_configs_.end()) { if (config_it != gamepad_configs_.end()) {
// Se encontró una configuración específica para este puerto/dispositivo. La aplicamos. // Se encontró una configuración específica para este puerto/dispositivo. La aplicamos.
std::cout << "Applying custom config for gamepad at path: " << gamepad->path << '\n'; std::cout << "Applying custom config for gamepad at path: " << gamepad->path << '\n';
for (const auto &[action, button] : config_it->bindings) { for (const auto& [action, button] : config_it->bindings) {
if (gamepad->bindings.find(action) != gamepad->bindings.end()) { if (gamepad->bindings.find(action) != gamepad->bindings.end()) {
gamepad->bindings[action].button = button; gamepad->bindings[action].button = button;
} }
@@ -456,7 +458,7 @@ void Input::saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad) {
} }
// --- CAMBIO CLAVE: Buscar si ya existe una configuración por RUTA (path) --- // --- CAMBIO CLAVE: Buscar si ya existe una configuración por RUTA (path) ---
auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad](const GamepadConfig &config) { auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad](const GamepadConfig& config) {
return config.path == gamepad->path; return config.path == gamepad->path;
}); });
@@ -465,7 +467,7 @@ void Input::saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad) {
new_config.bindings.clear(); new_config.bindings.clear();
// Copiar todos los bindings actuales del gamepad // Copiar todos los bindings actuales del gamepad
for (const auto &[action, buttonState] : gamepad->bindings) { for (const auto& [action, buttonState] : gamepad->bindings) {
new_config.bindings[action] = static_cast<SDL_GamepadButton>(buttonState.button); new_config.bindings[action] = static_cast<SDL_GamepadButton>(buttonState.button);
} }
@@ -482,14 +484,14 @@ void Input::saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad) {
} }
// Método para establecer el archivo de configuración (opcional) // Método para establecer el archivo de configuración (opcional)
void Input::setGamepadConfigsFile(const std::string &filename) { void Input::setGamepadConfigsFile(const std::string& filename) {
gamepad_configs_file_ = filename; gamepad_configs_file_ = filename;
loadGamepadConfigs(); // Recargar con el nuevo archivo loadGamepadConfigs(); // Recargar con el nuevo archivo
} }
// Método para obtener configuración de un gamepad específico (opcional) // Método para obtener configuración de un gamepad específico (opcional)
auto Input::getGamepadConfig(const std::string &gamepad_name) -> GamepadConfig * { auto Input::getGamepadConfig(const std::string& gamepad_name) -> GamepadConfig* {
auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad_name](const GamepadConfig &config) { auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad_name](const GamepadConfig& config) {
return config.name == gamepad_name; return config.name == gamepad_name;
}); });
@@ -497,8 +499,8 @@ auto Input::getGamepadConfig(const std::string &gamepad_name) -> GamepadConfig *
} }
// Método para eliminar configuración de gamepad (opcional) // Método para eliminar configuración de gamepad (opcional)
auto Input::removeGamepadConfig(const std::string &gamepad_name) -> bool { auto Input::removeGamepadConfig(const std::string& gamepad_name) -> bool {
auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad_name](const GamepadConfig &config) { auto config_it = std::ranges::find_if(gamepad_configs_, [&gamepad_name](const GamepadConfig& config) {
return config.name == gamepad_name; return config.name == gamepad_name;
}); });
@@ -511,21 +513,21 @@ auto Input::removeGamepadConfig(const std::string &gamepad_name) -> bool {
return false; return false;
} }
auto Input::findAvailableGamepadByName(const std::string &gamepad_name) -> std::shared_ptr<Input::Gamepad> { auto Input::findAvailableGamepadByName(const std::string& gamepad_name) -> std::shared_ptr<Input::Gamepad> {
// Si no hay gamepads disponibles, devolver gamepad por defecto // Si no hay gamepads disponibles, devolver gamepad por defecto
if (gamepads_.empty()) { if (gamepads_.empty()) {
return nullptr; return nullptr;
} }
// Buscar por nombre // Buscar por nombre
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
if (gamepad && gamepad->name == gamepad_name) { if (gamepad && gamepad->name == gamepad_name) {
return gamepad; return gamepad;
} }
} }
// Si no se encuentra por nombre, devolver el primer gamepad válido // Si no se encuentra por nombre, devolver el primer gamepad válido
for (const auto &gamepad : gamepads_) { for (const auto& gamepad : gamepads_) {
if (gamepad) { if (gamepad) {
return gamepad; return gamepad;
} }

Some files were not shown because too many files have changed in this diff Show More