Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e73a3159f | |||
| cf19194e7a | |||
| 8a43e7cd65 | |||
| 370120345e | |||
| 134b679a75 | |||
| 788aec0dab | |||
| a08da3b983 | |||
| 62a61ecad4 | |||
| 2e6436cc4e | |||
| 7c50cc00fa | |||
| 8f5d56af7f | |||
| 424c243ffc | |||
| 78f858831f | |||
| d3e031e8b5 | |||
| 4792e4f91d | |||
| e1801a9255 | |||
| f0d9e39bb1 | |||
| eb94a17f26 | |||
| ea5c2c15d6 | |||
| ff7170934e | |||
| 1c1762f6b1 | |||
| ee8c075213 | |||
| 958e9f7f75 | |||
| 8fda06e232 | |||
| fb2ffd58ee | |||
| 3f183a5489 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
|
build/
|
||||||
data/config/config.txt
|
data/config/config.txt
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
thumbs.db
|
thumbs.db
|
||||||
@@ -12,3 +13,8 @@ thumbs.db
|
|||||||
*config.bin
|
*config.bin
|
||||||
*score.bin
|
*score.bin
|
||||||
coffee_crisis*
|
coffee_crisis*
|
||||||
|
SDL2.dll
|
||||||
|
libwinpthread-1.dll
|
||||||
|
libstdc++-6.dll
|
||||||
|
libgcc_s_seh-1.dll
|
||||||
|
linux_utils/
|
||||||
71
CMakeLists.txt
Normal file
71
CMakeLists.txt
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# CMakeLists.txt
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(coffee_crisis VERSION 1.00)
|
||||||
|
|
||||||
|
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||||
|
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
|
set(CMAKE_CXX_COMPILER "g++")
|
||||||
|
set(CMAKE_C_COMPILER "gcc")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Establecer estándar de C++
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
# Configuración global de flags de compilación
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -ffunction-sections -fdata-sections")
|
||||||
|
|
||||||
|
# Define el directorio de los archivos fuente
|
||||||
|
set(DIR_SOURCES "${CMAKE_SOURCE_DIR}/source")
|
||||||
|
|
||||||
|
# Cargar todos los archivos fuente en DIR_SOURCES
|
||||||
|
file(GLOB SOURCES "${DIR_SOURCES}/*.cpp")
|
||||||
|
|
||||||
|
# Verificar si se encontraron archivos fuente
|
||||||
|
if(NOT SOURCES)
|
||||||
|
message(FATAL_ERROR "No se encontraron archivos fuente en ${DIR_SOURCES}. Verifica que el directorio existe y contiene archivos .cpp.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configuración de SDL2
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
if(SDL2_FOUND)
|
||||||
|
message(STATUS "SDL2 encontrado: ${SDL2_INCLUDE_DIRS}")
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS})
|
||||||
|
link_directories(${SDL2_LIBDIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "SDL2 no encontrado")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Incluye rutas de SDL2 obtenidas con pkg-config
|
||||||
|
include_directories(/usr/local/include /usr/local/include/SDL2)
|
||||||
|
link_directories(/usr/local/lib)
|
||||||
|
|
||||||
|
# Definir las bibliotecas comunes
|
||||||
|
set(LIBS SDL2)
|
||||||
|
|
||||||
|
# Configuración común de salida de ejecutables en el directorio raíz
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
# Añadir ejecutable principal
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
# Añadir definiciones de compilación dependiendo del tipo de build
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:DEBUG VERBOSE>)
|
||||||
|
|
||||||
|
# Enlazar bibliotecas
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||||
|
|
||||||
|
# Configuración específica para cada plataforma
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE WINDOWS_BUILD)
|
||||||
|
target_link_libraries(${PROJECT_NAME} mingw32 gdi32 winmm imm32 ole32 version)
|
||||||
|
elseif(APPLE)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD)
|
||||||
|
# Configurar compilación para Apple Silicon
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "arm64")
|
||||||
|
elseif(UNIX AND NOT APPLE)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD)
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||||
|
endif()
|
||||||
29
Makefile
29
Makefile
@@ -1,8 +1,9 @@
|
|||||||
executable = coffee_crisis
|
executable = coffee_crisis
|
||||||
source = source/*.cpp source/common/*.cpp
|
source = source/*.cpp
|
||||||
appName = Coffee Crisis
|
appName = Coffee Crisis
|
||||||
releaseFolder = cc_release
|
releaseFolder = cc_release
|
||||||
version = v2.3
|
version = v2.3.2
|
||||||
|
resource_file = release/coffee.res
|
||||||
|
|
||||||
# Release names
|
# Release names
|
||||||
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||||
@@ -10,14 +11,18 @@ macosIntelRelease = $(executable)-$(version)-macos-intel.dmg
|
|||||||
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
|
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
|
||||||
linuxRelease = $(executable)-$(version)-linux.tar.gz
|
linuxRelease = $(executable)-$(version)-linux.tar.gz
|
||||||
|
|
||||||
|
# Specify the C++ standard
|
||||||
|
cpp_standard = c++20
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
@echo off
|
||||||
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"
|
windres release/coffee.rc -O coff -o $(resource_file)
|
||||||
|
g++ $(source) $(resource_file) -std=$(cpp_standard) -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:
|
windows_debug:
|
||||||
@echo off
|
@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"
|
g++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -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
|
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
|
||||||
|
|
||||||
windows_release:
|
windows_release:
|
||||||
@@ -36,7 +41,7 @@ windows_release:
|
|||||||
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
|
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
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"
|
g++ $(source) $(resource_file) -std=$(cpp_standard) -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,10 +52,10 @@ windows_release:
|
|||||||
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
||||||
|
|
||||||
macos_debug:
|
macos_debug:
|
||||||
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
clang++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
||||||
|
|
||||||
macos_release:
|
macos_release:
|
||||||
# Remove data and possible data from previous builds
|
# Remove data and possible data from previous builds
|
||||||
@@ -81,7 +86,7 @@ macos_release:
|
|||||||
ln -s /Applications "$(releaseFolder)"/Applications
|
ln -s /Applications "$(releaseFolder)"/Applications
|
||||||
|
|
||||||
# Build INTEL
|
# Build INTEL
|
||||||
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||||
|
|
||||||
# Build INTEL DMG
|
# Build INTEL DMG
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
@@ -89,7 +94,7 @@ macos_release:
|
|||||||
rm -f tmp.dmg
|
rm -f tmp.dmg
|
||||||
|
|
||||||
# Build APPLE SILICON
|
# Build APPLE SILICON
|
||||||
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
||||||
|
|
||||||
# Build APPLE SILICON DMG
|
# Build APPLE SILICON DMG
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
@@ -101,11 +106,11 @@ macos_release:
|
|||||||
rm -rdf "$(releaseFolder)"
|
rm -rdf "$(releaseFolder)"
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
||||||
|
|
||||||
linux_debug:
|
linux_debug:
|
||||||
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
g++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
||||||
|
|
||||||
linux_release:
|
linux_release:
|
||||||
@@ -121,7 +126,7 @@ linux_release:
|
|||||||
cp README.md "$(releaseFolder)"
|
cp README.md "$(releaseFolder)"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
g++ $(source) -std=$(cpp_standard) -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
|
||||||
|
|||||||
45
README.md
45
README.md
@@ -1,35 +1,34 @@
|
|||||||
# Coffee Crisis
|
# Coffee Crisis
|
||||||
|
|
||||||
Coffee Crisis es un juego arcade que pondrá a prueba tus reflejos. Empezado durante el verano de 2020 y terminado un año despues, en el verano de 2021. Intenta conseguir todos los puntos que puedas con una sola vida a traves de los 10 niveles de juego y ayuda a Bal1 a defender la UPV de la invasión de la cafeína esférica y saltarina.
|
Coffee Crisis és un joc arcade que posarà a prova els teus reflexos. Començat durant l'estiu de 2020 i acabat un any després a l'estiu de 2021. Intenta aconseguir tots els punts que pugues amb una sola vida a través dels 10 nivells de joc i ajuda a Bal1 a defensar la UPV de la invasió de la cafeïna esfèrica i saltarina.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Teclado
|
## Teclat
|
||||||
El juego se maneja con teclado, aunque tambien se puede conectar un mando de control.
|
|
||||||
Las teclas son las siguientes:
|
|
||||||
|
|
||||||
* **Cursores**: Mover al personaje, moverse por los menus
|
El joc es maneja amb teclat, encara que també es pot connectar un comandament de control.
|
||||||
* **Q, W, E**: Disparar a la izquierda, al centro y a la derecha respectivamente
|
Les tecles són les següents:
|
||||||
* **ESCAPE**: Pone en pausa el juego durante la partida. Sale de los menus. Cierra el juego
|
* **Fletxes**: Moure el personatge, moure's pels menús
|
||||||
* **ENTER**: Acepta las opciones en los menus
|
* **Q, W, E**: Disparar a l'esquerra, al centre i a la dreta respectivament
|
||||||
|
* **ESCAPE**: Posa en pausa el joc durant la partida. Surt dels menús. Tanca el joc
|
||||||
|
* **ENTER**: Accepta les opcions en els menús
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Compilar
|
## Compilar
|
||||||
|
|
||||||
Para compilar el código se necesitan tener las librerías SDL instaladas en el sistema y el compilador g++.
|
Per compilar el codi cal tindre les biblioteques SDL instal·lades al sistema i el compilador g++.
|
||||||
|
|
||||||
En Linux:
|
En Linux:
|
||||||
```bash
|
```bash
|
||||||
sudo apt install libsdl2-dev g++
|
sudo apt install libsdl2-dev g++
|
||||||
```
|
```
|
||||||
|
|
||||||
En macOS se pueden instalar fácilmente con [brew](https://brew.sh):
|
En macOS es poden instal·lar fàcilment amb [brew](https://brew.sh):
|
||||||
```bash
|
```bash
|
||||||
brew install sdl2 g++
|
brew install sdl2 g++
|
||||||
```
|
```
|
||||||
|
|
||||||
Una vez instaladas las librerías SDL, se puede compilar utilizando el fichero Makefile suministrado.
|
Un cop instal·lades les biblioteques SDL, es pot compilar utilitzant el fitxer Makefile subministrat.
|
||||||
|
|
||||||
En Linux:
|
En Linux:
|
||||||
```bash
|
```bash
|
||||||
@@ -40,11 +39,11 @@ En macOS:
|
|||||||
```bash
|
```bash
|
||||||
make macos
|
make macos
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
## Como ejecutar
|
## Com executar
|
||||||
|
|
||||||
Para ejecutar el juego hay que escribir en la terminal la orden que se muestra a continuación.
|
Per executar el joc cal escriure a la terminal l'ordre que es mostra a continuació.
|
||||||
|
|
||||||
En Linux:
|
En Linux:
|
||||||
```bash
|
```bash
|
||||||
@@ -56,12 +55,12 @@ En macOS:
|
|||||||
./coffee_crisis_macos
|
./coffee_crisis_macos
|
||||||
```
|
```
|
||||||
|
|
||||||
En macOS tambien puedes hacer doble click sobre el archivo coffee_crisis_macos
|
En macOS també pots fer doble clic sobre l'arxiu coffee_crisis_macos
|
||||||
|
|
||||||
## Agradecimientos
|
## Agraïments
|
||||||
A los jailers y a la jail. Y entre ellos, a JailDoctor por estar siempre ahí apoyándonos/obligándonos a sacar un Jailgame más.
|
Als jailers i a la jail. I entre ells, a JailDoctor per estar sempre donant-nos suport/obligant-nos a traure un Jailgame més.
|
||||||
|
|
||||||
Y por supuesto a ti por estar aquí.
|
I per descomptat a tu per estar aquí.
|
||||||
|
|
||||||
## Licencia
|
## Llicència
|
||||||
Usa el código para lo que quieras: aprender, reirte, curiosear... excepto para sacar beneficio económico. Si lo consigues, por favor avísame y vamos a medias.
|
Utilitza el codi per a el que vulgues: aprendre, riure't, tafanejar... excepte per treure'n benefici econòmic. Si ho aconsegueixes, si us plau avisa'm i anem a mitges.
|
||||||
@@ -101,18 +101,7 @@ line=true
|
|||||||
|
|
||||||
[item]
|
[item]
|
||||||
text=HOW TO PLAY
|
text=HOW TO PLAY
|
||||||
hPaddingDown=2
|
hPaddingDown=10
|
||||||
[/item]
|
|
||||||
|
|
||||||
[item]
|
|
||||||
text=HISCORE TABLE
|
|
||||||
hPaddingDown=2
|
|
||||||
[/item]
|
|
||||||
|
|
||||||
[item]
|
|
||||||
text=JAILERID:
|
|
||||||
hPaddingDown=6
|
|
||||||
line=true
|
|
||||||
[/item]
|
[/item]
|
||||||
|
|
||||||
[item]
|
[item]
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
@@ -21,11 +21,11 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>2.2a</string>
|
<string>2.3.2</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>2.3</string>
|
<string>2.3.2</string>
|
||||||
<key>CSResourcesFileMapped</key>
|
<key>CSResourcesFileMapped</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
1
release/coffee.rc
Normal file
1
release/coffee.rc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
id ICON "icon.ico"
|
||||||
BIN
release/coffee.res
Normal file
BIN
release/coffee.res
Normal file
Binary file not shown.
BIN
release/icon.ico
Normal file
BIN
release/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
@@ -1,4 +1,8 @@
|
|||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
|
||||||
|
#include <iostream> // for cout
|
||||||
|
#include <sstream> // for basic_stringstream
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "movingsprite.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <fstream>
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include <iostream>
|
#include <string> // for string, basic_string
|
||||||
#include <sstream>
|
#include <vector> // for vector
|
||||||
#include <string>
|
#include "movingsprite.h" // for MovingSprite
|
||||||
#include <vector>
|
class Texture;
|
||||||
|
|
||||||
#ifndef ANIMATEDSPRITE_H
|
|
||||||
#define ANIMATEDSPRITE_H
|
|
||||||
|
|
||||||
struct animation_t
|
struct animation_t
|
||||||
{
|
{
|
||||||
@@ -99,5 +96,3 @@ public:
|
|||||||
// Reinicia la animación
|
// Reinicia la animación
|
||||||
void resetAnimation();
|
void resetAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
||||||
|
#include <stddef.h> // for size_t
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Asset::Asset(std::string executablePath)
|
Asset::Asset(std::string executablePath)
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <string> // for string, basic_string
|
||||||
#include <string>
|
#include <vector> // for vector
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef ASSET_H
|
|
||||||
#define ASSET_H
|
|
||||||
|
|
||||||
enum assetType
|
enum assetType
|
||||||
{
|
{
|
||||||
@@ -62,5 +58,3 @@ public:
|
|||||||
// Establece si ha de mostrar texto por pantalla
|
// Establece si ha de mostrar texto por pantalla
|
||||||
void setVerbose(bool value);
|
void setVerbose(bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
|
#include <math.h> // for abs
|
||||||
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
|
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_AR...
|
||||||
|
#include "movingsprite.h" // for MovingSprite
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
||||||
|
|||||||
@@ -1,72 +1,71 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||||
#include "common/utils.h"
|
#include <string> // for string
|
||||||
#include <sstream>
|
#include <vector> // for vector
|
||||||
#include <vector>
|
#include "utils.h" // for circle_t
|
||||||
|
class AnimatedSprite;
|
||||||
#ifndef BALLOON_H
|
class Texture;
|
||||||
#define BALLOON_H
|
|
||||||
|
|
||||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||||
#define MAX_BOUNCE 10
|
constexpr int MAX_BOUNCE = 10;
|
||||||
|
|
||||||
// Tipos de globo
|
// Tipos de globo
|
||||||
#define BALLOON_1 1
|
constexpr int BALLOON_1 = 1;
|
||||||
#define BALLOON_2 2
|
constexpr int BALLOON_2 = 2;
|
||||||
#define BALLOON_3 3
|
constexpr int BALLOON_3 = 3;
|
||||||
#define BALLOON_4 4
|
constexpr int BALLOON_4 = 4;
|
||||||
#define HEXAGON_1 5
|
constexpr int HEXAGON_1 = 5;
|
||||||
#define HEXAGON_2 6
|
constexpr int HEXAGON_2 = 6;
|
||||||
#define HEXAGON_3 7
|
constexpr int HEXAGON_3 = 7;
|
||||||
#define HEXAGON_4 8
|
constexpr int HEXAGON_4 = 8;
|
||||||
#define POWER_BALL 9
|
constexpr int POWER_BALL = 9;
|
||||||
|
|
||||||
// Puntos de globo
|
// Puntos de globo
|
||||||
#define BALLOON_SCORE_1 50
|
constexpr int BALLOON_SCORE_1 = 50;
|
||||||
#define BALLOON_SCORE_2 100
|
constexpr int BALLOON_SCORE_2 = 100;
|
||||||
#define BALLOON_SCORE_3 200
|
constexpr int BALLOON_SCORE_3 = 200;
|
||||||
#define BALLOON_SCORE_4 400
|
constexpr int BALLOON_SCORE_4 = 400;
|
||||||
|
|
||||||
// Tamaños de globo
|
// Tamaños de globo
|
||||||
#define BALLOON_SIZE_1 1
|
constexpr int BALLOON_SIZE_1 = 1;
|
||||||
#define BALLOON_SIZE_2 2
|
constexpr int BALLOON_SIZE_2 = 2;
|
||||||
#define BALLOON_SIZE_3 3
|
constexpr int BALLOON_SIZE_3 = 3;
|
||||||
#define BALLOON_SIZE_4 4
|
constexpr int BALLOON_SIZE_4 = 4;
|
||||||
|
|
||||||
// Clases de globo
|
// Clases de globo
|
||||||
#define BALLOON_CLASS 0
|
constexpr int BALLOON_CLASS = 0;
|
||||||
#define HEXAGON_CLASS 1
|
constexpr int HEXAGON_CLASS = 1;
|
||||||
|
|
||||||
// Velocidad del globo
|
// Velocidad del globo
|
||||||
#define BALLOON_VELX_POSITIVE 0.7f
|
constexpr float BALLOON_VELX_POSITIVE = 0.7f;
|
||||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
constexpr float BALLOON_VELX_NEGATIVE = -0.7f;
|
||||||
|
|
||||||
// Indice para las animaciones de los globos
|
// Índice para las animaciones de los globos
|
||||||
#define BALLOON_MOVING_ANIMATION 0
|
constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||||
#define BALLOON_POP_ANIMATION 1
|
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||||
#define BALLOON_BORN_ANIMATION 2
|
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||||
|
|
||||||
// Cantidad posible de globos
|
// Cantidad posible de globos
|
||||||
#define MAX_BALLOONS 100
|
constexpr int MAX_BALLOONS = 100;
|
||||||
|
|
||||||
// Velocidades a las que se mueven los globos
|
// Velocidades a las que se mueven los globos
|
||||||
#define BALLOON_SPEED_1 0.60f
|
constexpr float BALLOON_SPEED_1 = 0.60f;
|
||||||
#define BALLOON_SPEED_2 0.70f
|
constexpr float BALLOON_SPEED_2 = 0.70f;
|
||||||
#define BALLOON_SPEED_3 0.80f
|
constexpr float BALLOON_SPEED_3 = 0.80f;
|
||||||
#define BALLOON_SPEED_4 0.90f
|
constexpr float BALLOON_SPEED_4 = 0.90f;
|
||||||
#define BALLOON_SPEED_5 1.00f
|
constexpr float BALLOON_SPEED_5 = 1.00f;
|
||||||
|
|
||||||
// Tamaño de los globos
|
// Tamaño de los globos
|
||||||
#define BALLOON_WIDTH_1 8
|
constexpr int BALLOON_WIDTH_1 = 8;
|
||||||
#define BALLOON_WIDTH_2 13
|
constexpr int BALLOON_WIDTH_2 = 13;
|
||||||
#define BALLOON_WIDTH_3 21
|
constexpr int BALLOON_WIDTH_3 = 21;
|
||||||
#define BALLOON_WIDTH_4 37
|
constexpr int BALLOON_WIDTH_4 = 37;
|
||||||
|
|
||||||
// PowerBall
|
// PowerBall
|
||||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||||
#define POWERBALL_COUNTER 8
|
constexpr int POWERBALL_COUNTER = 8;
|
||||||
|
|
||||||
// Clase Balloon
|
// Clase Balloon
|
||||||
class Balloon
|
class Balloon
|
||||||
@@ -250,5 +249,3 @@ public:
|
|||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getPower();
|
Uint8 getPower();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
|
#include "const.h" // for NO_KIND, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer)
|
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer)
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/sprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include "common/utils.h"
|
#include "utils.h" // for circle_t
|
||||||
|
class Sprite;
|
||||||
#ifndef BULLET_H
|
class Texture;
|
||||||
#define BULLET_H
|
|
||||||
|
|
||||||
// Tipos de bala
|
// Tipos de bala
|
||||||
#define BULLET_UP 1
|
constexpr int BULLET_UP = 1;
|
||||||
#define BULLET_LEFT 2
|
constexpr int BULLET_LEFT = 2;
|
||||||
#define BULLET_RIGHT 3
|
constexpr int BULLET_RIGHT = 3;
|
||||||
|
|
||||||
// Tipos de retorno de la funcion move de la bala
|
// Tipos de retorno de la función move de la bala
|
||||||
#define BULLET_MOVE_OK 0
|
constexpr int BULLET_MOVE_OK = 0;
|
||||||
#define BULLET_MOVE_OUT 1
|
constexpr int BULLET_MOVE_OUT = 1;
|
||||||
|
|
||||||
// Clase Bullet
|
// Clase Bullet
|
||||||
class Bullet
|
class Bullet
|
||||||
@@ -80,5 +79,3 @@ public:
|
|||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
#ifdef JA_USESDLMIXER
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct JA_Sound_t {}; // Dummy structs
|
|
||||||
struct JA_Music_t {};
|
|
||||||
|
|
||||||
int JA_freq {48000};
|
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
|
||||||
Uint8 JA_channels {2};
|
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|
||||||
JA_freq = freq;
|
|
||||||
JA_format = format;
|
|
||||||
JA_channels = channels;
|
|
||||||
Mix_OpenAudio(JA_freq, JA_format, JA_channels, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_Quit() {
|
|
||||||
Mix_CloseAudio();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
|
||||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
|
||||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseMusic() {
|
|
||||||
Mix_PauseMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeMusic() {
|
|
||||||
Mix_ResumeMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopMusic() {
|
|
||||||
Mix_HaltMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState() {
|
|
||||||
if (Mix_PausedMusic()) {
|
|
||||||
return JA_MUSIC_PAUSED;
|
|
||||||
} else if (Mix_PlayingMusic()) {
|
|
||||||
return JA_MUSIC_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteMusic(JA_Music_t *music) {
|
|
||||||
Mix_FreeMusic((Mix_Music*)music);
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
|
||||||
JA_Sound_t *sound = (JA_Sound_t*)Mix_LoadWAV(filename);
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
|
||||||
return Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
|
||||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseChannel(const int channel) {
|
|
||||||
Mix_Pause(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeChannel(const int channel) {
|
|
||||||
Mix_Resume(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopChannel(const int channel) {
|
|
||||||
Mix_HaltChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
|
||||||
if (Mix_Paused(channel)) {
|
|
||||||
return JA_CHANNEL_PAUSED;
|
|
||||||
} else if (Mix_Playing(channel)) {
|
|
||||||
return JA_CHANNEL_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_CHANNEL_FREE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_SetVolume(int volume) {
|
|
||||||
return Mix_Volume(-1, volume);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#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);
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
#include "notify.h"
|
|
||||||
#include <string>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->options = options;
|
|
||||||
bgColor = options->notifications.color;
|
|
||||||
waitTime = 300;
|
|
||||||
|
|
||||||
// Crea objetos
|
|
||||||
iconTexture = new Texture(renderer, iconFile);
|
|
||||||
textTexture = new Texture(renderer, bitmapFile);
|
|
||||||
text = new Text(textFile, textTexture, renderer);
|
|
||||||
sound = JA_LoadSound(soundFile.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Notify::~Notify()
|
|
||||||
{
|
|
||||||
// Libera la memoria de los objetos
|
|
||||||
delete textTexture;
|
|
||||||
delete iconTexture;
|
|
||||||
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[i].sprite->render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado de las notificaiones
|
|
||||||
void Notify::update()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
|
||||||
{
|
|
||||||
// Si la notificación anterior está "saliendo", no hagas nada
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
if (notifications[i - 1].state == ns_rising)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications[i].counter++;
|
|
||||||
|
|
||||||
// Hace sonar la notificación en el primer frame
|
|
||||||
if (notifications[i].counter == 1)
|
|
||||||
{
|
|
||||||
if (options->notifications.sound)
|
|
||||||
{
|
|
||||||
if (notifications[i].state == ns_rising)
|
|
||||||
{ // Reproduce el sonido de la notificación
|
|
||||||
JA_PlaySound(sound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los estados
|
|
||||||
if (notifications[i].state == ns_rising)
|
|
||||||
{
|
|
||||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
|
||||||
const int alpha = 255 * step;
|
|
||||||
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
notifications[i].rect.y++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notifications[i].rect.y--;
|
|
||||||
}
|
|
||||||
notifications[i].texture->setAlpha(alpha);
|
|
||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_stay;
|
|
||||||
notifications[i].texture->setAlpha(255);
|
|
||||||
notifications[i].counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (notifications[i].state == ns_stay)
|
|
||||||
{
|
|
||||||
if (notifications[i].counter == waitTime)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_vanishing;
|
|
||||||
notifications[i].counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (notifications[i].state == ns_vanishing)
|
|
||||||
{
|
|
||||||
|
|
||||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
|
||||||
const int alpha = 255 * (1 - step);
|
|
||||||
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
notifications[i].rect.y--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notifications[i].rect.y++;
|
|
||||||
}
|
|
||||||
notifications[i].texture->setAlpha(alpha);
|
|
||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_finished;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications[i].sprite->setRect(notifications[i].rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
clearFinishedNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Elimina las notificaciones finalizadas
|
|
||||||
void Notify::clearFinishedNotifications()
|
|
||||||
{
|
|
||||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
if (notifications[i].state == ns_finished)
|
|
||||||
{
|
|
||||||
delete notifications[i].sprite;
|
|
||||||
delete notifications[i].texture;
|
|
||||||
notifications.erase(notifications.begin() + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
const int iconSize = 16;
|
|
||||||
const int padding = text->getCharacterSize();
|
|
||||||
const int iconSpace = icon >= 0 ? iconSize + padding : 0;
|
|
||||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
|
||||||
const int width = text->lenght(txt) + (padding * 2) + iconSpace;
|
|
||||||
const int height = (text->getCharacterSize() * 2) + (padding * 2);
|
|
||||||
|
|
||||||
// Posición horizontal
|
|
||||||
int despH = 0;
|
|
||||||
if (options->notifications.posH == pos_left)
|
|
||||||
{
|
|
||||||
despH = padding;
|
|
||||||
}
|
|
||||||
else if (options->notifications.posH == pos_middle)
|
|
||||||
{
|
|
||||||
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Posición vertical
|
|
||||||
int despV = 0;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
despV = padding;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int travelDist = height + padding;
|
|
||||||
|
|
||||||
// Offset
|
|
||||||
int offset = 0;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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.text1 = text1;
|
|
||||||
n.text2 = text2;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
n.rect = {despH, offset - travelDist, width, height};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
||||||
|
|
||||||
// Prepara para dibujar en la textura
|
|
||||||
n.texture->setAsRenderTarget(renderer);
|
|
||||||
|
|
||||||
// Dibuja el fondo de la notificación
|
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
|
||||||
SDL_Rect rect;
|
|
||||||
rect = {4, 0, width - (4 * 2), height};
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
|
|
||||||
rect = {4 / 2, 1, width - 4, height - 2};
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
|
|
||||||
rect = {1, 4 / 2, width - 2, height - 4};
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
|
|
||||||
rect = {0, 4, width, height - (4 * 2)};
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
|
|
||||||
// Dibuja el icono de la notificación
|
|
||||||
if (icon >= 0)
|
|
||||||
{
|
|
||||||
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture, renderer);
|
|
||||||
sp->setPos({padding, padding, iconSize, iconSize});
|
|
||||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
|
||||||
sp->render();
|
|
||||||
delete sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto de la notificación
|
|
||||||
color_t color = {255, 255, 255};
|
|
||||||
if (text2 != "")
|
|
||||||
{ // Dos lineas de texto
|
|
||||||
text->writeColored(padding + iconSpace, padding, text1, color);
|
|
||||||
text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Una linea de texto
|
|
||||||
text->writeColored(padding + iconSpace, (height / 2) - (text->getCharacterSize() / 2), text1, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja de dibujar en la textura
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Crea el sprite de la notificación
|
|
||||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
|
||||||
|
|
||||||
// Deja la notificación invisible
|
|
||||||
n.texture->setAlpha(0);
|
|
||||||
|
|
||||||
// Añade la notificación a la lista
|
|
||||||
notifications.push_back(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
|
||||||
bool Notify::active()
|
|
||||||
{
|
|
||||||
if ((int)notifications.size() > 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
#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 text1;
|
|
||||||
std::string text2;
|
|
||||||
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 *textTexture; // Textura para la fuente de las notificaciones
|
|
||||||
Texture *iconTexture; // Textura para los iconos de las notificaciones
|
|
||||||
Text *text; // Objeto para dibujar texto
|
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
|
||||||
|
|
||||||
// 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_t *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 iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Notify();
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
|
||||||
bool active();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,65 +1,60 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "common/utils.h"
|
#include "utils.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
|
||||||
#ifndef CONST_H
|
|
||||||
#define CONST_H
|
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
#define BLOCK 8
|
constexpr int BLOCK = 8;
|
||||||
#define HALF_BLOCK BLOCK / 2
|
constexpr int HALF_BLOCK = BLOCK / 2;
|
||||||
|
|
||||||
// Tamaño de la pantalla virtual
|
// Tamaño de la pantalla virtual
|
||||||
#define GAMECANVAS_WIDTH 256
|
constexpr int GAMECANVAS_WIDTH = 256;
|
||||||
#define GAMECANVAS_HEIGHT 192
|
constexpr int GAMECANVAS_HEIGHT = 192;
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
constexpr int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
const int PLAY_AREA_BOTTOM = GAMECANVAS_HEIGHT - (4 * BLOCK);
|
constexpr int PLAY_AREA_BOTTOM = GAMECANVAS_HEIGHT - (4 * BLOCK);
|
||||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
constexpr int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||||
const int PLAY_AREA_RIGHT = GAMECANVAS_WIDTH - (0 * BLOCK);
|
constexpr int PLAY_AREA_RIGHT = GAMECANVAS_WIDTH - (0 * BLOCK);
|
||||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||||
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
||||||
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
||||||
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
||||||
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
||||||
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Anclajes de pantalla
|
// Anclajes de pantalla
|
||||||
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
||||||
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
||||||
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
||||||
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||||
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||||
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Secciones del programa
|
// Secciones del programa
|
||||||
#define SECTION_PROG_LOGO 0
|
constexpr int SECTION_PROG_LOGO = 0;
|
||||||
#define SECTION_PROG_INTRO 1
|
constexpr int SECTION_PROG_INTRO = 1;
|
||||||
#define SECTION_PROG_TITLE 2
|
constexpr int SECTION_PROG_TITLE = 2;
|
||||||
#define SECTION_PROG_GAME 3
|
constexpr int SECTION_PROG_GAME = 3;
|
||||||
#define SECTION_PROG_QUIT 4
|
constexpr int SECTION_PROG_QUIT = 4;
|
||||||
|
|
||||||
// Subsecciones
|
// Subsecciones
|
||||||
#define SUBSECTION_GAME_PLAY_1P 0
|
constexpr int SUBSECTION_GAME_PLAY_1P = 0;
|
||||||
#define SUBSECTION_GAME_PLAY_2P 1
|
constexpr int SUBSECTION_GAME_PLAY_2P = 1;
|
||||||
#define SUBSECTION_GAME_PAUSE 2
|
constexpr int SUBSECTION_GAME_PAUSE = 2;
|
||||||
#define SUBSECTION_GAME_GAMEOVER 3
|
constexpr int SUBSECTION_GAME_GAMEOVER = 3;
|
||||||
#define SUBSECTION_TITLE_1 3
|
constexpr int SUBSECTION_TITLE_1 = 3;
|
||||||
#define SUBSECTION_TITLE_2 4
|
constexpr int SUBSECTION_TITLE_2 = 4;
|
||||||
#define SUBSECTION_TITLE_3 5
|
constexpr int SUBSECTION_TITLE_3 = 5;
|
||||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
constexpr int SUBSECTION_TITLE_INSTRUCTIONS = 6;
|
||||||
|
|
||||||
// Ningun tipo
|
// Ningun tipo
|
||||||
#define NO_KIND 0
|
constexpr int NO_KIND = 0;
|
||||||
|
|
||||||
// Colores
|
// Colores
|
||||||
const color_t bgColor = {0x27, 0x27, 0x36};
|
const color_t bgColor = {0x27, 0x27, 0x36};
|
||||||
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
||||||
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,20 +1,44 @@
|
|||||||
#include "common/jscore.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "director.h"
|
#include "director.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL.h> // for SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||||
#include <fstream>
|
#include <SDL2/SDL_audio.h> // for AUDIO_S16
|
||||||
#include <string>
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
#include <sys/stat.h>
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <unistd.h>
|
#include <SDL2/SDL_gamecontroller.h> // for SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||||
|
#include <SDL2/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_SC...
|
||||||
|
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_ESCAPE, SDL_SCANCO...
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||||
|
#include <stdio.h> // for printf, perror
|
||||||
|
#include <string.h> // for strcmp
|
||||||
|
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
||||||
|
#include <unistd.h> // for getuid
|
||||||
|
#include <cstdlib> // for exit, EXIT_FAILURE, srand
|
||||||
|
#include <fstream> // for basic_ostream, operator<<, basi...
|
||||||
|
#include <iostream> // for cout
|
||||||
|
#include <string> // for basic_string, operator+, char_t...
|
||||||
|
#include <vector> // for vector
|
||||||
|
#include <memory>
|
||||||
|
#include "asset.h" // for Asset, assetType
|
||||||
|
#include "const.h" // for SECTION_PROG_LOGO, GAMECANVAS_H...
|
||||||
|
#include "game.h" // for Game
|
||||||
|
#include "input.h" // for Input, inputs_e, INPUT_USE_GAME...
|
||||||
|
#include "intro.h" // for Intro
|
||||||
|
#include "jail_audio.h" // for JA_Init
|
||||||
|
#include "lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK
|
||||||
|
#include "logo.h" // for Logo
|
||||||
|
#include "screen.h" // for FILTER_NEAREST, Screen, FILTER_...
|
||||||
|
#include "title.h" // for Title
|
||||||
|
#include "utils.h" // for options_t, input_t, boolToString
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, char *argv[])
|
Director::Director(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
|
std::cout << "Game start" << std::endl;
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section = new section_t();
|
section = new section_t();
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_LOGO;
|
||||||
@@ -60,9 +84,6 @@ Director::Director(int argc, char *argv[])
|
|||||||
initInput();
|
initInput();
|
||||||
|
|
||||||
screen = new Screen(window, renderer, asset, options);
|
screen = new Screen(window, renderer, asset, options);
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
initOnline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director()
|
Director::~Director()
|
||||||
@@ -80,6 +101,8 @@ Director::~Director()
|
|||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
|
std::cout << "\nBye!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el objeto input
|
// Inicializa el objeto input
|
||||||
@@ -240,9 +263,6 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/config/demo.bin", t_data);
|
asset->add(prefix + "/data/config/demo.bin", t_data);
|
||||||
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
// Notificaciones
|
|
||||||
asset->add(prefix + "/data/notifications/notify.png", t_bitmap);
|
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
||||||
asset->add(prefix + "/data/music/playing.ogg", t_music);
|
asset->add(prefix + "/data/music/playing.ogg", t_music);
|
||||||
@@ -266,7 +286,6 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/clock.wav", t_sound);
|
asset->add(prefix + "/data/sound/clock.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/powerball.wav", t_sound);
|
asset->add(prefix + "/data/sound/powerball.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/notify.wav", t_sound);
|
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
asset->add(prefix + "/data/gfx/balloon1.png", t_bitmap);
|
asset->add(prefix + "/data/gfx/balloon1.png", t_bitmap);
|
||||||
@@ -398,28 +417,10 @@ void Director::initOptions()
|
|||||||
options->difficulty = DIFFICULTY_NORMAL;
|
options->difficulty = DIFFICULTY_NORMAL;
|
||||||
options->language = ba_BA;
|
options->language = ba_BA;
|
||||||
options->console = false;
|
options->console = false;
|
||||||
|
|
||||||
// Opciones online
|
|
||||||
options->online.enabled = false;
|
|
||||||
options->online.server = "jaildoctor.duckdns.org";
|
|
||||||
options->online.port = 9911;
|
|
||||||
#ifdef DEBUG
|
|
||||||
options->online.gameID = "coffee_crisis_test2";
|
|
||||||
#else
|
|
||||||
options->online.gameID = "coffee_crisis";
|
|
||||||
#endif
|
|
||||||
options->online.jailerID = "";
|
|
||||||
options->online.score = 0;
|
|
||||||
|
|
||||||
// Opciones de las notificaciones
|
|
||||||
options->notifications.posV = pos_top;
|
|
||||||
options->notifications.posH = pos_left;
|
|
||||||
options->notifications.sound = true;
|
|
||||||
options->notifications.color = {48, 48, 48};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void Director::checkProgramArguments(int argc, char *argv[])
|
void Director::checkProgramArguments(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
// Establece la ruta del programa
|
// Establece la ruta del programa
|
||||||
executablePath = argv[0];
|
executablePath = argv[0];
|
||||||
@@ -435,7 +436,7 @@ void Director::checkProgramArguments(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
void Director::createSystemFolder(std::string folder)
|
void Director::createSystemFolder(const std::string &folder)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
|
systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
|
||||||
@@ -446,7 +447,18 @@ void Director::createSystemFolder(std::string folder)
|
|||||||
#elif __linux__
|
#elif __linux__
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
const char *homedir = pw->pw_dir;
|
const char *homedir = pw->pw_dir;
|
||||||
systemFolder = std::string(homedir) + "/." + folder;
|
systemFolder = std::string(homedir) + "/.config/" + folder;
|
||||||
|
|
||||||
|
{
|
||||||
|
// Intenta crear ".config", per si no existeix
|
||||||
|
std::string config_base_folder = std::string(homedir) + "/.config";
|
||||||
|
int ret = mkdir(config_base_folder.c_str(), S_IRWXU);
|
||||||
|
if (ret == -1 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
printf("ERROR CREATING CONFIG BASE FOLDER.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
@@ -590,12 +602,12 @@ bool Director::saveConfigFile()
|
|||||||
|
|
||||||
else if (options->videoMode == 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->videoMode == 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";
|
||||||
@@ -623,41 +635,6 @@ bool Director::saveConfigFile()
|
|||||||
file << "input0=" + std::to_string(options->input[0].deviceType) + "\n";
|
file << "input0=" + std::to_string(options->input[0].deviceType) + "\n";
|
||||||
file << "input1=" + std::to_string(options->input[1].deviceType) + "\n";
|
file << "input1=" + std::to_string(options->input[1].deviceType) + "\n";
|
||||||
|
|
||||||
// Opciones sobre la conexión online
|
|
||||||
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";
|
|
||||||
|
|
||||||
// Opciones de las notificaciones
|
|
||||||
file << "\n## NOTIFICATION OPTIONS\n";
|
|
||||||
file << "## notifications.posV = pos_top | pos_bottom\n";
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
file << "notifications.posV=pos_top\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file << "notifications.posV=pos_bottom\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
file << "## notifications.posH = pos_left | pos_middle | pos_right\n";
|
|
||||||
if (options->notifications.posH == pos_left)
|
|
||||||
{
|
|
||||||
file << "notifications.posH=pos_left\n";
|
|
||||||
}
|
|
||||||
else if (options->notifications.posH == pos_middle)
|
|
||||||
{
|
|
||||||
file << "notifications.posH=pos_middle\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file << "notifications.posH=pos_right\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
file << "notifications.sound=" + boolToString(options->notifications.sound) + "\n";
|
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@@ -666,34 +643,30 @@ bool Director::saveConfigFile()
|
|||||||
|
|
||||||
void Director::runLogo()
|
void Director::runLogo()
|
||||||
{
|
{
|
||||||
logo = new Logo(renderer, screen, asset, input, section);
|
auto logo = std::make_unique<Logo>(renderer, screen, asset, input, section);
|
||||||
logo->run();
|
logo->run();
|
||||||
delete logo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runIntro()
|
void Director::runIntro()
|
||||||
{
|
{
|
||||||
intro = new Intro(renderer, screen, asset, input, lang, section);
|
auto intro = std::make_unique<Intro>(renderer, screen, asset, input, lang, section);
|
||||||
intro->run();
|
intro->run();
|
||||||
delete intro;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
title = new Title(renderer, screen, input, asset, options, lang, section);
|
auto title = std::make_unique<Title>(renderer, screen, input, asset, options, lang, section);
|
||||||
title->run();
|
title->run();
|
||||||
delete title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
||||||
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
|
auto game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
|
||||||
game->run();
|
game->run();
|
||||||
delete game;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::run()
|
int Director::run()
|
||||||
{
|
{
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
while (section->name != SECTION_PROG_QUIT)
|
while (section->name != SECTION_PROG_QUIT)
|
||||||
@@ -717,66 +690,8 @@ void Director::run()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
return 0;
|
||||||
void Director::initOnline()
|
|
||||||
{
|
|
||||||
if (options->online.sessionEnabled)
|
|
||||||
{ // Si ya ha iniciado la sesión, que no continue
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->online.jailerID == "")
|
|
||||||
{ // Jailer ID no definido
|
|
||||||
options->online.enabled = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Jailer ID iniciado
|
|
||||||
options->online.enabled = options->online.sessionEnabled = true;
|
|
||||||
// Establece el servidor y el puerto
|
|
||||||
jscore::init(options->online.server, options->online.port);
|
|
||||||
#ifdef DEBUG
|
|
||||||
const std::string caption = options->online.jailerID + " (DEBUG)";
|
|
||||||
#else
|
|
||||||
const std::string caption = options->online.jailerID;
|
|
||||||
#endif
|
|
||||||
//screen->showNotification(caption, lang->getText(85), 12);
|
|
||||||
screen->showNotification(caption, lang->getText(85));
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << caption << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene la información de puntuaciones online
|
|
||||||
if (!jscore::initOnlineScore(options->online.gameID))
|
|
||||||
{
|
|
||||||
screen->showNotification(lang->getText(80), options->online.server);
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Can't connect to " << options->online.server << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
options->online.enabled = false;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten la puntuación online para el jailerID
|
|
||||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
|
||||||
if (points == 0)
|
|
||||||
{ // Fallo de conexión o no hay registros
|
|
||||||
screen->showNotification(lang->getText(81), lang->getText(82));
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Can't get online scores" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->online.score = points;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
@@ -874,65 +789,6 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
options->input[1].deviceType = std::stoi(value);
|
options->input[1].deviceType = std::stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opciones onlince
|
|
||||||
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 = toLower(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Opciones de notificaciones
|
|
||||||
else if (var == "notifications.posH")
|
|
||||||
{
|
|
||||||
if (value == "pos_left")
|
|
||||||
{
|
|
||||||
options->notifications.posH = pos_left;
|
|
||||||
}
|
|
||||||
else if (value == "pos_middle")
|
|
||||||
{
|
|
||||||
options->notifications.posH = pos_middle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->notifications.posH = pos_right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "notifications.posV")
|
|
||||||
{
|
|
||||||
if (value == "pos_top")
|
|
||||||
{
|
|
||||||
options->notifications.posV = pos_top;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->notifications.posV = pos_bottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "notifications.sound")
|
|
||||||
{
|
|
||||||
options->notifications.sound = stringToBool(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lineas vacias o que empiezan por comentario
|
// Lineas vacias o que empiezan por comentario
|
||||||
else if (var == "" || var.substr(0, 1) == "#")
|
else if (var == "" || var.substr(0, 1) == "#")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,33 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "balloon.h"
|
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||||
#include "bullet.h"
|
#include <string> // for string, basic_string
|
||||||
#include "common/asset.h"
|
class Asset;
|
||||||
#include "common/input.h"
|
class Game;
|
||||||
#include "common/jail_audio.h"
|
class Input;
|
||||||
#include "common/menu.h"
|
class Intro;
|
||||||
#include "common/movingsprite.h"
|
class Lang;
|
||||||
#include "common/screen.h"
|
class Logo;
|
||||||
#include "common/smartsprite.h"
|
class Screen;
|
||||||
#include "common/sprite.h"
|
class Title;
|
||||||
#include "common/text.h"
|
struct options_t;
|
||||||
#include "common/utils.h"
|
struct section_t;
|
||||||
#include "common/writer.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "fade.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include "intro.h"
|
|
||||||
#include "item.h"
|
|
||||||
#include "logo.h"
|
|
||||||
#include "player.h"
|
|
||||||
#include "title.h"
|
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
|
||||||
#define DIRECTOR_H
|
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
#define WINDOW_CAPTION "Coffee Crisis"
|
constexpr const char* WINDOW_CAPTION = "Coffee Crisis";
|
||||||
|
|
||||||
class Director
|
class Director
|
||||||
{
|
{
|
||||||
@@ -36,10 +24,6 @@ private:
|
|||||||
SDL_Window *window; // La ventana donde dibujamos
|
SDL_Window *window; // La ventana donde dibujamos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Logo *logo; // Objeto para la sección del logo
|
|
||||||
Intro *intro; // Objeto para la sección de la intro
|
|
||||||
Title *title; // Objeto para la sección del titulo y el menu de opciones
|
|
||||||
Game *game; // Objeto para la sección del juego
|
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
@@ -59,9 +43,6 @@ private:
|
|||||||
// Inicializa el objeto input
|
// Inicializa el objeto input
|
||||||
void initInput();
|
void initInput();
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void initOnline();
|
|
||||||
|
|
||||||
// Inicializa las opciones del programa
|
// Inicializa las opciones del programa
|
||||||
void initOptions();
|
void initOptions();
|
||||||
|
|
||||||
@@ -78,13 +59,10 @@ private:
|
|||||||
bool saveConfigFile();
|
bool saveConfigFile();
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, char *argv[]);
|
void checkProgramArguments(int argc, const char *argv[]);
|
||||||
|
|
||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
void createSystemFolder(std::string folder);
|
void createSystemFolder(const std::string &folder);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setSection(section_t section);
|
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el logo
|
// Ejecuta la seccion de juego con el logo
|
||||||
void runLogo();
|
void runLogo();
|
||||||
@@ -100,13 +78,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Director(int argc, char *argv[]);
|
Director(int argc, const char *argv[]);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Director();
|
~Director();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
int run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,348 +0,0 @@
|
|||||||
#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, Lang *lang, options_t *options, section_t *section)
|
|
||||||
{
|
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->lang = lang;
|
|
||||||
this->options = options;
|
|
||||||
this->section = section;
|
|
||||||
|
|
||||||
// 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
|
|
||||||
oldJailerID = options->online.jailerID;
|
|
||||||
loopRunning = true;
|
|
||||||
counter = 0;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
jailerIDPos = 0;
|
|
||||||
initName();
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
EnterID::~EnterID()
|
|
||||||
{
|
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
|
||||||
delete texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
void EnterID::run()
|
|
||||||
{
|
|
||||||
while (loopRunning)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
checkEvents();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void EnterID::checkEvents()
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
loopRunning = false;
|
|
||||||
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_RETURN)
|
|
||||||
{
|
|
||||||
options->online.jailerID = toLower((std::string)name);
|
|
||||||
endSection();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
loopRunning = false;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
// Actualiza el contador
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
// Actualiza el cursor
|
|
||||||
cursor = (counter % 20 >= 10) ? " " : "_";
|
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void EnterID::render()
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// 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, jailerIDPos, jailerID, 1, color);
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los textos
|
|
||||||
void EnterID::iniTexts()
|
|
||||||
{
|
|
||||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
|
||||||
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
|
||||||
|
|
||||||
texts.clear();
|
|
||||||
texts.push_back({lang->getText(89), orangeColor});
|
|
||||||
texts.push_back({"", noColor});
|
|
||||||
texts.push_back({lang->getText(90), noColor});
|
|
||||||
texts.push_back({lang->getText(91), noColor});
|
|
||||||
texts.push_back({lang->getText(92), noColor});
|
|
||||||
texts.push_back({"", noColor});
|
|
||||||
texts.push_back({"", noColor});
|
|
||||||
texts.push_back({"", noColor});
|
|
||||||
texts.push_back({"JAILER_ID:", orangeColor});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
void EnterID::fillTexture()
|
|
||||||
{
|
|
||||||
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
|
||||||
|
|
||||||
// Inicializa los textos
|
|
||||||
iniTexts();
|
|
||||||
|
|
||||||
// Rellena la textura con un color de fondo
|
|
||||||
SDL_SetRenderTarget(renderer, textTexture);
|
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Añade el efecto de degradado en el fondo
|
|
||||||
//Texture *gradient = new Texture(renderer, asset->get("title_gradient.png"));
|
|
||||||
//SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
|
||||||
//gradient->render(renderer, 0, 0, &rect);
|
|
||||||
//delete gradient;
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
const int desp = 40;
|
|
||||||
const int size = text->getCharacterSize() + 2;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (auto t : texts)
|
|
||||||
{
|
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, PLAY_AREA_CENTER_X, (i * size) + desp, t.label, 1, t.color, 1, shdwTxtColor);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
jailerIDPos = ((i + 1) * size) + desp;
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void EnterID::initOnline()
|
|
||||||
{
|
|
||||||
// Si ya ha iniciado la sesión y no ha cambiado el jailerID, que no continue
|
|
||||||
if (options->online.sessionEnabled)
|
|
||||||
{
|
|
||||||
if (oldJailerID == options->online.jailerID)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->online.jailerID == "")
|
|
||||||
{ // Jailer ID no definido
|
|
||||||
options->online.enabled = false;
|
|
||||||
options->online.sessionEnabled = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Jailer ID iniciado
|
|
||||||
options->online.enabled = options->online.sessionEnabled = true;
|
|
||||||
// Establece el servidor y el puerto
|
|
||||||
jscore::init(options->online.server, options->online.port);
|
|
||||||
#ifdef DEBUG
|
|
||||||
const std::string caption = options->online.jailerID + " (DEBUG)";
|
|
||||||
#else
|
|
||||||
const std::string caption = options->online.jailerID;
|
|
||||||
#endif
|
|
||||||
// screen->showNotification(caption, lang->getText(85), 12);
|
|
||||||
screen->showNotification(caption, lang->getText(85));
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << caption << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene la información de puntuaciones online
|
|
||||||
if (!jscore::initOnlineScore(options->online.gameID))
|
|
||||||
{
|
|
||||||
screen->showNotification(lang->getText(80), options->online.server);
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Can't connect to " << options->online.server << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
options->online.enabled = false;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten la puntuación online para el jailerID
|
|
||||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
|
||||||
if (points == 0)
|
|
||||||
{ // Fallo de conexión o no hay registros
|
|
||||||
screen->showNotification(lang->getText(81), lang->getText(82));
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Can't get online scores" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->online.score = points;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Termina la sección
|
|
||||||
void EnterID::endSection()
|
|
||||||
{
|
|
||||||
loopRunning = false;
|
|
||||||
initOnline();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
|
||||||
void EnterID::initName()
|
|
||||||
{
|
|
||||||
// Calcula el tamaño del vector
|
|
||||||
name[0] = 0;
|
|
||||||
maxLenght = sizeof(name) / sizeof(name[pos]);
|
|
||||||
|
|
||||||
// Inicializa el vector con ceros
|
|
||||||
for (int i = 0; i < maxLenght; ++i)
|
|
||||||
{
|
|
||||||
name[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si no hay definido ningun JailerID, coloca el cursor en primera posición
|
|
||||||
if (options->online.jailerID == "")
|
|
||||||
{
|
|
||||||
pos = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // En caso contrario, copia el texto al vector y coloca el cursor en posición
|
|
||||||
const int len = std::min((int)options->online.jailerID.size(), maxLenght);
|
|
||||||
for (int i = 0; i < len; ++i)
|
|
||||||
{
|
|
||||||
name[i] = (char)options->online.jailerID[i];
|
|
||||||
}
|
|
||||||
pos = len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
#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 ENTER_ID_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
|
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
|
||||||
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
|
|
||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
bool loopRunning; // Indica si ha de terminar el bucle principal
|
|
||||||
int counter; // Contador
|
|
||||||
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]; // Aqui se guardan los caracteres de las teclas que se van pulsando
|
|
||||||
int pos; // Posición actual en el vector name
|
|
||||||
int maxLenght; // Tamaño máximo del jailerID
|
|
||||||
std::string oldJailerID; // Almacena el valor de jailerID al inicio para ver si se ha modificado
|
|
||||||
int jailerIDPos; // Posición en el eje Y donde ser va a escribir el texto
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void checkEvents();
|
|
||||||
|
|
||||||
// Inicializa los textos
|
|
||||||
void iniTexts();
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
void fillTexture();
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void initOnline();
|
|
||||||
|
|
||||||
// Termina la sección
|
|
||||||
void endSection();
|
|
||||||
|
|
||||||
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
|
||||||
void initName();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~EnterID();
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "fade.h"
|
#include "fade.h"
|
||||||
#include "const.h"
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <iostream>
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_Delay
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||||
|
#include "const.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Fade::Fade(SDL_Renderer *renderer)
|
Fade::Fade(SDL_Renderer *renderer)
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "common/texture.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16
|
||||||
#ifndef FADE_H
|
|
||||||
#define FADE_H
|
|
||||||
|
|
||||||
// Tipos de fundido
|
// Tipos de fundido
|
||||||
#define FADE_FULLSCREEN 0
|
constexpr int FADE_FULLSCREEN = 0;
|
||||||
#define FADE_CENTER 1
|
constexpr int FADE_CENTER = 1;
|
||||||
#define FADE_RANDOM_SQUARE 2
|
constexpr int FADE_RANDOM_SQUARE = 2;
|
||||||
|
|
||||||
// Clase Fade
|
// Clase Fade
|
||||||
class Fade
|
class Fade
|
||||||
@@ -53,5 +51,3 @@ public:
|
|||||||
// Establece el tipo de fade
|
// Establece el tipo de fade
|
||||||
void setFadeType(Uint8 fadeType);
|
void setFadeType(Uint8 fadeType);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
124
source/game.cpp
124
source/game.cpp
@@ -1,5 +1,30 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "common/jscore.h"
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks, SDL_Delay
|
||||||
|
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_LOST
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include <algorithm> // for max, min
|
||||||
|
#include <fstream> // for basic_ifstream
|
||||||
|
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "balloon.h" // for Balloon, BALLOON_VELX_NEGATIVE, BALLOON_...
|
||||||
|
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT, BULLE...
|
||||||
|
#include "const.h" // for PLAY_AREA_CENTER_X, BLOCK, PLAY_AREA_CEN...
|
||||||
|
#include "fade.h" // for Fade, FADE_CENTER
|
||||||
|
#include "input.h" // for inputs_e, Input, REPEAT_TRUE, REPEAT_FALSE
|
||||||
|
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||||
|
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
|
||||||
|
#include "lang.h" // for Lang
|
||||||
|
#include "menu.h" // for Menu
|
||||||
|
#include "movingsprite.h" // for MovingSprite
|
||||||
|
#include "player.h" // for Player, DEATH_COUNTER
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "smartsprite.h" // for SmartSprite
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "text.h" // for Text, TXT_CENTER
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section)
|
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section)
|
||||||
@@ -16,7 +41,11 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
// Pasa variables
|
// Pasa variables
|
||||||
this->demo.enabled = demo;
|
this->demo.enabled = demo;
|
||||||
this->numPlayers = numPlayers;
|
this->numPlayers = numPlayers;
|
||||||
|
#ifdef PAUSE
|
||||||
|
this->currentStage = 3;
|
||||||
|
#else
|
||||||
this->currentStage = currentStage;
|
this->currentStage = currentStage;
|
||||||
|
#endif
|
||||||
lastStageReached = currentStage;
|
lastStageReached = currentStage;
|
||||||
if (numPlayers == 1)
|
if (numPlayers == 1)
|
||||||
{ // Si solo juega un jugador, permite jugar tanto con teclado como con mando
|
{ // Si solo juega un jugador, permite jugar tanto con teclado como con mando
|
||||||
@@ -57,12 +86,14 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Game'
|
// Inicializa las variables necesarias para la sección 'Game'
|
||||||
init();
|
init();
|
||||||
|
#ifdef PAUSE
|
||||||
|
pause = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
saveScoreFile();
|
saveScoreFile();
|
||||||
sendOnlineScore();
|
|
||||||
saveDemoFile();
|
saveDemoFile();
|
||||||
|
|
||||||
// Restaura el metodo de control
|
// Restaura el metodo de control
|
||||||
@@ -766,38 +797,6 @@ bool Game::saveScoreFile()
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sube la puntuación online
|
|
||||||
bool Game::sendOnlineScore()
|
|
||||||
{
|
|
||||||
if (!options->online.enabled)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (demo.enabled)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int score = players[0]->getScore();
|
|
||||||
if (score <= options->online.score)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jscore::updateUserPoints(options->online.gameID, options->online.jailerID, score))
|
|
||||||
{
|
|
||||||
options->online.score = score;
|
|
||||||
screen->showNotification(lang->getText(86) + std::to_string(score), "", 2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
screen->showNotification(lang->getText(86), lang->getText(87));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Guarda el fichero de datos para la demo
|
// Guarda el fichero de datos para la demo
|
||||||
bool Game::saveDemoFile()
|
bool Game::saveDemoFile()
|
||||||
{
|
{
|
||||||
@@ -1614,12 +1613,6 @@ void Game::updateHiScore()
|
|||||||
// Actualiza la máxima puntuación
|
// Actualiza la máxima puntuación
|
||||||
hiScore = player->getScore();
|
hiScore = player->getScore();
|
||||||
|
|
||||||
// Cambia el nombre del jugador con la máxima puntuación
|
|
||||||
if (options->online.enabled)
|
|
||||||
{
|
|
||||||
hiScoreName = options->online.jailerID.substr(0, 12) + " - ";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Almacena la máxima puntuación en el fichero junto con un checksum
|
// Almacena la máxima puntuación en el fichero junto con un checksum
|
||||||
scoreDataFile[0] = hiScore;
|
scoreDataFile[0] = hiScore;
|
||||||
scoreDataFile[1] = hiScore % 43;
|
scoreDataFile[1] = hiScore % 43;
|
||||||
@@ -2552,7 +2545,7 @@ Uint8 Game::dropItem()
|
|||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void Game::createItem(Uint8 kind, float x, float y)
|
void Game::createItem(Uint8 kind, float x, float y)
|
||||||
{
|
{
|
||||||
Item *item = new Item(kind, x, y, itemTextures[kind], itemAnimations[kind], renderer);
|
Item *item = new Item(kind, x, y, itemTextures[kind - 1], itemAnimations[kind - 1], renderer);
|
||||||
items.push_back(item);
|
items.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2786,9 +2779,6 @@ void Game::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
// Actualiza el contador de juego
|
// Actualiza el contador de juego
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
@@ -3066,7 +3056,7 @@ void Game::checkGameInput()
|
|||||||
if (players[index]->canFire())
|
if (players[index]->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(input_fire_left);
|
players[index]->setInput(input_fire_left);
|
||||||
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
|
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_LEFT, players[index]->isPowerUp(), index);
|
||||||
players[index]->setFireCooldown(10);
|
players[index]->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3076,7 +3066,7 @@ void Game::checkGameInput()
|
|||||||
if (players[index]->canFire())
|
if (players[index]->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(input_fire_right);
|
players[index]->setInput(input_fire_right);
|
||||||
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
|
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_RIGHT, players[index]->isPowerUp(), index);
|
||||||
players[index]->setFireCooldown(10);
|
players[index]->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3367,8 +3357,13 @@ void Game::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PAUSE
|
||||||
|
if (!pause)
|
||||||
|
update();
|
||||||
|
#else
|
||||||
// Actualiza la lógica del juego
|
// Actualiza la lógica del juego
|
||||||
update();
|
update();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba los eventos que hay en cola
|
// Comprueba los eventos que hay en cola
|
||||||
checkEvents();
|
checkEvents();
|
||||||
@@ -3388,9 +3383,6 @@ void Game::updatePausedGame()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
if (leavingPauseMenu)
|
if (leavingPauseMenu)
|
||||||
{
|
{
|
||||||
if (pauseCounter > 0)
|
if (pauseCounter > 0)
|
||||||
@@ -3533,9 +3525,6 @@ void Game::updateGameOverScreen()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
// Actualiza la lógica del menu
|
// Actualiza la lógica del menu
|
||||||
gameOverMenu->update();
|
gameOverMenu->update();
|
||||||
|
|
||||||
@@ -3681,9 +3670,6 @@ void Game::runGameOverScreen()
|
|||||||
// Guarda los puntos
|
// Guarda los puntos
|
||||||
saveScoreFile();
|
saveScoreFile();
|
||||||
|
|
||||||
// Sube la puntuación online
|
|
||||||
sendOnlineScore();
|
|
||||||
|
|
||||||
// Reinicia el menu
|
// Reinicia el menu
|
||||||
gameOverMenu->reset();
|
gameOverMenu->reset();
|
||||||
|
|
||||||
@@ -3869,6 +3855,16 @@ void Game::checkEvents()
|
|||||||
section->subsection = SUBSECTION_GAME_PAUSE;
|
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PAUSE
|
||||||
|
else if (eventHandler->type == SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_P)
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3963,23 +3959,5 @@ void Game::setHiScore()
|
|||||||
{
|
{
|
||||||
// Carga el fichero de puntos
|
// Carga el fichero de puntos
|
||||||
loadScoreFile();
|
loadScoreFile();
|
||||||
|
|
||||||
// Establece el resto de variables
|
|
||||||
if (options->online.enabled)
|
|
||||||
{
|
|
||||||
if (jscore::getNumUsers() > 0)
|
|
||||||
{
|
|
||||||
hiScoreName = jscore::getUserName(0).substr(0, 12) + " - ";
|
|
||||||
hiScore = (Uint32)jscore::getPoints(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hiScoreName = "Bacteriol - ";
|
|
||||||
hiScore = 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hiScoreName = "";
|
hiScoreName = "";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,54 +1,56 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "balloon.h"
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "bullet.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||||
#include "common/input.h"
|
#include <string> // for string, basic_string
|
||||||
#include "common/jail_audio.h"
|
#include <vector> // for vector
|
||||||
#include "common/menu.h"
|
#include "utils.h" // for demoKeys_t, color_t
|
||||||
#include "common/movingsprite.h"
|
class Asset;
|
||||||
#include "common/screen.h"
|
class Balloon;
|
||||||
#include "common/smartsprite.h"
|
class Bullet;
|
||||||
#include "common/sprite.h"
|
class Fade;
|
||||||
#include "common/text.h"
|
class Input;
|
||||||
#include "common/utils.h"
|
class Item;
|
||||||
#include "common/writer.h"
|
class Lang;
|
||||||
#include "const.h"
|
class Menu;
|
||||||
#include "fade.h"
|
class MovingSprite;
|
||||||
#include "item.h"
|
class Player;
|
||||||
#include "player.h"
|
class Screen;
|
||||||
#include <iostream>
|
class SmartSprite;
|
||||||
|
class Sprite;
|
||||||
#ifndef GAME_H
|
class Text;
|
||||||
#define GAME_H
|
class Texture;
|
||||||
|
struct JA_Music_t;
|
||||||
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Cantidad de elementos a escribir en los ficheros de datos
|
// Cantidad de elementos a escribir en los ficheros de datos
|
||||||
#define TOTAL_SCORE_DATA 3
|
constexpr int TOTAL_SCORE_DATA = 3;
|
||||||
#define TOTAL_DEMO_DATA 2000
|
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||||
|
|
||||||
// Contadores
|
// Contadores
|
||||||
#define STAGE_COUNTER 200
|
constexpr int STAGE_COUNTER = 200;
|
||||||
#define SHAKE_COUNTER 10
|
constexpr int SHAKE_COUNTER = 10;
|
||||||
#define HELP_COUNTER 1000
|
constexpr int HELP_COUNTER = 1000;
|
||||||
#define GAME_COMPLETED_START_FADE 500
|
constexpr int GAME_COMPLETED_START_FADE = 500;
|
||||||
#define GAME_COMPLETED_END 700
|
constexpr int GAME_COMPLETED_END = 700;
|
||||||
|
|
||||||
// Formaciones enemigas
|
// Formaciones enemigas
|
||||||
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
constexpr int NUMBER_OF_ENEMY_FORMATIONS = 100;
|
||||||
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
constexpr int MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION = 50;
|
||||||
|
|
||||||
// Porcentaje de aparición de los objetos
|
// Porcentaje de aparición de los objetos
|
||||||
#define ITEM_POINTS_1_DISK_ODDS 10
|
constexpr int ITEM_POINTS_1_DISK_ODDS = 10;
|
||||||
#define ITEM_POINTS_2_GAVINA_ODDS 6
|
constexpr int ITEM_POINTS_2_GAVINA_ODDS = 6;
|
||||||
#define ITEM_POINTS_3_PACMAR_ODDS 3
|
constexpr int ITEM_POINTS_3_PACMAR_ODDS = 3;
|
||||||
#define ITEM_CLOCK_ODDS 5
|
constexpr int ITEM_CLOCK_ODDS = 5;
|
||||||
#define ITEM_COFFEE_ODDS 5
|
constexpr int ITEM_COFFEE_ODDS = 5;
|
||||||
#define ITEM_POWER_BALL_ODDS 0
|
constexpr int ITEM_POWER_BALL_ODDS = 0;
|
||||||
#define ITEM_COFFEE_MACHINE_ODDS 4
|
constexpr int ITEM_COFFEE_MACHINE_ODDS = 4;
|
||||||
|
|
||||||
// Valores para las variables asociadas a los objetos
|
// Valores para las variables asociadas a los objetos
|
||||||
#define TIME_STOPPED_COUNTER 300
|
constexpr int TIME_STOPPED_COUNTER = 300;
|
||||||
|
|
||||||
// Clase Game
|
// Clase Game
|
||||||
class Game
|
class Game
|
||||||
@@ -238,6 +240,9 @@ private:
|
|||||||
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
||||||
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
||||||
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
||||||
|
#ifdef PAUSE
|
||||||
|
bool pause;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Actualiza el juego
|
// Actualiza el juego
|
||||||
void update();
|
void update();
|
||||||
@@ -263,9 +268,6 @@ private:
|
|||||||
// Guarda el fichero de puntos
|
// Guarda el fichero de puntos
|
||||||
bool saveScoreFile();
|
bool saveScoreFile();
|
||||||
|
|
||||||
// Sube la puntuación online
|
|
||||||
bool sendOnlineScore();
|
|
||||||
|
|
||||||
// Guarda el fichero de datos para la demo
|
// Guarda el fichero de datos para la demo
|
||||||
bool saveDemoFile();
|
bool saveDemoFile();
|
||||||
|
|
||||||
@@ -525,5 +527,3 @@ public:
|
|||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,286 +0,0 @@
|
|||||||
#include "hiscore_table.h"
|
|
||||||
#include "common/jscore.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
const Uint8 SELF = 0;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section)
|
|
||||||
{
|
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
this->lang = lang;
|
|
||||||
this->section = section;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
|
|
||||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
|
||||||
if (backbuffer == nullptr)
|
|
||||||
{
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
section->name = SELF;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
manualQuit = false;
|
|
||||||
counter = 0;
|
|
||||||
counterEnd = 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
HiScoreTable::~HiScoreTable()
|
|
||||||
{
|
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
|
||||||
|
|
||||||
SDL_DestroyTexture(backbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void HiScoreTable::update()
|
|
||||||
{
|
|
||||||
// Comprueba los eventos
|
|
||||||
checkEventHandler();
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
checkInput();
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
|
||||||
{
|
|
||||||
// Actualiza el contador de ticks
|
|
||||||
ticks = SDL_GetTicks();
|
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
if (mode == mhst_auto)
|
|
||||||
{ // Modo automático
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
if (counter == counterEnd)
|
|
||||||
{
|
|
||||||
section->name = SECTION_PROG_TITLE;
|
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Modo manual
|
|
||||||
++counter %= 60000;
|
|
||||||
|
|
||||||
if (manualQuit)
|
|
||||||
{
|
|
||||||
section->name = SECTION_PROG_TITLE;
|
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pinta en pantalla
|
|
||||||
void HiScoreTable::render()
|
|
||||||
{
|
|
||||||
// Pinta en pantalla
|
|
||||||
SDL_Rect window = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
|
||||||
|
|
||||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
|
||||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
|
||||||
const int spaceBetweenHeader = 32;
|
|
||||||
const int spaceBetweenLines = text->getCharacterSize() * 1.8f;
|
|
||||||
|
|
||||||
// Pinta en el backbuffer el texto y los sprites
|
|
||||||
SDL_SetRenderTarget(renderer, backbuffer);
|
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Escribe el texto: Mejores puntuaciones
|
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 8, lang->getText(42), 1, orangeColor, 1, shdwTxtColor);
|
|
||||||
|
|
||||||
// Escribe la lista de jugadores
|
|
||||||
int numUsers = jscore::getNumUsers();
|
|
||||||
for (int i = 0; i < numUsers; ++i)
|
|
||||||
{
|
|
||||||
const std::string userName = jscore::getUserName(i).substr(0, 17);
|
|
||||||
const int nameLenght = (int)userName.length();
|
|
||||||
const int numDots = 20 - nameLenght;
|
|
||||||
std::string dots = "";
|
|
||||||
for (int j = 0; j < numDots; ++j)
|
|
||||||
{
|
|
||||||
dots = dots + ".";
|
|
||||||
}
|
|
||||||
const std::string line = userName + dots + scoreToString(jscore::getPoints(i));
|
|
||||||
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rellena la lista con otros nombres
|
|
||||||
if (numUsers < 10)
|
|
||||||
{
|
|
||||||
std::vector<std::string> names;
|
|
||||||
names.insert(names.end(), {"Bry", "Usufondo", "G.Lucas", "P.Delgat", "P.Arrabalera", "Pelechano", "Sahuquillo", "Bacteriol", "Pepe", "Rosita"});
|
|
||||||
|
|
||||||
for (int i = numUsers; i < 10; ++i)
|
|
||||||
{
|
|
||||||
const int nameLenght = names[i - numUsers].length();
|
|
||||||
const int numDots = 20 - nameLenght;
|
|
||||||
std::string dots = "";
|
|
||||||
for (int j = 0; j < numDots; ++j)
|
|
||||||
{
|
|
||||||
dots = dots + ".";
|
|
||||||
}
|
|
||||||
const std::string line = names[i - numUsers] + dots + "0000000";
|
|
||||||
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mode == mhst_manual) && (counter % 50 > 14))
|
|
||||||
{
|
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el destino de renderizado
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean(bgColor);
|
|
||||||
|
|
||||||
// Establece la ventana del backbuffer
|
|
||||||
if (mode == mhst_auto)
|
|
||||||
{
|
|
||||||
window.y = std::max(8, GAMECANVAS_HEIGHT - counter + 100);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
window.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copia el backbuffer al renderizador
|
|
||||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &window);
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los eventos
|
|
||||||
void HiScoreTable::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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
void HiScoreTable::checkInput()
|
|
||||||
{
|
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
section->name = SECTION_PROG_QUIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
if (mode == mhst_auto)
|
|
||||||
{
|
|
||||||
JA_StopMusic();
|
|
||||||
section->name = SECTION_PROG_TITLE;
|
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (counter > 30)
|
|
||||||
{
|
|
||||||
manualQuit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bucle para la pantalla de instrucciones
|
|
||||||
void HiScoreTable::run(mode_hiScoreTable_e mode)
|
|
||||||
{
|
|
||||||
this->mode = mode;
|
|
||||||
|
|
||||||
while (section->name == SELF)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string HiScoreTable::scoreToString(Uint32 num)
|
|
||||||
{
|
|
||||||
if ((num >= 0) && (num <= 9))
|
|
||||||
{
|
|
||||||
return ("000000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 10) && (num <= 99))
|
|
||||||
{
|
|
||||||
return ("00000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100) && (num <= 999))
|
|
||||||
{
|
|
||||||
return ("0000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000) && (num <= 9999))
|
|
||||||
{
|
|
||||||
return ("000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 010000) && (num <= 99999))
|
|
||||||
{
|
|
||||||
return ("00" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100000) && (num <= 999999))
|
|
||||||
{
|
|
||||||
return ("0" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000000) && (num <= 9999999))
|
|
||||||
{
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/input.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
#ifndef HISCORE_TABLE_H
|
|
||||||
#define HISCORE_TABLE_H
|
|
||||||
|
|
||||||
enum mode_hiScoreTable_e
|
|
||||||
{
|
|
||||||
mhst_manual,
|
|
||||||
mhst_auto
|
|
||||||
};
|
|
||||||
|
|
||||||
class HiScoreTable
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
|
||||||
Text *text; // Objeto para escribir texto
|
|
||||||
options_t *options; // Opciones y parametros del programa
|
|
||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
Uint16 counter; // Contador
|
|
||||||
Uint16 counterEnd; // Valor final para el contador
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
bool manualQuit; // Indica si se quiere salir del modo manual
|
|
||||||
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Pinta en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Comprueba los eventos
|
|
||||||
void checkEventHandler();
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
void checkInput();
|
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string scoreToString(Uint32 num);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~HiScoreTable();
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
void run(mode_hiScoreTable_e mode);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||||
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_events.h> // for SDL_ENABLE
|
||||||
|
#include <SDL2/SDL_joystick.h> // for SDL_NumJoysticks
|
||||||
|
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, basi...
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file)
|
Input::Input(std::string file)
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_G...
|
||||||
#include <string>
|
#include <SDL2/SDL_scancode.h> // for SDL_Scancode
|
||||||
#include <vector>
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
|
#include <string> // for string, basic_string
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
#ifndef INPUT_H
|
// Valores de repetición
|
||||||
#define INPUT_H
|
constexpr bool REPEAT_TRUE = true;
|
||||||
|
constexpr bool REPEAT_FALSE = false;
|
||||||
|
|
||||||
|
// Métodos de entrada
|
||||||
|
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||||
|
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||||
|
constexpr int INPUT_USE_ANY = 2;
|
||||||
|
|
||||||
enum inputs_e
|
enum inputs_e
|
||||||
{
|
{
|
||||||
@@ -32,13 +40,6 @@ enum inputs_e
|
|||||||
input_number_of_inputs
|
input_number_of_inputs
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REPEAT_TRUE true
|
|
||||||
#define REPEAT_FALSE false
|
|
||||||
|
|
||||||
#define INPUT_USE_KEYBOARD 0
|
|
||||||
#define INPUT_USE_GAMECONTROLLER 1
|
|
||||||
#define INPUT_USE_ANY 2
|
|
||||||
|
|
||||||
enum i_disable_e
|
enum i_disable_e
|
||||||
{
|
{
|
||||||
d_notDisabled,
|
d_notDisabled,
|
||||||
@@ -114,5 +115,3 @@ public:
|
|||||||
// Hablita las entradas
|
// Hablita las entradas
|
||||||
void enable();
|
void enable();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,21 @@
|
|||||||
#include "instructions.h"
|
#include "instructions.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <algorithm> // for max
|
||||||
|
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||||
|
#include <string> // for basic_string
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for shdwTxtColor, GAMECANVAS_CENTER_X, GAME...
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_StopMusic
|
||||||
|
#include "lang.h" // for Lang
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for color_t, section_t
|
||||||
|
|
||||||
const Uint8 SELF = 0;
|
const Uint8 SELF = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include "common/input.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint16, Uint32
|
||||||
#include "common/jail_audio.h"
|
#include <vector> // for vector
|
||||||
#include "common/screen.h"
|
class Asset;
|
||||||
#include "common/sprite.h"
|
class Input;
|
||||||
#include "common/text.h"
|
class Lang;
|
||||||
#include "common/utils.h"
|
class Screen;
|
||||||
#include "const.h"
|
class Sprite;
|
||||||
|
class Text;
|
||||||
#ifndef INSTRUCTIONS_H
|
class Texture;
|
||||||
#define INSTRUCTIONS_H
|
struct section_t;
|
||||||
|
|
||||||
enum mode_e
|
enum mode_e
|
||||||
{
|
{
|
||||||
@@ -66,5 +66,3 @@ public:
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run(mode_e mode);
|
void run(mode_e mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,4 +1,17 @@
|
|||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <string> // for basic_string
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QU...
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
|
||||||
|
#include "lang.h" // for Lang
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "smartsprite.h" // for SmartSprite
|
||||||
|
#include "text.h" // for Text
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for section_t, color_t
|
||||||
|
#include "writer.h" // for Writer
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section)
|
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section)
|
||||||
@@ -398,9 +411,6 @@ void Intro::update()
|
|||||||
|
|
||||||
// Actualiza las escenas de la intro
|
// Actualiza las escenas de la intro
|
||||||
updateScenes();
|
updateScenes();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/input.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||||
#include "common/jail_audio.h"
|
#include <vector> // for vector
|
||||||
#include "common/screen.h"
|
class Asset;
|
||||||
#include "common/smartsprite.h"
|
class Input;
|
||||||
#include "common/utils.h"
|
class Lang;
|
||||||
#include "common/writer.h"
|
class Screen;
|
||||||
#include "const.h"
|
class SmartSprite;
|
||||||
#include <vector>
|
class Text;
|
||||||
|
class Texture;
|
||||||
#ifndef INTRO_H
|
class Writer;
|
||||||
#define INTRO_H
|
struct JA_Music_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
// Clase Intro
|
// Clase Intro
|
||||||
class Intro
|
class Intro
|
||||||
@@ -65,5 +66,3 @@ public:
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
|
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_AR...
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(Uint8 kind, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
Item::Item(Uint8 kind, float x, float y, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16
|
||||||
#include "common/utils.h"
|
#include <string> // for string
|
||||||
|
#include <vector> // for vector
|
||||||
#ifndef ITEM_H
|
#include "utils.h" // for circle_t
|
||||||
#define ITEM_H
|
class AnimatedSprite;
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Tipos de objetos
|
// Tipos de objetos
|
||||||
#define ITEM_POINTS_1_DISK 0
|
constexpr int ITEM_POINTS_1_DISK = 1;
|
||||||
#define ITEM_POINTS_2_GAVINA 1
|
constexpr int ITEM_POINTS_2_GAVINA = 2;
|
||||||
#define ITEM_POINTS_3_PACMAR 2
|
constexpr int ITEM_POINTS_3_PACMAR = 3;
|
||||||
#define ITEM_CLOCK 3
|
constexpr int ITEM_CLOCK = 4;
|
||||||
#define ITEM_COFFEE 4
|
constexpr int ITEM_COFFEE = 5;
|
||||||
#define ITEM_COFFEE_MACHINE 5
|
constexpr int ITEM_COFFEE_MACHINE = 6;
|
||||||
|
|
||||||
// Clase Item
|
// Clase Item
|
||||||
class Item
|
class Item
|
||||||
@@ -41,6 +42,7 @@ private:
|
|||||||
|
|
||||||
// Actualiza la posición y estados del objeto
|
// Actualiza la posición y estados del objeto
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||||
|
|
||||||
@@ -56,7 +58,6 @@ public:
|
|||||||
// Pinta el objeto en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
|
||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
@@ -93,5 +94,3 @@ public:
|
|||||||
// Informa si el objeto ha colisionado con el suelo
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
bool isOnFloor();
|
bool isOnFloor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
#ifndef JA_USESDLMIXER
|
#ifndef JA_USESDLMIXER
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "stb_vorbis.c"
|
#include <SDL2/SDL_log.h> // for SDL_Log, SDL_LogSetPriority, SDL_LOG_CAT...
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
|
||||||
#include <stdio.h>
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <stdint.h> // for uint8_t, uint32_t
|
||||||
|
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
|
||||||
|
#include <stdlib.h> // for free, malloc
|
||||||
|
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
|
||||||
|
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||||
|
|
||||||
struct JA_Sound_t {
|
struct JA_Sound_t {
|
||||||
Uint32 length {0};
|
Uint32 length {0};
|
||||||
@@ -20,6 +24,7 @@ struct JA_Channel_t {
|
|||||||
|
|
||||||
struct JA_Music_t {
|
struct JA_Music_t {
|
||||||
int samples {0};
|
int samples {0};
|
||||||
|
Uint32 length {0};
|
||||||
int pos {0};
|
int pos {0};
|
||||||
int times {0};
|
int times {0};
|
||||||
short* output {NULL};
|
short* output {NULL};
|
||||||
@@ -32,19 +37,41 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
|||||||
int JA_freq {48000};
|
int JA_freq {48000};
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||||
Uint8 JA_channels {2};
|
Uint8 JA_channels {2};
|
||||||
int JA_volume = 128;
|
int JA_musicVolume = 128;
|
||||||
|
int JA_soundVolume = 64;
|
||||||
|
bool JA_musicEnabled = true;
|
||||||
|
bool JA_soundEnabled = true;
|
||||||
SDL_AudioDeviceID sdlAudioDevice = 0;
|
SDL_AudioDeviceID sdlAudioDevice = 0;
|
||||||
|
|
||||||
|
bool fading = false;
|
||||||
|
int fade_start_time;
|
||||||
|
int fade_duration;
|
||||||
|
int fade_initial_volume;
|
||||||
|
|
||||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||||
SDL_memset(stream, 0, len);
|
SDL_memset(stream, 0, len);
|
||||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
int volume = JA_musicVolume;
|
||||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
if (fading) {
|
||||||
current_music->pos += size/2;
|
int time = SDL_GetTicks();
|
||||||
|
if (time > (fade_start_time+fade_duration)) {
|
||||||
|
fading = false;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
volume = 0;
|
||||||
|
} else {
|
||||||
|
const int time_passed = time - fade_start_time;
|
||||||
|
const float percent = (float)time_passed / (float)fade_duration;
|
||||||
|
volume = JA_musicVolume * (1.0 - percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const int size = SDL_min(len, current_music->length - current_music->pos);
|
||||||
|
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output)+current_music->pos, AUDIO_S16, size, volume);
|
||||||
|
current_music->pos += size;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (current_music->times != 0) {
|
if (current_music->times != 0) {
|
||||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, volume);
|
||||||
current_music->pos = (len-size)/2;
|
current_music->pos = len-size;
|
||||||
if (current_music->times > 0) current_music->times--;
|
if (current_music->times > 0) current_music->times--;
|
||||||
} else {
|
} else {
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
@@ -56,11 +83,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
|
||||||
channels[i].pos += size;
|
channels[i].pos += size;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (channels[i].times != 0) {
|
if (channels[i].times != 0) {
|
||||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_soundVolume);
|
||||||
channels[i].pos = len-size;
|
channels[i].pos = len-size;
|
||||||
if (channels[i].times > 0) channels[i].times--;
|
if (channels[i].times > 0) channels[i].times--;
|
||||||
} else {
|
} else {
|
||||||
@@ -71,13 +98,19 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
||||||
|
#endif
|
||||||
|
|
||||||
JA_freq = freq;
|
JA_freq = freq;
|
||||||
JA_format = format;
|
JA_format = format;
|
||||||
JA_channels = channels;
|
JA_channels = channels;
|
||||||
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
||||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||||
|
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +120,35 @@ void JA_Quit() {
|
|||||||
sdlAudioDevice = 0;
|
sdlAudioDevice = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
||||||
|
{
|
||||||
int chan, samplerate;
|
int chan, samplerate;
|
||||||
|
JA_Music_t *music = new JA_Music_t();
|
||||||
|
|
||||||
|
music->samples = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &music->output);
|
||||||
|
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||||
|
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||||
|
if (cvt.needed) {
|
||||||
|
cvt.len = music->samples * chan * 2;
|
||||||
|
music->length = cvt.len;
|
||||||
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
free(music->output);
|
||||||
|
music->output = (short*)cvt.buf;
|
||||||
|
}
|
||||||
|
music->length = music->samples * chan * 2;
|
||||||
|
music->pos = 0;
|
||||||
|
music->state = JA_MUSIC_STOPPED;
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music_t *JA_LoadMusic(const char* filename)
|
||||||
|
{
|
||||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||||
FILE *f = fopen(filename, "rb");
|
FILE *f = fopen(filename, "rb");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@@ -99,30 +158,17 @@ JA_Music_t *JA_LoadMusic(const char* filename) {
|
|||||||
if (fread(buffer, fsize, 1, f)!=1) return NULL;
|
if (fread(buffer, fsize, 1, f)!=1) return NULL;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
JA_Music_t *music = new JA_Music_t();
|
JA_Music_t *music = JA_LoadMusic(buffer, fsize);
|
||||||
|
|
||||||
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
|
||||||
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
|
||||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
|
||||||
if (cvt.needed) {
|
|
||||||
cvt.len = music->samples * chan * 2;
|
|
||||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
|
||||||
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
|
||||||
SDL_ConvertAudio(&cvt);
|
|
||||||
free(music->output);
|
|
||||||
music->output = (short*)cvt.buf;
|
|
||||||
}
|
|
||||||
music->pos = 0;
|
|
||||||
music->state = JA_MUSIC_STOPPED;
|
|
||||||
|
|
||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
|
||||||
if (current_music != NULL) {
|
if (current_music != NULL) {
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
@@ -133,23 +179,45 @@ void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
|||||||
current_music->times = loop;
|
current_music->times = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_PauseMusic() {
|
void JA_PauseMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
current_music->state = JA_MUSIC_PAUSED;
|
current_music->state = JA_MUSIC_PAUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_ResumeMusic() {
|
void JA_ResumeMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
current_music->state = JA_MUSIC_PLAYING;
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_StopMusic() {
|
void JA_StopMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JA_FadeOutMusic(const int milliseconds)
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
|
||||||
|
fading = true;
|
||||||
|
fade_start_time = SDL_GetTicks();
|
||||||
|
fade_duration = milliseconds;
|
||||||
|
fade_initial_volume = JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState() {
|
JA_Music_state JA_GetMusicState() {
|
||||||
|
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
||||||
|
|
||||||
if (current_music == NULL) return JA_MUSIC_INVALID;
|
if (current_music == NULL) return JA_MUSIC_INVALID;
|
||||||
return current_music->state;
|
return current_music->state;
|
||||||
}
|
}
|
||||||
@@ -160,6 +228,35 @@ void JA_DeleteMusic(JA_Music_t *music) {
|
|||||||
delete music;
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int JA_SetMusicVolume(int volume)
|
||||||
|
{
|
||||||
|
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||||
|
return JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_SetMusicPosition(float value)
|
||||||
|
{
|
||||||
|
if (!current_music) return;
|
||||||
|
current_music->pos = value * JA_freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
float JA_GetMusicPosition()
|
||||||
|
{
|
||||||
|
if (!current_music) return 0;
|
||||||
|
return float(current_music->pos)/float(JA_freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_EnableMusic(const bool value)
|
||||||
|
{
|
||||||
|
if (!value && current_music != NULL && current_music->state==JA_MUSIC_PLAYING) JA_StopMusic();
|
||||||
|
|
||||||
|
JA_musicEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||||
JA_Sound_t *sound = new JA_Sound_t();
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
sound->buffer = buffer;
|
sound->buffer = buffer;
|
||||||
@@ -167,6 +264,24 @@ JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
|||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
||||||
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
|
SDL_AudioSpec wavSpec;
|
||||||
|
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||||
|
cvt.len = sound->length;
|
||||||
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
SDL_FreeWAV(sound->buffer);
|
||||||
|
sound->buffer = cvt.buf;
|
||||||
|
sound->length = cvt.len_cvt;
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
JA_Sound_t *JA_LoadSound(const char* filename) {
|
||||||
JA_Sound_t *sound = new JA_Sound_t();
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
SDL_AudioSpec wavSpec;
|
SDL_AudioSpec wavSpec;
|
||||||
@@ -185,7 +300,10 @@ JA_Sound_t *JA_LoadSound(const char* filename) {
|
|||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return -1;
|
||||||
|
|
||||||
int channel = 0;
|
int channel = 0;
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
||||||
@@ -197,7 +315,21 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return -1;
|
||||||
|
|
||||||
|
if (channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1;
|
||||||
|
|
||||||
|
channels[channel].sound = sound;
|
||||||
|
channels[channel].times = loop;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_DeleteSound(JA_Sound_t *sound)
|
||||||
|
{
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||||
}
|
}
|
||||||
@@ -205,7 +337,10 @@ void JA_DeleteSound(JA_Sound_t *sound) {
|
|||||||
delete sound;
|
delete sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_PauseChannel(const int channel) {
|
void JA_PauseChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return;
|
||||||
|
|
||||||
if (channel == -1) {
|
if (channel == -1) {
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
|
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
|
||||||
@@ -215,7 +350,10 @@ void JA_PauseChannel(const int channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_ResumeChannel(const int channel) {
|
void JA_ResumeChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return;
|
||||||
|
|
||||||
if (channel == -1) {
|
if (channel == -1) {
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
|
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
|
||||||
@@ -225,7 +363,10 @@ void JA_ResumeChannel(const int channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_StopChannel(const int channel) {
|
void JA_StopChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return;
|
||||||
|
|
||||||
if (channel == -1) {
|
if (channel == -1) {
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
channels[i].state = JA_CHANNEL_FREE;
|
channels[i].state = JA_CHANNEL_FREE;
|
||||||
@@ -239,13 +380,34 @@ void JA_StopChannel(const int channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
JA_Channel_state JA_GetChannelState(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
|
||||||
|
|
||||||
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
||||||
return channels[channel].state;
|
return channels[channel].state;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JA_SetVolume(int volume) {
|
int JA_SetSoundVolume(int volume)
|
||||||
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
{
|
||||||
return JA_volume;
|
JA_soundVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||||
|
return JA_soundVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JA_EnableSound(const bool value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
JA_soundEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume)
|
||||||
|
{
|
||||||
|
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||||
|
JA_soundVolume = JA_musicVolume/2;
|
||||||
|
return JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
#include <SDL2/SDL_audio.h> // for SDL_AudioFormat
|
||||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||||
|
struct JA_Music_t; // lines 8-8
|
||||||
|
struct JA_Sound_t; // lines 7-7
|
||||||
|
|
||||||
|
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED };
|
||||||
|
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
|
||||||
|
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
@@ -11,20 +15,30 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
|
|||||||
void JA_Quit();
|
void JA_Quit();
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename);
|
JA_Music_t *JA_LoadMusic(const char* filename);
|
||||||
|
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length);
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
||||||
void JA_PauseMusic();
|
void JA_PauseMusic();
|
||||||
void JA_ResumeMusic();
|
void JA_ResumeMusic();
|
||||||
void JA_StopMusic();
|
void JA_StopMusic();
|
||||||
|
void JA_FadeOutMusic(const int milliseconds);
|
||||||
JA_Music_state JA_GetMusicState();
|
JA_Music_state JA_GetMusicState();
|
||||||
void JA_DeleteMusic(JA_Music_t *music);
|
void JA_DeleteMusic(JA_Music_t *music);
|
||||||
|
int JA_SetMusicVolume(int volume);
|
||||||
|
void JA_SetMusicPosition(float value);
|
||||||
|
float JA_GetMusicPosition();
|
||||||
|
void JA_EnableMusic(const bool value);
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
||||||
|
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename);
|
JA_Sound_t *JA_LoadSound(const char* filename);
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
||||||
|
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
|
||||||
void JA_PauseChannel(const int channel);
|
void JA_PauseChannel(const int channel);
|
||||||
void JA_ResumeChannel(const int channel);
|
void JA_ResumeChannel(const int channel);
|
||||||
void JA_StopChannel(const int channel);
|
void JA_StopChannel(const int channel);
|
||||||
JA_Channel_state JA_GetChannelState(const int channel);
|
JA_Channel_state JA_GetChannelState(const int channel);
|
||||||
void JA_DeleteSound(JA_Sound_t *sound);
|
void JA_DeleteSound(JA_Sound_t *sound);
|
||||||
|
int JA_SetSoundVolume(int volume);
|
||||||
|
void JA_EnableSound(const bool value);
|
||||||
|
|
||||||
int JA_SetVolume(int volume);
|
int JA_SetVolume(int volume);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include <iostream>
|
#include <fstream> // for basic_ifstream, basic_istream, ifstream
|
||||||
#include <fstream>
|
#include "asset.h" // for Asset
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Lang::Lang(Asset *mAsset)
|
Lang::Lang(Asset *mAsset)
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include "common/asset.h"
|
#include <string> // for string, basic_string
|
||||||
#include <string>
|
class Asset;
|
||||||
|
|
||||||
#ifndef LANG_H
|
|
||||||
#define LANG_H
|
|
||||||
|
|
||||||
// Códigos de idioma
|
// Códigos de idioma
|
||||||
#define es_ES 0
|
constexpr int es_ES = 0;
|
||||||
#define ba_BA 1
|
constexpr int ba_BA = 1;
|
||||||
#define en_UK 2
|
constexpr int en_UK = 2;
|
||||||
#define MAX_LANGUAGES 3
|
constexpr int MAX_LANGUAGES = 3;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
#define MAX_TEXT_STRINGS 100
|
constexpr int MAX_TEXT_STRINGS = 100;
|
||||||
|
|
||||||
// Clase Lang
|
// Clase Lang
|
||||||
class Lang
|
class Lang
|
||||||
@@ -36,4 +33,3 @@ public:
|
|||||||
// Obtiene la cadena de texto del indice
|
// Obtiene la cadena de texto del indice
|
||||||
std::string getText(int index);
|
std::string getText(int index);
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,19 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <algorithm> // for min
|
||||||
|
#include <string> // for basic_string
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for bgColor, SECTION_PROG_LOGO, SECTION_PROG...
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_StopMusic
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for section_t, color_t
|
||||||
|
|
||||||
#define INIT_FADE 100
|
// Valores de inicialización y fin
|
||||||
#define END_LOGO 200
|
constexpr int INIT_FADE = 100;
|
||||||
|
constexpr int END_LOGO = 200;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section)
|
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section)
|
||||||
@@ -119,9 +131,6 @@ void Logo::update()
|
|||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
checkLogoEnd();
|
checkLogoEnd();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/input.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include "common/jail_audio.h"
|
class Asset;
|
||||||
#include "common/screen.h"
|
class Input;
|
||||||
#include "common/sprite.h"
|
class Screen;
|
||||||
#include "common/utils.h"
|
class Sprite;
|
||||||
#include "const.h"
|
class Texture;
|
||||||
|
struct section_t;
|
||||||
#ifndef LOGO_H
|
|
||||||
#define LOGO_H
|
|
||||||
|
|
||||||
// Clase Logo
|
// Clase Logo
|
||||||
class Logo
|
class Logo
|
||||||
@@ -59,5 +57,3 @@ public:
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -39,24 +39,14 @@ Reescribiendo el código el 27/09/2022
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "director.h"
|
#include "director.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::cout << "Starting the game..." << std::endl
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
// Crea el objeto Director
|
// Crea el objeto Director
|
||||||
Director *director = new Director(argc, argv);
|
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
director->run();
|
return director->run();
|
||||||
|
|
||||||
// Destruye el objeto Director
|
|
||||||
delete director;
|
|
||||||
|
|
||||||
std::cout << "\nShutting down the game..." << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#include "../const.h"
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include <iostream>
|
#include <algorithm> // for max, min
|
||||||
|
#include <fstream> // for char_traits, basic_ifstream, basic_istream
|
||||||
|
#include <sstream> // for basic_stringstream
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_LoadSound, JA_PlaySound, JA_DeleteSound
|
||||||
|
#include "text.h" // for Text
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
||||||
@@ -1,30 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "asset.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "input.h"
|
#include <string> // for string, basic_string
|
||||||
#include "jail_audio.h"
|
#include <vector> // for vector
|
||||||
#include "sprite.h"
|
#include "utils.h" // for color_t
|
||||||
#include "text.h"
|
class Asset;
|
||||||
#include "utils.h"
|
class Input;
|
||||||
#include <fstream>
|
class Text;
|
||||||
#include <sstream>
|
struct JA_Sound_t;
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef MENU_H
|
// Tipos de fondos para el menú
|
||||||
#define MENU_H
|
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
|
||||||
|
constexpr int MENU_BACKGROUND_SOLID = 1;
|
||||||
// Tipos de fondos para el menu
|
|
||||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
|
||||||
#define MENU_BACKGROUND_SOLID 1
|
|
||||||
|
|
||||||
// Tipos de archivos de audio
|
// Tipos de archivos de audio
|
||||||
#define SOUND_ACCEPT 0
|
constexpr int SOUND_ACCEPT = 0;
|
||||||
#define SOUND_MOVE 1
|
constexpr int SOUND_MOVE = 1;
|
||||||
#define SOUND_CANCEL 2
|
constexpr int SOUND_CANCEL = 2;
|
||||||
|
|
||||||
// Opciones de menu
|
// Opciones de menú
|
||||||
#define MENU_NO_OPTION -1
|
constexpr int MENU_NO_OPTION = -1;
|
||||||
|
|
||||||
// Clase Menu
|
// Clase Menu
|
||||||
class Menu
|
class Menu
|
||||||
@@ -232,5 +228,3 @@ public:
|
|||||||
// Establece el rectangulo de fondo del menu
|
// Establece el rectangulo de fondo del menu
|
||||||
void setRectSize(int w = 0, int h = 0);
|
void setRectSize(int w = 0, int h = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||||
#include "sprite.h"
|
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||||
#ifndef MOVINGSPRITE_H
|
#include "sprite.h" // for Sprite
|
||||||
#define MOVINGSPRITE_H
|
class Texture;
|
||||||
|
|
||||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||||
class MovingSprite : public Sprite
|
class MovingSprite : public Sprite
|
||||||
@@ -163,5 +163,3 @@ public:
|
|||||||
// Devuelve el incremento en el eje X en pixels
|
// Devuelve el incremento en el eje X en pixels
|
||||||
int getIncX();
|
int getIncX();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
|
#include "const.h" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT
|
||||||
|
#include "input.h" // for inputs_e
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
Player::Player(float x, int y, SDL_Renderer *renderer, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||||
|
|||||||
@@ -1,31 +1,29 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||||
#include "common/asset.h"
|
#include <string> // for string
|
||||||
#include "common/input.h"
|
#include <vector> // for vector
|
||||||
#include "common/texture.h"
|
#include "utils.h" // for circle_t
|
||||||
#include "common/utils.h"
|
class AnimatedSprite;
|
||||||
|
class Texture;
|
||||||
#ifndef PLAYER_H
|
|
||||||
#define PLAYER_H
|
|
||||||
|
|
||||||
// Contadores
|
// Contadores
|
||||||
#define DEATH_COUNTER 350
|
constexpr int DEATH_COUNTER = 350;
|
||||||
|
|
||||||
// Estados del jugador
|
// Estados del jugador
|
||||||
#define PLAYER_STATUS_WALKING_LEFT 0
|
constexpr int PLAYER_STATUS_WALKING_LEFT = 0;
|
||||||
#define PLAYER_STATUS_WALKING_RIGHT 1
|
constexpr int PLAYER_STATUS_WALKING_RIGHT = 1;
|
||||||
#define PLAYER_STATUS_WALKING_STOP 2
|
constexpr int PLAYER_STATUS_WALKING_STOP = 2;
|
||||||
|
|
||||||
#define PLAYER_STATUS_FIRING_UP 0
|
constexpr int PLAYER_STATUS_FIRING_UP = 0;
|
||||||
#define PLAYER_STATUS_FIRING_LEFT 1
|
constexpr int PLAYER_STATUS_FIRING_LEFT = 1;
|
||||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
constexpr int PLAYER_STATUS_FIRING_RIGHT = 2;
|
||||||
#define PLAYER_STATUS_FIRING_NO 3
|
constexpr int PLAYER_STATUS_FIRING_NO = 3;
|
||||||
|
|
||||||
// Variables del jugador
|
// Variables del jugador
|
||||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
|
||||||
#define PLAYER_POWERUP_COUNTER 1500
|
constexpr int PLAYER_POWERUP_COUNTER = 1500;
|
||||||
|
|
||||||
// Clase Player
|
// Clase Player
|
||||||
class Player
|
class Player
|
||||||
@@ -217,5 +215,3 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint16 getDeathCounter();
|
Uint16 getDeathCounter();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include <string>
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <iostream>
|
#include <SDL2/SDL_events.h> // for SDL_DISABLE, SDL_ENABLE
|
||||||
|
#include <SDL2/SDL_mouse.h> // for SDL_ShowCursor
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <algorithm> // for max, min
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
|
#include <string> // for basic_string, char_traits, string
|
||||||
|
class Asset;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||||
@@ -11,9 +17,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
this->options = options;
|
this->options = options;
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
|
||||||
// Crea los objetos
|
|
||||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
|
||||||
|
|
||||||
gameCanvasWidth = options->gameWidth;
|
gameCanvasWidth = options->gameWidth;
|
||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
borderWidth = options->borderWidth * 2;
|
borderWidth = options->borderWidth * 2;
|
||||||
@@ -47,7 +50,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen()
|
||||||
{
|
{
|
||||||
delete notify;
|
|
||||||
SDL_DestroyTexture(gameCanvas);
|
SDL_DestroyTexture(gameCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +79,6 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -178,9 +177,6 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
options->videoMode = videoMode;
|
options->videoMode = videoMode;
|
||||||
options->screen.windowWidth = windowWidth;
|
options->screen.windowWidth = windowWidth;
|
||||||
options->screen.windowHeight = windowHeight;
|
options->screen.windowHeight = windowHeight;
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
setNotificationSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
@@ -384,53 +380,3 @@ 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 text1, std::string text2, int icon)
|
|
||||||
{
|
|
||||||
notify->showText(text1, text2, icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,17 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||||
#include "asset.h"
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "notify.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include "utils.h"
|
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||||
#include "../const.h"
|
#include <vector> // for vector
|
||||||
#include <vector>
|
#include "utils.h" // for color_t
|
||||||
|
class Asset;
|
||||||
|
|
||||||
#ifndef SCREEN_H
|
// Tipos de filtro
|
||||||
#define SCREEN_H
|
constexpr int FILTER_NEAREST = 0;
|
||||||
|
constexpr int FILTER_LINEAL = 1;
|
||||||
#define FILTER_NEAREST 0
|
|
||||||
#define FILTER_LINEAL 1
|
|
||||||
|
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
@@ -22,7 +21,6 @@ private:
|
|||||||
Asset *asset; // Objeto con el listado de recursos
|
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 windowWidth; // Ancho de la pantalla o ventana
|
int windowWidth; // Ancho de la pantalla o ventana
|
||||||
@@ -64,12 +62,6 @@ 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, Asset *asset, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||||
@@ -134,12 +126,4 @@ 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 text1 = "", std::string text2 = "", int icon = -1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "smartsprite.h"
|
#include "smartsprite.h"
|
||||||
|
#include "movingsprite.h" // for MovingSprite
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SmartSprite::SmartSprite(Texture *texture, SDL_Renderer *renderer)
|
SmartSprite::SmartSprite(Texture *texture, SDL_Renderer *renderer)
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
#include "utils.h"
|
class Texture;
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef SMARTSPRITE_H
|
|
||||||
#define SMARTSPRITE_H
|
|
||||||
|
|
||||||
// Clase SmartSprite
|
// Clase SmartSprite
|
||||||
class SmartSprite : public AnimatedSprite
|
class SmartSprite : public AnimatedSprite
|
||||||
@@ -69,5 +65,3 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool hasFinished();
|
bool hasFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "texture.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
|
class Texture;
|
||||||
#ifndef SPRITE_H
|
|
||||||
#define SPRITE_H
|
|
||||||
|
|
||||||
// Clase sprite
|
// Clase sprite
|
||||||
class Sprite
|
class Sprite
|
||||||
@@ -92,5 +90,3 @@ public:
|
|||||||
// Establece los valores de posición y tamaño del sprite
|
// Establece los valores de posición y tamaño del sprite
|
||||||
void setRect(SDL_Rect rect);
|
void setRect(SDL_Rect rect);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <iostream>
|
#include <fstream> // for char_traits, basic_ostream, basic_ifstream, ope...
|
||||||
#include <fstream>
|
#include <iostream> // for cout
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for color_t
|
||||||
|
|
||||||
// Llena una estructuta textFile_t desde un fichero
|
// Llena una estructuta textFile_t desde un fichero
|
||||||
textFile_t LoadTextFile(std::string file, bool verbose)
|
textFile_t LoadTextFile(std::string file, bool verbose)
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sprite.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
|
#include <string> // for string
|
||||||
|
class Sprite;
|
||||||
|
class Texture;
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef TEXT_H
|
// Opciones de texto
|
||||||
#define TEXT_H
|
constexpr int TXT_COLOR = 1;
|
||||||
|
constexpr int TXT_SHADOW = 2;
|
||||||
#define TXT_COLOR 1
|
constexpr int TXT_CENTER = 4;
|
||||||
#define TXT_SHADOW 2
|
constexpr int TXT_STROKE = 8;
|
||||||
#define TXT_CENTER 4
|
|
||||||
#define TXT_STROKE 8
|
|
||||||
|
|
||||||
struct offset_t
|
struct offset_t
|
||||||
{
|
{
|
||||||
@@ -64,7 +66,7 @@ public:
|
|||||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||||
|
|
||||||
// Escribe texto con extras
|
// Escribe texto con extras
|
||||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = color_t(255, 255, 255), Uint8 shadowDistance = 1, color_t shadowColor = color_t(0, 0, 0), int lenght = -1);
|
||||||
|
|
||||||
// Obtiene la longitud en pixels de una cadena
|
// Obtiene la longitud en pixels de una cadena
|
||||||
int lenght(std::string text, int kerning = 1);
|
int lenght(std::string text, int kerning = 1);
|
||||||
@@ -78,5 +80,3 @@ public:
|
|||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void setFixedWidth(bool value);
|
void setFixedWidth(bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
|
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_log.h> // for SDL_Log
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT...
|
||||||
|
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
||||||
|
#include <stdlib.h> // for exit
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h" // for stbi_failure_reason, stbi_image_free
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||||
#include <stdio.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||||
#include <string>
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#ifndef TEXTURE_H
|
#include <string> // for basic_string, string
|
||||||
#define TEXTURE_H
|
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
@@ -62,5 +61,3 @@ public:
|
|||||||
// Obtiene la textura
|
// Obtiene la textura
|
||||||
SDL_Texture *getSDLTexture();
|
SDL_Texture *getSDLTexture();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,25 @@
|
|||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "common/jscore.h"
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLS...
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
|
||||||
|
#include <string> // for basic_string, operator+, char_traits
|
||||||
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for GAMECANVAS_CENTER_X, SECTION_PROG_QUIT
|
||||||
|
#include "fade.h" // for Fade
|
||||||
|
#include "game.h" // for Game
|
||||||
|
#include "input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_...
|
||||||
|
#include "jail_audio.h" // for JA_StopMusic, JA_GetMusicState, JA_Play...
|
||||||
|
#include "lang.h" // for Lang, ba_BA, en_UK, es_ES
|
||||||
|
#include "menu.h" // for Menu
|
||||||
|
#include "screen.h" // for Screen, FILTER_LINEAL, FILTER_NEAREST
|
||||||
|
#include "smartsprite.h" // for SmartSprite
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
||||||
@@ -206,9 +226,6 @@ void Title::init()
|
|||||||
|
|
||||||
// Actualiza los textos de los menus
|
// Actualiza los textos de los menus
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
|
|
||||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
|
||||||
setHiScoreTableOptionMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -223,9 +240,6 @@ void Title::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
switch (section->subsection)
|
switch (section->subsection)
|
||||||
{
|
{
|
||||||
// Sección 1 - Titulo desplazandose
|
// Sección 1 - Titulo desplazandose
|
||||||
@@ -321,10 +335,6 @@ void Title::update()
|
|||||||
{
|
{
|
||||||
runInstructions(m_auto);
|
runInstructions(m_auto);
|
||||||
}
|
}
|
||||||
if (section->name != SECTION_PROG_QUIT)
|
|
||||||
{
|
|
||||||
runHiScoreTable(mhst_auto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_LOGO;
|
||||||
@@ -478,23 +488,13 @@ void Title::update()
|
|||||||
runInstructions(m_manual);
|
runInstructions(m_manual);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 12: // HISCORE TABLE
|
case 12: // ACCEPT
|
||||||
runHiScoreTable(mhst_manual);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 13: // JAILERID:
|
|
||||||
runEnterID();
|
|
||||||
setHiScoreTableOptionMenu();
|
|
||||||
updateMenuLabels();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 14: // ACCEPT
|
|
||||||
applyOptions();
|
applyOptions();
|
||||||
menu.active->reset();
|
menu.active->reset();
|
||||||
menu.active = menu.title;
|
menu.active = menu.title;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 15: // CANCEL
|
case 13: // CANCEL
|
||||||
options = &optionsPrevious;
|
options = &optionsPrevious;
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
menu.active->reset();
|
menu.active->reset();
|
||||||
@@ -515,10 +515,6 @@ void Title::update()
|
|||||||
{
|
{
|
||||||
if (demo)
|
if (demo)
|
||||||
{
|
{
|
||||||
if (section->name != SECTION_PROG_QUIT)
|
|
||||||
{
|
|
||||||
runHiScoreTable(mhst_auto);
|
|
||||||
}
|
|
||||||
runDemoGame();
|
runDemoGame();
|
||||||
if (section->name != SECTION_PROG_QUIT)
|
if (section->name != SECTION_PROG_QUIT)
|
||||||
{
|
{
|
||||||
@@ -918,15 +914,6 @@ void Title::updateMenuLabels()
|
|||||||
// HOW TO PLAY
|
// HOW TO PLAY
|
||||||
menu.options->setItemCaption(i, lang->getText(2));
|
menu.options->setItemCaption(i, lang->getText(2));
|
||||||
|
|
||||||
i++;
|
|
||||||
// HISCORE TABLE
|
|
||||||
menu.options->setItemCaption(i, lang->getText(93));
|
|
||||||
|
|
||||||
i++;
|
|
||||||
// JAILERID;
|
|
||||||
const std::string jailerID = options->online.jailerID == "" ? lang->getText(64) : options->online.jailerID;
|
|
||||||
menu.options->setItemCaption(i, "JAILERID: " + jailerID);
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// ACCEPT
|
// ACCEPT
|
||||||
menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT
|
menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT
|
||||||
@@ -1004,22 +991,6 @@ void Title::runInstructions(mode_e mode)
|
|||||||
delete instructions;
|
delete instructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la parte donde se muestra la tabla de puntuaciones
|
|
||||||
void Title::runHiScoreTable(mode_hiScoreTable_e mode)
|
|
||||||
{
|
|
||||||
if (!options->online.enabled)
|
|
||||||
{
|
|
||||||
section->name = SECTION_PROG_TITLE;
|
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section);
|
|
||||||
hiScoreTable->run(mode);
|
|
||||||
delete hiScoreTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ejecuta el juego en modo demo
|
// Ejecuta el juego en modo demo
|
||||||
void Title::runDemoGame()
|
void Title::runDemoGame()
|
||||||
{
|
{
|
||||||
@@ -1028,14 +999,6 @@ void Title::runDemoGame()
|
|||||||
delete demoGame;
|
delete demoGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Introduce el JailerID
|
|
||||||
void Title::runEnterID()
|
|
||||||
{
|
|
||||||
enterID = new EnterID(renderer, screen, asset, lang, options, section);
|
|
||||||
enterID->run();
|
|
||||||
delete enterID;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
bool Title::updatePlayerInputs(int numPlayer)
|
bool Title::updatePlayerInputs(int numPlayer)
|
||||||
{
|
{
|
||||||
@@ -1187,18 +1150,3 @@ void Title::reLoadTextures()
|
|||||||
gradientTexture->reLoad();
|
gradientTexture->reLoad();
|
||||||
createTiledBackground();
|
createTiledBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
|
||||||
void Title::setHiScoreTableOptionMenu()
|
|
||||||
{
|
|
||||||
if (options->online.sessionEnabled)
|
|
||||||
{
|
|
||||||
menu.options->setSelectable(12, true);
|
|
||||||
menu.options->setGreyed(12, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
menu.options->setSelectable(12, false);
|
|
||||||
menu.options->setGreyed(12, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "common/input.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include "common/jail_audio.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||||
#include "common/menu.h"
|
#include <vector> // for vector
|
||||||
#include "common/movingsprite.h"
|
#include "instructions.h" // for mode_e
|
||||||
#include "common/screen.h"
|
#include "utils.h" // for input_t, options_t, section_t
|
||||||
#include "common/smartsprite.h"
|
class AnimatedSprite;
|
||||||
#include "common/sprite.h"
|
class Asset;
|
||||||
#include "common/text.h"
|
class Fade;
|
||||||
#include "common/utils.h"
|
class Game;
|
||||||
#include "const.h"
|
class Input;
|
||||||
#include "fade.h"
|
class Lang;
|
||||||
#include "game.h"
|
class Menu;
|
||||||
#include "enter_id.h"
|
class Screen;
|
||||||
#include "hiscore_table.h"
|
class SmartSprite;
|
||||||
#include "instructions.h"
|
class Sprite;
|
||||||
#include "item.h"
|
class Text;
|
||||||
|
class Texture;
|
||||||
#ifndef TITLE_H
|
struct JA_Music_t;
|
||||||
#define TITLE_H
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
#define TEXT_COPYRIGHT "@2020,2023 JailDesigner (v2.3)"
|
constexpr const char *TEXT_COPYRIGHT = "@2020,2023 JailDesigner (v2.3.2)";
|
||||||
|
|
||||||
// Contadores
|
// Contadores
|
||||||
#define TITLE_COUNTER 800
|
constexpr int TITLE_COUNTER = 800;
|
||||||
|
|
||||||
// Cantidad de eventos de la pantalla de titulo
|
// Cantidad de eventos de la pantalla de título
|
||||||
#define TITLE_TOTAL_EVENTS 2
|
constexpr int TITLE_TOTAL_EVENTS = 2;
|
||||||
|
|
||||||
class Title
|
class Title
|
||||||
{
|
{
|
||||||
@@ -50,9 +50,7 @@ private:
|
|||||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
Instructions *instructions; // Objeto para la sección de las instrucciones
|
Instructions *instructions; // Objeto para la sección de las instrucciones
|
||||||
HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online
|
|
||||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
Game *demoGame; // Objeto para lanzar la demo del juego
|
||||||
EnterID *enterID; // Objeto para introducir o modificar el JailerID
|
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
section_t *section; // Indicador para el bucle del titulo
|
section_t *section; // Indicador para el bucle del titulo
|
||||||
|
|
||||||
@@ -125,15 +123,9 @@ private:
|
|||||||
// Ejecuta la parte donde se muestran las instrucciones
|
// Ejecuta la parte donde se muestran las instrucciones
|
||||||
void runInstructions(mode_e mode);
|
void runInstructions(mode_e mode);
|
||||||
|
|
||||||
// Ejecuta la parte donde se muestra la tabla de puntuaciones
|
|
||||||
void runHiScoreTable(mode_hiScoreTable_e mode);
|
|
||||||
|
|
||||||
// Ejecuta el juego en modo demo
|
// Ejecuta el juego en modo demo
|
||||||
void runDemoGame();
|
void runDemoGame();
|
||||||
|
|
||||||
// Introduce el JailerID
|
|
||||||
void runEnterID();
|
|
||||||
|
|
||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
bool updatePlayerInputs(int numPlayer);
|
bool updatePlayerInputs(int numPlayer);
|
||||||
|
|
||||||
@@ -146,9 +138,6 @@ private:
|
|||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
void reLoadTextures();
|
void reLoadTextures();
|
||||||
|
|
||||||
// Comprueba si se puede acceder a la tabla de puntuaciones y habilita la opción de menu
|
|
||||||
void setHiScoreTableOptionMenu();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section);
|
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section);
|
||||||
@@ -159,5 +148,3 @@ public:
|
|||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <math.h>
|
#include <stdlib.h> // for abs, free, malloc
|
||||||
|
#include <cmath> // for round, abs
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||||
@@ -1,21 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||||
#include "texture.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
|
||||||
#include <string>
|
#include <string> // for string, basic_string
|
||||||
#include <vector>
|
#include <vector> // for vector
|
||||||
|
|
||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
// Dificultad del juego
|
// Dificultad del juego
|
||||||
#define DIFFICULTY_EASY 0
|
constexpr int DIFFICULTY_EASY = 0;
|
||||||
#define DIFFICULTY_NORMAL 1
|
constexpr int DIFFICULTY_NORMAL = 1;
|
||||||
#define DIFFICULTY_HARD 2
|
constexpr int DIFFICULTY_HARD = 2;
|
||||||
|
|
||||||
// Tipo de filtro
|
|
||||||
#define FILTER_NEAREST 0
|
|
||||||
#define FILTER_LINEAL 1
|
|
||||||
|
|
||||||
// Estructura para definir un circulo
|
// Estructura para definir un circulo
|
||||||
struct circle_t
|
struct circle_t
|
||||||
@@ -55,6 +48,9 @@ struct color_t
|
|||||||
Uint8 r;
|
Uint8 r;
|
||||||
Uint8 g;
|
Uint8 g;
|
||||||
Uint8 b;
|
Uint8 b;
|
||||||
|
|
||||||
|
color_t() : r(0), g(0), b(0) {} // Constructor por defecto
|
||||||
|
color_t(Uint8 red, Uint8 green, Uint8 blue) : r(red), g(green), b(blue) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tipos de paleta
|
// Tipos de paleta
|
||||||
@@ -64,16 +60,6 @@ enum palette_e
|
|||||||
p_zxarne
|
p_zxarne
|
||||||
};
|
};
|
||||||
|
|
||||||
// Posiciones de las notificaciones
|
|
||||||
enum not_pos_e
|
|
||||||
{
|
|
||||||
pos_top,
|
|
||||||
pos_bottom,
|
|
||||||
pos_left,
|
|
||||||
pos_middle,
|
|
||||||
pos_right
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para saber la seccion y subseccion del programa
|
// Estructura para saber la seccion y subseccion del programa
|
||||||
struct section_t
|
struct section_t
|
||||||
{
|
{
|
||||||
@@ -100,18 +86,6 @@ struct input_t
|
|||||||
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
|
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para el servicio online
|
|
||||||
struct online_t
|
|
||||||
{
|
|
||||||
bool enabled; // Indica si se quiere usar el modo online o no
|
|
||||||
bool sessionEnabled; // Indica ya se ha hecho login
|
|
||||||
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 con opciones de la pantalla
|
// Estructura con opciones de la pantalla
|
||||||
struct op_screen_t
|
struct op_screen_t
|
||||||
{
|
{
|
||||||
@@ -119,15 +93,6 @@ struct op_screen_t
|
|||||||
int windowHeight; // Alto de la ventana
|
int windowHeight; // Alto de la ventana
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para las opciones de las notificaciones
|
|
||||||
struct op_notification_t
|
|
||||||
{
|
|
||||||
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
|
||||||
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
|
||||||
bool sound; // Indica si las notificaciones suenan
|
|
||||||
color_t color; // Color de las notificaciones
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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
|
||||||
{
|
{
|
||||||
@@ -150,9 +115,7 @@ struct options_t
|
|||||||
palette_e palette; // Paleta de colores a usar en el juego
|
palette_e palette; // Paleta de colores a usar en el juego
|
||||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||||
|
|
||||||
online_t online; // Datos del servicio online
|
|
||||||
op_screen_t screen; // Opciones relativas a la clase screen
|
op_screen_t screen; // Opciones relativas a la clase screen
|
||||||
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
@@ -202,5 +165,3 @@ std::string boolToString(bool value);
|
|||||||
|
|
||||||
// Convierte una cadena a minusculas
|
// Convierte una cadena a minusculas
|
||||||
std::string toLower(std::string str);
|
std::string toLower(std::string str);
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
|
#include "text.h" // for Text
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Writer::Writer(Text *text)
|
Writer::Writer(Text *text)
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <string> // for string, basic_string
|
||||||
#include "sprite.h"
|
class Text;
|
||||||
#include "text.h"
|
|
||||||
|
|
||||||
#ifndef WRITER_H
|
|
||||||
#define WRITER_H
|
|
||||||
|
|
||||||
// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un bitmap
|
// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un bitmap
|
||||||
class Writer
|
class Writer
|
||||||
@@ -71,5 +67,3 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool hasFinished();
|
bool hasFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user