96 Commits

Author SHA1 Message Date
4e083a8cdb item.cpp: afegida rotació 2025-09-30 14:16:25 +02:00
cbe4315701 moving_sprite.cpp: afegit umbral a stopRotate() 2025-09-30 14:11:58 +02:00
49d561b583 moving_sprite.cpp: afegida funcio per a escalar la velocitat de rotacio 2025-09-30 13:59:13 +02:00
6e56a6fd79 moving_sprite.cpp: afegits nous metodes per controlar la rotació 2025-09-30 13:47:48 +02:00
267d9647e0 moving_sprite.cpp: la variable rotate.speed ja no es gastava 2025-09-30 13:38:06 +02:00
13b3702d00 eliminat param.game.item_size 2025-09-30 13:23:50 +02:00
4500845dcd muguda la logica de demo de utils.cpp a demo.cpp 2025-09-30 12:58:32 +02:00
a4abc02f88 nou: modificat el valor de velocitat en la creació dels globos verds. i tornat a deixar com estava 2025-09-30 12:42:38 +02:00
a0fb6934b0 corregit: en el mode demo no calculava correctament el estat del fondo 2025-09-30 09:56:32 +02:00
19645445b2 corregit: els fills dels globos verds eixien taronja 2025-09-30 08:47:49 +02:00
efe8628a3c corregit: el log de CREATING PLAYER TEXTURES en resource.cpp 2025-09-29 14:22:44 +02:00
c98cb0d29f repensada la forma d'asignar fitxers de demo als jugadors
refets els fitxers de demo i afegit un tercer fitxer
2025-09-29 14:00:10 +02:00
c16fc1bae5 corregit: el mode demo ja funciona correctament 2025-09-29 12:47:13 +02:00
fa0af1179a corregit: no trobava version.h 2025-09-29 07:54:46 +02:00
d1e4a5eb07 eliminat tot el define NO_AUDIO del codi 2025-09-27 00:33:05 +02:00
e18d1b186a player.h: eliminat codi mort 2025-09-27 00:22:46 +02:00
d056a5e336 nou: afegida versió de git en la pantalla de carrega 2025-09-27 00:20:46 +02:00
b9e26aa755 corregit: flags estatics en credits.cpp i title.cpp 2025-09-26 23:48:08 +02:00
b2afef2226 corregit: flags estatics en hiscore_tale.cpp 2025-09-26 23:40:37 +02:00
c400aa96c0 corregit: flags estatics en game.cpp 2025-09-26 23:36:49 +02:00
8818954dcd afegit define rapidet per a renderer metal basic en macos 2025-09-26 22:45:14 +02:00
b92e5df98b nou: sonidos de bala diferent per a cada jugador 2025-09-26 20:48:22 +02:00
83871273ec nou: bales de colors diferents per a cada jugador 2025-09-26 20:37:00 +02:00
0459b39366 screen.cpp: getDisplayInfo()
resource.cpp: afegida info del display en la pantalla de carrega
2025-09-26 19:42:39 +02:00
5bb0ff19bc corregit: asset::checkFile() fallava desde fora del directori 2025-09-26 19:16:25 +02:00
a867b3cf4d integrat empaquetador de recursos en el makefile 2025-09-26 18:16:48 +02:00
8a6ce8e66d organitzat player.h 2025-09-26 17:37:29 +02:00
a40f04a739 nou: musiqueta i veu per al game over i timings ajustats 2025-09-26 17:20:35 +02:00
0c670fd344 novetat: canvi de color de les bales quan queda poc powerUp 2025-09-26 14:13:52 +02:00
35f4bf690c corregit: bug en Audio::fadeOutMusic quan la musica no es reproduia en bucle 2025-09-25 21:21:39 +02:00
abeaf47f96 corregit: timing de les celebracions del final 2025-09-25 19:48:58 +02:00
6498c35628 corregit audio i timing del game over 2025-09-25 19:36:40 +02:00
d1c6af02db corregit: la musica del joc soles sonava la primera volta 2025-09-25 19:19:46 +02:00
5edef17d84 nou: musica al completar el joc 2025-09-25 19:10:46 +02:00
e4532fcef2 nou: ruidet per a quan acabes de posar el nom 2025-09-25 18:18:39 +02:00
7a8d66c29d nou: quan arribes a la maxima puntuació, posa un lletreret 2025-09-25 17:52:49 +02:00
54292c9f8f fix: warning de override 2025-09-25 16:58:01 +02:00
3897553704 eliminat el vector precalculat en tiled_bg per al moviment circular 2025-09-25 08:08:29 +02:00
308f5c20fb corregit en background.cpp la desaceleració final, millorada amb funció de suavitzat i arreglades les velocitats dels nuvols que no variaven amb el pas del joc 2025-09-24 21:54:38 +02:00
987dcd0205 fix: el audio del logo.cpp soles sonava la primera volta 2025-09-24 20:54:45 +02:00
d56f23544c corregit menu_renderer.cpp, de vegades es modificava el ample del menu al canviar les opcions 2025-09-24 20:46:07 +02:00
c79a846b29 migrat service_menu.cpp a deltaTime 2025-09-24 19:34:08 +02:00
ad39d55e79 style: static auto *const SCREEN = Screen::get(); 2025-09-24 18:57:10 +02:00
853ef426f0 corregit el START PROMPT en title.cpp que no resetejava el contador de parpadeig 2025-09-24 18:51:36 +02:00
cadf7de3d8 tiled_bg.cpp, afegit changeSpeedTo() 2025-09-24 18:44:37 +02:00
ec65ff9acb corregit audio de timeStopItem 2025-09-24 18:26:39 +02:00
d077374883 migrat a deltaTime screen.cpp i notifier.cpp 2025-09-24 18:08:50 +02:00
40a2b2cc00 afegit TODO per al proxim dia 2025-09-24 14:02:30 +02:00
b3f3f151da corregits alguns parametres de ms a s 2025-09-24 13:56:12 +02:00
3fdd61655a corregit throwCoffee() i el rolling del jugador 2025-09-24 13:24:05 +02:00
504727b95f corregit del delay entre formacions 2025-09-24 13:09:54 +02:00
ff5446fcdf corregit createItemText() 2025-09-24 12:41:41 +02:00
545eb70082 corregida la creacio de globos 2025-09-24 12:37:21 +02:00
232a23a5dd corregida velocitat_y en createChild() 2025-09-24 11:42:48 +02:00
c9a29e26dd revisant la seccio game: bales, items e inici 2025-09-24 11:37:23 +02:00
2977869ab5 revisat tabe.cpp, item.cpp i game.cpp 2025-09-24 09:37:23 +02:00
6a223b68ba revisant title.cpp (falla el jugador) 2025-09-23 14:13:48 +02:00
3fafff026b revisat balloon_formationc.cpp i credits.cpp 2025-09-23 14:03:07 +02:00
159528adc9 revisat credits.cpp, player.cpp, balloon.cpp i balloon_manager.cpp 2025-09-23 13:42:09 +02:00
6c8f231b34 revisat instructions.cpp 2025-09-23 12:10:16 +02:00
c5d6d77ebf revisat hiscore_table.cpp 2025-09-23 11:24:29 +02:00
5e73327b2f revisat intro.cpp, path_sprite i writer.cpp 2025-09-23 11:13:15 +02:00
720d286dcf revisat logo.cpp 2025-09-23 09:11:29 +02:00
dd13a2bd7c revisat background, game_logo, smart sprite, tiled_bg 2025-09-23 09:00:00 +02:00
1a6ef79466 revisat moving i animated sprite 2025-09-23 08:29:29 +02:00
8f83a1d13e magic numbers: moving_sprite.cpp i game_logo.cpp 2025-09-22 13:57:58 +02:00
9edfe6877f magic numbers: item.cpp 2025-09-22 13:14:23 +02:00
91b26631c6 magic numbers: bullet.cpp 2025-09-22 12:14:09 +02:00
331a690b78 fix: balloon_manager.cpp conflicto al crear los globos y detener el tiempo 2025-09-22 10:13:12 +02:00
5e3946e28b fix: no inicialitzava be animated_sprite 2025-09-22 10:03:38 +02:00
d4a0189dc8 arreglant balloon.cpp per a deltaTime pur 2025-09-19 14:15:44 +02:00
568b941990 eliminats metodes frame-based obsolets 2025-09-19 09:56:25 +02:00
49a3989ecf magic numbers: game.cpp 2025-09-19 09:11:10 +02:00
af7cb01ead magic numbers: game.cpp 2025-09-19 07:33:27 +02:00
5c82916650 magic numbers: game.cpp i player.cpp 2025-09-18 14:17:54 +02:00
0c0518adac magic numbers: game.cpp i player.cpp (en progres) 2025-09-18 13:15:43 +02:00
cb7b290818 magic numbers: game.cpp 2025-09-17 14:20:13 +02:00
ae30c9b34f magic numbers: title.cpp 2025-09-17 13:53:31 +02:00
9acd9aa631 magic numbers: intro.cpp 2025-09-17 13:25:16 +02:00
577510ff8c magic numbers: logo.cpp 2025-09-17 13:01:43 +02:00
66566913f6 delta-time: game.cpp (funciona pero va un poc massa ràpid) 2025-09-16 22:56:00 +02:00
3e6cc9dfab delta-time: explosions.cpp 2025-09-16 22:43:16 +02:00
a15e29344f delta-time: balloon.cpp
delta-time: balloon_manager.cpp
delta-time: credits.cpp
2025-09-16 22:38:48 +02:00
a96a17e11b delta-time: tabe.cpp 2025-09-16 20:29:35 +02:00
e0f6a424a9 delta-time: bullet.cpp 2025-09-16 20:26:22 +02:00
49e30f947a delta-time: title.cpp 2025-09-16 20:23:10 +02:00
470a07d28c delta-time: player.cpp 2025-09-16 19:21:44 +02:00
65716fce20 delta-time: tiled_bg.cpp 2025-09-16 17:35:03 +02:00
dfa66b0e95 delta-time: game_logo.cpp
delta-time: smart_sprite.cpp
2025-09-16 17:19:05 +02:00
3d9ffe356e Elimina .claude 2025-09-16 17:18:39 +02:00
19768cb72b delta-time: animated_sprite.cpp 2025-09-16 16:51:31 +02:00
26e0fd7247 delta-time: moving_sprite.cpp 2025-09-16 16:37:39 +02:00
e2fd470ad3 migració a delta time 2025-09-16 12:23:02 +02:00
a72ae0a5fc migració a delta time 2025-09-16 12:06:49 +02:00
7579594c22 migració a delta time 2025-09-16 10:48:22 +02:00
6c702e7e23 Logo: convertit per a usar delta time 2025-09-16 08:40:41 +02:00
129 changed files with 3893 additions and 2510 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.vscode
.claude
build/
data/config/config.txt
*.DS_Store
@@ -17,3 +18,4 @@ debug.txt
cppcheck-result*
desktop.ini
ccae_release/
resources.pack

View File

@@ -14,6 +14,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
cmake_policy(SET CMP0072 NEW)
set(OpenGL_GL_PREFERENCE GLVND)
# --- GENERACIÓN DE VERSIÓN AUTOMÁTICA ---
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
else()
set(GIT_HASH "unknown")
endif()
# Configurar archivo de versión
configure_file(${CMAKE_SOURCE_DIR}/source/version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
# --- 1. LISTA EXPLÍCITA DE FUENTES ---
set(APP_SOURCES
@@ -79,6 +95,7 @@ set(APP_SOURCES
# --- Otros ---
source/color.cpp
source/demo.cpp
source/define_buttons.cpp
source/difficulty.cpp
source/input_types.cpp
@@ -92,17 +109,12 @@ set(APP_SOURCES
# Fuentes de librerías de terceros
set(EXTERNAL_SOURCES
source/external/jail_audio.cpp
source/external/jail_shader.cpp
source/external/json.hpp
source/external/gif.cpp
)
# Añadir jail_audio.cpp solo si el audio está habilitado
if(NOT DISABLE_AUDIO)
list(APPEND EXTERNAL_SOURCES source/external/jail_audio.cpp)
endif()
# Configuración de SDL3
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}")
@@ -114,6 +126,7 @@ add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_SOURCE_DIR}/source"
"${CMAKE_SOURCE_DIR}/source/external"
"${CMAKE_BINARY_DIR}"
)
# Enlazar la librería SDL3
@@ -128,16 +141,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
# Definir _DEBUG en modo Debug
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
# Opción para habilitar/deshabilitar audio
option(DISABLE_AUDIO "Disable audio system" OFF)
# Descomentar la siguiente línea para activar el modo grabación de demos
# target_compile_definitions(${PROJECT_NAME} PRIVATE RECORDING)
# Definir NO_AUDIO si la opción está activada
if(DISABLE_AUDIO)
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_AUDIO)
message(STATUS "Audio deshabilitado - NO_AUDIO definido")
else()
message(STATUS "Audio habilitado")
endif()
# Configuración específica para cada plataforma
if(WIN32)

View File

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

61
TODO.md Normal file
View File

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

View File

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

View File

@@ -8,270 +8,270 @@
formation: 0
# Dos enemigos BALLOON3 uno a cada extremo
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.0000
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.0000
formation: 1
# Dos enemigos BALLOON3 uno a cada cuarto. Ambos van hacia el centro
X3_25, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0
X3_75, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0
X3_25, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.0000
X3_75, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.0000
formation: 2
# Cuatro enemigos BALLOON1 uno detrás del otro. A la izquierda y hacia el centro
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 30
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 20
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 10
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.5000
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.3333
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.1667
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.0000
formation: 3
# Cuatro enemigos BALLOON1 uno detrás del otro. A la derecha y hacia el centro
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 30
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 20
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 10
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.5000
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.3333
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.1667
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.0000
formation: 4
# Tres enemigos BALLOON2. 0, 25, 50. Hacia la derecha
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
formation: 5
# Tres enemigos BALLOON2. 50, 75, 100. Hacia la izquierda
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 6
# Tres enemigos BALLOON2. 0, 0, 0. Hacia la derecha
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
formation: 7
# Tres enemigos BALLOON2. 100, 100, 100. Hacia la izquierda
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 8
# Seis enemigos BALLOON0. 0, 0, 0, 0, 0, 0. Hacia la derecha
X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50
X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40
X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30
X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20
X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10
X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0
X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.8333
X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.6667
X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5000
X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.3333
X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.1667
X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0000
formation: 9
# Seis enemigos BALLOON0. 100, 100, 100, 100, 100, 100. Hacia la izquierda
X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50
X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40
X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30
X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20
X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10
X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0
X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.8333
X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.6667
X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5000
X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.3333
X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.1667
X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0000
formation: 10
# Tres enemigos BALLOON3 seguidos desde la izquierda. Hacia la derecha
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 30
X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 15
X3_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.5000
X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.2500
X3_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.0000
formation: 11
# Tres enemigos BALLOON3 seguidos desde la derecha. Hacia la izquierda
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 30
X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 15
X3_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.5000
X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.2500
X3_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.0000
formation: 12
# Seis enemigos BALLOON1 uno detrás del otro. A la izquierda y hacia el centro
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 50
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 40
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 30
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 20
X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 10
X1_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.8333
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.6667
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.5000
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.3333
X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.1667
X1_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.0000
formation: 13
# Seis enemigos BALLOON1 uno detrás del otro. A la derecha y hacia el centro
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 50
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 40
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 30
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 20
X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 10
X1_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.8333
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.6667
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.5000
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.3333
X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.1667
X1_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.0000
formation: 14
# Cinco enemigos BALLOON2. Hacia la derecha. Separados
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.6667
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.5000
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
formation: 15
# Cinco enemigos BALLOON2. Hacia la izquierda. Separados
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.6667
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.5000
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 16
# Cinco enemigos BALLOON2. Hacia la derecha. Juntos
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.6667
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.5000
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
formation: 17
# Cinco enemigos BALLOON2. Hacia la izquierda. Juntos
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.6667
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.5000
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 18
# Doce enemigos BALLOON0. Hacia la derecha. Juntos
X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 110
X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 100
X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 90
X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 80
X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70
X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60
X0_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50
X0_0, 7, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40
X0_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30
X0_0, 9, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20
X0_0, 10, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10
X0_0, 11, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0
X0_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.8333
X0_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.6667
X0_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.5000
X0_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.3333
X0_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.1667
X0_0, 5, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.0000
X0_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.8333
X0_0, 7, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.6667
X0_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5000
X0_0, 9, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.3333
X0_0, 10, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.1667
X0_0, 11, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0000
formation: 19
# Doce enemigos BALLOON0. Hacia la izquierda. Juntos
X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 110
X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 100
X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 90
X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 80
X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70
X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60
X0_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50
X0_100, -7, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40
X0_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30
X0_100, -9, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20
X0_100, -10, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10
X0_100, -11, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0
X0_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.8333
X0_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.6667
X0_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.5000
X0_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.3333
X0_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.1667
X0_100, -5, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.0000
X0_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.8333
X0_100, -7, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.6667
X0_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5000
X0_100, -9, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.3333
X0_100, -10, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.1667
X0_100, -11, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0000
formation: 20
# Cuatro enemigos BALLOON3 seguidos desde la izquierda/derecha. Simétricos
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0
X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0
X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0
X3_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.0000
X3_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, EXTRALARGE, 0.0000
X3_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.0000
X3_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, EXTRALARGE, 0.0000
formation: 21
# Diez enemigos BALLOON1 uno detrás del otro. Izquierda/derecha. Simétricos
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 12
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 9
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 6
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 3
X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 12
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 9
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 6
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 3
X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0
X1_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.2000
X1_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.1500
X1_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.1000
X1_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.0500
X1_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, MEDIUM, 0.0000
X1_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.2000
X1_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.1500
X1_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.1000
X1_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.0500
X1_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, MEDIUM, 0.0000
formation: 22
# Diez enemigos BALLOON2. Hacia la derecha/izquierda. Separados. Simétricos
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.6667
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.5000
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 6, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 8, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.6667
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.5000
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -6, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -8, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 23
# Diez enemigos BALLOON2. Hacia la derecha. Juntos. Simétricos
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 40
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 30
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 20
X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 10
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 40
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 30
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 20
X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 10
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0
X2_0, 0, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.6667
X2_0, 1, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.5000
X2_0, 2, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.3333
X2_0, 3, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.1667
X2_0, 4, DEFAULT_POS_Y, RIGHT, BALLOON, LARGE, 0.0000
X2_100, 0, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.6667
X2_100, -1, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.5000
X2_100, -2, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.3333
X2_100, -3, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.1667
X2_100, -4, DEFAULT_POS_Y, LEFT, BALLOON, LARGE, 0.0000
formation: 24
# Treinta enemigos BALLOON0. Del centro hacia los extremos. Juntos. Simétricos
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 5
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 15
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 25
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 35
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 45
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 55
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 65
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 5
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 15
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 25
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 35
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 45
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 55
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 65
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0000
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0833
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.1667
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.2500
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.3333
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.4167
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5000
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5833
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.6667
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.7500
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.8333
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.9167
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.0000
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.0833
X0_50, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.1667
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0000
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0833
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.1667
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.2500
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.3333
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.4167
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5000
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5833
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.6667
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.7500
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.8333
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.9167
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.0000
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.0833
X0_50, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.1667
formation: 25
# Treinta enemigos BALLOON0. Del centro hacia adentro. Juntos. Simétricos
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 70
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 65
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 60
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 55
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 50
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 45
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 40
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 35
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 30
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 25
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 20
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 15
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 10
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 5
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 70
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 65
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 60
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 55
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 50
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 45
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 40
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 35
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 30
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 25
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 20
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 15
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 10
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 5
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.1667
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.0833
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 1.0000
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.9167
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.8333
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.7500
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.6667
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5833
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.5000
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.4167
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.3333
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.2500
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.1667
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0833
X0_50 + 20, 0, DEFAULT_POS_Y, LEFT, BALLOON, SMALL, 0.0000
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.1667
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.0833
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 1.0000
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.9167
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.8333
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.7500
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.6667
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5833
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.5000
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.4167
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.3333
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.2500
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.1667
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0833
X0_50 - 20, 0, DEFAULT_POS_Y, RIGHT, BALLOON, SMALL, 0.0000

View File

@@ -2,7 +2,6 @@
# Formato: PARAMETRO VALOR
# --- GAME ---
game.item_size 20 # Tamaño de los items del juego (en píxeles)
game.item_text_outline_color E0E0E0F0 # Color del outline del texto de los items (RGBA hex)
game.width 320 # Ancho de la resolución nativa del juego (en píxeles)
game.height 240 # Alto de la resolución nativa del juego (en píxeles)
@@ -40,7 +39,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
# --- TITLE ---
title.press_start_position 180 # Posición Y del texto "Press Start"
title.title_duration 800 # Duración de la pantalla de título (frames)
title.title_duration 14 # Duración de la pantalla de título (segundos)
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
title.title_c_c_position 80 # Posición Y del título principal
title.bg_color 41526F # Color de fondo en la sección titulo
@@ -48,15 +47,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo
# --- BACKGROUND ---
background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal)
# --- BALLOONS ---
balloon.settings[0].vel 2.75f # Velocidad inicial del globo 1
balloon.settings[0].grav 0.09f # Gravedad aplicada al globo 1
balloon.settings[1].vel 3.70f # Velocidad inicial del globo 2
balloon.settings[1].grav 0.10f # Gravedad aplicada al globo 2
balloon.settings[2].vel 4.70f # Velocidad inicial del globo 3
balloon.settings[2].grav 0.10f # Gravedad aplicada al globo 3
balloon.settings[3].vel 5.45f # Velocidad inicial del globo 4
balloon.settings[3].grav 0.10f # Gravedad aplicada al globo 4
# --- BALLOONS --- (deltaTime en segundos: vel en pixels/s, grav en pixels/s²)
balloon.settings[0].vel 165.0f # Velocidad inicial del globo 1 (pixels/s)
balloon.settings[0].grav 320.0f # Gravedad aplicada al globo 1 (pixels/s²)
balloon.settings[1].vel 222.0f # Velocidad inicial del globo 2 (pixels/s)
balloon.settings[1].grav 360.0f # Gravedad aplicada al globo 2 (pixels/s²)
balloon.settings[2].vel 282.0f # Velocidad inicial del globo 3 (pixels/s)
balloon.settings[2].grav 360.0f # Gravedad aplicada al globo 3 (pixels/s²)
balloon.settings[3].vel 327.0f # Velocidad inicial del globo 4 (pixels/s)
balloon.settings[3].grav 360.0f # Gravedad aplicada al globo 4 (pixels/s²)
balloon.color[0] blue # Color de creación del globo normal
balloon.color[1] orange # Color del globo normal

View File

@@ -40,7 +40,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
# --- TITLE ---
title.press_start_position 180 # Posición Y del texto "Press Start"
title.title_duration 800 # Duración de la pantalla de título (frames)
title.title_duration 14 # Duración de la pantalla de título (segundos)
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
title.title_c_c_position 80 # Posición Y del título principal
title.bg_color 41526F # Color de fondo en la sección titulo
@@ -48,15 +48,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo
# --- BACKGROUND ---
background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal)
# --- BALLOONS ---
balloon.settings[0].vel 2.75f # Velocidad inicial del globo 1
balloon.settings[0].grav 0.09f # Gravedad aplicada al globo 1
balloon.settings[1].vel 3.70f # Velocidad inicial del globo 2
balloon.settings[1].grav 0.10f # Gravedad aplicada al globo 2
balloon.settings[2].vel 4.70f # Velocidad inicial del globo 3
balloon.settings[2].grav 0.10f # Gravedad aplicada al globo 3
balloon.settings[3].vel 5.45f # Velocidad inicial del globo 4
balloon.settings[3].grav 0.10f # Gravedad aplicada al globo 4
# --- BALLOONS --- (deltaTime en segundos: vel en pixels/s, grav en pixels/s²)
balloon.settings[0].vel 165.0f # Velocidad inicial del globo 1 (pixels/s)
balloon.settings[0].grav 320.0f # Gravedad aplicada al globo 1 (pixels/s²)
balloon.settings[1].vel 222.0f # Velocidad inicial del globo 2 (pixels/s)
balloon.settings[1].grav 360.0f # Gravedad aplicada al globo 2 (pixels/s²)
balloon.settings[2].vel 282.0f # Velocidad inicial del globo 3 (pixels/s)
balloon.settings[2].grav 360.0f # Gravedad aplicada al globo 3 (pixels/s²)
balloon.settings[3].vel 327.0f # Velocidad inicial del globo 4 (pixels/s)
balloon.settings[3].grav 360.0f # Gravedad aplicada al globo 4 (pixels/s²)
balloon.color[0] blue # Color de creación del globo normal
balloon.color[1] orange # Color del globo normal

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
data/demo/demo3.bin Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -3,28 +3,28 @@ frame_height=10
[animation]
name=orange
speed=10
speed=0.1667
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
speed=0.3333
loop=0
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
speed=0.1667
loop=0
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
speed=0.3333
loop=0
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

View File

@@ -3,28 +3,28 @@ frame_height=16
[animation]
name=orange
speed=10
speed=0.1667
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
speed=0.3333
loop=0
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
speed=0.1667
loop=0
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
speed=0.3333
loop=0
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

View File

@@ -3,28 +3,28 @@ frame_height=26
[animation]
name=orange
speed=10
speed=0.1667
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
speed=0.3333
loop=0
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
speed=0.1667
loop=0
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
speed=0.3333
loop=0
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

View File

@@ -3,28 +3,28 @@ frame_height=48
[animation]
name=orange
speed=10
speed=0.1667
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
speed=0.3333
loop=0
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
speed=0.1667
loop=0
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
speed=0.3333
loop=0
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=10
[animation]
name=default
speed=5
speed=0.0833
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation]
name=default
speed=5
speed=0.0833
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=26
[animation]
name=default
speed=5
speed=0.0833
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=48
[animation]
name=default
speed=5
speed=0.0833
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=49
[animation]
name=powerball
speed=10
speed=0.0167
loop=-1
frames=1
[/animation]

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=39
[animation]
name=default
speed=6
speed=0.1
loop=0
frames=0,1,2,3,4,5,6,7,8
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=20
[animation]
name=default
speed=8
speed=0.1333
loop=0
frames=0,0,1
[/animation]

View File

@@ -3,133 +3,133 @@ frame_height=32
[animation]
name=walk
speed=5
speed=0.0833
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand
speed=10
speed=0.167
loop=0
frames=4,5,6,7
[/animation]
[animation]
name=walk-fire-side
speed=5
speed=0.0833
loop=0
frames=8,9,10,11
[/animation]
[animation]
name=walk-recoil-side
speed=5
speed=0.0833
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk-cool-side
speed=5
speed=0.0833
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand-fire-side
speed=5
speed=0.0833
loop=0
frames=20
[/animation]
[animation]
name=stand-recoil-side
speed=5
speed=0.0833
loop=0
frames=21
[/animation]
[animation]
name=stand-cool-side
speed=5
speed=0.0833
loop=0
frames=22
[/animation]
[animation]
name=walk-fire-center
speed=5
speed=0.0833
loop=0
frames=23,24,25,26
[/animation]
[animation]
name=walk-recoil-center
speed=5
speed=0.0833
loop=0
frames=27,28,29,30
[/animation]
[animation]
name=walk-cool-center
speed=5
speed=0.0833
loop=0
frames=31,32,33,34
[/animation]
[animation]
name=stand-fire-center
speed=5
speed=0.0833
loop=0
frames=35
[/animation]
[animation]
name=stand-recoil-center
speed=5
speed=0.0833
loop=0
frames=36
[/animation]
[animation]
name=stand-cool-center
speed=5
speed=0.0833
loop=0
frames=37
[/animation]
[animation]
name=rolling
speed=10
speed=0.167
loop=0
frames=38,39,40,41
[/animation]
[animation]
name=celebration
speed=10
loop=-1
speed=0.167
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
[/animation]
[animation]
name=dizzy
speed=5
speed=0.0833
loop=0
frames=47,48,49,50,51,52,53
[/animation]
[animation]
name=recover
speed=3
speed=0.05
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
[/animation]
[animation]
name=hello
speed=3
speed=0.05
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
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=44
[animation]
name=default
speed=5
speed=0.0833
loop=0
frames=0,1,2,3
[/animation]

View File

@@ -3,14 +3,14 @@ frame_height=32
[animation]
name=fly
speed=2
speed=0.0333
loop=0
frames=0,1
[/animation]
[animation]
name=hit
speed=2
speed=0.0333
loop=0
frames=2,3
[/animation]

View File

@@ -3,7 +3,7 @@ frame_height=16
[animation]
name=default
speed=8
speed=0.1333
loop=-1
frames=0,1,2,3,4,5,6
[/animation]

View File

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

View File

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

View File

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

Binary file not shown.

BIN
data/sound/bullet2p.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

43
development_guidelines.md Normal file
View File

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

View File

