forked from jaildesigner-jailgames/jaildoctors_dilemma
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba19dcb904 | |||
| b035b92ff4 | |||
| 8c425f5698 | |||
| d382bb6403 | |||
| da64a5e082 | |||
| 7070dac482 | |||
| ea5360ea74 | |||
| 3aa4440390 | |||
| ce105e252e | |||
| 1aac5b7719 | |||
| a8b467290f | |||
| 706ad6f9c0 | |||
| 54d428ed96 | |||
| c71adfbac4 | |||
| c955543d31 | |||
| fae8e2d82c | |||
| ff7b825cbb | |||
| 09ed0105e9 | |||
| 07ae93fd3a | |||
| 72fb30b927 | |||
| 8d37f31a08 | |||
| e6fb412c4d | |||
| 10c29eb547 | |||
| 1f9e36dc93 | |||
| c114884de1 | |||
| d6a366555d | |||
| fd0d8a05fe | |||
| 79d610a7d9 | |||
| 9060e1c92a | |||
| 0d586c0827 | |||
| fd0bebf533 | |||
| 2665b93b70 | |||
| c35be7d21c | |||
| bc84968b23 | |||
| 1b49097f80 | |||
| 859e3f3b44 | |||
| 3fa7657c79 | |||
| e90c61a416 | |||
| d003b51de4 | |||
| 8d381010c8 | |||
| 2216c9632e | |||
| fdc8797d2b | |||
| 90bdad7d51 | |||
| d50b193d9f | |||
| ee885d5ca7 | |||
| bb3a0f263b | |||
| 85d6c48f42 | |||
| 896dd9daef |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
*config.txt
|
*data/config/config.txt
|
||||||
*stats.txt
|
*stats.txt
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
thumbs.db
|
thumbs.db
|
||||||
@@ -10,4 +10,4 @@ thumbs.db
|
|||||||
*.tar.gz
|
*.tar.gz
|
||||||
*.zip
|
*.zip
|
||||||
*.app
|
*.app
|
||||||
*_debug
|
*_debug*
|
||||||
82
Makefile
82
Makefile
@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
|
|||||||
source = source/*.cpp source/common/*.cpp
|
source = source/*.cpp source/common/*.cpp
|
||||||
appName = JailDoctor's Dilemma
|
appName = JailDoctor's Dilemma
|
||||||
releaseFolder = jdd_release
|
releaseFolder = jdd_release
|
||||||
version = v1.04
|
version = v1.06.1
|
||||||
|
|
||||||
# Release names
|
# Release names
|
||||||
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||||
@@ -12,34 +12,33 @@ linuxRelease = $(executable)-$(version)-linux.tar.gz
|
|||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
@echo off
|
||||||
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o $(executable).exe
|
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
|
||||||
strip -s -R .comment -R .gnu.version $(executable).exe --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
|
||||||
|
|
||||||
|
windows_debug:
|
||||||
|
@echo off
|
||||||
|
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
|
||||||
|
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
|
||||||
|
|
||||||
windows_release:
|
windows_release:
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
# Remove data
|
# Create release folder
|
||||||
powershell if (Test-Path $(releaseFolder)) {Remove-Item $(releaseFolder) -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
||||||
|
powershell if (-not (Test-Path "$(releaseFolder)")) {New-Item "$(releaseFolder)" -ItemType Directory}
|
||||||
|
|
||||||
# Create folders
|
# Prepare data folder
|
||||||
powershell if (-not (Test-Path $(releaseFolder))) {New-Item $(releaseFolder) -ItemType Directory}
|
|
||||||
|
|
||||||
# Copy data
|
|
||||||
powershell Copy-Item -Path "data" -Destination "$(releaseFolder)" -recurse -Force
|
powershell Copy-Item -Path "data" -Destination "$(releaseFolder)" -recurse -Force
|
||||||
powershell Copy-Item "LICENSE" -Destination "$(releaseFolder)"
|
|
||||||
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
|
|
||||||
powershell Copy-Item "release/SDL2.dll" -Destination "$(releaseFolder)"
|
|
||||||
|
|
||||||
# Remove data
|
|
||||||
powershell if (Test-Path "$(releaseFolder)\data\room\map.world") {Remove-Item "$(releaseFolder)\data\room\map.world" -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)\data\room\map.world") {Remove-Item "$(releaseFolder)\data\room\map.world" -Recurse -Force}
|
||||||
powershell if (Test-Path "$(releaseFolder)\data\room\standard.tsx") {Remove-Item "$(releaseFolder)\data\room\standard.tsx" -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)\data\room\standard.tsx") {Remove-Item "$(releaseFolder)\data\room\standard.tsx" -Recurse -Force}
|
||||||
powershell if (Test-Path "$(releaseFolder)\data\config") {Remove-Item "$(releaseFolder)\data\config" -Recurse -Force}
|
|
||||||
|
# Copy root files
|
||||||
# Create data
|
powershell Copy-Item "LICENSE" -Destination "$(releaseFolder)"
|
||||||
powershell if (-not (Test-Path "$(releaseFolder)\data\config")) {New-Item "$(releaseFolder)\data\config" -ItemType Directory}
|
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
|
||||||
|
powershell Copy-Item "release\SDL2.dll" -Destination "$(releaseFolder)"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
|
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
|
||||||
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
||||||
|
|
||||||
# Create ZIP
|
# Create ZIP
|
||||||
@@ -47,13 +46,16 @@ windows_release:
|
|||||||
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
|
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
|
||||||
|
|
||||||
# Remove folder
|
# Remove folder
|
||||||
powershell if (Test-Path $(releaseFolder)) {Remove-Item $(releaseFolder) -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o $(executable)_macos
|
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
||||||
|
|
||||||
|
macos_debug:
|
||||||
|
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
||||||
|
|
||||||
macos_release:
|
macos_release:
|
||||||
# Remove data and possible data
|
# Remove data and possible data from previous builds
|
||||||
rm -rdf "$(releaseFolder)"
|
rm -rdf "$(releaseFolder)"
|
||||||
rm -rdf Frameworks
|
rm -rdf Frameworks
|
||||||
rm -f tmp.dmg
|
rm -f tmp.dmg
|
||||||
@@ -74,10 +76,6 @@ macos_release:
|
|||||||
# Delete data
|
# Delete data
|
||||||
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/map.world"
|
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/map.world"
|
||||||
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/standard.tsx"
|
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/standard.tsx"
|
||||||
rm -rdf "$(releaseFolder)/$(appName).app/Contents/Resources/data/config"
|
|
||||||
|
|
||||||
# Create folders
|
|
||||||
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources/data/config"
|
|
||||||
|
|
||||||
# Copy files
|
# Copy files
|
||||||
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
|
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
|
||||||
@@ -106,36 +104,36 @@ macos_release:
|
|||||||
rm -rdf "$(releaseFolder)"
|
rm -rdf "$(releaseFolder)"
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(executable)_linux
|
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||||
strip -s -R .comment -R .gnu.version $(executable)_linux --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
||||||
|
|
||||||
|
linux_debug:
|
||||||
|
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
||||||
|
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
||||||
|
|
||||||
linux_release:
|
linux_release:
|
||||||
# Remove data
|
# Remove data
|
||||||
rm -rdf $(releaseFolder)
|
rm -rdf "$(releaseFolder)"
|
||||||
|
|
||||||
# Create folders
|
# Create folders
|
||||||
mkdir -p $(releaseFolder)
|
mkdir -p "$(releaseFolder)"
|
||||||
|
|
||||||
# Copy data
|
# Copy data
|
||||||
cp -R data $(releaseFolder)
|
cp -R data "$(releaseFolder)"
|
||||||
cp LICENSE $(releaseFolder)
|
cp LICENSE "$(releaseFolder)"
|
||||||
cp README.md $(releaseFolder)
|
cp README.md "$(releaseFolder)"
|
||||||
|
|
||||||
# Delete data
|
# Delete data
|
||||||
rm -f "$(releaseFolder)/data/room/map.world"
|
rm -f "$(releaseFolder)/data/room/map.world"
|
||||||
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
||||||
rm -rdf "$(releaseFolder)/data/config"
|
|
||||||
|
|
||||||
# Create folders
|
|
||||||
mkdir -p "$(releaseFolder)/data/config"
|
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(releaseFolder)/$(executable)
|
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
||||||
strip -s -R .comment -R .gnu.version $(releaseFolder)/$(executable) --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
|
||||||
|
|
||||||
# Pack files
|
# Pack files
|
||||||
rm -f $(linuxRelease)
|
rm -f "$(linuxRelease)"
|
||||||
cd $(releaseFolder) && tar -czvf ../$(linuxRelease) *
|
cd "$(releaseFolder)" && tar -czvf "../$(linuxRelease)" *
|
||||||
|
|
||||||
# Remove data
|
# Remove data
|
||||||
rm -rdf $(releaseFolder)
|
rm -rdf "$(releaseFolder)"
|
||||||
66
README.md
66
README.md
@@ -1,37 +1,87 @@
|
|||||||
# JailDoctor's Dilemma
|
# JailDoctor's Dilemma (v1.06.1)
|
||||||
|
|
||||||
JailDoc es un Jailer. A los Jailers les gusta empezar proyectos. A nadie le gusta terminarlos. Los Jailers viven en la Jail. A la Jail va uno a empezar proyectos. A la Jail va uno a enseñar sus proyectos. A la Jail va uno a aprender como empezar nuevos proyectos. A la Jail va uno a ayudar a sus compañeros a que empiecen nuevos proyectos.
|
JailDoc es un Jailer. A los Jailers les gusta empezar proyectos. A nadie le gusta terminarlos. Los Jailers viven en la Jail. A la Jail va uno a empezar proyectos. A la Jail va uno a enseñar sus proyectos. A la Jail va uno a aprender como empezar nuevos proyectos. A la Jail va uno a ayudar a sus compañeros a que empiecen nuevos proyectos.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JailDoc es un Jailer destacado entre los Jailers. Tiene más proyectos empezados que nadie y es el que más ayuda a que los demas empiecen los suyos.
|
JailDoc es un Jailer destacado entre los Jailers. Tiene más proyectos empezados que nadie y es el que más ayuda a que los demas empiecen los suyos.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Un día, ocurrió algo. Alguien terminó un proyecto. Alguien liberó el *Puzzle Jail Facker*. Algún desaprensivo.
|
Un día, ocurrió algo. Alguien terminó un proyecto. Alguien liberó el *Puzzle Jail Facker*. Algún desaprensivo.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Esto hizo que JailDoc decidiera terminar y entregar uno de sus proyectos, pero, ¿cual? ¿JailBattle? ¿Sigmasuá? ¿Calculín Doom? Menudo dilema. JailDoc se arremangó y decidió finalizar y entregar todos sus proyectos inacabados. ¿Lo logrará?
|
Esto hizo que JailDoc decidiera terminar y entregar uno de sus proyectos, pero, ¿cual? ¿JailBattle? ¿Sigmasuá? ¿Calculín Doom? Menudo dilema. JailDoc se arremangó y decidió finalizar y entregar todos sus proyectos inacabados. ¿Lo logrará?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Jugabilidad
|
## Jugabilidad
|
||||||
|
|
||||||
Ayuda a JailDoc a recuperar las partes de su proyecto que estan desperdigadas por cualquier lugar del Universo Jailer. Hay mas de **150 piezas** desperdigadas por **60 pantallas**. Algunas son un paseo, pero en otras tendras que calcular muy bien tus movimientos si no quieres acabar como un arounder del montón.
|
Ayuda a JailDoc a recuperar las partes de su proyecto que estan desperdigadas por cualquier lugar del Universo Jailer. Hay mas de **150 piezas** desperdigadas por **60 pantallas**. Algunas son un paseo, pero en otras tendras que calcular muy bien tus movimientos si no quieres acabar como un arounder del montón.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Cuando consigas recuperar gran parte de las piezas desperdigadas, dirigete a la Jail a mostrar a los Jailers como se termina un proyecto. Ten en cuenta que Bry no te dejará entrar. Solo aquellos que han realizado un *Fire Effect* o un *Facedor de Tornejos* son dignos de tal privilegio.
|
Cuando consigas recuperar gran parte de las piezas desperdigadas, dirigete a la Jail a mostrar a los Jailers como se termina un proyecto. Ten en cuenta que Bry no te dejará entrar. Solo aquellos que han realizado un *Fire Effect* o un *Facedor de Tornejos* son dignos de tal privilegio.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Controles
|
## Controles
|
||||||
|
|
||||||
El juego permite tanto el uso del teclado como de un mando de control. Las teclas para manejar el juego son las siguientes:
|
El juego permite tanto el uso del teclado como de un mando de control. Las teclas para manejar el juego son las siguientes:
|
||||||
|
|
||||||
- **Cursores**: Para mover a izquierda o derecha a JailDoc y para saltar
|
|
||||||
- **Tecla M**: Activa o desactiva la música
|
|
||||||
- **Tecla P**: Pone en pausa el juego
|
- **Cursores**: Para mover a izquierda o derecha a JailDoc y para saltar
|
||||||
- **Tecla ESC**: Sale del juego si estas jugando. Sale del programa en cualquier otra circunstancia
|
|
||||||
- **Tecla F**: Cambia a modo de pantalla completa o de ventana
|
- **Tecla M**: Activa o desactiva la música
|
||||||
- **Teclas F1 a F4**: Cambian el tamaño de la ventana
|
|
||||||
- **Tecla B**: Activa o desactiva el borde de colores de la pantalla cuando el programa se ejecuta en modo de ventana
|
- **Tecla P**: Pone en pausa el juego
|
||||||
|
|
||||||
|
- **Tecla ESC**: Sale del juego si estas jugando. Sale del programa en cualquier otra circunstancia
|
||||||
|
|
||||||
|
- **Tecla F**: Cambia a modo de pantalla completa o de ventana
|
||||||
|
|
||||||
|
- **Teclas F1 a F4**: Cambian el tamaño de la ventana
|
||||||
|
|
||||||
|
- **Tecla B**: Activa o desactiva el borde de colores de la pantalla cuando el programa se ejecuta en modo de ventana
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Datos del programa
|
||||||
|
El programa guarda automáticamente la configuración del modo de video y las estadísticas de juego en tu carpeta personal del sistema. Esta carpeta tiene una ubicación distinta en función del sistema operativo que utilices.
|
||||||
|
|
||||||
|
En **Windows** se encuentra en:
|
||||||
|
`C:\Users\<nombre_de_usuario>\AppData\Roaming\jaildoctors_dilemma`
|
||||||
|
|
||||||
|
En **MacOS** se encuentra en:
|
||||||
|
`~/Library/Application Support/jaildoctors_dilemma`
|
||||||
|
|
||||||
|
En **Linux** se encuentra en:
|
||||||
|
`~/.jaildoctors_dilemma`
|
||||||
|
|
||||||
|
La primera vez, el juego te pregunta por tu identificador online. Esta información se guarda para futuras partidas.
|
||||||
|
|
||||||
|
En la carpeta está el fichero de configuración `config.txt` donde se puede modificar la configuración para conectarse al servicio online y los ficheros `stats.csv` y `stats_buffer.csv` con información de las estadisticas de juego.
|
||||||
|
|
||||||
## Agradecimientos
|
## Agradecimientos
|
||||||
|
|
||||||
Agradecimientos como siempre a todos los Jailers por motivarme a hacer el juego y ayudarme en los momentos de duda a la hora de escribir el código. Y, como siempre, en especial a JailDoc por su unidad de Jail_Audio y cualquier otro código/ayuda/enseñanzas que haya necesitado para terminar el programa.
|
Agradecimientos como siempre a todos los Jailers por motivarme a hacer el juego y ayudarme en los momentos de duda a la hora de escribir el código. Y, como siempre, en especial a JailDoc por su unidad de Jail_Audio y cualquier otro código/ayuda/enseñanzas que haya necesitado para terminar el programa.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Si no me he descontado, este es el cuarto juego que consigo crear.
|
Si no me he descontado, este es el cuarto juego que consigo crear.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*13 de noviembre de 2022, JailDesigner*
|
*13 de noviembre de 2022, JailDesigner*
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
34,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,25,
|
34,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,25,
|
||||||
34,34,389,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,387,25,25,
|
34,34,389,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,387,25,25,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,513,190,189,190,537,0,0,0,0,
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,513,189,190,537,0,0,0,0,
|
||||||
34,34,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,191,0,0,189,190,189,190,189,190,189,190,25,25
|
34,34,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,191,0,0,189,190,189,190,189,190,189,190,25,25
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
|
|||||||
BIN
data/sound/notify.wav
Normal file
BIN
data/sound/notify.wav
Normal file
Binary file not shown.
@@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
|
||||||
<string>English</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>com.apple.xcode.dsym.jaildoctors_dilemma_debug</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>dSYM</string>
|
|
||||||
<key>CFBundleSignature</key>
|
|
||||||
<string>????</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.0.0</string>
|
<string>1.0.6</string>
|
||||||
<key>CSResourcesFileMapped</key>
|
<key>CSResourcesFileMapped</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
13
source/cheevos.cpp
Normal file
13
source/cheevos.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "cheevos.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Cheevos::Cheevos(options_t *options)
|
||||||
|
{
|
||||||
|
this->options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Cheevos::~Cheevos()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
27
source/cheevos.h
Normal file
27
source/cheevos.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef CHEEVOS_H
|
||||||
|
#define CHEEVOS_H
|
||||||
|
|
||||||
|
class Cheevos
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// Punteros y objetos
|
||||||
|
options_t *options;
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Cheevos(options_t *options);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Cheevos();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -10,10 +10,10 @@ Asset::Asset(std::string executablePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(std::string file, enum assetType type, bool required)
|
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
temp.file = executablePath + file;
|
temp.file = absolute ? file : executablePath + file;
|
||||||
temp.type = type;
|
temp.type = type;
|
||||||
temp.required = required;
|
temp.required = required;
|
||||||
fileList.push_back(temp);
|
fileList.push_back(temp);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ private:
|
|||||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||||
enum assetType type; // Indica el tipo de recurso
|
enum assetType type; // Indica el tipo de recurso
|
||||||
bool required; // Indica si es un fichero que debe de existir
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
|
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
@@ -50,7 +51,7 @@ public:
|
|||||||
Asset(std::string path);
|
Asset(std::string path);
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void add(std::string file, enum assetType type, bool required = true);
|
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
||||||
|
|
||||||
// Devuelve un elemento de la lista a partir de una cadena
|
// Devuelve un elemento de la lista a partir de una cadena
|
||||||
std::string get(std::string text);
|
std::string get(std::string text);
|
||||||
|
|||||||
154
source/common/jscore.cpp
Normal file
154
source/common/jscore.cpp
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
#include "jscore.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace jscore {
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
struct user {
|
||||||
|
string name;
|
||||||
|
int points;
|
||||||
|
};
|
||||||
|
vector<user> score;
|
||||||
|
|
||||||
|
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||||
|
int sock;
|
||||||
|
struct sockaddr_in client;
|
||||||
|
|
||||||
|
int PORT = 9911;
|
||||||
|
string HOST = "jaildoctor.duckdns.org";
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
WSADATA WsaData;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool jscore_error = false;
|
||||||
|
string error_message;
|
||||||
|
|
||||||
|
void init(std::string host, const int port) {
|
||||||
|
PORT = port;
|
||||||
|
HOST = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setErrorMessage(string message) {
|
||||||
|
jscore_error = true;
|
||||||
|
error_message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
string sendRequest(const string request) {
|
||||||
|
#ifdef WIN32
|
||||||
|
int ret = WSAStartup(0x101,&WsaData);
|
||||||
|
if (ret != 0) return 0;
|
||||||
|
#endif
|
||||||
|
struct hostent * host = gethostbyname(HOST.c_str());
|
||||||
|
|
||||||
|
if ( (host == NULL) || (host->h_addr == NULL) ) {
|
||||||
|
setErrorMessage("Error retrieving DNS information.\n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero(&client, sizeof(client));
|
||||||
|
client.sin_family = AF_INET;
|
||||||
|
client.sin_port = htons( PORT );
|
||||||
|
memcpy(&client.sin_addr, host->h_addr, host->h_length);
|
||||||
|
|
||||||
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
if (sock < 0) {
|
||||||
|
setErrorMessage("Error creating socket.\n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( connect(sock, (struct sockaddr *)&client, sizeof(client)) < 0 ) {
|
||||||
|
close(sock);
|
||||||
|
setErrorMessage("Could not connect\n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
string r = request + " HTTP/1.1\r\nHost: "+HOST+"\r\nConnection: close\r\n\r\n\r\n";
|
||||||
|
if (send(sock, r.c_str(), r.length(), 0) != (int)r.length()) {
|
||||||
|
setErrorMessage("Error sending request.\n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char cur;
|
||||||
|
char start[5]="\r\n\r\n";
|
||||||
|
int pos = 0;
|
||||||
|
while ( recv(sock, &cur, 1,0) > 0 ) {
|
||||||
|
if (cur==start[pos]) { pos++; if (pos == 4) break; } else { pos = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[1024]; buffer[0]=0; pos=0;
|
||||||
|
while ( recv(sock, &cur, 1,0) > 0 ) {
|
||||||
|
buffer[pos] = cur;
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
#ifdef WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
buffer[pos]=0;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool initOnlineScore(string game) {
|
||||||
|
string strbuff = sendRequest("GET /score-list.php?game=" + game);
|
||||||
|
if (jscore_error) return not jscore_error;
|
||||||
|
|
||||||
|
user u;
|
||||||
|
char buffer[1024];
|
||||||
|
strcpy(buffer, strbuff.c_str());
|
||||||
|
char *str = buffer;
|
||||||
|
char *p = str;
|
||||||
|
score.clear();
|
||||||
|
while (*p!=0) {
|
||||||
|
while (*p!=',') {p++;}
|
||||||
|
*p=0; u.name = str; p++; str=p;
|
||||||
|
while (*p!='\n') {p++;}
|
||||||
|
*p=0; u.points = atoi(str); p++; str=p;
|
||||||
|
score.push_back(u);
|
||||||
|
}
|
||||||
|
return not jscore_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int getNumUsers() {
|
||||||
|
return score.size();
|
||||||
|
}
|
||||||
|
string getUserName(const int index) {
|
||||||
|
return score[index].name;
|
||||||
|
}
|
||||||
|
const int getPoints(const int index) {
|
||||||
|
return score[index].points;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool updateUserPoints(string game, string user, const int points) {
|
||||||
|
string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + to_string(points));
|
||||||
|
initOnlineScore(game);
|
||||||
|
return not jscore_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int getUserPoints(string game, std::string user) {
|
||||||
|
return atoi(sendRequest("GET /getuserpoints.php?game=" + game + "&user=" + user).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
string getUserData(string game, string user) {
|
||||||
|
return sendRequest("GET /getuserdata.php?game=" + game + "&user=" + user);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUserData(string game, string user, string data) {
|
||||||
|
sendRequest("GET /setuserdata.php?game=" + game + "&user=" + user + "&data=" + data);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
16
source/common/jscore.h
Normal file
16
source/common/jscore.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace jscore {
|
||||||
|
void init(std::string host, const int port);
|
||||||
|
const bool initOnlineScore(std::string game);
|
||||||
|
const int getNumUsers();
|
||||||
|
std::string getUserName(const int index);
|
||||||
|
const int getPoints(const int index);
|
||||||
|
const int getUserPoints(std::string game, std::string user);
|
||||||
|
|
||||||
|
const bool updateUserPoints(std::string game, std::string user, const int points);
|
||||||
|
std::string getUserData(std::string game, std::string user);
|
||||||
|
void setUserData(std::string game, std::string user, std::string data);
|
||||||
|
};
|
||||||
|
|
||||||
162
source/common/notify.cpp
Normal file
162
source/common/notify.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
#include "notify.h"
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
this->renderer = renderer;
|
||||||
|
bgColor = {64, 64, 64};
|
||||||
|
waitTime = 300;
|
||||||
|
|
||||||
|
// Crea objetos
|
||||||
|
texture = new Texture(renderer, bitmapFile);
|
||||||
|
text = new Text(textFile, texture, renderer);
|
||||||
|
sound = JA_LoadSound(soundFile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Notify::~Notify()
|
||||||
|
{
|
||||||
|
// Libera la memoria de los objetos
|
||||||
|
delete texture;
|
||||||
|
delete text;
|
||||||
|
JA_DeleteSound(sound);
|
||||||
|
|
||||||
|
for (auto notification : notifications)
|
||||||
|
{
|
||||||
|
delete notification.sprite;
|
||||||
|
delete notification.texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las notificaciones por pantalla
|
||||||
|
void Notify::render()
|
||||||
|
{
|
||||||
|
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
notifications.at(i).sprite->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado de las notificaiones
|
||||||
|
void Notify::update()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||||
|
{
|
||||||
|
notifications.at(i).counter++;
|
||||||
|
|
||||||
|
// Comprueba los estados
|
||||||
|
if (notifications.at(i).state == ns_rising)
|
||||||
|
{
|
||||||
|
const float step = ((float)notifications.at(i).counter / notifications.at(i).travelDist);
|
||||||
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
|
notifications.at(i).rect.y++;
|
||||||
|
notifications.at(i).texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notifications.at(i).rect.y == notifications.at(i).y)
|
||||||
|
{
|
||||||
|
notifications.at(i).state = ns_stay;
|
||||||
|
notifications.at(i).texture->setAlpha(255);
|
||||||
|
notifications.at(i).counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (notifications.at(i).state == ns_stay)
|
||||||
|
{
|
||||||
|
if (notifications.at(i).counter == waitTime)
|
||||||
|
{
|
||||||
|
notifications.at(i).state = ns_vanishing;
|
||||||
|
notifications.at(i).counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (notifications.at(i).state == ns_vanishing)
|
||||||
|
{
|
||||||
|
|
||||||
|
const float step = (notifications.at(i).counter / (float)notifications.at(i).travelDist);
|
||||||
|
const int alpha = 255 * (1 - step);
|
||||||
|
|
||||||
|
notifications.at(i).rect.y--;
|
||||||
|
notifications.at(i).texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notifications.at(i).rect.y == notifications.at(i).y - notifications.at(i).travelDist)
|
||||||
|
{
|
||||||
|
notifications.at(i).state = ns_finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications.at(i).sprite->setRect(notifications.at(i).rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearFinishedNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elimina las notificaciones finalizadas
|
||||||
|
void Notify::clearFinishedNotifications()
|
||||||
|
{
|
||||||
|
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (notifications.at(i).state == ns_finished)
|
||||||
|
{
|
||||||
|
delete notifications.at(i).sprite;
|
||||||
|
delete notifications.at(i).texture;
|
||||||
|
notifications.erase(notifications.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void Notify::showText(std::string text)
|
||||||
|
{
|
||||||
|
// Crea constantes
|
||||||
|
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
||||||
|
const int height = this->text->getCharacterSize() * 2;
|
||||||
|
const int despH = this->text->getCharacterSize() / 2;
|
||||||
|
const int despV = despH;
|
||||||
|
const int travelDist = height + despV;
|
||||||
|
const int offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||||
|
|
||||||
|
// Crea la notificacion
|
||||||
|
notification_t n;
|
||||||
|
|
||||||
|
// inicializa variables
|
||||||
|
n.y = offset;
|
||||||
|
n.travelDist = travelDist;
|
||||||
|
n.counter = 0;
|
||||||
|
n.state = ns_rising;
|
||||||
|
n.text = text;
|
||||||
|
n.rect = {despH, offset - travelDist, width, height};
|
||||||
|
|
||||||
|
// Crea la textura
|
||||||
|
n.texture = new Texture(renderer);
|
||||||
|
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
|
||||||
|
n.texture->setAsRenderTarget(renderer);
|
||||||
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||||
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
|
// Crea el sprite
|
||||||
|
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||||
|
|
||||||
|
// Añade la notificación a la lista
|
||||||
|
notifications.push_back(n);
|
||||||
|
|
||||||
|
// Reproduce el sonido de la notificación
|
||||||
|
JA_PlaySound(sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si hay notificaciones activas
|
||||||
|
bool Notify::active()
|
||||||
|
{
|
||||||
|
if ((int)notifications.size() > 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
84
source/common/notify.h
Normal file
84
source/common/notify.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef NOTIFY_H
|
||||||
|
#define NOTIFY_H
|
||||||
|
|
||||||
|
class Notify
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
enum notification_state_e
|
||||||
|
{
|
||||||
|
ns_rising,
|
||||||
|
ns_stay,
|
||||||
|
ns_vanishing,
|
||||||
|
ns_finished
|
||||||
|
};
|
||||||
|
|
||||||
|
enum notification_position_e
|
||||||
|
{
|
||||||
|
upperLeft,
|
||||||
|
upperCenter,
|
||||||
|
upperRight,
|
||||||
|
middleLeft,
|
||||||
|
middleRight,
|
||||||
|
bottomLeft,
|
||||||
|
bottomCenter,
|
||||||
|
bottomRight
|
||||||
|
};
|
||||||
|
|
||||||
|
struct notification_t
|
||||||
|
{
|
||||||
|
std::string text;
|
||||||
|
int counter;
|
||||||
|
notification_state_e state;
|
||||||
|
notification_position_e position;
|
||||||
|
Texture *texture;
|
||||||
|
Sprite *sprite;
|
||||||
|
SDL_Rect rect;
|
||||||
|
int y;
|
||||||
|
int travelDist;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Texture *texture; // Textura para la fuente de las notificaciones
|
||||||
|
Text *text; // Objeto para dibujar texto
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
color_t bgColor; // Color de fondo de las notificaciones
|
||||||
|
int waitTime; // Tiempo que se ve la notificación
|
||||||
|
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
||||||
|
JA_Sound sound; // Sonido a reproducir cuando suena la notificación
|
||||||
|
|
||||||
|
// Elimina las notificaciones finalizadas
|
||||||
|
void clearFinishedNotifications();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Dibuja las notificaciones por pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza el estado de las notificaiones
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Notify();
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void showText(std::string text);
|
||||||
|
|
||||||
|
// Indica si hay notificaciones activas
|
||||||
|
bool active();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,15 +3,23 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->options = options;
|
this->options = options;
|
||||||
|
this->asset = asset;
|
||||||
|
|
||||||
gameCanvasWidth = gameInternalResX;
|
// Crea los objetos
|
||||||
gameCanvasHeight = gameInternalResY;
|
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
|
||||||
|
|
||||||
|
gameCanvasWidth = options->gameWidth;
|
||||||
|
gameCanvasHeight = options->gameHeight;
|
||||||
|
borderWidth = options->gameWidth * options->borderSize;
|
||||||
|
borderHeight = options->gameHeight * options->borderSize;
|
||||||
|
notificationLogicalWidth = gameCanvasWidth;
|
||||||
|
notificationLogicalHeight = gameCanvasHeight;
|
||||||
|
|
||||||
iniFade();
|
iniFade();
|
||||||
iniSpectrumFade();
|
iniSpectrumFade();
|
||||||
@@ -23,19 +31,23 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
|
|||||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||||
if (gameCanvas == nullptr)
|
if (gameCanvas == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->fullScreenMode);
|
setVideoMode(options->videoMode);
|
||||||
|
|
||||||
// Calcula los anclajes
|
// Inicializa variables
|
||||||
anchor.left = 0;
|
notifyActive = false;
|
||||||
anchor.right = gameCanvasWidth;
|
}
|
||||||
anchor.center = gameCanvasWidth / 2;
|
|
||||||
anchor.top = 0;
|
// Destructor
|
||||||
anchor.bottom = gameCanvasHeight;
|
Screen::~Screen()
|
||||||
anchor.middle = gameCanvasHeight / 2;
|
{
|
||||||
|
delete notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
@@ -64,107 +76,109 @@ void Screen::blit()
|
|||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||||
|
|
||||||
|
// Dibuja las notificaciones
|
||||||
|
renderNotifications();
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void Screen::setVideoMode(int fullScreenMode)
|
void Screen::setVideoMode(int videoMode)
|
||||||
{
|
{
|
||||||
|
// Muestra el puntero
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
// Aplica el modo de video
|
// Aplica el modo de video
|
||||||
SDL_SetWindowFullscreen(window, fullScreenMode);
|
SDL_SetWindowFullscreen(window, videoMode);
|
||||||
|
|
||||||
// Si está activo el modo ventana quita el borde
|
// Si está activo el modo ventana quita el borde
|
||||||
if (fullScreenMode == 0)
|
if (videoMode == 0)
|
||||||
{
|
{
|
||||||
if (options->borderEnabled)
|
if (options->borderEnabled)
|
||||||
{
|
{
|
||||||
const int incWidth = gameCanvasWidth * options->borderSize;
|
windowWidth = gameCanvasWidth + borderWidth;
|
||||||
const int incHeight = gameCanvasHeight * options->borderSize;
|
windowHeight = gameCanvasHeight + borderHeight;
|
||||||
screenWidth = gameCanvasWidth + incWidth;
|
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||||
screenHeight = gameCanvasHeight + incHeight;
|
|
||||||
dest = {0 + (incWidth / 2), 0 + (incHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
screenWidth = gameCanvasWidth;
|
windowWidth = gameCanvasWidth;
|
||||||
screenHeight = gameCanvasHeight;
|
windowHeight = gameCanvasHeight;
|
||||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador y de la ventana
|
// Modifica el tamaño del renderizador y de la ventana
|
||||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
SDL_SetWindowSize(window, screenWidth * options->windowSize, screenHeight * options->windowSize);
|
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
{
|
{
|
||||||
|
// Oculta el puntero
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
// Obten el alto y el ancho de la ventana
|
// Obten el alto y el ancho de la ventana
|
||||||
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||||
|
|
||||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||||
if (options->integerScale)
|
if (options->integerScale)
|
||||||
{
|
{
|
||||||
// Calcula el tamaño de la escala máxima
|
// Calcula el tamaño de la escala máxima
|
||||||
int scale = 0;
|
int scale = 0;
|
||||||
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight))
|
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
|
||||||
{
|
{
|
||||||
scale++;
|
scale++;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest.w = gameCanvasWidth * scale;
|
dest.w = gameCanvasWidth * scale;
|
||||||
dest.h = gameCanvasHeight * scale;
|
dest.h = gameCanvasHeight * scale;
|
||||||
dest.x = (screenWidth - dest.w) / 2;
|
dest.x = (windowWidth - dest.w) / 2;
|
||||||
dest.y = (screenHeight - dest.h) / 2;
|
dest.y = (windowHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
else if (options->keepAspect)
|
else if (options->keepAspect)
|
||||||
{
|
{
|
||||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||||
if ((screenWidth - gameCanvasWidth) >= (screenHeight - gameCanvasHeight))
|
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||||
{
|
{
|
||||||
dest.h = screenHeight;
|
dest.h = windowHeight;
|
||||||
dest.w = (int)((screenHeight * ratio) + 0.5f);
|
dest.w = (int)((windowHeight * ratio) + 0.5f);
|
||||||
dest.x = (screenWidth - dest.w) / 2;
|
dest.x = (windowWidth - dest.w) / 2;
|
||||||
dest.y = (screenHeight - dest.h) / 2;
|
dest.y = (windowHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dest.w = screenWidth;
|
dest.w = windowWidth;
|
||||||
dest.h = (int)((screenWidth / ratio) + 0.5f);
|
dest.h = (int)((windowWidth / ratio) + 0.5f);
|
||||||
dest.x = (screenWidth - dest.w) / 2;
|
dest.x = (windowWidth - dest.w) / 2;
|
||||||
dest.y = (screenHeight - dest.h) / 2;
|
dest.y = (windowHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dest.w = screenWidth;
|
dest.w = windowWidth;
|
||||||
dest.h = screenHeight;
|
dest.h = windowHeight;
|
||||||
dest.x = dest.y = 0;
|
dest.x = dest.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador
|
// Modifica el tamaño del renderizador
|
||||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
options->fullScreenMode = fullScreenMode;
|
options->videoMode = videoMode;
|
||||||
|
|
||||||
|
// Establece el tamaño de las notificaciones
|
||||||
|
setNotificationSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
void Screen::switchVideoMode()
|
void Screen::switchVideoMode()
|
||||||
{
|
{
|
||||||
if (options->fullScreenMode == 0)
|
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||||
{
|
setVideoMode(options->videoMode);
|
||||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->fullScreenMode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
setVideoMode(options->fullScreenMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
// Cambia el tamaño de la ventana
|
||||||
@@ -338,4 +352,54 @@ void Screen::renderFX()
|
|||||||
{
|
{
|
||||||
renderFade();
|
renderFade();
|
||||||
renderSpectrumFade();
|
renderSpectrumFade();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el notificador
|
||||||
|
void Screen::updateNotifier()
|
||||||
|
{
|
||||||
|
notify->update();
|
||||||
|
notifyActive = notify->active();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void Screen::showNotification(std::string text)
|
||||||
|
{
|
||||||
|
notify->showText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las notificaciones
|
||||||
|
void Screen::renderNotifications()
|
||||||
|
{
|
||||||
|
if (!notifyActive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
||||||
|
notify->render();
|
||||||
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tamaño de las notificaciones
|
||||||
|
void Screen::setNotificationSize()
|
||||||
|
{
|
||||||
|
if (options->videoMode == 0)
|
||||||
|
{
|
||||||
|
if (options->windowSize == 3)
|
||||||
|
{
|
||||||
|
notificationLogicalWidth = (windowWidth * 3) / 2;
|
||||||
|
notificationLogicalHeight = (windowHeight * 3) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notificationLogicalWidth = windowWidth * 2;
|
||||||
|
notificationLogicalHeight = windowHeight * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
|
{
|
||||||
|
notificationLogicalWidth = windowWidth / 3;
|
||||||
|
notificationLogicalHeight = windowHeight / 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "notify.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -10,42 +12,37 @@
|
|||||||
#define FILTER_NEAREST 0
|
#define FILTER_NEAREST 0
|
||||||
#define FILTER_LINEAL 1
|
#define FILTER_LINEAL 1
|
||||||
|
|
||||||
struct anchor_t
|
|
||||||
{
|
|
||||||
int left; // Parte izquierda de la pantalla de juego
|
|
||||||
int right; // Parte drecha de la pantalla de juego
|
|
||||||
int center; // Parte central horizontal de la pantalla de juego
|
|
||||||
int top; // Parte superior de la pantalla de juego
|
|
||||||
int bottom; // Parte infoerior de la pantalla de juego
|
|
||||||
int middle; // Parte central vertical de la pantalla de juego
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clase Screen
|
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window; // Ventana de la aplicación
|
SDL_Window *window; // Ventana de la aplicación
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Asset *asset; // Objeto con el listado de recursos
|
||||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
Notify *notify; // Dibuja notificaciones por pantalla
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int screenWidth; // Ancho de la pantalla o ventana
|
int windowWidth; // Ancho de la pantalla o ventana
|
||||||
int screenHeight; // Alto de la pantalla o ventana
|
int windowHeight; // Alto de la pantalla o ventana
|
||||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||||
anchor_t anchor; // Variable con los anclajes de la pantalla
|
int borderWidth; // Anchura del borde
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
int borderHeight; // Anltura del borde
|
||||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
bool notifyActive; // Indica si hay notificaciones activas
|
||||||
|
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
||||||
|
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
||||||
|
|
||||||
// Variables - Efectos
|
// Variables - Efectos
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
bool fade; // Indica si esta activo el efecto de fade
|
||||||
int fadeCounter; // Temporizador para el efecto de fade
|
int fadeCounter; // Temporizador para el efecto de fade
|
||||||
int fadeLenght; // Duración del fade
|
int fadeLenght; // Duración del fade
|
||||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
||||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
||||||
int spectrumFadeLenght; // Duración del fade spectrum
|
int spectrumFadeLenght; // Duración del fade spectrum
|
||||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
// Inicializa las variables para el fade
|
||||||
@@ -66,9 +63,18 @@ private:
|
|||||||
// Dibuja el spectrum fade
|
// Dibuja el spectrum fade
|
||||||
void renderSpectrumFade();
|
void renderSpectrumFade();
|
||||||
|
|
||||||
|
// Dibuja las notificaciones
|
||||||
|
void renderNotifications();
|
||||||
|
|
||||||
|
// Establece el tamaño de las notificaciones
|
||||||
|
void setNotificationSize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Screen();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void clean(color_t color = {0x00, 0x00, 0x00});
|
void clean(color_t color = {0x00, 0x00, 0x00});
|
||||||
@@ -80,7 +86,7 @@ public:
|
|||||||
void blit();
|
void blit();
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(int fullScreenMode);
|
void setVideoMode(int videoMode);
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
void switchVideoMode();
|
void switchVideoMode();
|
||||||
@@ -120,6 +126,12 @@ public:
|
|||||||
|
|
||||||
// Dibuja los efectos
|
// Dibuja los efectos
|
||||||
void renderFX();
|
void renderFX();
|
||||||
|
|
||||||
|
// Actualiza el notificador
|
||||||
|
void updateNotifier();
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void showNotification(std::string text);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende
|
|||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {x, y, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -41,7 +41,7 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
|
|||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {x, y, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -83,8 +83,8 @@ int Sprite::getHeight()
|
|||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void Sprite::setPos(SDL_Rect rect)
|
void Sprite::setPos(SDL_Rect rect)
|
||||||
{
|
{
|
||||||
x = rect.x;
|
this->x = rect.x;
|
||||||
y = rect.y;
|
this->y = rect.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -166,6 +166,12 @@ void Sprite::setRenderer(SDL_Renderer *renderer)
|
|||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Renderer *Sprite::getRenderer()
|
||||||
|
{
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setEnabled(bool value)
|
void Sprite::setEnabled(bool value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ public:
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setRenderer(SDL_Renderer *renderer);
|
void setRenderer(SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Renderer *getRenderer();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setEnabled(bool value);
|
void setEnabled(bool value);
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -111,6 +114,9 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -133,7 +139,8 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
|||||||
sprite->setPosX(x + shift);
|
sprite->setPosX(x + shift);
|
||||||
sprite->setPosY(y);
|
sprite->setPosY(y);
|
||||||
sprite->render();
|
sprite->render();
|
||||||
shift += (offset[int(text[i])].w + kerning);
|
// shift += (offset[int(text[i])].w + kerning);
|
||||||
|
shift += fixedWidth ? boxWidth : (offset[int(text[i])].w + kerning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,4 +232,10 @@ int Text::getCharacterSize()
|
|||||||
void Text::reLoadTexture()
|
void Text::reLoadTexture()
|
||||||
{
|
{
|
||||||
sprite->getTexture()->reLoad();
|
sprite->getTexture()->reLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si se usa un tamaño fijo de letra
|
||||||
|
void Text::setFixedWidth(bool value)
|
||||||
|
{
|
||||||
|
fixedWidth = value;
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,12 @@ class Text
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Sprite *sprite; // Objeto con los graficos para el texto
|
Sprite *sprite; // Objeto con los graficos para el texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||||
|
bool fixedWidth; // Indica si el texto se ha de escribir con longitud fija en todas las letras
|
||||||
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -71,6 +72,9 @@ public:
|
|||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture();
|
||||||
|
|
||||||
|
// Establece si se usa un tamaño fijo de letra
|
||||||
|
void setFixedWidth(bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -294,28 +294,6 @@ SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
|
|||||||
return {-1, -1};
|
return {-1, -1};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detector de colisiones entre una linea diagonal y una vertical
|
|
||||||
/*bool checkCollision(d_line_t &l1, v_line_t &l2)
|
|
||||||
{
|
|
||||||
// Normaliza la linea diagonal
|
|
||||||
normalizeLine(l1);
|
|
||||||
|
|
||||||
// Comprueba si la linea vertical esta a la izquierda de la linea diagonal
|
|
||||||
if (l2.x < l1.x1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si la linea vertical esta a la derecha de la linea diagonal
|
|
||||||
if (l2.x > l1.x2)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inacabada
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Normaliza una linea diagonal
|
// Normaliza una linea diagonal
|
||||||
void normalizeLine(d_line_t &l)
|
void normalizeLine(d_line_t &l)
|
||||||
{
|
{
|
||||||
@@ -367,16 +345,6 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
|
|||||||
|
|
||||||
// En caso contrario, el punto está en la linea
|
// En caso contrario, el punto está en la linea
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
/*const int m = (l.y2 - l.y1) / (l.x2 - l.x1);
|
|
||||||
const int c = 0;
|
|
||||||
|
|
||||||
// Comprueba si p cumple la ecuación de la linea
|
|
||||||
if (p.y == ((m * p.x) + c))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve un color_t a partir de un string
|
// Devuelve un color_t a partir de un string
|
||||||
|
|||||||
@@ -70,24 +70,44 @@ struct cheat_t
|
|||||||
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
|
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estructura para el servicio online
|
||||||
|
struct online_t
|
||||||
|
{
|
||||||
|
bool enabled; // Indica si se quiere usar el modo online o no
|
||||||
|
std::string server; // Servidor para los servicios online
|
||||||
|
int port; // Puerto del servidor
|
||||||
|
std::string gameID; // Identificador del juego para los servicios online
|
||||||
|
std::string jailerID; // Identificador del jugador para los servicios online
|
||||||
|
int score; // Puntuación almacenada online
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar estadísticas
|
||||||
|
struct op_stats_t
|
||||||
|
{
|
||||||
|
int rooms; // Cantidad de habitaciones visitadas
|
||||||
|
int items; // Cantidad de items obtenidos
|
||||||
|
std::string worstNightmare; // Habitación con más muertes acumuladas
|
||||||
|
};
|
||||||
|
|
||||||
// Estructura con todas las opciones de configuración del programa
|
// Estructura con todas las opciones de configuración del programa
|
||||||
struct options_t
|
struct options_t
|
||||||
{
|
{
|
||||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
||||||
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
||||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
int screenWidth; // Ancho de la pantalla o ventana
|
bool vSync; // Indica si se quiere usar vsync o no
|
||||||
int screenHeight; // Alto de la pantalla o ventana
|
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
int gameHeight; // Alto de la resolucion nativa del juego
|
||||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||||
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||||
palette_e palette; // Paleta de colores a usar en el juego
|
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
||||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
palette_e palette; // Paleta de colores a usar en el juego
|
||||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||||
int rooms; // Cantidad de habitaciones visitadas
|
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||||
int items; // Cantidad de items obtenidos
|
op_stats_t stats; // Datos con las estadisticas de juego
|
||||||
|
online_t online; // Datos del servicio online
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
|||||||
#define SECTION_PROG_GAME_OVER 6
|
#define SECTION_PROG_GAME_OVER 6
|
||||||
#define SECTION_PROG_ENDING 7
|
#define SECTION_PROG_ENDING 7
|
||||||
#define SECTION_PROG_ENDING2 8
|
#define SECTION_PROG_ENDING2 8
|
||||||
#define SECTION_PROG_QUIT 9
|
#define SECTION_PROG_ENTER_ID 9
|
||||||
|
#define SECTION_PROG_QUIT 10
|
||||||
|
|
||||||
// Subsecciones
|
// Subsecciones
|
||||||
#define SUBSECTION_LOGO_TO_INTRO 0
|
#define SUBSECTION_LOGO_TO_INTRO 0
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ void Credits::fillTexture()
|
|||||||
{
|
{
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
iniTexts();
|
iniTexts();
|
||||||
|
|
||||||
// Rellena la textura de texto
|
// Rellena la textura de texto
|
||||||
SDL_SetRenderTarget(renderer, textTexture);
|
SDL_SetRenderTarget(renderer, textTexture);
|
||||||
color_t c = stringToColor(options->palette, "black");
|
color_t c = stringToColor(options->palette, "black");
|
||||||
@@ -264,6 +264,9 @@ void Credits::update()
|
|||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
updateCounter();
|
updateCounter();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
|
|
||||||
// Actualiza el sprite con el brillo
|
// Actualiza el sprite con el brillo
|
||||||
if (counter > 770)
|
if (counter > 770)
|
||||||
{
|
{
|
||||||
@@ -315,14 +318,6 @@ section_t Credits::run()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Credits::switchPalette()
|
void Credits::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->palette == p_zxspectrum)
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
{
|
fillTexture();
|
||||||
options->palette = p_zxarne;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->palette = p_zxspectrum;
|
|
||||||
}
|
|
||||||
|
|
||||||
fillTexture();
|
|
||||||
}
|
}
|
||||||
@@ -153,6 +153,9 @@ void Demo::update()
|
|||||||
scoreboard->update();
|
scoreboard->update();
|
||||||
screen->updateFX();
|
screen->updateFX();
|
||||||
checkRoomChange();
|
checkRoomChange();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +192,7 @@ void Demo::renderRoomName()
|
|||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void Demo::reLoadTextures()
|
void Demo::reLoadTextures()
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options->console)
|
||||||
{
|
{
|
||||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
#include "director.h"
|
#include "common/jscore.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
#include "director.h"
|
||||||
|
#include <errno.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, char *argv[])
|
Director::Director(int argc, char *argv[])
|
||||||
@@ -10,15 +18,18 @@ Director::Director(int argc, char *argv[])
|
|||||||
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_LOGO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
iniOptions();
|
initOptions();
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
|
createSystemFolder();
|
||||||
|
|
||||||
// Crea el objeto que controla los ficheros de recursos
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
asset = new Asset(executablePath);
|
asset = new Asset(executablePath);
|
||||||
asset->setVerbose(options->console);
|
asset->setVerbose(options->console);
|
||||||
@@ -26,7 +37,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
// Si falta algún fichero no inicia el programa
|
// Si falta algún fichero no inicia el programa
|
||||||
if (!setFileList())
|
if (!setFileList())
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables desde el fichero de configuración
|
// Inicializa variables desde el fichero de configuración
|
||||||
@@ -42,11 +53,13 @@ Director::Director(int argc, char *argv[])
|
|||||||
resource = new Resource(renderer, asset, options);
|
resource = new Resource(renderer, asset, options);
|
||||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
initInput();
|
initInput();
|
||||||
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
screen = new Screen(window, renderer, asset, options);
|
||||||
screen->setBorderColor(borderColor);
|
screen->setBorderColor(borderColor);
|
||||||
screen->setVideoMode(options->fullScreenMode);
|
|
||||||
debug = new Debug(renderer, screen, asset);
|
debug = new Debug(renderer, screen, asset);
|
||||||
music = JA_LoadMusic(asset->get("title.ogg").c_str());
|
music = JA_LoadMusic(asset->get("title.ogg").c_str());
|
||||||
|
|
||||||
|
// Inicializa los servicios online
|
||||||
|
//initOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director()
|
Director::~Director()
|
||||||
@@ -68,21 +81,51 @@ Director::~Director()
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inicializa los servicios online
|
||||||
|
void Director::initOnline()
|
||||||
|
{
|
||||||
|
if (options->online.jailerID == "")
|
||||||
|
{ // Jailer ID no definido
|
||||||
|
|
||||||
|
options->online.enabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Jailer ID iniciado
|
||||||
|
|
||||||
|
if (options->online.enabled)
|
||||||
|
{ // Establece el servidor y el puerto
|
||||||
|
jscore::init(options->online.server, options->online.port);
|
||||||
|
|
||||||
|
const std::string caption = options->online.jailerID + " IS LOGGED IN";
|
||||||
|
screen->showNotification(caption);
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << caption << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
void Director::iniOptions()
|
void Director::initOptions()
|
||||||
{
|
{
|
||||||
// Crea el puntero a la estructura de opciones
|
// Crea el puntero a la estructura de opciones
|
||||||
options = new options_t;
|
options = new options_t;
|
||||||
|
|
||||||
// Inicializa valores
|
// Version
|
||||||
options->fullScreenMode = 0;
|
options->configVersion = "v1.06.1";
|
||||||
|
|
||||||
|
// Opciones dee video
|
||||||
|
options->gameWidth = GAMECANVAS_WIDTH;
|
||||||
|
options->gameHeight = GAMECANVAS_HEIGHT;
|
||||||
|
options->videoMode = 0;
|
||||||
options->windowSize = 3;
|
options->windowSize = 3;
|
||||||
options->filter = FILTER_NEAREST;
|
options->filter = FILTER_NEAREST;
|
||||||
options->vSync = true;
|
options->vSync = true;
|
||||||
options->integerScale = true;
|
options->integerScale = true;
|
||||||
options->keepAspect = true;
|
options->keepAspect = true;
|
||||||
options->borderEnabled = true;
|
options->borderEnabled = true;
|
||||||
options->borderSize = 0.1f;
|
options->borderSize = 0.2f;
|
||||||
options->palette = p_zxspectrum;
|
options->palette = p_zxspectrum;
|
||||||
|
|
||||||
// Estos valores no se guardan en el fichero de configuraci´ón
|
// Estos valores no se guardan en el fichero de configuraci´ón
|
||||||
@@ -91,8 +134,19 @@ void Director::iniOptions()
|
|||||||
options->cheat.invincible = false;
|
options->cheat.invincible = false;
|
||||||
options->cheat.jailEnabled = false;
|
options->cheat.jailEnabled = false;
|
||||||
options->cheat.altSkin = false;
|
options->cheat.altSkin = false;
|
||||||
options->rooms = 0;
|
options->stats.rooms = 0;
|
||||||
options->items = 0;
|
options->stats.items = 0;
|
||||||
|
|
||||||
|
// Opciones online
|
||||||
|
options->online.enabled = true;
|
||||||
|
options->online.server = "jaildoctor.duckdns.org";
|
||||||
|
options->online.port = 9911;
|
||||||
|
#ifdef DEBUG
|
||||||
|
options->online.gameID = "jaildoctors_dilemma_test";
|
||||||
|
#else
|
||||||
|
options->online.gameID = "jaildoctors_dilemma";
|
||||||
|
#endif
|
||||||
|
options->online.jailerID = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
@@ -137,6 +191,10 @@ bool Director::loadConfig()
|
|||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
|
// Versión actual del fichero
|
||||||
|
const std::string configVersion = options->configVersion;
|
||||||
|
options->configVersion = "";
|
||||||
|
|
||||||
// Variables para manejar el fichero
|
// Variables para manejar el fichero
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream file(asset->get("config.txt"));
|
std::ifstream file(asset->get("config.txt"));
|
||||||
@@ -183,19 +241,40 @@ bool Director::loadConfig()
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto
|
||||||
|
if (configVersion != options->configVersion)
|
||||||
|
{
|
||||||
|
initOptions();
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza los valores
|
||||||
|
const bool a = options->videoMode == 0;
|
||||||
|
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
|
||||||
|
const bool c = options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
if (!(a || b || c))
|
||||||
|
{
|
||||||
|
options->videoMode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options->windowSize < 1 || options->windowSize > 4)
|
||||||
|
{
|
||||||
|
options->windowSize = 3;
|
||||||
|
}
|
||||||
|
|
||||||
// Aplica opciones
|
// Aplica opciones
|
||||||
if (options->borderEnabled)
|
// if (options->borderEnabled)
|
||||||
{
|
//{
|
||||||
const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
|
// const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
|
||||||
const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
|
// const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
|
||||||
options->screenWidth = (GAMECANVAS_WIDTH + incWidth) * options->windowSize;
|
// options->gameWidth = GAMECANVAS_WIDTH + incWidth;
|
||||||
options->screenHeight = (GAMECANVAS_HEIGHT + incHeight) * options->windowSize;
|
// options->gameHeight = GAMECANVAS_HEIGHT + incHeight;
|
||||||
}
|
//}
|
||||||
else
|
// else
|
||||||
{
|
//{
|
||||||
options->screenWidth = GAMECANVAS_WIDTH * options->windowSize;
|
// options->gameWidth = GAMECANVAS_WIDTH;
|
||||||
options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize;
|
// options->gameHeight = GAMECANVAS_HEIGHT;
|
||||||
}
|
//}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -208,20 +287,39 @@ bool Director::saveConfig()
|
|||||||
// Crea y abre el fichero de texto
|
// Crea y abre el fichero de texto
|
||||||
std::ofstream file(asset->get("config.txt"));
|
std::ofstream file(asset->get("config.txt"));
|
||||||
|
|
||||||
|
if (file.good())
|
||||||
|
{
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << asset->get("config.txt") << " open for writing" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << asset->get("config.txt") << " can't be opened" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Escribe en el fichero
|
// Escribe en el fichero
|
||||||
if (options->fullScreenMode == 0)
|
file << "## VERSION\n";
|
||||||
|
file << "configVersion=" + options->configVersion + "\n";
|
||||||
|
|
||||||
|
file << "\n## VISUAL OPTIONS\n";
|
||||||
|
if (options->videoMode == 0)
|
||||||
{
|
{
|
||||||
file << "fullScreenMode=0\n";
|
file << "videoMode=0\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN)
|
else if (options->videoMode == SDL_WINDOW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN\n";
|
file << "videoMode=SDL_WINDOW_FULLSCREEN\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
else if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
{
|
{
|
||||||
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
file << "windowSize=" + std::to_string(options->windowSize) + "\n";
|
file << "windowSize=" + std::to_string(options->windowSize) + "\n";
|
||||||
@@ -242,12 +340,73 @@ bool Director::saveConfig()
|
|||||||
file << "borderSize=" + std::to_string(options->borderSize) + "\n";
|
file << "borderSize=" + std::to_string(options->borderSize) + "\n";
|
||||||
file << "palette=" + std::to_string(options->palette) + "\n";
|
file << "palette=" + std::to_string(options->palette) + "\n";
|
||||||
|
|
||||||
|
file << "\n## ONLINE OPTIONS\n";
|
||||||
|
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
||||||
|
file << "server=" + options->online.server + "\n";
|
||||||
|
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||||
|
file << "jailerID=" + options->online.jailerID + "\n";
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
|
void Director::createSystemFolder()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
const std::string folderName = "jaildoctors_dilemma_debug";
|
||||||
|
#else
|
||||||
|
const std::string folderName = "jaildoctors_dilemma";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
systemFolder = std::string(getenv("APPDATA")) + "/" + folderName;
|
||||||
|
#elif __APPLE__
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
const char *homedir = pw->pw_dir;
|
||||||
|
systemFolder = std::string(homedir) + "/Library/Application Support/" + folderName;
|
||||||
|
#elif __linux__
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
const char *homedir = pw->pw_dir;
|
||||||
|
systemFolder = std::string(homedir) + "/." + folderName;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct stat st = {0};
|
||||||
|
if (stat(systemFolder.c_str(), &st) == -1)
|
||||||
|
{
|
||||||
|
errno = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
|
int ret = mkdir(systemFolder.c_str());
|
||||||
|
#else
|
||||||
|
int ret = mkdir(systemFolder.c_str(), S_IRWXU);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret == -1)
|
||||||
|
{
|
||||||
|
switch (errno)
|
||||||
|
{
|
||||||
|
case EACCES:
|
||||||
|
printf("the parent directory does not allow write");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
case EEXIST:
|
||||||
|
printf("pathname already exists");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
case ENAMETOOLONG:
|
||||||
|
printf("pathname is too long");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
default:
|
||||||
|
perror("mkdir");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Carga los recursos
|
// Carga los recursos
|
||||||
void Director::loadResources(section_t section)
|
void Director::loadResources(section_t section)
|
||||||
{
|
{
|
||||||
@@ -812,19 +971,24 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
// Indicador de éxito en la asignación
|
// Indicador de éxito en la asignación
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
if (var == "fullScreenMode")
|
if (var == "configVersion")
|
||||||
|
{
|
||||||
|
options->configVersion = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "videoMode")
|
||||||
{
|
{
|
||||||
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
||||||
{
|
{
|
||||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
options->videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
}
|
}
|
||||||
else if (value == "SDL_WINDOW_FULLSCREEN")
|
else if (value == "SDL_WINDOW_FULLSCREEN")
|
||||||
{
|
{
|
||||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN;
|
options->videoMode = SDL_WINDOW_FULLSCREEN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
options->fullScreenMode = 0;
|
options->videoMode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +1057,31 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "")
|
else if (var == "enabled")
|
||||||
|
{
|
||||||
|
options->online.enabled = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "server")
|
||||||
|
{
|
||||||
|
options->online.server = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "port")
|
||||||
|
{
|
||||||
|
if (value == "")
|
||||||
|
{
|
||||||
|
value = "0";
|
||||||
|
}
|
||||||
|
options->online.port = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "jailerID")
|
||||||
|
{
|
||||||
|
options->online.jailerID = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "" || var.substr(0, 1) == "#")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,7 +1161,15 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
int incW = 0;
|
||||||
|
int incH = 0;
|
||||||
|
if (options->borderEnabled)
|
||||||
|
{
|
||||||
|
incW = options->gameWidth * options->borderSize;
|
||||||
|
incH = options->gameHeight * options->borderSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options->console)
|
||||||
@@ -1008,7 +1204,7 @@ bool Director::initSDL()
|
|||||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
// Establece el tamaño del buffer de renderizado
|
// Establece el tamaño del buffer de renderizado
|
||||||
SDL_RenderSetLogicalSize(renderer, options->screenWidth, options->screenHeight);
|
SDL_RenderSetLogicalSize(renderer, options->gameWidth, options->gameHeight);
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
// Establece el modo de mezcla
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||||
@@ -1038,10 +1234,13 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/font/debug.png", t_font);
|
asset->add(prefix + "/data/font/debug.png", t_font);
|
||||||
asset->add(prefix + "/data/font/debug.txt", t_font);
|
asset->add(prefix + "/data/font/debug.txt", t_font);
|
||||||
|
|
||||||
// Configuración
|
// Datos
|
||||||
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
|
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
|
||||||
asset->add(prefix + "/data/config/config.txt", t_data, false);
|
|
||||||
asset->add(prefix + "/data/config/stats.txt", t_data, false);
|
// Ficheros de sistema
|
||||||
|
asset->add(systemFolder + "/config.txt", t_data, false, true);
|
||||||
|
asset->add(systemFolder + "/stats_buffer.csv", t_data, false, true);
|
||||||
|
asset->add(systemFolder + "/stats.csv", t_data, false, true);
|
||||||
|
|
||||||
// Habitaciones
|
// Habitaciones
|
||||||
asset->add(prefix + "/data/room/01.room", t_room);
|
asset->add(prefix + "/data/room/01.room", t_room);
|
||||||
@@ -1335,6 +1534,7 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/sound/jump22.wav", t_sound);
|
asset->add(prefix + "/data/sound/jump22.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/jump23.wav", t_sound);
|
asset->add(prefix + "/data/sound/jump23.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/jump24.wav", t_sound);
|
asset->add(prefix + "/data/sound/jump24.wav", t_sound);
|
||||||
|
asset->add(prefix + "/data/sound/notify.wav", t_sound);
|
||||||
|
|
||||||
// Logo
|
// Logo
|
||||||
asset->add(prefix + "/data/logo/jailgames.png", t_bitmap);
|
asset->add(prefix + "/data/logo/jailgames.png", t_bitmap);
|
||||||
@@ -1457,6 +1657,20 @@ void Director::runDemo()
|
|||||||
resource->free();
|
resource->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ejecuta la seccion en la que se solicita al usuario su ID online
|
||||||
|
void Director::runEnterID()
|
||||||
|
{
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << "\n* SECTION: ENTER_ID" << std::endl;
|
||||||
|
}
|
||||||
|
// loadResources(section);
|
||||||
|
enterID = new EnterID(renderer, screen, asset, options, section);
|
||||||
|
setSection(enterID->run());
|
||||||
|
delete enterID;
|
||||||
|
resource->free();
|
||||||
|
}
|
||||||
|
|
||||||
// Ejecuta la seccion del final del juego
|
// Ejecuta la seccion del final del juego
|
||||||
void Director::runEnding()
|
void Director::runEnding()
|
||||||
{
|
{
|
||||||
@@ -1541,6 +1755,10 @@ void Director::run()
|
|||||||
runDemo();
|
runDemo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SECTION_PROG_ENTER_ID:
|
||||||
|
runEnterID();
|
||||||
|
break;
|
||||||
|
|
||||||
case SECTION_PROG_GAME:
|
case SECTION_PROG_GAME:
|
||||||
runGame();
|
runGame();
|
||||||
break;
|
break;
|
||||||
@@ -1558,4 +1776,4 @@ void Director::run()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,13 +12,14 @@
|
|||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "credits.h"
|
#include "credits.h"
|
||||||
#include "demo.h"
|
#include "demo.h"
|
||||||
|
#include "ending.h"
|
||||||
|
#include "ending2.h"
|
||||||
|
#include "enter_id.h"
|
||||||
|
#include "game_over.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "game_over.h"
|
|
||||||
#include "ending.h"
|
|
||||||
#include "ending2.h"
|
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
#ifndef DIRECTOR_H
|
||||||
#define DIRECTOR_H
|
#define DIRECTOR_H
|
||||||
@@ -39,19 +40,24 @@ private:
|
|||||||
Intro *intro; // Objeto para gestionar la introducción del juego
|
Intro *intro; // Objeto para gestionar la introducción del juego
|
||||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
Credits *credits; // Objeto para gestionar los creditos del juego
|
||||||
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
||||||
|
EnterID *enterID; // Objeto para gestionar la sección donde se solicita el ID online al usuario
|
||||||
Ending *ending; // Objeto para gestionar el final del juego
|
Ending *ending; // Objeto para gestionar el final del juego
|
||||||
Ending2 *ending2; // Objeto para gestionar el final del juego
|
Ending2 *ending2; // Objeto para gestionar el final del juego
|
||||||
GameOver *gameOver; // Objeto para gestionar el final de la partida
|
GameOver *gameOver; // Objeto para gestionar el final de la partida
|
||||||
Debug *debug; // Objeto para getsionar la información de debug
|
Debug *debug; // Objeto para getsionar la información de debug
|
||||||
struct options_t *options; // Variable con todas las opciones del programa
|
struct options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
section_t section; // Sección y subsección actual del programa;
|
||||||
JA_Music music; // Musica del titulo
|
JA_Music music; // Musica del titulo
|
||||||
std::string executablePath; // Path del ejecutable
|
std::string executablePath; // Path del ejecutable
|
||||||
section_t section; // Sección y subsección actual del programa;
|
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
void iniOptions();
|
void initOptions();
|
||||||
|
|
||||||
|
// Inicializa los servicios online
|
||||||
|
void initOnline();
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, char *argv[]);
|
void checkProgramArguments(int argc, char *argv[]);
|
||||||
@@ -62,6 +68,9 @@ private:
|
|||||||
// Guarda el fichero de configuración
|
// Guarda el fichero de configuración
|
||||||
bool saveConfig();
|
bool saveConfig();
|
||||||
|
|
||||||
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
|
void createSystemFolder();
|
||||||
|
|
||||||
// Carga los recursos
|
// Carga los recursos
|
||||||
void loadResources(section_t section);
|
void loadResources(section_t section);
|
||||||
|
|
||||||
@@ -104,6 +113,9 @@ private:
|
|||||||
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
||||||
void runDemo();
|
void runDemo();
|
||||||
|
|
||||||
|
// Ejecuta la seccion en la que se solicita al usuario su ID online
|
||||||
|
void runEnterID();
|
||||||
|
|
||||||
// Ejecuta la seccion del final del juego
|
// Ejecuta la seccion del final del juego
|
||||||
void runEnding();
|
void runEnding();
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ void Ending::update()
|
|||||||
|
|
||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ void Ending2::update()
|
|||||||
|
|
||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
310
source/enter_id.cpp
Normal file
310
source/enter_id.cpp
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
#include "common/jail_audio.h"
|
||||||
|
#include "common/jscore.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "enter_id.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section)
|
||||||
|
{
|
||||||
|
// Copia la dirección de los objetos
|
||||||
|
this->renderer = renderer;
|
||||||
|
this->screen = screen;
|
||||||
|
this->asset = asset;
|
||||||
|
this->options = options;
|
||||||
|
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
eventHandler = new SDL_Event();
|
||||||
|
texture = new Texture(renderer, asset->get("smb2.png"));
|
||||||
|
text = new Text(asset->get("smb2.txt"), texture, renderer);
|
||||||
|
|
||||||
|
// Crea la textura para el texto que se escribe en pantalla
|
||||||
|
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
|
if (textTexture == nullptr)
|
||||||
|
{
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
counter = 0;
|
||||||
|
ticks = 0;
|
||||||
|
ticksSpeed = 15;
|
||||||
|
pos = 0;
|
||||||
|
name[pos] = 0;
|
||||||
|
maxLenght = 15;
|
||||||
|
this->section.subsection = section.subsection;
|
||||||
|
|
||||||
|
if (options->online.enabled && options->online.jailerID == "")
|
||||||
|
{
|
||||||
|
this->section.name = SECTION_PROG_ENTER_ID;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
endSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto en la textura
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
EnterID::~EnterID()
|
||||||
|
{
|
||||||
|
delete eventHandler;
|
||||||
|
delete text;
|
||||||
|
delete texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para el logo del juego
|
||||||
|
section_t EnterID::run()
|
||||||
|
{
|
||||||
|
// Detiene la música
|
||||||
|
JA_StopMusic();
|
||||||
|
|
||||||
|
while (section.name == SECTION_PROG_ENTER_ID)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void EnterID::checkEventHandler()
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que hay en la cola
|
||||||
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (eventHandler->type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// El ENTER solo se comprueba cuando se suelta, para no saltarse la siguiente sección
|
||||||
|
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
|
||||||
|
{
|
||||||
|
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
||||||
|
{
|
||||||
|
options->online.jailerID = (std::string)name;
|
||||||
|
endSection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba las teclas que se han pulsado
|
||||||
|
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
|
||||||
|
{ // Si pulsa una letra
|
||||||
|
if (pos < maxLenght)
|
||||||
|
{
|
||||||
|
name[pos++] = eventHandler->key.keysym.scancode + 61;
|
||||||
|
name[pos] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_1 && eventHandler->key.keysym.scancode <= SDL_SCANCODE_9)
|
||||||
|
{ // Si pulsa un número
|
||||||
|
if (pos < maxLenght)
|
||||||
|
{ // En ascii el '0' va antes del '1', pero en scancode el '0' va despues de '9'
|
||||||
|
name[pos++] = eventHandler->key.keysym.scancode + 19;
|
||||||
|
name[pos] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_0)
|
||||||
|
{
|
||||||
|
if (pos < maxLenght)
|
||||||
|
{
|
||||||
|
name[pos++] = 48;
|
||||||
|
name[pos] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_BACKSPACE)
|
||||||
|
{
|
||||||
|
if (pos > 0)
|
||||||
|
{
|
||||||
|
name[--pos] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F1)
|
||||||
|
{
|
||||||
|
screen->setWindowSize(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F2)
|
||||||
|
{
|
||||||
|
screen->setWindowSize(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F3)
|
||||||
|
{
|
||||||
|
screen->setWindowSize(3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F4)
|
||||||
|
{
|
||||||
|
screen->setWindowSize(4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F5)
|
||||||
|
{
|
||||||
|
switchPalette();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void EnterID::update()
|
||||||
|
{
|
||||||
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
checkEventHandler();
|
||||||
|
|
||||||
|
// Actualiza el contador
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
// Actualiza el cursor
|
||||||
|
cursor = (counter % 20 >= 10) ? " " : "_";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void EnterID::render()
|
||||||
|
{
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
screen->clean();
|
||||||
|
|
||||||
|
// Dibuja la textura con el texto en pantalla
|
||||||
|
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||||
|
|
||||||
|
// Escribe el jailerID
|
||||||
|
const std::string jailerID = (std::string)name + cursor;
|
||||||
|
const color_t color = stringToColor(options->palette, "white");
|
||||||
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa los textos
|
||||||
|
void EnterID::iniTexts()
|
||||||
|
{
|
||||||
|
texts.clear();
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"ONLINE CONFIGURATION:", stringToColor(options->palette, "red")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"YOU HAVE NOT SPECIFIED ANY ID", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"FOR THE ONLINE SERVICE", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"PLEASE ENTER AN ID OR", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"LEAVE BLANK FOR OFFLINE MODE", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"JAILER_ID:", stringToColor(options->palette, "red")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto en la textura
|
||||||
|
void EnterID::fillTexture()
|
||||||
|
{
|
||||||
|
// Inicializa los textos
|
||||||
|
iniTexts();
|
||||||
|
|
||||||
|
// Rellena la textura de texto
|
||||||
|
SDL_SetRenderTarget(renderer, textTexture);
|
||||||
|
color_t c = stringToColor(options->palette, "black");
|
||||||
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
// Escribe el texto en la textura
|
||||||
|
const int size = text->getCharacterSize();
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (auto t : texts)
|
||||||
|
{
|
||||||
|
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void EnterID::switchPalette()
|
||||||
|
{
|
||||||
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa los servicios online
|
||||||
|
void EnterID::initOnline()
|
||||||
|
{
|
||||||
|
if (options->online.jailerID == "")
|
||||||
|
{ // Jailer ID no definido
|
||||||
|
|
||||||
|
options->online.enabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Jailer ID iniciado
|
||||||
|
|
||||||
|
options->online.enabled = true;
|
||||||
|
jscore::init(options->online.server, options->online.port);
|
||||||
|
|
||||||
|
const std::string caption = options->online.jailerID + " IS LOGGED IN";
|
||||||
|
screen->showNotification(caption);
|
||||||
|
if (options->console)
|
||||||
|
{
|
||||||
|
std::cout << caption << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void EnterID::endSection()
|
||||||
|
{
|
||||||
|
initOnline();
|
||||||
|
section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
80
source/enter_id.h
Normal file
80
source/enter_id.h
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "common/asset.h"
|
||||||
|
#include "common/screen.h"
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include "common/text.h"
|
||||||
|
#include "common/texture.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef ENTER_ID_H
|
||||||
|
#define ASK_ME_H
|
||||||
|
|
||||||
|
class EnterID
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct captions_t
|
||||||
|
{
|
||||||
|
std::string label; // Texto a escribir
|
||||||
|
color_t color; // Color del texto
|
||||||
|
};
|
||||||
|
|
||||||
|
// Punteros y objetos
|
||||||
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
|
options_t *options; // Puntero a las opciones del juego
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
SDL_Texture *textTexture; // Textura para dibujar el texto
|
||||||
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
|
Texture *texture; // Textura para la fuente para el texto
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
int counter; // Contador
|
||||||
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
std::vector<captions_t> texts; // Vector con los textos
|
||||||
|
std::string cursor; // Contiene el caracter que se muestra como cursor
|
||||||
|
|
||||||
|
char name[15];
|
||||||
|
int pos;
|
||||||
|
int maxLenght; // Tamaño máximo del jailerID
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void checkEventHandler();
|
||||||
|
|
||||||
|
// Inicializa los textos
|
||||||
|
void iniTexts();
|
||||||
|
|
||||||
|
// Escribe el texto en la textura
|
||||||
|
void fillTexture();
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void switchPalette();
|
||||||
|
|
||||||
|
// Inicializa los servicios online
|
||||||
|
void initOnline();
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void endSection();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~EnterID();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
section_t run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -21,8 +21,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
this->options = options;
|
this->options = options;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
currentRoom = "48.room";
|
currentRoom = "01.room";
|
||||||
const int x1 = 18;
|
const int x1 = 25;
|
||||||
const int y1 = 13;
|
const int y1 = 13;
|
||||||
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
#endif
|
#endif
|
||||||
@@ -40,13 +40,15 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
||||||
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
|
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
|
||||||
stats = new Stats(asset->get("stats.txt"));
|
stats = new Stats(asset->get("stats.csv"), asset->get("stats_buffer.csv"), options);
|
||||||
stats->addVisit(room->getName());
|
|
||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
board.lives = 9;
|
board.lives = 9;
|
||||||
|
#ifdef DEBUG
|
||||||
|
board.lives = 0;
|
||||||
|
#endif
|
||||||
board.items = 0;
|
board.items = 0;
|
||||||
board.rooms = 1;
|
board.rooms = 1;
|
||||||
board.music = true;
|
board.music = true;
|
||||||
@@ -57,6 +59,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
blackScreen = false;
|
blackScreen = false;
|
||||||
blackScreenCounter = 0;
|
blackScreenCounter = 0;
|
||||||
totalItems = getTotalItems();
|
totalItems = getTotalItems();
|
||||||
|
initStats();
|
||||||
|
stats->addVisit(room->getName());
|
||||||
|
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
section.subsection = 0;
|
section.subsection = 0;
|
||||||
@@ -131,6 +135,10 @@ void Game::checkEventHandler()
|
|||||||
case SDL_SCANCODE_D:
|
case SDL_SCANCODE_D:
|
||||||
goToRoom(BORDER_RIGHT);
|
goToRoom(BORDER_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F6:
|
||||||
|
screen->showNotification("MAMA MIRA! SIN MANOS!");
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case SDL_SCANCODE_M:
|
case SDL_SCANCODE_M:
|
||||||
@@ -228,11 +236,15 @@ void Game::update()
|
|||||||
checkIfPlayerIsAlive();
|
checkIfPlayerIsAlive();
|
||||||
checkGameOver();
|
checkGameOver();
|
||||||
checkEndGame();
|
checkEndGame();
|
||||||
|
checkRestoringJail();
|
||||||
scoreboard->update();
|
scoreboard->update();
|
||||||
input->update();
|
input->update();
|
||||||
|
|
||||||
updateBlackScreen();
|
updateBlackScreen();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
updateDebugInfo();
|
updateDebugInfo();
|
||||||
#endif
|
#endif
|
||||||
@@ -340,7 +352,7 @@ bool Game::changeRoom(std::string file)
|
|||||||
{
|
{
|
||||||
// Incrementa el contador de habitaciones visitadas
|
// Incrementa el contador de habitaciones visitadas
|
||||||
board.rooms++;
|
board.rooms++;
|
||||||
options->rooms = board.rooms;
|
options->stats.rooms = board.rooms;
|
||||||
|
|
||||||
// Actualiza las estadisticas
|
// Actualiza las estadisticas
|
||||||
stats->addVisit(room->getName());
|
stats->addVisit(room->getName());
|
||||||
@@ -593,4 +605,36 @@ void Game::switchPause()
|
|||||||
scoreboard->pause();
|
scoreboard->pause();
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Da vidas al jugador cuando está en la Jail
|
||||||
|
void Game::checkRestoringJail()
|
||||||
|
{
|
||||||
|
if (room->getName() != "THE JAIL" || board.lives == 9)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int counter = 0;
|
||||||
|
counter++;
|
||||||
|
if (counter == 100)
|
||||||
|
{
|
||||||
|
counter = 0;
|
||||||
|
board.lives++;
|
||||||
|
JA_PlaySound(deathSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa el diccionario de las estadísticas
|
||||||
|
void Game::initStats()
|
||||||
|
{
|
||||||
|
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||||
|
rooms = resource->getAllRooms();
|
||||||
|
|
||||||
|
for (auto room : *rooms)
|
||||||
|
{
|
||||||
|
stats->addDictionary(room.room->number, room.room->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
stats->init();
|
||||||
}
|
}
|
||||||
@@ -127,6 +127,12 @@ private:
|
|||||||
// Pone el juego en pausa
|
// Pone el juego en pausa
|
||||||
void switchPause();
|
void switchPause();
|
||||||
|
|
||||||
|
// Da vidas al jugador cuando está en la Jail
|
||||||
|
void checkRestoringJail();
|
||||||
|
|
||||||
|
// Inicializa el diccionario de las estadísticas
|
||||||
|
void initStats();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);
|
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
iniFade = 310;
|
iniFade = 310;
|
||||||
fadeLenght = 20;
|
fadeLenght = 20;
|
||||||
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
|
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
|
||||||
playerSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
|
playerSprite->setPosY(30);
|
||||||
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getAnimationClip(0, 0).w - 10);
|
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getAnimationClip(0, 0).w - 10);
|
||||||
tvSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
|
tvSprite->setPosY(30);
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
@@ -73,12 +73,17 @@ void GameOver::update()
|
|||||||
// Actualiza los dos sprites
|
// Actualiza los dos sprites
|
||||||
playerSprite->update();
|
playerSprite->update();
|
||||||
tvSprite->update();
|
tvSprite->update();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el final en pantalla
|
// Dibuja el final en pantalla
|
||||||
void GameOver::render()
|
void GameOver::render()
|
||||||
{
|
{
|
||||||
|
const int y = 32;
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
@@ -86,17 +91,22 @@ void GameOver::render()
|
|||||||
screen->clean();
|
screen->clean();
|
||||||
|
|
||||||
// Escribe el texto de GAME OVER
|
// Escribe el texto de GAME OVER
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - 40, "G A M E O V E R", 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y, "G A M E O V E R", 1, color);
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
|
playerSprite->setPosY(y + 30);
|
||||||
|
tvSprite->setPosY(y + 30);
|
||||||
renderSprites();
|
renderSprites();
|
||||||
|
|
||||||
// Escribe el texto con las habitaciones y los items
|
// Escribe el texto con las habitaciones y los items
|
||||||
const std::string itemsTxt = std::to_string(options->items / 100) + std::to_string((options->items % 100) / 10) + std::to_string(options->items % 10);
|
const std::string itemsTxt = std::to_string(options->stats.items / 100) + std::to_string((options->stats.items % 100) / 10) + std::to_string(options->stats.items % 10);
|
||||||
const std::string roomsTxt = std::to_string(options->rooms / 100) + std::to_string((options->rooms % 100) / 10) + std::to_string(options->rooms % 10);
|
const std::string roomsTxt = std::to_string(options->stats.rooms / 100) + std::to_string((options->stats.rooms % 100) / 10) + std::to_string(options->stats.rooms % 10);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 40, "ITEMS: " + itemsTxt, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 55, "ROOMS: " + roomsTxt, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
|
||||||
|
|
||||||
|
// Escribe el texto con "Tu peor pesadilla"
|
||||||
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
|
||||||
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options->stats.worstNightmare, 1, color);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
|
|||||||
@@ -251,6 +251,9 @@ void Intro::update()
|
|||||||
// Gestiona el contador de carga
|
// Gestiona el contador de carga
|
||||||
updateLoad();
|
updateLoad();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
|
|
||||||
// Comprueba si ha terminado la intro
|
// Comprueba si ha terminado la intro
|
||||||
if (loadCounter >= 768)
|
if (loadCounter >= 768)
|
||||||
{
|
{
|
||||||
@@ -281,7 +284,7 @@ void Intro::render()
|
|||||||
section_t Intro::run()
|
section_t Intro::run()
|
||||||
{
|
{
|
||||||
// Inicia el sonido de carga
|
// Inicia el sonido de carga
|
||||||
JA_SetVolume(64);
|
JA_SetVolume(64);
|
||||||
JA_PlayMusic(loadingSound1);
|
JA_PlayMusic(loadingSound1);
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_INTRO)
|
while (section.name == SECTION_PROG_INTRO)
|
||||||
@@ -290,7 +293,7 @@ section_t Intro::run()
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_SetVolume(128);
|
JA_SetVolume(128);
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
|
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
|
||||||
texture2->setColor(0, 0, 0);
|
texture2->setColor(0, 0, 0);
|
||||||
|
|
||||||
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < texture->getHeight(); ++i)
|
for (int i = 0; i < texture->getHeight(); ++i)
|
||||||
{
|
{
|
||||||
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
|
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
|
||||||
|
sprite.back()->setSpriteClip(0, i, texture->getWidth(), 1);
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
{
|
{
|
||||||
sprite.at(i)->setPosX(256 + (i * 3));
|
sprite.at(i)->setPosX(256 + (i * 3));
|
||||||
@@ -80,12 +82,11 @@ void Logo::checkEventHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las teclas que se han pulsado
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
switch (eventHandler->key.keysym.scancode)
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
case SDL_SCANCODE_ESCAPE:
|
||||||
//std::cout << "PULSADO ESCAPE" << std::endl;
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
section.name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -124,8 +125,8 @@ void Logo::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
section.name = SECTION_PROG_TITLE;
|
section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||||
section.subsection = 0;
|
endSection();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,19 +263,13 @@ void Logo::update()
|
|||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
updateTextureColors();
|
updateTextureColors();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
if (counter == endLogo + postLogo)
|
if (counter == endLogo + postLogo)
|
||||||
{
|
{
|
||||||
if (section.subsection == SUBSECTION_LOGO_TO_INTRO)
|
endSection();
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_INTRO;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,12 +312,11 @@ section_t Logo::run()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Logo::switchPalette()
|
void Logo::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->palette == p_zxspectrum)
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
{
|
}
|
||||||
options->palette = p_zxarne;
|
|
||||||
}
|
// Termina la sección
|
||||||
else
|
void Logo::endSection()
|
||||||
{
|
{
|
||||||
options->palette = p_zxspectrum;
|
section.name = SECTION_PROG_ENTER_ID;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,9 @@ private:
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void switchPalette();
|
void switchPalette();
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void endSection();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);
|
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);
|
||||||
|
|||||||
@@ -823,6 +823,8 @@ void Player::setState(state_e value)
|
|||||||
{
|
{
|
||||||
prevState = state;
|
prevState = state;
|
||||||
state = value;
|
state = value;
|
||||||
|
|
||||||
|
checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el jugador esta vivo
|
// Comprueba si el jugador esta vivo
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
room.itemColor2 = "magenta";
|
room.itemColor2 = "magenta";
|
||||||
room.autoSurfaceDirection = 1;
|
room.autoSurfaceDirection = 1;
|
||||||
|
|
||||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
room.number = fileName.substr(0, fileName.find_last_of("."));
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
@@ -94,7 +96,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (line != "[/enemy]");
|
} while (line != "[/enemy]");
|
||||||
@@ -123,7 +125,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +145,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +154,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Room loaded: " << filename.c_str() << std::endl;
|
std::cout << "Room loaded: " << fileName.c_str() << std::endl;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@@ -160,7 +162,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
std::cout << "Warning: Unable to open " << fileName.c_str() << " file" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +402,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
this->debug = debug;
|
this->debug = debug;
|
||||||
this->options = options;
|
this->options = options;
|
||||||
|
|
||||||
|
number = room->number;
|
||||||
name = room->name;
|
name = room->name;
|
||||||
bgColor = room->bgColor;
|
bgColor = room->bgColor;
|
||||||
borderColor = room->borderColor;
|
borderColor = room->borderColor;
|
||||||
@@ -824,7 +827,7 @@ bool Room::itemCollision(SDL_Rect &rect)
|
|||||||
items.erase(items.begin() + i);
|
items.erase(items.begin() + i);
|
||||||
JA_PlaySound(itemSound);
|
JA_PlaySound(itemSound);
|
||||||
*itemsPicked = *itemsPicked + 1;
|
*itemsPicked = *itemsPicked + 1;
|
||||||
options->items = *itemsPicked;
|
options->stats.items = *itemsPicked;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct aTile_t
|
|||||||
|
|
||||||
struct room_t
|
struct room_t
|
||||||
{
|
{
|
||||||
|
std::string number; // Numero de la habitación
|
||||||
std::string name; // Nombre de la habitación
|
std::string name; // Nombre de la habitación
|
||||||
std::string bgColor; // Color de fondo de la habitación
|
std::string bgColor; // Color de fondo de la habitación
|
||||||
std::string borderColor; // Color del borde de la pantalla
|
std::string borderColor; // Color del borde de la pantalla
|
||||||
@@ -89,6 +90,7 @@ private:
|
|||||||
options_t *options; // Puntero a las opciones del juego
|
options_t *options; // Puntero a las opciones del juego
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
std::string number; // Numero de la habitación
|
||||||
std::string name; // Nombre de la habitación
|
std::string name; // Nombre de la habitación
|
||||||
std::string bgColor; // Color de fondo de la habitación
|
std::string bgColor; // Color de fondo de la habitación
|
||||||
std::string borderColor; // Color del borde de la pantalla
|
std::string borderColor; // Color del borde de la pantalla
|
||||||
|
|||||||
218
source/stats.cpp
218
source/stats.cpp
@@ -1,31 +1,66 @@
|
|||||||
|
#include "common/jscore.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include <iostream>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Stats::Stats(std::string file)
|
Stats::Stats(std::string file, std::string buffer, options_t *options)
|
||||||
{
|
{
|
||||||
|
this->options = options;
|
||||||
|
bufferPath = buffer;
|
||||||
filePath = file;
|
filePath = file;
|
||||||
|
bufferList.clear();
|
||||||
list.clear();
|
list.clear();
|
||||||
loadFromFile();
|
dictionary.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Stats::~Stats()
|
Stats::~Stats()
|
||||||
{
|
{
|
||||||
saveToFile();
|
// Vuelca los datos del buffer en la lista de estadisticas
|
||||||
|
updateListFromBuffer();
|
||||||
|
|
||||||
|
// Calcula cual es la habitación con más muertes
|
||||||
|
checkWorstNightmare();
|
||||||
|
|
||||||
|
// Guarda las estadísticas
|
||||||
|
saveToServer();
|
||||||
|
saveToFile(bufferPath, bufferList);
|
||||||
|
saveToFile(filePath, list);
|
||||||
|
|
||||||
|
bufferList.clear();
|
||||||
list.clear();
|
list.clear();
|
||||||
|
dictionary.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
// Se debe llamar a este procediiento una vez se haya creado el diccionario numero-nombre
|
||||||
|
void Stats::init()
|
||||||
|
{
|
||||||
|
loadFromFile(bufferPath, bufferList);
|
||||||
|
loadFromFile(filePath, list);
|
||||||
|
if (options->online.enabled)
|
||||||
|
{
|
||||||
|
loadFromServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca los datos del buffer en la lista de estadisticas
|
||||||
|
updateListFromBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade una muerte a las estadisticas
|
// Añade una muerte a las estadisticas
|
||||||
void Stats::addDeath(std::string name)
|
void Stats::addDeath(std::string name)
|
||||||
{
|
{
|
||||||
|
// Normaliza el nombre
|
||||||
|
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||||
|
|
||||||
// Primero busca si ya hay una entrada con ese nombre
|
// Primero busca si ya hay una entrada con ese nombre
|
||||||
const int index = findByName(name);
|
const int index = findByName(name, bufferList);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
list.at(index).died++;
|
bufferList.at(index).died++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// En caso contrario crea la entrada
|
// En caso contrario crea la entrada
|
||||||
@@ -35,18 +70,21 @@ void Stats::addDeath(std::string name)
|
|||||||
item.name = name;
|
item.name = name;
|
||||||
item.visited = 0;
|
item.visited = 0;
|
||||||
item.died = 1;
|
item.died = 1;
|
||||||
list.push_back(item);
|
bufferList.push_back(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade una visita a las estadisticas
|
// Añade una visita a las estadisticas
|
||||||
void Stats::addVisit(std::string name)
|
void Stats::addVisit(std::string name)
|
||||||
{
|
{
|
||||||
|
// Normaliza el nombre
|
||||||
|
// std::replace(name.begin(), name.end(), ' ', '_');
|
||||||
|
|
||||||
// Primero busca si ya hay una entrada con ese nombre
|
// Primero busca si ya hay una entrada con ese nombre
|
||||||
const int index = findByName(name);
|
const int index = findByName(name, bufferList);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
list.at(index).visited++;
|
bufferList.at(index).visited++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// En caso contrario crea la entrada
|
// En caso contrario crea la entrada
|
||||||
@@ -56,12 +94,12 @@ void Stats::addVisit(std::string name)
|
|||||||
item.name = name;
|
item.name = name;
|
||||||
item.visited = 1;
|
item.visited = 1;
|
||||||
item.died = 0;
|
item.died = 0;
|
||||||
list.push_back(item);
|
bufferList.push_back(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Busca una entrada en la lista por nombre
|
// Busca una entrada en la lista por nombre
|
||||||
int Stats::findByName(std::string name)
|
int Stats::findByName(std::string name, std::vector<stats_t> &list)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
@@ -78,8 +116,10 @@ int Stats::findByName(std::string name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las estadisticas desde un fichero
|
// Carga las estadisticas desde un fichero
|
||||||
bool Stats::loadFromFile()
|
bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||||
{
|
{
|
||||||
|
list.clear();
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
@@ -123,20 +163,68 @@ bool Stats::loadFromFile()
|
|||||||
// El fichero no existe
|
// El fichero no existe
|
||||||
else
|
else
|
||||||
{ // Crea el fichero con los valores por defecto
|
{ // Crea el fichero con los valores por defecto
|
||||||
saveToFile();
|
saveToFile(filePath, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga las estadisticas desde un servidor
|
||||||
|
void Stats::loadFromServer()
|
||||||
|
{
|
||||||
|
// Limpia los datos del servidor
|
||||||
|
// eraseServerData();
|
||||||
|
|
||||||
|
list.clear();
|
||||||
|
|
||||||
|
std::string data;
|
||||||
|
if (options->online.enabled)
|
||||||
|
{
|
||||||
|
data = jscore::getUserData(options->online.gameID, options->online.jailerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream ss(data);
|
||||||
|
std::string tmp;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < (int)data.size(); ++i)
|
||||||
|
{
|
||||||
|
if (data[i] == ';')
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (count > 0)
|
||||||
|
{
|
||||||
|
stats_t stat;
|
||||||
|
|
||||||
|
// Obtiene el nombre
|
||||||
|
getline(ss, tmp, ';');
|
||||||
|
stat.name = numberToName(tmp);
|
||||||
|
|
||||||
|
// Obtiene las visitas
|
||||||
|
getline(ss, tmp, ';');
|
||||||
|
stat.visited = std::stoi(tmp);
|
||||||
|
|
||||||
|
// Obtiene las muertes
|
||||||
|
getline(ss, tmp, ';');
|
||||||
|
stat.died = std::stoi(tmp);
|
||||||
|
|
||||||
|
list.push_back(stat);
|
||||||
|
count = count - 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Guarda las estadisticas en un fichero
|
// Guarda las estadisticas en un fichero
|
||||||
void Stats::saveToFile()
|
void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||||
{
|
{
|
||||||
// Crea y abre el fichero de texto
|
// Crea y abre el fichero de texto
|
||||||
std::ofstream file(filePath);
|
std::ofstream file(filePath);
|
||||||
|
|
||||||
// Escribe en el fichero
|
// Escribe en el fichero
|
||||||
file << "# NOMBRE DE LA HABITACION;VISITAS;MUERTES" << std::endl;
|
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||||
for (auto item : list)
|
for (auto item : list)
|
||||||
{
|
{
|
||||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||||
@@ -144,4 +232,104 @@ void Stats::saveToFile()
|
|||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
file.close();
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guarda las estadisticas en un servidor
|
||||||
|
void Stats::saveToServer()
|
||||||
|
{
|
||||||
|
std::string data = "";
|
||||||
|
if (options->online.enabled)
|
||||||
|
{
|
||||||
|
for (auto item : list)
|
||||||
|
{
|
||||||
|
data = data + nameToNumber(item.name) + ";" + std::to_string(item.visited) + ";" + std::to_string(item.died) + ";";
|
||||||
|
}
|
||||||
|
jscore::setUserData(options->online.gameID, options->online.jailerID, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcula cual es la habitación con más muertes
|
||||||
|
void Stats::checkWorstNightmare()
|
||||||
|
{
|
||||||
|
int deaths = 0;
|
||||||
|
for (auto item : list)
|
||||||
|
{
|
||||||
|
if (item.died > deaths)
|
||||||
|
{
|
||||||
|
deaths = item.died;
|
||||||
|
options->stats.worstNightmare = item.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade una entrada al diccionario
|
||||||
|
void Stats::addDictionary(std::string number, std::string name)
|
||||||
|
{
|
||||||
|
dictionary.push_back({number, name});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el nombre de una habitación a partir del número
|
||||||
|
std::string Stats::numberToName(std::string number)
|
||||||
|
{
|
||||||
|
for (auto l : dictionary)
|
||||||
|
{
|
||||||
|
if (l.number == number)
|
||||||
|
{
|
||||||
|
return l.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el número de una habitación a partir del nombre
|
||||||
|
std::string Stats::nameToNumber(std::string name)
|
||||||
|
{
|
||||||
|
for (auto l : dictionary)
|
||||||
|
{
|
||||||
|
if (l.name == name)
|
||||||
|
{
|
||||||
|
return l.number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca los datos del buffer en la lista de estadisticas
|
||||||
|
void Stats::updateListFromBuffer()
|
||||||
|
{
|
||||||
|
// Actualiza list desde bufferList
|
||||||
|
for (auto buffer : bufferList)
|
||||||
|
{
|
||||||
|
int index = findByName(buffer.name, list);
|
||||||
|
|
||||||
|
if (index != -1)
|
||||||
|
{ // Encontrado. Aumenta sus estadisticas
|
||||||
|
list.at(index).visited += buffer.visited;
|
||||||
|
list.at(index).died += buffer.died;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // En caso contrario crea la entrada
|
||||||
|
stats_t item;
|
||||||
|
item.name = buffer.name;
|
||||||
|
item.visited = buffer.visited;
|
||||||
|
item.died = buffer.died;
|
||||||
|
list.push_back(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sube los datos al servidor
|
||||||
|
if (options->online.enabled)
|
||||||
|
{
|
||||||
|
saveToServer();
|
||||||
|
bufferList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveToFile(bufferPath, bufferList);
|
||||||
|
saveToFile(filePath, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limpia los datos del servidor
|
||||||
|
void Stats::eraseServerData()
|
||||||
|
{
|
||||||
|
jscore::setUserData(options->online.gameID, options->online.jailerID, "");
|
||||||
}
|
}
|
||||||
@@ -7,41 +7,81 @@
|
|||||||
#ifndef STATS_H
|
#ifndef STATS_H
|
||||||
#define STATS_H
|
#define STATS_H
|
||||||
|
|
||||||
struct stats_t
|
|
||||||
{
|
|
||||||
std::string name; // Nombre de la habitación donde se encuentra el objeto
|
|
||||||
int visited; // Cuenta las veces que se ha visitado una habitación
|
|
||||||
int died; // Cuenta las veces que se ha muerto en una habitación
|
|
||||||
};
|
|
||||||
|
|
||||||
class Stats
|
class Stats
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
struct stats_t
|
||||||
|
{
|
||||||
|
std::string name; // Nombre de la habitación
|
||||||
|
int visited; // Cuenta las veces que se ha visitado una habitación
|
||||||
|
int died; // Cuenta las veces que se ha muerto en una habitación
|
||||||
|
};
|
||||||
|
|
||||||
|
struct stats_dictionary_t
|
||||||
|
{
|
||||||
|
std::string number; // Numero de la habitación
|
||||||
|
std::string name; // Nombre de la habitación
|
||||||
|
};
|
||||||
|
|
||||||
|
// Punteros y objetos
|
||||||
|
options_t *options;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<stats_t> list; // Lista con las estadisticas por habitación
|
std::vector<stats_dictionary_t> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
||||||
std::string filePath; // Fichero con las estadísticas
|
std::vector<stats_t> bufferList; // Lista con las estadisticas temporales por habitación
|
||||||
|
std::vector<stats_t> list; // Lista con las estadisticas completas por habitación
|
||||||
|
std::string bufferPath; // Fichero con las estadísticas temporales
|
||||||
|
std::string filePath; // Fichero con las estadísticas completas
|
||||||
|
|
||||||
// Busca una entrada en la lista por nombre
|
// Busca una entrada en la lista por nombre
|
||||||
int findByName(std::string name);
|
int findByName(std::string name, std::vector<stats_t> &list);
|
||||||
|
|
||||||
// Carga las estadisticas desde un fichero
|
// Carga las estadisticas desde un fichero
|
||||||
bool loadFromFile();
|
bool loadFromFile(std::string filePath, std::vector<stats_t> &list);
|
||||||
|
|
||||||
|
// Carga las estadisticas desde un servidor
|
||||||
|
void loadFromServer();
|
||||||
|
|
||||||
// Guarda las estadisticas en un fichero
|
// Guarda las estadisticas en un fichero
|
||||||
void saveToFile();
|
void saveToFile(std::string filePath, std::vector<stats_t> &list);
|
||||||
|
|
||||||
|
// Guarda las estadisticas en un servidor
|
||||||
|
void saveToServer();
|
||||||
|
|
||||||
|
// Calcula cual es la habitación con más muertes
|
||||||
|
void checkWorstNightmare();
|
||||||
|
|
||||||
|
// Obtiene el nombre de una habitación a partir del número
|
||||||
|
std::string numberToName(std::string number);
|
||||||
|
|
||||||
|
// Obtiene el número de una habitación a partir del nombre
|
||||||
|
std::string nameToNumber(std::string name);
|
||||||
|
|
||||||
|
// Vuelca los datos del buffer en la lista de estadisticas
|
||||||
|
void updateListFromBuffer();
|
||||||
|
|
||||||
|
// Limpia los datos del servidor
|
||||||
|
void eraseServerData();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Stats(std::string file);
|
Stats(std::string file, std::string buffer, options_t *options);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Stats();
|
~Stats();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
// Se debe llamar a este procediiento una vez se haya creado el diccionario numero-nombre
|
||||||
|
void init();
|
||||||
|
|
||||||
// Añade una muerte a las estadisticas
|
// Añade una muerte a las estadisticas
|
||||||
void addDeath(std::string name);
|
void addDeath(std::string name);
|
||||||
|
|
||||||
// Añade una visita a las estadisticas
|
// Añade una visita a las estadisticas
|
||||||
void addVisit(std::string name);
|
void addVisit(std::string name);
|
||||||
|
|
||||||
|
// Añade una entrada al diccionario
|
||||||
|
void addDictionary(std::string number, std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -115,6 +115,12 @@ void Title::checkEventHandler()
|
|||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
case SDL_SCANCODE_F6:
|
||||||
|
screen->showNotification("MAMA MIRA! SIN MANOS!");
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -176,6 +182,9 @@ void Title::update()
|
|||||||
// Actualiza la marquesina
|
// Actualiza la marquesina
|
||||||
updateMarquee();
|
updateMarquee();
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
|
|
||||||
// Comprueba si ha terminado la marquesina y acaba con el titulo
|
// Comprueba si ha terminado la marquesina y acaba con el titulo
|
||||||
if (letters.at(letters.size() - 1).x < -10)
|
if (letters.at(letters.size() - 1).x < -10)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user