Compare commits

12 Commits

26 changed files with 1334 additions and 341 deletions

171
Makefile
View File

@@ -11,7 +11,22 @@ APP_NAME := Coffee Crisis Arcade Edition
RELEASE_FOLDER := ccae_release
RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME)
RESOURCE_FILE := release/coffee.res
VERSION := 2025-08-10
# 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'")
else
VERSION := $(shell date +%Y-%m-%d)
endif
# Variables específicas para Windows (usando APP_NAME)
ifeq ($(OS),Windows_NT)
WIN_TARGET_FILE := $(DIR_BIN)$(APP_NAME)
WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME)
else
WIN_TARGET_FILE := $(TARGET_FILE)
WIN_RELEASE_FILE := $(RELEASE_FILE)
endif
# Nombres para los ficheros de lanzamiento
WINDOWS_RELEASE := $(TARGET_NAME)-$(VERSION)-win32-x64.zip
@@ -120,20 +135,24 @@ endif
# Reglas para compilación
windows:
@echo off
@echo Compilando para Windows con nombre: "$(APP_NAME).exe"
windres release/coffee.rc -O coff -o $(RESOURCE_FILE)
$(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE).exe"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE).exe" --strip-unneeded
$(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_TARGET_FILE).exe"
strip -s -R .comment -R .gnu.version "$(WIN_TARGET_FILE).exe" --strip-unneeded
windows_rec:
@echo off
$(CXX) $(APP_SOURCES) $(INCLUDES) -DRECORDING $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)_rec.exe"
@echo Compilando version de grabacion para Windows: "$(APP_NAME)_rec.exe"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DRECORDING $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_rec.exe"
windows_debug:
@echo off
$(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug.exe"
@echo Compilando version debug para Windows: "$(APP_NAME)_debug.exe"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe"
windows_release:
@echo off
@echo Creando release para Windows - Version: $(VERSION)
# Crea carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
@@ -149,23 +168,27 @@ windows_release:
# Compila
windres release/coffee.rc -O coff -o $(RESOURCE_FILE)
$(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE).exe"
strip -s -R .comment -R .gnu.version "$(RELEASE_FILE).exe" --strip-unneeded
$(CXX) $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe"
strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded
# Crea el fichero .zip
powershell if (Test-Path "$(WINDOWS_RELEASE)") {Remove-Item "$(WINDOWS_RELEASE)"}
powershell Compress-Archive -Path "$(RELEASE_FOLDER)"/* -DestinationPath "$(WINDOWS_RELEASE)"
@echo Release creado: $(WINDOWS_RELEASE)
# Elimina la carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
macos:
@echo "Compilando para macOS: $(TARGET_NAME)"
$(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
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:
@echo "Creando release para macOS - Version: $(VERSION)"
# Elimina datos de compilaciones anteriores
$(RMDIR) "$(RELEASE_FOLDER)"
$(RMDIR) Frameworks
@@ -202,6 +225,7 @@ ifdef ENABLE_MACOS_X86_64
hdiutil create tmp.dmg -ov -volname "$(APP_NAME)" -fs HFS+ -srcfolder "$(RELEASE_FOLDER)"
hdiutil convert tmp.dmg -format UDZO -o "$(MACOS_INTEL_RELEASE)"
$(RMFILE) tmp.dmg
@echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"
endif
# Compila la versión para procesadores Apple Silicon
@@ -214,19 +238,23 @@ endif
hdiutil create tmp.dmg -ov -volname "$(APP_NAME)" -fs HFS+ -srcfolder "$(RELEASE_FOLDER)"
hdiutil convert tmp.dmg -format UDZO -o "$(MACOS_APPLE_SILICON_RELEASE)"
$(RMFILE) tmp.dmg
@echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)"
# Elimina las carpetas temporales
$(RMDIR) Frameworks
$(RMDIR) "$(RELEASE_FOLDER)"
linux:
@echo "Compilando para Linux: $(TARGET_NAME)"
$(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded
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:
@echo "Creando release para Linux - Version: $(VERSION)"
# Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"
@@ -245,18 +273,117 @@ linux_release:
# Empaqueta ficheros
$(RMFILE) "$(LINUX_RELEASE)"
tar -czvf "$(LINUX_RELEASE)" -C "$(RELEASE_FOLDER)" .
@echo "Release creado: $(LINUX_RELEASE)"
# Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)"
linux_release_desktop:
@echo "Creando release con integracion desktop para Linux - Version: $(VERSION)"
# Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"
# Crea la estructura de directorios estándar para Linux
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)"
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin"
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications"
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps"
$(MKDIR) "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/$(TARGET_NAME)"
# Copia ficheros del juego
cp -R data "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/$(TARGET_NAME)/"
cp LICENSE "$(RELEASE_FOLDER)/$(TARGET_NAME)/"
cp README.md "$(RELEASE_FOLDER)/$(TARGET_NAME)/"
# Compila el ejecutable
$(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)"
strip -s -R .comment -R .gnu.version "$(RELEASE_FOLDER)/$(TARGET_NAME)/bin/$(TARGET_NAME)" --strip-unneeded
# Crea el archivo .desktop
@echo '[Desktop Entry]' > "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Version=1.0' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Type=Application' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Name=$(APP_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Comment=Arcade action game - defend Earth from alien invasion!' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Exec=/opt/$(TARGET_NAME)/bin/$(TARGET_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Icon=$(TARGET_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Path=/opt/$(TARGET_NAME)/share/$(TARGET_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Terminal=false' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'StartupNotify=true' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Categories=Game;ArcadeGame;' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
@echo 'Keywords=arcade;action;shooter;retro;' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop"
# Copia el icono (si existe) y lo redimensiona si es necesario
@if [ -f "release/icon.png" ]; then \
if command -v magick >/dev/null 2>&1; then \
magick "release/icon.png" -resize 256x256 "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png"; \
echo "Icono redimensionado de release/icon.png (usando ImageMagick)"; \
elif command -v convert >/dev/null 2>&1; then \
convert "release/icon.png" -resize 256x256 "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png"; \
echo "Icono redimensionado de release/icon.png (usando ImageMagick legacy)"; \
elif command -v ffmpeg >/dev/null 2>&1; then \
ffmpeg -i "release/icon.png" -vf scale=256:256 "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png" -y -loglevel quiet; \
echo "Icono redimensionado de release/icon.png (usando ffmpeg)"; \
else \
cp "release/icon.png" "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png"; \
echo "Icono copiado sin redimensionar (instalar ImageMagick o ffmpeg para redimensionado automatico)"; \
fi; \
elif [ -f "release/coffee.png" ]; then \
cp "release/coffee.png" "$(RELEASE_FOLDER)/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png"; \
echo "Icono copiado desde release/coffee.png"; \
else \
echo "Advertencia: No se encontró release/icon.png ni release/coffee.png - crear icono manualmente"; \
fi
# Crea script de instalación
@echo '#!/bin/bash' > "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'echo "Instalando $(APP_NAME)..."' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo mkdir -p /opt/$(TARGET_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp -R bin /opt/$(TARGET_NAME)/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp -R share /opt/$(TARGET_NAME)/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp LICENSE /opt/$(TARGET_NAME)/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp README.md /opt/$(TARGET_NAME)/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo mkdir -p /usr/share/applications' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo mkdir -p /usr/share/icons/hicolor/256x256/apps' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp /opt/$(TARGET_NAME)/share/applications/$(TARGET_NAME).desktop /usr/share/applications/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo cp /opt/$(TARGET_NAME)/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png /usr/share/icons/hicolor/256x256/apps/' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo update-desktop-database /usr/share/applications 2>/dev/null || true' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'sudo gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'echo "$(APP_NAME) instalado correctamente!"' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
@echo 'echo "Ya puedes encontrarlo en el menu de aplicaciones en la categoria Juegos."' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
chmod +x "$(RELEASE_FOLDER)/$(TARGET_NAME)/install.sh"
# Crea script de desinstalación
@echo '#!/bin/bash' > "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'echo "Desinstalando $(APP_NAME)..."' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'sudo rm -rf /opt/$(TARGET_NAME)' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'sudo rm -f /usr/share/applications/$(TARGET_NAME).desktop' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'sudo rm -f /usr/share/icons/hicolor/256x256/apps/$(TARGET_NAME).png' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'sudo update-desktop-database /usr/share/applications 2>/dev/null || true' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'sudo gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
@echo 'echo "$(APP_NAME) desinstalado correctamente."' >> "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
chmod +x "$(RELEASE_FOLDER)/$(TARGET_NAME)/uninstall.sh"
# Empaqueta ficheros
$(RMFILE) "$(TARGET_NAME)-$(VERSION)-linux-desktop.tar.gz"
tar -czvf "$(TARGET_NAME)-$(VERSION)-linux-desktop.tar.gz" -C "$(RELEASE_FOLDER)" .
@echo "Release con integracion desktop creado: $(TARGET_NAME)-$(VERSION)-linux-desktop.tar.gz"
@echo "Para instalar: extraer y ejecutar ./$(TARGET_NAME)/install.sh"
# Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)"
raspi:
@echo "Compilando para Raspberry Pi: $(TARGET_NAME)"
$(CXX) $(APP_SOURCES) $(INCLUDES) -DVERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
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:
@echo "Creando release para Raspberry Pi - Version: $(VERSION)"
# Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"
@@ -275,11 +402,13 @@ raspi_release:
# Empaqueta ficheros
$(RMFILE) "$(RASPI_RELEASE)"
tar -czvf "$(RASPI_RELEASE)" -C "$(RELEASE_FOLDER)" .
@echo "Release creado: $(RASPI_RELEASE)"
# Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)"
anbernic:
@echo "Compilando para Anbernic: $(TARGET_NAME)"
# Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"_anbernic
@@ -294,6 +423,32 @@ anbernic:
# Opción para deshabilitar audio (equivalente a la opción DISABLE_AUDIO de CMake)
no_audio:
@echo "Compilando sin audio: $(TARGET_NAME)_no_audio"
$(CXX) $(filter-out source/external/jail_audio.cpp,$(APP_SOURCES)) $(INCLUDES) -DNO_AUDIO $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)_no_audio"
.PHONY: windows windows_rec windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release raspi raspi_debug raspi_release anbernic no_audio
# Regla para mostrar la versión actual
show_version:
@echo "Version actual: $(VERSION)"
# Regla de ayuda
help:
@echo "Makefile para Coffee Crisis Arcade Edition"
@echo "Comandos disponibles:"
@echo " windows - Compilar para Windows"
@echo " windows_debug - Compilar debug para Windows"
@echo " windows_release - Crear release completo para Windows"
@echo " linux - Compilar para Linux"
@echo " linux_debug - Compilar debug para Linux"
@echo " linux_release - Crear release basico para Linux"
@echo " linux_release_desktop - Crear release con integracion desktop para Linux"
@echo " macos - Compilar para macOS"
@echo " macos_debug - Compilar debug para macOS"
@echo " macos_release - Crear release completo para macOS"
@echo " raspi - Compilar para Raspberry Pi"
@echo " raspi_release - Crear release completo para Raspberry Pi"
@echo " anbernic - Compilar para Anbernic"
@echo " no_audio - Compilar sin sistema de audio"
@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

View File

@@ -16,6 +16,7 @@ DEMODATA|${PREFIX}/data/config/demo2.bin
DATA|${PREFIX}/data/config/gamecontrollerdb.txt
DATA|${PREFIX}/data/config/formations.txt
DATA|${PREFIX}/data/config/pools.txt
DATA|${PREFIX}/data/config/stages.txt
# Música
MUSIC|${PREFIX}/data/music/intro.ogg

19
data/config/stages.txt Normal file
View File

@@ -0,0 +1,19 @@
# Archivo de configuración de fases
# Formato: power_to_complete,min_menace,max_menace,name
# Líneas que empiezan con # son comentarios y se ignoran
# Fases iniciales - Tutorial y aprendizaje
200, 11, 19, Tutorial
300, 15, 23, Primeros pasos
# Fases intermedias - Incremento de dificultad
600, 19, 27, Intensificación
600, 19, 27, Persistencia
600, 23, 31, Desafío medio
600, 23, 31, Resistencia
# Fases avanzadas - Desafío final
650, 27, 35, Aproximación final
750, 27, 35, Penúltimo obstáculo
850, 31, 39, Clímax
950, 35, 47, Maestría

View File

@@ -113,6 +113,13 @@ loop=-1
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=thank_you
speed=3
loop=-1
frames=42,42,43,44,45,46,46,46,45,44
[/animation]
[animation]
name=dizzy
speed=5

View File

@@ -26,6 +26,7 @@
"[GAME_TEXT] 6": "Temps!",
"[GAME_TEXT] 7": "Endavant!",
"[GAME_TEXT] 8": "1.000.000 de punts!",
"[GAME_TEXT] THANK_YOU": "Gracies!",
"[HIGHSCORE_TABLE] CAPTION": "Millors puntuacions",

View File

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

View File

@@ -25,6 +25,7 @@
"[GAME_TEXT] 6": "Tiempo!",
"[GAME_TEXT] 7": "Adelante!",
"[GAME_TEXT] 8": "1.000.000 de puntos!",
"[GAME_TEXT] THANK_YOU": "Gracias!",
"[HIGHSCORE_TABLE] CAPTION": "Mejores puntuaciones",

Binary file not shown.

150
release/create_icons.py Normal file
View File

@@ -0,0 +1,150 @@
#!/usr/bin/env python3
import os
import sys
import shutil
import subprocess
from pathlib import Path
def check_dependencies():
"""Verifica que ImageMagick esté instalado"""
try:
subprocess.run(['magick', '--version'], capture_output=True, check=True)
except (subprocess.CalledProcessError, FileNotFoundError):
print("Error: ImageMagick no está instalado o no se encuentra en el PATH")
print("Instala ImageMagick desde: https://imagemagick.org/script/download.php")
sys.exit(1)
# Verificar iconutil solo en macOS
if sys.platform == 'darwin':
try:
# iconutil no tiene --version, mejor usar which o probar con -h
result = subprocess.run(['which', 'iconutil'], capture_output=True, check=True)
if result.returncode == 0:
print("✓ iconutil disponible - se crearán archivos .ico e .icns")
except (subprocess.CalledProcessError, FileNotFoundError):
print("Error: iconutil no está disponible (solo funciona en macOS)")
print("Solo se creará el archivo .ico")
else:
print(" Sistema no-macOS detectado - solo se creará archivo .ico")
def create_icons(input_file):
"""Crea archivos .icns e .ico a partir de un PNG"""
# Verificar que el archivo existe
if not os.path.isfile(input_file):
print(f"Error: El archivo {input_file} no existe.")
return False
# Obtener información del archivo
file_path = Path(input_file)
file_dir = file_path.parent
file_name = file_path.stem # Nombre sin extensión
file_extension = file_path.suffix
if file_extension.lower() not in ['.png', '.jpg', '.jpeg', '.bmp', '.tiff']:
print(f"Advertencia: {file_extension} puede no ser compatible. Se recomienda usar PNG.")
# Crear archivo .ico usando el método simplificado
ico_output = file_dir / f"{file_name}.ico"
try:
print(f"Creando {ico_output}...")
subprocess.run([
'magick', str(input_file),
'-define', 'icon:auto-resize=256,128,64,48,32,16',
str(ico_output)
], check=True)
print(f"✓ Archivo .ico creado: {ico_output}")
except subprocess.CalledProcessError as e:
print(f"Error creando archivo .ico: {e}")
return False
# Crear archivo .icns (solo en macOS)
if sys.platform == 'darwin':
try:
# Crear carpeta temporal para iconset
temp_folder = file_dir / "icon.iconset"
# Eliminar carpeta temporal si existe
if temp_folder.exists():
shutil.rmtree(temp_folder)
# Crear carpeta temporal
temp_folder.mkdir(parents=True)
# Definir los tamaños y nombres de archivo para .icns
icon_sizes = [
(16, "icon_16x16.png"),
(32, "icon_16x16@2x.png"),
(32, "icon_32x32.png"),
(64, "icon_32x32@2x.png"),
(128, "icon_128x128.png"),
(256, "icon_128x128@2x.png"),
(256, "icon_256x256.png"),
(512, "icon_256x256@2x.png"),
(512, "icon_512x512.png"),
(1024, "icon_512x512@2x.png")
]
print("Generando imágenes para .icns...")
# Crear cada tamaño de imagen
for size, output_name in icon_sizes:
output_path = temp_folder / output_name
subprocess.run([
'magick', str(input_file),
'-resize', f'{size}x{size}',
str(output_path)
], check=True)
# Crear archivo .icns usando iconutil
icns_output = file_dir / f"{file_name}.icns"
print(f"Creando {icns_output}...")
subprocess.run([
'iconutil', '-c', 'icns',
str(temp_folder),
'-o', str(icns_output)
], check=True)
# Limpiar carpeta temporal
if temp_folder.exists():
shutil.rmtree(temp_folder)
print(f"✓ Archivo .icns creado: {icns_output}")
except subprocess.CalledProcessError as e:
print(f"Error creando archivo .icns: {e}")
# Limpiar carpeta temporal en caso de error
if temp_folder.exists():
shutil.rmtree(temp_folder)
return False
else:
print(" Archivo .icns no creado (solo disponible en macOS)")
return True
def main():
"""Función principal"""
# Verificar argumentos
if len(sys.argv) != 2:
print(f"Uso: {sys.argv[0]} ARCHIVO")
print("Ejemplo: python3 create_icons.py imagen.png")
sys.exit(0)
input_file = sys.argv[1]
# Verificar dependencias
check_dependencies()
# Crear iconos
if create_icons(input_file):
print("\n✅ Proceso completado exitosamente")
else:
print("\n❌ El proceso falló")
sys.exit(1)
if __name__ == "__main__":
main()

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 438 KiB

View File

@@ -14,8 +14,12 @@
#include "texture.h" // Para Texture
// Constructor
Background::Background()
: renderer_(Screen::get()->getRenderer()),
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),
renderer_(Screen::get()->getRenderer()),
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
@@ -28,81 +32,16 @@ Background::Background()
rect_(SDL_FRect{0, 0, static_cast<float>(gradients_texture_->getWidth() / 2), static_cast<float>(gradients_texture_->getHeight() / 2)}),
src_rect_({0, 0, 320, 240}),
dst_rect_({0, 0, 320, 240}),
base_(rect_.h),
attenuate_color_(Color(param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b)),
alpha_color_text_(param.background.attenuate_color.a),
alpha_color_text_temp_(param.background.attenuate_color.a)
{
// Precalcula rutas
createSunPath();
createMoonPath();
// Inicializa variables
{
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
const float TOP_CLOUDS_TEXTURE_HEIGHT = top_clouds_texture_->getHeight() / 4;
const float BOTTOM_CLOUDS_TEXTURE_HEIGHT = bottom_clouds_texture_->getHeight() / 4;
for (int i = 0; i < 4; ++i) {
top_clouds_rect_[i] = {0, i * TOP_CLOUDS_TEXTURE_HEIGHT, static_cast<float>(top_clouds_texture_->getWidth()), TOP_CLOUDS_TEXTURE_HEIGHT};
bottom_clouds_rect_[i] = {0, i * BOTTOM_CLOUDS_TEXTURE_HEIGHT, static_cast<float>(bottom_clouds_texture_->getWidth()), BOTTOM_CLOUDS_TEXTURE_HEIGHT};
}
}
// Crea los sprites
{
const float TOP_CLOUDS_Y = base_ - 165;
const float BOTTOM_CLOUDS_Y = base_ - 101;
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_FRect){0, TOP_CLOUDS_Y, rect_.w, static_cast<float>(top_clouds_texture_->getHeight())});
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_FRect){rect_.w, TOP_CLOUDS_Y, rect_.w, static_cast<float>(top_clouds_texture_->getHeight())});
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_FRect){0, BOTTOM_CLOUDS_Y, rect_.w, static_cast<float>(bottom_clouds_texture_->getHeight())});
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_FRect){rect_.w, BOTTOM_CLOUDS_Y, rect_.w, static_cast<float>(bottom_clouds_texture_->getHeight())});
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
sun_sprite_ = std::make_unique<Sprite>(sun_texture_);
moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
}
// Inicializa objetos
{
constexpr float TOP_CLOUDS_SPEED = 0.1F;
constexpr float BOTTOM_CLOUDS_SPEED = 0.05F;
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_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_b_->setVelX(-TOP_CLOUDS_SPEED);
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_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_b_->setVelX(-BOTTOM_CLOUDS_SPEED);
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
sun_sprite_->setPosition(sun_path_.front());
moon_sprite_->setPosition(moon_path_.front());
}
// Crea la textura para componer el fondo
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
// Crea la textura para atenuar el fondo
color_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
setColor(attenuate_color_);
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
alpha_color_texture_(param.background.attenuate_color.a),
previous_alpha_color_texture_(param.background.attenuate_color.a),
base_(rect_.h) {
initializePaths();
initializeRects();
initializeSprites();
initializeSpriteProperties();
initializeTextures();
}
// Destructor
@@ -111,9 +50,88 @@ Background::~Background() {
SDL_DestroyTexture(color_texture_);
}
// Inicializa las rutas del sol y la luna
void Background::initializePaths() {
createSunPath();
createMoonPath();
}
// Inicializa los rectángulos de gradientes y nubes
void Background::initializeRects() {
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
const float TOP_CLOUDS_TEXTURE_HEIGHT = top_clouds_texture_->getHeight() / 4;
const float BOTTOM_CLOUDS_TEXTURE_HEIGHT = bottom_clouds_texture_->getHeight() / 4;
for (int i = 0; i < 4; ++i) {
top_clouds_rect_[i] = {0, i * TOP_CLOUDS_TEXTURE_HEIGHT, static_cast<float>(top_clouds_texture_->getWidth()), TOP_CLOUDS_TEXTURE_HEIGHT};
bottom_clouds_rect_[i] = {0, i * BOTTOM_CLOUDS_TEXTURE_HEIGHT, static_cast<float>(bottom_clouds_texture_->getWidth()), BOTTOM_CLOUDS_TEXTURE_HEIGHT};
}
}
// Crea los sprites
void Background::initializeSprites() {
const float TOP_CLOUDS_Y = base_ - 165;
const float BOTTOM_CLOUDS_Y = base_ - 101;
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_FRect){0, TOP_CLOUDS_Y, rect_.w, static_cast<float>(top_clouds_texture_->getHeight())});
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_FRect){rect_.w, TOP_CLOUDS_Y, rect_.w, static_cast<float>(top_clouds_texture_->getHeight())});
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_FRect){0, BOTTOM_CLOUDS_Y, rect_.w, static_cast<float>(bottom_clouds_texture_->getHeight())});
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_FRect){rect_.w, BOTTOM_CLOUDS_Y, rect_.w, static_cast<float>(bottom_clouds_texture_->getHeight())});
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_);
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
sun_sprite_ = std::make_unique<Sprite>(sun_texture_);
moon_sprite_ = std::make_unique<Sprite>(moon_texture_);
}
// Configura las propiedades iniciales de los sprites
void Background::initializeSpriteProperties() {
constexpr float TOP_CLOUDS_SPEED = 0.1F;
constexpr float BOTTOM_CLOUDS_SPEED = 0.05F;
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_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_b_->setVelX(-TOP_CLOUDS_SPEED);
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_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_b_->setVelX(-BOTTOM_CLOUDS_SPEED);
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
sun_sprite_->setPosition(sun_path_.front());
moon_sprite_->setPosition(moon_path_.front());
}
// Inicializa las texturas de renderizado
void Background::initializeTextures() {
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
color_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
setColor(attenuate_color_);
SDL_SetTextureAlphaMod(color_texture_, alpha_color_texture_);
}
// Actualiza la lógica del objeto
void Background::update() {
// Actualiza el valor de alpha_
// Actualiza la progresión y calcula transiciones
if (!manual_mode_) {
updateProgression();
}
// Actualiza el valor de alpha
updateAlphaColorTexture();
// Actualiza las nubes
@@ -122,10 +140,10 @@ void Background::update() {
// Calcula el frame de la hierba
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
// Calcula el valor de alpha_
// Calcula el valor de alpha
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
// Mueve el sol
// Mueve el sol y la luna según la progresión
sun_sprite_->setPosition(sun_path_.at(sun_index_));
moon_sprite_->setPosition(moon_path_.at(moon_index_));
@@ -136,6 +154,190 @@ void Background::update() {
fillCanvas();
}
// Incrementa la progresión interna
void Background::incrementProgress(float amount) {
if (state_ == State::NORMAL) {
float old_progress = progress_;
progress_ += amount;
progress_ = std::min(progress_, total_progress_to_complete_);
// Notifica el cambio si hay callback y el progreso cambió
if (progress_callback_ && progress_ != old_progress) {
progress_callback_(progress_);
}
}
}
// Establece la progresión absoluta
void Background::setProgress(float absolute_progress) {
float old_progress = progress_;
progress_ = std::clamp(absolute_progress, 0.0f, total_progress_to_complete_);
// Notifica el cambio si hay callback y el progreso cambió
if (progress_callback_ && progress_ != old_progress) {
progress_callback_(progress_);
}
}
// Cambia el estado del fondo
void Background::setState(State new_state) {
state_ = new_state;
}
// Reinicia la progresión
void Background::reset() {
float old_progress = progress_;
progress_ = 0.0f;
state_ = State::NORMAL;
manual_mode_ = false;
gradient_number_ = 0;
transition_ = 0.0f;
sun_index_ = 0;
moon_index_ = 0;
// Notifica el cambio si hay callback
if (progress_callback_ && progress_ != old_progress) {
progress_callback_(progress_);
}
}
// Activa/desactiva el modo manual
void Background::setManualMode(bool manual) {
manual_mode_ = manual;
}
// Establece callback para sincronización automática
void Background::setProgressCallback(ProgressCallback callback) {
progress_callback_ = callback;
}
// Elimina el callback
void Background::removeProgressCallback() {
progress_callback_ = nullptr;
}
// Ajusta la velocidad de las nubes
void Background::setCloudsSpeed(float value) {
clouds_speed_ = value;
// En modo manual, aplicar la velocidad directamente
// Las nubes inferiores van a la mitad de velocidad que las superiores
top_clouds_sprite_a_->setVelX(value);
top_clouds_sprite_b_->setVelX(value);
bottom_clouds_sprite_a_->setVelX(value / 2.0f);
bottom_clouds_sprite_b_->setVelX(value / 2.0f);
}
// Establece el degradado de fondo
void Background::setGradientNumber(int value) {
gradient_number_ = value % STAGES;
}
// Ajusta la transición entre texturas
void Background::setTransition(float value) {
transition_ = std::clamp(value, 0.0F, 1.0F);
}
// Establece la posición del sol
void Background::setSunProgression(float progress) {
progress = std::clamp(progress, 0.0F, 1.0F);
sun_index_ = static_cast<size_t>(progress * (sun_path_.size() - 1));
}
// Establece la posición de la luna
void Background::setMoonProgression(float progress) {
progress = std::clamp(progress, 0.0F, 1.0F);
moon_index_ = static_cast<size_t>(progress * (moon_path_.size() - 1));
}
// Actualiza la progresión y calcula las transiciones
void Background::updateProgression() {
// Si el juego está completado, reduce la progresión gradualmente
if (state_ == State::COMPLETED) {
if (progress_ > MINIMUM_COMPLETED_PROGRESS) {
progress_ -= COMPLETED_REDUCTION_RATE;
} else {
progress_ = MINIMUM_COMPLETED_PROGRESS;
}
}
// Calcula la transición de los diferentes fondos
const float gradient_number_float = std::min(progress_ / progress_per_stage_, 3.0F);
const float percent = gradient_number_float - static_cast<int>(gradient_number_float);
gradient_number_ = static_cast<size_t>(gradient_number_float);
transition_ = percent;
// Calcula la posición del sol
const float sun_progression = std::min(progress_ / sun_completion_progress_, 1.0f);
sun_index_ = static_cast<size_t>(sun_progression * (sun_path_.size() - 1));
// Calcula la posición de la luna
const float moon_progression = std::min(progress_ / total_progress_to_complete_, 1.0f);
moon_index_ = static_cast<size_t>(moon_progression * (moon_path_.size() - 1));
// Actualiza la velocidad de las nubes
updateCloudsSpeed();
}
// 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;
// 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_));
// 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);
completion_factor = std::max(0.1f, completion_factor);
base_clouds_speed *= completion_factor;
}
// Aplicar velocidades diferentes para nubes superiores e inferiores
const float top_clouds_speed = base_clouds_speed;
const float bottom_clouds_speed = base_clouds_speed / 2.0f;
// Aplicar las velocidades a los sprites correspondientes
top_clouds_sprite_a_->setVelX(top_clouds_speed);
top_clouds_sprite_b_->setVelX(top_clouds_speed);
bottom_clouds_sprite_a_->setVelX(bottom_clouds_speed);
bottom_clouds_sprite_b_->setVelX(bottom_clouds_speed);
// Guardar la velocidad principal
clouds_speed_ = top_clouds_speed;
}
// Actualiza las nubes
void Background::updateClouds() {
// Mueve las nubes
top_clouds_sprite_a_->update();
top_clouds_sprite_b_->update();
bottom_clouds_sprite_a_->update();
bottom_clouds_sprite_b_->update();
// Calcula el offset de las nubes
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
}
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth()) {
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
}
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth()) {
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
}
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth()) {
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
}
}
// Dibuja el gradiente de fondo
void Background::renderGradient() {
// Dibuja el gradiente de detras
@@ -221,21 +423,6 @@ void Background::render() {
SDL_RenderTexture(renderer_, color_texture_, &src_rect_, &dst_rect_);
}
// Ajusta el valor de la variable
void Background::setCloudsSpeed(float value) {
clouds_speed_ = value;
}
// Ajusta el valor de la variable
void Background::setGradientNumber(int value) {
gradient_number_ = value % 4;
}
// Ajusta el valor de la variable
void Background::setTransition(float value) {
transition_ = std::clamp(value, 0.0F, 1.0F);
}
// Establece la posición del objeto
void Background::setPos(SDL_FRect pos) {
dst_rect_ = pos;
@@ -247,7 +434,7 @@ void Background::setPos(SDL_FRect pos) {
src_rect_.h = pos.h;
}
// Establece el color_ de atenuación
// Establece el color de atenuación
void Background::setColor(Color color) {
attenuate_color_ = color;
@@ -264,52 +451,20 @@ void Background::setColor(Color color) {
// Establece la transparencia de la atenuación
void Background::setAlpha(int alpha) {
// Evita que se asignen valores fuera de rango
alpha_ = std::clamp(alpha, 0, 255);
alpha = std::clamp(alpha, 0, 255);
// Guarda el valor actual y establece el nuevo valor
alpha_color_text_temp_ = alpha_color_text_;
alpha_color_text_ = alpha_;
previous_alpha_color_texture_ = alpha_color_texture_;
alpha_color_texture_ = alpha;
}
// Actualiza el valor de alpha_
// Actualiza el valor de alpha
void Background::updateAlphaColorTexture() {
if (alpha_color_text_ == alpha_color_text_temp_) {
if (alpha_color_texture_ == previous_alpha_color_texture_) {
return;
}
alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_;
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_);
}
// Actualiza las nubes
void Background::updateClouds() {
// Aplica la velocidad calculada a las nubes
top_clouds_sprite_a_->setVelX(clouds_speed_);
top_clouds_sprite_b_->setVelX(clouds_speed_);
bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2);
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
// Mueve las nubes
top_clouds_sprite_a_->update();
top_clouds_sprite_b_->update();
bottom_clouds_sprite_a_->update();
bottom_clouds_sprite_b_->update();
// Calcula el offset de las nubes
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) {
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
}
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth()) {
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
}
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth()) {
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
}
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth()) {
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
}
alpha_color_texture_ > previous_alpha_color_texture_ ? ++previous_alpha_color_texture_ : --previous_alpha_color_texture_;
SDL_SetTextureAlphaMod(color_texture_, previous_alpha_color_texture_);
}
// Precalcula el vector con el recorrido del sol
@@ -343,26 +498,22 @@ void Background::createMoonPath() {
const float CENTER_Y = base_ - 50;
constexpr float RADIUS = 140;
// Generar puntos de la curva desde 0 a 90 grados
constexpr double STEP = 0.01;
const int NUM_STEPS = static_cast<int>((M_PI / 2 - 0) / STEP) + 1;
const int NUM_STEPS = static_cast<int>((M_PI / 2) / STEP) + 1;
constexpr float FREEZE_PERCENTAGE = 0.2f; // Porcentaje final del recorrido que se mantiene fijo
const int FREEZE_START_INDEX = static_cast<int>(NUM_STEPS * (1.0f - FREEZE_PERCENTAGE));
for (int i = 0; i < NUM_STEPS; ++i) {
double theta = 0 + i * STEP;
double theta = i * STEP;
float x = CENTER_X + (RADIUS * cos(theta));
float y = CENTER_Y - (RADIUS * sin(theta));
moon_path_.push_back({x, y});
if (i >= FREEZE_START_INDEX && !moon_path_.empty()) {
moon_path_.push_back(moon_path_.back()); // Repite el último punto válido
} else {
moon_path_.push_back({x, y});
}
}
}
// Establece la posición del sol
void Background::setSunProgression(float progress) {
progress = std::clamp(progress, 0.0F, 1.0F);
sun_index_ = static_cast<size_t>(progress * (sun_path_.size() - 1));
}
// Establece la posición de la luna
void Background::setMoonProgression(float progress) {
progress = std::clamp(progress, 0.0F, 1.0F);
moon_index_ = static_cast<size_t>(progress * (moon_path_.size() - 1));
}

View File

@@ -2,10 +2,11 @@
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_FPoint, SDL_Texture, SDL_Renderer
#include <array> // Para array
#include <cstddef> // Para size_t
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include <array> // Para array
#include <cstddef> // Para size_t
#include <functional> // Para std::function
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include "color.h" // Para Color
@@ -16,21 +17,29 @@ class Texture;
/*
Esta clase gestiona el fondo que aparece en la sección jugable.
Usa una textura compuesta y una capa superior con un color sólido cuya opacidad es ajustable.
Su área total está definida por "rect", pero solo se pinta la región "srcRect" en la pantalla en "dstRect".
Maneja internamente su progresión a través de diferentes estados del día/noche,
controlando las transiciones entre gradientes, posiciones del sol/luna y velocidad de nubes.
Estados:
- NORMAL: Progresión normal del día
- COMPLETED: Reducción gradual de la actividad (nubes más lentas)
Métodos clave:
- setCloudsSpeed(float value) -> Define la velocidad de las nubes
- setGradientNumber(int value) -> Ajusta el índice del color de cielo
- setTransition(float value) -> Configura la transición entre texturas
- setColor(Color color) -> Aplica un color de atenuación
- setAlpha(int alpha) -> Ajusta la transparencia de la capa de atenuación
- incrementProgress() -> Avanza la progresión del fondo
- setState() -> Cambia el estado del fondo
- setColor/setAlpha -> Efectos de atenuación
*/
class Background {
public:
// Enumeración de estados
enum class State {
NORMAL,
COMPLETED
};
// Constructor y Destructor
Background();
Background(float total_progress_to_complete = 6100.0f);
~Background();
// Actualización y renderizado
@@ -40,20 +49,46 @@ class Background {
// Configuración de posición
void setPos(SDL_FRect pos); // Establece la posición del objeto
// Configuración de animaciones y efectos
void setCloudsSpeed(float value); // Ajusta la velocidad de desplazamiento de las nubes
void setGradientNumber(int value); // Establece el degradado de fondo a usar
void setTransition(float value); // Ajusta la transición entre texturas de fondo
// Control de progresión
void incrementProgress(float amount = 1.0f); // Incrementa la progresión interna
void setProgress(float absolute_progress); // Establece la progresión absoluta
void setState(State new_state); // Cambia el estado del fondo
void reset(); // Reinicia la progresión
// Sistema de callback para sincronización automática
using ProgressCallback = std::function<void(float)>;
void setProgressCallback(ProgressCallback callback); // Establece callback para sincronización
void removeProgressCallback(); // Elimina el callback
// Configuración manual (para uso fuera del juego principal)
void setManualMode(bool manual); // Activa/desactiva el modo manual
void setCloudsSpeed(float value); // Ajusta la velocidad de las nubes
void setGradientNumber(int value); // Establece el degradado de fondo
void setTransition(float value); // Ajusta la transición entre texturas
void setSunProgression(float progress); // Establece la posición del sol
void setMoonProgression(float progress); // Establece la posición de la luna
// Configuración de efectos visuales
void setColor(Color color); // Establece el color de atenuación
void setAlpha(int alpha); // Ajusta la transparencia del fondo
// Configuración del sol y la luna
void setSunProgression(float progress); // Establece la posición del sol
void setMoonProgression(float progress); // Establece la posición de la luna
// Getters para información del estado
float getProgress() const { return progress_; }
State getState() const { return state_; }
int getCurrentGradient() const { return static_cast<int>(gradient_number_); }
private:
// Constantes de configuración
static constexpr size_t STAGES = 4;
static constexpr float COMPLETED_REDUCTION_RATE = 25.0f;
static constexpr float MINIMUM_COMPLETED_PROGRESS = 200.0f;
static constexpr float SUN_COMPLETION_FACTOR = 0.5f; // El sol completa su recorrido a la mitad del progreso total
// Configuración paramétrica
const float total_progress_to_complete_;
const float progress_per_stage_;
const float sun_completion_progress_;
// Objetos y punteros
SDL_Renderer *renderer_; // Renderizador de la ventana
@@ -81,34 +116,51 @@ class Background {
SDL_Texture *canvas_; // Textura para componer el fondo
SDL_Texture *color_texture_; // Textura para atenuar el fondo
// Variables de control
std::array<SDL_FRect, 4> gradient_rect_;
std::array<SDL_FRect, 4> top_clouds_rect_;
std::array<SDL_FRect, 4> bottom_clouds_rect_;
int gradient_number_ = 0;
int alpha_ = 0;
float clouds_speed_ = 0;
float transition_ = 0;
int counter_ = 0;
SDL_FRect rect_;
SDL_FRect src_rect_;
SDL_FRect dst_rect_;
int base_;
Color attenuate_color_;
int alpha_color_text_;
int alpha_color_text_temp_;
std::vector<SDL_FPoint> sun_path_;
std::vector<SDL_FPoint> moon_path_;
size_t sun_index_ = 0;
size_t moon_index_ = 0;
// Variables de estado y progresión
State state_ = State::NORMAL;
float progress_ = 0.0f; // Progresión interna (0 a total_progress_to_complete_)
bool manual_mode_ = false; // Si está en modo manual, no actualiza automáticamente
ProgressCallback progress_callback_; // Callback para notificar cambios de progreso
// Variables de renderizado
SDL_FRect rect_; // Tamaño del objeto
SDL_FRect src_rect_; // Parte del objeto para copiar en pantalla
SDL_FRect dst_rect_; // Posición en pantalla donde se copia el objeto
std::array<SDL_FRect, STAGES> gradient_rect_; // Fondos degradados
std::array<SDL_FRect, 4> top_clouds_rect_; // Nubes superiores
std::array<SDL_FRect, 4> bottom_clouds_rect_; // Nubes inferiores
Color attenuate_color_; // Color de atenuación
std::vector<SDL_FPoint> sun_path_; // Recorrido del sol
std::vector<SDL_FPoint> moon_path_; // Recorrido de la luna
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
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
size_t moon_index_ = 0; // Índice del recorrido de la luna
int base_ = 0; // Posición base del fondo
Uint8 alpha_ = 0; // Transparencia entre fases
// Métodos internos
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 createSunPath(); // Precalcula el recorrido del sol
void createMoonPath(); // Precalcula el recorrido de la luna
};
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 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 createSunPath(); // Precalcula el recorrido del sol
void createMoonPath(); // Precalcula el recorrido de la luna
};

View File

@@ -12,13 +12,14 @@
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "stage.h" // Para addPower
#include "stage_interface.h" // Para IStageInfo
#include "utils.h"
// Constructor
BalloonManager::BalloonManager()
BalloonManager::BalloonManager(IStageInfo *stage_info)
: explosions_(std::make_unique<Explosions>()),
balloon_formations_(std::make_unique<BalloonFormations>()) { init(); }
balloon_formations_(std::make_unique<BalloonFormations>()),
stage_info_(stage_info) { init(); }
// Inicializa
void BalloonManager::init() {
@@ -110,7 +111,7 @@ void BalloonManager::deployRandomFormation(int stage) {
}
// Reinicia el contador para el próximo despliegue
balloon_deploy_counter_ = 300;
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_COUNTER;
}
}
}
@@ -227,7 +228,7 @@ void BalloonManager::setBalloonSpeed(float speed) {
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
auto BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon) -> int {
Stage::addPower(1);
stage_info_->addPower(1);
int score = 0;
if (balloon->getType() == Balloon::Type::POWERBALL) {
@@ -274,7 +275,7 @@ auto BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) -> int {
}
// Aumenta el poder de la fase
Stage::addPower(balloon->getPower());
stage_info_->addPower(balloon->getPower());
// Destruye el globo
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));