@@ -43,6 +43,10 @@ auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffe
std::vector<std::string> buffer;
std::string line;
while (std::getline(input_stream, line)) {
// Eliminar caracteres de retorno de carro (\r) al final de la línea
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (!line.empty()) {
buffer.push_back(line);
}
@@ -82,33 +86,33 @@ auto AnimatedSprite::getAnimationIndex(const std::string& name) -> int {
return -1;
}
// Calcula el frame correspondiente a la animación
void AnimatedSprite::animate() {
// Calcula el frame correspondiente a la animación (time-based)
void AnimatedSprite::animate(float deltaTime) {
if (animations_[current_animation_].speed == 0 || animations_[current_animation_].paused) {
return;
}
// Calcula el frame actual a partir del contador
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
// Acumular tiempo transcurrido
animations_[current_animation_].time_accumulator += deltaTime;
// Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop y coloca el nuevo frame
// Verificar si es momento de cambiar frame
if (animations_[current_animation_].time_accumulator >= animations_[current_animation_].speed) {
animations_[current_animation_].time_accumulator -= animations_[current_animation_].speed;
animations_[current_animation_].current_frame++;
// Si alcanza el final de la animación
if (animations_[current_animation_].current_frame >= animations_[current_animation_].frames.size()) {
if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size() - 1;
animations_[current_animation_].completed = true;
} else { // Si hay loop, vuelve al frame indicado
animations_[current_animation_].counter = 0;
animations_[current_animation_].time_accumulator = 0.0f;
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
}
}
// En caso contrario
else {
// Escoge el frame correspondiente de la animación
updateSpriteClip();
// Incrementa el contador de la animacion
animations_[current_animation_].counter++;
// Actualizar el sprite clip
updateSpriteClip();
}
}
@@ -125,11 +129,11 @@ void AnimatedSprite::setCurrentAnimation(const std::string& name, bool reset) {
current_animation_ = NEW_ANIMATION;
if (reset) {
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].time_accumulator = 0.0f;
animations_[current_animation_].completed = false;
} else {
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size() - 1);
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
}
updateSpriteClip();
@@ -144,27 +148,27 @@ void AnimatedSprite::setCurrentAnimation(int index, bool reset) {
current_animation_ = NEW_ANIMATION;
if (reset) {
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].time_accumulator = 0.0f;
animations_[current_animation_].completed = false;
} else {
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
animations_[current_animation_].time_accumulator = animations_[OLD_ANIMATION].time_accumulator;
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
}
updateSpriteClip();
}
}
// Actualiza las variables del objeto
void AnimatedSprite::update() {
animate();
MovingSprite::update();
// Actualiza las variables del objeto (time-based)
void AnimatedSprite::update(float deltaTime) {
animate(deltaTime);
MovingSprite::update(deltaTime);
}
// Reinicia la animación
void AnimatedSprite::resetAnimation() {
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].time_accumulator = 0.0f;
animations_[current_animation_].completed = false;
animations_[current_animation_].paused = false;
updateSpriteClip();
@@ -190,6 +194,12 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer& so
// Pone un valor por defecto
setWidth(config.frame_width);
setHeight(config.frame_height);
// Establece el primer frame inmediatamente si hay animaciones
if (!animations_.empty()) {
current_animation_ = 0;
updateSpriteClip();
}
}
// Procesa una línea de configuración
@@ -259,7 +269,7 @@ void AnimatedSprite::processAnimationParameter(const std::string& line, Animatio
if (key == "name") {
animation.name = value;
} else if (key == "speed") {
animation.speed = std::stoi(value);
animation.speed = std::stof(value);
} else if (key == "loop") {
animation.loop = std::stoi(value);
} else if (key == "frames") {
@@ -286,7 +296,7 @@ void AnimatedSprite::parseFramesParameter(const std::string& frames_str, Animati
}
// Establece la velocidad de la animación
void AnimatedSprite::setAnimationSpeed(size_t value) {
void AnimatedSprite::setAnimationSpeed(float value) {
animations_[current_animation_].speed = value;
}

View File

@@ -17,15 +17,15 @@ class Texture;
// --- Estructuras ---
struct Animation {
static constexpr int DEFAULT_SPEED = 5;
static constexpr float DEFAULT_SPEED = 80.0F;
std::string name; // Nombre de la animación
std::vector<SDL_FRect> frames; // Frames que componen la animación
int speed{DEFAULT_SPEED}; // Velocidad de reproducción
float speed{DEFAULT_SPEED}; // Velocidad de reproducción (ms entre frames)
int loop{0}; // Frame de vuelta al terminar (-1 para no repetir)
bool completed{false}; // Indica si la animación ha finalizado
size_t current_frame{0}; // Frame actual en reproducción
int counter{0}; // Contador para la animación
float time_accumulator{0.0f}; // Acumulador de tiempo para animaciones time-based
bool paused{false}; // La animación no avanza
Animation() = default;
@@ -55,14 +55,14 @@ class AnimatedSprite : public MovingSprite {
~AnimatedSprite() override = default;
// --- Métodos principales ---
void update() override; // Actualiza la animación
void update(float deltaTime) override; // Actualiza la animación (time-based)
// --- Control de animaciones ---
void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre
void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice
void resetAnimation(); // Reinicia la animación actual
void setAnimationSpeed(size_t value); // Establece la velocidad de la animación
auto getAnimationSpeed() const -> size_t { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
void setAnimationSpeed(float value); // Establece la velocidad de la animación
auto getAnimationSpeed() const -> float { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
void animtionPause() { animations_[current_animation_].paused = true; } // Detiene la animación
void animationResume() { animations_[current_animation_].paused = false; } // Reanuda la animación
auto getCurrentAnimationFrame() const -> size_t { return animations_[current_animation_].current_frame; } // Obtiene el numero de frame de la animación actual
@@ -78,7 +78,7 @@ class AnimatedSprite : public MovingSprite {
int current_animation_ = 0; // Índice de la animación activa
// --- Métodos internos ---
void animate(); // Calcula el frame correspondiente a la animación
void animate(float deltaTime); // 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 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

View File

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

View File

@@ -57,7 +57,7 @@ class Asset {
std::string executable_path_; // Ruta del ejecutable
// --- Métodos internos ---
[[nodiscard]] static auto checkFile(const std::string &path) -> bool; // Verifica si un archivo existe
[[nodiscard]] auto checkFile(const std::string &path) const -> bool; // Verifica si un archivo existe
[[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo
[[nodiscard]] static auto 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

View File

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

View File

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

View File

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

View File

@@ -31,7 +31,7 @@ class Background {
~Background(); // Destructor
// --- Métodos principales ---
void update(); // Actualiza la lógica del objeto
void update(float delta_time); // Actualiza la lógica del objeto
void render(); // Dibuja el objeto
void reset(); // Reinicia la progresión
@@ -61,9 +61,9 @@ class Background {
private:
// --- Constantes ---
static constexpr size_t STAGES = 4; // Número de etapas
static constexpr float COMPLETED_REDUCTION_RATE = 25.0F; // Tasa de reducción completada
static constexpr float MINIMUM_COMPLETED_PROGRESS = 200.0F; // Progreso mínimo completado
static constexpr float MINIMUM_COMPLETED_PROGRESS_PERCENTAGE = 0.05F; // Porcentaje mínimo completado (10%)
static constexpr float SUN_COMPLETION_FACTOR = 0.5F; // Factor de completado del sol
static constexpr float COMPLETION_TRANSITION_DURATION_S = 3.0F; // Duración de la transición de completado en segundos
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // Renderizador de la ventana
@@ -90,6 +90,7 @@ class Background {
const float total_progress_to_complete_; // Progreso total para completar
const float progress_per_stage_; // Progreso por etapa
const float sun_completion_progress_; // Progreso de completado del sol
const float minimum_completed_progress_; // Progreso mínimo calculado dinámicamente
ProgressCallback progress_callback_; // Callback para notificar cambios de progreso
// --- Variables de estado ---
@@ -107,7 +108,8 @@ class Background {
float clouds_speed_ = 0; // Velocidad de las nubes
float transition_ = 0; // Porcentaje de transición
size_t gradient_number_ = 0; // Índice de fondo degradado
size_t counter_ = 0; // Contador interno
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 previous_alpha_color_texture_ = 0; // Transparencia anterior
size_t sun_index_ = 0; // Índice del recorrido del sol
@@ -116,20 +118,24 @@ class Background {
Uint8 alpha_ = 0; // Transparencia entre fases
bool manual_mode_ = false; // Si está en modo manual
// --- Variables para transición suave de completado ---
float completion_transition_timer_ = 0.0f; // Timer para la transición de completado
float completion_initial_progress_ = 0.0f; // Progreso inicial al entrar en estado completado
// --- Métodos internos ---
void initializePaths(); // Inicializa las rutas del sol y la luna
void initializeRects(); // Inicializa los rectángulos de gradientes y nubes
void initializeSprites(); // Crea los sprites
void initializeSpriteProperties(); // Configura las propiedades iniciales de los sprites
void initializeTextures(); // Inicializa las texturas de renderizado
void updateProgression(); // Actualiza la progresión y calcula transiciones
void updateProgression(float delta_time); // Actualiza la progresión y calcula transiciones
void updateCloudsSpeed(); // Actualiza la velocidad de las nubes según el estado
void renderGradient(); // Dibuja el gradiente de fondo
void renderTopClouds(); // Dibuja las nubes superiores
void renderBottomClouds(); // Dibuja las nubes inferiores
void fillCanvas(); // Compone todos los elementos en la textura
void updateAlphaColorTexture(); // Actualiza el alpha de la textura de atenuación
void updateClouds(); // Actualiza el movimiento de las nubes
void updateClouds(float deltaTime); // Actualiza el movimiento de las nubes (time-based)
void createSunPath(); // Precalcula el recorrido del sol
void createMoonPath(); // Precalcula el recorrido de la luna
};

View File

@@ -23,13 +23,13 @@ Balloon::Balloon(const Config& config)
creation_counter_ini_(config.creation_counter),
type_(config.type),
size_(config.size),
speed_(config.speed),
game_tempo_(config.game_tempo),
play_area_(config.play_area),
sound_(config.sound) {
switch (type_) {
case Type::BALLOON: {
vy_ = 0;
max_vy_ = 3.0F;
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
const int INDEX = static_cast<int>(size_);
gravity_ = param.balloon.settings.at(INDEX).grav;
@@ -65,12 +65,12 @@ Balloon::Balloon(const Config& config)
power_ = score_ = menace_ = 0;
vy_ = 0;
max_vy_ = 3.0F;
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
gravity_ = param.balloon.settings.at(INDEX).grav;
default_vy_ = param.balloon.settings.at(INDEX).vel;
sprite_->setRotate(config.creation_counter <= 0);
sprite_->setRotateAmount(vx_ > 0.0F ? 2.0 : -2.0);
sprite_->setRotateAmount(vx_ > 0.0F ? 120.0 : -120.0); // Convert from 2 degrees/frame to 120 degrees/second
break;
}
@@ -89,6 +89,12 @@ Balloon::Balloon(const Config& config)
// Establece la animación a usar
setAnimation();
// Si no se está creando (creation_counter = 0), asegurar estado activo
if (!being_created_) {
start();
setInvulnerable(false);
}
}
// Centra el globo en la posición X
@@ -135,19 +141,20 @@ void Balloon::render() {
}
}
// Actualiza la posición y estados del globo
void Balloon::move() {
// Actualiza la posición y estados del globo (time-based)
void Balloon::move(float deltaTime) {
if (isStopped()) {
return;
}
handleHorizontalMovement();
handleVerticalMovement();
applyGravity();
handleHorizontalMovement(deltaTime);
handleVerticalMovement(deltaTime);
applyGravity(deltaTime);
}
void Balloon::handleHorizontalMovement() {
x_ += vx_ * speed_;
void Balloon::handleHorizontalMovement(float deltaTime) {
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
x_ += vx_ * game_tempo_ * deltaTime;
const int CLIP = 2;
const float MIN_X = play_area_.x - CLIP;
@@ -158,8 +165,9 @@ void Balloon::handleHorizontalMovement() {
}
}
void Balloon::handleVerticalMovement() {
y_ += vy_ * speed_;
void Balloon::handleVerticalMovement(float deltaTime) {
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
y_ += vy_ * game_tempo_ * deltaTime;
if (shouldCheckTopCollision()) {
handleTopCollision();
@@ -214,20 +222,9 @@ void Balloon::handleBottomCollision() {
}
}
void Balloon::applyGravity() {
/*
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
*/
travel_y_ += speed_;
if (travel_y_ >= 1.0F) {
travel_y_ -= 1.0F;
vy_ += gravity_;
}
void Balloon::applyGravity(float deltaTime) {
// DeltaTime en segundos: aceleración (pixels/s²) * tempo * tiempo (s)
vy_ += gravity_ * game_tempo_ * deltaTime;
}
void Balloon::playBouncingSound() {
@@ -242,19 +239,20 @@ void Balloon::playPoppingSound() {
}
}
// Actualiza al globo a su posicion, animación y controla los contadores
void Balloon::update() {
move();
updateState();
// Actualiza al globo a su posicion, animación y controla los contadores (time-based)
void Balloon::update(float deltaTime) {
move(deltaTime);
updateState(deltaTime);
updateBounceEffect();
shiftSprite();
shiftColliders();
sprite_->update();
++counter_;
sprite_->update(deltaTime);
// Contador interno con deltaTime en segundos
counter_ += deltaTime;
}
// Actualiza los estados del globo
void Balloon::updateState() {
// Actualiza los estados del globo (time-based)
void Balloon::updateState(float deltaTime) {
// Si se está creando
if (isBeingCreated()) {
// Actualiza el valor de las variables
@@ -263,9 +261,14 @@ void Balloon::updateState() {
if (creation_counter_ > 0) {
// Desplaza lentamente el globo hacia abajo y hacia un lado
if (creation_counter_ % 10 == 0) {
// Cada 10/60 segundos (equivalente a 10 frames a 60fps)
movement_accumulator_ += deltaTime;
constexpr float MOVEMENT_INTERVAL_S = 10.0f / 60.0f; // 10 frames = ~0.167s
if (movement_accumulator_ >= MOVEMENT_INTERVAL_S) {
movement_accumulator_ -= MOVEMENT_INTERVAL_S;
y_++;
x_ += vx_;
x_ += vx_ / 60.0f; // Convierte de pixels/segundo a pixels/frame para movimiento discreto
// Comprueba no se salga por los laterales
const int MIN_X = play_area_.x;
@@ -273,11 +276,12 @@ void Balloon::updateState() {
if (x_ < MIN_X || x_ > MAX_X) {
// Corrige y cambia el sentido de la velocidad
x_ -= vx_;
x_ -= vx_ / 60.0f;
vx_ = -vx_;
}
}
--creation_counter_;
creation_counter_ -= deltaTime;
if (creation_counter_ < 0) creation_counter_ = 0;
}
else {
@@ -311,11 +315,14 @@ void Balloon::setAnimation() {
}
// Establece el frame de animación
std::string chosen_animation;
if (use_reversed_colors_) {
sprite_->setCurrentAnimation(creating_animation);
chosen_animation = creating_animation;
} else {
sprite_->setCurrentAnimation(isBeingCreated() ? creating_animation : normal_animation);
chosen_animation = isBeingCreated() ? creating_animation : normal_animation;
}
sprite_->setCurrentAnimation(chosen_animation);
}
// Detiene el globo

View File

@@ -36,10 +36,12 @@ class Balloon {
"balloon_pop2.wav",
"balloon_pop3.wav"};
static constexpr float VELX_POSITIVE = 0.7F;
static constexpr float VELX_NEGATIVE = -0.7F;
// Velocidades horizontales en pixels/segundo (convertidas desde 0.7 pixels/frame a 60fps)
static constexpr float VELX_POSITIVE = 0.7F * 60.0F; // 42 pixels/segundo
static constexpr float VELX_NEGATIVE = -0.7F * 60.0F; // -42 pixels/segundo
static constexpr std::array<float, 5> SPEED = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F};
// Multiplicadores de tempo del juego (sin cambios, son puros multiplicadores)
static constexpr std::array<float, 5> GAME_TEMPO = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F};
static constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
static constexpr int POWERBALL_COUNTER = 8;
@@ -74,8 +76,8 @@ class Balloon {
Type type = Type::BALLOON;
Size size = Size::EXTRALARGE;
float vel_x = VELX_POSITIVE;
float speed = SPEED.at(0);
Uint16 creation_counter = 0;
float game_tempo = GAME_TEMPO.at(0);
float creation_counter = 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::vector<std::string> animation;
@@ -89,8 +91,8 @@ class Balloon {
// --- Métodos principales ---
void alignTo(int x); // Centra el globo en la posición X
void render(); // Pinta el globo en la pantalla
void move(); // Actualiza la posición y estados del globo
void update(); // Actualiza el globo (posición, animación, contadores)
void move(float deltaTime); // 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 stop(); // Detiene el globo
void start(); // Pone el globo en movimiento
void pop(bool should_sound = false); // Explota el globo
@@ -120,7 +122,9 @@ class Balloon {
// --- Setters ---
void setVelY(float vel_y) { vy_ = vel_y; }
void setSpeed(float speed) { speed_ = speed; }
void setVelX(float vel_x) { vx_ = vel_x; }
void alterVelX(float percent) {vx_ *= percent; }
void setGameTempo(float tempo) { game_tempo_ = tempo; }
void setInvulnerable(bool value) { invulnerable_ = value; }
void setBouncingSound(bool value) { sound_.bouncing_enabled = value; }
void setPoppingSound(bool value) { sound_.poping_enabled = value; }
@@ -256,15 +260,15 @@ class Balloon {
bool stopped_; // Si el globo está parado
bool use_reversed_colors_ = false; // Si se usa el color alternativo
Circle collider_; // Círculo de colisión
Uint16 creation_counter_; // Temporizador de creación
Uint16 creation_counter_ini_; // Valor inicial del temporizador de creación
float creation_counter_; // Temporizador de creación
float creation_counter_ini_; // Valor inicial del temporizador de creación
Uint16 score_; // Puntos al destruir el globo
Type type_; // Tipo de globo
Size size_; // Tamaño de globo
Uint8 menace_; // Amenaza que genera el globo
Uint32 counter_ = 0; // Contador interno
float travel_y_ = 1.0F; // Distancia a recorrer en Y antes de aplicar gravedad
float speed_; // Velocidad del globo
float game_tempo_; // Multiplicador de tempo del juego
float movement_accumulator_ = 0.0f; // Acumulador para movimiento durante creación (deltaTime)
Uint8 power_; // Poder que alberga el globo
SDL_FRect play_area_; // Zona de movimiento del globo
Sound sound_; // Configuración de sonido del globo
@@ -280,9 +284,9 @@ class Balloon {
void playPoppingSound(); // Reproduce el sonido de reventar
// --- Movimiento y física ---
void handleHorizontalMovement(); // Maneja el movimiento horizontal
void handleVerticalMovement(); // Maneja el movimiento vertical
void applyGravity(); // Aplica la gravedad al objeto
void handleHorizontalMovement(float deltaTime); // Maneja el movimiento horizontal (time-based)
void handleVerticalMovement(float deltaTime); // Maneja el movimiento vertical (time-based)
void applyGravity(float deltaTime); // Aplica la gravedad al objeto (time-based)
// --- Rebote ---
void enableBounceEffect(); // Activa el efecto de rebote
@@ -297,5 +301,5 @@ class Balloon {
void handleBottomCollision(); // Maneja la colisión inferior
// --- Lógica de estado ---
void updateState(); // Actualiza los estados del globo
void updateState(float deltaTime); // Actualiza los estados del globo (time-based)
};

View File

@@ -155,7 +155,7 @@ auto BalloonFormations::parseBalloonLine(const std::string& line, const std::map
return std::nullopt;
}
int creation_time = DEFAULT_CREATION_TIME + evaluateExpression(tokens.at(6), variables);
float creation_time = CREATION_TIME + evaluateExpression(tokens.at(6), variables); // Base time + offset from formations.txt
return SpawnParams(x + offset, y, vel_x, type, size, creation_time);
} catch (const std::exception&) {
@@ -168,7 +168,7 @@ auto BalloonFormations::evaluateExpression(const std::string& expr, const std::m
// Si es un número directo
if ((std::isdigit(trimmed_expr.at(0)) != 0) || (trimmed_expr.at(0) == '-' && trimmed_expr.length() > 1)) {
return std::stoi(trimmed_expr);
return std::stof(trimmed_expr);
}
// Si es una variable simple
@@ -205,7 +205,7 @@ auto BalloonFormations::evaluateSimpleExpression(const std::string& expr, const
}
// Si no se encuentra operador, intentar como variable o número
return variables.find(expr) != variables.end() ? variables.at(expr) : std::stoi(expr);
return variables.find(expr) != variables.end() ? variables.at(expr) : std::stof(expr);
}
auto BalloonFormations::trim(const std::string& str) -> std::string {
@@ -235,10 +235,10 @@ void BalloonFormations::createFloaterVariants() {
#ifdef _DEBUG
void BalloonFormations::addTestFormation() {
std::vector<SpawnParams> test_params = {
{10, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::SMALL, 200},
{50, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::MEDIUM, 200},
{90, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::LARGE, 200},
{140, -BLOCK, 0, Balloon::Type::FLOATER, Balloon::Size::EXTRALARGE, 200}};
{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
{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
formations_.at(99) = Formation(test_params);
}

View File

@@ -20,13 +20,13 @@ class BalloonFormations {
float vel_x = 0.0F; // Velocidad inicial en el eje X
Balloon::Type type = Balloon::Type::BALLOON; // Tipo de globo
Balloon::Size size = Balloon::Size::SMALL; // Tamaño de globo
Uint16 creation_counter = 0; // Temporizador para la creación del globo
float creation_counter = 0.0f; // Temporizador para la creación del globo
// Constructor por defecto
SpawnParams() = default;
// Constructor con parámetros
SpawnParams(float x, float y, float vel_x, Balloon::Type type, Balloon::Size size, Uint16 creation_counter)
SpawnParams(float x, float y, float vel_x, Balloon::Type type, Balloon::Size size, float creation_counter)
: x(x),
y(y),
vel_x(vel_x),
@@ -82,7 +82,8 @@ class BalloonFormations {
private:
// --- Constantes ---
static constexpr int BALLOON_SPAWN_HEIGHT = 208; // Altura desde el suelo en la que aparecen los globos
static constexpr int DEFAULT_CREATION_TIME = 200; // Tiempo base de creación de los globos para las formaciones
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)
// --- Variables ---
std::vector<Formation> formations_; // Vector con todas las formaciones disponibles

View File

@@ -16,7 +16,7 @@
#include "utils.h"
// Constructor
BalloonManager::BalloonManager(IStageInfo *stage_info)
BalloonManager::BalloonManager(IStageInfo* stage_info)
: explosions_(std::make_unique<Explosions>()),
balloon_formations_(std::make_unique<BalloonFormations>()),
stage_info_(stage_info) { init(); }
@@ -62,18 +62,18 @@ void BalloonManager::init() {
explosions_->addTexture(3, explosions_textures_.at(3), explosions_animations_.at(3));
}
// Actualiza
void BalloonManager::update() {
for (const auto &balloon : balloons_) {
balloon->update();
// Actualiza (time-based)
void BalloonManager::update(float deltaTime) {
for (const auto& balloon : balloons_) {
balloon->update(deltaTime);
}
updateBalloonDeployCounter();
explosions_->update();
updateBalloonDeployCounter(deltaTime);
explosions_->update(deltaTime);
}
// Renderiza los objetos
void BalloonManager::render() {
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
balloon->render();
}
explosions_->render();
@@ -81,12 +81,12 @@ void BalloonManager::render() {
// Crea una formación de globos
void BalloonManager::deployRandomFormation(int stage) {
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
if (balloon_deploy_counter_ == 0) {
// Solo despliega una formación enemiga si el timer ha llegado a cero
if (balloon_deploy_counter_ <= 0.0f) {
// En este punto se decide entre crear una powerball o una formación enemiga
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
createPowerBall(); // Crea una powerball
balloon_deploy_counter_ = 10; // Da un poco de margen para que se creen mas globos
balloon_deploy_counter_ = POWERBALL_DEPLOY_DELAY; // Resetea con pequeño retraso
} else {
// Decrementa el contador de despliegues de globos necesarios para la siguiente PowerBall
if (power_ball_counter_ > 0) {
@@ -113,13 +113,13 @@ void BalloonManager::deployRandomFormation(int stage) {
.type = balloon.type,
.size = balloon.size,
.vel_x = balloon.vel_x,
.speed = balloon_speed_,
.creation_counter = static_cast<Uint16>(creation_time_enabled_ ? balloon.creation_counter : 0)};
.game_tempo = balloon_speed_,
.creation_counter = creation_time_enabled_ ? balloon.creation_counter : 0.0f};
createBalloon(config);
}
// Reinicia el contador para el próximo despliegue
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_COUNTER;
// Reinicia el timer para el próximo despliegue
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY;
}
}
}
@@ -134,7 +134,7 @@ void BalloonManager::deployFormation(int formation_id) {
.type = balloon.type,
.size = balloon.size,
.vel_x = balloon.vel_x,
.speed = balloon_speed_,
.game_tempo = balloon_speed_,
.creation_counter = balloon.creation_counter};
createBalloon(config);
}
@@ -150,7 +150,7 @@ void BalloonManager::deployFormation(int formation_id, float y) {
.type = balloon.type,
.size = balloon.size,
.vel_x = balloon.vel_x,
.speed = balloon_speed_,
.game_tempo = balloon_speed_,
.creation_counter = balloon.creation_counter};
createBalloon(config);
}
@@ -158,15 +158,14 @@ void BalloonManager::deployFormation(int formation_id, float y) {
// Vacia del vector de globos los globos que ya no sirven
void BalloonManager::freeBalloons() {
auto result = std::ranges::remove_if(balloons_, [](const auto &balloon) { return !balloon->isEnabled(); });
auto result = std::ranges::remove_if(balloons_, [](const auto& balloon) { return !balloon->isEnabled(); });
balloons_.erase(result.begin(), balloons_.end());
}
// Actualiza la variable enemyDeployCounter
void BalloonManager::updateBalloonDeployCounter() {
if (balloon_deploy_counter_ > 0) {
--balloon_deploy_counter_;
}
// Actualiza el timer de despliegue de globos (time-based)
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
// DeltaTime en segundos - timer decrementa hasta llegar a cero
balloon_deploy_counter_ -= deltaTime;
}
// Indica si se puede crear una powerball
@@ -174,7 +173,7 @@ auto BalloonManager::canPowerBallBeCreated() -> bool { return (!power_ball_enabl
// Calcula el poder actual de los globos en pantalla
auto BalloonManager::calculateScreenPower() -> int {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto& balloon) { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
}
// Crea un globo nuevo en el vector de globos
@@ -195,7 +194,7 @@ auto BalloonManager::createBalloon(Balloon::Config config) -> std::shared_ptr<Ba
}
// Crea un globo a partir de otro globo
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction) {
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& balloon, const std::string& direction) {
if (can_deploy_balloons_) {
// Calcula parametros
const int PARENT_HEIGHT = balloon->getHeight();
@@ -209,16 +208,31 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
Balloon::Config config = {
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
.type = balloon->getType(),
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
.speed = balloon_speed_,
.game_tempo = balloon_speed_,
.creation_counter = 0};
// Crea el globo
auto b = createBalloon(config);
// Establece parametros
b->setVelY(b->getType() == Balloon::Type::BALLOON ? -2.50F : Balloon::VELX_NEGATIVE * 2.0F);
constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
switch (b->getType()) {
case Balloon::Type::BALLOON: {
b->setVelY(VEL_Y_BALLOON_PER_S);
break;
}
case Balloon::Type::FLOATER: {
const float MODIFIER = (rand() % 2 == 0) ? 1.0F : 1.0F;
b->setVelY(Balloon::VELX_NEGATIVE * 2.0F * MODIFIER);
(rand() % 2 == 0) ? b->alterVelX(1.0F) : b->alterVelX(1.0F);
break;
}
default:
break;
}
// Herencia de estados
if (balloon->isStopped()) { b->stop(); }
@@ -245,7 +259,7 @@ void BalloonManager::createPowerBall() {
.type = Balloon::Type::POWERBALL,
.size = Balloon::Size::EXTRALARGE,
.vel_x = VEL_X.at(LUCK),
.speed = balloon_speed_,
.game_tempo = balloon_speed_,
.creation_counter = 0,
.play_area = play_area_,
.texture = balloon_textures_.at(4),
@@ -266,13 +280,13 @@ void BalloonManager::createPowerBall() {
// Establece la velocidad de los globos
void BalloonManager::setBalloonSpeed(float speed) {
balloon_speed_ = speed;
for (auto &balloon : balloons_) {
balloon->setSpeed(speed);
for (auto& balloon : balloons_) {
balloon->setGameTempo(speed);
}
}
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int {
auto BalloonManager::popBalloon(const std::shared_ptr<Balloon>& balloon) -> int {
stage_info_->addPower(1);
int score = 0;
@@ -280,7 +294,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
balloon->pop(true);
score = destroyAllBalloons();
power_ball_enabled_ = false;
balloon_deploy_counter_ = 20;
balloon_deploy_counter_ = BALLOON_POP_DELAY; // Resetea con retraso
} else {
score = balloon->getScore();
if (balloon->getSize() != Balloon::Size::SMALL) {
@@ -297,7 +311,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
}
// Explosiona un globo. Lo destruye = no crea otros globos
auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int {
auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon>& balloon) -> int {
int score = 0;
// Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos
@@ -332,12 +346,12 @@ auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int {
// Destruye todos los globos
auto BalloonManager::destroyAllBalloons() -> int {
int score = 0;
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
score += destroyBalloon(balloon);
}
balloon_deploy_counter_ = 300;
Screen::get()->flash(Colors::FLASH, 3);
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY;
Screen::get()->flash(Colors::FLASH, 0.05F);
Screen::get()->shake();
return score;
@@ -345,14 +359,16 @@ auto BalloonManager::destroyAllBalloons() -> int {
// Detiene todos los globos
void BalloonManager::stopAllBalloons() {
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
if (!balloon->isBeingCreated()) {
balloon->stop();
}
}
}
// Pone en marcha todos los globos
void BalloonManager::startAllBalloons() {
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
if (!balloon->isBeingCreated()) {
balloon->start();
}
@@ -361,7 +377,7 @@ void BalloonManager::startAllBalloons() {
// Cambia el color de todos los globos
void BalloonManager::reverseColorsToAllBalloons() {
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
if (balloon->isStopped()) {
balloon->useReverseColor();
}
@@ -370,7 +386,7 @@ void BalloonManager::reverseColorsToAllBalloons() {
// Cambia el color de todos los globos
void BalloonManager::normalColorsToAllBalloons() {
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
balloon->useNormalColor();
}
}
@@ -382,13 +398,13 @@ void BalloonManager::createTwoBigBalloons() {
// Obtiene el nivel de ameza actual generado por los globos
auto BalloonManager::getMenace() -> int {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto& balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
}
// Establece el sonido de los globos
void BalloonManager::setSounds(bool value) {
sound_enabled_ = value;
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
balloon->setSound(value);
}
}
@@ -396,14 +412,14 @@ void BalloonManager::setSounds(bool value) {
// Activa o desactiva los sonidos de rebote los globos
void BalloonManager::setBouncingSounds(bool value) {
bouncing_sound_enabled_ = value;
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
balloon->setBouncingSound(value);
}
}
// Activa o desactiva los sonidos de los globos al explotar
void BalloonManager::setPoppingSounds(bool value) {
poping_sound_enabled_ = value;
for (auto &balloon : balloons_) {
for (auto& balloon : balloons_) {
balloon->setPoppingSound(value);
}
}

View File

@@ -28,7 +28,7 @@ class BalloonManager {
~BalloonManager() = default;
// --- Métodos principales ---
void update(); // Actualiza el estado de los globos
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
void render(); // Renderiza los globos en pantalla
// --- Gestión de globos ---
@@ -49,7 +49,7 @@ class BalloonManager {
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
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 updateBalloonDeployCounter(); // Actualiza el contador de despliegue
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
@@ -82,7 +82,9 @@ class BalloonManager {
private:
// --- Constantes ---
static const int DEFAULT_BALLOON_DEPLOY_COUNTER = 300;
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 BALLOON_POP_DELAY = 0.333f; // 20 frames = 0.333 segundos
// --- Objetos y punteros ---
Balloons balloons_; // Vector con los globos activos
@@ -96,9 +98,9 @@ class BalloonManager {
// --- Variables de estado ---
SDL_FRect play_area_ = param.game.play_area.rect;
float balloon_speed_ = Balloon::SPEED.at(0);
float default_balloon_speed_ = Balloon::SPEED.at(0);
int balloon_deploy_counter_ = 0;
float balloon_speed_ = Balloon::GAME_TEMPO.at(0);
float default_balloon_speed_ = Balloon::GAME_TEMPO.at(0);
float balloon_deploy_counter_ = 0;
int power_ball_counter_ = 0;
int last_balloon_deploy_ = 0;
bool power_ball_enabled_ = false;

View File

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

View File

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

View File

@@ -6,6 +6,7 @@
#include "color.h"
#include "ui/notifier.h" // Para Notifier::Position
#include "version.h" // Para Version::APP_NAME
// --- Namespace GameDefaults: configuración centralizada con valores por defecto del juego ---
namespace GameDefaults {
@@ -14,7 +15,6 @@ namespace GameDefaults {
namespace Game {
constexpr float WIDTH = 320.0F;
constexpr float HEIGHT = 256.0F;
constexpr float ITEM_SIZE = 20.0F;
constexpr int NAME_ENTRY_IDLE_TIME = 10;
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
constexpr bool HIT_STOP = false;
@@ -58,7 +58,7 @@ constexpr int SKIP_COUNTDOWN_VALUE = 8;
// --- TITLE ---
namespace Title {
constexpr int PRESS_START_POSITION = 180;
constexpr int DURATION = 800;
constexpr float DURATION_S = 14.0F;
constexpr int ARCADE_EDITION_POSITION = 123;
constexpr int TITLE_C_C_POSITION = 80;
constexpr const char* BG_COLOR = "41526F";
@@ -80,11 +80,12 @@ struct BalloonSettings {
grav(g) {}
};
// Valores para deltaTime en segundos: vel en pixels/s, grav en pixels/s² (aceleración)
constexpr std::array<BalloonSettings, 4> SETTINGS = {{
BalloonSettings(2.75F, 0.09F), // Globo 0
BalloonSettings(3.70F, 0.10F), // Globo 1
BalloonSettings(4.70F, 0.10F), // Globo 2
BalloonSettings(5.45F, 0.10F) // Globo 3
BalloonSettings(165.0F, 320.0F), // Globo 0: vel=165 pixels/s, grav=320 pixels/s²
BalloonSettings(222.0F, 360.0F), // Globo 1: vel=222 pixels/s, grav=360 pixels/s²
BalloonSettings(282.0F, 360.0F), // Globo 2: vel=282 pixels/s, grav=360 pixels/s²
BalloonSettings(327.0F, 360.0F) // Globo 3: vel=327 pixels/s, grav=360 pixels/s²
}};
constexpr std::array<const char*, 4> COLORS = {
@@ -210,7 +211,7 @@ constexpr const char* PLAYER1 = "422028FF";
// --- OPTIONS ---
namespace Options {
// Window
constexpr const char* WINDOW_CAPTION = "Coffee Crisis Arcade Edition";
constexpr const char* WINDOW_CAPTION = Version::APP_NAME;
constexpr int WINDOW_ZOOM = 2;
constexpr int WINDOW_MAX_ZOOM = 2;

View File

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

View File

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

70
source/demo.cpp Normal file
View File

@@ -0,0 +1,70 @@
#include "demo.h"
#include <SDL3/SDL.h> // Para SDL_IOStream, SDL_IOFromConstMem, SDL_IOFromFile, SDL_ReadIO, SDL_WriteIO, SDL_CloseIO
#include <stdexcept> // Para runtime_error
#include "resource_helper.h" // Para ResourceHelper
#include "utils.h" // Para printWithDots, getFileName
// Carga el fichero de datos para la demo
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData {
DemoData dd;
SDL_IOStream *file = nullptr;
// Intentar cargar desde ResourceHelper primero
auto resource_data = ResourceHelper::loadFile(file_path);
if (!resource_data.empty()) {
file = SDL_IOFromConstMem(resource_data.data(), resource_data.size());
} else {
// Fallback a filesystem directo
file = SDL_IOFromFile(file_path.c_str(), "r+b");
}
if (file == nullptr) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
throw std::runtime_error("Fichero no encontrado: " + file_path);
}
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]");
// Lee todos los datos del fichero y los deja en el destino
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {
DemoKeys dk = DemoKeys();
SDL_ReadIO(file, &dk, sizeof(DemoKeys));
dd.push_back(dk);
}
// Cierra el fichero
SDL_CloseIO(file);
return dd;
}
#ifdef RECORDING
// Guarda el fichero de datos para la demo
bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
auto success = true;
auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
if (file) {
// Guarda los datos
for (const auto &data : dd) {
if (SDL_WriteIO(file, &data, sizeof(DemoKeys)) != sizeof(DemoKeys)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
success = false;
break;
}
}
if (success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file %s", getFileName(file_path).c_str());
}
// Cierra el fichero
SDL_CloseIO(file);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Unable to save %s file! %s", getFileName(file_path).c_str(), SDL_GetError());
success = false;
}
return success;
}
#endif // RECORDING

54
source/demo.h Normal file
View File

@@ -0,0 +1,54 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint8
#include <string> // Para string
#include <vector> // Para vector
// --- Constantes ---
constexpr int TOTAL_DEMO_DATA = 2000;
// --- Estructuras ---
struct DemoKeys {
Uint8 left;
Uint8 right;
Uint8 no_input;
Uint8 fire;
Uint8 fire_left;
Uint8 fire_right;
explicit DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
: left(l),
right(r),
no_input(ni),
fire(f),
fire_left(fl),
fire_right(fr) {}
};
// --- Tipos ---
using DemoData = std::vector<DemoKeys>;
struct Demo {
bool enabled = false; // Indica si está activo el modo demo
bool recording = false; // Indica si está activado el modo para grabar la demo
float elapsed_s = 0.0F; // Segundos transcurridos de demo
int index = 0; // Contador para el modo demo
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
Demo() = default;
Demo(bool e, bool r, int c, const DemoKeys& k, const std::vector<DemoData>& d)
: enabled(e),
recording(r),
index(c),
keys(k),
data(d) {}
};
// --- Funciones ---
auto loadDemoDataFromFile(const std::string& file_path) -> DemoData;
#ifdef RECORDING
bool saveDemoFile(const std::string& file_path, const DemoData& dd);
#endif

View File

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

View File

@@ -6,10 +6,10 @@
class Texture; // lines 4-4
// Actualiza la lógica de la clase
void Explosions::update() {
// Actualiza la lógica de la clase (time-based)
void Explosions::update(float deltaTime) {
for (auto &explosion : explosions_) {
explosion->update();
explosion->update(deltaTime);
}
// Vacia el vector de elementos finalizados

View File

@@ -29,7 +29,7 @@ class Explosions {
~Explosions() = default; // Destructor por defecto
// --- Métodos principales ---
void update(); // Actualiza la lógica de la clase
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
void render(); // Dibuja el objeto en pantalla
// --- Configuración ---

View File

@@ -82,6 +82,11 @@ 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() {
// Sistema basado en tiempo únicamente
Uint32 elapsed_time = SDL_GetTicks() - pre_start_time_;

View File

@@ -39,7 +39,8 @@ class Fade {
// --- Métodos principales ---
void reset(); // Resetea variables para reutilizar el fade
void render(); // Dibuja la transición en pantalla
void update(); // Actualiza el estado interno
void update(); // Actualiza el estado interno (ya usa tiempo real)
void update(float delta_time); // Compatibilidad delta-time (ignora el parámetro)
void activate(); // Activa el fade
// --- Configuración ---
@@ -47,8 +48,8 @@ class Fade {
void setColor(Color color); // Establece el color del fade
void setType(Type type) { type_ = type; } // Establece el tipo de fade
void setMode(Mode mode) { mode_ = mode; } // Establece el modo de fade
void setPostDuration(int value) { post_duration_ = value; } // Duración posterior al fade en milisegundos
void setPreDuration(int value) { pre_duration_ = value; } // Duración previa 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
// --- Getters ---
[[nodiscard]] auto getValue() const -> int { return value_; }

View File

@@ -15,8 +15,9 @@
#include "texture.h" // Para Texture
constexpr int ZOOM_FACTOR = 5;
constexpr int FLASH_DELAY = 3;
constexpr int FLASH_LENGTH = FLASH_DELAY + 3;
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 Color FLASH_COLOR = Color(0xFF, 0xFF, 0xFF); // Color blanco para el flash
// Constructor
GameLogo::GameLogo(int x, int y)
@@ -45,6 +46,7 @@ void GameLogo::init() {
arcade_edition_status_ = Status::DISABLED;
shake_.init(1, 2, 8, XP);
zoom_ = 3.0F * ZOOM_FACTOR;
post_finished_timer_ = 0.0f;
// Inicializa el bitmap de 'Coffee'
coffee_sprite_->setPosX(XP);
@@ -52,44 +54,44 @@ void GameLogo::init() {
coffee_sprite_->setWidth(coffee_texture_->getWidth());
coffee_sprite_->setHeight(coffee_texture_->getHeight());
coffee_sprite_->setVelX(0.0F);
coffee_sprite_->setVelY(2.5F);
coffee_sprite_->setVelY(COFFEE_VEL_Y);
coffee_sprite_->setAccelX(0.0F);
coffee_sprite_->setAccelY(0.1F);
coffee_sprite_->setAccelY(COFFEE_ACCEL_Y);
coffee_sprite_->setSpriteClip(0, 0, coffee_texture_->getWidth(), coffee_texture_->getHeight());
coffee_sprite_->setEnabled(true);
coffee_sprite_->setFinishedCounter(0);
coffee_sprite_->setFinishedDelay(0.0f);
coffee_sprite_->setDestX(XP);
coffee_sprite_->setDestY(y_ - coffee_texture_->getHeight());
// Inicializa el bitmap de 'Crisis'
crisis_sprite_->setPosX(XP + 15);
crisis_sprite_->setPosX(XP + CRISIS_OFFSET_X);
crisis_sprite_->setPosY(y_ + DESP);
crisis_sprite_->setWidth(crisis_texture_->getWidth());
crisis_sprite_->setHeight(crisis_texture_->getHeight());
crisis_sprite_->setVelX(0.0F);
crisis_sprite_->setVelY(-2.5F);
crisis_sprite_->setVelY(CRISIS_VEL_Y);
crisis_sprite_->setAccelX(0.0F);
crisis_sprite_->setAccelY(-0.1F);
crisis_sprite_->setAccelY(CRISIS_ACCEL_Y);
crisis_sprite_->setSpriteClip(0, 0, crisis_texture_->getWidth(), crisis_texture_->getHeight());
crisis_sprite_->setEnabled(true);
crisis_sprite_->setFinishedCounter(0);
crisis_sprite_->setDestX(XP + 15);
crisis_sprite_->setFinishedDelay(0.0f);
crisis_sprite_->setDestX(XP + CRISIS_OFFSET_X);
crisis_sprite_->setDestY(y_);
// Inicializa el bitmap de 'DustRight'
dust_right_sprite_->resetAnimation();
dust_right_sprite_->setPosX(coffee_sprite_->getPosX() + coffee_sprite_->getWidth());
dust_right_sprite_->setPosY(y_);
dust_right_sprite_->setWidth(16);
dust_right_sprite_->setHeight(16);
dust_right_sprite_->setWidth(DUST_SIZE);
dust_right_sprite_->setHeight(DUST_SIZE);
dust_right_sprite_->setFlip(SDL_FLIP_HORIZONTAL);
// Inicializa el bitmap de 'DustLeft'
dust_left_sprite_->resetAnimation();
dust_left_sprite_->setPosX(coffee_sprite_->getPosX() - 16);
dust_left_sprite_->setPosX(coffee_sprite_->getPosX() - DUST_SIZE);
dust_left_sprite_->setPosY(y_);
dust_left_sprite_->setWidth(16);
dust_left_sprite_->setHeight(16);
dust_left_sprite_->setWidth(DUST_SIZE);
dust_left_sprite_->setHeight(DUST_SIZE);
// Inicializa el bitmap de 'Arcade Edition'
arcade_edition_sprite_->setZoom(zoom_);
@@ -112,45 +114,45 @@ void GameLogo::render() {
}
}
// Actualiza la lógica de la clase
void GameLogo::update() {
updateCoffeeCrisis();
updateArcadeEdition();
updatePostFinishedCounter();
// Actualiza la lógica de la clase (time-based)
void GameLogo::update(float deltaTime) {
updateCoffeeCrisis(deltaTime);
updateArcadeEdition(deltaTime);
updatePostFinishedCounter(deltaTime);
}
void GameLogo::updateCoffeeCrisis() {
void GameLogo::updateCoffeeCrisis(float deltaTime) {
switch (coffee_crisis_status_) {
case Status::MOVING:
handleCoffeeCrisisMoving();
handleCoffeeCrisisMoving(deltaTime);
break;
case Status::SHAKING:
handleCoffeeCrisisShaking();
handleCoffeeCrisisShaking(deltaTime);
break;
case Status::FINISHED:
handleCoffeeCrisisFinished();
handleCoffeeCrisisFinished(deltaTime);
break;
default:
break;
}
}
void GameLogo::updateArcadeEdition() {
void GameLogo::updateArcadeEdition(float deltaTime) {
switch (arcade_edition_status_) {
case Status::MOVING:
handleArcadeEditionMoving();
handleArcadeEditionMoving(deltaTime);
break;
case Status::SHAKING:
handleArcadeEditionShaking();
handleArcadeEditionShaking(deltaTime);
break;
default:
break;
}
}
void GameLogo::handleCoffeeCrisisMoving() {
coffee_sprite_->update();
crisis_sprite_->update();
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
coffee_sprite_->update(deltaTime);
crisis_sprite_->update(deltaTime);
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) {
coffee_crisis_status_ = Status::SHAKING;
@@ -158,22 +160,23 @@ void GameLogo::handleCoffeeCrisisMoving() {
}
}
void GameLogo::handleCoffeeCrisisShaking() {
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
if (shake_.remaining > 0) {
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get());
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime);
} else {
finishCoffeeCrisisShaking();
}
updateDustSprites();
updateDustSprites(deltaTime);
}
void GameLogo::handleCoffeeCrisisFinished() {
updateDustSprites();
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
updateDustSprites(deltaTime);
}
void GameLogo::handleArcadeEditionMoving() {
zoom_ -= 0.1F * ZOOM_FACTOR;
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
// DeltaTime en segundos: decremento por segundo
zoom_ -= (ZOOM_DECREMENT_PER_S * ZOOM_FACTOR) * deltaTime;
arcade_edition_sprite_->setZoom(zoom_);
if (zoom_ <= 1.0F) {
@@ -181,34 +184,38 @@ void GameLogo::handleArcadeEditionMoving() {
}
}
void GameLogo::handleArcadeEditionShaking() {
void GameLogo::handleArcadeEditionShaking(float deltaTime) {
if (shake_.remaining > 0) {
processArcadeEditionShake();
processArcadeEditionShake(deltaTime);
} else {
arcade_edition_sprite_->setX(shake_.origin);
arcade_edition_status_ = Status::FINISHED;
}
}
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite) {
if (shake_.counter > 0) {
shake_.counter--;
} else {
shake_.counter = shake_.delay;
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime) {
shake_.time_accumulator += deltaTime;
if (shake_.time_accumulator >= SHAKE_DELAY_S) {
shake_.time_accumulator -= SHAKE_DELAY_S;
const auto DISPLACEMENT = calculateShakeDisplacement();
primary_sprite->setPosX(shake_.origin + DISPLACEMENT);
if (secondary_sprite != nullptr) {
secondary_sprite->setPosX(shake_.origin + DISPLACEMENT + 15);
secondary_sprite->setPosX(shake_.origin + DISPLACEMENT + CRISIS_OFFSET_X);
}
shake_.remaining--;
}
}
void GameLogo::processArcadeEditionShake() {
if (shake_.counter > 0) {
shake_.counter--;
} else {
shake_.counter = shake_.delay;
void GameLogo::processArcadeEditionShake(float deltaTime) {
// Delay fijo en segundos (shake_.delay era frames, ahora usamos constante)
float delayTime = SHAKE_DELAY_S;
shake_.time_accumulator += deltaTime;
if (shake_.time_accumulator >= delayTime) {
shake_.time_accumulator -= delayTime;
const auto DISPLACEMENT = calculateShakeDisplacement();
arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT);
shake_.remaining--;
@@ -221,7 +228,7 @@ auto GameLogo::calculateShakeDisplacement() const -> int {
void GameLogo::finishCoffeeCrisisShaking() {
coffee_sprite_->setPosX(shake_.origin);
crisis_sprite_->setPosX(shake_.origin + 15);
crisis_sprite_->setPosX(shake_.origin + CRISIS_OFFSET_X);
coffee_crisis_status_ = Status::FINISHED;
arcade_edition_status_ = Status::MOVING;
}
@@ -236,20 +243,20 @@ void GameLogo::finishArcadeEditionMoving() {
void GameLogo::playTitleEffects() {
Audio::get()->playSound("title.wav");
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGTH, FLASH_DELAY);
Screen::get()->flash(FLASH_COLOR, FLASH_DURATION_S, FLASH_DELAY_S);
Screen::get()->shake();
}
void GameLogo::updateDustSprites() {
dust_right_sprite_->update();
dust_left_sprite_->update();
void GameLogo::updateDustSprites(float deltaTime) {
dust_right_sprite_->update(deltaTime);
dust_left_sprite_->update(deltaTime);
}
void GameLogo::updatePostFinishedCounter() {
void GameLogo::updatePostFinishedCounter(float deltaTime) {
if (coffee_crisis_status_ == Status::FINISHED &&
arcade_edition_status_ == Status::FINISHED &&
post_finished_counter_ > 0) {
--post_finished_counter_;
arcade_edition_status_ == Status::FINISHED) {
post_finished_timer_ += deltaTime;
}
}
@@ -261,7 +268,7 @@ void GameLogo::enable() {
// Indica si ha terminado la animación
auto GameLogo::hasFinished() const -> bool {
return post_finished_counter_ == 0;
return post_finished_timer_ >= post_finished_delay_s_;
}
// Calcula el desplazamiento vertical inicial

View File

@@ -11,13 +11,24 @@ 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(); // Actualiza la lógica de la clase
void update(float deltaTime); // Actualiza la lógica de la clase (time-based)
void enable(); // Activa la clase
// --- Getters ---
@@ -35,10 +46,11 @@ class GameLogo {
// --- 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
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
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;
@@ -56,6 +68,7 @@ class GameLogo {
length = l;
remaining = l;
counter = de;
time_accumulator = 0.0f;
origin = o;
}
};
@@ -79,32 +92,34 @@ class GameLogo {
float x_; // Posición X del logo
float y_; // Posición Y del logo
float zoom_ = 1.0F; // Zoom aplicado al texto "ARCADE EDITION"
int post_finished_counter_ = 1; // Contador final tras animaciones
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(); // Actualiza el estado de "Coffee Crisis"
void updateArcadeEdition(); // Actualiza el estado de "Arcade Edition"
void updatePostFinishedCounter(); // Actualiza el contador tras finalizar una animación
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(); // Maneja el movimiento de "Coffee Crisis"
void handleCoffeeCrisisShaking(); // Maneja la sacudida de "Coffee Crisis"
void handleArcadeEditionMoving(); // Maneja el movimiento de "Arcade Edition"
void handleArcadeEditionShaking(); // Maneja la sacudida de "Arcade Edition"
void processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite = nullptr); // Procesa el efecto de sacudida en sprites
void processArcadeEditionShake(); // Procesa la sacudida específica de "Arcade Edition"
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(); // Maneja el final de la animación "Coffee Crisis"
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(); // Actualiza los sprites de polvo
void updateDustSprites(float deltaTime); // Actualiza los sprites de polvo (time-based)
};

View File

@@ -1,6 +1,7 @@
#include "item.h"
#include <algorithm> // Para clamp
#include <cmath> // Para fmod
#include <cstdlib> // Para rand
#include "animated_sprite.h" // Para AnimatedSprite
@@ -8,7 +9,7 @@
class Texture; // lines 6-6
Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation)
Item::Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation)
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
play_area_(play_area),
type_(type) {
@@ -18,29 +19,31 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha
height_ = COFFEE_MACHINE_HEIGHT;
pos_x_ = getCoffeeMachineSpawn(x, width_, play_area_.w);
pos_y_ = y;
vel_x_ = ((rand() % 3) - 1) * 0.5F;
vel_y_ = -0.1F;
accel_y_ = 0.1F;
vel_x_ = ((rand() % 3) - 1) * COFFEE_MACHINE_VEL_X_FACTOR;
vel_y_ = COFFEE_MACHINE_VEL_Y;
accel_y_ = COFFEE_MACHINE_ACCEL_Y;
collider_.r = 10;
break;
}
default: {
width_ = param.game.item_size;
height_ = param.game.item_size;
pos_x_ = x;
pos_y_ = y;
// 6 velocidades: 3 negativas (-1.0, -0.66, -0.33) y 3 positivas (0.33, 0.66, 1.0)
const int direction = rand() % 6;
if (direction < 3) {
// Velocidades negativas: -1.0, -0.66, -0.33
vel_x_ = -1.0F + (direction * 0.33F);
vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP);
rotate_speed_ = -720.0F;
} else {
// Velocidades positivas: 0.33, 0.66, 1.0
vel_x_ = 0.33F + ((direction - 3) * 0.33F);
vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP);
rotate_speed_ = 720.0F;
}
vel_y_ = -4.0F;
accel_y_ = 0.2F;
vel_y_ = ITEM_VEL_Y;
accel_y_ = ITEM_ACCEL_Y;
collider_.r = width_ / 2;
sprite_->startRotate();
sprite_->setRotateAmount(rotate_speed_);
break;
}
}
@@ -66,24 +69,34 @@ void Item::alignTo(int x) {
void Item::render() {
if (enabled_) {
if (time_to_live_ > 200) {
// Muestra normalmente hasta los últimos ~3.3 segundos
constexpr float BLINK_START_S = LIFETIME_DURATION_S - 3.33f;
if (lifetime_timer_ < BLINK_START_S) {
sprite_->render();
} else if (time_to_live_ % 20 > 10) {
} else {
// Efecto de parpadeo en los últimos segundos (cada ~0.33 segundos)
constexpr float BLINK_INTERVAL_S = 0.33f;
const float phase = fmod(lifetime_timer_, BLINK_INTERVAL_S);
const float half_interval = BLINK_INTERVAL_S / 2.0f;
if (phase < half_interval) {
sprite_->render();
}
}
}
}
void Item::move() {
void Item::move(float deltaTime) {
floor_collision_ = false;
// Calcula la nueva posición
pos_x_ += vel_x_;
pos_y_ += vel_y_;
// Calcula la nueva posición usando deltaTime (velocidad en pixels/segundo)
pos_x_ += vel_x_ * deltaTime;
pos_y_ += vel_y_ * deltaTime;
// Aplica las aceleraciones a la velocidad
vel_x_ += accel_x_;
vel_y_ += accel_y_;
// Aplica las aceleraciones a la velocidad usando deltaTime (aceleración en pixels/segundo²)
vel_x_ += accel_x_ * deltaTime;
vel_y_ += accel_y_ * deltaTime;
// Comprueba los laterales de la zona de juego
const float MIN_X = param.game.play_area.rect.x;
@@ -93,6 +106,7 @@ void Item::move() {
// Si toca el borde lateral
if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
vel_x_ = -vel_x_; // Invierte la velocidad horizontal
sprite_->scaleRotateAmount(-1.0F); // Invierte la rotación
}
// Si colisiona por arriba, rebota (excepto la máquina de café)
@@ -106,31 +120,32 @@ void Item::move() {
// Si colisiona con la parte inferior
if (pos_y_ > play_area_.h - height_) {
// Corrige la posición
pos_y_ = play_area_.h - height_;
pos_y_ = play_area_.h - height_; // Corrige la posición
sprite_->scaleRotateAmount(0.5F); // Reduce la rotación
sprite_->stopRotate(300.0F); // Detiene la rotacion
switch (type_) {
case ItemType::COFFEE_MACHINE:
// La máquina de café es mas pesada y tiene una fisica diferente, ademas hace ruido
floor_collision_ = true;
if (vel_y_ < 1.0F) {
if (std::abs(vel_y_) < BOUNCE_VEL_THRESHOLD) {
// Si la velocidad vertical es baja, detiene el objeto
vel_y_ = vel_x_ = accel_x_ = accel_y_ = 0;
} else {
// Si la velocidad vertical es alta, el objeto rebota y pierde velocidad
vel_y_ *= -0.20F;
vel_x_ *= 0.75F;
vel_y_ *= COFFEE_BOUNCE_DAMPING;
vel_x_ *= HORIZONTAL_DAMPING;
}
break;
default:
// Si no es una máquina de café
if (vel_y_ < 1.0F) {
if (std::abs(vel_y_) < BOUNCE_VEL_THRESHOLD) {
// Si la velocidad vertical es baja, detiene el objeto
vel_y_ = vel_x_ = accel_x_ = accel_y_ = 0;
} else {
// Si la velocidad vertical es alta, el objeto rebota y pierde velocidad
vel_y_ *= -0.5F;
vel_x_ *= 0.75F;
vel_y_ *= ITEM_BOUNCE_DAMPING;
vel_x_ *= HORIZONTAL_DAMPING;
}
break;
}
@@ -143,16 +158,15 @@ void Item::move() {
void Item::disable() { enabled_ = false; }
void Item::update() {
move();
sprite_->update();
updateTimeToLive();
void Item::update(float deltaTime) {
move(deltaTime);
sprite_->update(deltaTime);
updateTimeToLive(deltaTime);
}
void Item::updateTimeToLive() {
if (time_to_live_ > 0) {
time_to_live_--;
} else {
void Item::updateTimeToLive(float deltaTime) {
lifetime_timer_ += deltaTime;
if (lifetime_timer_ >= LIFETIME_DURATION_S) {
disable();
}
}

View File

@@ -27,18 +27,38 @@ enum class ItemType : int {
class Item {
public:
// --- Constantes ---
static constexpr float WIDTH = 20.0F; // Anchura del item
static constexpr float HEIGHT = 20.0F; // ALtura del item
static constexpr int COFFEE_MACHINE_WIDTH = 30; // Anchura de la máquina de café
static constexpr int COFFEE_MACHINE_HEIGHT = 39; // Altura de la máquina de café
static constexpr float LIFETIME_DURATION_S = 10.0f; // Duración de vida del ítem en segundos
// Velocidades base (pixels/segundo) - Coffee Machine
static constexpr float COFFEE_MACHINE_VEL_X_FACTOR = 30.0F; // Factor para velocidad X de máquina de café (0.5*60fps)
static constexpr float COFFEE_MACHINE_VEL_Y = -6.0F; // Velocidad Y inicial de máquina de café (-0.1*60fps)
static constexpr float COFFEE_MACHINE_ACCEL_Y = 360.0F; // Aceleración Y de máquina de café (0.1*60²fps = 360 pixels/segundo²)
// Velocidades base (pixels/segundo) - Items normales
static constexpr float ITEM_VEL_X_BASE = 60.0F; // Velocidad X base para items (1.0F*60fps)
static constexpr float ITEM_VEL_X_STEP = 20.0F; // Incremento de velocidad X (0.33F*60fps)
static constexpr float ITEM_VEL_Y = -240.0F; // Velocidad Y inicial de items (-4.0F*60fps)
static constexpr float ITEM_ACCEL_Y = 720.0F; // Aceleración Y de items (0.2*60²fps = 720 pixels/segundo²)
// Constantes de física de rebote
static constexpr float BOUNCE_VEL_THRESHOLD = 60.0F; // Umbral de velocidad para parar (1.0F*60fps)
static constexpr float COFFEE_BOUNCE_DAMPING = -0.20F; // Factor de rebote Y para máquina de café
static constexpr float ITEM_BOUNCE_DAMPING = -0.5F; // Factor de rebote Y para items normales
static constexpr float HORIZONTAL_DAMPING = 0.75F; // Factor de amortiguación horizontal
// --- Constructor y destructor ---
Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation); // Constructor principal
Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation); // Constructor principal
~Item() = default; // Destructor
// --- Métodos principales ---
void alignTo(int x); // Centra el objeto en la posición X indicada
void render(); // Renderiza el objeto en pantalla
void disable(); // Desactiva el objeto
void update(); // Actualiza la posición, animación y contadores
void update(float deltaTime); // Actualiza la posición, animación y contadores (time-based)
// --- Getters ---
[[nodiscard]] auto getPosX() const -> float { return pos_x_; } // Obtiene la posición X
@@ -48,7 +68,7 @@ class Item {
[[nodiscard]] auto getType() const -> ItemType { return type_; } // Obtiene el tipo
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; } // Verifica si está habilitado
[[nodiscard]] auto isOnFloor() const -> bool { return floor_collision_; } // Verifica si está en el suelo
auto getCollider() -> Circle & { return collider_; } // Obtiene el colisionador
auto getCollider() -> Circle& { return collider_; } // Obtiene el colisionador
private:
// --- Objetos y punteros ---
@@ -58,22 +78,23 @@ class Item {
SDL_FRect play_area_; // Rectángulo con la zona de juego
Circle collider_; // Círculo de colisión del objeto
ItemType type_; // Tipo de objeto
float pos_x_; // Posición X del objeto
float pos_y_; // Posición Y del objeto
float vel_x_; // Velocidad en el eje X
float vel_y_; // Velocidad en el eje Y
float pos_x_ = 0.0F; // Posición X del objeto
float pos_y_ = 0.0F; // Posición Y del objeto
float vel_x_ = 0.0F; // Velocidad en el eje X
float vel_y_ = 0.0F; // Velocidad en el eje Y
float accel_x_ = 0.0F; // Aceleración en el eje X
float accel_y_; // Aceleración en el eje Y
int width_; // Ancho del objeto
int height_; // Alto del objeto
Uint16 time_to_live_ = 600; // Tiempo que el objeto está presente
float accel_y_ = 0.0F; // Aceleración en el eje Y
float width_ = WIDTH; // Ancho del objeto
float height_ = HEIGHT; // Alto del objeto
float rotate_speed_ = 0.0F; // Velocidad de rotacion
float lifetime_timer_ = 0.0f; // Acumulador de tiempo de vida del ítem (segundos)
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
bool enabled_ = true; // Indica si el objeto está habilitado
// --- Métodos internos ---
void shiftColliders(); // Alinea el círculo de colisión con la posición del objeto
void shiftSprite(); // Coloca el sprite en la posición del objeto
void move(); // Actualiza la posición y estados del objeto
void updateTimeToLive(); // Actualiza el contador de tiempo de vida
void move(float deltaTime); // Actualiza la posición y estados del objeto (time-based)
void updateTimeToLive(float deltaTime); // Actualiza el contador de tiempo de vida (time-based)
static auto getCoffeeMachineSpawn(int player_x, int item_width, int area_width, int margin = 2) -> int; // Calcula la zona de aparición de la máquina de café
};

View File

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

View File

@@ -1,5 +1,6 @@
#include "moving_sprite.h"
#include <cmath> // Para std::abs
#include <utility>
#include "texture.h" // Para Texture
@@ -53,42 +54,56 @@ void MovingSprite::stop() {
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
}
// Mueve el sprite
void MovingSprite::move() {
x_ += vx_;
y_ += vy_;
// Mueve el sprite (time-based)
void MovingSprite::move(float deltaTime) {
// DeltaTime puro: velocidad (pixels/ms) * tiempo (ms)
x_ += vx_ * deltaTime;
y_ += vy_ * deltaTime;
vx_ += ax_;
vy_ += ay_;
// Aceleración (pixels/ms²) * tiempo (ms)
vx_ += ax_ * deltaTime;
vy_ += ay_ * deltaTime;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Actualiza las variables internas del objeto
void MovingSprite::update() {
move();
rotate();
// Actualiza las variables internas del objeto (time-based)
void MovingSprite::update(float deltaTime) {
move(deltaTime);
rotate(deltaTime);
}
// Muestra el sprite por pantalla
void MovingSprite::render() { getTexture()->render(pos_.x, pos_.y, &sprite_clip_, horizontal_zoom_, vertical_zoom_, rotate_.angle, &rotate_.center, flip_); }
void MovingSprite::render() {
getTexture()->render(pos_.x, pos_.y, &sprite_clip_, horizontal_zoom_, vertical_zoom_, rotate_.angle, &rotate_.center, flip_);
}
// Establece la rotacion
void MovingSprite::rotate() {
// Establece la rotacion (time-based)
void MovingSprite::rotate(float deltaTime) {
if (rotate_.enabled) {
++rotate_.counter;
if (rotate_.counter % rotate_.speed == 0) {
updateAngle();
rotate_.counter = 0;
}
rotate_.angle += rotate_.amount * deltaTime;
}
}
// Activa o desactiva el efecto de rotación
void MovingSprite::setRotate(bool enable) {
rotate_.enabled = enable;
rotate_.counter = 0;
}
// Habilita la rotación y establece el centro en el centro del sprite
void MovingSprite::startRotate() {
rotate_.enabled = true;
rotate_.center.x = pos_.w / 2.0F;
rotate_.center.y = pos_.h / 2.0F;
}
// Detiene la rotación y resetea el ángulo a cero
void MovingSprite::stopRotate(float threshold) {
if (threshold == 0.0F || std::abs(rotate_.amount) <= threshold) {
rotate_.enabled = false;
rotate_.angle = 0.0;
}
}
// Establece la posición y_ el tamaño del objeto

View File

@@ -15,8 +15,6 @@ class MovingSprite : public Sprite {
// --- Estructuras ---
struct Rotate {
bool enabled{false}; // Indica si ha de rotar
int counter{0}; // Contador
int speed{1}; // Velocidad de giro
double angle{0.0}; // Ángulo para dibujarlo
float amount{0.0F}; // Cantidad de grados a girar en cada iteración
SDL_FPoint center{.x = 0.0F, .y = 0.0F}; // Centro de rotación
@@ -29,7 +27,7 @@ class MovingSprite : public Sprite {
~MovingSprite() override = default;
// --- Métodos principales ---
virtual void update(); // Actualiza las variables internas del objeto
virtual void update(float deltaTime); // Actualiza las variables internas del objeto (time-based)
void clear() override; // Reinicia todas las variables a cero
void stop(); // Elimina el movimiento del sprite
void render() override; // Muestra el sprite por pantalla
@@ -48,8 +46,10 @@ class MovingSprite : public Sprite {
void setAngle(double value) { rotate_.angle = value; } // Establece el ángulo
void setRotatingCenter(SDL_FPoint point) { rotate_.center = point; } // Establece el centro de rotación
void setRotate(bool enable); // Activa o desactiva el efecto de rotación
void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); } // Establece la velocidad de rotación
void setRotateAmount(double value) { rotate_.amount = value; } // Establece la cantidad de rotación
void startRotate(); // Habilita la rotación con centro automático
void stopRotate(float threshold = 0.0F); // Detiene la rotación y resetea ángulo
void setRotateAmount(double value) { rotate_.amount = value; } // Establece la velocidad de rotación
void scaleRotateAmount(float value) { rotate_.amount *= value; } // Modifica la velocidad de rotacion
void switchRotate() { rotate_.amount *= -1; } // Cambia el sentido de la rotación
void setFlip(SDL_FlipMode flip) { flip_ = flip; } // Establece el flip
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; } // Cambia el flip
@@ -79,6 +79,6 @@ class MovingSprite : public Sprite {
// --- Métodos internos ---
void updateAngle() { rotate_.angle += rotate_.amount; } // Incrementa el valor del ángulo
void move(); // Mueve el sprite según velocidad y aceleración
void rotate(); // Rota el sprite según los parámetros de rotación
void move(float deltaTime); // Mueve el sprite según velocidad y aceleración (time-based)
void rotate(float deltaTime); // Rota el sprite según los parámetros de rotación (time-based)
};

View File

@@ -87,7 +87,6 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
static const std::unordered_map<std::string, std::function<void(const std::string&)>> INT_PARAMS = {
{"game.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
{"game.height", [](const std::string& v) { param.game.height = std::stoi(v); }},
{"game.item_size", [](const std::string& v) { param.game.item_size = std::stoi(v); }},
{"game.play_area.rect.x", [](const std::string& v) { param.game.play_area.rect.x = std::stoi(v); }},
{"game.play_area.rect.y", [](const std::string& v) { param.game.play_area.rect.y = std::stoi(v); }},
{"game.play_area.rect.w", [](const std::string& v) { param.game.play_area.rect.w = std::stoi(v); }},
@@ -106,7 +105,6 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
{"scoreboard.rect.h", [](const std::string& v) { param.scoreboard.rect.h = std::stoi(v); }},
{"scoreboard.skip_countdown_value", [](const std::string& v) { param.scoreboard.skip_countdown_value = std::stoi(v); }},
{"title.press_start_position", [](const std::string& v) { param.title.press_start_position = std::stoi(v); }},
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stoi(v); }},
{"title.arcade_edition_position", [](const std::string& v) { param.title.arcade_edition_position = std::stoi(v); }},
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
@@ -182,6 +180,7 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }},
{"tabe.min_spawn_time", [](const std::string& v) { param.tabe.min_spawn_time = std::stof(v); }},
{"tabe.max_spawn_time", [](const std::string& v) { param.tabe.max_spawn_time = std::stof(v); }},
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stof(v); }},
{"service_menu.window_message.padding", [](const std::string& v) { param.service_menu.window_message.padding = std::stof(v); }},
{"service_menu.window_message.line_spacing", [](const std::string& v) { param.service_menu.window_message.line_spacing = std::stof(v); }},
{"service_menu.window_message.title_separator_spacing", [](const std::string& v) { param.service_menu.window_message.title_separator_spacing = std::stof(v); }},

View File

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

View File

@@ -4,6 +4,12 @@
#include <functional> // Para function
#include <utility> // Para move
// Constructor para paths por puntos (convertido a segundos)
Path::Path(const std::vector<SDL_FPoint> &spots_init, float waiting_time_s_init)
: spots(spots_init), is_point_path(true) {
waiting_time_s = waiting_time_s_init;
}
// Devuelve un vector con los puntos que conforman la ruta
auto createPath(float start, float end, PathType type, float fixed_pos, int steps, const std::function<double(double)> &easing_function) -> std::vector<SDL_FPoint> {
std::vector<SDL_FPoint> v;
@@ -33,9 +39,9 @@ auto createPath(float start, float end, PathType type, float fixed_pos, int step
}
// Actualiza la posición y comprueba si ha llegado a su destino
void PathSprite::update() {
void PathSprite::update(float delta_time) {
if (enabled_ && !has_finished_) {
moveThroughCurrentPath();
moveThroughCurrentPath(delta_time);
goToNextPathOrDie();
}
}
@@ -77,14 +83,14 @@ void PathSprite::addPath(Path path, bool centered) {
}
}
// Añade un recorrido
void PathSprite::addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easing_function, int waiting_counter) {
paths_.emplace_back(createPath(start, end, type, fixed_pos, steps, easing_function), waiting_counter);
// Añade un recorrido generado (en segundos)
void PathSprite::addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)> &easing_function, float waiting_time_s) {
paths_.emplace_back(start, end, type, fixed_pos, duration_s, waiting_time_s, easing_function);
}
// Añade un recorrido
void PathSprite::addPath(const std::vector<SDL_FPoint> &spots, int waiting_counter) {
paths_.emplace_back(spots, waiting_counter);
// Añade un recorrido por puntos (en segundos)
void PathSprite::addPath(const std::vector<SDL_FPoint> &spots, float waiting_time_s) {
paths_.emplace_back(spots, waiting_time_s);
}
// Habilita el objeto
@@ -95,21 +101,32 @@ void PathSprite::enable() {
enabled_ = true;
// Establece la posición
// Establece la posición inicial
auto &path = paths_.at(current_path_);
if (path.is_point_path) {
const auto &p = path.spots.at(path.counter);
setPosition(p);
} else {
// Para paths generados, establecer posición inicial
SDL_FPoint initial_pos;
if (path.type == PathType::HORIZONTAL) {
initial_pos = {path.start_pos, path.fixed_pos};
} else {
initial_pos = {path.fixed_pos, path.start_pos};
}
setPosition(initial_pos);
}
}
// Coloca el sprite en los diferentes puntos del recorrido
void PathSprite::moveThroughCurrentPath() {
void PathSprite::moveThroughCurrentPath(float delta_time) {
auto &path = paths_.at(current_path_);
// Establece la posición
if (path.is_point_path) {
// Lógica para paths por puntos (compatibilidad)
const auto &p = path.spots.at(path.counter);
setPosition(p);
// Comprobar si ha terminado el recorrido
if (!path.on_destination) {
++path.counter;
if (path.counter >= static_cast<int>(path.spots.size())) {
@@ -118,12 +135,44 @@ void PathSprite::moveThroughCurrentPath() {
}
}
// Comprobar si ha terminado la espera
if (path.on_destination) {
if (path.waiting_counter == 0) {
path.waiting_elapsed += delta_time;
if (path.waiting_elapsed >= path.waiting_time_s) {
path.finished = true;
}
}
} else {
--path.waiting_counter;
// Lógica para paths generados en tiempo real
if (!path.on_destination) {
path.elapsed_time += delta_time;
// Calcular progreso (0.0 a 1.0)
float progress = path.elapsed_time / path.duration_s;
if (progress >= 1.0f) {
progress = 1.0f;
path.on_destination = true;
}
// Aplicar función de easing
double eased_progress = path.easing_function(progress);
// Calcular posición actual
float current_pos = path.start_pos + (path.end_pos - path.start_pos) * static_cast<float>(eased_progress);
// Establecer posición según el tipo
SDL_FPoint position;
if (path.type == PathType::HORIZONTAL) {
position = {current_pos, path.fixed_pos};
} else {
position = {path.fixed_pos, current_pos};
}
setPosition(position);
} else {
// Esperar en destino
path.waiting_elapsed += delta_time;
if (path.waiting_elapsed >= path.waiting_time_s) {
path.finished = true;
}
}
}
}

View File

@@ -25,16 +25,30 @@ enum class PathCentered { // Centrado del recorrido
// --- Estructuras ---
struct Path { // Define un recorrido para el sprite
std::vector<SDL_FPoint> spots; // Puntos por los que se desplazará el sprite
int waiting_counter; // Tiempo de espera una vez en el destino
float start_pos; // Posición inicial
float end_pos; // Posición final
PathType type; // Tipo de movimiento (horizontal/vertical)
float fixed_pos; // Posición fija en el eje contrario
float duration_s; // Duración de la animación en segundos
float waiting_time_s; // Tiempo de espera una vez en el destino
std::function<double(double)> easing_function; // Función de easing
float elapsed_time = 0.0f; // Tiempo transcurrido
float waiting_elapsed = 0.0f; // Tiempo de espera transcurrido
bool on_destination = false; // Indica si ha llegado al destino
bool finished = false; // Indica si ha terminado de esperarse
int counter = 0; // Contador interno
// Constructor
Path(const std::vector<SDL_FPoint> &spots_init, int waiting_counter_init)
: spots(spots_init),
waiting_counter(waiting_counter_init) {}
// Constructor para paths generados
Path(float start, float end, PathType path_type, float fixed, float duration, float waiting, std::function<double(double)> easing)
: start_pos(start), end_pos(end), type(path_type), fixed_pos(fixed),
duration_s(duration), waiting_time_s(waiting), easing_function(std::move(easing)) {}
// Constructor para paths por puntos (convertido a segundos)
Path(const std::vector<SDL_FPoint> &spots_init, float waiting_time_s_init);
// Variables para paths por puntos
std::vector<SDL_FPoint> spots; // Solo para paths por puntos
int counter = 0; // Solo para paths por puntos
bool is_point_path = false; // Indica si es un path por puntos
};
// --- Funciones ---
@@ -49,13 +63,13 @@ class PathSprite : public Sprite {
~PathSprite() override = default;
// --- Métodos principales ---
void update(); // Actualiza la posición del sprite según el recorrido
void update(float delta_time); // Actualiza la posición del sprite según el recorrido (delta_time en segundos)
void render() override; // Muestra el sprite por pantalla
// --- Gestión de recorridos ---
void addPath(Path path, bool centered = false); // Añade un recorrido (Path)
void addPath(const std::vector<SDL_FPoint> &spots, int waiting_counter = 0); // Añade un recorrido a partir de puntos
void addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easing_function, int waiting_counter = 0); // Añade un recorrido generado
void addPath(const std::vector<SDL_FPoint> &spots, float waiting_time_s = 0.0f); // Añade un recorrido a partir de puntos
void addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)> &easing_function, float waiting_time_s = 0.0f); // Añade un recorrido generado
// --- Estado y control ---
void enable(); // Habilita el objeto
@@ -72,6 +86,6 @@ class PathSprite : public Sprite {
std::vector<Path> paths_; // Caminos a recorrer por el sprite
// --- Métodos internos ---
void moveThroughCurrentPath(); // Coloca el sprite en los diferentes puntos del recorrido
void moveThroughCurrentPath(float delta_time); // Coloca el sprite en los diferentes puntos del recorrido
void goToNextPathOrDie(); // Cambia de recorrido o finaliza
};

View File

@@ -3,6 +3,7 @@
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_FlipMode
#include <algorithm> // Para clamp, max, min
#include <cmath> // Para fmod
#include <cstdlib> // Para rand
#include "animated_sprite.h" // Para AnimatedSprite
@@ -21,7 +22,7 @@
#endif
// Constructor
Player::Player(const Config &config)
Player::Player(const Config& config)
: player_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(0), config.animations.at(0))),
power_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(4), config.animations.at(1))),
enter_name_(std::make_unique<EnterName>()),
@@ -59,17 +60,14 @@ void Player::init() {
power_up_counter_ = POWERUP_COUNTER;
extra_hit_ = false;
coffees_ = 0;
continue_ticks_ = 0;
continue_counter_ = 10;
name_entry_ticks_ = 0;
name_entry_idle_counter_ = 0;
name_entry_total_counter_ = 0;
name_entry_idle_time_accumulator_ = 0.0f;
name_entry_total_time_accumulator_ = 0.0f;
shiftColliders();
vel_x_ = 0;
vel_y_ = 0;
score_ = 0;
score_multiplier_ = 1.0F;
cant_fire_counter_ = 10;
enter_name_->init(last_enter_name_);
// Establece la posición del sprite
@@ -148,35 +146,37 @@ void Player::setInputEnteringName(Input::Action action) {
default:
break;
}
name_entry_idle_counter_ = 0;
name_entry_idle_time_accumulator_ = 0.0f;
}
// Mueve el jugador a la posición y animación que le corresponde
void Player::move() {
// Sistema de movimiento
void Player::move(float deltaTime) {
switch (playing_state_) {
case State::PLAYING:
handlePlayingMovement();
handlePlayingMovement(deltaTime);
break;
case State::ROLLING:
handleRollingMovement();
break;
case State::TITLE_ANIMATION:
handleTitleAnimation();
handleTitleAnimation(deltaTime);
break;
case State::CONTINUE_TIME_OUT:
handleContinueTimeOut();
break;
case State::LEAVING_SCREEN:
handleLeavingScreen();
updateStepCounter(deltaTime);
handleLeavingScreen(deltaTime);
break;
case State::ENTERING_SCREEN:
handleEnteringScreen();
updateStepCounter(deltaTime);
handleEnteringScreen(deltaTime);
break;
case State::CREDITS:
handleCreditsMovement();
handleCreditsMovement(deltaTime);
break;
case State::WAITING:
handleWaitingMovement();
handleWaitingMovement(deltaTime);
break;
case State::RECOVER:
handleRecoverMovement();
@@ -186,9 +186,10 @@ void Player::move() {
}
}
void Player::handlePlayingMovement() {
// Mueve el jugador a derecha o izquierda
pos_x_ += vel_x_;
// Movimiento time-based durante el juego
void Player::handlePlayingMovement(float deltaTime) {
// Mueve el jugador a derecha o izquierda (time-based en segundos)
pos_x_ += vel_x_ * deltaTime;
// Si el jugador abandona el area de juego por los laterales, restaura su posición
const float MIN_X = play_area_.x - 5;
@@ -225,7 +226,7 @@ void Player::handleRollingGroundCollision() {
return;
}
if (player_sprite_->getVelY() < 2.0F) {
if (player_sprite_->getVelY() < 120.0F) { // 2.0F * 60fps = 120.0F pixels/segundo
handleRollingStop();
} else {
handleRollingBounce();
@@ -252,10 +253,10 @@ void Player::handleRollingBounce() {
playSound("jump.wav");
}
void Player::handleTitleAnimation() {
void Player::handleTitleAnimation(float deltaTime) {
setInputBasedOnPlayerId();
pos_x_ += vel_x_ * 2.0F;
pos_x_ += (vel_x_ * 2.0F) * deltaTime;
const float MIN_X = -WIDTH;
const float MAX_X = play_area_.w;
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
@@ -274,11 +275,11 @@ void Player::handleContinueTimeOut() {
}
}
void Player::handleLeavingScreen() {
updateStepCounter();
void Player::handleLeavingScreen(float deltaTime) {
// updateStepCounter se llama desde move() con deltaTime
setInputBasedOnPlayerId();
pos_x_ += vel_x_;
pos_x_ += vel_x_ * deltaTime;
const float MIN_X = -WIDTH;
const float MAX_X = play_area_.w;
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
@@ -289,15 +290,15 @@ void Player::handleLeavingScreen() {
}
}
void Player::handleEnteringScreen() {
updateStepCounter();
void Player::handleEnteringScreen(float deltaTime) {
// updateStepCounter se llama desde move() con deltaTime
switch (id_) {
case Id::PLAYER1:
handlePlayer1Entering();
handlePlayer1Entering(deltaTime);
break;
case Id::PLAYER2:
handlePlayer2Entering();
handlePlayer2Entering(deltaTime);
break;
default:
break;
@@ -306,26 +307,27 @@ void Player::handleEnteringScreen() {
shiftSprite();
}
void Player::handlePlayer1Entering() {
void Player::handlePlayer1Entering(float deltaTime) {
setInputPlaying(Input::Action::RIGHT);
pos_x_ += vel_x_;
pos_x_ += vel_x_ * deltaTime;
if (pos_x_ > default_pos_x_) {
pos_x_ = default_pos_x_;
setPlayingState(State::PLAYING);
}
}
void Player::handlePlayer2Entering() {
void Player::handlePlayer2Entering(float deltaTime) {
setInputPlaying(Input::Action::LEFT);
pos_x_ += vel_x_;
pos_x_ += vel_x_ * deltaTime;
if (pos_x_ < default_pos_x_) {
pos_x_ = default_pos_x_;
setPlayingState(State::PLAYING);
}
}
void Player::handleCreditsMovement() {
pos_x_ += vel_x_ / 2.0F;
// Movimiento general en la pantalla de créditos (time-based)
void Player::handleCreditsMovement(float deltaTime) {
pos_x_ += (vel_x_ / 2.0F) * deltaTime;
if (vel_x_ > 0) {
handleCreditsRightMovement();
@@ -351,10 +353,12 @@ void Player::handleCreditsLeftMovement() {
}
}
void Player::handleWaitingMovement() {
++waiting_counter_;
if (waiting_counter_ == WAITING_COUNTER) {
waiting_counter_ = 0;
// Controla la animación del jugador saludando (time-based)
void Player::handleWaitingMovement(float deltaTime) {
waiting_time_accumulator_ += deltaTime;
const float WAITING_DURATION_S = static_cast<float>(WAITING_COUNTER) / 60.0f; // Convert frames to seconds
if (waiting_time_accumulator_ >= WAITING_DURATION_S) {
waiting_time_accumulator_ = 0.0f;
player_sprite_->resetAnimation();
}
}
@@ -380,20 +384,21 @@ void Player::setInputBasedOnPlayerId() {
}
}
void Player::updateStepCounter() {
++step_counter_;
if (step_counter_ % 10 == 0) {
// Incrementa o ajusta el contador de pasos (time-based)
void Player::updateStepCounter(float deltaTime) {
step_time_accumulator_ += deltaTime;
const float STEP_INTERVAL_S = 10.0f / 60.0f; // 10 frames converted to seconds
if (step_time_accumulator_ >= STEP_INTERVAL_S) {
step_time_accumulator_ = 0.0f;
playSound("walk.wav");
}
}
// Pinta el jugador en pantalla
void Player::render() {
if (power_up_ && isPlaying()) {
if (power_up_counter_ > (POWERUP_COUNTER / 4) || power_up_counter_ % 20 > 4) {
if (power_sprite_visible_ && isPlaying()) {
power_sprite_->render();
}
}
if (isRenderable()) {
player_sprite_->render();
@@ -455,10 +460,9 @@ auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
}
// Establece la animación correspondiente al estado
void Player::setAnimation() {
void Player::setAnimation(float deltaTime) {
switch (playing_state_) {
case State::PLAYING:
case State::ENTERING_NAME_GAME_COMPLETED:
case State::ENTERING_SCREEN:
case State::LEAVING_SCREEN:
case State::TITLE_ANIMATION:
@@ -484,6 +488,7 @@ void Player::setAnimation() {
case State::CONTINUE:
player_sprite_->setCurrentAnimation("dizzy");
break;
case State::ENTERING_NAME_GAME_COMPLETED:
case State::CELEBRATING:
player_sprite_->setCurrentAnimation("celebration");
break;
@@ -491,108 +496,23 @@ void Player::setAnimation() {
break;
}
player_sprite_->update();
power_sprite_->update();
// La diferencia clave: usa deltaTime para las animaciones
player_sprite_->update(deltaTime);
power_sprite_->update(deltaTime);
}
// Actualiza el valor de la variable
void Player::updateCooldown() {
if (playing_state_ != State::PLAYING) {
return;
}
if (cant_fire_counter_ > 0) {
handleFiringCooldown();
} else {
handleRecoilAndCooling();
}
}
void Player::handleFiringCooldown() {
cooling_state_counter_ = COOLING_DURATION;
// Transition to recoiling state at halfway point
if (cant_fire_counter_ == recoiling_state_duration_ / 2) {
transitionToRecoiling();
}
--cant_fire_counter_;
if (cant_fire_counter_ == 0) {
recoiling_state_counter_ = recoiling_state_duration_;
}
}
void Player::handleRecoilAndCooling() {
if (recoiling_state_counter_ > 0) {
--recoiling_state_counter_;
return;
}
handleCoolingState();
}
void Player::handleCoolingState() {
if (cooling_state_counter_ > COOLING_COMPLETE) {
if (cooling_state_counter_ == COOLING_DURATION) {
transitionToCooling();
}
--cooling_state_counter_;
}
if (cooling_state_counter_ == COOLING_COMPLETE) {
completeCooling();
}
}
void Player::transitionToRecoiling() {
switch (firing_state_) {
case State::FIRING_LEFT:
setFiringState(State::RECOILING_LEFT);
break;
case State::FIRING_RIGHT:
setFiringState(State::RECOILING_RIGHT);
break;
case State::FIRING_UP:
setFiringState(State::RECOILING_UP);
break;
default:
break;
}
}
void Player::transitionToCooling() {
switch (firing_state_) {
case State::RECOILING_LEFT:
setFiringState(State::COOLING_LEFT);
break;
case State::RECOILING_RIGHT:
setFiringState(State::COOLING_RIGHT);
break;
case State::RECOILING_UP:
setFiringState(State::COOLING_UP);
break;
default:
break;
}
}
void Player::completeCooling() {
setFiringState(State::FIRING_NONE);
cooling_state_counter_ = -1;
}
// Actualiza al jugador a su posicion, animación y controla los contadores
void Player::update() {
move();
setAnimation();
shiftColliders();
updateCooldown();
updatePowerUp();
updateInvulnerable();
updateScoreboard();
updateContinueCounter();
updateEnterNameCounter();
updateShowingName();
// Actualiza al jugador con deltaTime (time-based)
void Player::update(float deltaTime) {
move(deltaTime); // Sistema de movimiento time-based
setAnimation(deltaTime); // Animaciones time-based
shiftColliders(); // Sin cambios (posicional)
updateFireSystem(deltaTime); // Sistema de disparo de dos líneas
updatePowerUp(deltaTime); // Sistema de power-up time-based
updateInvulnerable(deltaTime); // Sistema de invulnerabilidad time-based
updateScoreboard(); // Sin cambios (no temporal)
updateContinueCounter(deltaTime); // Sistema de continue time-based
updateEnterNameCounter(deltaTime); // Sistema de name entry time-based
updateShowingName(deltaTime); // Sistema de showing name time-based
}
void Player::passShowingName() {
@@ -662,8 +582,8 @@ void Player::setPlayingState(State state) {
}
case State::CONTINUE: {
// Inicializa el contador de continuar
continue_ticks_ = SDL_GetTicks();
continue_counter_ = 9;
continue_time_accumulator_ = 0.0f; // Initialize time accumulator
playSound("continue_clock.wav");
setScoreboardMode(Scoreboard::Mode::CONTINUE);
break;
@@ -682,6 +602,7 @@ void Player::setPlayingState(State state) {
}
pos_y_ = default_pos_y_;
waiting_counter_ = 0;
waiting_time_accumulator_ = 0.0f; // Initialize time accumulator
shiftSprite();
player_sprite_->setCurrentAnimation("hello");
player_sprite_->animtionPause();
@@ -693,7 +614,7 @@ void Player::setPlayingState(State state) {
break;
}
case State::SHOWING_NAME: {
showing_name_ticks_ = SDL_GetTicks();
showing_name_time_accumulator_ = 0.0f; // Inicializar acumulador time-based
setScoreboardMode(Scoreboard::Mode::SHOW_NAME);
Scoreboard::get()->setRecordName(scoreboard_panel_, last_enter_name_);
addScoreToScoreBoard();
@@ -702,15 +623,15 @@ void Player::setPlayingState(State state) {
case State::ROLLING: {
// Activa la animación de rodar dando botes
player_sprite_->setCurrentAnimation("rolling");
player_sprite_->setAnimationSpeed(4);
player_sprite_->setVelY(-6.6F); // Velocidad inicial
player_sprite_->setAccelY(0.2F); // Gravedad
player_sprite_->setAnimationSpeed(4.0f / 60.0f); // 4 frames convertido a segundos
player_sprite_->setVelY(-396.0F); // Velocidad inicial (6.6 * 60 = 396 pixels/s)
player_sprite_->setAccelY(720.0F); // Gravedad (0.2 * 60² = 720 pixels/s²)
player_sprite_->setPosY(pos_y_ - 2); // Para "sacarlo" del suelo, ya que está hundido un pixel para ocultar el outline de los pies
(rand() % 2 == 0) ? player_sprite_->setVelX(3.3F) : player_sprite_->setVelX(-3.3F);
(rand() % 2 == 0) ? player_sprite_->setVelX(198.0F) : player_sprite_->setVelX(-198.0F); // 3.3 * 60 = 198 pixels/s
break;
}
case State::TITLE_ANIMATION: {
// Activa la animación de rodar
// Activa la animación de caminar
player_sprite_->setCurrentAnimation("walk");
playSound("voice_credit_thankyou.wav");
break;
@@ -722,11 +643,11 @@ void Player::setPlayingState(State state) {
}
case State::CONTINUE_TIME_OUT: {
// Activa la animación de sacar al jugador de la zona de juego
player_sprite_->setAccelY(0.2F);
player_sprite_->setVelY(-4.0F);
player_sprite_->setAccelY(720.0F); // 0.2 * 60² = 720 pixels/s²
player_sprite_->setVelY(-240.0F); // -4.0 * 60 = -240 pixels/s
player_sprite_->setVelX(0.0F);
player_sprite_->setCurrentAnimation("rolling");
player_sprite_->setAnimationSpeed(5);
player_sprite_->setAnimationSpeed(5.0f / 60.0f); // 5 frames convertido a segundos
setScoreboardMode(Scoreboard::Mode::GAME_OVER);
playSound("voice_aw_aw_aw.wav");
playSound("jump.wav");
@@ -742,19 +663,21 @@ void Player::setPlayingState(State state) {
break;
}
case State::ENTERING_NAME_GAME_COMPLETED: {
setWalkingState(State::WALKING_STOP);
setFiringState(State::FIRING_NONE);
// setWalkingState(State::WALKING_STOP);
// setFiringState(State::FIRING_NONE);
setScoreboardMode(Scoreboard::Mode::ENTER_NAME);
break;
}
case State::LEAVING_SCREEN: {
step_counter_ = 0;
step_time_accumulator_ = 0.0f; // Initialize time accumulator
setScoreboardMode(Scoreboard::Mode::GAME_COMPLETED);
break;
}
case State::ENTERING_SCREEN: {
init();
step_counter_ = 0;
step_time_accumulator_ = 0.0f; // Initialize time accumulator
setScoreboardMode(Scoreboard::Mode::SCORE);
switch (id_) {
case Id::PLAYER1:
@@ -795,24 +718,26 @@ void Player::decScoreMultiplier() {
void Player::setInvulnerable(bool value) {
invulnerable_ = value;
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER : 0;
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f : 0.0f; // Convert frames to seconds
}
// Monitoriza el estado
void Player::updateInvulnerable() {
// Monitoriza el estado (time-based)
void Player::updateInvulnerable(float deltaTime) {
if (playing_state_ == State::PLAYING && invulnerable_) {
if (invulnerable_counter_ > 0) {
--invulnerable_counter_;
if (invulnerable_time_accumulator_ > 0) {
invulnerable_time_accumulator_ -= deltaTime;
// Frecuencia fija de parpadeo (como el original)
constexpr int blink_speed = 8;
// Frecuencia fija de parpadeo adaptada a deltaTime (en segundos)
constexpr float BLINK_PERIOD_S = 8.0f / 60.0f; // 8 frames convertidos a segundos
// Calcula proporción decreciente: menos textura blanca hacia el final
// Al inicio: 50-50, hacia el final: 70-30 (menos blanco)
float progress = 1.0f - (static_cast<float>(invulnerable_counter_) / INVULNERABLE_COUNTER);
int white_frames = static_cast<int>((0.5f - progress * 0.2f) * blink_speed);
// Calcula proporción decreciente basada en tiempo restante
const float TOTAL_INVULNERABLE_TIME_S = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f;
float progress = 1.0f - (invulnerable_time_accumulator_ / TOTAL_INVULNERABLE_TIME_S);
float white_proportion = 0.5f - progress * 0.2f; // Menos blanco hacia el final
// Alterna entre texturas con proporción variable
bool should_show_invulnerable = (invulnerable_counter_ % blink_speed) < white_frames;
// Calcula si debe mostrar textura de invulnerabilidad basado en el ciclo temporal
float cycle_position = fmod(invulnerable_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
bool should_show_invulnerable = cycle_position < white_proportion;
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
// Solo cambia textura si es diferente (optimización)
@@ -821,6 +746,7 @@ void Player::updateInvulnerable() {
}
} else {
// Fin de invulnerabilidad
invulnerable_time_accumulator_ = 0;
setInvulnerable(false);
player_sprite_->setActiveTexture(coffees_);
}
@@ -831,14 +757,47 @@ void Player::updateInvulnerable() {
void Player::setPowerUp() {
power_up_ = true;
power_up_counter_ = POWERUP_COUNTER;
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds
power_sprite_visible_ = true; // Inicialmente visible cuando se activa el power-up
in_power_up_ending_phase_ = false; // Empezar en fase normal
bullet_color_toggle_ = false; // Resetear toggle
}
// Actualiza el valor de la variable
void Player::updatePowerUp() {
// Actualiza el valor de la variable (time-based)
void Player::updatePowerUp(float deltaTime) {
if (playing_state_ == State::PLAYING) {
if (power_up_) {
--power_up_counter_;
power_up_ = power_up_counter_ > 0;
power_up_time_accumulator_ -= deltaTime;
power_up_ = power_up_time_accumulator_ > 0;
if (!power_up_) {
power_up_time_accumulator_ = 0;
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
// Los colores ahora se manejan dinámicamente en getNextBulletColor()
} else {
// Calcular visibilidad del power sprite
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f;
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f;
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
// En los primeros 75% del tiempo, siempre visible
power_sprite_visible_ = true;
in_power_up_ending_phase_ = false;
} else {
// En el último 25%, parpadea cada 20 frames (≈0.333s)
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f;
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f;
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
power_sprite_visible_ = cycle_position >= VISIBLE_PROPORTION;
in_power_up_ending_phase_ = true; // Activar modo alternancia de colores de balas
}
}
} else {
power_sprite_visible_ = false;
in_power_up_ending_phase_ = false;
bullet_color_toggle_ = false;
}
}
}
@@ -870,36 +829,41 @@ void Player::shiftColliders() {
}
// Pone las texturas del jugador
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture) {
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture) {
player_sprite_->setTexture(texture[0]);
power_sprite_->setTexture(texture[1]);
}
// Actualiza el contador de continue
void Player::updateContinueCounter() {
// Actualiza el contador de continue (time-based)
void Player::updateContinueCounter(float deltaTime) {
if (playing_state_ == State::CONTINUE) {
constexpr int TICKS_SPEED = 1000;
if (SDL_GetTicks() - continue_ticks_ > TICKS_SPEED) {
continue_time_accumulator_ += deltaTime;
constexpr float CONTINUE_INTERVAL_S = 1.0f; // 1 segundo
if (continue_time_accumulator_ >= CONTINUE_INTERVAL_S) {
continue_time_accumulator_ -= CONTINUE_INTERVAL_S;
decContinueCounter();
}
}
}
// Actualiza el contador de entrar nombre
void Player::updateEnterNameCounter() {
// Actualiza el contador de entrar nombre (time-based)
void Player::updateEnterNameCounter(float deltaTime) {
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
constexpr int TICKS_SPEED = 1000;
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
name_entry_time_accumulator_ += deltaTime;
constexpr float NAME_ENTRY_INTERVAL_S = 1.0f; // 1 segundo
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL_S) {
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL_S;
decNameEntryCounter();
}
}
}
// Actualiza el estado de SHOWING_NAME
void Player::updateShowingName() {
// Actualiza el estado de SHOWING_NAME (time-based)
void Player::updateShowingName(float deltaTime) {
if (playing_state_ == State::SHOWING_NAME) {
constexpr int TICKS_SPEED = 5000;
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
showing_name_time_accumulator_ += deltaTime;
constexpr float SHOWING_NAME_DURATION_S = 5.0f; // 5 segundos
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION_S) {
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
}
}
@@ -907,7 +871,7 @@ void Player::updateShowingName() {
// Decrementa el contador de continuar
void Player::decContinueCounter() {
continue_ticks_ = SDL_GetTicks();
continue_time_accumulator_ = 0.0f; // Reset time accumulator
--continue_counter_;
if (continue_counter_ < 0) {
setPlayingState(State::CONTINUE_TIME_OUT);
@@ -918,17 +882,16 @@ void Player::decContinueCounter() {
// Decrementa el contador de entrar nombre
void Player::decNameEntryCounter() {
name_entry_ticks_ = SDL_GetTicks();
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
// Actualiza contadores
++name_entry_idle_counter_;
++name_entry_total_counter_;
// Incrementa acumuladores de tiempo (1 segundo)
name_entry_idle_time_accumulator_ += 1.0f;
name_entry_total_time_accumulator_ += 1.0f;
// Comprueba los contadores
if ((name_entry_total_counter_ >= param.game.name_entry_total_time) ||
(name_entry_idle_counter_ >= param.game.name_entry_idle_time)) {
name_entry_total_counter_ = 0;
name_entry_idle_counter_ = 0;
if ((name_entry_total_time_accumulator_ >= param.game.name_entry_total_time) ||
(name_entry_idle_time_accumulator_ >= param.game.name_entry_idle_time)) {
name_entry_total_time_accumulator_ = 0.0f;
name_entry_idle_time_accumulator_ = 0.0f;
if (playing_state_ == State::ENTERING_NAME) {
last_enter_name_ = getRecordName();
setPlayingState(State::SHOWING_NAME);
@@ -955,12 +918,12 @@ void Player::shiftSprite() {
}
// Hace sonar un sonido
void Player::playSound(const std::string &name) const {
void Player::playSound(const std::string& name) const {
if (demo_) {
return;
}
static auto *audio_ = Audio::get();
static auto* audio_ = Audio::get();
audio_->playSound(name);
}
@@ -969,6 +932,33 @@ auto Player::isRenderable() const -> bool {
return !isTitleHidden();
};
// Devuelve el color actual de bala según el estado
auto Player::getBulletColor() const -> Bullet::Color {
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Devuelve el color para la próxima bala (alterna si está en modo toggle)
auto Player::getNextBulletColor() -> Bullet::Color {
if (in_power_up_ending_phase_) {
// En fase final: alternar entre colores powered y normal
bullet_color_toggle_ = !bullet_color_toggle_;
return bullet_color_toggle_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Modo normal: sin power-up = normal_color, con power-up = powered_color
return power_up_ ? bullet_colors_.powered_color : bullet_colors_.normal_color;
}
// Establece los colores de bala para este jugador
void Player::setBulletColors(Bullet::Color normal, Bullet::Color powered) {
bullet_colors_.normal_color = normal;
bullet_colors_.powered_color = powered;
}
// Establece el archivo de sonido de bala para este jugador
void Player::setBulletSoundFile(const std::string& filename) {
bullet_sound_file_ = filename;
}
// Añade una puntuación a la tabla de records
void Player::addScoreToScoreBoard() const {
if (hi_score_table_ == nullptr) {
@@ -989,3 +979,160 @@ void Player::addCredit() {
++credits_used_;
playSound("credit.wav");
}
// ========================================
// SISTEMA DE DISPARO DE DOS LÍNEAS
// ========================================
// Método principal del sistema de disparo
void Player::updateFireSystem(float deltaTime) {
updateFunctionalLine(deltaTime); // Línea 1: CanFire
updateVisualLine(deltaTime); // Línea 2: Animaciones
}
// LÍNEA 1: Sistema Funcional (CanFire)
void Player::updateFunctionalLine(float deltaTime) {
if (fire_cooldown_timer_ > 0) {
fire_cooldown_timer_ -= deltaTime;
can_fire_new_system_ = false;
} else {
fire_cooldown_timer_ = 0; // Evitar valores negativos
can_fire_new_system_ = true;
}
}
// LÍNEA 2: Sistema Visual (Animaciones)
void Player::updateVisualLine(float deltaTime) {
if (visual_fire_state_ == VisualFireState::NORMAL) {
return; // No hay temporizador activo en estado NORMAL
}
visual_state_timer_ -= deltaTime;
switch (visual_fire_state_) {
case VisualFireState::AIMING:
if (visual_state_timer_ <= 0) {
transitionToRecoilingNew();
}
break;
case VisualFireState::RECOILING:
if (visual_state_timer_ <= 0) {
transitionToThreatPose();
}
break;
case VisualFireState::THREAT_POSE:
if (visual_state_timer_ <= 0) {
transitionToNormalNew();
}
break;
case VisualFireState::NORMAL:
// Ya manejado arriba
break;
}
}
// Inicia un disparo en ambas líneas
void Player::startFiringSystem(int cooldown_frames) {
// LÍNEA 1: Inicia cooldown funcional
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f; // Convertir frames a segundos
can_fire_new_system_ = false;
// LÍNEA 2: Resetea completamente el estado visual
aiming_duration_ = fire_cooldown_timer_ * AIMING_DURATION_FACTOR; // 50% del cooldown
recoiling_duration_ = aiming_duration_ * RECOILING_DURATION_MULTIPLIER; // 4 veces la duración de aiming
visual_fire_state_ = VisualFireState::AIMING;
visual_state_timer_ = aiming_duration_;
updateFiringStateFromVisual(); // Sincroniza firing_state_ para animaciones
}
// Sincroniza firing_state_ con visual_fire_state_
void Player::updateFiringStateFromVisual() {
// Mantener la dirección actual del disparo
State base_state = State::FIRING_NONE;
if (firing_state_ == State::FIRING_LEFT || firing_state_ == State::RECOILING_LEFT || firing_state_ == State::COOLING_LEFT) {
base_state = State::FIRING_LEFT;
} else if (firing_state_ == State::FIRING_RIGHT || firing_state_ == State::RECOILING_RIGHT || firing_state_ == State::COOLING_RIGHT) {
base_state = State::FIRING_RIGHT;
} else if (firing_state_ == State::FIRING_UP || firing_state_ == State::RECOILING_UP || firing_state_ == State::COOLING_UP) {
base_state = State::FIRING_UP;
}
switch (visual_fire_state_) {
case VisualFireState::NORMAL:
firing_state_ = State::FIRING_NONE;
break;
case VisualFireState::AIMING:
firing_state_ = base_state; // FIRING_LEFT/RIGHT/UP
break;
case VisualFireState::RECOILING:
switch (base_state) {
case State::FIRING_LEFT:
firing_state_ = State::RECOILING_LEFT;
break;
case State::FIRING_RIGHT:
firing_state_ = State::RECOILING_RIGHT;
break;
case State::FIRING_UP:
firing_state_ = State::RECOILING_UP;
break;
default:
firing_state_ = State::RECOILING_UP;
break;
}
break;
case VisualFireState::THREAT_POSE:
switch (base_state) {
case State::FIRING_LEFT:
firing_state_ = State::COOLING_LEFT;
break;
case State::FIRING_RIGHT:
firing_state_ = State::COOLING_RIGHT;
break;
case State::FIRING_UP:
firing_state_ = State::COOLING_UP;
break;
default:
firing_state_ = State::COOLING_UP;
break;
}
break;
}
}
// Transiciones del sistema visual
void Player::transitionToRecoilingNew() {
visual_fire_state_ = VisualFireState::RECOILING;
visual_state_timer_ = recoiling_duration_;
updateFiringStateFromVisual();
}
void Player::transitionToThreatPose() {
visual_fire_state_ = VisualFireState::THREAT_POSE;
// Calcular threat_pose_duration ajustada:
// Duración original (833ms) menos el tiempo extra que ahora dura recoiling
float original_recoiling_duration = fire_cooldown_timer_; // Era 100% del cooldown
float new_recoiling_duration = aiming_duration_ * RECOILING_DURATION_MULTIPLIER; // Ahora es más del cooldown
float extra_recoiling_time = new_recoiling_duration - original_recoiling_duration;
float adjusted_threat_duration = THREAT_POSE_DURATION - extra_recoiling_time;
// Asegurar que no sea negativo
visual_state_timer_ = std::max(adjusted_threat_duration, MIN_THREAT_POSE_DURATION);
updateFiringStateFromVisual();
}
void Player::transitionToNormalNew() {
visual_fire_state_ = VisualFireState::NORMAL;
visual_state_timer_ = 0;
updateFiringStateFromVisual();
}

View File

@@ -8,6 +8,7 @@
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimatedSprite
#include "bullet.h" // Para Bullet
#include "enter_name.h" // Para EnterName
#include "input.h" // Para Input
#include "manage_hiscore_table.h" // Para Table
@@ -17,13 +18,33 @@
class Texture;
// --- Clase Player ---
// --- Clase Player: jugador principal del juego ---
//
// Esta clase gestiona todos los aspectos de un jugador durante el juego,
// incluyendo movimiento, disparos, animaciones y estados especiales.
//
// Funcionalidades principales:
// • Sistema de disparo de dos líneas: funcional (cooldown) + visual (animaciones)
// • Estados de animación: normal → aiming → recoiling → threat_pose → normal
// • Movimiento time-based: compatibilidad con deltaTime para fluidez variable
// • Power-ups e invulnerabilidad: coffee machine, extra hits, parpadeos
// • Sistema de puntuación: multipliers, high scores, entrada de nombres
// • Estados de juego: playing, rolling, continue, entering_name, etc.
//
// El sistema de disparo utiliza duraciones configurables mediante constantes
// para facilitar el ajuste del gameplay y la sensación de disparo.
class Player {
public:
// --- Constantes ---
static constexpr int WIDTH = 32; // Anchura
static constexpr int HEIGHT = 32; // Altura
// --- Estructuras ---
struct BulletColorPair {
Bullet::Color normal_color; // Color de bala sin power-up
Bullet::Color powered_color; // Color de bala con power-up
};
// --- Enums ---
enum class Id : int {
NO_PLAYER = -1, // Sin jugador
@@ -81,21 +102,21 @@ class Player {
float x; // Posición X inicial
int y; // Posición Y inicial
bool demo; // Modo demo
SDL_FRect *play_area; // Área de juego (puntero para mantener referencia)
SDL_FRect* play_area; // Área de juego (puntero para mantener referencia)
std::vector<std::shared_ptr<Texture>> texture; // Texturas del jugador
std::vector<std::vector<std::string>> animations; // Animaciones del jugador
Table *hi_score_table; // Tabla de puntuaciones (puntero para referencia)
int *glowing_entry; // Entrada brillante (puntero para mantener referencia)
IStageInfo *stage_info; // Gestor de pantallas (puntero)
Table* hi_score_table; // Tabla de puntuaciones (puntero para referencia)
int* glowing_entry; // Entrada brillante (puntero para mantener referencia)
IStageInfo* stage_info; // Gestor de pantallas (puntero)
};
// --- Constructor y destructor ---
Player(const Config &config);
Player(const Config& config);
~Player() = default;
// --- Inicialización y ciclo de vida ---
void init(); // Inicializa el jugador
void update(); // Actualiza estado, animación y contadores
void update(float deltaTime); // Actualiza estado, animación y contadores (time-based)
void render(); // Dibuja el jugador en pantalla
// --- Entrada y control ---
@@ -104,16 +125,13 @@ class Player {
void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
// --- Movimiento y animación ---
void move(); // Mueve el jugador
void setAnimation(); // Establece la animación según el estado
void move(float deltaTime); // Mueve el jugador (time-based)
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
// --- Texturas y animaciones ---
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); // Cambia las texturas del jugador
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture); // Cambia las texturas del jugador
// --- Estados y contadores ---
void updateCooldown(); // Actualiza el cooldown de disparo
// --- Puntuación y marcador ---
// --- Gameplay: Puntuación y power-ups ---
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
void incScoreMultiplier(); // Incrementa el multiplicador
void decScoreMultiplier(); // Decrementa el multiplicador
@@ -122,15 +140,17 @@ class Player {
void setPlayingState(State state); // Cambia el estado de juego
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
void setPowerUp(); // Activa el modo PowerUp
void updatePowerUp(); // Actualiza el valor de PowerUp
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp
void giveExtraHit(); // Concede un toque extra al jugador
void removeExtraHit(); // Quita el toque extra al jugador
void decContinueCounter(); // Decrementa el contador de continuar
void setWalkingState(State state) { walking_state_ = state; } // Establece el estado de caminar
void startFiringSystem(int cooldown_frames); // Inicia el sistema de disparo
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; } // Establece el panel del marcador
void addCredit();
void passShowingName();
// --- Getters y comprobaciones de estado ---
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
// Comprobación de playing_state
// --- Estado del juego: Consultas (is* methods) ---
[[nodiscard]] auto isLyingOnTheFloorForever() const -> bool { return playing_state_ == State::LYING_ON_THE_FLOOR_FOREVER; }
[[nodiscard]] auto isCelebrating() const -> bool { return playing_state_ == State::CELEBRATING; }
[[nodiscard]] auto isContinue() const -> bool { return playing_state_ == State::CONTINUE; }
@@ -144,72 +164,93 @@ class Player {
[[nodiscard]] auto isWaiting() const -> bool { return playing_state_ == State::WAITING; }
[[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; }
// Getters
[[nodiscard]] auto canFire() const -> bool { return cant_fire_counter_ <= 0; }
// --- Estados específicos: Consultas adicionales ---
[[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
[[nodiscard]] auto isRecoiling() const -> bool { return firing_state_ == State::RECOILING_LEFT || firing_state_ == State::RECOILING_UP || firing_state_ == State::RECOILING_RIGHT; }
[[nodiscard]] auto qualifiesForHighScore() const -> bool { return qualifies_for_high_score_; }
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
[[nodiscard]] auto isPowerUp() const -> bool { return power_up_; }
auto getCollider() -> Circle & { return collider_; }
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
[[nodiscard]] auto getController() const -> int { return controller_index_; }
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
[[nodiscard]] auto isInBulletColorToggleMode() const -> bool { return in_power_up_ending_phase_; }
// --- Getters: Propiedades y valores ---
// Posición y dimensiones
[[nodiscard]] auto getPosX() const -> int { return static_cast<int>(pos_x_); }
[[nodiscard]] auto getPosY() const -> int { return pos_y_; }
[[nodiscard]] static auto getWidth() -> int { return WIDTH; }
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
// Jugador y identificación
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
[[nodiscard]] auto getName() const -> const std::string& { return name_; }
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
auto getCollider() -> Circle& { return collider_; }
// Puntuación y juego
[[nodiscard]] auto getScore() const -> int { return score_; }
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
[[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; }
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
// Power-ups y estado especial
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
[[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; }
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
[[nodiscard]] auto getBulletColor() const -> Bullet::Color; // Devuelve el color actual de bala según el estado
auto getNextBulletColor() -> Bullet::Color; // Devuelve el color para la próxima bala (alterna si está en modo toggle)
void setBulletColors(Bullet::Color normal, Bullet::Color powered); // Establece los colores de bala para este jugador
[[nodiscard]] auto getBulletSoundFile() const -> std::string { return bullet_sound_file_; } // Devuelve el archivo de sonido de bala
void setBulletSoundFile(const std::string& filename); // Establece el archivo de sonido de bala para este jugador
// Contadores y timers
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
[[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; }
[[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; }
[[nodiscard]] auto getScore() const -> int { return score_; }
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
[[nodiscard]] static auto getWidth() -> int { return WIDTH; }
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
[[nodiscard]] auto getName() const -> const std::string & { return name_; }
[[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; }
[[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; }
// Setters inline
void setController(int index) { controller_index_ = index; }
void setCantFireCounter(int counter) { recoiling_state_duration_ = cant_fire_counter_ = counter; }
void setFiringState(State state) { firing_state_ = state; }
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
void setName(const std::string &name) { name_ = name; }
void setPowerUpCounter(int value) { power_up_counter_ = value; }
void setScore(int score) { score_ = score; }
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; }
void setScoreMultiplier(float value) { score_multiplier_ = value; }
void setWalkingState(State state) { walking_state_ = state; }
void addCredit();
void passShowingName();
// --- Configuración e interfaz externa ---
void setName(const std::string& name) { name_ = name; }
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = std::move(gamepad); }
[[nodiscard]] auto getGamepad() const -> std::shared_ptr<Input::Gamepad> { return gamepad_; }
void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
[[nodiscard]] auto getController() const -> int { return controller_index_; }
// Demo file management
[[nodiscard]] auto getDemoFile() const -> size_t { return demo_file_; }
void setDemoFile(size_t demo_file) { demo_file_ = demo_file; }
private:
// --- Constantes ---
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable
// --- Constantes de física y movimiento ---
static constexpr float BASE_SPEED = 90.0f; // Velocidad base del jugador (pixels/segundo)
// --- Constantes de power-ups y estados especiales ---
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp (frames)
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable (frames)
static constexpr size_t INVULNERABLE_TEXTURE = 3; // Textura usada durante invulnerabilidad
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
// --- Constantes del sistema de disparo (obsoletas - usar nuevo sistema) ---
static constexpr int COOLING_DURATION = 50; // Duración del enfriamiento tras disparar
static constexpr int COOLING_COMPLETE = 0; // Valor que indica enfriamiento completado
// --- Constantes de estados de espera ---
static constexpr int WAITING_COUNTER = 1000; // Tiempo de espera en estado de espera
// --- Constantes del nuevo sistema de disparo de dos líneas ---
static constexpr float AIMING_DURATION_FACTOR = 0.5f; // 50% del cooldown funcional
static constexpr float RECOILING_DURATION_MULTIPLIER = 4.0f; // 4 veces la duración de aiming
static constexpr float THREAT_POSE_DURATION = 50.0f / 60.0f; // 50 frames = ~0.833s (duración base)
static constexpr float MIN_THREAT_POSE_DURATION = 6.0f / 60.0f; // 6 frames = ~0.1s (duración mínima)
// --- Objetos y punteros ---
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
std::shared_ptr<Input::Gamepad> gamepad_ = nullptr; // Dispositivo asociado
Table *hi_score_table_ = nullptr; // Tabla de máximas puntuaciones
int *glowing_entry_ = nullptr; // Entrada de la tabla de puntuaciones para hacerla brillar
IStageInfo *stage_info_; // Informacion de la pantalla actual
Table* hi_score_table_ = nullptr; // Tabla de máximas puntuaciones
int* glowing_entry_ = nullptr; // Entrada de la tabla de puntuaciones para hacerla brillar
IStageInfo* stage_info_; // Informacion de la pantalla actual
// --- Variables de estado ---
SDL_FRect play_area_; // Rectángulo con la zona de juego
@@ -221,10 +262,9 @@ class Player {
State walking_state_ = State::WALKING_STOP; // Estado del jugador al moverse
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
State playing_state_ = State::WAITING; // Estado del jugador en el juego
BulletColorPair bullet_colors_ = {Bullet::Color::YELLOW, Bullet::Color::GREEN}; // Par de colores de balas para este jugador
std::string bullet_sound_file_ = "bullet1p.wav"; // Archivo de sonido de bala para este jugador
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
Uint32 name_entry_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
Uint32 showing_name_ticks_ = 0; // Tiempo en el que se entra al estado SHOWING_NAME
float pos_x_ = 0.0F; // Posición en el eje X
float default_pos_x_; // Posición inicial para el jugador
float vel_x_ = 0.0F; // Cantidad de píxeles a desplazarse en el eje X
@@ -232,10 +272,35 @@ class Player {
int pos_y_ = 0; // Posición en el eje Y
int default_pos_y_; // Posición inicial para el jugador
int vel_y_ = 0; // Cantidad de píxeles a desplazarse en el eje Y
int cant_fire_counter_ = 0; // Contador durante el cual no puede disparar
int recoiling_state_counter_ = 0; // Contador para la animación del estado de retroceso
int recoiling_state_duration_ = 0; // Número de frames que dura el estado de retroceso
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling
float invulnerable_time_accumulator_ = 0.0f; // Acumulador de tiempo para invulnerabilidad (time-based)
float power_up_time_accumulator_ = 0.0f; // Acumulador de tiempo para power-up (time-based)
float continue_time_accumulator_ = 0.0f; // Acumulador de tiempo para continue counter (time-based)
float name_entry_time_accumulator_ = 0.0f; // Acumulador de tiempo para name entry counter (time-based)
float showing_name_time_accumulator_ = 0.0f; // Acumulador de tiempo para showing name (time-based)
float waiting_time_accumulator_ = 0.0f; // Acumulador de tiempo para waiting movement (time-based)
float step_time_accumulator_ = 0.0f; // Acumulador de tiempo para step counter (time-based)
// ========================================
// NUEVO SISTEMA DE DISPARO DE DOS LÍNEAS
// ========================================
// LÍNEA 1: SISTEMA FUNCIONAL (CanFire)
float fire_cooldown_timer_ = 0.0f; // Tiempo restante hasta poder disparar otra vez
bool can_fire_new_system_ = true; // true si puede disparar ahora mismo
// LÍNEA 2: SISTEMA VISUAL (Animaciones)
enum class VisualFireState {
NORMAL, // Brazo en posición neutral
AIMING, // Brazo alzado (disparando)
RECOILING, // Brazo en retroceso
THREAT_POSE // Posición amenazante
};
VisualFireState visual_fire_state_ = VisualFireState::NORMAL;
float visual_state_timer_ = 0.0f; // Tiempo en el estado visual actual
float aiming_duration_ = 0.0f; // Duración del estado AIMING
float recoiling_duration_ = 0.0f; // Duración del estado RECOILING
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
int score_ = 0; // Puntos del jugador
int coffees_ = 0; // Indica cuántos cafés lleva acumulados
@@ -243,8 +308,9 @@ class Player {
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
int continue_counter_ = 10; // Contador para poder continuar
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
int name_entry_idle_counter_ = 0; // Contador para poner nombre
int name_entry_total_counter_ = 0; // Segundos totales que lleva acumulados poniendo nombre
size_t demo_file_ = 0; // Indice del fichero de datos para el modo demo
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
int credits_used_ = 0; // Indica el número de veces que ha continuado
int waiting_counter_ = 0; // Contador para el estado de espera
@@ -252,6 +318,9 @@ class Player {
bool invulnerable_ = true; // Indica si el jugador es invulnerable
bool extra_hit_ = false; // Indica si el jugador tiene un toque extra
bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp
bool power_sprite_visible_ = false; // Indica si el sprite de power-up debe ser visible
bool in_power_up_ending_phase_ = false; // Indica si está en la fase final del power-up (alternando colores)
bool bullet_color_toggle_ = false; // Para alternar entre verde y amarillo en fase final
bool demo_ = false; // Para que el jugador sepa si está en el modo demostración
bool game_completed_ = false; // Indica si ha completado el juego
bool uses_keyboard_ = false; // Indica si usa el teclado como dispositivo de control
@@ -259,41 +328,66 @@ class Player {
// --- Métodos internos ---
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
void shiftSprite(); // Recoloca el sprite
void updateInvulnerable(); // Monitoriza el estado de invulnerabilidad
void updateContinueCounter(); // Actualiza el contador de continue
void updateEnterNameCounter(); // Actualiza el contador de entrar nombre
void updateShowingName(); // Actualiza el estado SHOWING_NAME
// --- Setters internos ---
void setController(int index) { controller_index_ = index; }
void setFiringState(State state) { firing_state_ = state; }
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
void setPowerUpCounter(int value) { power_up_counter_ = value; }
void setScore(int score) { score_ = score; }
void setScoreMultiplier(float value) { score_multiplier_ = value; }
// --- Actualizadores de estado (time-based) ---
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
// --- Utilidades generales ---
void updateScoreboard(); // Actualiza el panel del marcador
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
void playSound(const std::string &name) const; // Hace sonar un sonido
void playSound(const std::string& name) const; // Hace sonar un sonido
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo
void handleRecoilAndCooling(); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica
void handleCoolingState(); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento
void transitionToRecoiling(); // Cambia el estado actual al de retroceso después de disparar
void transitionToCooling(); // Cambia el estado actual al de enfriamiento (por ejemplo, tras una ráfaga o sobrecalentamiento)
void completeCooling(); // Finaliza el proceso de enfriamiento y restablece el estado listo para disparar
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo
void handleRecoverMovement(); // Comprueba si ha acabado la animación
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla
void handleRollingGroundCollision(); // Gestiona la interacción del objeto rodante con el suelo (rebotes, frenado, etc.)
void handleRollingStop(); // Detiene el movimiento del objeto rodante cuando se cumplen las condiciones necesarias
void handleRollingBounce(); // Aplica una lógica de rebote al colisionar con superficies durante el rodamiento
void handleTitleAnimation(); // Ejecuta la animación del título en pantalla (ej. entrada, parpadeo o desplazamiento)
void handleContinueTimeOut(); // Gestiona el tiempo de espera en la pantalla de "Continuar" y decide si pasar a otro estado
void handleLeavingScreen(); // Lógica para salir de la pantalla actual (transición visual o cambio de escena)
void handleEnteringScreen(); // Lógica para entrar en una nueva pantalla, posiblemente con animación o retraso
void handlePlayer1Entering(); // Controla la animación o posición de entrada del Jugador 1 en pantalla
void handlePlayer2Entering(); // Controla la animación o posición de entrada del Jugador 2 en pantalla
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (desplazamiento vertical u horizontal)
void handleCreditsRightMovement(); // Lógica específica para mover los créditos hacia la derecha
void handleCreditsLeftMovement(); // Lógica específica para mover los créditos hacia la izquierda
void handleWaitingMovement(); // Controla la animación del jugador saludando
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
void updateStepCounter(); // Incrementa o ajusta el contador de pasos para animaciones o mecánicas relacionadas con movimiento
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula la animacion de moverse y disparar del jugador
// --- Sistema de disparo (nuevo - dos líneas) ---
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones)
void updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
void transitionToRecoilingNew(); // Transición AIMING → RECOILING
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
// --- Manejadores de movimiento ---
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento durante el juego
void handleRecoverMovement(); // Comprueba si ha acabado la animación de recuperación
void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos
void setInputBasedOnPlayerId(); // Asocia las entradas de control según el jugador
// --- Manejadores de estados especiales ---
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar"
void handleRollingBoundaryCollision(); // Detecta colisiones con límites durante rodamiento
void handleRollingGroundCollision(); // Gestiona interacción con el suelo durante rodamiento
void handleRollingStop(); // Detiene el movimiento del objeto rodante
void handleRollingBounce(); // Aplica lógica de rebote durante rodamiento
void handleContinueTimeOut(); // Gestiona tiempo de espera en pantalla "Continuar"
// --- Manejadores de transiciones de pantalla ---
void handleTitleAnimation(float deltaTime); // Ejecuta animación del título
void handleLeavingScreen(float deltaTime); // Lógica para salir de pantalla
void handleEnteringScreen(float deltaTime); // Lógica para entrar en pantalla
void handlePlayer1Entering(float deltaTime); // Entrada del Jugador 1
void handlePlayer2Entering(float deltaTime); // Entrada del Jugador 2
// --- Manejadores de pantallas especiales ---
void handleCreditsMovement(float deltaTime); // Movimiento en pantalla de créditos
void handleCreditsRightMovement(); // Movimiento hacia la derecha en créditos
void handleCreditsLeftMovement(); // Movimiento hacia la izquierda en créditos
void handleWaitingMovement(float deltaTime); // Animación del jugador saludando
void updateWalkingStateForCredits(); // Actualiza estado de caminata en créditos
// --- Utilidades de animación ---
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula animación de movimiento y disparo
};

View File

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

View File

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

View File

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

View File

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

View File

@@ -49,16 +49,17 @@ Credits::Credits()
fade_in_->setColor(param.fade.color);
fade_in_->setType(Fade::Type::FULLSCREEN);
fade_in_->setPostDuration(50);
fade_in_->setPostDuration(800);
fade_in_->setMode(Fade::Mode::IN);
fade_in_->activate();
fade_out_->setColor(0, 0, 0);
fade_out_->setType(Fade::Type::FULLSCREEN);
fade_out_->setPostDuration(400);
fade_out_->setPostDuration(7000);
updateRedRect();
tiled_bg_->setColor(Color(255, 96, 96));
tiled_bg_->setSpeed(60.0F);
initPlayers();
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
@@ -78,37 +79,49 @@ Credits::~Credits() {
Options::gamepad_manager.clearPlayers();
}
// Calcula el deltatime
auto Credits::calculateDeltaTime() -> float {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
}
// Bucle principal
void Credits::run() {
last_time_ = SDL_GetTicks();
while (Section::name == Section::Name::CREDITS) {
checkInput();
update();
const float delta_time = calculateDeltaTime();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Actualiza las variables
void Credits::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks();
const int REPEAT = want_to_pass_ ? 4 : 1;
for (int i = 0; i < REPEAT; ++i) {
tiled_bg_->update();
cycleColors();
balloon_manager_->update();
updateTextureDstRects();
throwBalloons();
updatePlayers();
updateAllFades();
++counter_;
}
// Actualiza las variables (time-based)
void Credits::update(float deltaTime) {
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
const float adjusted_delta_time = deltaTime * multiplier;
Screen::get()->update();
static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
tiled_bg_->update(adjusted_delta_time);
cycleColors();
balloon_manager_->update(adjusted_delta_time);
updateTextureDstRects(adjusted_delta_time);
throwBalloons(adjusted_delta_time);
updatePlayers(adjusted_delta_time);
updateAllFades(adjusted_delta_time);
// Convertir deltaTime a equivalente de frames (60fps)
const float frameFactor = adjusted_delta_time * 60.0f;
counter_ += frameFactor;
fillCanvas();
}
Audio::update();
}
// Dibuja Credits::en patalla
@@ -277,9 +290,14 @@ void Credits::fillCanvas() {
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
}
// Actualiza el destino de los rectangulos de las texturas
void Credits::updateTextureDstRects() {
if (counter_ % 10 == 0) {
// Actualiza el destino de los rectangulos de las texturas (time-based)
void Credits::updateTextureDstRects(float deltaTime) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
credits_state_.texture_accumulator += deltaTime;
if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
credits_state_.texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S;
// Comprueba la posición de la textura con los titulos de credito
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
--credits_rect_dst_.y;
@@ -306,21 +324,28 @@ void Credits::updateTextureDstRects() {
}
}
// Tira globos al escenario
void Credits::throwBalloons() {
// Tira globos al escenario (time-based)
void Credits::throwBalloons(float deltaTime) {
constexpr int SPEED = 200;
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0f; // ~3.33s (cada 200 frames)
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0f; // ~13.33s (cada 800 frames)
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
return;
}
if (counter_ % SPEED == 0) {
const int INDEX = (counter_ / SPEED) % SETS.size();
credits_state_.balloon_accumulator += deltaTime;
credits_state_.powerball_accumulator += deltaTime;
if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
balloon_manager_->deployFormation(SETS.at(INDEX), -60);
}
if (counter_ % (SPEED * 4) == 0 && counter_ > 0) {
if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S;
balloon_manager_->createPowerBall();
}
}
@@ -392,12 +417,16 @@ void Credits::initPlayers() {
}
}
// Actualiza los rectangulos negros
void Credits::updateBlackRects() {
static int current_step_ = steps_;
// Actualiza los rectangulos negros (time-based)
void Credits::updateBlackRects(float deltaTime) {
static float current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
// Si los rectangulos superior e inferior no han llegado al centro
if (counter_ % 4 == 0) {
credits_state_.black_rect_accumulator += deltaTime;
if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
// Incrementa la altura del rectangulo superior
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
@@ -406,7 +435,7 @@ void Credits::updateBlackRects() {
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
--current_step_;
setVolume((initial_volume_ * current_step_ / steps_));
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
}
} else {
// Si los rectangulos superior e inferior han llegado al centro
@@ -421,7 +450,7 @@ void Credits::updateBlackRects() {
right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x);
--current_step_;
setVolume((initial_volume_ * current_step_ / steps_));
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
} else {
// Si los rectangulos izquierdo y derecho han llegado al centro
setVolume(0);
@@ -429,7 +458,9 @@ void Credits::updateBlackRects() {
if (counter_pre_fade_ == 400) {
fade_out_->activate();
} else {
++counter_pre_fade_;
// Convertir deltaTime a equivalente de frames
const float frameFactor = deltaTime * 60.0f;
counter_pre_fade_ += frameFactor;
}
}
}
@@ -443,15 +474,15 @@ void Credits::updateRedRect() {
border_rect_.h = bottom_black_rect_.y - border_rect_.y + 1;
}
// Actualiza el estado de fade
void Credits::updateAllFades() {
// Actualiza el estado de fade (time-based)
void Credits::updateAllFades(float deltaTime) {
if (fading_) {
updateBlackRects();
updateBlackRects(deltaTime);
updateRedRect();
}
fade_in_->update();
if (fade_in_->hasEnded()) {
if (fade_in_->hasEnded() && Audio::get()->getMusicState() != Audio::MusicState::PLAYING) {
Audio::get()->playMusic("credits.ogg");
}
@@ -478,40 +509,40 @@ void Credits::cycleColors() {
constexpr int UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior
static auto r_ = static_cast<float>(UPPER_LIMIT);
static auto g_ = static_cast<float>(LOWER_LIMIT);
static auto b_ = static_cast<float>(LOWER_LIMIT);
static float step_r_ = -0.5F; // Paso flotante para transiciones suaves
static float step_g_ = 0.3F;
static float step_b_ = 0.1F;
// Inicializar valores RGB si es la primera vez
if (credits_state_.r == 255.0f && credits_state_.g == 0.0f && credits_state_.b == 0.0f && credits_state_.step_r == -0.5f) {
credits_state_.r = static_cast<float>(UPPER_LIMIT);
credits_state_.g = static_cast<float>(LOWER_LIMIT);
credits_state_.b = static_cast<float>(LOWER_LIMIT);
}
// Ajustar valores de R
r_ += step_r_;
if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) {
step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites
credits_state_.r += credits_state_.step_r;
if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) {
credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de G
g_ += step_g_;
if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) {
step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites
credits_state_.g += credits_state_.step_g;
if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) {
credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de B
b_ += step_b_;
if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) {
step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites
credits_state_.b += credits_state_.step_b;
if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) {
credits_state_.step_b = -credits_state_.step_b; // Cambia de dirección al alcanzar los límites
}
// Aplicar el color, redondeando a enteros antes de usar
color_ = Color(static_cast<int>(r_), static_cast<int>(g_), static_cast<int>(b_));
color_ = Color(static_cast<int>(credits_state_.r), static_cast<int>(credits_state_.g), static_cast<int>(credits_state_.b));
tiled_bg_->setColor(color_);
}
// Actualza los jugadores
void Credits::updatePlayers() {
// Actualza los jugadores (time-based)
void Credits::updatePlayers(float deltaTime) {
for (auto &player : players_) {
player->update();
player->update(deltaTime);
}
}

View File

@@ -25,6 +25,11 @@ class Credits {
// --- Bucle principal ---
void run();
private:
// --- Métodos del bucle principal ---
void update(float deltaTime); // Actualización principal de la lógica (time-based)
auto calculateDeltaTime() -> float; // Calcula el deltatime
private:
// --- Constantes de clase ---
static constexpr int PLAY_AREA_HEIGHT = 200;
@@ -41,10 +46,10 @@ class Credits {
SDL_Texture *canvas_; // Textura donde se dibuja todo
// --- Temporización y contadores ---
Uint64 ticks_ = 0; // Control de velocidad del programa
Uint32 counter_ = 0; // Contador principal de lógica
Uint32 counter_pre_fade_ = 0; // Activación del fundido final
Uint32 counter_prevent_endless_ = 0; // Prevención de bucle infinito
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
float counter_ = 0; // Contador principal de lógica
float counter_pre_fade_ = 0; // Activación del fundido final
float counter_prevent_endless_ = 0; // Prevención de bucle infinito
// --- Variables de estado ---
bool fading_ = false; // Estado del fade final
@@ -60,6 +65,20 @@ class Credits {
int initial_volume_ = Options::audio.music.volume; // Volumen inicial
int steps_ = 0; // Pasos para reducir audio
// --- Estado de acumuladores para animaciones ---
struct CreditsState {
float texture_accumulator = 0.0f;
float balloon_accumulator = 0.0f;
float powerball_accumulator = 0.0f;
float black_rect_accumulator = 0.0f;
float r = 255.0f; // UPPER_LIMIT
float g = 0.0f; // LOWER_LIMIT
float b = 0.0f; // LOWER_LIMIT
float step_r = -0.5f;
float step_g = 0.3f;
float step_b = 0.1f;
} credits_state_;
// --- Rectángulos de renderizado ---
// Texto de créditos
SDL_FRect credits_rect_src_ = param.game.game_area.rect;
@@ -101,8 +120,6 @@ class Credits {
// Borde para la ventana
SDL_FRect border_rect_ = play_area_; // Delimitador de ventana
// --- Métodos del bucle principal ---
void update(); // Actualización principal de la lógica
void render(); // Renderizado de la escena
static void checkEvents(); // Manejo de eventos
void checkInput(); // Procesamiento de entrada
@@ -110,19 +127,23 @@ class Credits {
// --- Métodos de renderizado ---
void fillTextTexture(); // Crear textura de texto de créditos
void fillCanvas(); // Renderizar todos los sprites y fondos
void updateTextureDstRects(); // Actualizar destinos de texturas
void renderPlayers(); // Renderiza los jugadores
// --- Métodos de lógica del juego ---
void throwBalloons(); // Lanzar globos al escenario
void throwBalloons(); // Lanzar globos al escenario (frame-based)
void throwBalloons(float deltaTime); // Lanzar globos al escenario (time-based)
void initPlayers(); // Inicializar jugadores
void updateAllFades(); // Actualizar estados de fade
void updateAllFades(); // Actualizar estados de fade (frame-based)
void updateAllFades(float deltaTime); // Actualizar estados de fade (time-based)
void cycleColors(); // Cambiar colores de fondo
void updatePlayers(); // Actualza los jugadores
void updatePlayers(float deltaTime); // Actualza los jugadores (time-based)
// --- Métodos de interfaz ---
void updateBlackRects(); // Actualizar rectángulos negros (letterbox)
void updateBlackRects(); // Actualizar rectángulos negros (letterbox) (frame-based)
void updateBlackRects(float deltaTime); // Actualizar rectángulos negros (letterbox) (time-based)
void updateRedRect(); // Actualizar rectángulo rojo (borde)
void updateTextureDstRects(); // Actualizar destinos de texturas (frame-based)
void updateTextureDstRects(float deltaTime); // Actualizar destinos de texturas (time-based)
// --- Métodos de audio ---
static void setVolume(int amount); // Establecer volumen

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
#include <string> // Para string
#include <vector> // Para vector
#include "bullet.h" // Para Bullet
#include "hit.h" // Para Hit
#include "item.h" // Para Item, ItemType
#include "manage_hiscore_table.h" // Para HiScoreEntry
@@ -14,7 +15,8 @@
#include "player.h" // Para Player
#include "smart_sprite.h" // Para SmartSprite
#include "stage.h" // Para StageManager
#include "utils.h" // Para Demo
#include "demo.h" // Para Demo
#include "utils.h" // Para otras utilidades
class Background;
class Balloon;
@@ -27,13 +29,27 @@ class Scoreboard;
class Screen;
class Tabe;
class Texture;
enum class BulletType : Uint8;
namespace Difficulty {
enum class Code;
} // namespace Difficulty
// --- Clase Game: gestor principal del juego ---
// --- Clase Game: núcleo principal del gameplay ---
//
// Esta clase gestiona toda la lógica del juego durante las partidas activas,
// incluyendo mecánicas de juego, estados, objetos y sistemas de puntuación.
//
// Funcionalidades principales:
// • Gestión de jugadores: soporte para 1 o 2 jugadores simultáneos
// • Sistema de estados: fade-in, entrada, jugando, completado, game-over
// • Mecánicas de juego: globos, balas, ítems, power-ups y efectos especiales
// • Sistema de puntuación: scoreboard y tabla de récords
// • Efectos temporales: tiempo detenido, ayudas automáticas
// • Modo demo: reproducción automática para attract mode
// • Gestión de fases: progresión entre niveles y dificultad
//
// Utiliza un sistema de tiempo basado en milisegundos para garantizar
// comportamiento consistente independientemente del framerate.
class Game {
public:
// --- Constantes ---
@@ -41,7 +57,7 @@ class Game {
static constexpr bool DEMO_ON = true; // Modo demo activado
// --- Constructor y destructor ---
Game(Player::Id player_id, int current_stage, bool demo); // Constructor principal
Game(Player::Id player_id, int current_stage, bool demo_enabled); // Constructor principal
~Game(); // Destructor
// --- Bucle principal ---
@@ -58,12 +74,13 @@ class Game {
GAME_OVER, // Fin del juego
};
// --- Constantes internas ---
static constexpr int HELP_COUNTER = 1000;
static constexpr int GAME_COMPLETED_START_FADE = 500;
static constexpr int GAME_COMPLETED_END = 700;
static constexpr int GAME_OVER_COUNTER = 350;
static constexpr int TIME_STOPPED_COUNTER = 360;
// --- Constantes de tiempo (en segundos) ---
static constexpr float HELP_COUNTER_S = 16.667f; // Contador de ayuda (1000 frames a 60fps → segundos)
static constexpr float GAME_COMPLETED_START_FADE_S = 8.333f; // Inicio del fade al completar (500 frames → segundos)
static constexpr float GAME_COMPLETED_END_S = 11.667f; // Fin del juego completado (700 frames → segundos)
static constexpr float GAME_OVER_DURATION_S = 8.5f;
static constexpr float TIME_STOPPED_DURATION_S = 6.0f;
static constexpr float DEMO_FADE_PRE_DURATION_S = 0.5f;
static constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
static constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
static constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
@@ -77,7 +94,7 @@ class Game {
bool need_coffee{false}; // Indica si se necesitan cafes
bool need_coffee_machine{false}; // Indica si se necesita PowerUp
bool need_power_ball{false}; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
float counter; // Contador para no dar ayudas consecutivas
int item_disk_odds; // Probabilidad de aparición del objeto
int item_gavina_odds; // Probabilidad de aparición del objeto
int item_pacmar_odds; // Probabilidad de aparición del objeto
@@ -86,7 +103,7 @@ class Game {
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
Helper()
: counter(HELP_COUNTER),
: counter(HELP_COUNTER_S * 1000), // Convertir a milisegundos para compatibilidad
item_disk_odds(ITEM_POINTS_1_DISK_ODDS),
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS),
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS),
@@ -96,12 +113,12 @@ class Game {
};
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
Screen *screen_; // Objeto encargado de dibujar en pantalla
Input *input_; // Manejador de entrada
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
SDL_Renderer* renderer_; // El renderizador de la ventana
Screen* screen_; // Objeto encargado de dibujar en pantalla
Input* input_; // Manejador de entrada
Scoreboard* scoreboard_; // Objeto para dibujar el marcador
SDL_Texture *canvas_; // Textura para dibujar la zona de juego
SDL_Texture* canvas_; // Textura para dibujar la zona de juego
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
std::vector<std::shared_ptr<Bullet>> bullets_; // Vector con las balas
@@ -134,14 +151,14 @@ class Game {
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
Difficulty::Code difficulty_ = Options::settings.difficulty; // Dificultad del juego
Helper helper_; // Variable para gestionar las ayudas
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
int counter_ = 0; // Contador para el juego
int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más globos
int game_over_counter_ = GAME_OVER_COUNTER; // Contador para el estado de fin de partida
int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
float difficulty_score_multiplier_ = 1.0f; // Multiplicador de puntos en función de la dificultad
float counter_ = 0.0f; // Contador para el juego
float game_completed_timer_ = 0.0f; // Acumulador de tiempo para el tramo final (milisegundos)
float game_over_timer_ = 0.0f; // Timer para el estado de fin de partida (milisegundos)
float time_stopped_timer_ = 0.0f; // Temporizador para llevar la cuenta del tiempo detenido
int menace_ = 0; // Nivel de amenaza actual
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
State state_ = State::FADE_IN; // Estado
@@ -149,12 +166,46 @@ class Game {
std::vector<std::shared_ptr<Player>> players_to_put_at_front_;
Hit hit_; // Para representar colisiones en pantalla
// Estructuras para gestionar flags de eventos basados en tiempo
struct GameOverFlags {
bool music_fade_triggered = false;
bool message_triggered = false;
bool fade_out_triggered = false;
void reset() {
music_fade_triggered = false;
message_triggered = false;
fade_out_triggered = false;
}
} game_over_flags_;
struct GameCompletedFlags {
bool start_celebrations_triggered = false;
bool end_celebrations_triggered = false;
void reset() {
start_celebrations_triggered = false;
end_celebrations_triggered = false;
}
} game_completed_flags_;
struct TimeStoppedFlags {
bool color_flash_sound_played = false;
bool warning_phase_started = false;
void reset() {
color_flash_sound_played = false;
warning_phase_started = false;
}
} time_stopped_flags_;
#ifdef _DEBUG
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
#endif
// --- Ciclo principal del juego ---
void update(); // Actualiza la lógica principal del juego
void update(float deltaTime); // Actualiza la lógica principal del juego
auto calculateDeltaTime() -> float; // Calcula el deltatime
void render(); // Renderiza todos los elementos del juego
void handleEvents(); // Procesa los eventos del sistema en cola
void checkState(); // Verifica y actualiza el estado actual del juego
@@ -162,17 +213,17 @@ class Game {
void cleanVectors(); // Limpia vectores de elementos deshabilitados
// --- Gestión de estados del juego ---
void updateGameStates(); // Actualiza todos los estados del juego
void updateGameStateFadeIn(); // Gestiona el estado de transición de entrada
void updateGameStateEnteringPlayer(); // Gestiona el estado de entrada de jugador
void updateGameStateShowingGetReadyMessage(); // Gestiona el estado de mensaje "preparado"
void updateGameStatePlaying(); // Gestiona el estado de juego activo
void updateGameStateCompleted(); // Gestiona el estado de juego completado
void updateGameStateGameOver(); // Gestiona el estado de fin de partida
void updateGameStates(float deltaTime); // Actualiza todos los estados del juego
void updateGameStateFadeIn(float deltaTime); // Gestiona el estado de transición de entrada (time-based)
void updateGameStateEnteringPlayer(float deltaTime); // Gestiona el estado de entrada de jugador
void updateGameStateShowingGetReadyMessage(float deltaTime); // Gestiona el estado de mensaje "preparado"
void updateGameStatePlaying(float deltaTime); // Gestiona el estado de juego activo
void updateGameStateCompleted(float deltaTime); // Gestiona el estado de juego completado
void updateGameStateGameOver(float deltaTime); // Gestiona las actualizaciones continuas del estado de fin de partida
// --- Gestión de jugadores ---
void initPlayers(Player::Id player_id); // Inicializa los datos de los jugadores
void updatePlayers(); // Actualiza las variables y estados de los jugadores
void updatePlayers(float deltaTime); // Actualiza las variables y estados de los jugadores
void renderPlayers(); // Renderiza todos los jugadores en pantalla
void sortPlayersByZOrder(); // Reorganiza el orden de dibujado de jugadores
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador por su identificador
@@ -186,9 +237,9 @@ class Game {
auto allPlayersAreNotPlaying() -> bool; // Verifica si ningún jugador está activo
// --- Colisiones de jugadores ---
void handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_ptr<Balloon> &balloon); // Procesa colisión de jugador con globo
auto checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon>; // Detecta colisión jugador-globo
void checkPlayerItemCollision(std::shared_ptr<Player> &player); // Detecta colisión jugador-ítem
void handlePlayerCollision(std::shared_ptr<Player>& player, std::shared_ptr<Balloon>& balloon); // Procesa colisión de jugador con globo
auto checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon>; // Detecta colisión jugador-globo
void checkPlayerItemCollision(std::shared_ptr<Player>& player); // Detecta colisión jugador-ítem
// --- Sistema de entrada (input) ---
void checkInput(); // Gestiona toda la entrada durante el juego
@@ -196,32 +247,32 @@ class Game {
// --- Entrada de jugadores normales ---
void handlePlayersInput(); // Gestiona entrada de todos los jugadores
void handleNormalPlayerInput(const std::shared_ptr<Player> &player); // Procesa entrada de un jugador específico
void handleFireInput(const std::shared_ptr<Player> &player, BulletType bullet_type); // Gestiona disparo de jugador
void handleFireInputs(const std::shared_ptr<Player> &player, bool autofire); // Procesa disparos automáticos
void handlePlayerContinueInput(const std::shared_ptr<Player> &player); // Permite continuar al jugador
void handlePlayerWaitingInput(const std::shared_ptr<Player> &player); // Permite (re)entrar al jugador
void handleNameInput(const std::shared_ptr<Player> &player); // Gestiona entrada de nombre del jugador
void handleNormalPlayerInput(const std::shared_ptr<Player>& player); // Procesa entrada de un jugador específico
void handleFireInput(const std::shared_ptr<Player>& player, Bullet::Type type); // Gestiona disparo de jugador
void handleFireInputs(const std::shared_ptr<Player>& player, bool autofire); // Procesa disparos automáticos
void handlePlayerContinueInput(const std::shared_ptr<Player>& player); // Permite continuar al jugador
void handlePlayerWaitingInput(const std::shared_ptr<Player>& player); // Permite (re)entrar al jugador
void handleNameInput(const std::shared_ptr<Player>& player); // Gestiona entrada de nombre del jugador
// --- Entrada en modo demo ---
void demoHandleInput(); // Gestiona entrada durante el modo demostración
void demoHandlePassInput(); // Permite saltar la demostración
void demoHandlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa entrada de jugador en demo
void demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index); // Procesa entrada de jugador en demo
// --- Sistema de balas y proyectiles ---
void updateBullets(); // Actualiza posición y estado de todas las balas
void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based)
void renderBullets(); // Renderiza todas las balas activas
void createBullet(int x, int y, BulletType kind, bool powered_up, Player::Id owner); // Crea una nueva bala
void createBullet(int x, int y, Bullet::Type kind, Bullet::Color color, int owner); // Crea una nueva bala
void checkBulletCollision(); // Verifica colisiones de todas las balas
void freeBullets(); // Libera memoria del vector de balas
// --- Colisiones específicas de balas ---
auto checkBulletTabeCollision(const std::shared_ptr<Bullet> &bullet) -> bool; // Detecta colisión bala-Tabe
auto checkBulletBalloonCollision(const std::shared_ptr<Bullet> &bullet) -> bool; // Detecta colisión bala-globo
void processBalloonHit(const std::shared_ptr<Bullet> &bullet, const std::shared_ptr<Balloon> &balloon); // Procesa impacto en globo
auto checkBulletTabeCollision(const std::shared_ptr<Bullet>& bullet) -> bool; // Detecta colisión bala-Tabe
auto checkBulletBalloonCollision(const std::shared_ptr<Bullet>& bullet) -> bool; // Detecta colisión bala-globo
void processBalloonHit(const std::shared_ptr<Bullet>& bullet, const std::shared_ptr<Balloon>& balloon); // Procesa impacto en globo
// --- Sistema de ítems y power-ups ---
void updateItems(); // Actualiza posición y estado de todos los ítems
void updateItems(float deltaTime); // Actualiza posición y estado de todos los ítems
void renderItems(); // Renderiza todos los ítems activos
auto dropItem() -> ItemType; // Determina aleatoriamente qué ítem soltar
void createItem(ItemType type, float x, float y); // Crea un nuevo ítem en posición específica
@@ -231,29 +282,31 @@ class Game {
// --- ítems especiales ---
void enableTimeStopItem(); // Activa el efecto de detener el tiempo
void disableTimeStopItem(); // Desactiva el efecto de detener el tiempo
void updateTimeStopped(); // Actualiza el estado del tiempo detenido
void updateTimeStopped(float deltaTime); // Actualiza el estado del tiempo detenido
void handleGameCompletedEvents(); // Maneja eventos del juego completado
void handleGameOverEvents(); // Maneja eventos discretos basados en tiempo durante game over
void throwCoffee(int x, int y); // Crea efecto de café arrojado al ser golpeado
// --- Gestión de caída de ítems ---
void handleItemDrop(const std::shared_ptr<Balloon> &balloon, const std::shared_ptr<Player> &player); // Gestiona caída de ítem desde globo
void handleItemDrop(const std::shared_ptr<Balloon>& balloon, const std::shared_ptr<Player>& player); // Gestiona caída de ítem desde globo
// --- Sprites inteligentes (smartsprites) ---
void updateSmartSprites(); // Actualiza todos los sprites con lógica propia
void updateSmartSprites(float deltaTime); // Actualiza todos los sprites con lógica propia (time-based)
void renderSmartSprites(); // Renderiza todos los sprites inteligentes
void freeSmartSprites(); // Libera memoria de sprites inteligentes
// --- Sprites por ruta (pathsprites) ---
void updatePathSprites(); // Actualiza sprites que siguen rutas predefinidas
void updatePathSprites(float deltaTime); // Actualiza sprites que siguen rutas predefinidas
void renderPathSprites(); // Renderiza sprites animados por ruta
void freePathSprites(); // Libera memoria de sprites por ruta
void initPaths(); // Inicializa rutas predefinidas para animaciones
// --- Creación de sprites especiales ---
void createItemText(int x, const std::shared_ptr<Texture> &texture); // Crea texto animado para ítems
void createMessage(const std::vector<Path> &paths, const std::shared_ptr<Texture> &texture); // Crea mensaje con animación por ruta
void createItemText(int x, const std::shared_ptr<Texture>& texture); // Crea texto animado para ítems
void createMessage(const std::vector<Path>& paths, const std::shared_ptr<Texture>& texture); // Crea mensaje con animación por ruta
// --- Sistema de globos y enemigos ---
void handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std::shared_ptr<Player> &player); // Procesa destrucción de globo
void handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std::shared_ptr<Player>& player); // Procesa destrucción de globo
void handleTabeHitEffects(); // Gestiona efectos al golpear a Tabe
void checkAndUpdateBalloonSpeed(); // Ajusta velocidad de globos según progreso
@@ -273,32 +326,32 @@ class Game {
// --- Modo demostración ---
void initDemo(Player::Id player_id); // Inicializa variables para el modo demostración
void updateDemo(); // Actualiza lógica específica del modo demo
void updateDemo(float deltaTime); // Actualiza lógica específica del modo demo
// --- Recursos y renderizado ---
void setResources(); // Asigna texturas y animaciones a los objetos
void updateBackground(); // Actualiza elementos del fondo
void updateBackground(float deltaTime); // Actualiza elementos del fondo (time-based)
void fillCanvas(); // Renderiza elementos del área de juego en su textura
void updateHelper(); // Actualiza variables auxiliares de renderizado
// --- Sistema de audio ---
static void playMusic(); // Reproduce la música de fondo
static void playMusic(const std::string& music_file, int loop = -1); // Reproduce la música de fondo
void stopMusic() const; // Detiene la reproducción de música
static void pauseMusic(); // Pausa la música
static void resumeMusic(); // Retoma la música que eestaba pausada
void playSound(const std::string &name) const; // Reproduce un efecto de sonido específico
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
void sendPlayerToTheBack(const std::shared_ptr<Player> &player); // Mueve el jugador para pintarlo al fondo de la lista de jugadores
void sendPlayerToTheFront(const std::shared_ptr<Player> &player); // Mueve el jugador para pintarlo el primero de la lista de jugadores
void sendPlayerToTheBack(const std::shared_ptr<Player>& player); // Mueve el jugador para pintarlo al fondo de la lista de jugadores
void sendPlayerToTheFront(const std::shared_ptr<Player>& player); // Mueve el jugador para pintarlo el primero de la lista de jugadores
void onPauseStateChanged(bool is_paused);
// SISTEMA DE GRABACIÓN (CONDICIONAL)
#ifdef RECORDING
void updateRecording(); // Actualiza variables durante modo de grabación
void updateRecording(float deltaTime); // Actualiza variables durante modo de grabación
#endif
// --- Depuración (solo en modo DEBUG) ---
#ifdef _DEBUG
void handleDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos en el modo DEBUG
#endif
};

View File

@@ -33,7 +33,7 @@ HiScoreTable::HiScoreTable()
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
fade_(std::make_unique<Fade>()),
background_(std::make_unique<Background>()),
ticks_(0),
last_time_(0),
view_area_(SDL_FRect{0, 0, param.game.width, param.game.height}),
fade_mode_(Fade::Mode::IN),
background_fade_color_(Color(0, 0, 0)) {
@@ -53,19 +53,18 @@ HiScoreTable::~HiScoreTable() {
}
// Actualiza las variables
void HiScoreTable::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
Screen::get()->update(); // Actualiza el objeto screen
void HiScoreTable::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
updateSprites(); // Actualiza las posiciones de los sprites de texto
background_->update(); // Actualiza el fondo
updateFade(); // Gestiona el fade
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto
background_->update(delta_time); // Actualiza el fondo
updateFade(delta_time); // Gestiona el fade
updateCounter(); // Gestiona el contador y sus eventos
fillTexture(); // Dibuja los sprites en la textura
}
Audio::update();
}
// Pinta en pantalla
@@ -76,7 +75,8 @@ void HiScoreTable::render() {
SCREEN->clean(); // Limpia la pantalla
background_->render(); // Pinta el fondo
view_area_.y = std::max(0.0F, param.game.height - counter_ + 100); // Establece la ventana del backbuffer
float counter_equivalent = elapsed_time_ * 60.0f; // Convertir tiempo a equivalente frame para UI
view_area_.y = std::max(0.0F, param.game.height - counter_equivalent + 100); // Establece la ventana del backbuffer
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Copia el backbuffer al renderizador
fade_->render(); // Renderiza el fade
@@ -117,20 +117,32 @@ void HiScoreTable::checkInput() {
GlobalInputs::check();
}
// Calcula el tiempo transcurrido desde el último frame
float HiScoreTable::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
}
// Bucle para la pantalla de instrucciones
void HiScoreTable::run() {
last_time_ = SDL_GetTicks();
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::HI_SCORE_TABLE) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Gestiona el fade
void HiScoreTable::updateFade() {
fade_->update();
void HiScoreTable::updateFade(float delta_time) {
fade_->update(delta_time);
if (fade_->hasEnded() && fade_mode_ == Fade::Mode::IN) {
fade_->reset();
@@ -208,15 +220,14 @@ void HiScoreTable::createSprites() {
const int DEFAULT_POS_X = (backbuffer_width - ENTRY_WIDTH) / 2;
const int POS_X = (i < 9) ? DEFAULT_POS_X : DEFAULT_POS_X - entry_text->getCharacterSize();
const int POS_Y = (i * SPACE_BETWEEN_LINES) + FIRST_LINE + SPACE_BETWEEN_HEADER;
constexpr int STEPS = 80;
switch (ANIMATION) {
case 0: // Ambos lados alternativamente
{
if (i % 2 == 0) {
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
} else {
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
}
break;
@@ -224,21 +235,21 @@ void HiScoreTable::createSprites() {
case 1: // Entran por la izquierda
{
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
break;
}
case 2: // Entran por la derecha
{
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
break;
}
case 3: // Entran desde la parte inferior
{
entry_names_.back()->addPath(backbuffer_height, POS_Y, PathType::VERTICAL, POS_X, STEPS, easeOutQuint);
entry_names_.back()->addPath(backbuffer_height, POS_Y, PathType::VERTICAL, POS_X, ANIM_DURATION_S, easeOutQuint);
entry_names_.back()->setPosition(0, backbuffer_height);
}
@@ -249,20 +260,20 @@ void HiScoreTable::createSprites() {
}
// Actualiza las posiciones de los sprites de texto
void HiScoreTable::updateSprites() {
constexpr int INIT_COUNTER = 190;
const int COUNTER_BETWEEN_ENTRIES = 16;
if (counter_ >= INIT_COUNTER) {
const int COUNTER2 = counter_ - INIT_COUNTER;
if (COUNTER2 % COUNTER_BETWEEN_ENTRIES == 0) {
int index = COUNTER2 / COUNTER_BETWEEN_ENTRIES;
if (index < static_cast<int>(entry_names_.size())) {
void HiScoreTable::updateSprites(float delta_time) {
if (elapsed_time_ >= INIT_DELAY_S) {
const float elapsed_since_init = elapsed_time_ - INIT_DELAY_S;
int index = static_cast<int>(elapsed_since_init / ENTRY_DELAY_S);
if (index < static_cast<int>(entry_names_.size()) && index >= 0) {
// Verificar si este índice debe activarse ahora
float expected_time = index * ENTRY_DELAY_S;
if (elapsed_since_init >= expected_time && elapsed_since_init < expected_time + delta_time) {
entry_names_.at(index)->enable();
}
}
}
for (auto const &entry : entry_names_) {
entry->update();
entry->update(delta_time);
}
glowEntryNames();
@@ -281,7 +292,7 @@ void HiScoreTable::initFade() {
void HiScoreTable::initBackground() {
background_->setManualMode(true);
background_->setPos(param.game.game_area.rect);
background_->setCloudsSpeed(-0.1F);
background_->setCloudsSpeed(CLOUDS_SPEED);
const int LUCKY = rand() % 3;
switch (LUCKY) {
@@ -346,7 +357,8 @@ void HiScoreTable::iniEntryColors() {
// Hace brillar los nombres de la tabla de records
void HiScoreTable::glowEntryNames() {
const Color ENTRY_COLOR = getEntryColor(counter_ / 5);
int color_counter = static_cast<int>(elapsed_time_ * 60.0f / 5.0f); // Convertir tiempo a equivalente frame
const Color ENTRY_COLOR = getEntryColor(color_counter);
for (const auto &entry_index : Options::settings.glowing_entries) {
if (entry_index != -1) {
entry_names_.at(entry_index)->getTexture()->setColor(ENTRY_COLOR);
@@ -356,14 +368,14 @@ void HiScoreTable::glowEntryNames() {
// Gestiona el contador
void HiScoreTable::updateCounter() {
++counter_;
if (counter_ == 150) {
if (elapsed_time_ >= BACKGROUND_CHANGE_S && !hiscore_flags_.background_changed) {
background_->setColor(background_fade_color_.DARKEN());
background_->setAlpha(96);
hiscore_flags_.background_changed = true;
}
if (counter_ == COUNTER_END) {
if (elapsed_time_ >= COUNTER_END_S && !hiscore_flags_.fade_activated) {
fade_->activate();
hiscore_flags_.fade_activated = true;
}
}

View File

@@ -30,8 +30,13 @@ class HiScoreTable {
void run();
private:
// --- Constantes ---
static constexpr Uint16 COUNTER_END = 800; // Valor final para el contador
// --- Constantes (en segundos) ---
static constexpr float COUNTER_END_S = 800.0f / 60.0f; // Tiempo final (≈13.33s)
static constexpr float INIT_DELAY_S = 190.0f / 60.0f; // Retraso inicial (≈3.17s)
static constexpr float ENTRY_DELAY_S = 16.0f / 60.0f; // Retraso entre entradas (≈0.27s)
static constexpr float BACKGROUND_CHANGE_S = 150.0f / 60.0f; // Tiempo cambio fondo (≈2.5s)
static constexpr float ANIM_DURATION_S = 80.0f / 60.0f; // Duración animación (≈1.33s)
static constexpr float CLOUDS_SPEED = -6.0f; // Velocidad nubes (pixels/s)
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
@@ -44,27 +49,39 @@ class HiScoreTable {
std::vector<Path> paths_; // Vector con los recorridos precalculados
// --- Variables ---
Uint16 counter_ = 0; // Contador
Uint64 ticks_; // Contador de ticks para ajustar la velocidad del programa
float elapsed_time_ = 0.0f; // Tiempo transcurrido (segundos)
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla
Fade::Mode fade_mode_; // Modo de fade a utilizar
Color background_fade_color_; // Color de atenuación del fondo
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla
// --- Flags para eventos basados en tiempo ---
struct HiScoreFlags {
bool background_changed = false;
bool fade_activated = false;
void reset() {
background_changed = false;
fade_activated = false;
}
} hiscore_flags_;
// --- Métodos internos ---
void update(); // Actualiza las variables
void update(float delta_time); // Actualiza las variables
void render(); // Pinta en pantalla
static void checkEvents(); // Comprueba los eventos
static void checkInput(); // Comprueba las entradas
static auto format(int number) -> std::string; // Convierte un entero a un string con separadores de miles
void fillTexture(); // Dibuja los sprites en la textura
void updateFade(); // Gestiona el fade
void updateFade(float delta_time); // Gestiona el fade
void createSprites(); // Crea los sprites con los textos
void updateSprites(); // Actualiza las posiciones de los sprites de texto
void updateSprites(float delta_time); // Actualiza las posiciones de los sprites de texto
void initFade(); // Inicializa el fade
void initBackground(); // Inicializa el fondo
auto getEntryColor(int counter) -> Color; // Obtiene un color del vector de colores de entradas
void iniEntryColors(); // Inicializa los colores de las entradas
void glowEntryNames(); // Hace brillar los nombres de la tabla de records
void updateCounter(); // Gestiona el contador
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
};

View File

@@ -14,6 +14,7 @@
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "item.h" // Para Item
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade, Param...
#include "resource.h" // Para Resource
@@ -78,43 +79,43 @@ void Instructions::iniSprites() {
// Inicializa los sprites
for (int i = 0; i < (int)item_textures_.size(); ++i) {
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, Item::WIDTH, Item::HEIGHT);
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((Item::HEIGHT + item_space_) * i)});
sprites_.push_back(std::move(sprite));
}
}
// Actualiza los sprites
void Instructions::updateSprites() {
SDL_FRect src_rect = {0, 0, param.game.item_size, param.game.item_size};
SDL_FRect src_rect = {0, 0, Item::WIDTH, Item::HEIGHT};
// Disquito
src_rect.y = param.game.item_size * (((counter_ + 12) / 36) % 2);
// Disquito (desplazamiento 12/60 = 0.2s)
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.2f) / SPRITE_ANIMATION_CYCLE_S) % 2);
sprites_[0]->setSpriteClip(src_rect);
// Gavina
src_rect.y = param.game.item_size * (((counter_ + 9) / 36) % 2);
// Gavina (desplazamiento 9/60 = 0.15s)
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.15f) / SPRITE_ANIMATION_CYCLE_S) % 2);
sprites_[1]->setSpriteClip(src_rect);
// Pacmar
src_rect.y = param.game.item_size * (((counter_ + 6) / 36) % 2);
// Pacmar (desplazamiento 6/60 = 0.1s)
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.1f) / SPRITE_ANIMATION_CYCLE_S) % 2);
sprites_[2]->setSpriteClip(src_rect);
// Time Stopper
src_rect.y = param.game.item_size * (((counter_ + 3) / 36) % 2);
// Time Stopper (desplazamiento 3/60 = 0.05s)
src_rect.y = Item::HEIGHT * (static_cast<int>((elapsed_time_ + 0.05f) / SPRITE_ANIMATION_CYCLE_S) % 2);
sprites_[3]->setSpriteClip(src_rect);
// Coffee
src_rect.y = param.game.item_size * (((counter_ + 0) / 36) % 2);
// Coffee (sin desplazamiento)
src_rect.y = Item::HEIGHT * (static_cast<int>(elapsed_time_ / SPRITE_ANIMATION_CYCLE_S) % 2);
sprites_[4]->setSpriteClip(src_rect);
}
// Rellena la textura de texto
void Instructions::fillTexture() {
const int X_OFFSET = param.game.item_size + 8;
const int X_OFFSET = Item::WIDTH + 8;
// Modifica el renderizador para pintar en la textura
auto *temp = SDL_GetRenderTarget(renderer_);
auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Limpia la textura
@@ -130,7 +131,7 @@ void Instructions::fillTexture() {
constexpr int SPACE_POST_HEADER = 20;
constexpr int SPACE_PRE_HEADER = 28;
const int SPACE_BETWEEN_LINES = text_->getCharacterSize() * 1.5F;
const int SPACE_BETWEEN_ITEM_LINES = param.game.item_size + item_space_;
const int SPACE_BETWEEN_ITEM_LINES = Item::HEIGHT + item_space_;
const int SPACE_NEW_PARAGRAPH = SPACE_BETWEEN_LINES * 0.5F;
const int SIZE = (NUM_LINES * SPACE_BETWEEN_LINES) + (NUM_ITEM_LINES * SPACE_BETWEEN_ITEM_LINES) + (NUM_POST_HEADERS * SPACE_POST_HEADER) + (NUM_PRE_HEADERS * SPACE_PRE_HEADER) + (SPACE_NEW_PARAGRAPH);
@@ -144,7 +145,7 @@ void Instructions::fillTexture() {
Lang::getText("[INSTRUCTIONS] 09"),
Lang::getText("[INSTRUCTIONS] 10"),
Lang::getText("[INSTRUCTIONS] 11")};
for (const auto &desc : ITEM_DESCRIPTIONS) {
for (const auto& desc : ITEM_DESCRIPTIONS) {
const int L = text_->length(desc);
length = L > length ? L : length;
}
@@ -178,13 +179,13 @@ void Instructions::fillTexture() {
// Da valor a la variable
sprite_pos_.x = ANCHOR_ITEM;
sprite_pos_.y = ANCHOR3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
sprite_pos_.y = ANCHOR3 - ((Item::HEIGHT - text_->getCharacterSize()) / 2);
}
// Rellena el backbuffer
void Instructions::fillBackbuffer() {
// Modifica el renderizador para pintar en la textura
auto *temp = SDL_GetRenderTarget(renderer_);
auto* temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_);
// Limpia la textura
@@ -195,7 +196,7 @@ void Instructions::fillBackbuffer() {
SDL_RenderTexture(renderer_, texture_, nullptr, nullptr);
// Dibuja los sprites
for (auto &sprite : sprites_) {
for (auto& sprite : sprites_) {
sprite->render();
}
@@ -204,25 +205,23 @@ void Instructions::fillBackbuffer() {
}
// Actualiza las variables
void Instructions::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
Screen::get()->update(); // Actualiza el objeto screen
void Instructions::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
static auto* const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
counter_++; // Incrementa el contador
updateSprites(); // Actualiza los sprites
updateBackbuffer(); // Gestiona la textura con los graficos
tiled_bg_->update(); // Actualiza el mosaico de fondo
fade_->update(); // Actualiza el objeto "fade"
updateBackbuffer(delta_time); // Gestiona la textura con los graficos
tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo
fade_->update(delta_time); // Actualiza el objeto "fade"
fillBackbuffer(); // Rellena el backbuffer
}
Audio::update();
}
// Pinta en pantalla
void Instructions::render() {
static auto *const SCREEN = Screen::get();
static auto* const SCREEN = Screen::get();
SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego
SCREEN->clean(); // Limpia la pantalla
@@ -255,12 +254,24 @@ void Instructions::checkInput() {
GlobalInputs::check();
}
// Calcula el tiempo transcurrido desde el último frame
float Instructions::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
}
// Bucle para la pantalla de instrucciones
void Instructions::run() {
last_time_ = SDL_GetTicks();
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::INSTRUCTIONS) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
@@ -277,11 +288,11 @@ auto Instructions::initializeLines(int height) -> std::vector<Line> {
}
// Método para mover las líneas con suavizado
auto Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool {
auto Instructions::moveLines(std::vector<Line>& lines, int width, float duration, Uint32 start_delay) -> bool {
Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true;
for (auto &line : lines) {
for (auto& line : lines) {
// Establecer start_time en el primer cuadro de animación
if (line.start_time == 0) {
line.start_time = current_time + line.y * start_delay;
@@ -306,8 +317,8 @@ auto Instructions::moveLines(std::vector<Line> &lines, int width, float duration
}
// Método para renderizar las líneas
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines) {
for (const auto &line : lines) {
void Instructions::renderLines(SDL_Renderer* renderer, SDL_Texture* texture, const std::vector<Line>& lines) {
for (const auto& line : lines) {
SDL_FRect src_rect = {0, static_cast<float>(line.y), 320, 1};
SDL_FRect dst_rect = {static_cast<float>(line.x), static_cast<float>(line.y), 320, 1};
SDL_RenderTexture(renderer, texture, &src_rect, &dst_rect);
@@ -315,23 +326,27 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con
}
// Gestiona la textura con los graficos
void Instructions::updateBackbuffer() {
// Establece la ventana del backbuffer
view_.y = std::max(0.0F, param.game.height - counter_ + 100);
void Instructions::updateBackbuffer(float delta_time) {
// Establece la ventana del backbuffer (convertir elapsed_time_ a equivalente de counter)
float counter_equivalent = elapsed_time_ * 60.0f; // Convertir segundos a equivalente frame para UI
view_.y = std::max(0.0F, param.game.height - counter_equivalent + 100);
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0) {
if (!start_delay_triggered_) {
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
} else if (SDL_GetTicks() - start_delay_time_ >= 4000) {
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0F, 5);
start_delay_timer_ = 0.0f;
} else {
start_delay_timer_ += delta_time;
if (start_delay_timer_ >= START_DELAY_S) {
// Han pasado los segundos de retraso, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, LINE_MOVE_DURATION_S, static_cast<Uint32>(LINE_START_DELAY_MS));
}
}
}
// Comprueba si el contador ha llegado al final
// Comprueba si todas las líneas han terminado
if (all_lines_off_screen_) {
Section::name = Section::Name::TITLE;
Section::options = Section::Options::TITLE_1;

View File

@@ -50,6 +50,12 @@ class Instructions {
void run();
private:
// --- Constantes de tiempo (en segundos) ---
static constexpr float SPRITE_ANIMATION_CYCLE_S = 36.0f / 60.0f; // Ciclo de animación sprites (≈0.6s)
static constexpr float START_DELAY_S = 4.0f; // Retraso antes de mover líneas (4s)
static constexpr float LINE_MOVE_DURATION_S = 1.0f; // Duración movimiento líneas (1s)
static constexpr float LINE_START_DELAY_MS = 5.0f; // Retraso entre líneas (5ms)
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *texture_; // Textura fija con el texto
@@ -62,18 +68,18 @@ class Instructions {
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
// --- Variables ---
int counter_ = 0; // Contador para manejar el progreso en la pantalla de instrucciones
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
float elapsed_time_ = 0.0f; // Tiempo transcurrido (segundos)
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
SDL_FRect view_; // Vista del backbuffer que se va a mostrar por pantalla
SDL_FPoint sprite_pos_ = {0, 0}; // Posición del primer sprite en la lista
float item_space_ = 2.0; // Espacio entre los items en pantalla
std::vector<Line> lines_; // Vector que contiene las líneas animadas en la pantalla
bool all_lines_off_screen_ = false; // Indica si todas las líneas han salido de la pantalla
Uint32 start_delay_time_ = 0; // Tiempo de inicio del retraso para mover las líneas
float start_delay_timer_ = 0.0f; // Timer para retraso antes de mover líneas (segundos)
bool start_delay_triggered_ = false; // Bandera para determinar si el retraso ha comenzado
// --- Métodos internos ---
void update(); // Actualiza las variables
void update(float delta_time); // Actualiza las variables
void render(); // Pinta en pantalla
static void checkEvents(); // Comprueba los eventos
static void checkInput(); // Comprueba las entradas
@@ -82,7 +88,8 @@ class Instructions {
void iniSprites(); // Inicializa los sprites de los items
void updateSprites(); // Actualiza los sprites
static auto initializeLines(int height) -> std::vector<Line>; // Inicializa las líneas animadas
static auto moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool; // Mueve las líneas
static auto moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool; // Mueve las líneas (ya usa tiempo real)
static void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines); // Renderiza las líneas
void updateBackbuffer(); // Gestiona la textura con los gráficos
void updateBackbuffer(float delta_time); // Gestiona la textura con los gráficos
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
};

View File

@@ -39,7 +39,7 @@ Intro::Intro()
initTexts();
// Configura el fondo
tiled_bg_->setSpeed(0.3F);
tiled_bg_->setSpeed(TILED_BG_SPEED);
tiled_bg_->setColor(bg_color_);
}
@@ -191,7 +191,7 @@ void Intro::updateScene5() {
// Acaba la ultima imagen
if (card_sprites_.at(5)->hasFinished() && texts_.at(8)->hasFinished()) {
state_ = State::POST;
state_start_time_ = SDL_GetTicks();
state_start_time_ = SDL_GetTicks() / 1000.0f;
}
}
@@ -207,17 +207,17 @@ void Intro::switchText(int from_index, int to_index) {
}
// Actualiza las variables del objeto
void Intro::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
Screen::get()->update(); // Actualiza el objeto screen
void Intro::update(float delta_time) {
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto Audio
tiled_bg_->update(); // Actualiza el fondo
tiled_bg_->update(delta_time); // Actualiza el fondo
switch (state_) {
case State::SCENES:
updateSprites();
updateTexts();
updateSprites(delta_time);
updateTexts(delta_time);
updateScenes();
break;
@@ -225,9 +225,6 @@ void Intro::update() {
updatePostState();
break;
}
}
Audio::update();
}
// Dibuja el objeto en pantalla
@@ -253,12 +250,24 @@ void Intro::render() {
SCREEN->render(); // Vuelca el contenido del renderizador en pantalla
}
// Calcula el tiempo transcurrido desde el último frame
float Intro::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
}
// Bucle principal
void Intro::run() {
last_time_ = SDL_GetTicks();
Audio::get()->playMusic("intro.ogg", 0);
while (Section::name == Section::Name::INTRO) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
@@ -277,7 +286,7 @@ void Intro::initSprites() {
// Constantes
constexpr int TOTAL_SPRITES = TEXTURE_LIST.size();
const float BORDER = 2.0F;
const float BORDER = CARD_BORDER_SIZE;
auto texture = Resource::get()->getTexture(TEXTURE_LIST.front());
const float CARD_WIDTH = texture->getWidth() + (BORDER * 2);
@@ -329,16 +338,16 @@ void Intro::initSprites() {
const float X_DEST = param.game.game_area.center_x - (CARD_WIDTH / 2);
const float Y_DEST = param.game.game_area.first_quarter_y - (CARD_HEIGHT / 4);
card_sprites_.at(0)->addPath(-CARD_WIDTH - 10, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeInOutExpo, 0);
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeOutBounce, 0);
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 40, easeOutQuint, 0);
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, 300, easeInOutExpo, 0);
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 70, easeOutElastic, 0);
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 250, easeOutQuad, 450);
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, 80, easeInElastic, 0);
card_sprites_.at(0)->addPath(-CARD_WIDTH - CARD_OFFSET_MARGIN, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0.0f);
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0.0f);
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
// Constantes
const float DESP = 8;
const float DESP = SHADOW_OFFSET;
const float SHADOW_SPRITE_WIDTH = CARD_WIDTH;
const float SHADOW_SPRITE_HEIGHT = CARD_HEIGHT;
@@ -380,13 +389,13 @@ void Intro::initSprites() {
const float S_X_DEST = X_DEST + DESP;
const float S_Y_DEST = Y_DEST + DESP;
shadow_sprites_.at(0)->addPath(param.game.height + 10, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeInOutExpo, 0);
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeOutBounce, 0);
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 40, easeOutQuint, 0);
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 300, easeInOutExpo, 0);
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 70, easeOutElastic, 0);
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 250, easeOutQuad, 450);
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, 80, easeInElastic, 0);
shadow_sprites_.at(0)->addPath(param.game.height + CARD_OFFSET_MARGIN, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0.0f);
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0.0f);
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
}
// Inicializa los textos
@@ -396,47 +405,47 @@ void Intro::initTexts() {
auto writer = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
writer->setPosX(0);
writer->setPosY(param.game.height - param.intro.text_distance_from_bottom);
writer->setKerning(-2);
writer->setKerning(TEXT_KERNING);
writer->setEnabled(false);
writer->setFinishedCounter(180);
writer->setFinishedTimerS(TEXT_DISPLAY_DURATION_S);
texts_.push_back(std::move(writer));
}
// Un dia qualsevol de l'any 2000
texts_.at(0)->setCaption(Lang::getText("[INTRO] 1"));
texts_.at(0)->setSpeed(8);
texts_.at(0)->setSpeedS(TEXT_SPEED_NORMAL);
// Tot esta tranquil a la UPV
texts_.at(1)->setCaption(Lang::getText("[INTRO] 2"));
texts_.at(1)->setSpeed(8);
texts_.at(1)->setSpeedS(TEXT_SPEED_NORMAL);
// Fins que un desaprensiu...
texts_.at(2)->setCaption(Lang::getText("[INTRO] 3"));
texts_.at(2)->setSpeed(12);
texts_.at(2)->setSpeedS(TEXT_SPEED_FAST);
// HEY! ME ANE A FERME UN CORTAET...
texts_.at(3)->setCaption(Lang::getText("[INTRO] 4"));
texts_.at(3)->setSpeed(8);
texts_.at(3)->setSpeedS(TEXT_SPEED_NORMAL);
// UAAAAAAAAAAAAA!!!
texts_.at(4)->setCaption(Lang::getText("[INTRO] 5"));
texts_.at(4)->setSpeed(1);
texts_.at(4)->setSpeedS(TEXT_SPEED_VERY_SLOW);
// Espera un moment...
texts_.at(5)->setCaption(Lang::getText("[INTRO] 6"));
texts_.at(5)->setSpeed(16);
texts_.at(5)->setSpeedS(TEXT_SPEED_VERY_FAST);
// Si resulta que no tinc solt!
texts_.at(6)->setCaption(Lang::getText("[INTRO] 7"));
texts_.at(6)->setSpeed(2);
texts_.at(6)->setSpeedS(TEXT_SPEED_SLOW);
// MERDA DE MAQUINA!
texts_.at(7)->setCaption(Lang::getText("[INTRO] 8"));
texts_.at(7)->setSpeed(3);
texts_.at(7)->setSpeedS(TEXT_SPEED_MEDIUM_SLOW);
// Blop... blop... blop...
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
texts_.at(8)->setSpeed(20);
texts_.at(8)->setSpeedS(TEXT_SPEED_ULTRA_FAST);
for (auto &text : texts_) {
text->center(param.game.game_area.center_x);
@@ -444,20 +453,20 @@ void Intro::initTexts() {
}
// Actualiza los sprites
void Intro::updateSprites() {
void Intro::updateSprites(float delta_time) {
for (auto &sprite : card_sprites_) {
sprite->update();
sprite->update(delta_time);
}
for (auto &sprite : shadow_sprites_) {
sprite->update();
sprite->update(delta_time);
}
}
// Actualiza los textos
void Intro::updateTexts() {
void Intro::updateTexts(float delta_time) {
for (auto &text : texts_) {
text->update();
text->updateS(delta_time); // Usar updateS para delta_time en segundos
}
}
@@ -476,12 +485,12 @@ void Intro::renderTexts() {
// Actualiza el estado POST
void Intro::updatePostState() {
const Uint32 ELAPSED_TIME = SDL_GetTicks() - state_start_time_;
const float ELAPSED_TIME = (SDL_GetTicks() / 1000.0f) - state_start_time_;
switch (post_state_) {
case PostState::STOP_BG:
// EVENTO: Detiene el fondo después de 1 segundo
if (ELAPSED_TIME >= 1000) {
// EVENTO: Detiene el fondo después del tiempo especificado
if (ELAPSED_TIME >= POST_BG_STOP_DELAY_S) {
tiled_bg_->stopGracefully();
if (!bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
@@ -494,13 +503,13 @@ void Intro::updatePostState() {
// Cambia de estado si el fondo se ha detenido y recuperado el color
if (tiled_bg_->isStopped() && bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
post_state_ = PostState::END;
state_start_time_ = SDL_GetTicks();
state_start_time_ = SDL_GetTicks() / 1000.0f;
}
break;
case PostState::END:
// Finaliza la intro después de 1 segundo
if (ELAPSED_TIME >= 1000) {
// Finaliza la intro después del tiempo especificado
if (ELAPSED_TIME >= POST_END_DELAY_S) {
Audio::get()->stopMusic();
Section::name = Section::Name::TITLE;
Section::options = Section::Options::TITLE_1;

View File

@@ -11,9 +11,22 @@
#include "tiled_bg.h" // Para TiledBG
#include "writer.h" // Para Writer
// --- Clase Intro: muestra la secuencia de introducción ---
// Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
// de introducción.
// --- Clase Intro: secuencia cinemática de introducción del juego ---
//
// Esta clase gestiona la secuencia de introducción narrativa del juego, mostrando
// una serie de escenas con imágenes, texto y efectos visuales sincronizados.
//
// Funcionalidades principales:
// • Sistema de escenas secuencial: 6 escenas con transiciones automáticas
// • Animaciones de tarjetas: efectos de entrada con diferentes tipos de easing
// • Texto narrativo: velocidades de escritura configurables por escena
// • Efectos visuales: sombras, bordes y transiciones de color
// • Audio sincronizado: música de fondo durante toda la secuencia
// • Estado POST: transición suave hacia el menú principal
//
// Todas las duraciones y velocidades están configuradas mediante constantes
// para facilitar el ajuste fino de la experiencia cinematográfica.
class Intro {
public:
// --- Constructor y destructor ---
@@ -24,6 +37,37 @@ class Intro {
void run();
private:
// --- Constantes de tiempo (en segundos) ---
static constexpr float TEXT_DISPLAY_DURATION_S = 3.0f; // Duración de visualización de texto (180 frames a 60fps)
static constexpr float POST_BG_STOP_DELAY_S = 1.0f; // Retraso antes de detener el fondo
static constexpr float POST_END_DELAY_S = 1.0f; // Retraso antes de finalizar intro
// --- Constantes de layout ---
static constexpr float CARD_BORDER_SIZE = 2.0f; // Tamaño del borde de tarjetas
static constexpr float SHADOW_OFFSET = 8.0f; // Desplazamiento de sombra
static constexpr float TILED_BG_SPEED = 18.0f; // Velocidad del fondo mosaico (pixels/segundo)
static constexpr int TEXT_KERNING = -2; // Espaciado entre caracteres
// --- Constantes de velocidades de texto (segundos entre caracteres) ---
static constexpr float TEXT_SPEED_NORMAL = 0.133f; // Velocidad normal (8 frames * 16.67ms = 133ms)
static constexpr float TEXT_SPEED_FAST = 0.2f; // Velocidad rápida (12 frames * 16.67ms = 200ms)
static constexpr float TEXT_SPEED_VERY_SLOW = 0.0167f; // Velocidad muy lenta (1 frame * 16.67ms = 16.7ms)
static constexpr float TEXT_SPEED_VERY_FAST = 0.267f; // Velocidad muy rápida (16 frames * 16.67ms = 267ms)
static constexpr float TEXT_SPEED_SLOW = 0.033f; // Velocidad lenta (2 frames * 16.67ms = 33ms)
static constexpr float TEXT_SPEED_MEDIUM_SLOW = 0.05f; // Velocidad medio-lenta (3 frames * 16.67ms = 50ms)
static constexpr float TEXT_SPEED_ULTRA_FAST = 0.333f; // Velocidad ultra rápida (20 frames * 16.67ms = 333ms)
// --- Constantes de animaciones de tarjetas (duraciones en segundos) ---
static constexpr float CARD_ANIM_DURATION_NORMAL = 100.0f / 60.0f; // ≈ 1.6667 s
static constexpr float CARD_ANIM_DURATION_FAST = 40.0f / 60.0f; // ≈ 0.6667 s
static constexpr float CARD_ANIM_DURATION_MEDIUM = 70.0f / 60.0f; // ≈ 1.1667 s
static constexpr float CARD_ANIM_DURATION_SHORT = 80.0f / 60.0f; // ≈ 1.3333 s
static constexpr float CARD_ANIM_DURATION_SLOW = 250.0f / 60.0f; // ≈ 4.1667 s
static constexpr float CARD_ANIM_DURATION_VERY_SLOW = 300.0f / 60.0f; // ≈ 5.0000 s
static constexpr float CARD_ANIM_DELAY_LONG = 0.45f; // Retraso largo antes de animación
static constexpr float CARD_OFFSET_MARGIN = 10.0f; // Margen fuera de pantalla
// --- Estados internos ---
enum class State {
SCENES,
@@ -42,27 +86,28 @@ class Intro {
std::unique_ptr<TiledBG> tiled_bg_; // Fondo en mosaico
// --- Variables ---
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
int scene_ = 0; // Indica qué escena está activa
State state_ = State::SCENES; // Estado principal de la intro
PostState post_state_ = PostState::STOP_BG; // Estado POST
Uint32 state_start_time_; // Tiempo de inicio del estado actual
float state_start_time_; // Tiempo de inicio del estado actual (segundos)
Color bg_color_ = param.intro.bg_color; // Color de fondo
// --- Métodos internos ---
void update(); // Actualiza las variables del objeto
void update(float delta_time); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla
static void checkInput(); // Comprueba las entradas
static void checkEvents(); // Comprueba los eventos
void updateScenes(); // Actualiza las escenas de la intro
void initSprites(); // Inicializa las imágenes
void initTexts(); // Inicializa los textos
void updateSprites(); // Actualiza los sprites
void updateTexts(); // Actualiza los textos
void updateSprites(float delta_time); // Actualiza los sprites
void updateTexts(float delta_time); // Actualiza los textos
void renderSprites(); // Dibuja los sprites
void renderTexts(); // Dibuja los textos
static void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
void updatePostState(); // Actualiza el estado POST
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
// --- Métodos para manejar cada escena individualmente ---
void updateScene0();

View File

@@ -28,38 +28,38 @@ Logo::Logo()
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
since_sprite_->setPosition(SDL_FRect{
static_cast<float>((param.game.width - since_texture_->getWidth()) / 2),
static_cast<float>(83 + jail_texture_->getHeight() + 5),
static_cast<float>(SINCE_SPRITE_Y_OFFSET + jail_texture_->getHeight() + LOGO_SPACING),
static_cast<float>(since_texture_->getWidth()),
static_cast<float>(since_texture_->getHeight())});
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + LOGO_SPACING);
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
since_texture_->setColor(0x00, 0x00, 0x00);
since_texture_->setColor(SPECTRUM_BLACK.r, SPECTRUM_BLACK.g, SPECTRUM_BLACK.b);
// Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i) {
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), SPRITE_LINE_HEIGHT);
temp->setSpriteClip(0, i, jail_texture_->getWidth(), SPRITE_LINE_HEIGHT);
const int POS_X = (i % 2 == 0) ? param.game.width + (i * LINE_OFFSET_FACTOR) : -jail_texture_->getWidth() - (i * LINE_OFFSET_FACTOR);
temp->setX(POS_X);
temp->setY(dest_.y + i);
jail_sprite_.push_back(std::move(temp));
}
// Inicializa el vector de colores
color_.emplace_back(0x00, 0x00, 0x00); // Black
color_.emplace_back(0x00, 0x00, 0xd8); // Blue
color_.emplace_back(0xd8, 0x00, 0x00); // Red
color_.emplace_back(0xd8, 0x00, 0xd8); // Magenta
color_.emplace_back(0x00, 0xd8, 0x00); // Green
color_.emplace_back(0x00, 0xd8, 0xd8); // Cyan
color_.emplace_back(0xd8, 0xd8, 0x00); // Yellow
color_.emplace_back(0xFF, 0xFF, 0xFF); // Bright white
// Inicializa el vector de colores con la paleta ZX Spectrum
color_.emplace_back(SPECTRUM_BLACK);
color_.emplace_back(SPECTRUM_BLUE);
color_.emplace_back(SPECTRUM_RED);
color_.emplace_back(SPECTRUM_MAGENTA);
color_.emplace_back(SPECTRUM_GREEN);
color_.emplace_back(SPECTRUM_CYAN);
color_.emplace_back(SPECTRUM_YELLOW);
color_.emplace_back(SPECTRUM_WHITE);
}
// Destructor
Logo::~Logo() {
jail_texture_->setColor(255, 255, 255);
since_texture_->setColor(255, 255, 255);
jail_texture_->setColor(RESET_COLOR.r, RESET_COLOR.g, RESET_COLOR.b);
since_texture_->setColor(RESET_COLOR.r, RESET_COLOR.g, RESET_COLOR.b);
Audio::get()->stopAllSounds();
Audio::get()->stopMusic();
}
@@ -78,22 +78,28 @@ void Logo::checkInput() {
GlobalInputs::check();
}
// Gestiona el logo de JAILGAMES
void Logo::updateJAILGAMES() {
if (counter_ == 30) {
// Maneja la reproducción del sonido del logo
void Logo::handleSound() {
if (!sound_triggered_ && elapsed_time_s_ >= SOUND_TRIGGER_TIME_S) {
Audio::get()->playSound("logo.wav");
sound_triggered_ = true;
}
}
if (counter_ > 30) {
for (int i = 0; i < (int)jail_sprite_.size(); ++i) {
// Gestiona el logo de JAILGAMES
void Logo::updateJAILGAMES(float delta_time) {
if (elapsed_time_s_ > SOUND_TRIGGER_TIME_S) {
const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_S * delta_time;
for (size_t i = 0; i < jail_sprite_.size(); ++i) {
if (jail_sprite_[i]->getX() != dest_.x) {
if (i % 2 == 0) {
jail_sprite_[i]->incX(-SPEED);
jail_sprite_[i]->incX(-PIXELS_TO_MOVE);
if (jail_sprite_[i]->getX() < dest_.x) {
jail_sprite_[i]->setX(dest_.x);
}
} else {
jail_sprite_[i]->incX(SPEED);
jail_sprite_[i]->incX(PIXELS_TO_MOVE);
if (jail_sprite_[i]->getX() > dest_.x) {
jail_sprite_[i]->setX(dest_.x);
}
@@ -103,43 +109,42 @@ void Logo::updateJAILGAMES() {
}
// Comprueba si ha terminado el logo
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION) {
if (elapsed_time_s_ >= END_LOGO_TIME_S + POST_LOGO_DURATION_S) {
Section::name = Section::Name::INTRO;
}
}
// Gestiona el color de las texturas
void Logo::updateTextureColors() {
constexpr int INC = 4;
void Logo::updateTextureColors(float delta_time) {
// Manejo de 'sinceTexture'
for (int i = 0; i <= 7; ++i) {
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + INC * i) {
for (int i = 0; i <= MAX_SINCE_COLOR_INDEX; ++i) {
const float target_time = SHOW_SINCE_SPRITE_TIME_S + COLOR_CHANGE_INTERVAL_S * i;
if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) {
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
}
}
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
for (int i = 0; i <= 6; ++i) {
if (counter_ == INIT_FADE_COUNTER_MARK + INC * i) {
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
for (int i = 0; i <= MAX_FADE_COLOR_INDEX; ++i) {
const float target_time = INIT_FADE_TIME_S + COLOR_CHANGE_INTERVAL_S * i;
if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) {
jail_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
since_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
}
}
}
// Actualiza las variables
void Logo::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
Screen::get()->update(); // Actualiza el objeto screen
void Logo::update(float delta_time) {
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
updateJAILGAMES(); // Actualiza el logo de JAILGAMES
updateTextureColors(); // Actualiza los colores de las texturas
++counter_; // Gestiona el contador
}
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
Audio::update();
handleSound(); // Maneja la reproducción del sonido
updateTextureColors(delta_time); // Actualiza los colores de las texturas
updateJAILGAMES(delta_time); // Actualiza el logo de JAILGAMES
}
// Dibuja en pantalla
@@ -154,11 +159,23 @@ void Logo::render() {
SCREEN->render();
}
// Calcula el tiempo transcurrido desde el último frame
float Logo::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
}
// Bucle para el logo del juego
void Logo::run() {
last_time_ = SDL_GetTicks();
while (Section::name == Section::Name::LOGO) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
@@ -171,7 +188,7 @@ void Logo::renderJAILGAMES() {
sprite->render();
}
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK) {
if (elapsed_time_s_ >= SHOW_SINCE_SPRITE_TIME_S) {
since_sprite_->render();
}
}

View File

@@ -10,12 +10,21 @@
class Texture;
// --- Clase Logo: dibuja el logo de JAILGAMES con efectos visuales ---
// Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
// logo de "JAILGAMES" utilizando un sencillo efecto consistente en generar un sprite por
// cada línea del bitmap que forma la palabra "JAILGAMES". Posteriormente realiza una
// modulación de color sobre la textura para simular un fade to black al estilo
// ZX Spectrum.
// --- Clase Logo: pantalla de presentación de JAILGAMES con efectos retro ---
//
// Esta clase gestiona el estado inicial del programa, mostrando el logo corporativo
// de JAILGAMES con efectos visuales inspirados en el ZX Spectrum.
//
// Funcionalidades principales:
// • Animación de convergencia: cada línea del logo entra desde los laterales
// • Efectos de color: transiciones automáticas usando la paleta ZX Spectrum
// • Audio sincronizado: reproduce sonido del logo en momento específico
// • Transición temporal: duración controlada con paso automático al siguiente estado
// • Sistema delta-time: animaciones suaves independientes del framerate
//
// La clase utiliza un sistema de tiempo basado en segundos para garantizar
// consistencia visual en diferentes velocidades de procesamiento.
class Logo {
public:
// --- Constructor y destructor ---
@@ -26,12 +35,35 @@ class Logo {
void run();
private:
// --- Constantes ---
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
static constexpr int END_LOGO_COUNTER_MARK = 400; // Tiempo del contador para terminar el logo
static constexpr int POST_LOGO_DURATION = 20; // Tiempo que dura el logo con el fade al máximo
static constexpr int SPEED = 8; // Velocidad de desplazamiento de cada línea
// --- Constantes de tiempo (en segundos) ---
static constexpr float SOUND_TRIGGER_TIME_S = 0.5f; // Tiempo para activar el sonido del logo
static constexpr float SHOW_SINCE_SPRITE_TIME_S = 1.167f; // Tiempo para mostrar el sprite "SINCE 1998"
static constexpr float INIT_FADE_TIME_S = 5.0f; // Tiempo de inicio del fade a negro
static constexpr float END_LOGO_TIME_S = 6.668f; // Tiempo de finalización del logo
static constexpr float POST_LOGO_DURATION_S = 0.333f; // Duración adicional después del fade
static constexpr float LOGO_SPEED_PX_PER_S = 480.0f; // Velocidad de desplazamiento (píxeles por segundo) - 8.0f/16.67f*1000
static constexpr float COLOR_CHANGE_INTERVAL_S = 0.0667f; // Intervalo entre cambios de color (~4 frames a 60fps)
// --- Constantes de layout ---
static constexpr int SINCE_SPRITE_Y_OFFSET = 83; // Posición Y base del sprite "Since 1998"
static constexpr int LOGO_SPACING = 5; // Espaciado entre elementos del logo
static constexpr int LINE_OFFSET_FACTOR = 3; // Factor de desplazamiento inicial por línea
static constexpr int SPRITE_LINE_HEIGHT = 1; // Altura de cada línea sprite
// --- Constantes de colores ---
static constexpr int MAX_SINCE_COLOR_INDEX = 7; // Índice máximo para colores del sprite "Since"
static constexpr int MAX_FADE_COLOR_INDEX = 6; // Índice máximo para colores del fade
// --- Paleta ZX Spectrum para efectos de logo ---
static constexpr Color SPECTRUM_BLACK = Color(0x00, 0x00, 0x00); // Negro
static constexpr Color SPECTRUM_BLUE = Color(0x00, 0x00, 0xd8); // Azul
static constexpr Color SPECTRUM_RED = Color(0xd8, 0x00, 0x00); // Rojo
static constexpr Color SPECTRUM_MAGENTA = Color(0xd8, 0x00, 0xd8); // Magenta
static constexpr Color SPECTRUM_GREEN = Color(0x00, 0xd8, 0x00); // Verde
static constexpr Color SPECTRUM_CYAN = Color(0x00, 0xd8, 0xd8); // Cian
static constexpr Color SPECTRUM_YELLOW = Color(0xd8, 0xd8, 0x00); // Amarillo
static constexpr Color SPECTRUM_WHITE = Color(0xFF, 0xFF, 0xFF); // Blanco brillante
static constexpr Color RESET_COLOR = Color(255, 255, 255); // Color de reset
// --- Objetos y punteros ---
std::shared_ptr<Texture> since_texture_; // Textura con los gráficos "Since 1998"
@@ -41,16 +73,19 @@ class Logo {
// --- Variables ---
std::vector<Color> color_; // Vector con los colores para el fade
int counter_ = 0; // Contador
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
float elapsed_time_s_ = 0.0f; // Tiempo transcurrido en segundos
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
SDL_FPoint dest_; // Posición donde dibujar el logo
bool sound_triggered_ = false; // Indica si el sonido del logo ya se reprodujo
// --- Métodos internos ---
void update(); // Actualiza las variables
void update(float delta_time); // Actualiza las variables
void render(); // Dibuja en pantalla
static void checkEvents(); // Comprueba el manejador de eventos
static void checkInput(); // Comprueba las entradas
void updateJAILGAMES(); // Gestiona el logo de JAILGAMES
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAMES
void renderJAILGAMES(); // Renderiza el logo de JAILGAMES
void updateTextureColors(); // Gestiona el color de las texturas
void updateTextureColors(float delta_time); // Gestiona el color de las texturas
void handleSound(); // Maneja la reproducción del sonido del logo
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
};

View File

@@ -42,10 +42,15 @@ Title::Title()
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
state_(TitleState::LOGO_ANIMATING),
num_controllers_(Input::get()->getNumGamepads()) {
state_(State::LOGO_ANIMATING),
num_controllers_(Input::get()->getNumGamepads())
#ifdef _DEBUG
, debug_color_(param.title.bg_color)
#endif
{
// Configura objetos
tiled_bg_->setColor(param.title.bg_color);
tiled_bg_->setSpeed(0.0F);
game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
fade_->setColor(param.fade.color);
@@ -60,16 +65,16 @@ Title::Title()
Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO;
// Define los anclajes de los elementos
anchor_.mini_logo = (param.game.height / 5 * 4) + BLOCK;
anchor_.mini_logo = (param.game.height / MINI_LOGO_Y_DIVISOR * MINI_LOGO_Y_FACTOR) + BLOCK;
mini_logo_sprite_->setY(anchor_.mini_logo);
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + 3;
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + COPYRIGHT_TEXT_SPACING;
}
// Destructor
Title::~Title() {
Audio::get()->stopAllSounds();
if (Section::name == Section::Name::LOGO) {
Audio::get()->fadeOutMusic(300);
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_SHORT_MS);
}
// Desregistra los jugadores de Options
@@ -78,18 +83,26 @@ Title::~Title() {
}
// Actualiza las variables del objeto
void Title::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks();
Screen::get()->update();
void Title::update(float deltaTime) {
static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateFade();
updateState();
updateStartPrompt();
updatePlayers();
}
updateState(deltaTime);
updateStartPrompt(deltaTime);
Audio::update();
for (auto& player : players_) {
player->update(deltaTime);
}
}
// Calcula el tiempo transcurrido desde el último frame
float Title::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convert ms to seconds
last_time_ = current_time;
return delta_time;
}
// Dibuja el objeto en pantalla
@@ -132,13 +145,11 @@ void Title::handleKeyDownEvent(const SDL_Event& event) {
#ifdef _DEBUG
void Title::handleDebugColorKeys(SDL_Keycode key) {
static Color color_ = param.title.bg_color;
adjustColorComponent(key, debug_color_);
adjustColorComponent(key, color_);
counter_ = 0;
tiled_bg_->setColor(color_);
printColorValue(color_);
counter_time_ = 0.0f;
tiled_bg_->setColor(debug_color_);
printColorValue(debug_color_);
}
void Title::adjustColorComponent(SDL_Keycode key, Color& color) {
@@ -270,7 +281,7 @@ void Title::handleStartButtonPress(const Options::Gamepad* controller) {
}
auto Title::canProcessStartButton() const -> bool {
return (state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP);
return (state_ != State::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP);
}
void Title::processPlayer1Start() {
@@ -289,22 +300,26 @@ void Title::processPlayer2Start() {
void Title::activatePlayerAndSetState(Player::Id player_id) {
getPlayer(player_id)->setPlayingState(Player::State::TITLE_ANIMATION);
setState(TitleState::START_HAS_BEEN_PRESSED);
counter_ = 0;
setState(State::START_HAS_BEEN_PRESSED);
counter_time_ = 0.0f;
}
// Bucle para el titulo del juego
void Title::run() {
last_time_ = SDL_GetTicks();
while (Section::name == Section::Name::TITLE) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Reinicia el contador interno
void Title::resetCounter() { counter_ = 0; }
void Title::resetCounter() { counter_time_ = 0.0f; }
// Intercambia la asignación de mandos a los jugadores
void Title::swapControllers() {
@@ -366,22 +381,22 @@ void Title::updateFade() {
}
// Actualiza el estado
void Title::updateState() {
void Title::updateState(float deltaTime) {
game_logo_->update(deltaTime);
tiled_bg_->update(deltaTime);
// Establece la lógica según el estado
switch (state_) {
case TitleState::LOGO_ANIMATING: {
game_logo_->update();
case State::LOGO_ANIMATING: {
if (game_logo_->hasFinished()) {
setState(TitleState::LOGO_FINISHED);
setState(State::LOGO_FINISHED);
}
break;
}
case TitleState::LOGO_FINISHED: {
++counter_; // Incrementa el contador
game_logo_->update(); // Actualiza el logo con el título del juego
tiled_bg_->update(); // Actualiza el mosaico de fondo
case State::LOGO_FINISHED: {
counter_time_ += deltaTime;
if (counter_ == param.title.title_duration) {
if (counter_time_ >= param.title.title_duration) {
// El menu ha hecho time out
fade_->setPostDuration(0);
fade_->activate();
@@ -389,12 +404,10 @@ void Title::updateState() {
}
break;
}
case TitleState::START_HAS_BEEN_PRESSED: {
++counter_; // Incrementa el contador
game_logo_->update(); // Actualiza el logo con el título del juego
tiled_bg_->update(); // Actualiza el mosaico de fondo
case State::START_HAS_BEEN_PRESSED: {
counter_time_ += deltaTime;
if (counter_ == 100) {
if (counter_time_ >= START_PRESSED_DELAY_S) {
fade_->activate();
}
break;
@@ -405,29 +418,38 @@ void Title::updateState() {
}
}
void Title::updateStartPrompt() {
constexpr Uint32 LOGO_BLINK_PERIOD = 833; // milisegundos
constexpr Uint32 LOGO_BLINK_ON_TIME = 583; // 833 - 250
void Title::updateStartPrompt(float deltaTime) {
blink_accumulator_ += deltaTime;
constexpr Uint32 START_BLINK_PERIOD = 167;
constexpr Uint32 START_BLINK_ON_TIME = 83; // 167 - 83
Uint32 time_ms = SDL_GetTicks();
bool condition_met = false;
float period = 0.0f;
float on_time = 0.0f;
switch (state_) {
case TitleState::LOGO_FINISHED:
condition_met = (time_ms % LOGO_BLINK_PERIOD) >= (LOGO_BLINK_PERIOD - LOGO_BLINK_ON_TIME);
case State::LOGO_FINISHED:
period = LOGO_BLINK_PERIOD_S;
on_time = LOGO_BLINK_ON_TIME_S;
break;
case TitleState::START_HAS_BEEN_PRESSED:
condition_met = (time_ms % START_BLINK_PERIOD) >= (START_BLINK_PERIOD - START_BLINK_ON_TIME);
case State::START_HAS_BEEN_PRESSED:
period = START_BLINK_PERIOD_S;
on_time = START_BLINK_ON_TIME_S;
break;
default:
break;
}
if (period > 0.0f) {
// Reset accumulator when it exceeds the period
if (blink_accumulator_ >= period) {
blink_accumulator_ -= period;
}
// Check if we're in the "on" time of the blink cycle
condition_met = blink_accumulator_ >= (period - on_time);
}
should_render_start_prompt_ = condition_met;
}
@@ -445,7 +467,7 @@ void Title::renderStartPrompt() {
}
void Title::renderCopyright() {
if (state_ != TitleState::LOGO_ANIMATING) {
if (state_ != State::LOGO_ANIMATING) {
// Mini logo
mini_logo_sprite_->render();
@@ -462,20 +484,23 @@ void Title::renderCopyright() {
}
// Cambia el estado
void Title::setState(TitleState state) {
void Title::setState(State state) {
if (state_ == state) {
return;
}
state_ = state;
switch (state_) {
case TitleState::LOGO_ANIMATING:
case State::LOGO_ANIMATING:
break;
case TitleState::LOGO_FINISHED:
case State::LOGO_FINISHED:
Audio::get()->playMusic("title.ogg");
tiled_bg_->changeSpeedTo(60.0F, 0.5F);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break;
case TitleState::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(1500);
case State::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break;
}
}
@@ -544,13 +569,6 @@ void Title::initPlayers() {
}
}
// Actualza los jugadores
void Title::updatePlayers() {
for (auto& player : players_) {
player->update();
}
}
// Renderiza los jugadores
void Title::renderPlayers() {
for (auto const& player : players_) {

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