View File

@@ -12,6 +12,7 @@
#include "balloon_formations.h" // Para BalloonFormations
#include "explosions.h" // Para Explosions
#include "param.h" // Para Param, ParamGame, param
#include "stage_interface.h" // Para IStageInfo
#include "utils.h" // Para Zone
class Texture;
@@ -22,7 +23,7 @@ using Balloons = std::vector<std::shared_ptr<Balloon>>;
class BalloonManager {
public:
// Constructor y Destructor
BalloonManager();
BalloonManager(IStageInfo *stage_info);
~BalloonManager() = default;
// Actualización y Renderizado
@@ -80,6 +81,8 @@ class BalloonManager {
[[nodiscard]] auto getNumBalloons() const -> int { return balloons_.size(); }
private:
static const int DEFAULT_BALLOON_DEPLOY_COUNTER = 300;
Balloons balloons_; // Vector con los globos activos
std::unique_ptr<Explosions> explosions_; // Objeto para gestionar explosiones
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para manejar formaciones enemigas
@@ -103,6 +106,7 @@ class BalloonManager {
bool bouncing_sound_enabled_ = false; // Si debe sonar el globo al rebotar
bool poping_sound_enabled_ = true; // Si debe sonar el globo al explotar
bool sound_enabled_ = true; // Indica si los globos deben hacer algun sonido
IStageInfo *stage_info_; // Informacion de la pantalla actual
// Metodos privados
void init();

View File

@@ -14,6 +14,7 @@
#include "param.h" // Para Param, ParamGame, param
#include "scoreboard.h" // Para Scoreboard
#include "stage.h" // Para power_can_be_added
#include "stage_interface.h" // Para IStageInfo
#include "texture.h" // Para Texture
#ifdef _DEBUG
#include <iostream>
@@ -26,6 +27,7 @@ Player::Player(const Config &config)
enter_name_(std::make_unique<EnterName>()),
hi_score_table_(config.hi_score_table),
glowing_entry_(config.glowing_entry),
stage_info_(config.stage_info),
play_area_(*config.play_area),
id_(config.id),
default_pos_x_(config.x),
@@ -179,6 +181,9 @@ void Player::move() {
case State::WAITING:
handleWaitingMovement();
break;
case State::THANK_YOU:
handleThankYouMovement();
break;
default:
break;
}
@@ -196,6 +201,13 @@ void Player::handlePlayingMovement() {
shiftSprite();
}
void Player::handleThankYouMovement() {
// Si termina la animacion, cambia de estado
if (player_sprite_->animationIsCompleted()) {
setPlayingState(State::RESPAWNING);
}
}
void Player::handleRollingMovement() {
handleRollingBoundaryCollision();
handleRollingGroundCollision();
@@ -463,6 +475,9 @@ void Player::setAnimation() {
player_sprite_->setFlip(flipMode);
break;
}
case State::THANK_YOU:
player_sprite_->setCurrentAnimation("thank_you");
break;
case State::WAITING:
case State::GAME_OVER:
player_sprite_->setCurrentAnimation("hello");
@@ -625,8 +640,11 @@ void Player::setPlayingState(State state) {
playing_state_ = state;
switch (playing_state_) {
case State::RESPAWNING: {
case State::THANK_YOU: {
playSound("voice_thankyou.wav");
break;
}
case State::RESPAWNING: {
setPlayingState(State::PLAYING);
setInvulnerable(true);
break;
@@ -635,7 +653,7 @@ void Player::setPlayingState(State state) {
init();
setInvulnerable(true);
setScoreboardMode(Scoreboard::Mode::SCORE);
Stage::power_can_be_added = true;
stage_info_->canCollectPower();
break;
}
case State::CONTINUE: {

View File

@@ -12,6 +12,7 @@
#include "input.h" // Para Input
#include "manage_hiscore_table.h" // Para Table
#include "scoreboard.h" // Para Scoreboard
#include "stage_interface.h" // Para IStageInfo
#include "utils.h" // Para Circle
class Texture;
@@ -71,7 +72,8 @@ class Player {
CREDITS, // Estado para mostrar los créditos del juego
TITLE_ANIMATION, // Animacion para el titulo
TITLE_HIDDEN, // Animacion para el titulo
RESPAWNING, // Tras continuar y volver al juego
THANK_YOU, // Al aceptar continuar
RESPAWNING, // Tras continuar y dar las gracias, otorga inmunidad y vuelve al juego
};
struct Config {
@@ -82,8 +84,9 @@ class Player {
SDL_FRect *play_area; // Usamos puntero para mantener la referencia
std::vector<std::shared_ptr<Texture>> texture;
std::vector<std::vector<std::string>> animations;
Table *hi_score_table; // También como puntero para referencia
int *glowing_entry; // Puntero para mantener la referencia
Table *hi_score_table; // También como puntero para referencia
int *glowing_entry; // Puntero para mantener la referencia
IStageInfo *stage_info; // Puntero para el gestor de pantallas
};
// --- Constructor y destructor ---
@@ -204,6 +207,7 @@ class Player {
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
std::string name_; // Nombre del jugador
std::string last_enter_name_; // Último nombre introducido en la tabla de puntuaciones
@@ -277,6 +281,7 @@ class Player {
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 handleThankYouMovement(); // 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.)

View File

@@ -598,7 +598,8 @@ void Resource::createTextTextures() {
{"game_text_powerup", Lang::getText("[GAME_TEXT] 4")},
{"game_text_one_hit", Lang::getText("[GAME_TEXT] 5")},
{"game_text_stop", Lang::getText("[GAME_TEXT] 6")},
{"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")}};
{"game_text_1000000_points", Lang::getText("[GAME_TEXT] 8")},
{"game_text_thank_you", Lang::getText("[GAME_TEXT] THANK_YOU")}};
auto text = getText("04b_25");
for (const auto &s : strings) {

View File

@@ -241,7 +241,7 @@ void Scoreboard::renderGameOverMode() {
void Scoreboard::renderStageInfoMode() {
// STAGE
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + std::to_string(stage_), 1, text_color1_);
text_scoreboard_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, Lang::getText("[SCOREBOARD] 5") + " " + std::to_string(stage_), 1, text_color1_);
// POWERMETER
power_meter_sprite_->setSpriteClip(0, 0, 40, 7);

View File

@@ -35,7 +35,7 @@ constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner";
// Constructor
Credits::Credits()
: balloon_manager_(std::make_unique<BalloonManager>()),
: balloon_manager_(std::make_unique<BalloonManager>(nullptr)),
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL)),
fade_in_(std::make_unique<Fade>()),
fade_out_(std::make_unique<Fade>()),

View File

@@ -42,7 +42,7 @@
#include "texture.h" // Para Texture
#include "ui/service_menu.h" // Para ServiceMenu
#ifdef _DEBUG
#include <iostream> // Para Notifier
#include <iostream> // Para std::cout
#include "ui/notifier.h" // Para Notifier
#endif
@@ -52,12 +52,13 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
: renderer_(Screen::get()->getRenderer()),
screen_(Screen::get()),
input_(Input::get()),
background_(std::make_unique<Background>()),
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
pause_manager_(std::make_unique<PauseManager>([this](bool is_paused) { onPauseStateChanged(is_paused); })),
stage_manager_(std::make_unique<StageManager>()),
balloon_manager_(std::make_unique<BalloonManager>(stage_manager_.get())),
background_(std::make_unique<Background>(stage_manager_->getTotalPowerNeededToCompleteGame())),
fade_in_(std::make_unique<Fade>()),
fade_out_(std::make_unique<Fade>()),
balloon_manager_(std::make_unique<BalloonManager>()),
tabe_(std::make_unique<Tabe>()),
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
// Pasa variables
@@ -66,8 +67,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
// Otras variables
Section::name = Section::Name::GAME;
Section::options = Section::Options::NONE;
Stage::init();
Stage::number = current_stage;
stage_manager_->initialize(Asset::get()->get("stages.txt"));
stage_manager_->setPowerChangeCallback([this](int amount) { background_->incrementProgress(amount); });
stage_manager_->jumpToStage(current_stage);
// Asigna texturas y animaciones
setResources();
@@ -99,7 +101,6 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
initDifficultyVars();
initDemo(player_id);
initPaths();
setTotalPower();
// Registra callbacks
ServiceMenu::get()->setStateChangeCallback([this](bool is_active) {
@@ -109,14 +110,14 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
}
});
#ifdef _DEBUG
// Si se empieza en una fase que no es la primera
if (!demo_.enabled) {
for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
/* #ifdef _DEBUG
// Si se empieza en una fase que no es la primera
if (!demo_.enabled) {
for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
}
}
}
#endif
#endif */
}
Game::~Game() {
@@ -152,6 +153,7 @@ void Game::setResources() {
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_one_hit"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_stop"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_100000_points"));
game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_thank_you"));
// Texturas - Items
item_textures_.clear();
@@ -260,7 +262,7 @@ void Game::renderPlayers() {
}
}
// Comprueba si hay cambio de fase y actualiza las variables
/* // Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage() {
if (Stage::power >= Stage::get(Stage::number).power_to_complete) {
// Cambio de fase
@@ -289,6 +291,64 @@ void Game::updateStage() {
background_->setAlpha(96);
}
}
} */
// Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage() {
if (!stage_manager_->isCurrentStageCompleted()) {
return; // No hay cambio de fase
}
// Calcular poder sobrante antes de avanzar
int power_overflow = 0;
auto current_stage = stage_manager_->getCurrentStage();
if (current_stage.has_value()) {
int current_power = stage_manager_->getCurrentPower();
int power_needed = current_stage->getPowerToComplete();
power_overflow = current_power - power_needed; // Poder que sobra
}
// Intentar avanzar a la siguiente fase
if (!stage_manager_->advanceToNextStage()) {
// No se pudo avanzar (probablemente juego completado)
return;
}
// Aplicar el poder sobrante a la nueva fase
if (power_overflow > 0) {
stage_manager_->addPower(power_overflow);
}
// Efectos de cambio de fase
playSound("stage_change.wav");
balloon_manager_->resetBalloonSpeed();
screen_->flash(FLASH_COLOR, 3);
screen_->shake();
// Obtener datos de la nueva fase
size_t current_stage_index = stage_manager_->getCurrentStageIndex();
size_t total_stages = stage_manager_->getTotalStages();
// Escribir texto por pantalla
if (current_stage_index < total_stages) { // No es la última fase
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
if (current_stage_index == total_stages - 1) { // Penúltima fase (será la última)
createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
} else {
auto text = Resource::get()->getText("04b_25_2x");
const std::string CAPTION = Lang::getText("[GAME_TEXT] 2") +
std::to_string(total_stages - current_stage_index) +
Lang::getText("[GAME_TEXT] 2A");
createMessage(paths, text->writeToTexture(CAPTION, 1, -4));
}
}
// Modificar color de fondo en la última fase
if (current_stage_index == total_stages - 1) { // Última fase
background_->setColor(Color(0xdd, 0x19, 0x1d).DARKEN());
background_->setAlpha(96);
}
}
// Actualiza el estado de fin de la partida
@@ -363,11 +423,11 @@ void Game::updateGameStateCompleted() {
// Para la música y elimina todos los globos e items
if (game_completed_counter_ == 0) {
stopMusic();
Stage::number = 9; // Deja el valor dentro de los limites
// Stage::number = 9; // Deja el valor dentro de los limites
balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos
playSound("power_ball_explosion.wav");
destroyAllItems(); // Destruye todos los items
Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
destroyAllItems(); // Destruye todos los items
// Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
}
@@ -409,8 +469,10 @@ void Game::updateGameStateCompleted() {
// Comprueba el estado del juego
void Game::checkState() {
if (state_ != State::COMPLETED && Stage::number == 10) {
// if (state_ != State::COMPLETED && Stage::number == 10) {
if (state_ != State::COMPLETED && stage_manager_->isGameCompleted()) {
setState(State::COMPLETED);
background_->setState(Background::State::COMPLETED);
}
if (state_ != State::GAME_OVER && allPlayersAreGameOver()) {
@@ -876,7 +938,8 @@ void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_pt
player->setPlayingState(Player::State::ROLLING);
sendPlayerToTheBack(player);
if (allPlayersAreNotPlaying()) {
Stage::power_can_be_added = false; // No se puede subir poder de fase si no hay nadie jugando
// Stage::power_can_be_added = false; // No se puede subir poder de fase si no hay nadie jugando
stage_manager_->disablePowerCollection();
}
}
}
@@ -961,6 +1024,8 @@ void Game::updateGameStates() {
// Actualiza el fondo
void Game::updateBackground() {
/* static const auto total_power_to_complete_game = stage_manager_->getTotalPowerNeededToCompleteGame();
// Si el juego está completado, se reduce la velocidad de las nubes
if (state_ == State::COMPLETED) {
Stage::total_power = (Stage::total_power > 200) ? (Stage::total_power - 25) : 200;
@@ -969,7 +1034,7 @@ void Game::updateBackground() {
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
constexpr float CLOUDS_INITIAL_SPEED = 0.05F;
constexpr float CLOUDS_FINAL_SPEED = 2.00F - CLOUDS_INITIAL_SPEED;
const float CLOUDS_SPEED = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game_));
const float CLOUDS_SPEED = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game));
background_->setCloudsSpeed(CLOUDS_SPEED);
// Calcula la transición de los diferentes fondos
@@ -982,7 +1047,7 @@ void Game::updateBackground() {
// Calcula la posición del sol
constexpr float SUN_FINAL_POWER = NUM * 2;
background_->setSunProgression(Stage::total_power / SUN_FINAL_POWER);
background_->setMoonProgression(Stage::total_power / static_cast<float>(total_power_to_complete_game_));
background_->setMoonProgression(Stage::total_power / static_cast<float>(total_power_to_complete_game)); */
// Actualiza el objeto
background_->update();
@@ -1166,12 +1231,11 @@ void Game::updateScoreboard() {
}
// Resto de marcador
scoreboard_->setStage(Stage::number + 1);
scoreboard_->setPower((float)Stage::power / (float)Stage::get(Stage::number).power_to_complete);
scoreboard_->setStage(stage_manager_->getCurrentStageIndex() + 1);
scoreboard_->setPower(stage_manager_->getCurrentStageProgressFraction());
scoreboard_->setHiScore(hi_score_.score);
scoreboard_->setHiScoreName(hi_score_.name);
// Lógica del marcador
scoreboard_->update();
}
@@ -1411,9 +1475,12 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
player->setPlayingState(Player::State::RESPAWNING);
player->setPlayingState(Player::State::THANK_YOU);
player->addCredit();
sendPlayerToTheFront(player);
// Crea letrero de THANK_YOU
const auto X = player->getPosX() + (player->getWidth() - game_text_textures_.at(7)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(7));
}
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
@@ -1488,13 +1555,14 @@ void Game::initDemo(Player::Id player_id) {
constexpr auto NUM_DEMOS = 3;
const auto DEMO = rand() % NUM_DEMOS;
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
Stage::number = STAGES[DEMO];
// Stage::number = STAGES[DEMO];
stage_manager_->jumpToStage(STAGES.at(DEMO));
}
// Actualiza el numero de globos explotados según la fase del modo demostración
for (int i = 0; i < Stage::number; ++i) {
/* for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
}
} */
// Activa o no al otro jugador
if (rand() % 3 != 0) {
@@ -1529,14 +1597,6 @@ void Game::initDemo(Player::Id player_id) {
demo_.counter = 0;
}
// Calcula el poder total necesario para completar el juego
void Game::setTotalPower() {
total_power_to_complete_game_ = 0;
for (const auto &stage : Stage::stages) {
total_power_to_complete_game_ += stage.power_to_complete;
}
}
// Inicializa el marcador
void Game::initScoreboard() {
scoreboard_->setPos(param.scoreboard.rect);
@@ -1596,6 +1656,7 @@ void Game::initPlayers(Player::Id player_id) {
config_player1.animations = player_animations_;
config_player1.hi_score_table = &Options::settings.hi_score_table;
config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER1) - 1);
config_player1.stage_info = stage_manager_.get();
auto player1 = std::make_unique<Player>(config_player1);
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
@@ -1616,6 +1677,7 @@ void Game::initPlayers(Player::Id player_id) {
config_player2.animations = player_animations_;
config_player2.hi_score_table = &Options::settings.hi_score_table;
config_player2.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER2) - 1);
config_player2.stage_info = stage_manager_.get();
auto player2 = std::make_unique<Player>(config_player2);
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
@@ -1755,7 +1817,8 @@ void Game::updateGameStateShowingGetReadyMessage() {
void Game::updateGameStatePlaying() {
#ifdef _DEBUG
if (auto_pop_balloons_) {
Stage::addPower(5);
// Stage::addPower(5);
stage_manager_->addPower(5);
}
#endif
updatePlayers();
@@ -1789,19 +1852,25 @@ void Game::cleanVectors() {
// Gestiona el nivel de amenaza
void Game::updateMenace() {
if (state_ == State::PLAYING) {
const auto STAGE = Stage::get(Stage::number);
const float PERCENT = Stage::power / STAGE.power_to_complete;
const int DIFFERENCE = STAGE.max_menace - STAGE.min_menace;
if (state_ != State::PLAYING) {
return;
}
// Aumenta el nivel de amenaza en función de la puntuación
menace_threshold_ = STAGE.min_menace + (DIFFERENCE * PERCENT);
auto current_stage = stage_manager_->getCurrentStage();
if (!current_stage.has_value()) {
return;
}
// Si el nivel de amenza es inferior al umbral
if (menace_current_ < menace_threshold_) {
balloon_manager_->deployRandomFormation(Stage::number); // Crea una formación aleatoria de globos
evaluateAndSetMenace(); // Recalcula el nivel de amenaza con el nuevo globo
}
const auto &stage = current_stage.value();
const double fraction = stage_manager_->getCurrentStageProgressFraction();
const int difference = stage.getMaxMenace() - stage.getMinMenace();
// Aumenta el nivel de amenaza en función del progreso de la fase
menace_threshold_ = stage.getMinMenace() + (difference * fraction);
if (menace_current_ < menace_threshold_) {
balloon_manager_->deployRandomFormation(stage_manager_->getCurrentStageIndex());
evaluateAndSetMenace();
}
}
@@ -1816,7 +1885,8 @@ void Game::checkAndUpdateBalloonSpeed() {
return;
}
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
// const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
const float PERCENT = stage_manager_->getCurrentStageProgressPercentage();
constexpr std::array<float, 4> THRESHOLDS = {0.2F, 0.4F, 0.6F, 0.8F};
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {

View File

@@ -14,6 +14,7 @@
#include "player.h" // Para Player
#include "smart_sprite.h" // Para SmartSprite
#include "utils.h" // Para Demo
#include "stage.h" // Para StageManager
class Background;
class Balloon;
@@ -100,28 +101,28 @@ class Game {
Input *input_; // Manejador de entrada
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del 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
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los pathsprites
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
std::unique_ptr<PauseManager> pause_manager_; // Objeto para gestionar la pausa
std::unique_ptr<StageManager> stage_manager_; // Objeto para gestionar las fases
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
std::unique_ptr<Tabe> tabe_; // Objeto para gestionar el Tabe Volaor
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
@@ -141,7 +142,6 @@ class Game {
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
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
int menace_current_ = 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

View File

@@ -1,43 +1,303 @@
#include "stage.h"
#include <algorithm>
#include <fstream>
#include <sstream>
#include <algorithm> // Para min
#include <vector> // Para vector
// Implementación de StageData
StageData::StageData(int power_to_complete, int min_menace, int max_menace, const std::string& name)
: power_to_complete_(power_to_complete), min_menace_(min_menace),
max_menace_(max_menace), name_(name), status_(StageStatus::LOCKED) {}
namespace Stage {
std::vector<Stage> stages; // Variable con los datos de cada pantalla
int power = 0; // Poder acumulado en la fase
int total_power = 0; // Poder total necesario para completar el juego
int number = 0; // Fase actual
bool power_can_be_added = true; // Habilita la recolecta de poder
// Devuelve una fase
auto get(int index) -> Stage { return stages.at(std::min(9, index)); }
// Inicializa las variables del namespace Stage
void init() {
stages.clear();
stages.emplace_back(200, 7 + (4 * 1), 7 + (4 * 3));
stages.emplace_back(300, 7 + (4 * 2), 7 + (4 * 4));
stages.emplace_back(600, 7 + (4 * 3), 7 + (4 * 5));
stages.emplace_back(600, 7 + (4 * 3), 7 + (4 * 5));
stages.emplace_back(600, 7 + (4 * 4), 7 + (4 * 6));
stages.emplace_back(600, 7 + (4 * 4), 7 + (4 * 6));
stages.emplace_back(650, 7 + (4 * 5), 7 + (4 * 7));
stages.emplace_back(750, 7 + (4 * 5), 7 + (4 * 7));
stages.emplace_back(850, 7 + (4 * 6), 7 + (4 * 8));
stages.emplace_back(950, 7 + (4 * 7), 7 + (4 * 10));
power = 0;
total_power = 0;
number = 0;
// Implementación de StageManager
StageManager::StageManager()
: current_power_(0), total_power_(0), current_stage_index_(0),
power_collection_state_(PowerCollectionState::ENABLED),
power_change_callback_(nullptr) {
initialize();
}
// Añade poder
void addPower(int amount) {
if (power_can_be_added) {
power += amount;
total_power += amount;
void StageManager::initialize() {
stages_.clear();
createDefaultStages();
reset();
}
void StageManager::initialize(const std::string& stages_file) {
stages_.clear();
// Intentar cargar desde archivo, si falla usar valores predeterminados
if (!loadStagesFromFile(stages_file)) {
createDefaultStages();
}
reset();
}
} // namespace Stage
void StageManager::reset() {
current_power_ = 0;
total_power_ = 0;
current_stage_index_ = 0;
power_collection_state_ = PowerCollectionState::ENABLED;
updateStageStatuses();
}
void StageManager::createDefaultStages() {
// Crear las 10 fases predeterminadas con dificultad progresiva
stages_.emplace_back(200, 7 + (4 * 1), 7 + (4 * 3), "Tutorial");
stages_.emplace_back(300, 7 + (4 * 2), 7 + (4 * 4), "Primeros pasos");
stages_.emplace_back(600, 7 + (4 * 3), 7 + (4 * 5), "Intensificación");
stages_.emplace_back(600, 7 + (4 * 3), 7 + (4 * 5), "Persistencia");
stages_.emplace_back(600, 7 + (4 * 4), 7 + (4 * 6), "Desafío medio");
stages_.emplace_back(600, 7 + (4 * 4), 7 + (4 * 6), "Resistencia");
stages_.emplace_back(650, 7 + (4 * 5), 7 + (4 * 7), "Aproximación final");
stages_.emplace_back(750, 7 + (4 * 5), 7 + (4 * 7), "Penúltimo obstáculo");
stages_.emplace_back(850, 7 + (4 * 6), 7 + (4 * 8), "Clímax");
stages_.emplace_back(950, 7 + (4 * 7), 7 + (4 * 10), "Maestría");
}
bool StageManager::loadStagesFromFile(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
return false; // No se pudo abrir el archivo
}
std::string line;
int line_number = 0;
while (std::getline(file, line)) {
line_number++;
// Ignorar líneas vacías y comentarios (líneas que empiezan con #)
if (line.empty() || line[0] == '#') {
continue;
}
// Parsear línea: power_to_complete,min_menace,max_menace,name
std::stringstream ss(line);
std::string token;
std::vector<std::string> tokens;
// Dividir por comas
while (std::getline(ss, token, ',')) {
// Eliminar espacios en blanco al inicio y final
token.erase(0, token.find_first_not_of(" \t"));
token.erase(token.find_last_not_of(" \t") + 1);
tokens.push_back(token);
}
// Verificar que tenemos exactamente 4 campos
if (tokens.size() != 4) {
// Error de formato, continuar con la siguiente línea
continue;
}
try {
// Convertir a enteros los primeros tres campos
int power_to_complete = std::stoi(tokens[0]);
int min_menace = std::stoi(tokens[1]);
int max_menace = std::stoi(tokens[2]);
std::string name = tokens[3];
// Validar valores
if (power_to_complete <= 0 || min_menace < 0 || max_menace < min_menace) {
continue; // Valores inválidos, saltar línea
}
// Crear y añadir la fase
stages_.emplace_back(power_to_complete, min_menace, max_menace, name);
} catch (const std::exception&) {
// Error de conversión, continuar con la siguiente línea
continue;
}
}
file.close();
// Verificar que se cargó al menos una fase
return !stages_.empty();
}
bool StageManager::advanceToNextStage() {
if (!isCurrentStageCompleted() || current_stage_index_ >= stages_.size() - 1) {
return false;
}
current_stage_index_++;
current_power_ = 0; // Reiniciar poder para la nueva fase
updateStageStatuses();
return true;
}
bool StageManager::jumpToStage(size_t target_stage_index) {
if (!validateStageIndex(target_stage_index)) {
return false;
}
// Calcular el poder acumulado hasta la fase objetivo
int accumulated_power = 0;
for (size_t i = 0; i < target_stage_index; ++i) {
accumulated_power += stages_[i].getPowerToComplete();
}
// Actualizar estado
current_stage_index_ = target_stage_index;
current_power_ = 0; // Comenzar la fase objetivo sin poder
total_power_ = accumulated_power; // Poder total como si se hubieran completado las anteriores
updateStageStatuses();
return true;
}
bool StageManager::subtractPower(int amount) {
if (amount <= 0 || current_power_ < amount) {
return false;
}
current_power_ -= amount;
updateStageStatuses();
return true;
}
void StageManager::enablePowerCollection() {
power_collection_state_ = PowerCollectionState::ENABLED;
}
void StageManager::disablePowerCollection() {
power_collection_state_ = PowerCollectionState::DISABLED;
}
std::optional<StageData> StageManager::getCurrentStage() const {
return getStage(current_stage_index_);
}
std::optional<StageData> StageManager::getStage(size_t index) const {
if (!validateStageIndex(index)) {
return std::nullopt;
}
return stages_[index];
}
bool StageManager::isCurrentStageCompleted() const {
auto current_stage = getCurrentStage();
if (!current_stage.has_value()) {
return false;
}
return current_power_ >= current_stage->getPowerToComplete();
}
bool StageManager::isGameCompleted() const {
return current_stage_index_ >= stages_.size() - 1 && isCurrentStageCompleted();
}
double StageManager::getProgressPercentage() const {
if (stages_.empty()) return 0.0;
int total_power_needed = getTotalPowerNeededToCompleteGame();
if (total_power_needed == 0) return 100.0;
return (static_cast<double>(total_power_) / total_power_needed) * 100.0;
}
double StageManager::getCurrentStageProgressPercentage() const {
return getCurrentStageProgressFraction() * 100.0;
}
double StageManager::getCurrentStageProgressFraction() const {
auto current_stage = getCurrentStage();
if (!current_stage.has_value()) {
return 0.0;
}
int power_needed = current_stage->getPowerToComplete();
if (power_needed == 0) {
return 1.0;
}
// Devuelve una fracción entre 0.0 y 1.0
double fraction = static_cast<double>(current_power_) / power_needed;
return std::min(fraction, 1.0);
}
int StageManager::getPowerNeededForCurrentStage() const {
auto current_stage = getCurrentStage();
if (!current_stage.has_value()) {
return 0;
}
return std::max(0, current_stage->getPowerToComplete() - current_power_);
}
int StageManager::getTotalPowerNeededToCompleteGame() const {
int total_power_needed = 0;
for (const auto& stage : stages_) {
total_power_needed += stage.getPowerToComplete();
}
return total_power_needed;
}
// Implementación de la interfaz IStageInfo
bool StageManager::canCollectPower() const {
return power_collection_state_ == PowerCollectionState::ENABLED;
}
void StageManager::addPower(int amount) {
if (amount <= 0 || !canCollectPower()) {
return;
}
current_power_ += amount;
total_power_ += amount;
// Ejecutar callback si está registrado
if (power_change_callback_) {
power_change_callback_(amount);
}
// Verificar si se completó la fase actual
if (isCurrentStageCompleted()) {
auto current_stage = getCurrentStage();
if (current_stage.has_value()) {
stages_[current_stage_index_].setStatus(StageStatus::COMPLETED);
}
}
updateStageStatuses();
}
int StageManager::getCurrentMenaceLevel() const {
auto current_stage = getCurrentStage();
if (!current_stage.has_value()) {
return 0;
}
return current_stage->getMinMenace();
}
// Gestión de callbacks
void StageManager::setPowerChangeCallback(PowerChangeCallback callback) {
power_change_callback_ = callback;
}
void StageManager::removePowerChangeCallback() {
power_change_callback_ = nullptr;
}
// Métodos privados
bool StageManager::validateStageIndex(size_t index) const {
return index < stages_.size();
}
void StageManager::updateStageStatuses() {
// Actualizar el estado de cada fase según su posición relativa a la actual
for (size_t i = 0; i < stages_.size(); ++i) {
if (i < current_stage_index_) {
stages_[i].setStatus(StageStatus::COMPLETED);
} else if (i == current_stage_index_) {
stages_[i].setStatus(StageStatus::IN_PROGRESS);
} else {
stages_[i].setStatus(StageStatus::LOCKED);
}
}
}

View File

@@ -1,33 +1,111 @@
#pragma once
#include <vector> // Para vector
#include "stage_interface.h"
#include <vector>
#include <optional>
#include <string>
#include <functional>
/*
Namespace Stage: gestiona los datos y operaciones de las fases del juego.
Permite consultar y modificar el poder necesario, la amenaza y el estado de cada fase.
*/
namespace Stage {
// --- Estructura con los datos de una fase ---
struct Stage {
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
int min_menace; // Umbral mínimo de amenaza de la fase
int max_menace; // Umbral máximo de amenaza de la fase
// Constructor
Stage(int power_to_complete, int min_menace, int max_menace)
: power_to_complete(power_to_complete), min_menace(min_menace), max_menace(max_menace) {}
// --- Estados posibles para la recolección de poder ---
enum class PowerCollectionState {
ENABLED, // Recolección habilitada
DISABLED // Recolección deshabilitada
};
// --- Variables globales del estado de las fases ---
extern std::vector<Stage> stages; // Vector con los datos de cada pantalla
extern int power; // Poder acumulado en la fase actual
extern int total_power; // Poder total necesario para completar el juego
extern int number; // Índice de la fase actual
extern bool power_can_be_added; // Indica si se puede añadir poder a la fase
// --- Estados posibles para una fase del juego ---
enum class StageStatus {
LOCKED, // Fase bloqueada
IN_PROGRESS, // Fase en progreso
COMPLETED // Fase completada
};
// --- Funciones principales ---
auto get(int index) -> Stage; // Devuelve una fase por índice
void init(); // Inicializa las variables del namespace Stage
void addPower(int amount); // Añade poder a la fase actual
} // namespace Stage
// --- Representa los datos de una fase del juego ---
class StageData {
private:
int power_to_complete_; // Poder necesario para completar la fase
int min_menace_; // Nivel mínimo de amenaza
int max_menace_; // Nivel máximo de amenaza
std::string name_; // Nombre de la fase
StageStatus status_; // Estado actual de la fase
public:
// Constructor de una fase
StageData(int power_to_complete, int min_menace, int max_menace, const std::string& name = "");
// --- Getters ---
int getPowerToComplete() const { return power_to_complete_; }
int getMinMenace() const { return min_menace_; }
int getMaxMenace() const { return max_menace_; }
const std::string& getName() const { return name_; }
StageStatus getStatus() const { return status_; }
// --- Setters ---
void setStatus(StageStatus status) { status_ = status; }
// --- Utilidades ---
bool isCompleted() const { return status_ == StageStatus::COMPLETED; }
};
// --- Gestor principal del sistema de fases del juego ---
class StageManager : public IStageInfo {
private:
std::vector<StageData> stages_; // Lista de todas las fases
int current_power_; // Poder actual en la fase activa
int total_power_; // Poder total acumulado en todo el juego
size_t current_stage_index_; // Índice de la fase actual
PowerCollectionState power_collection_state_; // Estado de recolección de poder
public:
using PowerChangeCallback = std::function<void(int)>;
StageManager();
// --- Métodos principales del juego ---
void initialize(); // Inicializa el gestor de fases
void initialize(const std::string& stages_file); // Inicializa con archivo personalizado
void reset(); // Reinicia el progreso del juego
bool advanceToNextStage(); // Avanza a la siguiente fase
// --- Gestión de poder ---
bool subtractPower(int amount); // Resta poder de la fase actual
void enablePowerCollection(); // Habilita la recolección de poder
void disablePowerCollection(); // Deshabilita la recolección de poder
// --- Navegación ---
bool jumpToStage(size_t target_stage_index); // Salta a una fase específica
// --- Consultas de estado ---
std::optional<StageData> getCurrentStage() const; // Obtiene la fase actual
std::optional<StageData> getStage(size_t index) const; // Obtiene una fase específica
size_t getCurrentStageIndex() const { return current_stage_index_; }
int getCurrentPower() const { return current_power_; }
int getTotalPower() const { return total_power_; }
int getTotalPowerNeededToCompleteGame() const; // Poder total necesario para completar el juego
size_t getTotalStages() const { return stages_.size(); }
// --- Seguimiento de progreso ---
bool isCurrentStageCompleted() const; // Verifica si la fase actual está completada
bool isGameCompleted() const; // Verifica si el juego está completado
double getProgressPercentage() const; // Progreso total del juego (0-100%)
double getCurrentStageProgressPercentage() const; // Progreso de la fase actual (0-100%)
double getCurrentStageProgressFraction() const; // Progreso de la fase actual (0.0-1.0)
int getPowerNeededForCurrentStage() const; // Poder restante para completar la fase actual
// --- Gestión de callbacks ---
void setPowerChangeCallback(PowerChangeCallback callback); // Establece callback para cambios de poder
void removePowerChangeCallback(); // Elimina callback de cambios de poder
// --- Implementación de la interfaz IStageInfo ---
bool canCollectPower() const override;
void addPower(int amount) override;
int getCurrentMenaceLevel() const override;
private:
PowerChangeCallback power_change_callback_; // Callback para notificar cambios de poder
// --- Métodos privados ---
void createDefaultStages(); // Crea las fases predeterminadas del juego
bool loadStagesFromFile(const std::string& filename); // Carga fases desde archivo
bool validateStageIndex(size_t index) const; // Valida que un índice de fase sea válido
void updateStageStatuses(); // Actualiza los estados de todas las fases
};

18
source/stage_interface.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
/**
* Interfaz para acceso a información de fases.
* Proporciona una API mínima para componentes que necesitan interactuar con datos de fases
* sin requerir acceso a toda la funcionalidad de StageManager.
*/
class IStageInfo {
public:
virtual ~IStageInfo() = default;
// Interfaz de recolección de poder
virtual bool canCollectPower() const = 0;
virtual void addPower(int amount) = 0;
// Ajuste de comportamiento del gameplay
virtual int getCurrentMenaceLevel() const = 0;
};