Compare commits
77 Commits
2024-10-28
...
2024-12-05
| Author | SHA1 | Date | |
|---|---|---|---|
| e3d0145417 | |||
| f0863b3691 | |||
| 80e366b208 | |||
| 3c5bbf2ab0 | |||
| 1aa0dd3864 | |||
| ab45c984a2 | |||
| 020ee81479 | |||
| 0cd96aced5 | |||
| ad32bb7d45 | |||
| c3a5166ee1 | |||
| 687d329d23 | |||
| faba87c06d | |||
| eed45bdbc6 | |||
| 6ed37425bf | |||
| b987d06aca | |||
| 9c9cfdabc2 | |||
| 9f2448753b | |||
| 736bf7e544 | |||
| a2d4331430 | |||
| fd7beee5a1 | |||
| a36120cf0c | |||
| ad221243cb | |||
| b8d4c8f17c | |||
| 8941072357 | |||
| 77bf1d73b3 | |||
| 700d3846fb | |||
| 185a1b47d1 | |||
| 121774e460 | |||
| 47e468034f | |||
| da74b8dfce | |||
| 065336c310 | |||
| 79d25fb812 | |||
| 6262b5814d | |||
| f9520185a2 | |||
| 2fb7e88e4b | |||
| 0e527ff9d9 | |||
| d902bb9088 | |||
| caf04e3a7e | |||
| 12213a3dab | |||
| 1f2a8ae38d | |||
| aa8d3502e2 | |||
| e445a0b218 | |||
| 3f9c4b887f | |||
| 27ccae6132 | |||
| 443f0f3254 | |||
| 2e62214a4b | |||
| 7b1c2a6005 | |||
| 2256ee46eb | |||
| 087fd3377c | |||
| 30735f00e8 | |||
| e0e82ee273 | |||
| 371c477d0d | |||
| f29eb2f411 | |||
| 69a92cba66 | |||
| 86cd7b0f16 | |||
| a1ccb6102a | |||
| 2dd8bbbbf7 | |||
| c66cc965f1 | |||
| 0757f63b73 | |||
| 80a110e1d7 | |||
| cd68c5ffea | |||
| f786cb7776 | |||
| 2e0d27a95c | |||
| 861a9411d3 | |||
| da27fde366 | |||
| c6e2368e82 | |||
| 30dfa4c545 | |||
| 7e2691e33e | |||
| 7e918e99f7 | |||
| 2aa3f827cb | |||
| 06899d95a8 | |||
| 20c51d0796 | |||
| b43782786a | |||
| 15554c449f | |||
| ba05eab79e | |||
| d83c05bad4 | |||
| e2abf835f9 |
85
CMakeLists.txt
Normal file
@@ -0,0 +1,85 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(coffee_crisis_arcade_edition VERSION 0.01)
|
||||
|
||||
# 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 opengl32 gdi32 winmm imm32 ole32 version)
|
||||
elseif(APPLE)
|
||||
set(LIBS ${LIBS} "-framework OpenGL")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
|
||||
# Configurar compilación para Apple Silicon
|
||||
set(CMAKE_OSX_ARCHITECTURES "arm64")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(LIBS ${LIBS} GL)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD)
|
||||
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||
endif()
|
||||
|
||||
# Añadir OpenGL a las bibliotecas enlazadas
|
||||
if(NOT WIN32)
|
||||
find_package(OpenGL REQUIRED)
|
||||
if(OPENGL_FOUND)
|
||||
message(STATUS "OpenGL encontrado: ${OPENGL_LIBRARIES}")
|
||||
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
|
||||
else()
|
||||
message(FATAL_ERROR "OpenGL no encontrado")
|
||||
endif()
|
||||
endif()
|
||||
91
Makefile
@@ -50,84 +50,7 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
OBJECTS := $(subst $(DIR_SOURCES), $(DIR_BUILD), $(SOURCES))
|
||||
OBJECTS := $(OBJECTS:.cpp=.o)
|
||||
DEPENDENCIES:= $(OBJECTS:.o=.d)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# #
|
||||
# RULES #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
.PHONY: all a1
|
||||
|
||||
all: a1
|
||||
|
||||
a1: $(TARGET_FILE)
|
||||
|
||||
$(TARGET_FILE): $(OBJECTS)
|
||||
$(MKD) $(@D)
|
||||
$(CXX) $(OBJECTS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||
|
||||
$(DIR_BUILD)%.o: $(DIR_SOURCES)%.cpp
|
||||
$(MKD) $(@D)
|
||||
$(CXX) -c $< $(CXXFLAGS) $(INCLUDES) -o $@
|
||||
|
||||
-include $(DEPENDENCIES)
|
||||
|
||||
###############################################################################
|
||||
# #
|
||||
# CLEAN #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
$(RM) $(call FixPath,$(DIR_BUILD))
|
||||
|
||||
###############################################################################
|
||||
# #
|
||||
# PRINT-VARIABLES #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
.PHONY: print-variables
|
||||
|
||||
print-variables:
|
||||
@echo MAKEFILE_LIST: $(MAKEFILE_LIST)
|
||||
|
||||
@echo "DIR_ROOT :" $(DIR_ROOT)
|
||||
@echo "DIR_SOURCES:" $(DIR_SOURCES)
|
||||
@echo "DIR_BIN :" $(DIR_BIN)
|
||||
@echo "DIR_BUILD :" $(DIR_BUILD)
|
||||
|
||||
@echo "DIR_IMGUI :" $(DIR_IMGUI)
|
||||
@echo "DIR_IMGUI_SFML:" $(DIR_IMGUI_SFML)
|
||||
@echo "INCLUDES :" $(INCLUDES)
|
||||
|
||||
@echo CXX: $(CXX)
|
||||
@echo CXXFLAGS: $(CXXFLAGS)
|
||||
@echo LDFLAGS: $(LDFLAGS)
|
||||
|
||||
@echo SOURCES: $(SOURCES)
|
||||
@echo OBJECTS: $(OBJECTS)
|
||||
@echo DEPENDENCIES: $(DEPENDENCIES)
|
||||
|
||||
@echo TARGET_NAME: $(TARGET_NAME)
|
||||
@echo TARGET_FILE: $(TARGET_FILE)
|
||||
|
||||
@echo RM: $(RM)
|
||||
|
||||
raspi:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
||||
|
||||
raspi_debug:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE -D DEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
||||
|
||||
# Rules
|
||||
windows:
|
||||
@echo off
|
||||
$(CXX) $(SOURCES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE).exe"
|
||||
@@ -249,6 +172,13 @@ linux_release:
|
||||
# Elimina la carpeta temporal
|
||||
$(RM) "$(RELEASE_FOLDER)"
|
||||
|
||||
raspi:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
||||
|
||||
raspi_debug:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE -D DEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
||||
|
||||
anbernic:
|
||||
# Elimina carpetas previas
|
||||
$(RM) "$(RELEASE_FOLDER)"_anbernic
|
||||
@@ -259,6 +189,5 @@ anbernic:
|
||||
# Copia ficheros
|
||||
cp -R data "$(RELEASE_FOLDER)"_anbernic
|
||||
|
||||
# Complia
|
||||
$(CXX) $(SOURCES) -D ANBERNIC -D NO_SHADERS -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME)
|
||||
$(CXX) $(SOURCES) -D ANBERNIC -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME).shaders
|
||||
# Compila
|
||||
$(CXX) $(SOURCES) -D ANBERNIC -D NO_SHADERS -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME)
|
||||
@@ -28,6 +28,10 @@ Les tecles son les següents:
|
||||
|
||||
- **Tecla F4**: Activa o desactiva els shaders
|
||||
|
||||
- **Tecla F5**: Activa o desactiva l'audio
|
||||
|
||||
- **Tecla F6**: Canvia el idioma del joc i reinicia
|
||||
|
||||
- **Tecla F10**: Reset
|
||||
|
||||
<p align="center">
|
||||
|
||||
@@ -6,7 +6,7 @@ game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 200 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
game.enter_name_seconds 60 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
|
||||
## FADE
|
||||
fade.num_squares_width 160
|
||||
|
||||
@@ -6,8 +6,7 @@ game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 216 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
game.game_text.dest_y
|
||||
game.enter_name_seconds 60 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
|
||||
## FADE
|
||||
fade.num_squares_width 160
|
||||
|
||||
BIN
data/font/04b_25.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
@@ -1,194 +1,194 @@
|
||||
# box width
|
||||
10
|
||||
14
|
||||
# box height
|
||||
10
|
||||
14
|
||||
# 32 espacio ( )
|
||||
5
|
||||
8
|
||||
# 33 !
|
||||
4
|
||||
5
|
||||
# 34 "
|
||||
5
|
||||
# 35 #
|
||||
7
|
||||
8
|
||||
# 35
|
||||
10
|
||||
# 36 $
|
||||
7
|
||||
10
|
||||
# 37 %
|
||||
8
|
||||
9
|
||||
# 38 &
|
||||
8
|
||||
11
|
||||
# 39 '
|
||||
3
|
||||
5
|
||||
# 40 (
|
||||
5
|
||||
7
|
||||
# 41 )
|
||||
5
|
||||
7
|
||||
# 42 *
|
||||
7
|
||||
7
|
||||
# 43 +
|
||||
7
|
||||
9
|
||||
# 44 ,
|
||||
4
|
||||
5
|
||||
# 45 -
|
||||
6
|
||||
9
|
||||
# 46 .
|
||||
4
|
||||
5
|
||||
# 47 /
|
||||
5
|
||||
12
|
||||
# 48 0
|
||||
7
|
||||
# 49 1
|
||||
5
|
||||
# 50 2
|
||||
7
|
||||
# 51 3
|
||||
7
|
||||
# 52 4
|
||||
7
|
||||
# 53 5
|
||||
7
|
||||
# 54 6
|
||||
7
|
||||
# 55 7
|
||||
7
|
||||
# 56 8
|
||||
7
|
||||
# 57 9
|
||||
7
|
||||
# 58 :
|
||||
4
|
||||
# 59 ;
|
||||
4
|
||||
# 60 <
|
||||
6
|
||||
# 61 =
|
||||
6
|
||||
# 62 >
|
||||
6
|
||||
# 63 ?
|
||||
7
|
||||
# 64 @
|
||||
8
|
||||
# 65 A
|
||||
7
|
||||
# 66 B
|
||||
7
|
||||
# 67 C
|
||||
7
|
||||
# 68 D
|
||||
7
|
||||
# 69 E
|
||||
7
|
||||
# 70 F
|
||||
7
|
||||
# 71 G
|
||||
7
|
||||
# 72 H
|
||||
7
|
||||
# 73 I
|
||||
4
|
||||
# 74 J
|
||||
# 49 1
|
||||
6
|
||||
# 50 2
|
||||
8
|
||||
# 51 3
|
||||
8
|
||||
# 52 4
|
||||
8
|
||||
# 53 5
|
||||
8
|
||||
# 54 6
|
||||
8
|
||||
# 55 7
|
||||
8
|
||||
# 56 8
|
||||
8
|
||||
# 57 9
|
||||
8
|
||||
# 58 :
|
||||
5
|
||||
# 59 ;
|
||||
5
|
||||
# 60 <
|
||||
8
|
||||
# 61 =
|
||||
8
|
||||
# 62 >
|
||||
8
|
||||
# 63 ?
|
||||
8
|
||||
# 64 @
|
||||
11
|
||||
# 65 A
|
||||
8
|
||||
# 66 B
|
||||
8
|
||||
# 67 C
|
||||
8
|
||||
# 68 D
|
||||
8
|
||||
# 69 E
|
||||
8
|
||||
# 70 F
|
||||
8
|
||||
# 71 G
|
||||
8
|
||||
# 72 H
|
||||
8
|
||||
# 73 I
|
||||
5
|
||||
# 74 J
|
||||
8
|
||||
# 75 K
|
||||
8
|
||||
# 76 L
|
||||
6
|
||||
8
|
||||
# 77 M
|
||||
9
|
||||
11
|
||||
# 78 N
|
||||
8
|
||||
# 79 O
|
||||
8
|
||||
# 80 P
|
||||
7
|
||||
8
|
||||
# 81 Q
|
||||
8
|
||||
# 82 R
|
||||
7
|
||||
# 83 S
|
||||
6
|
||||
# 84 T
|
||||
8
|
||||
# 83 S
|
||||
8
|
||||
# 84 T
|
||||
9
|
||||
# 85 U
|
||||
7
|
||||
8
|
||||
# 86 V
|
||||
8
|
||||
# 87 W
|
||||
9
|
||||
11
|
||||
# 88 X
|
||||
8
|
||||
# 89 Y
|
||||
8
|
||||
# 90 Z
|
||||
7
|
||||
# 91 [
|
||||
4
|
||||
# 92 \
|
||||
5
|
||||
# 93 ]
|
||||
4
|
||||
# 94 ^
|
||||
5
|
||||
# 95 _
|
||||
8
|
||||
# 91 [
|
||||
7
|
||||
# 92 \
|
||||
11
|
||||
# 93 ]
|
||||
7
|
||||
# 94 ^
|
||||
6
|
||||
# 95 _
|
||||
7
|
||||
# 96 `
|
||||
4
|
||||
6
|
||||
# 97 a
|
||||
7
|
||||
8
|
||||
# 98 b
|
||||
7
|
||||
8
|
||||
# 99 c
|
||||
6
|
||||
8
|
||||
# 100 d
|
||||
7
|
||||
8
|
||||
# 101 e
|
||||
7
|
||||
8
|
||||
# 102 f
|
||||
5
|
||||
8
|
||||
# 103 g
|
||||
7
|
||||
8
|
||||
# 104 h
|
||||
7
|
||||
8
|
||||
# 105 i
|
||||
4
|
||||
5
|
||||
# 106 j
|
||||
5
|
||||
8
|
||||
# 107 k
|
||||
7
|
||||
8
|
||||
# 108 l
|
||||
4
|
||||
8
|
||||
# 109 m
|
||||
10
|
||||
11
|
||||
# 110 n
|
||||
7
|
||||
8
|
||||
# 111 o
|
||||
7
|
||||
8
|
||||
# 112 p
|
||||
7
|
||||
8
|
||||
# 113 q
|
||||
7
|
||||
8
|
||||
# 114 r
|
||||
6
|
||||
8
|
||||
# 115 s
|
||||
6
|
||||
8
|
||||
# 116 t
|
||||
5
|
||||
# 117 u
|
||||
7
|
||||
# 118 v
|
||||
7
|
||||
# 119 w
|
||||
9
|
||||
# 117 u
|
||||
8
|
||||
# 118 v
|
||||
8
|
||||
# 119 w
|
||||
11
|
||||
# 120 x
|
||||
7
|
||||
8
|
||||
# 121 y
|
||||
7
|
||||
8
|
||||
# 122 z
|
||||
7
|
||||
# 123 { -> ñ
|
||||
7
|
||||
# 124 | -> ç
|
||||
7
|
||||
8
|
||||
# 123 {
|
||||
1
|
||||
# 124 |
|
||||
1
|
||||
# 125 }
|
||||
0
|
||||
1
|
||||
# 126 ~
|
||||
0
|
||||
1
|
||||
BIN
data/font/04b_25_2x.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
@@ -1,43 +1,43 @@
|
||||
# box width
|
||||
16
|
||||
28
|
||||
# box height
|
||||
16
|
||||
28
|
||||
# 32 espacio ( )
|
||||
16
|
||||
# 33 !
|
||||
16
|
||||
10
|
||||
# 34 "
|
||||
16
|
||||
# 35 #
|
||||
16
|
||||
# 35
|
||||
20
|
||||
# 36 $
|
||||
16
|
||||
20
|
||||
# 37 %
|
||||
16
|
||||
18
|
||||
# 38 &
|
||||
16
|
||||
22
|
||||
# 39 '
|
||||
16
|
||||
10
|
||||
# 40 (
|
||||
16
|
||||
14
|
||||
# 41 )
|
||||
16
|
||||
14
|
||||
# 42 *
|
||||
16
|
||||
14
|
||||
# 43 +
|
||||
16
|
||||
18
|
||||
# 44 ,
|
||||
16
|
||||
10
|
||||
# 45 -
|
||||
16
|
||||
18
|
||||
# 46 .
|
||||
16
|
||||
10
|
||||
# 47 /
|
||||
16
|
||||
24
|
||||
# 48 0
|
||||
16
|
||||
# 49 1
|
||||
16
|
||||
12
|
||||
# 50 2
|
||||
16
|
||||
# 51 3
|
||||
@@ -55,9 +55,9 @@
|
||||
# 57 9
|
||||
16
|
||||
# 58 :
|
||||
16
|
||||
10
|
||||
# 59 ;
|
||||
16
|
||||
10
|
||||
# 60 <
|
||||
16
|
||||
# 61 =
|
||||
@@ -67,7 +67,7 @@
|
||||
# 63 ?
|
||||
16
|
||||
# 64 @
|
||||
16
|
||||
22
|
||||
# 65 A
|
||||
16
|
||||
# 66 B
|
||||
@@ -85,7 +85,7 @@
|
||||
# 72 H
|
||||
16
|
||||
# 73 I
|
||||
16
|
||||
10
|
||||
# 74 J
|
||||
16
|
||||
# 75 K
|
||||
@@ -93,7 +93,7 @@
|
||||
# 76 L
|
||||
16
|
||||
# 77 M
|
||||
16
|
||||
22
|
||||
# 78 N
|
||||
16
|
||||
# 79 O
|
||||
@@ -107,13 +107,13 @@
|
||||
# 83 S
|
||||
16
|
||||
# 84 T
|
||||
16
|
||||
18
|
||||
# 85 U
|
||||
16
|
||||
# 86 V
|
||||
16
|
||||
# 87 W
|
||||
16
|
||||
22
|
||||
# 88 X
|
||||
16
|
||||
# 89 Y
|
||||
@@ -121,17 +121,17 @@
|
||||
# 90 Z
|
||||
16
|
||||
# 91 [
|
||||
16
|
||||
14
|
||||
# 92 \
|
||||
16
|
||||
22
|
||||
# 93 ]
|
||||
16
|
||||
14
|
||||
# 94 ^
|
||||
16
|
||||
12
|
||||
# 95 _
|
||||
16
|
||||
14
|
||||
# 96 `
|
||||
16
|
||||
12
|
||||
# 97 a
|
||||
16
|
||||
# 98 b
|
||||
@@ -149,7 +149,7 @@
|
||||
# 104 h
|
||||
16
|
||||
# 105 i
|
||||
16
|
||||
10
|
||||
# 106 j
|
||||
16
|
||||
# 107 k
|
||||
@@ -157,7 +157,7 @@
|
||||
# 108 l
|
||||
16
|
||||
# 109 m
|
||||
16
|
||||
22
|
||||
# 110 n
|
||||
16
|
||||
# 111 o
|
||||
@@ -171,13 +171,13 @@
|
||||
# 115 s
|
||||
16
|
||||
# 116 t
|
||||
16
|
||||
18
|
||||
# 117 u
|
||||
16
|
||||
# 118 v
|
||||
16
|
||||
# 119 w
|
||||
16
|
||||
22
|
||||
# 120 x
|
||||
16
|
||||
# 121 y
|
||||
@@ -185,10 +185,10 @@
|
||||
# 122 z
|
||||
16
|
||||
# 123 {
|
||||
16
|
||||
2
|
||||
# 124 |
|
||||
16
|
||||
2
|
||||
# 125 }
|
||||
16
|
||||
2
|
||||
# 126 ~
|
||||
16
|
||||
2
|
||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
@@ -1,194 +0,0 @@
|
||||
# box width
|
||||
20
|
||||
# box height
|
||||
20
|
||||
# 32 espacio ( )
|
||||
8
|
||||
# 33 !
|
||||
8
|
||||
# 34 "
|
||||
10
|
||||
# 35 #
|
||||
14
|
||||
# 36 $
|
||||
14
|
||||
# 37 %
|
||||
16
|
||||
# 38 &
|
||||
16
|
||||
# 39 '
|
||||
6
|
||||
# 40 (
|
||||
10
|
||||
# 41 )
|
||||
10
|
||||
# 42 *
|
||||
14
|
||||
# 43 +
|
||||
14
|
||||
# 44 ,
|
||||
8
|
||||
# 45 -
|
||||
12
|
||||
# 46 .
|
||||
8
|
||||
# 47 /
|
||||
10
|
||||
# 48 0
|
||||
14
|
||||
# 49 1
|
||||
10
|
||||
# 50 2
|
||||
14
|
||||
# 51 6
|
||||
14
|
||||
# 52 8
|
||||
14
|
||||
# 53 10
|
||||
14
|
||||
# 54 12
|
||||
14
|
||||
# 55 14
|
||||
14
|
||||
# 56 16
|
||||
14
|
||||
# 57 18
|
||||
14
|
||||
# 58 :
|
||||
8
|
||||
# 59 ;
|
||||
8
|
||||
# 60 <
|
||||
12
|
||||
# 61 =
|
||||
12
|
||||
# 62 >
|
||||
12
|
||||
# 63 ?
|
||||
14
|
||||
# 64 @
|
||||
16
|
||||
# 65 A
|
||||
14
|
||||
# 66 B
|
||||
14
|
||||
# 67 C
|
||||
14
|
||||
# 68 D
|
||||
14
|
||||
# 69 E
|
||||
14
|
||||
# 70 F
|
||||
14
|
||||
# 71 G
|
||||
14
|
||||
# 72 H
|
||||
14
|
||||
# 73 I
|
||||
8
|
||||
# 74 J
|
||||
12
|
||||
# 75 K
|
||||
16
|
||||
# 76 L
|
||||
12
|
||||
# 77 M
|
||||
18
|
||||
# 78 N
|
||||
16
|
||||
# 79 O
|
||||
16
|
||||
# 80 P
|
||||
14
|
||||
# 81 Q
|
||||
16
|
||||
# 82 R
|
||||
14
|
||||
# 83 S
|
||||
12
|
||||
# 84 T
|
||||
16
|
||||
# 85 U
|
||||
14
|
||||
# 86 V
|
||||
16
|
||||
# 87 W
|
||||
18
|
||||
# 88 X
|
||||
16
|
||||
# 89 Y
|
||||
16
|
||||
# 90 Z
|
||||
14
|
||||
# 91 [
|
||||
8
|
||||
# 92 \
|
||||
10
|
||||
# 93 ]
|
||||
8
|
||||
# 94 ^
|
||||
10
|
||||
# 95 _
|
||||
16
|
||||
# 96 `
|
||||
8
|
||||
# 97 a
|
||||
14
|
||||
# 98 b
|
||||
14
|
||||
# 99 c
|
||||
12
|
||||
# 100 d
|
||||
14
|
||||
# 101 e
|
||||
14
|
||||
# 102 f
|
||||
10
|
||||
# 103 g
|
||||
14
|
||||
# 104 h
|
||||
14
|
||||
# 105 i
|
||||
8
|
||||
# 106 j
|
||||
10
|
||||
# 107 k
|
||||
14
|
||||
# 108 l
|
||||
8
|
||||
# 109 m
|
||||
20
|
||||
# 110 n
|
||||
14
|
||||
# 111 o
|
||||
14
|
||||
# 112 p
|
||||
14
|
||||
# 113 q
|
||||
14
|
||||
# 114 r
|
||||
12
|
||||
# 115 s
|
||||
12
|
||||
# 116 t
|
||||
10
|
||||
# 117 u
|
||||
14
|
||||
# 118 v
|
||||
14
|
||||
# 119 w
|
||||
18
|
||||
# 120 x
|
||||
14
|
||||
# 121 y
|
||||
14
|
||||
# 122 z
|
||||
14
|
||||
# 123 { -> ñ
|
||||
14
|
||||
# 124 | -> ç
|
||||
14
|
||||
# 125 }
|
||||
0
|
||||
# 126 ~
|
||||
0
|
||||
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 295 B |
|
Before Width: | Height: | Size: 371 B |
|
Before Width: | Height: | Size: 332 B |
|
Before Width: | Height: | Size: 399 B |
|
Before Width: | Height: | Size: 453 B |
|
Before Width: | Height: | Size: 392 B |
@@ -23,29 +23,71 @@ frames=8,9,10,11
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-sideshoot
|
||||
name=walk-sideshoot-cooldown
|
||||
speed=5
|
||||
loop=0
|
||||
frames=12,13,14,15
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-centershoot
|
||||
name=stand-sideshoot
|
||||
speed=5
|
||||
loop=0
|
||||
frames=16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-centershoot
|
||||
name=stand-sideshoot-cooldown
|
||||
speed=5
|
||||
loop=0
|
||||
frames=15
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-centershoot
|
||||
speed=5
|
||||
loop=0
|
||||
frames=20,21,22,23
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=death
|
||||
speed=15
|
||||
name=walk-centershoot-cooldown
|
||||
speed=5
|
||||
loop=0
|
||||
frames=24,25,26,27
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-centershoot
|
||||
speed=5
|
||||
loop=0
|
||||
frames=28,29,30,31
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-centershoot-cooldown
|
||||
speed=5
|
||||
loop=0
|
||||
frames=27
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=dying
|
||||
speed=10
|
||||
loop=0
|
||||
frames=32,33,34,35
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=dead
|
||||
speed=3
|
||||
loop=0
|
||||
frames=44,45,46,47,48,49,50
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=celebration
|
||||
speed=10
|
||||
loop=-1
|
||||
frames=36,36,36,36,36,36,37,38,39,40,40,40,40,40,40,39,39,39,40,40,40,39,39,39,38,37,36,36,36
|
||||
[/animation]
|
||||
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 9.2 KiB |
@@ -158,19 +158,19 @@ Felicitats!!
|
||||
2 JUGADORS
|
||||
|
||||
## 53 MARCADOR
|
||||
jugador 1
|
||||
Jugador 1
|
||||
|
||||
## 54 MARCADOR
|
||||
jugador 2
|
||||
Jugador 2
|
||||
|
||||
## 55 MARCADOR
|
||||
mult
|
||||
Multiplicador
|
||||
|
||||
## 56 MARCADOR
|
||||
max. puntuacio
|
||||
Max. puntuacio
|
||||
|
||||
## 57 MARCADOR
|
||||
fase
|
||||
Fase
|
||||
|
||||
## 58 - MENU DE OPCIONES
|
||||
MODE DE VISUALITZACIO
|
||||
@@ -206,7 +206,7 @@ NORMAL
|
||||
DIFICIL
|
||||
|
||||
## 69 - MENU DE OPCIONES
|
||||
TECLAT
|
||||
Teclat
|
||||
|
||||
## 70 - MENU DE OPCIONES
|
||||
MANDO
|
||||
@@ -347,4 +347,28 @@ Per favor
|
||||
espere
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Torna a polsar per apagar el sistema
|
||||
Torna a polsar per apagar el sistema
|
||||
|
||||
## 117 - GAME TEXT
|
||||
SuperPoder!
|
||||
|
||||
## 118 - GAME TEXT
|
||||
+1 Colp
|
||||
|
||||
## 119 - GAME TEXT
|
||||
Temps!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Puntuacio
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMAT I DISSENYAT PER
|
||||
|
||||
## 122 - CREDITS
|
||||
GRAFICS DIBUIXATS PER
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSICA COMPOSADA PER
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTES DE SO
|
||||
@@ -158,19 +158,19 @@ Congratulations!!
|
||||
2 PLAYERS
|
||||
|
||||
## 53 - MARCADOR
|
||||
player 1
|
||||
Player 1
|
||||
|
||||
## 54 - MARCADOR
|
||||
player 2
|
||||
Player 2
|
||||
|
||||
## 55 - MARCADOR
|
||||
mult
|
||||
Multiplier
|
||||
|
||||
## 56 - MARCADOR
|
||||
high score
|
||||
High Score
|
||||
|
||||
## 57 - MARCADOR
|
||||
stage
|
||||
Stage
|
||||
|
||||
## 58 - MENU DE OPCIONES
|
||||
DISPLAY MODE
|
||||
@@ -206,7 +206,7 @@ NORMAL
|
||||
HARD
|
||||
|
||||
## 69 - MENU DE OPCIONES
|
||||
KEYBOARD
|
||||
Keyboard
|
||||
|
||||
## 70 - MENU DE OPCIONES
|
||||
GAME CONTROLLER
|
||||
@@ -347,4 +347,28 @@ Please
|
||||
wait
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Press again to shutdown system
|
||||
Press again to shutdown system
|
||||
|
||||
## 117 - GAME TEXT
|
||||
PowerUp
|
||||
|
||||
## 118 - GAME TEXT
|
||||
+1 Hit
|
||||
|
||||
## 119 - GAME TEXT
|
||||
Stop!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Score
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMMED AND DESIGNED BY
|
||||
|
||||
## 122 - CREDITS
|
||||
PIXELART DRAWN BY
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSIC COMPOSED BY
|
||||
|
||||
## 124 - CREDITS
|
||||
SOUND EFFECTS
|
||||
@@ -158,19 +158,19 @@ Felicidades!!
|
||||
2 JUGADORES
|
||||
|
||||
## 53 - MARCADOR
|
||||
jugador 1
|
||||
Jugador 1
|
||||
|
||||
## 54 - MARCADOR
|
||||
jugador 2
|
||||
Jugador 2
|
||||
|
||||
## 55 - MARCADOR
|
||||
mult
|
||||
Multiplicador
|
||||
|
||||
## 56 - MARCADOR
|
||||
max. puntuacion
|
||||
Max. puntuacion
|
||||
|
||||
## 57 - MARCADOR
|
||||
FASE
|
||||
Fase
|
||||
|
||||
## 58 - MENU DE OPCIONES
|
||||
MODO DE VISUALIZACION
|
||||
@@ -206,7 +206,7 @@ NORMAL
|
||||
DIFICIL
|
||||
|
||||
## 69 - MENU DE OPCIONES
|
||||
TECLADO
|
||||
Teclado
|
||||
|
||||
## 70 - MENU DE OPCIONES
|
||||
MANDO
|
||||
@@ -347,4 +347,28 @@ Por favor
|
||||
espere
|
||||
|
||||
## 94 - NOTIFICACIONES
|
||||
Pulsa otra vez para apagar el sistema
|
||||
Pulsa otra vez para apagar el sistema
|
||||
|
||||
## 117 - GAME TEXT
|
||||
Potenciador
|
||||
|
||||
## 118 - GAME TEXT
|
||||
+1 Golpe
|
||||
|
||||
## 119 - GAME TEXT
|
||||
Tiempo!
|
||||
|
||||
## 120 - SCOREBOARD
|
||||
Puntuacion
|
||||
|
||||
## 121 - CREDITS
|
||||
PROGRAMADO Y DISE{ADO POR
|
||||
|
||||
## 122 - CREDITS
|
||||
GRAFICOS DIBUJADOS POR
|
||||
|
||||
## 123 - CREDITS
|
||||
MUSICA COMPUESTA POR
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTOS DE SONIDO
|
||||
BIN
data/music/credits.ogg
Normal file
234
data/shaders/crtpi_240.glsl
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
crt-pi - A Raspberry Pi friendly CRT shader.
|
||||
|
||||
Copyright (C) 2015-2016 davej
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
|
||||
|
||||
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
|
||||
|
||||
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
|
||||
|
||||
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
|
||||
|
||||
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
|
||||
|
||||
BLOOM_FACTOR controls the increase in width for bright scanlines.
|
||||
|
||||
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
|
||||
|
||||
*/
|
||||
|
||||
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
|
||||
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
|
||||
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
|
||||
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
|
||||
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
|
||||
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
|
||||
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
|
||||
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
|
||||
|
||||
// Haven't put these as parameters as it would slow the code down.
|
||||
#define SCANLINES
|
||||
#define MULTISAMPLE
|
||||
#define GAMMA
|
||||
//#define FAKE_GAMMA
|
||||
//#define CURVATURE
|
||||
//#define SHARPER
|
||||
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
|
||||
#define MASK_TYPE 2
|
||||
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
precision mediump float;
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float CURVATURE_X;
|
||||
uniform COMPAT_PRECISION float CURVATURE_Y;
|
||||
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
|
||||
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
|
||||
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
|
||||
uniform COMPAT_PRECISION float BLOOM_FACTOR;
|
||||
uniform COMPAT_PRECISION float INPUT_GAMMA;
|
||||
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
|
||||
#else
|
||||
#define CURVATURE_X 0.05
|
||||
#define CURVATURE_Y 0.1
|
||||
#define MASK_BRIGHTNESS 0.80
|
||||
#define SCANLINE_WEIGHT 6.0
|
||||
#define SCANLINE_GAP_BRIGHTNESS 0.12
|
||||
#define BLOOM_FACTOR 3.5
|
||||
#define INPUT_GAMMA 2.4
|
||||
#define OUTPUT_GAMMA 2.2
|
||||
#endif
|
||||
|
||||
/* COMPATIBILITY
|
||||
- GLSL compilers
|
||||
*/
|
||||
|
||||
//uniform vec2 TextureSize;
|
||||
#if defined(CURVATURE)
|
||||
varying vec2 screenScale;
|
||||
#endif
|
||||
varying vec2 TEX0;
|
||||
varying float filterWidth;
|
||||
|
||||
#if defined(VERTEX)
|
||||
//uniform mat4 MVPMatrix;
|
||||
//attribute vec4 VertexCoord;
|
||||
//attribute vec2 TexCoord;
|
||||
//uniform vec2 InputSize;
|
||||
//uniform vec2 OutputSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(CURVATURE)
|
||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||
#endif
|
||||
filterWidth = (768.0 / 240.0) / 3.0;
|
||||
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
uniform sampler2D Texture;
|
||||
|
||||
#if defined(CURVATURE)
|
||||
vec2 Distort(vec2 coord)
|
||||
{
|
||||
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
|
||||
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
|
||||
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
|
||||
coord *= screenScale;
|
||||
coord -= vec2(0.5);
|
||||
float rsq = coord.x * coord.x + coord.y * coord.y;
|
||||
coord += coord * (CURVATURE_DISTORTION * rsq);
|
||||
coord *= barrelScale;
|
||||
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
|
||||
coord = vec2(-1.0); // If out of bounds, return an invalid value.
|
||||
else
|
||||
{
|
||||
coord += vec2(0.5);
|
||||
coord /= screenScale;
|
||||
}
|
||||
|
||||
return coord;
|
||||
}
|
||||
#endif
|
||||
|
||||
float CalcScanLineWeight(float dist)
|
||||
{
|
||||
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
|
||||
}
|
||||
|
||||
float CalcScanLine(float dy)
|
||||
{
|
||||
float scanLineWeight = CalcScanLineWeight(dy);
|
||||
#if defined(MULTISAMPLE)
|
||||
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
|
||||
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
|
||||
scanLineWeight *= 0.3333333;
|
||||
#endif
|
||||
return scanLineWeight;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 TextureSize = vec2(320.0, 240.0);
|
||||
#if defined(CURVATURE)
|
||||
vec2 texcoord = Distort(TEX0);
|
||||
if (texcoord.x < 0.0)
|
||||
gl_FragColor = vec4(0.0);
|
||||
else
|
||||
#else
|
||||
vec2 texcoord = TEX0;
|
||||
#endif
|
||||
{
|
||||
vec2 texcoordInPixels = texcoord * TextureSize;
|
||||
#if defined(SHARPER)
|
||||
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
|
||||
vec2 coord = tempCoord / TextureSize;
|
||||
vec2 deltas = texcoordInPixels - tempCoord;
|
||||
float scanLineWeight = CalcScanLine(deltas.y);
|
||||
vec2 signs = sign(deltas);
|
||||
deltas.x *= 2.0;
|
||||
deltas = deltas * deltas;
|
||||
deltas.y = deltas.y * deltas.y;
|
||||
deltas.x *= 0.5;
|
||||
deltas.y *= 8.0;
|
||||
deltas /= TextureSize;
|
||||
deltas *= signs;
|
||||
vec2 tc = coord + deltas;
|
||||
#else
|
||||
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||
float yCoord = tempY / TextureSize.y;
|
||||
float dy = texcoordInPixels.y - tempY;
|
||||
float scanLineWeight = CalcScanLine(dy);
|
||||
float signY = sign(dy);
|
||||
dy = dy * dy;
|
||||
dy = dy * dy;
|
||||
dy *= 8.0;
|
||||
dy /= TextureSize.y;
|
||||
dy *= signY;
|
||||
vec2 tc = vec2(texcoord.x, yCoord + dy);
|
||||
#endif
|
||||
|
||||
vec3 colour = texture2D(Texture, tc).rgb;
|
||||
|
||||
#if defined(SCANLINES)
|
||||
#if defined(GAMMA)
|
||||
#if defined(FAKE_GAMMA)
|
||||
colour = colour * colour;
|
||||
#else
|
||||
colour = pow(colour, vec3(INPUT_GAMMA));
|
||||
#endif
|
||||
#endif
|
||||
scanLineWeight *= BLOOM_FACTOR;
|
||||
colour *= scanLineWeight;
|
||||
|
||||
#if defined(GAMMA)
|
||||
#if defined(FAKE_GAMMA)
|
||||
colour = sqrt(colour);
|
||||
#else
|
||||
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if MASK_TYPE == 0
|
||||
gl_FragColor = vec4(colour, 1.0);
|
||||
#else
|
||||
#if MASK_TYPE == 1
|
||||
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
|
||||
vec3 mask;
|
||||
if (whichMask < 0.5)
|
||||
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
|
||||
else
|
||||
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
|
||||
#elif MASK_TYPE == 2
|
||||
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
|
||||
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
|
||||
if (whichMask < 0.3333333)
|
||||
mask.x = 1.0;
|
||||
else if (whichMask < 0.6666666)
|
||||
mask.y = 1.0;
|
||||
else
|
||||
mask.z = 1.0;
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(colour * mask, 1.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -97,7 +97,6 @@ void main()
|
||||
#if defined(CURVATURE)
|
||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||
#endif
|
||||
//filterWidth = (768.0 / 240.0) / 3.0;
|
||||
filterWidth = (768.0 / 256.0) / 3.0;
|
||||
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
BIN
data/sound/logo.wav
Normal file
@@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# warning,style,performance
|
||||
#cppcheck --force --enable=warning,style,performance --std=c++20 \
|
||||
# --suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \
|
||||
# /home/sergio/gitea/coffee_crisis_arcade_edition/source/ \
|
||||
# 2>/home/sergio/cppcheck-result-warning-style-performance.txt
|
||||
|
||||
# all
|
||||
#cppcheck --force --enable=all -I /usr/include --std=c++20 \
|
||||
#--suppress=missingIncludeSystem \
|
||||
#--suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \
|
||||
#/home/sergio/gitea/coffee_crisis_arcade_edition/source/ \
|
||||
#2>/home/sergio/cppcheck-result-all.txt
|
||||
|
||||
# unusedFunction
|
||||
cppcheck --enable=style --std=c++20 \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
../source/ \
|
||||
2>/home/sergio/cppcheck-result-all.txt
|
||||
53
linux_utils/run_cppcheck.sh
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Función para mostrar el uso del script
|
||||
mostrar_uso() {
|
||||
echo "Uso: $0 [-o opción]"
|
||||
echo "Opciones:"
|
||||
echo " w Ejecutar cppcheck con warning, style, performance"
|
||||
echo " a Ejecutar cppcheck con todas las opciones habilitadas"
|
||||
echo " u Ejecutar cppcheck para unusedFunction"
|
||||
}
|
||||
|
||||
# Inicializar las variables
|
||||
opcion=""
|
||||
|
||||
# Procesar las opciones
|
||||
while getopts "o:" opt; do
|
||||
case $opt in
|
||||
o)
|
||||
opcion=$OPTARG
|
||||
;;
|
||||
*)
|
||||
mostrar_uso
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Ejecutar según la opción seleccionada
|
||||
case $opcion in
|
||||
w)
|
||||
cppcheck --force --enable=warning,style,performance --std=c++20 \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
../source/ \
|
||||
2>./cppcheck-result-warning-style-performance.txt
|
||||
;;
|
||||
a)
|
||||
cppcheck --force --enable=all -I /usr/include --std=c++20 \
|
||||
--suppress=missingIncludeSystem \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
../source/ \
|
||||
2>./cppcheck-result-all.txt
|
||||
;;
|
||||
u)
|
||||
cppcheck --enable=style --std=c++20 \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
../source/ \
|
||||
2>./cppcheck-result-unusedFunction.txt
|
||||
;;
|
||||
*)
|
||||
mostrar_uso
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_Rect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
x_(x),
|
||||
y_(y),
|
||||
@@ -19,7 +19,8 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
creation_counter_ini_(creation_timer),
|
||||
type_(type),
|
||||
size_(size),
|
||||
speed_(speed)
|
||||
speed_(speed),
|
||||
play_area_(play_area)
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
@@ -28,13 +29,13 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
vy_ = 0;
|
||||
max_vy_ = 3.0f;
|
||||
|
||||
const int size = static_cast<int>(size_);
|
||||
gravity_ = param.balloon.at(size).grav;
|
||||
default_vy_ = param.balloon.at(size).vel;
|
||||
h_ = w_ = BALLOON_SIZE[size];
|
||||
power_ = BALLOON_POWER[size];
|
||||
menace_ = BALLOON_MENACE[size];
|
||||
score_ = BALLOON_SCORE[size];
|
||||
const int index = static_cast<int>(size_);
|
||||
gravity_ = param.balloon.at(index).grav;
|
||||
default_vy_ = param.balloon.at(index).vel;
|
||||
h_ = w_ = BALLOON_SIZE[index];
|
||||
power_ = BALLOON_POWER[index];
|
||||
menace_ = BALLOON_MENACE[index];
|
||||
score_ = BALLOON_SCORE[index];
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -44,28 +45,27 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
default_vy_ = max_vy_ = vy_ = fabs(vx_ * 2.0f);
|
||||
gravity_ = 0.00f;
|
||||
|
||||
const int size = static_cast<int>(size_);
|
||||
h_ = w_ = BALLOON_SIZE[size];
|
||||
power_ = BALLOON_POWER[size];
|
||||
menace_ = BALLOON_MENACE[size];
|
||||
score_ = BALLOON_SCORE[size];
|
||||
const int index = static_cast<int>(size_);
|
||||
h_ = w_ = BALLOON_SIZE[index];
|
||||
power_ = BALLOON_POWER[index];
|
||||
menace_ = BALLOON_MENACE[index];
|
||||
score_ = BALLOON_SCORE[index];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BalloonType::POWERBALL:
|
||||
{
|
||||
const int size = 3;
|
||||
h_ = w_ = BALLOON_SIZE[size];
|
||||
const int index = 3;
|
||||
h_ = w_ = BALLOON_SIZE[4];
|
||||
power_ = score_ = menace_ = 0;
|
||||
|
||||
vy_ = 0;
|
||||
max_vy_ = 3.0f;
|
||||
gravity_ = param.balloon.at(size).grav;
|
||||
default_vy_ = param.balloon.at(size).vel;
|
||||
gravity_ = param.balloon.at(index).grav;
|
||||
default_vy_ = param.balloon.at(index).vel;
|
||||
|
||||
sprite_->disableRotate();
|
||||
sprite_->setRotateSpeed(0);
|
||||
sprite_->setRotate(creation_timer <= 0);
|
||||
sprite_->setRotateAmount(vx_ > 0.0f ? 2.0 : -2.0);
|
||||
|
||||
break;
|
||||
@@ -92,40 +92,41 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
void Balloon::alignTo(int x)
|
||||
{
|
||||
x_ = static_cast<float>(x - (w_ / 2));
|
||||
const int min_x = param.game.play_area.rect.x;
|
||||
const int max_x = param.game.play_area.rect.w - w_;
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.w - w_;
|
||||
x_ = std::clamp(x_, static_cast<float>(min_x), static_cast<float>(max_x));
|
||||
}
|
||||
|
||||
// Pinta el globo en la pantalla
|
||||
void Balloon::render()
|
||||
{
|
||||
if (isBeingCreated())
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
// Aplica alpha blending
|
||||
sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_)));
|
||||
// Renderizado para la PowerBall
|
||||
SDL_Point p = {24, 24};
|
||||
sprite_->setRotatingCenter(&p);
|
||||
sprite_->render();
|
||||
sprite_->getTexture()->setAlpha(255);
|
||||
|
||||
// Añade la máscara del borde y los reflejos
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||
sp->setSpriteClip(BALLOON_SIZE[4], 0, BALLOON_SIZE[4], BALLOON_SIZE[4]);
|
||||
sp->render();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bouncing_.enabled)
|
||||
// Renderizado para el resto de globos
|
||||
if (isBeingCreated())
|
||||
{
|
||||
// Aplica efecto de bouncing
|
||||
sprite_->setPos(x_ + bouncing_.despX, y_ + bouncing_.despY);
|
||||
// Renderizado con transparencia
|
||||
sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_)));
|
||||
sprite_->render();
|
||||
sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY);
|
||||
sprite_->getTexture()->setAlpha(255);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Renderizado normal
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Añade la máscara del borde a la PowerBall
|
||||
if (type_ == BalloonType::POWERBALL && !isBeingCreated())
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||
sp->setSpriteClip(BALLOON_SIZE[3], 0, BALLOON_SIZE[3], BALLOON_SIZE[3]);
|
||||
sp->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,40 +141,60 @@ void Balloon::move()
|
||||
|
||||
// Colisión en las partes laterales de la zona de juego
|
||||
const int clip = 2;
|
||||
const float min_x = param.game.play_area.rect.x - clip;
|
||||
const float max_x = param.game.play_area.rect.w - w_ + clip;
|
||||
const float min_x = play_area_.x - clip;
|
||||
const float max_x = play_area_.x + play_area_.w - w_ + clip;
|
||||
if (x_ < min_x || x_ > max_x)
|
||||
{
|
||||
x_ = std::clamp(x_, min_x, max_x);
|
||||
vx_ = -vx_;
|
||||
// Activa el efecto de rebote o invierte la rotación
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
sprite_->switchRotate();
|
||||
}
|
||||
else
|
||||
{
|
||||
enableBounce();
|
||||
}
|
||||
}
|
||||
|
||||
// Mueve el globo en vertical
|
||||
y_ += vy_ * speed_;
|
||||
|
||||
// Colisión en la parte superior de la zona de juego
|
||||
const int min_y = param.game.play_area.rect.y;
|
||||
if (y_ < min_y)
|
||||
// Colisión en la parte superior de la zona de juego excepto para la PowerBall
|
||||
/*if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
y_ = min_y;
|
||||
vy_ = -vy_;
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
const int min_y = play_area_.y;
|
||||
if (y_ < min_y)
|
||||
{
|
||||
y_ = min_y;
|
||||
vy_ = -vy_;
|
||||
enableBounce();
|
||||
}
|
||||
}*/
|
||||
|
||||
// Colisión en la parte superior solo si el globo va de subida
|
||||
if (vy_ < 0)
|
||||
{
|
||||
const int min_y = play_area_.y;
|
||||
if (y_ < min_y)
|
||||
{
|
||||
y_ = min_y;
|
||||
vy_ = -vy_;
|
||||
enableBounce();
|
||||
}
|
||||
}
|
||||
|
||||
// Colisión en la parte inferior de la zona de juego
|
||||
const int max_y = param.game.play_area.rect.h - h_;
|
||||
const int max_y = play_area_.y + play_area_.h - h_;
|
||||
if (y_ > max_y)
|
||||
{
|
||||
y_ = max_y;
|
||||
vy_ = -default_vy_;
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
enableBounce();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -200,17 +221,11 @@ void Balloon::move()
|
||||
}
|
||||
}
|
||||
|
||||
// Deshabilita el globo y pone a cero todos los valores
|
||||
void Balloon::disable()
|
||||
{
|
||||
enabled_ = false;
|
||||
}
|
||||
// Deshabilita el globo
|
||||
void Balloon::disable() { enabled_ = false; }
|
||||
|
||||
// Explosiona el globo
|
||||
void Balloon::pop()
|
||||
{
|
||||
disable();
|
||||
}
|
||||
void Balloon::pop() { disable(); }
|
||||
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores
|
||||
void Balloon::update()
|
||||
@@ -243,8 +258,8 @@ void Balloon::updateState()
|
||||
x_ += vx_;
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
const int min_x = param.game.play_area.rect.x;
|
||||
const int max_x = param.game.play_area.rect.w - w_;
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.w - w_;
|
||||
|
||||
if (x_ < min_x || x_ > max_x)
|
||||
{
|
||||
@@ -296,110 +311,24 @@ void Balloon::setAnimation()
|
||||
sprite_->setCurrentAnimation(isBeingCreated() ? creating_animation : normal_animation);
|
||||
}
|
||||
|
||||
// Comprueba si el globo está habilitado
|
||||
bool Balloon::isEnabled() const
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float Balloon::getPosX() const
|
||||
{
|
||||
return x_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float Balloon::getPosY() const
|
||||
{
|
||||
return y_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getWidth() const
|
||||
{
|
||||
return w_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getHeight() const
|
||||
{
|
||||
return h_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setVelY(float vel_y)
|
||||
{
|
||||
vy_ = vel_y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setSpeed(float speed)
|
||||
{
|
||||
speed_ = speed;
|
||||
}
|
||||
|
||||
// Obtiene el tamaño del globo
|
||||
BalloonSize Balloon::getSize() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
// Obtiene el tipo de globo
|
||||
BalloonType Balloon::getType() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
// Detiene el globo
|
||||
void Balloon::stop()
|
||||
{
|
||||
stopped_ = true;
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
sprite_->disableRotate();
|
||||
if (isPowerBall())
|
||||
{
|
||||
sprite_->setRotate(!stopped_);
|
||||
}
|
||||
}
|
||||
|
||||
// Pone el globo en movimiento
|
||||
void Balloon::start()
|
||||
{
|
||||
stopped_ = false;
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
sprite_->enableRotate();
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool Balloon::isStopped() const
|
||||
{
|
||||
return stopped_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setInvulnerable(bool value)
|
||||
{
|
||||
invulnerable_ = value;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool Balloon::isInvulnerable() const
|
||||
{
|
||||
return invulnerable_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool Balloon::isBeingCreated() const
|
||||
{
|
||||
return being_created_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
Uint16 Balloon::getScore() const
|
||||
{
|
||||
return score_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &Balloon::getCollider()
|
||||
{
|
||||
return collider_;
|
||||
if (isPowerBall())
|
||||
{
|
||||
sprite_->setRotate(!stopped_);
|
||||
}
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
@@ -423,18 +352,6 @@ void Balloon::zoomSprite()
|
||||
sprite_->setZoomH(bouncing_.zoomH);
|
||||
}
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 Balloon::getMenace() const
|
||||
{
|
||||
return isEnabled() ? menace_ : 0;
|
||||
}
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 Balloon::getPower() const
|
||||
{
|
||||
return power_;
|
||||
}
|
||||
|
||||
// Activa el efecto
|
||||
void Balloon::enableBounce()
|
||||
{
|
||||
@@ -462,27 +379,13 @@ void Balloon::updateBounce()
|
||||
|
||||
zoomSprite();
|
||||
|
||||
const auto spriteClip = sprite_->getSpriteClip();
|
||||
bouncing_.despX = spriteClip.w * (1.0f - bouncing_.zoomW);
|
||||
bouncing_.despY = spriteClip.h * (1.0f - bouncing_.zoomH);
|
||||
|
||||
if (++bouncing_.counter / bouncing_.speed >= MAX_BOUNCE)
|
||||
{
|
||||
disableBounce();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si el globo se puede explotar
|
||||
bool Balloon::canBePopped() const
|
||||
{
|
||||
return isEnabled() && !isBeingCreated();
|
||||
}
|
||||
|
||||
// Indica si el globo se puede destruir
|
||||
bool Balloon::canBeDestroyed() const
|
||||
{
|
||||
return isEnabled();
|
||||
}
|
||||
|
||||
// Pone el color alternativo en el globo
|
||||
void Balloon::useReverseColor()
|
||||
{
|
||||
@@ -498,10 +401,4 @@ void Balloon::useNormalColor()
|
||||
{
|
||||
use_reversed_colors_ = false;
|
||||
setAnimation();
|
||||
}
|
||||
|
||||
// Indica si está usando el color alternativo
|
||||
bool Balloon::isUsingReversedColor()
|
||||
{
|
||||
return use_reversed_colors_;
|
||||
}
|
||||
100
source/balloon.h
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture; // lines 10-10
|
||||
class Texture; // lines 9-9
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
constexpr int MAX_BOUNCE = 10;
|
||||
@@ -15,7 +16,7 @@ constexpr int MAX_BOUNCE = 10;
|
||||
constexpr int BALLOON_SCORE[] = {50, 100, 200, 400};
|
||||
constexpr int BALLOON_POWER[] = {1, 3, 7, 15};
|
||||
constexpr int BALLOON_MENACE[] = {1, 2, 4, 8};
|
||||
constexpr int BALLOON_SIZE[] = {10, 16, 26, 46};
|
||||
constexpr int BALLOON_SIZE[] = {10, 16, 26, 48, 49};
|
||||
|
||||
// Tamaños de globo
|
||||
enum class BalloonSize : Uint8
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
float travel_y_ = 1.0f; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
||||
float speed_; // Velocidad a la que se mueven los globos
|
||||
Uint8 power_; // Cantidad de poder que alberga el globo
|
||||
SDL_Rect play_area_; // Zona por donde se puede mover el globo
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void shiftColliders();
|
||||
@@ -138,7 +140,17 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation);
|
||||
Balloon(
|
||||
float x,
|
||||
float y,
|
||||
BalloonType type,
|
||||
BalloonSize size,
|
||||
float vel_x,
|
||||
float speed,
|
||||
Uint16 creation_timer,
|
||||
SDL_Rect play_area,
|
||||
std::shared_ptr<Texture> texture,
|
||||
const std::vector<std::string> &animation);
|
||||
|
||||
// Destructor
|
||||
~Balloon() = default;
|
||||
@@ -161,75 +173,39 @@ public:
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores
|
||||
void update();
|
||||
|
||||
// Comprueba si el globo está habilitado
|
||||
bool isEnabled() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float getPosX() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float getPosY() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int getWidth() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int getHeight() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float vel_y);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpeed(float speed);
|
||||
|
||||
// Obtiene el tamaño del globo
|
||||
BalloonSize getSize() const;
|
||||
|
||||
// Obtiene el tipo de globo
|
||||
BalloonType getType() const;
|
||||
|
||||
// Detiene el globo
|
||||
void stop();
|
||||
|
||||
// Pone el globo en movimiento
|
||||
void start();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool isStopped() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerable(bool value);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool isInvulnerable() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
bool isBeingCreated() const;
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
Uint16 getScore() const;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &getCollider();
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 getMenace() const;
|
||||
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 getPower() const;
|
||||
|
||||
// Indica si el globo se puede explotar
|
||||
bool canBePopped() const;
|
||||
|
||||
// Indica si el globo se puede destruir
|
||||
bool canBeDestroyed() const;
|
||||
|
||||
// Pone el color alternativo en el globo
|
||||
void useReverseColor();
|
||||
|
||||
// Pone el color normal en el globo
|
||||
void useNormalColor();
|
||||
|
||||
// Indica si está usando el color alternativo
|
||||
bool isUsingReversedColor();
|
||||
// Getters
|
||||
float getPosX() const { return x_; }
|
||||
float getPosY() const { return y_; }
|
||||
int getWidth() const { return w_; }
|
||||
int getHeight() const { return h_; }
|
||||
BalloonSize getSize() const { return size_; }
|
||||
BalloonType getType() const { return type_; }
|
||||
Uint16 getScore() const { return score_; }
|
||||
Circle &getCollider() { return collider_; }
|
||||
Uint8 getMenace() const { return isEnabled() ? menace_ : 0; }
|
||||
Uint8 getPower() const { return power_; }
|
||||
bool isStopped() const { return stopped_; }
|
||||
bool isPowerBall() const { return type_ == BalloonType::POWERBALL; }
|
||||
bool isInvulnerable() const { return invulnerable_; }
|
||||
bool isBeingCreated() const { return being_created_; }
|
||||
bool isEnabled() const { return enabled_; }
|
||||
bool isUsingReversedColor() { return use_reversed_colors_; }
|
||||
bool canBePopped() const { return !isBeingCreated(); }
|
||||
|
||||
// Setters
|
||||
void setVelY(float vel_y) { vy_ = vel_y; }
|
||||
void setSpeed(float speed) { speed_ = speed; }
|
||||
void setInvulnerable(bool value) { invulnerable_ = value; }
|
||||
};
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "balloon.h"
|
||||
#include "balloon.h" // para BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||
#include <vector>
|
||||
|
||||
constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100;
|
||||
constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50;
|
||||
constexpr int NUMBER_OF_SETS_PER_POOL = 10;
|
||||
constexpr int NUMBER_OF_STAGES = 10;
|
||||
|
||||
// Estructuras
|
||||
struct BalloonFormationParams
|
||||
{
|
||||
int x = 0; // Posición en el eje X donde crear el globo
|
||||
@@ -25,34 +25,26 @@ struct BalloonFormationParams
|
||||
: x(x_val), y(y_val), vel_x(vel_x_val), type(type_val), size(size_val), creation_counter(creation_counter_val) {}
|
||||
};
|
||||
|
||||
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
||||
struct BalloonFormationUnit
|
||||
{
|
||||
int number_of_balloons; // Cantidad de globos que forman la formación
|
||||
BalloonFormationParams init[MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION]; // Vector con todas las inicializaciones de los globos de la formación
|
||||
int number_of_balloons; // Cantidad de globos que forman la formación
|
||||
std::vector<BalloonFormationParams> init; // Vector con todas las inicializaciones de los globos de la formación
|
||||
|
||||
// Constructor
|
||||
BalloonFormationUnit(int num_balloons, const std::vector<BalloonFormationParams> &init_params)
|
||||
: number_of_balloons(num_balloons), init(init_params) {}
|
||||
|
||||
// Default constructor
|
||||
BalloonFormationUnit() : number_of_balloons(0), init() {}
|
||||
};
|
||||
|
||||
struct BalloonFormationPool
|
||||
{
|
||||
BalloonFormationUnit set[NUMBER_OF_SETS_PER_POOL]; // Conjunto de formaciones de globos
|
||||
};
|
||||
using BalloonFormationPool = std::vector<const BalloonFormationUnit *>;
|
||||
|
||||
struct Stage // Contiene todas las variables relacionadas con una fase
|
||||
{
|
||||
BalloonFormationPool balloon_pool; // El conjunto de formaciones de globos de la fase
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int number; // Número de fase
|
||||
};
|
||||
|
||||
// Clase BalloonFormations, para gestionar las formaciones de globos
|
||||
class BalloonFormations
|
||||
{
|
||||
private:
|
||||
// Variables
|
||||
Stage stage_[NUMBER_OF_STAGES]; // Variable con los datos de cada pantalla
|
||||
BalloonFormationUnit balloon_formation_[NUMBER_OF_BALLOON_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
BalloonFormationPool balloon_formation_pool_[NUMBER_OF_STAGES]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
std::vector<BalloonFormationUnit> balloon_formation_; // Vector con todas las formaciones enemigas
|
||||
std::vector<BalloonFormationPool> balloon_formation_pool_; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void initBalloonFormations();
|
||||
@@ -60,16 +52,19 @@ private:
|
||||
// Inicializa los conjuntos de formaciones
|
||||
void initBalloonFormationPools();
|
||||
|
||||
// Inicializa las fases del juego
|
||||
void initGameStages();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
BalloonFormations();
|
||||
BalloonFormations()
|
||||
{
|
||||
initBalloonFormations();
|
||||
initBalloonFormationPools();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
~BalloonFormations() = default;
|
||||
|
||||
// Devuelve una fase
|
||||
Stage getStage(int index) const;
|
||||
};
|
||||
// Getters
|
||||
const BalloonFormationPool &getPool(int pool) { return balloon_formation_pool_.at(pool); }
|
||||
const BalloonFormationUnit &getSet(int pool, int set) { return *balloon_formation_pool_.at(pool).at(set); }
|
||||
const BalloonFormationUnit &getSet(int set) const { return balloon_formation_.at(set); }
|
||||
};
|
||||
|
||||
374
source/balloon_manager.cpp
Normal file
@@ -0,0 +1,374 @@
|
||||
#include "balloon_manager.h"
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para remove_if
|
||||
#include <numeric> // Para accumulate
|
||||
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
|
||||
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
|
||||
#include "explosions.h" // Para Explosions
|
||||
#include "jail_audio.h" // Para JA_PlaySound
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "stage.h" // Para power
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Zone, BLOCK, Color, flash_color
|
||||
|
||||
// Constructor
|
||||
BalloonManager::BalloonManager()
|
||||
: explosions_(std::make_unique<Explosions>()),
|
||||
balloon_formations_(std::make_unique<BalloonFormations>()) { init(); }
|
||||
|
||||
// Inicializa
|
||||
void BalloonManager::init()
|
||||
{
|
||||
// Texturas - Globos
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon1.png"));
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon2.png"));
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon3.png"));
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon4.png"));
|
||||
balloon_textures_.emplace_back(Resource::get()->getTexture("powerball.png"));
|
||||
|
||||
// Animaciones -- Globos
|
||||
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon1.ani"));
|
||||
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon2.ani"));
|
||||
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon3.ani"));
|
||||
balloon_animations_.emplace_back(Resource::get()->getAnimation("balloon4.ani"));
|
||||
balloon_animations_.emplace_back(Resource::get()->getAnimation("powerball.ani"));
|
||||
|
||||
// Texturas - Explosiones
|
||||
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion1.png"));
|
||||
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion2.png"));
|
||||
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion3.png"));
|
||||
explosions_textures_.emplace_back(Resource::get()->getTexture("explosion4.png"));
|
||||
|
||||
// Animaciones -- Explosiones
|
||||
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion1.ani"));
|
||||
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion2.ani"));
|
||||
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion3.ani"));
|
||||
explosions_animations_.emplace_back(Resource::get()->getAnimation("explosion4.ani"));
|
||||
|
||||
// Añade texturas
|
||||
explosions_->addTexture(1, explosions_textures_[0], explosions_animations_[0]);
|
||||
explosions_->addTexture(2, explosions_textures_[1], explosions_animations_[1]);
|
||||
explosions_->addTexture(3, explosions_textures_[2], explosions_animations_[2]);
|
||||
explosions_->addTexture(4, explosions_textures_[3], explosions_animations_[3]);
|
||||
}
|
||||
|
||||
// Actualiza
|
||||
void BalloonManager::update()
|
||||
{
|
||||
for (auto balloon : balloons_)
|
||||
{
|
||||
balloon->update();
|
||||
}
|
||||
updateBalloonDeployCounter();
|
||||
explosions_->update();
|
||||
}
|
||||
|
||||
// Renderiza los objetos
|
||||
void BalloonManager::render()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
balloon->render();
|
||||
}
|
||||
explosions_->render();
|
||||
}
|
||||
|
||||
// Crea una formación de enemigos
|
||||
void BalloonManager::deployBalloonFormation(int stage)
|
||||
{
|
||||
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
||||
if (balloon_deploy_counter_ == 0)
|
||||
{
|
||||
// En este punto se decide entre crear una powerball o una formación enemiga
|
||||
if ((rand() % 100 < 15) && (canPowerBallBeCreated()))
|
||||
{
|
||||
// Crea una powerball
|
||||
createPowerBall();
|
||||
|
||||
// Da un poco de margen para que se creen mas enemigos
|
||||
balloon_deploy_counter_ = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrementa el contador de despliegues enemigos de la PowerBall
|
||||
power_ball_counter_ = (power_ball_counter_ > 0) ? (power_ball_counter_ - 1) : 0;
|
||||
|
||||
// Elige una formación enemiga la azar
|
||||
auto formation = rand() % 10;
|
||||
|
||||
// Evita repetir la ultima formación enemiga desplegada
|
||||
if (formation == last_balloon_deploy_)
|
||||
{
|
||||
++formation %= 10;
|
||||
}
|
||||
|
||||
last_balloon_deploy_ = formation;
|
||||
|
||||
const auto set = balloon_formations_->getSet(stage, formation);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
|
||||
balloon_deploy_counter_ = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void BalloonManager::deploySet(int set_number)
|
||||
{
|
||||
const auto set = balloon_formations_->getSet(set_number);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void BalloonManager::deploySet(int set_number, int y)
|
||||
{
|
||||
const auto set = balloon_formations_->getSet(set_number);
|
||||
const auto numEnemies = set.number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
auto p = set.init[i];
|
||||
createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
|
||||
}
|
||||
}
|
||||
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void BalloonManager::freeBalloons()
|
||||
{
|
||||
auto it = std::remove_if(balloons_.begin(), balloons_.end(), [](const auto &balloon)
|
||||
{ return !balloon->isEnabled(); });
|
||||
balloons_.erase(it, balloons_.end());
|
||||
}
|
||||
|
||||
// Actualiza la variable enemyDeployCounter
|
||||
void BalloonManager::updateBalloonDeployCounter()
|
||||
{
|
||||
if (balloon_deploy_counter_ > 0)
|
||||
{
|
||||
--balloon_deploy_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si se puede crear una powerball
|
||||
bool BalloonManager::canPowerBallBeCreated() { return (!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0); }
|
||||
|
||||
// Calcula el poder actual de los globos en pantalla
|
||||
int BalloonManager::calculateScreenPower()
|
||||
{
|
||||
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
||||
{ return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
|
||||
}
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer)
|
||||
{
|
||||
const int index = static_cast<int>(size);
|
||||
balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, play_area_, balloon_textures_.at(index), balloon_animations_.at(index)));
|
||||
return balloons_.back();
|
||||
}
|
||||
|
||||
// Crea un globo a partir de otro globo
|
||||
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction)
|
||||
{
|
||||
const float vx = direction == "LEFT" ? BALLOON_VELX_NEGATIVE : BALLOON_VELX_POSITIVE;
|
||||
const auto lower_size = static_cast<BalloonSize>(static_cast<int>(balloon->getSize()) - 1);
|
||||
auto b = createBalloon(0, balloon->getPosY(), balloon->getType(), lower_size, vx, balloon_speed_, 0);
|
||||
const int x = direction == "LEFT" ? balloon->getPosX() + (balloon->getWidth() / 3) : balloon->getPosX() + 2 * (balloon->getWidth() / 3);
|
||||
b->alignTo(x);
|
||||
b->setVelY(b->getType() == BalloonType::BALLOON ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
|
||||
if (balloon->isStopped())
|
||||
{
|
||||
b->stop();
|
||||
}
|
||||
if (balloon->isUsingReversedColor())
|
||||
{
|
||||
b->useReverseColor();
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una PowerBall
|
||||
void BalloonManager::createPowerBall()
|
||||
{
|
||||
constexpr int values = 6;
|
||||
constexpr int pos_y = -BALLOON_SIZE[4];
|
||||
constexpr int creation_time = 0;
|
||||
|
||||
const auto left = param.game.play_area.rect.x;
|
||||
const auto center = param.game.play_area.center_x - (BALLOON_SIZE[4] / 2);
|
||||
const auto right = param.game.play_area.rect.w - BALLOON_SIZE[4];
|
||||
|
||||
const auto luck = rand() % values;
|
||||
const int x[values] = {left, left, center, center, right, right};
|
||||
const float vx[values] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE};
|
||||
|
||||
balloons_.emplace_back(std::make_unique<Balloon>(x[luck], pos_y, BalloonType::POWERBALL, BalloonSize::SIZE4, vx[luck], balloon_speed_, creation_time, play_area_, balloon_textures_[4], balloon_animations_[4]));
|
||||
|
||||
power_ball_enabled_ = true;
|
||||
power_ball_counter_ = POWERBALL_COUNTER;
|
||||
}
|
||||
|
||||
// Establece la velocidad de los globos
|
||||
void BalloonManager::setBalloonSpeed(float speed)
|
||||
{
|
||||
balloon_speed_ = speed;
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
balloon->setSpeed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||
int BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
|
||||
{
|
||||
Stage::addPower(1);
|
||||
int score = 0;
|
||||
|
||||
if (balloon->getType() == BalloonType::POWERBALL)
|
||||
{
|
||||
score = destroyAllBalloons();
|
||||
power_ball_enabled_ = false;
|
||||
balloon_deploy_counter_ = 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
score = balloon->getScore();
|
||||
if (balloon->getSize() != BalloonSize::SIZE1)
|
||||
{
|
||||
createChildBalloon(balloon, "LEFT");
|
||||
createChildBalloon(balloon, "RIGHT");
|
||||
}
|
||||
|
||||
// Agrega la explosión y elimina el globo
|
||||
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
||||
balloon->pop();
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
// Explosiona un globo. Lo destruye = no crea otros globos
|
||||
int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
||||
{
|
||||
int score = 0;
|
||||
|
||||
// Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos
|
||||
switch (balloon->getSize())
|
||||
{
|
||||
case BalloonSize::SIZE4:
|
||||
score = BALLOON_SCORE[3] + (2 * BALLOON_SCORE[2]) + (4 * BALLOON_SCORE[1]) + (8 * BALLOON_SCORE[0]);
|
||||
break;
|
||||
case BalloonSize::SIZE3:
|
||||
score = BALLOON_SCORE[2] + (2 * BALLOON_SCORE[1]) + (4 * BALLOON_SCORE[0]);
|
||||
break;
|
||||
case BalloonSize::SIZE2:
|
||||
score = BALLOON_SCORE[1] + (2 * BALLOON_SCORE[0]);
|
||||
break;
|
||||
case BalloonSize::SIZE1:
|
||||
score = BALLOON_SCORE[0];
|
||||
break;
|
||||
default:
|
||||
score = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Aumenta el poder de la fase
|
||||
Stage::addPower(balloon->getPower());
|
||||
|
||||
// Destruye el globo
|
||||
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
|
||||
balloon->pop();
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
// Destruye todos los globos
|
||||
int BalloonManager::destroyAllBalloons()
|
||||
{
|
||||
int score = 0;
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
score += destroyBalloon(balloon);
|
||||
}
|
||||
|
||||
balloon_deploy_counter_ = 300;
|
||||
JA_PlaySound(Resource::get()->getSound("powerball.wav"));
|
||||
Screen::get()->flash(flash_color, 3);
|
||||
Screen::get()->shake();
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
// Detiene todos los globos
|
||||
void BalloonManager::stopAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
balloon->stop();
|
||||
}
|
||||
}
|
||||
|
||||
// Pone en marcha todos los globos
|
||||
void BalloonManager::startAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (!balloon->isBeingCreated())
|
||||
{
|
||||
balloon->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void BalloonManager::reverseColorsToAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->isStopped())
|
||||
{
|
||||
balloon->useReverseColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void BalloonManager::normalColorsToAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
balloon->useNormalColor();
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
void BalloonManager::reLoad()
|
||||
{
|
||||
for (auto &texture : balloon_textures_)
|
||||
{
|
||||
texture->reLoad();
|
||||
}
|
||||
}
|
||||
|
||||
// Crea dos globos gordos
|
||||
void BalloonManager::createTwoBigBalloons()
|
||||
{
|
||||
deploySet(1);
|
||||
}
|
||||
|
||||
// Obtiene el nivel de ameza actual generado por los globos
|
||||
int BalloonManager::getMenace()
|
||||
{
|
||||
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
|
||||
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
|
||||
}
|
||||
122
source/balloon_manager.h
Normal file
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "balloon.h" // Para BALLOON_SPEED, Balloon
|
||||
#include "balloon_formations.h" // Para BalloonFormations
|
||||
#include "explosions.h" // Para Explosions
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "utils.h" // Para Zone
|
||||
class Texture; // lines 10-10
|
||||
|
||||
using Balloons = std::vector<std::shared_ptr<Balloon>>;
|
||||
|
||||
class BalloonManager
|
||||
{
|
||||
private:
|
||||
Balloons balloons_; // Vector con los globos
|
||||
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
||||
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para gestionar las oleadas enemigas
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> balloon_textures_; // Vector con las texturas de los globos
|
||||
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Vector con las texturas de las explosiones
|
||||
|
||||
std::vector<std::vector<std::string>> balloon_animations_; // Vector con las animaciones de los globos
|
||||
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||
|
||||
float balloon_speed_ = BALLOON_SPEED[0]; // Velocidad a la que se mueven los enemigos
|
||||
float default_balloon_speed_ = BALLOON_SPEED[0]; // Velocidad base de los enemigos, sin incrementar
|
||||
int balloon_deploy_counter_ = 0; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
|
||||
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
SDL_Rect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos
|
||||
|
||||
// Inicializa
|
||||
void init();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
BalloonManager();
|
||||
|
||||
// Destructor
|
||||
~BalloonManager() = default;
|
||||
|
||||
// Actualiza
|
||||
void update();
|
||||
|
||||
// Renderiza los globos
|
||||
void render();
|
||||
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void freeBalloons();
|
||||
|
||||
// Crea una formación de enemigos al azar
|
||||
void deployBalloonFormation(int stage);
|
||||
|
||||
// Crea una formación de enemigos específica
|
||||
void deploySet(int set);
|
||||
void deploySet(int set, int y);
|
||||
|
||||
// Actualiza la variable enemyDeployCounter
|
||||
void updateBalloonDeployCounter();
|
||||
|
||||
// Indica si se puede crear una powerball
|
||||
bool canPowerBallBeCreated();
|
||||
|
||||
// Calcula el poder actual de los globos en pantalla
|
||||
int calculateScreenPower();
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
std::shared_ptr<Balloon> createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer);
|
||||
|
||||
// Crea un globo a partir de otro globo
|
||||
void createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction);
|
||||
|
||||
// Crea una PowerBall
|
||||
void createPowerBall();
|
||||
|
||||
// Establece la velocidad de los globos
|
||||
void setBalloonSpeed(float speed);
|
||||
|
||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||
int popBalloon(std::shared_ptr<Balloon> balloon);
|
||||
|
||||
// Explosiona un globo. Lo destruye = no crea otros globos
|
||||
int destroyBalloon(std::shared_ptr<Balloon> &balloon);
|
||||
|
||||
// Destruye todos los globos
|
||||
int destroyAllBalloons();
|
||||
|
||||
// Detiene todos los globos
|
||||
void stopAllBalloons();
|
||||
|
||||
// Pone en marcha todos los globos
|
||||
void startAllBalloons();
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void reverseColorsToAllBalloons();
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void normalColorsToAllBalloons();
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoad();
|
||||
|
||||
// Crea dos globos gordos
|
||||
void createTwoBigBalloons();
|
||||
|
||||
// Obtiene el nivel de ameza actual generado por los globos
|
||||
int getMenace();
|
||||
|
||||
// Getters
|
||||
float getBalloonSpeed() const { return balloon_speed_; }
|
||||
Balloons &getBalloons() { return balloons_; }
|
||||
|
||||
// Setters
|
||||
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }
|
||||
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }
|
||||
void setPlayArea(SDL_Rect play_area) { play_area_ = play_area; }
|
||||
};
|
||||
471
source/credits.cpp
Normal file
@@ -0,0 +1,471 @@
|
||||
#include "credits.h"
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_QUIT
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <string> // Para basic_string, string
|
||||
#include <vector> // Para vector
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input
|
||||
#include "jail_audio.h" // Para JA_PlayMusic, JA_StopMusic
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h" // Para Color, no_color, shdw_txt_color, Zone
|
||||
#include "player.h"
|
||||
#include "fade.h"
|
||||
#include "lang.h"
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||
|
||||
// Constructor
|
||||
Credits::Credits()
|
||||
: balloon_manager_(std::make_unique<BalloonManager>()),
|
||||
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL)),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>())
|
||||
{
|
||||
if (!text_texture_)
|
||||
{
|
||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||
}
|
||||
section::name = section::Name::CREDITS;
|
||||
//top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
|
||||
//bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
|
||||
balloon_manager_->setPlayArea(play_area_);
|
||||
|
||||
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_in_->setType(FadeType::FULLSCREEN);
|
||||
fade_in_->setPost(50);
|
||||
fade_in_->setMode(FadeMode::IN);
|
||||
fade_in_->activate();
|
||||
|
||||
fade_out_->setColor(0, 0, 0);
|
||||
fade_out_->setType(FadeType::FULLSCREEN);
|
||||
fade_out_->setPost(400);
|
||||
|
||||
initPlayers();
|
||||
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
||||
fillTextTexture();
|
||||
steps_ = std::abs((top_black_rect_.h - param.game.game_area.center_y - 1) + ((left_black_rect_.w - param.game.game_area.center_x) / 4));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits()
|
||||
{
|
||||
SDL_DestroyTexture(text_texture_);
|
||||
resetVolume();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Credits::run()
|
||||
{
|
||||
while (section::name == section::Name::CREDITS)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Credits::update()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
ticks_ = SDL_GetTicks();
|
||||
tiled_bg_->update();
|
||||
balloon_manager_->update();
|
||||
updateTextureDstRects();
|
||||
throwBalloons();
|
||||
for (auto &player : players_)
|
||||
{
|
||||
player->update();
|
||||
}
|
||||
updateAllFades();
|
||||
Screen::get()->update();
|
||||
globalInputs::update();
|
||||
++counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja Credits::en patalla
|
||||
void Credits::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean();
|
||||
|
||||
// Dibuja el fondo, los globos y los jugadores
|
||||
tiled_bg_->render();
|
||||
balloon_manager_->render();
|
||||
for (auto const &player : players_)
|
||||
{
|
||||
player->render();
|
||||
}
|
||||
|
||||
// Dibuja los titulos de credito
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_);
|
||||
|
||||
// Dibuja el mini_logo
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||
|
||||
// Dibuja los rectangulos negros
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &top_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &bottom_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &left_black_rect_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &right_black_rect_);
|
||||
|
||||
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
|
||||
if (mini_logo_on_position_)
|
||||
{
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||
}
|
||||
|
||||
// Dibuja el fade sobre el resto de elementos
|
||||
fade_in_->render();
|
||||
fade_out_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->blit();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::checkInput()
|
||||
{
|
||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
if (mini_logo_on_position_)
|
||||
{
|
||||
// Si el mini_logo ha llegado a su posición final, al pulsar cualquier tecla se activa el fundido
|
||||
fading_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si todavía estan los creditos en marcha, se pasan solos a toda pastilla
|
||||
want_to_pass_ = true;
|
||||
ticks_speed_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Crea la textura con el texto
|
||||
void Credits::fillTextTexture()
|
||||
{
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
|
||||
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
|
||||
std::vector<std::string> texts = {
|
||||
lang::getText(121),
|
||||
lang::getText(122),
|
||||
lang::getText(123),
|
||||
lang::getText(124),
|
||||
"JAILDESIGNER",
|
||||
"JAILDOCTOR (INTRO)",
|
||||
"ERIC MATYAS (SOUNDIMAGE.ORG)",
|
||||
"WWW.THEMOTIONMONKEY.CO.UK",
|
||||
"WWW.KENNEY.NL",
|
||||
"JAILDOCTOR"};
|
||||
|
||||
const int space_post_title = 3 + text->getCharacterSize();
|
||||
const int space_pre_title = text->getCharacterSize() * 4;
|
||||
const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title;
|
||||
credits_rect_dst_.h = credits_rect_src_.h = texts_height;
|
||||
|
||||
int y = (param.game.height - texts_height) / 2;
|
||||
y = 0;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(0), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(1), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(2), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(5), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(6), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
y += space_pre_title;
|
||||
text->setPalette(1);
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(3), 1, no_color, 1, shdw_txt_color);
|
||||
text->setPalette(0);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(7), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(8), 1, no_color, 1, shdw_txt_color);
|
||||
y += space_post_title;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(9), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
// Mini logo
|
||||
y += space_pre_title;
|
||||
mini_logo_rect_src_.y = y;
|
||||
auto mini_logo_sprite = std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"));
|
||||
mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y);
|
||||
Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(shdw_txt_color.r, shdw_txt_color.g, shdw_txt_color.b);
|
||||
mini_logo_sprite->render();
|
||||
|
||||
mini_logo_sprite->setPosition(param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, y);
|
||||
Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(255, 255, 255);
|
||||
mini_logo_sprite->render();
|
||||
|
||||
// Texto con el copyright
|
||||
y += mini_logo_sprite->getHeight() + 3;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXT_COPYRIGHT, 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
// Resetea el renderizador
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
|
||||
// Actualiza las variables
|
||||
mini_logo_rect_dst_.h = mini_logo_rect_src_.h = mini_logo_sprite->getHeight() + 3 + text->getCharacterSize();
|
||||
credits_rect_dst_.y = param.game.game_area.rect.h;
|
||||
mini_logo_rect_dst_.y = credits_rect_dst_.y + credits_rect_dst_.h + 30;
|
||||
mini_logo_final_pos_ = param.game.game_area.center_y - mini_logo_rect_src_.h / 2;
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas
|
||||
void Credits::updateTextureDstRects()
|
||||
{
|
||||
if (counter_ % 10 == 0)
|
||||
{
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y)
|
||||
{
|
||||
--credits_rect_dst_.y;
|
||||
}
|
||||
|
||||
// Comprueba la posición de la textura con el mini_logo
|
||||
if (mini_logo_rect_dst_.y == mini_logo_final_pos_)
|
||||
{
|
||||
mini_logo_on_position_ = true;
|
||||
|
||||
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
|
||||
if (want_to_pass_)
|
||||
{
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Se activa el contador para evitar que la sección sea infinita
|
||||
if (counter_prevent_endless_ == 1000)
|
||||
{
|
||||
fading_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
++counter_prevent_endless_;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
--mini_logo_rect_dst_.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario
|
||||
void Credits::throwBalloons()
|
||||
{
|
||||
constexpr int speed = 200;
|
||||
const std::vector<int> sets = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
|
||||
if (counter_ > ((sets.size() - 1) * speed) * 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (counter_ % speed == 0)
|
||||
{
|
||||
const int index = (counter_ / speed) % sets.size();
|
||||
balloon_manager_->deploySet(sets.at(index), -60);
|
||||
}
|
||||
|
||||
if (counter_ % (speed * 4) == 0 && counter_ > 0)
|
||||
{
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa los jugadores
|
||||
void Credits::initPlayers()
|
||||
{
|
||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
|
||||
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
|
||||
|
||||
// Texturas - Player1
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Texturas - Player2
|
||||
{
|
||||
std::vector<std::shared_ptr<Texture>> player_texture;
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
|
||||
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
|
||||
player_textures.push_back(player_texture);
|
||||
}
|
||||
|
||||
// Animaciones -- Jugador
|
||||
{
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
|
||||
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
|
||||
}
|
||||
|
||||
// Crea los dos jugadores
|
||||
constexpr int player_width = 30;
|
||||
const int y = play_area_.y + play_area_.h - player_width;
|
||||
constexpr bool demo = false;
|
||||
constexpr int away_distance = 700;
|
||||
players_.emplace_back(std::make_unique<Player>(1, play_area_.x - away_distance - player_width, y, demo, play_area_, player_textures.at(0), player_animations));
|
||||
players_.back()->setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
players_.back()->setPlayingState(PlayerState::CREDITS);
|
||||
players_.back()->setInvulnerable(false);
|
||||
|
||||
players_.emplace_back(std::make_unique<Player>(2, play_area_.x + play_area_.w + away_distance, y, demo, play_area_, player_textures.at(1), player_animations));
|
||||
players_.back()->setWalkingState(PlayerState::WALKING_LEFT);
|
||||
players_.back()->setPlayingState(PlayerState::CREDITS);
|
||||
players_.back()->setInvulnerable(false);
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
void Credits::updateBlackRects()
|
||||
{
|
||||
static int current_step = steps_;
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1)
|
||||
{
|
||||
// Si los rectangulos superior e inferior no han llegado al centro
|
||||
if (counter_ % 4 == 0)
|
||||
{
|
||||
// Incrementa la altura del rectangulo superior
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
|
||||
|
||||
// Incrementa la altura y modifica la posición del rectangulo inferior
|
||||
++bottom_black_rect_.h;
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
|
||||
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si los rectangulos superior e inferior han llegado al centro
|
||||
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x)
|
||||
{
|
||||
// Si los rectangulos izquierdo y derecho no han llegado al centro
|
||||
// Incrementa la anchura del rectangulo situado a la izquierda
|
||||
left_black_rect_.w = std::min(left_black_rect_.w + 4, param.game.game_area.center_x);
|
||||
|
||||
// Incrementa la anchura y modifica la posición del rectangulo situado a la derecha
|
||||
right_black_rect_.w += 4;
|
||||
right_black_rect_.x = std::max(right_black_rect_.x - 4, param.game.game_area.center_x);
|
||||
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||
setVolume(0);
|
||||
JA_StopMusic();
|
||||
if (counter_pre_fade_ == 400)
|
||||
{
|
||||
fade_out_->activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
++counter_pre_fade_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade
|
||||
void Credits::updateAllFades()
|
||||
{
|
||||
if (fading_)
|
||||
{
|
||||
updateBlackRects();
|
||||
}
|
||||
|
||||
fade_in_->update();
|
||||
if (fade_in_->hasEnded())
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
|
||||
}
|
||||
}
|
||||
|
||||
fade_out_->update();
|
||||
if (fade_out_->hasEnded())
|
||||
{
|
||||
section::name = section::Name::LOGO;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el nivel de volumen
|
||||
void Credits::setVolume(int amount)
|
||||
{
|
||||
options.audio.music.volume = std::clamp(amount, 0, 100);
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
}
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void Credits::resetVolume()
|
||||
{
|
||||
options.audio.music.volume = initial_volume_;
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
}
|
||||
100
source/credits.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
class BalloonManager;
|
||||
class TiledBG;
|
||||
class Player;
|
||||
class Fade;
|
||||
|
||||
constexpr int PLAY_AREA_HEIGHT = 200;
|
||||
|
||||
class Credits
|
||||
{
|
||||
private:
|
||||
// Objetos
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
SDL_Texture *text_texture_; // Textura con el texto
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_in_; // Objeto para realizar el fundido de entrada
|
||||
std::unique_ptr<Fade> fade_out_; // Objeto para realizar el fundido de salida
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
|
||||
// Variables
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_ = 15; // Velocidad del bucle update
|
||||
Uint32 counter_ = 0; // Contador para la lógica de la clase
|
||||
Uint32 counter_pre_fade_ = 0; // Contador para activar el fundido final
|
||||
Uint32 counter_prevent_endless_ = 0; // Contador para evitar que el juego se quede para siempre en los creditos
|
||||
int black_bars_size_ = (param.game.game_area.rect.h - PLAY_AREA_HEIGHT) / 2; // Tamaño de las barras negras
|
||||
int mini_logo_final_pos_ = 0; // Ubicación donde se detiene el minilogo
|
||||
bool fading_ = false; // Indica si se está realizando el fade final
|
||||
bool want_to_pass_ = false; // Indica si el jugador quiere saltarse los titulos de crédito
|
||||
bool mini_logo_on_position_ = false; // Indica si el minilogo ya se ha quedado en su posición
|
||||
int initial_volume_ = options.audio.music.volume; // Volumen actual al crear el objeto
|
||||
int steps_ = 0; // Cantidad de pasos a dar para ir reduciendo el audio
|
||||
|
||||
// Rectangulos
|
||||
SDL_Rect credits_rect_src_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (origen)
|
||||
SDL_Rect credits_rect_dst_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (destino)
|
||||
SDL_Rect mini_logo_rect_src_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (origen)
|
||||
SDL_Rect mini_logo_rect_dst_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (destino)
|
||||
SDL_Rect play_area_ = {
|
||||
param.game.game_area.rect.x,
|
||||
param.game.game_area.rect.y + black_bars_size_,
|
||||
param.game.game_area.rect.w,
|
||||
PLAY_AREA_HEIGHT}; // Area visible para los creditos
|
||||
SDL_Rect top_black_rect_ = {play_area_.x, param.game.game_area.rect.y, play_area_.w, black_bars_size_}; // Rectangulo negro superior
|
||||
SDL_Rect bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_}; // Rectangulo negro inferior
|
||||
SDL_Rect left_black_rect_ = {play_area_.x, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la izquierda
|
||||
SDL_Rect right_black_rect_ = {play_area_.x + play_area_.w, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la derecha
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Dibuja en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Crea la textura con el texto
|
||||
void fillTextTexture();
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas
|
||||
void updateTextureDstRects();
|
||||
|
||||
// Tira globos al escenario
|
||||
void throwBalloons();
|
||||
|
||||
// Inicializa los jugadores
|
||||
void initPlayers();
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
void updateBlackRects();
|
||||
|
||||
// Actualiza el estado de fade
|
||||
void updateAllFades();
|
||||
|
||||
// Establece el nivel de volumen
|
||||
void setVolume(int amount);
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void resetVolume();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Credits();
|
||||
|
||||
// Destructor
|
||||
~Credits();
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
@@ -1,26 +1,22 @@
|
||||
#include "define_buttons.h"
|
||||
#include <utility> // Para move
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
||||
DefineButtons::DefineButtons()
|
||||
: input_(Input::get()),
|
||||
text_(std::move(text_))
|
||||
text_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
x_ = param.game.width / 2;
|
||||
y_ = param.title.press_start_position;
|
||||
|
||||
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X);
|
||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y);
|
||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_START);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::EXIT, SDL_CONTROLLER_BUTTON_BACK);
|
||||
clearButtons();
|
||||
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
@@ -33,38 +29,40 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller[index_controller_].player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_[index_controller_]);
|
||||
text_->writeCentered(x_, y_ + 10, buttons_[index_button_].label);
|
||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controllers.at(index_controller_).player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_.at(index_controller_));
|
||||
text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent *event)
|
||||
void DefineButtons::doControllerButtonDown(const SDL_ControllerButtonEvent &event)
|
||||
{
|
||||
int i = input_->getJoyIndex(event->which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != index_controller_)
|
||||
// Solo pilla botones del mando que toca
|
||||
if (input_->getJoyIndex(event.which) != static_cast<int>(index_controller_))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons_[index_button_].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
const auto button = static_cast<SDL_GameControllerButton>(event.button);
|
||||
if (checkButtonNotInUse(button))
|
||||
{
|
||||
buttons_.at(index_button_).button = button;
|
||||
incIndexButton();
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (int i = 0; i < (int)buttons_.size(); ++i)
|
||||
for (const auto &button : buttons_)
|
||||
{
|
||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
||||
input_->bindGameControllerButton(index_controller_, button.input, button.button);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void DefineButtons::checkInput()
|
||||
// Comprueba los eventos
|
||||
void DefineButtons::checkEvents()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
@@ -81,13 +79,11 @@ void DefineButtons::checkInput()
|
||||
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
{
|
||||
doControllerButtonDown(&event.cbutton);
|
||||
doControllerButtonDown(event.cbutton);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -103,6 +99,7 @@ bool DefineButtons::enable(int index)
|
||||
enabled_ = true;
|
||||
index_controller_ = index;
|
||||
index_button_ = 0;
|
||||
clearButtons();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,18 +107,15 @@ bool DefineButtons::enable(int index)
|
||||
}
|
||||
|
||||
// Comprueba si está habilitado
|
||||
bool DefineButtons::isEnabled()
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
bool DefineButtons::isEnabled() { return enabled_; }
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
index_button_++;
|
||||
++index_button_;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (index_button_ == (int)buttons_.size())
|
||||
if (index_button_ == buttons_.size())
|
||||
{
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
@@ -129,11 +123,7 @@ void DefineButtons::incIndexButton()
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
// input_->allActive(index_controller_);
|
||||
|
||||
// Reinicia variables
|
||||
index_button_ = 0;
|
||||
index_controller_ = 0;
|
||||
// Deshabilita
|
||||
enabled_ = false;
|
||||
}
|
||||
}
|
||||
@@ -142,17 +132,34 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
options.controller[index_controller_].name = input_->getControllerName(index_controller_);
|
||||
for (int j = 0; j < (int)options.controller[index_controller_].inputs.size(); ++j)
|
||||
auto &controller = options.controllers.at(index_controller_);
|
||||
controller.name = input_->getControllerName(index_controller_);
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
options.controller[index_controller_].buttons[j] = input_->getControllerBinding(index_controller_, options.controller[index_controller_].inputs[j]);
|
||||
controller.buttons.at(j) = input_->getControllerBinding(index_controller_, controller.inputs.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void DefineButtons::swapControllers()
|
||||
// Comprueba que un botón no esté ya asignado
|
||||
bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
||||
{
|
||||
const int temp = options.controller[0].player_id;
|
||||
options.controller[0].player_id = options.controller[1].player_id;
|
||||
options.controller[1].player_id = temp;
|
||||
for (const auto &b : buttons_)
|
||||
{
|
||||
if (b.button == button)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Limpia la asignación de botones
|
||||
void DefineButtons::clearButtons()
|
||||
{
|
||||
buttons_.clear();
|
||||
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // para SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // para SDL_GameControllerButton
|
||||
#include <memory> // para shared_ptr, unique_ptr
|
||||
#include <string> // para string
|
||||
#include <vector> // para vector
|
||||
class Input;
|
||||
class Text;
|
||||
enum class InputType : int;
|
||||
#include <SDL2/SDL_events.h> // Para SDL_ControllerButtonEvent
|
||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
class Input; // lines 8-8
|
||||
class Text; // lines 9-9
|
||||
enum class InputType : int; // lines 10-10
|
||||
|
||||
struct DefineButtonsButton
|
||||
{
|
||||
@@ -33,15 +34,15 @@ private:
|
||||
int x_; // Posición donde dibujar el texto
|
||||
int y_; // Posición donde dibujar el texto
|
||||
std::vector<DefineButtonsButton> buttons_; // Vector con las nuevas definiciones de botones/acciones
|
||||
int index_controller_ = 0; // Indice del controlador a reasignar
|
||||
int index_button_ = 0; // Indice para saber qué bot´çon se está definiendo
|
||||
size_t index_controller_ = 0; // Indice del controlador a reasignar
|
||||
size_t index_button_ = 0; // Indice para saber qué botón se está definiendo
|
||||
std::vector<std::string> controller_names_; // Nombres de los mandos
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void incIndexButton();
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void doControllerButtonDown(SDL_ControllerButtonEvent *event);
|
||||
void doControllerButtonDown(const SDL_ControllerButtonEvent &event);
|
||||
|
||||
// Asigna los botones definidos al input
|
||||
void bindButtons();
|
||||
@@ -49,9 +50,15 @@ private:
|
||||
// Guarda los cambios en las opciones
|
||||
void saveBindingsToOptions();
|
||||
|
||||
// Comprueba que un botón no esté ya asignado
|
||||
bool checkButtonNotInUse(SDL_GameControllerButton button);
|
||||
|
||||
// Limpia la asignación de botones
|
||||
void clearButtons();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||
DefineButtons();
|
||||
|
||||
// Destructor
|
||||
~DefineButtons() = default;
|
||||
@@ -59,15 +66,12 @@ public:
|
||||
// Dibuja el objeto en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
// Comprueba los eventos
|
||||
void checkEvents();
|
||||
|
||||
// Habilita el objeto
|
||||
bool enable(int index);
|
||||
|
||||
// Comprueba si está habilitado
|
||||
bool isEnabled();
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapControllers();
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
// IWYU pragma: no_include <bits/chrono.h>
|
||||
#include "director.h"
|
||||
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
|
||||
@@ -7,19 +8,20 @@
|
||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <chrono> // Para duration, system_clock
|
||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // Para printf, perror
|
||||
#include <string.h> // Para strcmp
|
||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // Para getuid
|
||||
#include <cstdlib> // Para exit, EXIT_FAILURE, rand, srand
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout
|
||||
#include <memory> // Para make_unique, unique_ptr, make_s...
|
||||
#include <algorithm> // Para min
|
||||
#include <cstdlib> // Para exit, EXIT_FAILURE, size_t, rand
|
||||
#include <iostream> // Para basic_ostream, operator<<, basi...
|
||||
#include <memory> // Para make_unique, unique_ptr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string> // Para operator+, allocator, char_traits
|
||||
#include <string> // Para operator+, char_traits, allocator
|
||||
#include <vector> // Para vector
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "credits.h" // Para Credits
|
||||
#include "dbgtxt.h" // Para dbg_init
|
||||
#include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_...
|
||||
#include "global_inputs.h" // Para init
|
||||
@@ -27,18 +29,17 @@
|
||||
#include "input.h" // Para Input, InputType
|
||||
#include "instructions.h" // Para Instructions
|
||||
#include "intro.h" // Para Intro
|
||||
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
|
||||
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
||||
#include "lang.h" // Para Code, loadFromFile
|
||||
#include "logo.h" // Para Logo
|
||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "on_screen_help.h" // Para OnScreenHelp
|
||||
#include "options.h" // Para Options, options, OptionsContro...
|
||||
#include "options.h" // Para Options, OptionsController, opt...
|
||||
#include "param.h" // Para Param, ParamGame, param, loadPa...
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "text.h" // Para Text
|
||||
#include "title.h" // Para Title
|
||||
#include "utils.h" // Para Overrides, overrides
|
||||
|
||||
@@ -54,8 +55,9 @@ Director::Director(int argc, const char *argv[])
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
#elif DEBUG
|
||||
section::name = section::Name::LOGO;
|
||||
#else
|
||||
#else // NORMAL GAME
|
||||
section::name = section::Name::LOGO;
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||
#endif
|
||||
|
||||
#ifndef VERBOSE
|
||||
@@ -66,71 +68,50 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
// Inicia la semilla aleatoria
|
||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::srand(seed);
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
// Crea la carpeta del sistema donde guardar los datos persistentes
|
||||
createSystemFolder("jailgames");
|
||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executable_path_);
|
||||
|
||||
// Crea el indice de ficheros
|
||||
setFileList();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParams(paramFilePath);
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
{
|
||||
manager->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa SDL
|
||||
initSDL();
|
||||
|
||||
// Inicializa JailAudio
|
||||
initJailAudio();
|
||||
|
||||
// Inicializa el texto de debug
|
||||
dbg_init(renderer_);
|
||||
|
||||
// Crea los objetos
|
||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
||||
|
||||
Screen::init(window_, renderer_);
|
||||
|
||||
Resource::init();
|
||||
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
|
||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||
|
||||
OnScreenHelp::init();
|
||||
|
||||
globalInputs::init();
|
||||
init();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
{
|
||||
close();
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
}
|
||||
|
||||
// Inicializa todo
|
||||
void Director::init()
|
||||
{
|
||||
Asset::init(executable_path_); // Crea el objeto que controla los ficheros de recursos
|
||||
setFileList(); // Crea el indice de ficheros
|
||||
loadOptionsFile(Asset::get()->get("config.txt")); // Carga el fichero de configuración
|
||||
loadParams(); // Carga los parametros
|
||||
loadScoreFile(); // Carga el fichero de puntuaciones
|
||||
|
||||
// Inicializa y crea el resto de objetos
|
||||
initSDL();
|
||||
initJailAudio();
|
||||
dbg_init(renderer_);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
Screen::init(window_, renderer_);
|
||||
Resource::init();
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
Notifier::init(std::string(), Resource::get()->getText("8bithud"));
|
||||
OnScreenHelp::init();
|
||||
}
|
||||
|
||||
// Cierra todo
|
||||
void Director::close()
|
||||
{
|
||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||
|
||||
@@ -141,12 +122,38 @@ Director::~Director()
|
||||
Notifier::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
JA_Quit();
|
||||
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
// Carga los parametros
|
||||
void Director::loadParams()
|
||||
{
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParamsFromFile(paramFilePath);
|
||||
}
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void Director::loadScoreFile()
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
{
|
||||
manager->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
@@ -173,7 +180,8 @@ void Director::bindInputs()
|
||||
Input::get()->bindKey(InputType::WINDOW_FULLSCREEN, SDL_SCANCODE_F3);
|
||||
Input::get()->bindKey(InputType::VIDEO_SHADERS, SDL_SCANCODE_F4);
|
||||
Input::get()->bindKey(InputType::MUTE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputType::CHANGE_LANG, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F7);
|
||||
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10);
|
||||
|
||||
// Asigna botones a inputs
|
||||
@@ -194,27 +202,23 @@ void Director::bindInputs()
|
||||
|
||||
// Mando - Control del programa
|
||||
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
||||
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT);
|
||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
||||
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN);
|
||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||
}
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
for (int index = 0; index < (int)options.controller.size(); ++index)
|
||||
if (Input::get()->getControllerName(i) == options.controller[index].name)
|
||||
const size_t max_controllers = std::min(2, num_gamepads);
|
||||
for (size_t i = 0; i < max_controllers; ++i)
|
||||
{
|
||||
for (auto &controller : options.controllers)
|
||||
{
|
||||
if (Input::get()->getControllerName(i) == controller.name)
|
||||
{
|
||||
options.controller[index].plugged = true;
|
||||
for (int j = 0; j < (int)options.controller[index].inputs.size(); ++j)
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
Input::get()->bindGameControllerButton(i, options.controller[index].inputs[j], options.controller[index].buttons[j]);
|
||||
Input::get()->bindGameControllerButton(i, controller.inputs.at(j), controller.buttons.at(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna botones a inputs desde otros inputs
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
@@ -229,25 +233,41 @@ void Director::bindInputs()
|
||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||
}
|
||||
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
// Guarda las asignaciones de botones en las opciones de los dos primeros mandos
|
||||
for (size_t i = 0; i < max_controllers; ++i)
|
||||
{
|
||||
options.controller[i].name = Input::get()->getControllerName(i);
|
||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
||||
// Variables asociadas al mando
|
||||
options.controllers.at(i).index = i;
|
||||
options.controllers.at(i).name = Input::get()->getControllerName(i);
|
||||
options.controllers.at(i).plugged = true;
|
||||
// Asignaciones de botones
|
||||
for (size_t j = 0; j < options.controllers.at(i).inputs.size(); ++j)
|
||||
{
|
||||
options.controller[i].buttons[j] = Input::get()->getControllerBinding(i, options.controller[i].inputs[j]);
|
||||
options.controllers.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controllers.at(i).inputs.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
// Asegura que algún jugador tenga el teclado asignado
|
||||
if (getPlayerWhoUsesKeyboard() == 0)
|
||||
{
|
||||
setKeyboardToPlayer(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa JailAudio
|
||||
void Director::initJailAudio()
|
||||
{
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
JA_EnableMusic(options.audio.music.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
JA_SetMusicVolume(options.audio.music.volume);
|
||||
JA_SetSoundVolume(options.audio.sound.volume);
|
||||
if (options.audio.enabled)
|
||||
{
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
|
||||
}
|
||||
else
|
||||
{
|
||||
JA_SetMusicVolume(0);
|
||||
JA_SetSoundVolume(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
@@ -264,35 +284,36 @@ bool Director::initSDL()
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
/*
|
||||
// Muestra información de la pantalla
|
||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
||||
std::cout << "\nDisplay modes list:" << std::endl;
|
||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||
{
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetDisplayMode(0,i,&DM);
|
||||
std::cout << " - " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
||||
}*/
|
||||
std::cout << " - " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
||||
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.size << std::endl;
|
||||
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||
{
|
||||
std::cout << "Warning: texture filtering not enabled!\n";
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||
{
|
||||
std::cout << "Warning: opengl not enabled!\n";
|
||||
}
|
||||
#endif // NO_SHADERS
|
||||
// Crea la ventana
|
||||
#endif
|
||||
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||
if (!window_)
|
||||
{
|
||||
@@ -307,10 +328,12 @@ bool Director::initSDL()
|
||||
{
|
||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
// La aceleración se activa según el define
|
||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||
#endif
|
||||
|
||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||
|
||||
if (!renderer_)
|
||||
@@ -320,14 +343,9 @@ bool Director::initSDL()
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
||||
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
@@ -359,6 +377,7 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC);
|
||||
Asset::get()->add(prefix + "/data/music/credits.ogg", AssetType::MUSIC);
|
||||
|
||||
// Sonidos
|
||||
Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND);
|
||||
@@ -377,9 +396,11 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/sound/clock.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/powerball.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/notify.wav", AssetType::SOUND);
|
||||
Asset::get()->add(prefix + "/data/sound/logo.wav", AssetType::SOUND);
|
||||
|
||||
// Shaders
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi_256.glsl", AssetType::DATA);
|
||||
Asset::get()->add(prefix + "/data/shaders/crtpi_240.glsl", AssetType::DATA);
|
||||
|
||||
// Texturas
|
||||
|
||||
@@ -427,15 +448,6 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
{ // Game Text
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_powerup.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_one_hit.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/game_text/game_text_stop.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
{ // Intro
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||
}
|
||||
@@ -495,16 +507,14 @@ void Director::setFileList()
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE);
|
||||
Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25.txt", AssetType::FONT);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25_2x.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/font/04b_25_2x.txt", AssetType::FONT);
|
||||
|
||||
// Textos
|
||||
Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG);
|
||||
@@ -516,40 +526,22 @@ void Director::setFileList()
|
||||
throw std::runtime_error("Falta algun fichero");
|
||||
}
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
void Director::loadParams(const std::string &file_path)
|
||||
{
|
||||
loadParamsFromFile(file_path);
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
void Director::checkProgramArguments(int argc, const char *argv[])
|
||||
{
|
||||
const std::vector<std::string> argument_list = {"--h", "--320x240", "--clear_score"};
|
||||
|
||||
// Establece la ruta del programa
|
||||
executable_path_ = argv[0];
|
||||
|
||||
// Comprueba el resto de parámetros
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (strcmp(argv[i], "--h") == 0)
|
||||
{
|
||||
for (const auto &argument : argument_list)
|
||||
{
|
||||
std::cout << argument << std::endl;
|
||||
}
|
||||
// std::exit(EXIT_SUCCESS);
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
}
|
||||
std::string arg = argv[i];
|
||||
|
||||
if (strcmp(argv[i], "--320x240") == 0)
|
||||
if (arg == "--320x240")
|
||||
{
|
||||
overrides.param_file = argv[i];
|
||||
overrides.param_file = arg;
|
||||
}
|
||||
|
||||
if (strcmp(argv[i], "--clear_score") == 0)
|
||||
else if (arg == "--clear_score")
|
||||
{
|
||||
overrides.clear_hi_score_table = true;
|
||||
}
|
||||
@@ -641,7 +633,11 @@ void Director::runTitle()
|
||||
void Director::runGame()
|
||||
{
|
||||
const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
|
||||
#ifdef DEBUG
|
||||
constexpr auto current_stage = 0;
|
||||
#else
|
||||
constexpr auto current_stage = 0;
|
||||
#endif
|
||||
auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF);
|
||||
game->run();
|
||||
}
|
||||
@@ -653,6 +649,13 @@ void Director::runInstructions()
|
||||
instructions->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestran los creditos del programa
|
||||
void Director::runCredits()
|
||||
{
|
||||
auto credits = std::make_unique<Credits>();
|
||||
credits->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void Director::runHiScoreTable()
|
||||
{
|
||||
@@ -669,6 +672,16 @@ void Director::runDemoGame()
|
||||
game->run();
|
||||
}
|
||||
|
||||
// Ejecuta la sección init
|
||||
void Director::runInit()
|
||||
{
|
||||
if (section::options == section::Options::RELOAD)
|
||||
{
|
||||
Resource::get()->reload();
|
||||
}
|
||||
section::name = section::Name::LOGO;
|
||||
}
|
||||
|
||||
int Director::run()
|
||||
{
|
||||
// Bucle principal
|
||||
@@ -677,56 +690,62 @@ int Director::run()
|
||||
switch (section::name)
|
||||
{
|
||||
case section::Name::INIT:
|
||||
section::name = section::Name::LOGO;
|
||||
runInit();
|
||||
break;
|
||||
|
||||
case section::Name::LOGO:
|
||||
runLogo();
|
||||
break;
|
||||
|
||||
case section::Name::INTRO:
|
||||
runIntro();
|
||||
break;
|
||||
|
||||
case section::Name::TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
|
||||
case section::Name::GAME:
|
||||
runGame();
|
||||
break;
|
||||
|
||||
case section::Name::HI_SCORE_TABLE:
|
||||
runHiScoreTable();
|
||||
break;
|
||||
|
||||
case section::Name::GAME_DEMO:
|
||||
runDemoGame();
|
||||
break;
|
||||
|
||||
case section::Name::INSTRUCTIONS:
|
||||
runInstructions();
|
||||
break;
|
||||
|
||||
case section::Name::CREDITS:
|
||||
runCredits();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ARCADE
|
||||
// Comprueba si ha de apagar el sistema
|
||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||
shutdownSystem();
|
||||
#endif
|
||||
std::string return_code;
|
||||
switch (section::options)
|
||||
{
|
||||
case section::Options::QUIT_WITH_KEYBOARD:
|
||||
return_code = "with keyboard";
|
||||
break;
|
||||
case section::Options::QUIT_WITH_CONTROLLER:
|
||||
return_code = "with controller";
|
||||
break;
|
||||
default:
|
||||
return_code = "from event";
|
||||
break;
|
||||
}
|
||||
|
||||
const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
|
||||
: "from event";
|
||||
std::cout << "\nGame end " << return_code << std::endl;
|
||||
|
||||
#ifndef VERBOSE
|
||||
// Habilita de nuevo los std::cout
|
||||
std::cout.rdbuf(orig_buf);
|
||||
#endif
|
||||
#ifdef ARCADE
|
||||
// Comprueba si ha de apagar el sistema
|
||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||
shutdownSystem();
|
||||
#endif
|
||||
|
||||
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
||||
}
|
||||
@@ -739,15 +758,12 @@ std::string Director::getLangFile(lang::Code code)
|
||||
case lang::Code::ba_BA:
|
||||
return Asset::get()->get("ba_BA.txt");
|
||||
break;
|
||||
|
||||
case lang::Code::es_ES:
|
||||
return Asset::get()->get("es_ES.txt");
|
||||
break;
|
||||
|
||||
case lang::Code::en_UK:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -773,4 +789,4 @@ void Director::shutdownSystem()
|
||||
#error "Sistema operativo no soportado"
|
||||
#endif
|
||||
}
|
||||
#endif // ARCADE
|
||||
#endif // ARCADE
|
||||
|
||||
@@ -34,9 +34,6 @@ private:
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
void bindInputs();
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
void loadParams(const std::string &file_path);
|
||||
|
||||
// Crea el indice de ficheros
|
||||
void setFileList();
|
||||
|
||||
@@ -61,12 +58,18 @@ private:
|
||||
// Ejecuta la sección donde se muestran las instrucciones
|
||||
void runInstructions();
|
||||
|
||||
// Ejecuta la sección donde se muestran los creditos del programa
|
||||
void runCredits();
|
||||
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void runHiScoreTable();
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
void runDemoGame();
|
||||
|
||||
// Ejecuta la sección init
|
||||
void runInit();
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLangFile(lang::Code code);
|
||||
#ifdef ARCADE
|
||||
@@ -74,6 +77,18 @@ private:
|
||||
void shutdownSystem();
|
||||
#endif
|
||||
|
||||
// Inicializa todo
|
||||
void init();
|
||||
|
||||
// Cierra todo
|
||||
void close();
|
||||
|
||||
// Carga los parametros
|
||||
void loadParams();
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void loadScoreFile();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(int argc, const char *argv[]);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
constexpr int NAME_LENGHT = 8;
|
||||
constexpr int NAME_LENGHT = 6;
|
||||
|
||||
/*
|
||||
Un array, "characterList", contiene la lista de caracteres
|
||||
|
||||
1266
source/game.cpp
192
source/game.h
@@ -5,27 +5,25 @@
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "balloon.h" // Para Balloon
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "player.h" // Para Player
|
||||
#include "utils.h" // Para Demo
|
||||
class Asset; // lines 12-12
|
||||
class Background; // lines 13-13
|
||||
class BalloonFormations; // lines 14-14
|
||||
class Bullet; // lines 15-15
|
||||
class Explosions; // lines 16-16
|
||||
class Fade; // lines 17-17
|
||||
class Input; // lines 18-18
|
||||
class Item; // lines 19-19
|
||||
class PathSprite; // lines 20-20
|
||||
class Scoreboard; // lines 21-21
|
||||
class Screen; // lines 22-22
|
||||
class SmartSprite; // lines 23-23
|
||||
class Text; // lines 24-24
|
||||
class Texture; // lines 25-25
|
||||
enum class BulletType : Uint8; // lines 26-26
|
||||
enum class ItemType; // lines 27-27
|
||||
class Asset; // lines 13-13
|
||||
class Background; // lines 14-14
|
||||
class BalloonManager;
|
||||
class Bullet; // lines 15-15
|
||||
class Fade; // lines 16-16
|
||||
class Input; // lines 17-17
|
||||
class Item; // lines 18-18
|
||||
class PathSprite; // lines 19-19
|
||||
class Scoreboard; // lines 20-20
|
||||
class Screen; // lines 21-21
|
||||
class SmartSprite; // lines 22-22
|
||||
class Texture; // lines 23-23
|
||||
enum class BulletType : Uint8; // lines 24-24
|
||||
enum class ItemType; // lines 25-25
|
||||
struct Path; // lines 26-26
|
||||
|
||||
// Modo demo
|
||||
constexpr bool GAME_MODE_DEMO_OFF = false;
|
||||
@@ -64,10 +62,15 @@ constexpr int TOTAL_SCORE_DATA = 3;
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
// Constantes
|
||||
// Enum
|
||||
enum class GameState
|
||||
{
|
||||
PLAYING,
|
||||
COMPLETED,
|
||||
GAME_OVER,
|
||||
};
|
||||
|
||||
// Contadores
|
||||
static constexpr int STAGE_COUNTER_ = 200;
|
||||
static constexpr int HELP_COUNTER_ = 1000;
|
||||
static constexpr int GAME_COMPLETED_START_FADE_ = 500;
|
||||
static constexpr int GAME_COMPLETED_END_ = 700;
|
||||
@@ -118,14 +121,11 @@ private:
|
||||
Input *input_; // Manejador de entrada
|
||||
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
||||
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Explosions> explosions_; // Objeto para dibujar explosiones
|
||||
std::unique_ptr<BalloonFormations> balloon_formations_; // Objeto para gestionar las oleadas enemigas
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
|
||||
SDL_Texture *canvas_; // Textura para dibujar la zona de juego
|
||||
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
std::vector<std::shared_ptr<Balloon>> balloons_; // Vector con los globos
|
||||
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
|
||||
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
||||
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
|
||||
@@ -133,58 +133,38 @@ private:
|
||||
|
||||
std::shared_ptr<Texture> bullet_texture_; // Textura para las balas
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::shared_ptr<Texture>> balloon_textures_; // Vector con las texturas de los globos
|
||||
std::vector<std::shared_ptr<Texture>> explosions_textures_; // Vector con las texturas de las explosiones
|
||||
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores;
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
|
||||
|
||||
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
|
||||
std::vector<std::vector<std::string>> balloon_animations_; // Vector con las animaciones de los globos
|
||||
std::vector<std::vector<std::string>> explosions_animations_; // Vector con las animaciones de las explosiones
|
||||
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
|
||||
|
||||
std::unique_ptr<Text> text_; // Fuente para los textos del juego
|
||||
std::unique_ptr<Text> text_big_; // Fuente de texto grande
|
||||
std::unique_ptr<Text> text_nokia2_; // Otra fuente de texto para mensajes
|
||||
std::unique_ptr<Text> text_nokia2_big_; // Y la versión en grande
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
|
||||
|
||||
// Variables
|
||||
HiScoreEntry hi_score_ = HiScoreEntry(
|
||||
options.game.hi_score_table[0].name,
|
||||
options.game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
|
||||
|
||||
int current_stage_; // Indica la fase actual
|
||||
int last_stage_reached_; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
|
||||
GameDifficulty difficulty_ = options.game.difficulty; // Dificultad del juego
|
||||
Helper helper_; // Variable para gestionar las ayudas
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
|
||||
bool game_completed_ = false; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
|
||||
bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
|
||||
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
|
||||
float balloon_speed_; // Velocidad a la que se mueven los enemigos
|
||||
float default_balloon_speed_; // Velocidad base de los enemigos, sin incrementar
|
||||
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
|
||||
float get_ready_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos X por donde se desplaza el texto
|
||||
int stage_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos Y por donde se desplaza el texto
|
||||
int balloon_deploy_counter_ = 0; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
int balloons_popped_ = 0; // Lleva la cuenta de los globos explotados
|
||||
int counter_ = 0; // Contador para el juego
|
||||
int current_power_ = 0; // Poder actual almacenado para completar la fase
|
||||
int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida
|
||||
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
int menace_current_ = 0; // Nivel de amenaza actual
|
||||
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
int stage_bitmap_counter_ = STAGE_COUNTER_; // Contador para el tiempo visible del texto de Stage
|
||||
int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
|
||||
int menace_current_ = 0; // Nivel de amenaza actual
|
||||
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
GameState state_ = GameState::PLAYING; // Estado
|
||||
#ifdef DEBUG
|
||||
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
|
||||
#endif
|
||||
@@ -201,12 +181,6 @@ private:
|
||||
// Asigna texturas y animaciones
|
||||
void setResources();
|
||||
|
||||
// Crea una formación de enemigos
|
||||
void deployBalloonFormation();
|
||||
|
||||
// Aumenta el poder de la fase
|
||||
void increaseStageCurrentPower(int power);
|
||||
|
||||
// Actualiza el valor de HiScore en caso necesario
|
||||
void updateHiScore();
|
||||
|
||||
@@ -220,52 +194,10 @@ private:
|
||||
void updateStage();
|
||||
|
||||
// Actualiza el estado de fin de la partida
|
||||
void updateGameOver();
|
||||
void updateGameOverState();
|
||||
|
||||
// Actualiza los globos
|
||||
void updateBalloons();
|
||||
|
||||
// Pinta en pantalla todos los globos activos
|
||||
void renderBalloons();
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
std::shared_ptr<Balloon> createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int stopped_counter);
|
||||
|
||||
// Crea un globo a partir de otro globo
|
||||
void createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction);
|
||||
|
||||
// Crea una PowerBall
|
||||
void createPowerBall();
|
||||
|
||||
// Establece la velocidad de los globos
|
||||
void setBalloonSpeed(float speed);
|
||||
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void updateBalloonSpeed();
|
||||
|
||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||
void popBalloon(std::shared_ptr<Balloon> balloon);
|
||||
|
||||
// Explosiona un globo. Lo destruye
|
||||
void destroyBalloon(std::shared_ptr<Balloon> &balloon);
|
||||
|
||||
// Destruye todos los globos
|
||||
void destroyAllBalloons();
|
||||
|
||||
// Detiene todos los globos
|
||||
void stopAllBalloons();
|
||||
|
||||
// Pone en marcha todos los globos
|
||||
void startAllBalloons();
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void reverseColorsToAllBalloons();
|
||||
|
||||
// Cambia el color de todos los globos
|
||||
void normalColorsToAllBalloons();
|
||||
|
||||
// Vacia el vector de globos
|
||||
void freeBalloons();
|
||||
// Destruye todos los items
|
||||
void destroyAllItems();
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
bool checkPlayerBalloonCollision(std::shared_ptr<Player> &player);
|
||||
@@ -304,7 +236,10 @@ private:
|
||||
void freeItems();
|
||||
|
||||
// Crea un objeto PathSprite
|
||||
void createPathSprite(int x, std::shared_ptr<Texture> texture);
|
||||
void createItemText(int x, std::shared_ptr<Texture> texture);
|
||||
|
||||
// Crea un objeto PathSprite
|
||||
void createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture> texture);
|
||||
|
||||
// Vacia el vector de smartsprites
|
||||
void freeSmartSprites();
|
||||
@@ -330,42 +265,21 @@ private:
|
||||
// Acciones a realizar cuando el jugador muere
|
||||
void killPlayer(std::shared_ptr<Player> &player);
|
||||
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
void evaluateAndSetMenace();
|
||||
|
||||
// Actualiza la variable EnemyDeployCounter
|
||||
void updateBalloonDeployCounter();
|
||||
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateTimeStopped();
|
||||
|
||||
// Gestiona el nivel de amenaza
|
||||
void updateMenace();
|
||||
|
||||
// Actualiza el fondo
|
||||
void updateBackground();
|
||||
|
||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||
void initPaths();
|
||||
|
||||
// Pinta diferentes mensajes en la pantalla
|
||||
void renderMessages();
|
||||
|
||||
// Habilita el efecto del item de detener el tiempo
|
||||
void enableTimeStopItem();
|
||||
|
||||
// Deshabilita el efecto del item de detener el tiempo
|
||||
void disableTimeStopItem();
|
||||
|
||||
// Indica si se puede crear una powerball
|
||||
bool canPowerBallBeCreated();
|
||||
|
||||
// Calcula el poder actual de los globos en pantalla
|
||||
int calculateScreenPower();
|
||||
|
||||
// Actualiza el tramo final de juego, una vez completado
|
||||
void updateGameCompleted();
|
||||
|
||||
// Actualiza las variables de ayuda
|
||||
void updateHelper();
|
||||
|
||||
@@ -453,9 +367,6 @@ private:
|
||||
// Inicializa los jugadores
|
||||
void initPlayers(int player_id);
|
||||
|
||||
// Crea dos globos gordos
|
||||
void createTwoBigBalloons();
|
||||
|
||||
// Pausa la música
|
||||
void pauseMusic();
|
||||
|
||||
@@ -465,6 +376,33 @@ private:
|
||||
// Detiene la música
|
||||
void stopMusic();
|
||||
|
||||
// Actualiza las variables durante el modo demo
|
||||
void updateDemo();
|
||||
#ifdef RECORDING
|
||||
// Actualiza las variables durante el modo de grabación
|
||||
void updateRecording();
|
||||
#endif
|
||||
// Actualiza las variables durante el transcurso normal del juego
|
||||
void updateGame();
|
||||
|
||||
// Gestiona eventos para el estado del final del juego
|
||||
void updateCompletedState();
|
||||
|
||||
// Comprueba el estado del juego
|
||||
void checkState();
|
||||
|
||||
// Vacía los vectores de elementos deshabilitados
|
||||
void cleanVectors();
|
||||
|
||||
// Gestiona el nivel de amenaza
|
||||
void updateMenace();
|
||||
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
void evaluateAndSetMenace();
|
||||
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void checkAndUpdateBalloonSpeed();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(int playerID, int current_stage, bool demo);
|
||||
|
||||
@@ -15,30 +15,24 @@ GameLogo::GameLogo(int x, int y)
|
||||
coffee_texture_(Resource::get()->getTexture("title_coffee.png")),
|
||||
crisis_texture_(Resource::get()->getTexture("title_crisis.png")),
|
||||
arcade_edition_texture_(Resource::get()->getTexture("title_arcade_edition.png")),
|
||||
|
||||
dust_left_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
dust_right_sprite_(std::make_unique<AnimatedSprite>(dust_texture_, Resource::get()->getAnimation("title_dust.ani"))),
|
||||
|
||||
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
|
||||
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
|
||||
|
||||
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
|
||||
|
||||
x_(x),
|
||||
y_(y)
|
||||
{
|
||||
// Inicializa las variables
|
||||
init();
|
||||
}
|
||||
y_(y) { }
|
||||
|
||||
// Inicializa las variables
|
||||
void GameLogo::init()
|
||||
{
|
||||
const auto xp = x_ - coffee_sprite_->getWidth() / 2;
|
||||
const auto xp = x_ - coffee_texture_->getWidth() / 2;
|
||||
const auto desp = getInitialVerticalDesp();
|
||||
|
||||
// Variables
|
||||
status_ = Status::DISABLED;
|
||||
coffee_crisis_status_ = Status::DISABLED;
|
||||
arcade_edition_status_ = Status::DISABLED;
|
||||
|
||||
shake_.desp = 1;
|
||||
shake_.delay = 2;
|
||||
shake_.lenght = 8;
|
||||
@@ -46,6 +40,8 @@ void GameLogo::init()
|
||||
shake_.counter = shake_.delay;
|
||||
shake_.origin = xp;
|
||||
|
||||
zoom_ = 3.0f;
|
||||
|
||||
// Inicializa el bitmap de 'Coffee'
|
||||
coffee_sprite_->setPosX(xp);
|
||||
coffee_sprite_->setPosY(y_ - coffee_texture_->getHeight() - desp);
|
||||
@@ -90,6 +86,9 @@ void GameLogo::init()
|
||||
dust_left_sprite_->setPosY(y_);
|
||||
dust_left_sprite_->setWidth(16);
|
||||
dust_left_sprite_->setHeight(16);
|
||||
|
||||
// Inicializa el bitmap de 'Arcade Edition'
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
}
|
||||
|
||||
// Pinta la clase en pantalla
|
||||
@@ -99,7 +98,7 @@ void GameLogo::render()
|
||||
coffee_sprite_->render();
|
||||
crisis_sprite_->render();
|
||||
|
||||
if (status_ == Status::FINISHED)
|
||||
if (arcade_edition_status_ != Status::DISABLED)
|
||||
{
|
||||
arcade_edition_sprite_->render();
|
||||
}
|
||||
@@ -112,17 +111,18 @@ void GameLogo::render()
|
||||
// Actualiza la lógica de la clase
|
||||
void GameLogo::update()
|
||||
{
|
||||
switch (status_)
|
||||
switch (coffee_crisis_status_)
|
||||
{
|
||||
case Status::MOVING:
|
||||
{
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
|
||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||
// Si los objetos han llegado a su destino, cambia el estado
|
||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished())
|
||||
{
|
||||
status_ = Status::SHAKING;
|
||||
coffee_crisis_status_ = Status::SHAKING;
|
||||
arcade_edition_status_ = Status::MOVING;
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||
@@ -153,7 +153,7 @@ void GameLogo::update()
|
||||
{
|
||||
coffee_sprite_->setPosX(shake_.origin);
|
||||
crisis_sprite_->setPosX(shake_.origin + 15);
|
||||
status_ = Status::FINISHED;
|
||||
coffee_crisis_status_ = Status::FINISHED;
|
||||
}
|
||||
|
||||
dust_right_sprite_->update();
|
||||
@@ -173,19 +173,37 @@ void GameLogo::update()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (arcade_edition_status_)
|
||||
{
|
||||
case Status::MOVING:
|
||||
{
|
||||
zoom_ -= 0.1f;
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
if (zoom_ <= 1.0f)
|
||||
{
|
||||
arcade_edition_status_ = Status::FINISHED;
|
||||
zoom_ = 1.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Activa la clase
|
||||
void GameLogo::enable()
|
||||
{
|
||||
init();
|
||||
status_ = Status::MOVING;
|
||||
coffee_crisis_status_ = Status::MOVING;
|
||||
}
|
||||
|
||||
// Indica si ha terminado la animación
|
||||
bool GameLogo::hasFinished() const
|
||||
{
|
||||
return status_ == Status::FINISHED;
|
||||
return coffee_crisis_status_ == Status::FINISHED && arcade_edition_status_ == Status::FINISHED;
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
@@ -194,6 +212,7 @@ void GameLogo::reLoad()
|
||||
dust_texture_->reLoad();
|
||||
coffee_texture_->reLoad();
|
||||
crisis_texture_->reLoad();
|
||||
arcade_edition_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Calcula el desplazamiento vertical inicial
|
||||
|
||||
@@ -43,11 +43,13 @@ private:
|
||||
std::unique_ptr<Sprite> arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition"
|
||||
|
||||
// Variables
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
int x_; // Posición donde dibujar el logo
|
||||
int y_; // Posición donde dibujar el logo
|
||||
float zoom_; // Zoom aplicado al texto "ARCADE EDITION"
|
||||
|
||||
Status status_; // Estado en el que se encuentra la clase
|
||||
Shake shake_; // Estructura para generar el efecto de agitación
|
||||
Status coffee_crisis_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "COFFEE CRISIS"
|
||||
Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION"
|
||||
Shake shake_; // Estructura para generar el efecto de agitación
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "global_inputs.h"
|
||||
#include <string> // Para operator+, string
|
||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include <string> // Para operator+, string
|
||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "asset.h"
|
||||
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
|
||||
#include "lang.h" // Para getText
|
||||
#include "notifier.h" // Para Notifier
|
||||
@@ -8,22 +9,13 @@
|
||||
#include "options.h" // Para Options, OptionsAudio, options, OptionsM...
|
||||
#include "section.h" // Para Name, Options, name, options
|
||||
#include "utils.h" // Para boolToOnOff, stringInVector
|
||||
#include "screen.h"
|
||||
|
||||
namespace globalInputs
|
||||
{
|
||||
// Variables
|
||||
std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init()
|
||||
{
|
||||
const auto num_inputs = Input::get()->getNumControllers() + 1;
|
||||
service_pressed_counter.reserve(num_inputs);
|
||||
for (int i = 0; i < num_inputs; ++i)
|
||||
{
|
||||
service_pressed_counter.push_back(0);
|
||||
}
|
||||
}
|
||||
int service_pressed_counter = 0;
|
||||
bool service_pressed = false;
|
||||
|
||||
// Termina
|
||||
void quit(section::Options code)
|
||||
@@ -32,16 +24,18 @@ namespace globalInputs
|
||||
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
||||
if (code_found)
|
||||
{
|
||||
// Si la notificación de salir está activa, cambia de sección
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = code;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si la notificación de salir no está activa, muestra la notificación
|
||||
#ifdef ARCADE
|
||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
||||
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
|
||||
#else
|
||||
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
||||
Notifier::get()->showText({lang::getText(94), std::string()}, -1, exit_code);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -50,95 +44,225 @@ namespace globalInputs
|
||||
void reset()
|
||||
{
|
||||
section::name = section::Name::INIT;
|
||||
Notifier::get()->showText("Reset");
|
||||
Notifier::get()->showText({"Reset"});
|
||||
}
|
||||
|
||||
// Activa o desactiva el audio
|
||||
void switchAudio()
|
||||
void toggleAudio()
|
||||
{
|
||||
options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled;
|
||||
JA_EnableMusic(options.audio.music.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
Notifier::get()->showText("Audio " + boolToOnOff(options.audio.music.enabled));
|
||||
options.audio.enabled = !options.audio.enabled;
|
||||
if (options.audio.enabled)
|
||||
{
|
||||
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
|
||||
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
|
||||
}
|
||||
else
|
||||
{
|
||||
JA_SetMusicVolume(0);
|
||||
JA_SetSoundVolume(0);
|
||||
}
|
||||
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLangFile(lang::Code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return Asset::get()->get("ba_BA.txt");
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return Asset::get()->get("es_ES.txt");
|
||||
break;
|
||||
default:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene una cadena a partir de un lang::Code
|
||||
std::string getLangName(lang::Code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return "ba_BA";
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return "es_ES";
|
||||
break;
|
||||
default:
|
||||
return "en_UK";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el idioma
|
||||
void changeLang()
|
||||
{
|
||||
options.game.language = lang::change(options.game.language);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
section::name = section::Name::INIT;
|
||||
section::options = section::Options::RELOAD;
|
||||
Notifier::get()->showText({getLangName(options.game.language)});
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check()
|
||||
{
|
||||
// Comprueba si se sale con el teclado
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
// Teclado
|
||||
{
|
||||
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a resetear el juego
|
||||
else if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
service_pressed_counter[0]++;
|
||||
|
||||
if (service_pressed_counter[0] >= 3000)
|
||||
#ifndef ARCADE
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
service_pressed_counter[0] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se sale con el mando
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||
Screen::get()->toggleVideoMode();
|
||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
Notifier::get()->showText({mode + " mode"});
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a resetear el juego
|
||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText({"Window size x" + size});
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText({"Window size x" + size});
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Salir
|
||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
// Audio
|
||||
if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
switchAudio();
|
||||
toggleAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
// Idioma
|
||||
if (Input::get()->checkInput(InputType::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
service_pressed_counter[i + 1]++;
|
||||
changeLang();
|
||||
return;
|
||||
}
|
||||
|
||||
if (service_pressed_counter[i + 1] >= 3000)
|
||||
// Shaders
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->toggleShaders();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Comprueba el teclado para mostrar la información de debug
|
||||
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
Screen::get()->toggleDebugInfo();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// OnScreenHelp
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
service_pressed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Mandos
|
||||
{
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Salir
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Audio
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
toggleAudio();
|
||||
return;
|
||||
}
|
||||
|
||||
// Shaders
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
Screen::get()->toggleShaders();
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
// Debug Info
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||
Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
Screen::get()->toggleDebugInfo();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// OnScreenHelp
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
service_pressed = true;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
service_pressed_counter[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza variables
|
||||
void update()
|
||||
{
|
||||
if (service_pressed)
|
||||
{
|
||||
++service_pressed_counter;
|
||||
if (service_pressed_counter >= 200)
|
||||
{
|
||||
OnScreenHelp::get()->toggleState();
|
||||
service_pressed_counter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
service_pressed_counter = 0;
|
||||
}
|
||||
|
||||
service_pressed = false;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <vector>
|
||||
namespace globalInputs
|
||||
{
|
||||
extern std::vector<int> service_pressed_counter;
|
||||
|
||||
// Inicializa variables
|
||||
void init();
|
||||
extern int service_pressed_counter;
|
||||
extern bool service_pressed;
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check();
|
||||
|
||||
// Actualiza variables
|
||||
void update();
|
||||
}
|
||||
@@ -27,7 +27,7 @@ HiScoreTable::HiScoreTable()
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
background_(std::make_unique<Background>()),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
counter_(0),
|
||||
ticks_(0),
|
||||
view_area_({0, 0, param.game.width, param.game.height}),
|
||||
@@ -77,6 +77,9 @@ void HiScoreTable::update()
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background_->update();
|
||||
|
||||
@@ -208,9 +211,6 @@ void HiScoreTable::checkInput()
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
Screen::get()->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
Uint16 counter_; // Contador
|
||||
|
||||
386
source/input.cpp
@@ -1,9 +1,13 @@
|
||||
#include "input.h"
|
||||
#include <SDL2/SDL.h> // para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||
#include <SDL2/SDL_error.h> // para SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // para SDL_ENABLE
|
||||
#include <SDL2/SDL_keyboard.h> // para SDL_GetKeyboardState
|
||||
#include <iostream> // para basic_ostream, operator<<, cout, basi...
|
||||
#include <SDL2/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // Para SDL_ENABLE
|
||||
#include <SDL2/SDL_keyboard.h> // Para SDL_GetKeyboardState
|
||||
#include <algorithm> // Para find
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||
#include <iterator> // Para distance
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||
#include <utility> // Para pair
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Input *Input::input_ = nullptr;
|
||||
@@ -28,49 +32,23 @@ Input *Input::get()
|
||||
|
||||
// Constructor
|
||||
Input::Input(const std::string &game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path),
|
||||
enabled_(true)
|
||||
: game_controller_db_path_(game_controller_db_path)
|
||||
{
|
||||
// Busca si hay mandos conectados
|
||||
discoverGameControllers();
|
||||
|
||||
// Inicializa las vectores
|
||||
KeyBindings kb;
|
||||
kb.scancode = 0;
|
||||
kb.active = false;
|
||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), kb);
|
||||
|
||||
ControllerBindings gcb;
|
||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
gcb.active = false;
|
||||
controller_bindings_.resize(num_gamepads_);
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
controller_bindings_[i].resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), gcb);
|
||||
}
|
||||
|
||||
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
|
||||
game_inputs_.clear();
|
||||
game_inputs_.push_back(InputType::FIRE_LEFT);
|
||||
game_inputs_.push_back(InputType::FIRE_CENTER);
|
||||
game_inputs_.push_back(InputType::FIRE_RIGHT);
|
||||
game_inputs_.push_back(InputType::UP);
|
||||
game_inputs_.push_back(InputType::DOWN);
|
||||
game_inputs_.push_back(InputType::LEFT);
|
||||
game_inputs_.push_back(InputType::RIGHT);
|
||||
// Inicializa los vectores
|
||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), KeyBindings());
|
||||
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputType::NUMBER_OF_INPUTS), ControllerBindings()));
|
||||
|
||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||
button_inputs_.clear();
|
||||
button_inputs_.push_back(InputType::FIRE_LEFT);
|
||||
button_inputs_.push_back(InputType::FIRE_CENTER);
|
||||
button_inputs_.push_back(InputType::FIRE_RIGHT);
|
||||
button_inputs_.push_back(InputType::START);
|
||||
button_inputs_ = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START};
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(InputType input, SDL_Scancode code)
|
||||
{
|
||||
key_bindings_[static_cast<int>(input)].scancode = code;
|
||||
key_bindings_.at(static_cast<int>(input)).scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
@@ -78,7 +56,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input, SDL_
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
controller_bindings_[controller_index][static_cast<int>(input)].button = button;
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,41 +65,24 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
controller_bindings_[controller_index][static_cast<int>(input_target)].button = controller_bindings_[controller_index][static_cast<int>(input_source)].button;
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
||||
bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
if (!enabled_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
success_keyboard = keyStates[key_bindings_[input_index].scancode] != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -142,151 +103,29 @@ bool Input::checkInput(InputType input, bool repeat, int device, int controller_
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||
{
|
||||
key_bindings_[input_index].active = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
success_controller = checkAxisInput(input, controller_index);
|
||||
if (!success_controller)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!controller_bindings_[controller_index][input_index].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
controller_bindings_[controller_index][input_index].active = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
||||
{
|
||||
controller_bindings_[controller_index][input_index].active = false;
|
||||
success_controller = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (success_keyboard || success_controller);
|
||||
}
|
||||
|
||||
// Comprueba si un input con modificador esta activo
|
||||
bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int device, int controller_index)
|
||||
{
|
||||
if (!enabled_ || controller_index >= num_gamepads_ || !checkInput(input_mod, INPUT_ALLOW_REPEAT, device, controller_index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
{
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!key_bindings_[input_index].active)
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
key_bindings_[input_index].active = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||
{
|
||||
key_bindings_[input_index].active = false;
|
||||
success_keyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_)
|
||||
if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY))
|
||||
{
|
||||
success_controller = checkAxisInput(input, controller_index);
|
||||
if (!success_controller)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
{
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
}
|
||||
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!controller_bindings_[controller_index][input_index].active)
|
||||
if (!controller_bindings_.at(controller_index).at(input_index).active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
|
||||
{
|
||||
controller_bindings_[controller_index][input_index].active = true;
|
||||
controller_bindings_.at(controller_index).at(input_index).active = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
@@ -296,15 +135,11 @@ bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
|
||||
{
|
||||
controller_bindings_[controller_index][input_index].active = false;
|
||||
success_controller = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
controller_bindings_.at(controller_index).at(input_index).active = false;
|
||||
}
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,14 +149,9 @@ bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool Input::checkAnyInput(int device, int controller_index)
|
||||
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
if (device == INPUT_USE_ANY)
|
||||
{
|
||||
controller_index = 0;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
@@ -337,7 +167,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
||||
|
||||
if (gameControllerFound())
|
||||
{
|
||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||
if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||
{
|
||||
@@ -357,7 +187,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
||||
int Input::checkAnyButtonPressed(bool repeat)
|
||||
{
|
||||
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_ANY))
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -366,7 +196,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
||||
for (auto bi : button_inputs_)
|
||||
{
|
||||
// Comprueba el teclado
|
||||
if (checkInput(bi, repeat, INPUT_USE_KEYBOARD))
|
||||
if (checkInput(bi, repeat, InputDeviceToUse::KEYBOARD))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -374,7 +204,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
if (checkInput(bi, repeat, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (checkInput(bi, repeat, InputDeviceToUse::CONTROLLER, i))
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
@@ -396,9 +226,7 @@ bool Input::discoverGameControllers()
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||
{
|
||||
{
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
@@ -408,7 +236,7 @@ bool Input::discoverGameControllers()
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
||||
auto joy = SDL_JoystickOpen(i);
|
||||
joysticks_.push_back(joy);
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
@@ -417,7 +245,6 @@ bool Input::discoverGameControllers()
|
||||
}
|
||||
|
||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
// std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
|
||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||
|
||||
if (num_gamepads_ > 0)
|
||||
@@ -432,16 +259,12 @@ bool Input::discoverGameControllers()
|
||||
{
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
{
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
}
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
controller_names_.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,27 +272,17 @@ bool Input::discoverGameControllers()
|
||||
}
|
||||
|
||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
bool Input::gameControllerFound()
|
||||
{
|
||||
return num_gamepads_ > 0 ? true : false;
|
||||
}
|
||||
bool Input::gameControllerFound() { return num_gamepads_ > 0 ? true : false; }
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string Input::getControllerName(int controller_index) const
|
||||
{
|
||||
return num_gamepads_ > 0 ? controller_names_[controller_index] : "";
|
||||
}
|
||||
std::string Input::getControllerName(int controller_index) const { return num_gamepads_ > 0 ? controller_names_.at(controller_index) : std::string(); }
|
||||
|
||||
// Obten el número de mandos conectados
|
||||
int Input::getNumControllers() const
|
||||
{
|
||||
return num_gamepads_;
|
||||
}
|
||||
int Input::getNumControllers() const { return num_gamepads_; }
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int Input::getJoyIndex(int id) const
|
||||
@@ -485,14 +298,14 @@ int Input::getJoyIndex(int id) const
|
||||
}
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void Input::printBindings(int device, int controller_index) const
|
||||
void Input::printBindings(InputDeviceToUse device, int controller_index) const
|
||||
{
|
||||
if (device == INPUT_USE_ANY || device == INPUT_USE_KEYBOARD)
|
||||
if (device == InputDeviceToUse::ANY || device == InputDeviceToUse::KEYBOARD)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (device == INPUT_USE_GAMECONTROLLER)
|
||||
if (device == InputDeviceToUse::CONTROLLER)
|
||||
{
|
||||
if (controller_index >= num_gamepads_)
|
||||
{
|
||||
@@ -500,13 +313,12 @@ void Input::printBindings(int device, int controller_index) const
|
||||
}
|
||||
|
||||
// Muestra el nombre del mando
|
||||
std::cout << "\n"
|
||||
<< controller_names_[controller_index] << std::endl;
|
||||
std::cout << "\n" + controller_names_.at(controller_index) << std::endl;
|
||||
|
||||
// Muestra los botones asignados
|
||||
for (auto bi : button_inputs_)
|
||||
{
|
||||
std::cout << to_string(bi) << " : " << controller_bindings_[controller_index][static_cast<int>(bi)].button << std::endl;
|
||||
std::cout << to_string(bi) << " : " << controller_bindings_.at(controller_index).at(static_cast<int>(bi)).button << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -520,116 +332,58 @@ SDL_GameControllerButton Input::getControllerBinding(int controller_index, Input
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int Input::getIndexByName(const std::string &name) const
|
||||
{
|
||||
for (int i = 0; i < num_gamepads_; ++i)
|
||||
{
|
||||
if (controller_names_[i] == name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
auto it = std::find(controller_names_.begin(), controller_names_.end(), name);
|
||||
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||
}
|
||||
|
||||
// Convierte un InputType a std::string
|
||||
std::string Input::to_string(InputType input) const
|
||||
{
|
||||
if (input == InputType::FIRE_LEFT)
|
||||
switch (input)
|
||||
{
|
||||
case InputType::FIRE_LEFT:
|
||||
return "input_fire_left";
|
||||
}
|
||||
|
||||
if (input == InputType::FIRE_CENTER)
|
||||
{
|
||||
case InputType::FIRE_CENTER:
|
||||
return "input_fire_center";
|
||||
}
|
||||
|
||||
if (input == InputType::FIRE_RIGHT)
|
||||
{
|
||||
case InputType::FIRE_RIGHT:
|
||||
return "input_fire_right";
|
||||
}
|
||||
|
||||
if (input == InputType::START)
|
||||
{
|
||||
case InputType::START:
|
||||
return "input_start";
|
||||
}
|
||||
|
||||
if (input == InputType::SERVICE)
|
||||
{
|
||||
case InputType::SERVICE:
|
||||
return "input_service";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// Convierte un std::string a InputType
|
||||
InputType Input::to_inputs_e(const std::string &name) const
|
||||
{
|
||||
if (name == "input_fire_left")
|
||||
{
|
||||
return InputType::FIRE_LEFT;
|
||||
}
|
||||
static const std::unordered_map<std::string, InputType> inputMap = {
|
||||
{"input_fire_left", InputType::FIRE_LEFT},
|
||||
{"input_fire_center", InputType::FIRE_CENTER},
|
||||
{"input_fire_right", InputType::FIRE_RIGHT},
|
||||
{"input_start", InputType::START},
|
||||
{"input_service", InputType::SERVICE}};
|
||||
|
||||
if (name == "input_fire_center")
|
||||
{
|
||||
return InputType::FIRE_CENTER;
|
||||
}
|
||||
|
||||
if (name == "input_fire_right")
|
||||
{
|
||||
return InputType::FIRE_RIGHT;
|
||||
}
|
||||
|
||||
if (name == "input_start")
|
||||
{
|
||||
return InputType::START;
|
||||
}
|
||||
|
||||
if (name == "input_service")
|
||||
{
|
||||
return InputType::SERVICE;
|
||||
}
|
||||
|
||||
return InputType::NONE;
|
||||
auto it = inputMap.find(name);
|
||||
return it != inputMap.end() ? it->second : InputType::NONE;
|
||||
}
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case InputType::LEFT:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000;
|
||||
case InputType::RIGHT:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000;
|
||||
case InputType::UP:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000;
|
||||
case InputType::DOWN:
|
||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
|
||||
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -11,9 +11,9 @@
|
||||
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
|
||||
checkInput requiere de un indice para comprobar las pulsaciónes de un controlador en concreto [0 .. n]
|
||||
device contiene el tipo de dispositivo a comprobar:
|
||||
INPUT_USE_KEYBOARD solo mirará el teclado
|
||||
INPUT_USE_GAMECONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
||||
INPUT_USE_ANY mirará tanto el teclado como el PRIMER controlador
|
||||
InputDeviceToUse::KEYBOARD solo mirará el teclado
|
||||
InputDeviceToUse::CONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
||||
InputDeviceToUse::ANY mirará tanto el teclado como el PRIMER controlador
|
||||
*/
|
||||
|
||||
enum class InputType : int
|
||||
@@ -40,6 +40,7 @@ enum class InputType : int
|
||||
VIDEO_SHADERS,
|
||||
RESET,
|
||||
MUTE,
|
||||
CHANGE_LANG,
|
||||
SHOWINFO,
|
||||
CONFIG,
|
||||
SWAP_CONTROLLERS,
|
||||
@@ -52,9 +53,12 @@ enum class InputType : int
|
||||
constexpr bool INPUT_ALLOW_REPEAT = true;
|
||||
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false;
|
||||
|
||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||
constexpr int INPUT_USE_ANY = 2;
|
||||
enum class InputDeviceToUse : int
|
||||
{
|
||||
KEYBOARD = 0,
|
||||
CONTROLLER = 1,
|
||||
ANY = 2,
|
||||
};
|
||||
|
||||
class Input
|
||||
{
|
||||
@@ -66,12 +70,20 @@ private:
|
||||
{
|
||||
Uint8 scancode; // Scancode asociado
|
||||
bool active; // Indica si está activo
|
||||
|
||||
// Constructor
|
||||
explicit KeyBindings(Uint8 sc = 0, bool act = false)
|
||||
: scancode(sc), active(act) {}
|
||||
};
|
||||
|
||||
struct ControllerBindings
|
||||
{
|
||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||
bool active; // Indica si está activo
|
||||
|
||||
// Constructor
|
||||
explicit ControllerBindings(SDL_GameControllerButton btn = SDL_CONTROLLER_BUTTON_INVALID, bool act = false)
|
||||
: button(btn), active(act) {}
|
||||
};
|
||||
|
||||
// Variables
|
||||
@@ -80,12 +92,10 @@ private:
|
||||
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
||||
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||
std::vector<InputType> game_inputs_; // Inputs usados para jugar, normalmente direcciones y botones
|
||||
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||
int num_joysticks_; // Número de joysticks conectados
|
||||
int num_gamepads_; // Número de mandos conectados
|
||||
int num_joysticks_ = 0; // Número de joysticks conectados
|
||||
int num_gamepads_ = 0; // Número de mandos conectados
|
||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||
bool enabled_; // Indica si está habilitado
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||
@@ -114,13 +124,10 @@ public:
|
||||
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si un input con modificador esta activo
|
||||
bool checkModInput(InputType input_mod, InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
bool checkInput(InputType input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
||||
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||
|
||||
// Comprueba si hay algún botón pulsado
|
||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
||||
@@ -141,7 +148,7 @@ public:
|
||||
int getJoyIndex(int id) const;
|
||||
|
||||
// Muestra por consola los controles asignados
|
||||
void printBindings(int device = INPUT_USE_KEYBOARD, int controller_index = 0) const;
|
||||
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const;
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const;
|
||||
|
||||
@@ -26,19 +26,17 @@ Instructions::Instructions()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
text_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)),
|
||||
text_(Resource::get()->getText("smb2")),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::STATIC)),
|
||||
fade_(std::make_unique<Fade>())
|
||||
{
|
||||
// Crea un backbuffer para el renderizador
|
||||
// Configura las texturas
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea una textura para el texto fijo
|
||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
view_ = {0, 0, param.game.width, param.game.height};
|
||||
view_ = param.game.game_area.rect;
|
||||
|
||||
// Inicializa objetos
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
@@ -211,11 +209,16 @@ void Instructions::update()
|
||||
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||
}
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
|
||||
@@ -313,9 +316,6 @@ void Instructions::checkInput()
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
Screen::get()->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
|
||||
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
|
||||
std::unique_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::shared_ptr<Text> text_; // Objeto para escribir texto
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
: texture_(Resource::get()->getTexture("intro.png")),
|
||||
text_(std::make_shared<Text>(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt")))
|
||||
text_(Resource::get()->getText("nokia"))
|
||||
{
|
||||
|
||||
// Inicializa variables
|
||||
@@ -139,9 +139,7 @@ Intro::Intro()
|
||||
texts_[8]->setSpeed(16);
|
||||
|
||||
for (auto &text : texts_)
|
||||
{
|
||||
text->center(param.game.game_area.center_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
@@ -171,9 +169,7 @@ void Intro::checkEvents()
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -195,9 +191,6 @@ void Intro::checkInput()
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
Screen::get()->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
@@ -389,6 +382,9 @@ void Intro::update()
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
158
source/item.cpp
@@ -1,10 +1,10 @@
|
||||
#include "item.h"
|
||||
#include <stdlib.h> // para rand
|
||||
#include "animated_sprite.h" // para SpriteAnimated
|
||||
#include "param.h" // para param
|
||||
class Texture;
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para clamp
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
class Texture; // lines 6-6
|
||||
|
||||
// Constructor
|
||||
Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
type_(type),
|
||||
@@ -38,34 +38,26 @@ Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr
|
||||
}
|
||||
}
|
||||
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
// Actualiza el sprite
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void Item::alignTo(int x)
|
||||
{
|
||||
pos_x_ = static_cast<float>(x - (width_ / 2));
|
||||
const float min_x = param.game.play_area.rect.x + 1;
|
||||
const float max_x = play_area_.w - width_ - 1;
|
||||
|
||||
if (pos_x_ < param.game.play_area.rect.x)
|
||||
{
|
||||
pos_x_ = param.game.play_area.rect.x + 1;
|
||||
}
|
||||
else if (pos_x_ + width_ > play_area_.w)
|
||||
{
|
||||
pos_x_ = static_cast<float>(play_area_.w - width_ - 1);
|
||||
}
|
||||
pos_x_ = x - (width_ / 2);
|
||||
|
||||
// Posición X,Y del sprite
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
// Ajusta para que no quede fuera de la zona de juego
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
// Actualiza el sprite
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Pinta el objeto en la pantalla
|
||||
void Item::render()
|
||||
{
|
||||
if (enabled_)
|
||||
@@ -81,7 +73,6 @@ void Item::render()
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
void Item::move()
|
||||
{
|
||||
floor_collision_ = false;
|
||||
@@ -94,129 +85,90 @@ void Item::move()
|
||||
vel_x_ += accel_x_;
|
||||
vel_y_ += accel_y_;
|
||||
|
||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||
if ((pos_x_ < param.game.play_area.rect.x) || (pos_x_ + width_ > play_area_.w))
|
||||
{
|
||||
// Corregir posición
|
||||
pos_x_ -= vel_x_;
|
||||
// Comprueba los laterales de la zona de juego
|
||||
const float min_x = param.game.play_area.rect.x;
|
||||
const float max_x = play_area_.w - width_;
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
|
||||
// Invertir sentido
|
||||
// Si toca el borde lateral, invierte la velocidad horizontal
|
||||
if (pos_x_ == min_x || pos_x_ == max_x)
|
||||
{
|
||||
vel_x_ = -vel_x_;
|
||||
}
|
||||
|
||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||
// Si colisiona por arriba, rebota (excepto la máquina de café)
|
||||
if ((pos_y_ < param.game.play_area.rect.y) && !(type_ == ItemType::COFFEE_MACHINE))
|
||||
{
|
||||
// Corrige
|
||||
pos_y_ = param.game.play_area.rect.y;
|
||||
|
||||
// Invierte el sentido
|
||||
// Invierte la velocidad
|
||||
vel_y_ = -vel_y_;
|
||||
}
|
||||
|
||||
// Si el objeto se sale por la parte inferior
|
||||
if (pos_y_ + height_ > play_area_.h)
|
||||
// Si colisiona con la parte inferior
|
||||
if (pos_y_ > play_area_.h - height_)
|
||||
{
|
||||
// Detiene el objeto
|
||||
vel_y_ = 0;
|
||||
vel_x_ = 0;
|
||||
accel_x_ = 0;
|
||||
accel_y_ = 0;
|
||||
// Corrige la posición
|
||||
pos_y_ = play_area_.h - height_;
|
||||
|
||||
if (type_ == ItemType::COFFEE_MACHINE)
|
||||
{
|
||||
// Si es una máquina de café, detiene el objeto
|
||||
vel_y_ = vel_x_ = accel_x_ = accel_y_ = 0;
|
||||
floor_collision_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si no es una máquina de café
|
||||
if (vel_y_ < 1.0f)
|
||||
{
|
||||
// Si la velocidad vertical es baja, detiene el objeto
|
||||
vel_y_ = vel_x_ = accel_x_ = accel_y_ = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si la velocidad vertical es alta, el objeto rebota y pierde velocidad
|
||||
vel_y_ *= -0.5f;
|
||||
vel_x_ *= 0.75f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
sprite_->setPosX(int(pos_x_));
|
||||
sprite_->setPosY(int(pos_y_));
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Pone a cero todos los valores del objeto
|
||||
void Item::disable()
|
||||
{
|
||||
enabled_ = false;
|
||||
}
|
||||
void Item::disable() { enabled_ = false; }
|
||||
|
||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||
void Item::update()
|
||||
{
|
||||
move();
|
||||
sprite_->update();
|
||||
updateTimeToLive();
|
||||
checkTimeToLive();
|
||||
}
|
||||
|
||||
// Actualiza el contador
|
||||
void Item::updateTimeToLive()
|
||||
{
|
||||
if (time_to_live_ > 0)
|
||||
{
|
||||
time_to_live_--;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si el objeto sigue vivo
|
||||
void Item::checkTimeToLive()
|
||||
{
|
||||
if (time_to_live_ == 0)
|
||||
else
|
||||
{
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float Item::getPosX()
|
||||
{
|
||||
return pos_x_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float Item::getPosY()
|
||||
{
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Item::getWidth()
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Item::getHeight()
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
ItemType Item::getType()
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Item::isEnabled()
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &Item::getCollider()
|
||||
{
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto
|
||||
void Item::shiftColliders()
|
||||
{
|
||||
collider_.x = int(pos_x_ + (width_ / 2));
|
||||
collider_.y = int(pos_y_ + (height_ / 2));
|
||||
collider_.x = static_cast<int>(pos_x_ + (width_ / 2));
|
||||
collider_.y = static_cast<int>(pos_y_ + (height_ / 2));
|
||||
}
|
||||
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
bool Item::isOnFloor()
|
||||
void Item::shiftSprite()
|
||||
{
|
||||
return floor_collision_;
|
||||
}
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
}
|
||||
|
||||
174
source/item.h
@@ -9,93 +9,147 @@
|
||||
#include "utils.h" // para Circle
|
||||
class Texture;
|
||||
|
||||
// Tipos de objetos
|
||||
/**
|
||||
* @brief Tipos de objetos disponibles en el juego.
|
||||
*
|
||||
* Esta enumeración define los diferentes tipos de objetos que pueden existir en el juego,
|
||||
* cada uno con un identificador único.
|
||||
*/
|
||||
enum class ItemType : int
|
||||
{
|
||||
DISK = 1,
|
||||
GAVINA = 2,
|
||||
PACMAR = 3,
|
||||
CLOCK = 4,
|
||||
COFFEE = 5,
|
||||
COFFEE_MACHINE = 6,
|
||||
NONE = 7,
|
||||
DISK = 1, /**< Disco */
|
||||
GAVINA = 2, /**< Gavina */
|
||||
PACMAR = 3, /**< Pacman */
|
||||
CLOCK = 4, /**< Reloj */
|
||||
COFFEE = 5, /**< Café */
|
||||
COFFEE_MACHINE = 6,/**< Máquina de café */
|
||||
NONE = 7, /**< Ninguno */
|
||||
};
|
||||
|
||||
// Clase Item
|
||||
/**
|
||||
* @brief Clase Item.
|
||||
*
|
||||
* Esta clase representa un objeto en el juego, con sus propiedades y métodos para gestionar su comportamiento.
|
||||
*/
|
||||
class Item
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los graficos del objeto
|
||||
std::unique_ptr<AnimatedSprite> sprite_; /**< Sprite con los gráficos del objeto */
|
||||
|
||||
// Variables
|
||||
float pos_x_; // Posición X del objeto
|
||||
float pos_y_; // Posición Y del objeto
|
||||
int width_; // Ancho del objeto
|
||||
int height_; // Alto del objeto
|
||||
float vel_x_; // Velocidad en el eje X
|
||||
float vel_y_; // Velocidad en el eje Y
|
||||
float accel_x_ = 0.0f; // Aceleración en el eje X
|
||||
float accel_y_; // Aceleración en el eje Y
|
||||
bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
||||
ItemType type_; // Especifica el tipo de objeto que es
|
||||
bool enabled_ = true; // Especifica si el objeto está habilitado
|
||||
Circle collider_; // Circulo de colisión del objeto
|
||||
SDL_Rect play_area_; // Rectangulo con la zona de juego
|
||||
Uint16 time_to_live_ = 600; // Temporizador con el tiempo que el objeto está presente
|
||||
float pos_x_; /**< Posición X del objeto */
|
||||
float pos_y_; /**< Posición Y del objeto */
|
||||
int width_; /**< Ancho del objeto */
|
||||
int height_; /**< Alto del objeto */
|
||||
float vel_x_; /**< Velocidad en el eje X */
|
||||
float vel_y_; /**< Velocidad en el eje Y */
|
||||
float accel_x_ = 0.0f; /**< Aceleración en el eje X */
|
||||
float accel_y_; /**< Aceleración en el eje Y */
|
||||
bool floor_collision_ = false; /**< Indica si el objeto colisiona con el suelo */
|
||||
ItemType type_; /**< Especifica el tipo de objeto que es */
|
||||
bool enabled_ = true; /**< Especifica si el objeto está habilitado */
|
||||
Circle collider_; /**< Círculo de colisión del objeto */
|
||||
SDL_Rect play_area_; /**< Rectángulo con la zona de juego */
|
||||
Uint16 time_to_live_ = 600; /**< Temporizador con el tiempo que el objeto está presente */
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto
|
||||
/**
|
||||
* @brief Alinea el círculo de colisión con la posición del objeto.
|
||||
*
|
||||
* Esta función ajusta la posición del círculo de colisión para que coincida con la posición del objeto.
|
||||
* Actualiza las coordenadas X e Y del colisionador basándose en las coordenadas del objeto.
|
||||
*/
|
||||
void shiftColliders();
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
/**
|
||||
* @brief Coloca el sprite en la posición del objeto.
|
||||
*
|
||||
* Esta función ajusta la posición del sprite para que coincida con la posición del objeto.
|
||||
* Actualiza las coordenadas X e Y del sprite basándose en las coordenadas del objeto.
|
||||
*/
|
||||
void shiftSprite();
|
||||
|
||||
/**
|
||||
* @brief Actualiza la posición y estados del objeto.
|
||||
*
|
||||
* Esta función actualiza la posición del objeto basándose en su velocidad y aceleración.
|
||||
* Controla las colisiones con los límites del área de juego, ajustando la posición y la velocidad en consecuencia.
|
||||
* También actualiza la posición del sprite y el colisionador del objeto.
|
||||
*/
|
||||
void move();
|
||||
|
||||
// Actualiza el contador
|
||||
/**
|
||||
* @brief Actualiza el contador de tiempo de vida del objeto.
|
||||
*
|
||||
* Esta función decrementa el contador de tiempo de vida del objeto.
|
||||
* Si el tiempo de vida es mayor a 0, se decrementa en 1.
|
||||
* Si el tiempo de vida es 0 o menos, se desactiva el objeto llamando a la función `disable()`.
|
||||
*/
|
||||
void updateTimeToLive();
|
||||
|
||||
// Comprueba si el objeto sigue vivo
|
||||
void checkTimeToLive();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
/**
|
||||
* @brief Constructor de la clase Item.
|
||||
*
|
||||
* Este constructor inicializa un objeto Item con el tipo especificado, posición inicial, área de juego, textura y animación.
|
||||
*
|
||||
* @param type El tipo de objeto (ItemType).
|
||||
* @param x La posición X inicial del objeto.
|
||||
* @param y La posición Y inicial del objeto.
|
||||
* @param play_area El área de juego donde el objeto se moverá.
|
||||
* @param texture La textura del objeto.
|
||||
* @param animation La animación asociada al objeto.
|
||||
*/
|
||||
Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation);
|
||||
|
||||
// Destructor
|
||||
/**
|
||||
* @brief Destructor de la clase Item.
|
||||
*
|
||||
* Este destructor libera los recursos asociados con el objeto Item.
|
||||
*/
|
||||
~Item() = default;
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
/**
|
||||
* @brief Centra el objeto en la posición X.
|
||||
*
|
||||
* Esta función ajusta la posición X del objeto para que esté centrado en la posición X especificada.
|
||||
* Además, asegura que el objeto no se salga de los límites del área de juego.
|
||||
*
|
||||
* @param x La posición X en la que se desea centrar el objeto.
|
||||
*/
|
||||
void alignTo(int x);
|
||||
|
||||
// Pinta el objeto en la pantalla
|
||||
/**
|
||||
* @brief Pinta el objeto en la pantalla.
|
||||
*
|
||||
* Esta función renderiza el objeto en la pantalla si está habilitado.
|
||||
* Si el tiempo de vida (`time_to_live_`) es mayor que 200, renderiza el sprite.
|
||||
* Si el tiempo de vida es menor o igual a 200, renderiza el sprite de forma intermitente, basándose en un cálculo de módulo.
|
||||
*/
|
||||
void render();
|
||||
|
||||
// Pone a cero todos los valores del objeto
|
||||
/**
|
||||
* @brief Pone a cero todos los valores del objeto.
|
||||
*
|
||||
* Esta función desactiva el objeto estableciendo su estado `enabled_` a `false`.
|
||||
*/
|
||||
void disable();
|
||||
|
||||
// Actualiza al objeto a su posicion, animación y controla los contadores
|
||||
/**
|
||||
* @brief Actualiza el objeto a su posición, animación y controla los contadores.
|
||||
*
|
||||
* Esta función mueve el objeto, actualiza su animación y controla el contador de tiempo de vida.
|
||||
* Llama a las funciones `move()`, `sprite_->update()` y `updateTimeToLive()`.
|
||||
*/
|
||||
void update();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float getPosX();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
float getPosY();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int getWidth();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int getHeight();
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
ItemType getType();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isEnabled();
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &getCollider();
|
||||
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
bool isOnFloor();
|
||||
};
|
||||
// Getters
|
||||
float getPosX() const { return pos_x_; }
|
||||
float getPosY() const { return pos_y_; }
|
||||
int getWidth() const { return width_; }
|
||||
int getHeight() const { return height_; }
|
||||
ItemType getType() const { return type_; }
|
||||
bool isEnabled() const { return enabled_; }
|
||||
bool isOnFloor() const { return floor_collision_; }
|
||||
Circle &getCollider() { return collider_; }
|
||||
};
|
||||
|
||||
@@ -40,4 +40,12 @@ namespace lang
|
||||
{
|
||||
return texts.at(index);
|
||||
}
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang)
|
||||
{
|
||||
auto index = static_cast<int>(current_lang);
|
||||
index = (index + 1) % 3;
|
||||
return static_cast<Code>(index);
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,7 @@ namespace lang
|
||||
|
||||
// Obtiene la cadena de texto del indice
|
||||
std::string getText(int index);
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang);
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, Zone
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
@@ -53,6 +54,14 @@ Logo::Logo()
|
||||
color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Logo::~Logo()
|
||||
{
|
||||
jail_texture_->setColor(255, 255, 255);
|
||||
since_texture_->setColor(255, 255, 255);
|
||||
JA_PauseChannel(-1);
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
void Logo::reloadTextures()
|
||||
{
|
||||
@@ -98,9 +107,6 @@ void Logo::checkInput()
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
Screen::get()->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
@@ -108,6 +114,11 @@ void Logo::checkInput()
|
||||
// Gestiona el logo de JAILGAME
|
||||
void Logo::updateJAILGAMES()
|
||||
{
|
||||
if (counter_ == 30)
|
||||
{
|
||||
JA_PlaySound(Resource::get()->getSound("logo.wav"));
|
||||
}
|
||||
|
||||
if (counter_ > 30)
|
||||
{
|
||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||
@@ -190,6 +201,9 @@ void Logo::update()
|
||||
{
|
||||
section::name = section::Name::INTRO;
|
||||
}
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // para Uint32
|
||||
#include <memory> // para unique_ptr, shared_ptr
|
||||
#include <vector> // para vector
|
||||
#include "sprite.h" // para Sprite
|
||||
#include "utils.h" // para Color
|
||||
class Texture;
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <vector> // Para vector
|
||||
class Sprite;
|
||||
class Texture; // lines 9-9
|
||||
struct Color;
|
||||
|
||||
/*
|
||||
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
Logo();
|
||||
|
||||
// Destructor
|
||||
~Logo() = default;
|
||||
~Logo();
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
|
||||
@@ -12,16 +12,18 @@ void ManageHiScoreTable::clear()
|
||||
table_.clear();
|
||||
|
||||
// Añade 10 entradas predefinidas
|
||||
table_.push_back(HiScoreEntry("Bry", 1000000));
|
||||
table_.push_back(HiScoreEntry("Usufondo", 500000));
|
||||
table_.push_back(HiScoreEntry("G.Lucas", 100000));
|
||||
table_.push_back(HiScoreEntry("P.Delgat", 50000));
|
||||
table_.push_back(HiScoreEntry("P.Arrabalera", 10000));
|
||||
table_.push_back(HiScoreEntry("Pelechano", 5000));
|
||||
table_.push_back(HiScoreEntry("Sahuquillo", 1000));
|
||||
table_.push_back(HiScoreEntry("Bacteriol", 500));
|
||||
table_.push_back(HiScoreEntry("Pepe", 200));
|
||||
table_.push_back(HiScoreEntry("Rosita", 100));
|
||||
table_.push_back(HiScoreEntry("BRY", 1000000));
|
||||
table_.push_back(HiScoreEntry("USUFON", 500000));
|
||||
table_.push_back(HiScoreEntry("GLUCAS", 100000));
|
||||
table_.push_back(HiScoreEntry("PDLGAT", 50000));
|
||||
table_.push_back(HiScoreEntry("PARRAB", 10000));
|
||||
table_.push_back(HiScoreEntry("PELECH", 5000));
|
||||
table_.push_back(HiScoreEntry("SAHUQU", 1000));
|
||||
table_.push_back(HiScoreEntry("BACTER", 500));
|
||||
table_.push_back(HiScoreEntry("PEPE", 200));
|
||||
table_.push_back(HiScoreEntry("ROSITA", 100));
|
||||
|
||||
sort();
|
||||
}
|
||||
|
||||
// Añade un elemento a la tabla
|
||||
|
||||
@@ -96,6 +96,12 @@ void MovingSprite::setAngle(double value)
|
||||
rotate_.angle = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotatingCenter(SDL_Point *point)
|
||||
{
|
||||
rotate_.center = point;
|
||||
}
|
||||
|
||||
// Incrementa el valor del ángulo
|
||||
void MovingSprite::updateAngle()
|
||||
{
|
||||
@@ -122,17 +128,10 @@ void MovingSprite::rotate()
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::enableRotate()
|
||||
// Activa o desactiva el efecto de rotación
|
||||
void MovingSprite::setRotate(bool enable)
|
||||
{
|
||||
rotate_.enabled = true;
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate()
|
||||
{
|
||||
rotate_.enabled = false;
|
||||
rotate_.enabled = enable;
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
@@ -172,41 +171,6 @@ SDL_RendererFlip MovingSprite::getFlip()
|
||||
return flip_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosX() const
|
||||
{
|
||||
return x_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosY() const
|
||||
{
|
||||
return y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelX() const
|
||||
{
|
||||
return vx_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelY() const
|
||||
{
|
||||
return vy_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelX() const
|
||||
{
|
||||
return ax_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelY() const
|
||||
{
|
||||
return ay_;
|
||||
}
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
SDL_Point *center; // Centro de rotación
|
||||
|
||||
Rotate() : enabled(false), counter(0), speed(0), angle(0.0), amount(0.0f), center(nullptr) {}
|
||||
Rotate() : enabled(false), counter(0), speed(1), angle(0.0), amount(0.0f), center(nullptr) {}
|
||||
};
|
||||
|
||||
protected:
|
||||
@@ -65,12 +65,12 @@ public:
|
||||
void render() override;
|
||||
|
||||
// Obtiene la variable
|
||||
float getPosX() const;
|
||||
float getPosY() const;
|
||||
float getVelX() const;
|
||||
float getVelY() const;
|
||||
float getAccelX() const;
|
||||
float getAccelY() const;
|
||||
float getPosX() const { return x_; }
|
||||
float getPosY() const { return y_; }
|
||||
float getVelX() const { return vx_; }
|
||||
float getVelY() const { return vy_; }
|
||||
float getAccelX() const { return ax_; }
|
||||
float getAccelY() const { return ay_; }
|
||||
|
||||
// Establece la variable
|
||||
void setVelX(float value);
|
||||
@@ -87,10 +87,10 @@ public:
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
void setRotatingCenter(SDL_Point *point);
|
||||
|
||||
// Activa o desactiva el efecto derotación
|
||||
void enableRotate();
|
||||
void disableRotate();
|
||||
// Activa o desactiva el efecto de rotación
|
||||
void setRotate(bool enable);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
@@ -2,20 +2,23 @@
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <string> // Para string
|
||||
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "param.h" // Para Param, param, ParamNotification, Par...
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "param.h" // Para Param, param, ParamNotification, Par...
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include "resource.h"
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
||||
{
|
||||
Notifier::notifier_ = new Notifier(icon_file, text, sound_file);
|
||||
Notifier::notifier_ = new Notifier(icon_file, text);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
@@ -31,27 +34,22 @@ Notifier *Notifier::get()
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file)
|
||||
Notifier::Notifier(std::string icon_file, std::shared_ptr<Text> text)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr),
|
||||
text_(text),
|
||||
bg_color_(param.notification.color),
|
||||
wait_time_(150),
|
||||
stack_(false),
|
||||
has_icons_(!icon_file.empty()),
|
||||
sound_(JA_LoadSound(sound_file.c_str())) {}
|
||||
|
||||
// Destructor
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
JA_DeleteSound(sound_);
|
||||
}
|
||||
has_icons_(!icon_file.empty()) {}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notifier::render()
|
||||
{
|
||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||
{
|
||||
notifications_[i].sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
@@ -76,8 +74,9 @@ void Notifier::update()
|
||||
if (param.notification.sound)
|
||||
{
|
||||
if (notifications_[i].status == NotificationStatus::RISING)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
JA_PlaySound(sound_);
|
||||
{
|
||||
// Reproduce el sonido de la notificación
|
||||
JA_PlaySound(Resource::get()->getSound("notify.wav"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,39 +153,41 @@ void Notifier::clearFinishedNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::showText(std::string text1, std::string text2, int icon, const std::string &code)
|
||||
void Notifier::showText(std::vector<std::string> texts, int icon, const std::string &code)
|
||||
{
|
||||
// Cuenta el número de textos a mostrar
|
||||
const int num_texts = !text1.empty() + !text2.empty();
|
||||
|
||||
// Si no hay texto, acaba
|
||||
if (num_texts == 0)
|
||||
if (texts.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Si solo hay un texto, lo coloca en la primera variable
|
||||
if (num_texts == 1)
|
||||
{
|
||||
text1 += text2;
|
||||
text2.clear();
|
||||
}
|
||||
|
||||
// Si las notificaciones no se apilan, elimina las anteriores
|
||||
if (!stack_)
|
||||
{
|
||||
clearNotifications();
|
||||
}
|
||||
|
||||
// Elimina las cadenas vacías
|
||||
texts.erase(std::remove_if(texts.begin(), texts.end(), [](const std::string &s)
|
||||
{ return s.empty(); }),
|
||||
texts.end());
|
||||
|
||||
// Encuentra la cadena más larga
|
||||
std::string longest;
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
if (text.length() > longest.length())
|
||||
longest = text;
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
constexpr auto icon_size = 16;
|
||||
constexpr auto padding_out = 1;
|
||||
constexpr int icon_size = 16;
|
||||
constexpr int padding_out = 1;
|
||||
const auto padding_in_h = text_->getCharacterSize();
|
||||
const auto padding_in_v = text_->getCharacterSize() / 2;
|
||||
const auto icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||
const auto width = text_->lenght(txt) + (padding_in_h * 2) + icon_space;
|
||||
const auto height = (text_->getCharacterSize() * num_texts) + (padding_in_v * 2);
|
||||
const int icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
||||
const int width = text_->lenght(longest) + (padding_in_h * 2) + icon_space;
|
||||
const int height = (text_->getCharacterSize() * texts.size()) + (padding_in_v * 2);
|
||||
const auto shape = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
@@ -212,11 +213,11 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
||||
auto offset = 0;
|
||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||
{
|
||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y + travel_dist : desp_v;
|
||||
offset = !notifications_.empty() ? notifications_.back().y + travel_dist : desp_v;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y - travel_dist : desp_v;
|
||||
offset = !notifications_.empty() ? notifications_.back().y - travel_dist : desp_v;
|
||||
}
|
||||
|
||||
// Crea la notificacion
|
||||
@@ -226,8 +227,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
||||
n.code = code;
|
||||
n.y = offset;
|
||||
n.travel_dist = travel_dist;
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
n.texts = texts;
|
||||
n.shape = shape;
|
||||
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist);
|
||||
n.rect = {desp_h, y_pos, width, height};
|
||||
@@ -264,7 +264,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (has_icons_ && icon >= 0 && num_texts == 2)
|
||||
if (has_icons_ && icon >= 0 && texts.size() >= 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
||||
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
||||
@@ -273,15 +273,12 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
Color color{255, 255, 255};
|
||||
if (num_texts == 2)
|
||||
{ // Dos lineas de texto
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v + text_->getCharacterSize() + 1, text2, color);
|
||||
}
|
||||
else
|
||||
{ // Una linea de texto
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
||||
const Color color{255, 255, 255};
|
||||
int iterator = 0;
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
text_->writeColored(padding_in_h + icon_space, padding_in_v + iterator * (text_->getCharacterSize() + 1), text, color);
|
||||
++iterator;
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
@@ -294,26 +291,18 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
||||
n.texture->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.push_back(n);
|
||||
notifications_.emplace_back(n);
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool Notifier::isActive()
|
||||
{
|
||||
if ((int)notifications_.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool Notifier::isActive() { return !notifications_.empty(); }
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void Notifier::clearNotifications()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
for (auto ¬ification : notifications_)
|
||||
{
|
||||
notifications_[i].status = NotificationStatus::FINISHED;
|
||||
notification.status = NotificationStatus::FINISHED;
|
||||
}
|
||||
|
||||
clearFinishedNotifications();
|
||||
@@ -323,9 +312,9 @@ void Notifier::clearNotifications()
|
||||
std::vector<std::string> Notifier::getCodes()
|
||||
{
|
||||
std::vector<std::string> codes;
|
||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||
for (const auto ¬ification : notifications_)
|
||||
{
|
||||
codes.push_back(notifications_[i].code);
|
||||
codes.emplace_back(notification.code);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
@@ -35,8 +35,7 @@ private:
|
||||
{
|
||||
std::shared_ptr<Texture> texture;
|
||||
std::shared_ptr<Sprite> sprite;
|
||||
std::string text1;
|
||||
std::string text2;
|
||||
std::vector<std::string> texts;
|
||||
int counter;
|
||||
NotificationStatus status;
|
||||
NotificationShape shape;
|
||||
@@ -47,7 +46,7 @@ private:
|
||||
|
||||
// Constructor
|
||||
explicit Notification()
|
||||
: texture(nullptr), sprite(nullptr), text1(""), text2(""), counter(0), status(NotificationStatus::RISING),
|
||||
: texture(nullptr), sprite(nullptr), texts(), counter(0), status(NotificationStatus::RISING),
|
||||
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {}
|
||||
};
|
||||
|
||||
@@ -63,7 +62,6 @@ private:
|
||||
std::vector<Notification> notifications_; // La lista de notificaciones activas
|
||||
bool stack_; // Indica si las notificaciones se apilan
|
||||
bool has_icons_; // Indica si el notificador tiene textura para iconos
|
||||
JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
@@ -74,14 +72,14 @@ private:
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||
|
||||
// Constructor
|
||||
Notifier(std::string icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
Notifier(std::string icon_file, std::shared_ptr<Text> text);
|
||||
|
||||
// Destructor
|
||||
~Notifier();
|
||||
~Notifier() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text, const std::string &sound_file);
|
||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
||||
static void destroy();
|
||||
@@ -95,15 +93,8 @@ public:
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
/**
|
||||
* @brief Muestra una notificación de texto por pantalla.
|
||||
*
|
||||
* @param text1 Primer texto opcional para mostrar (valor predeterminado: cadena vacía).
|
||||
* @param text2 Segundo texto opcional para mostrar (valor predeterminado: cadena vacía).
|
||||
* @param icon Icono opcional para mostrar (valor predeterminado: -1).
|
||||
* @param code Permite asignar un código a la notificación (valor predeterminado: cadena vacía).
|
||||
*/
|
||||
void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1, const std::string &code = std::string());
|
||||
// Muestra una notificación de texto por pantalla
|
||||
void showText(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool isActive();
|
||||
|
||||
@@ -94,7 +94,7 @@ void OnScreenHelp::fillTexture()
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
|
||||
// Crea la textura con los gráficos
|
||||
auto controllersTexture = Resource::get()->getTexture("controllers.png");
|
||||
@@ -169,7 +169,7 @@ void OnScreenHelp::toggleState()
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
{
|
||||
auto text = std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
auto text = Resource::get()->getText("8bithud");
|
||||
auto size = 0;
|
||||
|
||||
for (int i = 107; i <= 113; ++i)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include "options.h"
|
||||
#include <SDL2/SDL_gamecontroller.h> // para SDL_GameControllerButton, SDL_C...
|
||||
#include <algorithm> // para max, min
|
||||
#include <fstream> // para basic_ostream, operator<<, basi...
|
||||
#include <iostream> // para cout
|
||||
#include <vector> // para vector
|
||||
#include "input.h" // para inputs_e, INPUT_USE_ANY, INPUT_...
|
||||
#include "lang.h" // para lang_e
|
||||
#include "screen.h" // para ScreenVideoMode, ScreenFilter
|
||||
#include "utils.h" // para OptionsController, Options, op_...
|
||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
||||
#include <algorithm> // Para clamp
|
||||
#include <fstream> // Para basic_ostream, operator<<, basi...
|
||||
#include <iostream> // Para cout
|
||||
#include <utility> // Para swap
|
||||
#include <vector> // Para vector
|
||||
#include "input.h" // Para InputDeviceToUse
|
||||
#include "lang.h" // Para Code
|
||||
#include "screen.h" // Para ScreenVideoMode, ScreenFilter
|
||||
#include "utils.h" // Para boolToString, stringToBool, get...
|
||||
|
||||
// Variables
|
||||
Options options;
|
||||
@@ -32,10 +33,12 @@ void initOptions()
|
||||
options.video.shaders = true;
|
||||
|
||||
// Opciones de audio
|
||||
options.audio.enabled = true;
|
||||
options.audio.volume = 100;
|
||||
options.audio.music.enabled = true;
|
||||
options.audio.music.volume = 128;
|
||||
options.audio.music.volume = 100;
|
||||
options.audio.sound.enabled = true;
|
||||
options.audio.sound.volume = 64;
|
||||
options.audio.sound.volume = 50;
|
||||
|
||||
// Opciones de juego
|
||||
options.game.difficulty = GameDifficulty::NORMAL;
|
||||
@@ -43,37 +46,11 @@ void initOptions()
|
||||
options.game.autofire = true;
|
||||
|
||||
// Opciones de control
|
||||
options.controller.clear();
|
||||
OptionsController c;
|
||||
|
||||
constexpr int num_players = 2;
|
||||
for (int index = 0; index < num_players; ++index)
|
||||
{
|
||||
c.index = index;
|
||||
c.player_id = index + 1;
|
||||
c.device_type = INPUT_USE_GAMECONTROLLER;
|
||||
c.name = "NO NAME";
|
||||
c.plugged = false;
|
||||
|
||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
||||
c.inputs.clear();
|
||||
c.inputs.push_back(InputType::FIRE_LEFT);
|
||||
c.inputs.push_back(InputType::FIRE_CENTER);
|
||||
c.inputs.push_back(InputType::FIRE_RIGHT);
|
||||
c.inputs.push_back(InputType::START);
|
||||
c.inputs.push_back(InputType::SERVICE);
|
||||
|
||||
// Botones asociados a los inputs anteriores
|
||||
c.buttons.clear();
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_B);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
|
||||
|
||||
options.controller.push_back(c);
|
||||
}
|
||||
options.controller[0].device_type = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
options.controllers.clear();
|
||||
options.controllers.resize(2);
|
||||
options.controllers.at(0).player_id = 1;
|
||||
options.controllers.at(1).player_id = 2;
|
||||
setKeyboardToPlayer(1);
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
@@ -127,12 +104,11 @@ bool loadOptionsFile(std::string file_path)
|
||||
options.video.mode = ScreenVideoMode::WINDOW;
|
||||
}
|
||||
|
||||
if (options.video.window.size < 1 || options.video.window.size > 4)
|
||||
{
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
options.video.window.size = std::clamp(options.video.window.size, 1, 4);
|
||||
|
||||
if (options.game.language != lang::Code::en_UK && options.game.language != lang::Code::ba_BA && options.game.language != lang::Code::es_ES)
|
||||
if (options.game.language != lang::Code::en_UK &&
|
||||
options.game.language != lang::Code::ba_BA &&
|
||||
options.game.language != lang::Code::es_ES)
|
||||
{
|
||||
options.game.language = lang::Code::en_UK;
|
||||
}
|
||||
@@ -154,71 +130,58 @@ bool saveOptionsFile(std::string file_path)
|
||||
std::cout << "Writing file: " << getFileName(file_path) << std::endl;
|
||||
|
||||
// Opciones de video
|
||||
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
||||
const auto value_video_mode_fullscreen = std::to_string(static_cast<int>(ScreenVideoMode::FULLSCREEN));
|
||||
const auto value_filter_nearest = std::to_string(static_cast<int>(ScreenFilter::NEAREST));
|
||||
const auto value_filter_lineal = std::to_string(static_cast<int>(ScreenFilter::LINEAL));
|
||||
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.mode [" << value_video_mode_winow << ": window, " << value_video_mode_fullscreen << ": fullscreen]\n";
|
||||
file << "## video.filter [" << value_filter_nearest << ": nearest, " << value_filter_lineal << ": lineal]\n";
|
||||
file << "## video.mode [" << static_cast<int>(ScreenVideoMode::WINDOW) << ": window, " << static_cast<int>(ScreenVideoMode::FULLSCREEN) << ": fullscreen]\n";
|
||||
file << "## video.filter [" << static_cast<int>(ScreenFilter::NEAREST) << ": nearest, " << static_cast<int>(ScreenFilter::LINEAL) << ": lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
const auto valueVideoMode = std::to_string(static_cast<int>(options.video.mode));
|
||||
file << "video.mode=" << valueVideoMode << "\n";
|
||||
|
||||
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
|
||||
|
||||
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
|
||||
file << "video.filter=" << valueFilter << "\n";
|
||||
|
||||
file << "video.v_sync=" + boolToString(options.video.v_sync) + "\n";
|
||||
file << "video.integer_scale=" + boolToString(options.video.integer_scale) + "\n";
|
||||
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
|
||||
file << "video.mode=" << static_cast<int>(options.video.mode) << "\n";
|
||||
file << "video.window.size=" << options.video.window.size << "\n";
|
||||
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
|
||||
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n\n## AUDIO\n";
|
||||
file << "## volume [0 .. 128]\n";
|
||||
file << "## volume [0 .. 100]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "audio.music.enabled=" + boolToString(options.audio.music.enabled) + "\n";
|
||||
file << "audio.music.volume=" + std::to_string(options.audio.music.volume) + "\n";
|
||||
file << "audio.sound.enabled=" + boolToString(options.audio.sound.enabled) + "\n";
|
||||
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
|
||||
file << "audio.enabled=" << boolToString(options.audio.enabled) << "\n";
|
||||
file << "audio.volume=" << options.audio.volume << "\n";
|
||||
file << "audio.music.enabled=" << boolToString(options.audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume=" << options.audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled=" << boolToString(options.audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume=" << options.audio.sound.volume << "\n";
|
||||
|
||||
// Opciones del juego
|
||||
const auto value_difficulty_easy = std::to_string(static_cast<int>(GameDifficulty::EASY));
|
||||
const auto value_difficulty_normal = std::to_string(static_cast<int>(GameDifficulty::NORMAL));
|
||||
const auto value_difficulty_hard = std::to_string(static_cast<int>(GameDifficulty::HARD));
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [" << value_difficulty_easy << ": easy, " << value_difficulty_normal << ": normal, " << value_difficulty_hard << ": hard]\n";
|
||||
file << "## game.difficulty [" << static_cast<int>(GameDifficulty::EASY) << ": easy, " << static_cast<int>(GameDifficulty::NORMAL) << ": normal, " << static_cast<int>(GameDifficulty::HARD) << ": hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" + std::to_string(static_cast<int>(options.game.language)) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(static_cast<int>(options.game.difficulty)) + "\n";
|
||||
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
|
||||
file << "game.language=" << static_cast<int>(options.game.language) << "\n";
|
||||
file << "game.difficulty=" << static_cast<int>(options.game.difficulty) << "\n";
|
||||
file << "game.autofire=" << boolToString(options.game.autofire) << "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n\n## CONTROLLERS\n";
|
||||
file << "\n";
|
||||
|
||||
const int num_players = 2;
|
||||
for (int index = 0; index < num_players; ++index)
|
||||
int controller_index = 0;
|
||||
for (const auto &controller : options.controllers)
|
||||
{
|
||||
const std::string joyIndex = std::to_string(index + 1);
|
||||
file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n";
|
||||
file << "controller" + joyIndex + ".player=" + std::to_string(options.controller[index].player_id) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_left=" + std::to_string((int)options.controller[index].buttons[0]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_center=" + std::to_string((int)options.controller[index].buttons[1]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_right=" + std::to_string((int)options.controller[index].buttons[2]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.start=" + std::to_string((int)options.controller[index].buttons[3]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.service=" + std::to_string((int)options.controller[index].buttons[4]) + "\n";
|
||||
file << "\n";
|
||||
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
||||
file << "controller." << controller_index << ".player=" << controller.player_id << "\n";
|
||||
file << "controller." << controller_index << ".type=" << static_cast<int>(controller.type) << "\n";
|
||||
file << "controller." << controller_index << ".button.fire_left=" << controller.buttons.at(0) << "\n";
|
||||
file << "controller." << controller_index << ".button.fire_center=" << controller.buttons.at(1) << "\n";
|
||||
file << "controller." << controller_index << ".button.fire_right=" << controller.buttons.at(2) << "\n";
|
||||
file << "controller." << controller_index << ".button.start=" << controller.buttons.at(3) << "\n";
|
||||
file << "controller." << controller_index << ".button.service=" << controller.buttons.at(4) << "\n";
|
||||
|
||||
if (index < num_players - 1)
|
||||
{
|
||||
file << "\n";
|
||||
}
|
||||
// Incrementa el índice
|
||||
++controller_index;
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
@@ -238,7 +201,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.window.size")
|
||||
{
|
||||
options.video.window.size = std::stoi(value);
|
||||
@@ -247,43 +209,44 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "video.filter")
|
||||
{
|
||||
options.video.filter = static_cast<ScreenFilter>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.shaders")
|
||||
{
|
||||
options.video.shaders = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.integer_scale")
|
||||
{
|
||||
options.video.integer_scale = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.v_sync")
|
||||
{
|
||||
options.video.v_sync = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de audio
|
||||
else if (var == "audio.enabled")
|
||||
{
|
||||
options.audio.enabled = stringToBool(value);
|
||||
}
|
||||
else if (var == "audio.volume")
|
||||
{
|
||||
options.audio.volume = std::stoi(value);
|
||||
}
|
||||
else if (var == "audio.music.enabled")
|
||||
{
|
||||
options.audio.music.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.music.volume")
|
||||
{
|
||||
options.audio.music.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.enabled")
|
||||
{
|
||||
options.audio.sound.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.volume")
|
||||
{
|
||||
options.audio.sound.volume = std::stoi(value);
|
||||
@@ -294,97 +257,138 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
{
|
||||
options.game.language = static_cast<lang::Code>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options.game.difficulty = static_cast<GameDifficulty>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "game.autofire")
|
||||
{
|
||||
options.game.autofire = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de mandos
|
||||
else if (var == "controller1.name")
|
||||
else if (var == "controller.0.name")
|
||||
{
|
||||
options.controller[0].name = value;
|
||||
options.controllers.at(0).name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller1.player")
|
||||
else if (var == "controller.0.player")
|
||||
{
|
||||
options.controller[0].player_id = std::max(1, std::min(2, std::stoi(value)));
|
||||
options.controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_left")
|
||||
else if (var == "controller.0.type")
|
||||
{
|
||||
options.controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_center")
|
||||
else if (var == "controller.0.button.fire_left")
|
||||
{
|
||||
options.controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_right")
|
||||
else if (var == "controller.0.button.fire_center")
|
||||
{
|
||||
options.controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.start")
|
||||
else if (var == "controller.0.button.fire_right")
|
||||
{
|
||||
options.controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.service")
|
||||
else if (var == "controller.0.button.start")
|
||||
{
|
||||
options.controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(0).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.name")
|
||||
else if (var == "controller.0.button.service")
|
||||
{
|
||||
options.controller[1].name = value;
|
||||
options.controllers.at(0).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.player")
|
||||
else if (var == "controller.1.name")
|
||||
{
|
||||
options.controller[1].player_id = std::max(1, std::min(2, std::stoi(value)));
|
||||
options.controllers.at(1).name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_left")
|
||||
else if (var == "controller.1.player")
|
||||
{
|
||||
options.controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_center")
|
||||
else if (var == "controller.1.type")
|
||||
{
|
||||
options.controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_right")
|
||||
else if (var == "controller.1.button.fire_left")
|
||||
{
|
||||
options.controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.start")
|
||||
else if (var == "controller.1.button.fire_center")
|
||||
{
|
||||
options.controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.service")
|
||||
else if (var == "controller.1.button.fire_right")
|
||||
{
|
||||
options.controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
options.controllers.at(1).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.start")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.service")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var.empty() || var.starts_with("#"))
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
||||
int to_JA_volume(int vol)
|
||||
{
|
||||
vol = vol * 1.28f;
|
||||
return std::clamp(vol, 0, 128);
|
||||
}
|
||||
|
||||
// Asigna el teclado al jugador
|
||||
void setKeyboardToPlayer(int player_id)
|
||||
{
|
||||
for (auto &controller : options.controllers)
|
||||
{
|
||||
if (controller.player_id == player_id)
|
||||
{
|
||||
controller.type = InputDeviceToUse::ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.type = InputDeviceToUse::CONTROLLER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapOptionsKeyboard()
|
||||
{
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapOptionsControllers()
|
||||
{
|
||||
std::swap(options.controllers.at(0).player_id, options.controllers.at(1).player_id);
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
int getPlayerWhoUsesKeyboard()
|
||||
{
|
||||
for (const auto &controller : options.controllers)
|
||||
{
|
||||
if (controller.type == InputDeviceToUse::ANY)
|
||||
{
|
||||
return controller.player_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include "manage_hiscore_table.h"
|
||||
#include <vector> // Para vector
|
||||
#include <string>
|
||||
enum class InputType : int;
|
||||
enum class ScreenFilter : int;
|
||||
enum class ScreenVideoMode : int;
|
||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "input.h" // Para InputType, InputDeviceToUse
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
enum class ScreenFilter : int; // lines 10-10
|
||||
enum class ScreenVideoMode : int; // lines 11-11
|
||||
namespace lang
|
||||
{
|
||||
enum class Code : int;
|
||||
}
|
||||
} // lines 14-14
|
||||
|
||||
// Dificultad del juego
|
||||
enum class GameDifficulty
|
||||
@@ -57,6 +56,8 @@ struct OptionsAudio
|
||||
{
|
||||
OptionsMusic music; // Opciones para la música
|
||||
OptionsSound sound; // Opciones para los efectos de sonido
|
||||
bool enabled; // Indica si el audio está activo o no
|
||||
int volume; // Volumen al que suenan el audio
|
||||
};
|
||||
|
||||
// Estructura para las opciones del juego
|
||||
@@ -73,27 +74,50 @@ struct OptionsController
|
||||
{
|
||||
int index; // Indice en el vector de mandos
|
||||
int player_id; // Jugador asociado al mando
|
||||
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
|
||||
InputDeviceToUse type; // Indica si se utilizará teclado o mando o ambos
|
||||
std::string name; // Nombre del dispositivo
|
||||
bool plugged; // Indica si el mando se encuentra conectado
|
||||
std::vector<InputType> inputs; // Listado de inputs
|
||||
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsController()
|
||||
: index(-1), player_id(-1), type(InputDeviceToUse::CONTROLLER), name(""), plugged(false),
|
||||
inputs{InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START, InputType::SERVICE},
|
||||
buttons{SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_BACK} {}
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct Options
|
||||
{
|
||||
OptionsGame game; // Opciones para el propio juego
|
||||
OptionsVideo video; // Opciones relativas a la clase screen
|
||||
OptionsAudio audio; // Opciones para el audio
|
||||
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
|
||||
OptionsGame game; // Opciones para el propio juego
|
||||
OptionsVideo video; // Opciones relativas a la clase screen
|
||||
OptionsAudio audio; // Opciones para el audio
|
||||
std::vector<OptionsController> controllers; // Opciones con las asignaciones del mando para cada jugador
|
||||
};
|
||||
|
||||
// Variables
|
||||
extern Options options;
|
||||
|
||||
void initOptions();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadOptionsFile(std::string file_path);
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool saveOptionsFile(std::string file_path);
|
||||
bool saveOptionsFile(std::string file_path);
|
||||
|
||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
||||
int to_JA_volume(int vol);
|
||||
|
||||
// Asigna el teclado al jugador
|
||||
void setKeyboardToPlayer(int player_id);
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapOptionsKeyboard();
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapOptionsControllers();
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
int getPlayerWhoUsesKeyboard();
|
||||
@@ -23,6 +23,7 @@ void initParam()
|
||||
param.game.item_size = 20;
|
||||
param.game.game_area.rect = {0, 0, param.game.width, param.game.height};
|
||||
param.game.play_area.rect = {0, 0, param.game.width, 216};
|
||||
param.game.enter_name_seconds = 30;
|
||||
precalculateZones();
|
||||
|
||||
// SCOREBOARD
|
||||
|
||||
@@ -63,19 +63,23 @@ struct ParamNotification
|
||||
};
|
||||
|
||||
// Estructura para almacenar todos los parámetros del juego
|
||||
struct Param
|
||||
{
|
||||
ParamGame game; // Parametros relacionados con el juego
|
||||
ParamFade fade; // Parametros para ajustar el fade
|
||||
SDL_Rect scoreboard; // Posición y tamaño del marcador
|
||||
ParamTitle title; // Parametros con ajustes para la sección Title
|
||||
ParamBackground background; // Parametros que afectan a la clase Background
|
||||
std::vector<ParamBalloon> balloon; // Parametros de velocidad y gravedad de cada tipo de globo
|
||||
ParamNotification notification; // Opciones para las notificaciones
|
||||
struct Param {
|
||||
ParamGame game;
|
||||
ParamFade fade;
|
||||
SDL_Rect scoreboard;
|
||||
ParamTitle title;
|
||||
ParamBackground background;
|
||||
std::vector<ParamBalloon> balloon;
|
||||
ParamNotification notification;
|
||||
|
||||
Param() { balloon.reserve(4); }
|
||||
Param() : game(), fade(), scoreboard(), title(), background(), notification() {
|
||||
balloon.reserve(4);
|
||||
}
|
||||
};
|
||||
|
||||
extern Param param;
|
||||
|
||||
|
||||
extern Param param;
|
||||
|
||||
// Establece valores para los parametros a partir de un fichero de texto
|
||||
|
||||
@@ -1,40 +1,10 @@
|
||||
#include "path_sprite.h"
|
||||
#include <bits/std_abs.h> // Para abs
|
||||
#include <stdlib.h> // Para abs
|
||||
#include <utility> // Para move
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
#include "utils.h" // Para easeOutQuint
|
||||
#include <functional>
|
||||
class Texture; // lines 3-3
|
||||
|
||||
// Constructor
|
||||
PathSprite::PathSprite(std::shared_ptr<Texture> texture)
|
||||
: AnimatedSprite(texture) {}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void PathSprite::update()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
moveThroughCurrentPath();
|
||||
goToNextPathOrDie();
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter)
|
||||
{
|
||||
paths_.emplace_back(createPath(start, end, type, fixed_pos, steps, easingFunction), waiting_counter);
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(std::vector<SDL_Point> spots, int waiting_counter)
|
||||
{
|
||||
paths_.emplace_back(std::move(spots), waiting_counter);
|
||||
}
|
||||
#include <cstdlib> // Para abs
|
||||
#include <functional> // Para function
|
||||
#include <utility> // Para move
|
||||
|
||||
// Devuelve un vector con los puntos que conforman la ruta
|
||||
std::vector<SDL_Point> PathSprite::createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction)
|
||||
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction)
|
||||
{
|
||||
std::vector<SDL_Point> v;
|
||||
v.reserve(steps);
|
||||
@@ -69,6 +39,59 @@ std::vector<SDL_Point> PathSprite::createPath(int start, int end, PathType type,
|
||||
return v;
|
||||
}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void PathSprite::update()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
moveThroughCurrentPath();
|
||||
goToNextPathOrDie();
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(Path path, bool centered)
|
||||
{
|
||||
PathCentered path_centered = PathCentered::NONE;
|
||||
if (centered)
|
||||
path_centered = (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y;
|
||||
|
||||
switch (path_centered)
|
||||
{
|
||||
case PathCentered::ON_X:
|
||||
{
|
||||
const int x = path.spots.back().x - pos_.w / 2;
|
||||
for (auto &spot : path.spots)
|
||||
spot.x = x;
|
||||
paths_.emplace_back(path);
|
||||
break;
|
||||
}
|
||||
case PathCentered::ON_Y:
|
||||
{
|
||||
const int y = path.spots.back().y - pos_.h / 2;
|
||||
for (auto &spot : path.spots)
|
||||
spot.y = y;
|
||||
paths_.emplace_back(path);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
paths_.emplace_back(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter)
|
||||
{
|
||||
paths_.emplace_back(createPath(start, end, type, fixed_pos, steps, easingFunction), waiting_counter);
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(std::vector<SDL_Point> spots, int waiting_counter)
|
||||
{
|
||||
paths_.emplace_back(std::move(spots), waiting_counter);
|
||||
}
|
||||
|
||||
// Habilita el objeto
|
||||
void PathSprite::enable()
|
||||
{
|
||||
@@ -82,7 +105,7 @@ void PathSprite::moveThroughCurrentPath()
|
||||
|
||||
// Establece la posición
|
||||
const auto &p = path.spots.at(path.counter);
|
||||
MovingSprite::setPos(p.x, p.y);
|
||||
setPosition(p);
|
||||
|
||||
// Comprobar si ha terminado el recorrido
|
||||
if (!path.on_destination)
|
||||
@@ -101,7 +124,7 @@ void PathSprite::moveThroughCurrentPath()
|
||||
if (path.waiting_counter == 0)
|
||||
path.finished = true;
|
||||
else
|
||||
--path.waiting_counter;
|
||||
--path.waiting_counter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <functional>
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
class Texture; // lines 5-5
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <functional> // Para function
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <vector> // Para vector
|
||||
#include "sprite.h" // Para Sprite
|
||||
class Texture; // lines 8-8
|
||||
|
||||
enum class PathType
|
||||
{
|
||||
@@ -13,26 +13,35 @@ enum class PathType
|
||||
HORIZONTAL,
|
||||
};
|
||||
|
||||
enum class PathCentered
|
||||
{
|
||||
ON_X,
|
||||
ON_Y,
|
||||
NONE,
|
||||
};
|
||||
|
||||
// Estructuras
|
||||
struct Path
|
||||
{
|
||||
std::vector<SDL_Point> spots; // Puntos por los que se desplazará el sprite
|
||||
int waiting_counter; // Tiempo de espera una vez en el destino
|
||||
bool on_destination = false; // Indica si ha llegado al destino
|
||||
bool finished = false; // Indica si ha terminado de esperarse
|
||||
int counter = 0; // Contador interno
|
||||
|
||||
// Constructor
|
||||
Path(const std::vector<SDL_Point> &spots_init, int waiting_counter_init)
|
||||
: spots(spots_init), waiting_counter(waiting_counter_init) {}
|
||||
};
|
||||
|
||||
// Devuelve un vector con los puntos que conforman la ruta
|
||||
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction);
|
||||
|
||||
// Clase PathSprite
|
||||
class PathSprite : public AnimatedSprite
|
||||
class PathSprite : public Sprite
|
||||
{
|
||||
private:
|
||||
// Estructuras
|
||||
struct Path
|
||||
{
|
||||
std::vector<SDL_Point> spots; // Puntos por los que se desplazará el sprite
|
||||
int waiting_counter; // Tiempo de espera una vez en el destino
|
||||
bool on_destination = false; // Indica si ha llegado al destino
|
||||
bool finished = false; // Indica si ha terminado de esperarse
|
||||
int counter = 0; // Contador interno
|
||||
|
||||
// Constructor
|
||||
Path(const std::vector<SDL_Point> &spots_init, int waiting_counter_init)
|
||||
: spots(spots_init), waiting_counter(waiting_counter_init) {}
|
||||
};
|
||||
|
||||
// Variables
|
||||
bool finished_ = false; // Indica si ya ha terminado
|
||||
bool enabled_ = false; // Indica si el objeto está habilitado
|
||||
int current_path_ = 0; // Path que se está recorriendo actualmente
|
||||
std::vector<Path> paths_; // Caminos a recorrer por el sprite
|
||||
@@ -45,21 +54,20 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit PathSprite(std::shared_ptr<Texture> texture);
|
||||
explicit PathSprite(std::shared_ptr<Texture> texture)
|
||||
: Sprite(texture) {}
|
||||
|
||||
// Destructor
|
||||
~PathSprite() = default;
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
void update() override;
|
||||
void update();
|
||||
|
||||
// Añade un recorrido
|
||||
void addPath(Path path, bool centered = false);
|
||||
void addPath(std::vector<SDL_Point> spots, int waiting_counter);
|
||||
void addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction, int waiting_counter);
|
||||
|
||||
// Devuelve un vector con los puntos que conforman la ruta
|
||||
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction);
|
||||
|
||||
// Habilita el objeto
|
||||
void enable();
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#include "player.h"
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para max, min
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "input.h" // Para InputType
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
||||
#include "texture.h" // Para Texture
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdlib.h> // Para rand
|
||||
#include <algorithm> // Para clamp, max, min
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "input.h" // Para InputType
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
||||
@@ -29,7 +27,7 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vect
|
||||
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));
|
||||
|
||||
// Inicializa variables
|
||||
setRecordName(enter_name_->getName());
|
||||
pos_x_ = default_pos_x_;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -37,11 +35,10 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vect
|
||||
void Player::init()
|
||||
{
|
||||
// Inicializa variables de estado
|
||||
pos_x_ = default_pos_x_;
|
||||
pos_y_ = default_pos_y_;
|
||||
status_walking_ = PlayerStatus::WALKING_STOP;
|
||||
status_firing_ = PlayerStatus::FIRING_NONE;
|
||||
status_playing_ = PlayerStatus::WAITING;
|
||||
walking_state_ = PlayerState::WALKING_STOP;
|
||||
firing_state_ = PlayerState::FIRING_NONE;
|
||||
playing_state_ = PlayerState::WAITING;
|
||||
invulnerable_ = true;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER_;
|
||||
power_up_ = false;
|
||||
@@ -58,11 +55,11 @@ void Player::init()
|
||||
score_ = 0;
|
||||
score_multiplier_ = 1.0f;
|
||||
cooldown_ = 10;
|
||||
enter_name_->init();
|
||||
|
||||
// Establece la posición del sprite
|
||||
player_sprite_->clear();
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
shiftSprite();
|
||||
|
||||
// Selecciona un frame para pintar
|
||||
player_sprite_->setCurrentAnimation("stand");
|
||||
@@ -71,20 +68,19 @@ void Player::init()
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(InputType input)
|
||||
{
|
||||
switch (status_playing_)
|
||||
switch (playing_state_)
|
||||
{
|
||||
case PlayerStatus::PLAYING:
|
||||
case PlayerState::PLAYING:
|
||||
{
|
||||
setInputPlaying(input);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::ENTERING_NAME:
|
||||
case PlayerState::ENTERING_NAME:
|
||||
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
|
||||
{
|
||||
setInputEnteringName(input);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -98,39 +94,34 @@ void Player::setInputPlaying(InputType input)
|
||||
case InputType::LEFT:
|
||||
{
|
||||
vel_x_ = -BASE_SPEED_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_LEFT);
|
||||
setWalkingState(PlayerState::WALKING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case InputType::RIGHT:
|
||||
{
|
||||
vel_x_ = BASE_SPEED_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_RIGHT);
|
||||
setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
case InputType::FIRE_CENTER:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_UP);
|
||||
setFiringState(PlayerState::FIRING_UP);
|
||||
break;
|
||||
}
|
||||
|
||||
case InputType::FIRE_LEFT:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_LEFT);
|
||||
setFiringState(PlayerState::FIRING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case InputType::FIRE_RIGHT:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_RIGHT);
|
||||
setFiringState(PlayerState::FIRING_RIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
vel_x_ = 0;
|
||||
setWalkingStatus(PlayerStatus::WALKING_STOP);
|
||||
setWalkingState(PlayerState::WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -144,70 +135,130 @@ void Player::setInputEnteringName(InputType input)
|
||||
case InputType::LEFT:
|
||||
enter_name_->decPosition();
|
||||
break;
|
||||
|
||||
case InputType::RIGHT:
|
||||
enter_name_->incPosition();
|
||||
break;
|
||||
|
||||
case InputType::UP:
|
||||
enter_name_->incIndex();
|
||||
break;
|
||||
|
||||
case InputType::DOWN:
|
||||
enter_name_->decIndex();
|
||||
break;
|
||||
|
||||
case InputType::START:
|
||||
setRecordName(enter_name_->getName());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
setRecordName(enter_name_->getName());
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void Player::move()
|
||||
{
|
||||
if (isPlaying())
|
||||
switch (playing_state_)
|
||||
{
|
||||
case PlayerState::PLAYING:
|
||||
{
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((pos_x_ < param.game.play_area.rect.x - 5) || (pos_x_ + WIDTH_ > play_area_.w + 5))
|
||||
{
|
||||
// Restaura su posición
|
||||
pos_x_ -= vel_x_;
|
||||
}
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float min_x = play_area_.x - 5;
|
||||
const float max_x = play_area_.w + 5 - WIDTH_;
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
player_sprite_->setPosX(getPosX());
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
|
||||
power_sprite_->setPosX(getPosX() - power_up_desp_x_);
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
else if (isDying())
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
player_sprite_->update();
|
||||
|
||||
// Si el cadaver abandona el area de juego por los laterales
|
||||
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
||||
if ((player_sprite_->getPosX() < play_area_.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
{
|
||||
// Restaura su posición
|
||||
const float vx = player_sprite_->getVelX();
|
||||
player_sprite_->setPosX(player_sprite_->getPosX() - vx);
|
||||
|
||||
// Rebota
|
||||
player_sprite_->setVelX(-vx);
|
||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||
}
|
||||
|
||||
// Si el cadaver abandona el area de juego por abajo
|
||||
if (player_sprite_->getPosY() > param.game.play_area.rect.h)
|
||||
// Si el cadaver toca el suelo cambia el estado
|
||||
if (player_sprite_->getPosY() > play_area_.h - HEIGHT_)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::DIED);
|
||||
if (player_sprite_->getVelY() < 2.0f)
|
||||
{
|
||||
// Si la velocidad de rebote es baja, termina de rebotar y cambia de estado
|
||||
setPlayingState(PlayerState::DIED);
|
||||
pos_x_ = player_sprite_->getPosX();
|
||||
pos_y_ = default_pos_y_;
|
||||
player_sprite_->clear();
|
||||
shiftSprite();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrementa las velocidades de rebote
|
||||
player_sprite_->setPosY(play_area_.h - HEIGHT_);
|
||||
player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f);
|
||||
player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerState::LEAVING_SCREEN:
|
||||
{
|
||||
switch (id_)
|
||||
{
|
||||
case 1:
|
||||
setInputPlaying(InputType::LEFT);
|
||||
break;
|
||||
case 2:
|
||||
setInputPlaying(InputType::RIGHT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pos_x_ += vel_x_;
|
||||
const float min_x = -WIDTH_;
|
||||
const float max_x = play_area_.w;
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
shiftSprite();
|
||||
|
||||
if (pos_x_ == min_x || pos_x_ == max_x)
|
||||
setPlayingState(PlayerState::GAME_OVER);
|
||||
break;
|
||||
}
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
pos_x_ += vel_x_ / 2.0f;
|
||||
if (vel_x_ > 0)
|
||||
{
|
||||
// setInputPlaying(InputType::RIGHT);
|
||||
if (pos_x_ > param.game.game_area.rect.w - WIDTH_)
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.w - WIDTH_;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::LEFT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// setInputPlaying(InputType::LEFT);
|
||||
if (pos_x_ < param.game.game_area.rect.x)
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.x;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
if (pos_x_ > param.game.game_area.center_x - WIDTH_ / 2)
|
||||
{
|
||||
setWalkingState(PlayerState::WALKING_LEFT);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWalkingState(PlayerState::WALKING_RIGHT);
|
||||
}
|
||||
shiftSprite();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,110 +274,111 @@ void Player::render()
|
||||
}
|
||||
|
||||
if (isRenderable())
|
||||
{
|
||||
player_sprite_->render();
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando camina
|
||||
void Player::setWalkingStatus(PlayerStatus status)
|
||||
{
|
||||
status_walking_ = status;
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando dispara
|
||||
void Player::setFiringStatus(PlayerStatus status)
|
||||
{
|
||||
status_firing_ = status;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Player::setAnimation()
|
||||
{
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
const std::string a_walking = status_walking_ == PlayerStatus::WALKING_STOP ? "stand" : "walk";
|
||||
const std::string a_firing = status_firing_ == PlayerStatus::FIRING_UP ? "centershoot" : "sideshoot";
|
||||
|
||||
const SDL_RendererFlip flip_walk = status_walking_ == PlayerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flip_fire = status_firing_ == PlayerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (isPlaying())
|
||||
switch (playing_state_)
|
||||
{
|
||||
if (status_firing_ == PlayerStatus::FIRING_NONE)
|
||||
case PlayerState::PLAYING:
|
||||
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
|
||||
case PlayerState::LEAVING_SCREEN:
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
const std::string a_walking = walking_state_ == PlayerState::WALKING_STOP ? "stand" : "walk";
|
||||
const std::string a_firing = firing_state_ == PlayerState::FIRING_UP ? "centershoot" : "sideshoot";
|
||||
const std::string a_cooling = firing_state_ == PlayerState::COOLING_UP ? "centershoot" : "sideshoot";
|
||||
|
||||
const SDL_RendererFlip flip_walk = walking_state_ == PlayerState::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flip_fire = firing_state_ == PlayerState::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flip_cooling = firing_state_ == PlayerState::COOLING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (firing_state_ == PlayerState::FIRING_NONE)
|
||||
{ // No esta disparando
|
||||
player_sprite_->setCurrentAnimation(a_walking);
|
||||
player_sprite_->setFlip(flip_walk);
|
||||
}
|
||||
else if (isCooling())
|
||||
{ // Acaba de disparar
|
||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
|
||||
player_sprite_->setFlip(flip_cooling);
|
||||
}
|
||||
else
|
||||
{ // Está disparando
|
||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
|
||||
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
||||
// Si dispara recto, invierte el sprite segun hacia donde camina
|
||||
a_firing == "centershoot" ? player_sprite_->setFlip(flip_walk) : player_sprite_->setFlip(flip_fire);
|
||||
player_sprite_->setFlip(a_firing == "centershoot" ? flip_walk : flip_fire);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
player_sprite_->setCurrentAnimation("death");
|
||||
player_sprite_->setCurrentAnimation("dying");
|
||||
break;
|
||||
}
|
||||
case PlayerState::DIED:
|
||||
case PlayerState::ENTERING_NAME:
|
||||
case PlayerState::CONTINUE:
|
||||
{
|
||||
player_sprite_->setCurrentAnimation("dead");
|
||||
break;
|
||||
}
|
||||
case PlayerState::CELEBRATING:
|
||||
{
|
||||
player_sprite_->setCurrentAnimation("celebration");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
player_sprite_->update();
|
||||
|
||||
// powerSprite->setFlip(flip_walk);
|
||||
player_sprite_->update(); // Hace avanzar las animaciones y mueve el cadaver del jugador
|
||||
power_sprite_->update();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPosX() const
|
||||
{
|
||||
return int(pos_x_);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPosY() const
|
||||
{
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getWidth() const
|
||||
{
|
||||
return WIDTH_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getHeight() const
|
||||
{
|
||||
return HEIGHT_;
|
||||
}
|
||||
|
||||
// Indica si el jugador puede disparar
|
||||
bool Player::canFire() const
|
||||
{
|
||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||
return cooldown_ > 0 ? false : true;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setFireCooldown(int time)
|
||||
{
|
||||
cooldown_ = time;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateCooldown()
|
||||
{
|
||||
if (cooldown_ > 0)
|
||||
{
|
||||
cooldown_--;
|
||||
if (power_up_)
|
||||
{
|
||||
cooldown_--;
|
||||
}
|
||||
cooldown_ -= power_up_ ? 2 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_NONE);
|
||||
if (!isCooling())
|
||||
{
|
||||
cooling_status_counter_ = 40;
|
||||
switch (firing_state_)
|
||||
{
|
||||
case PlayerState::FIRING_LEFT:
|
||||
firing_state_ = PlayerState::COOLING_LEFT;
|
||||
break;
|
||||
case PlayerState::FIRING_RIGHT:
|
||||
firing_state_ = PlayerState::COOLING_RIGHT;
|
||||
break;
|
||||
case PlayerState::FIRING_UP:
|
||||
firing_state_ = PlayerState::COOLING_UP;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (cooling_status_counter_ > 0)
|
||||
{
|
||||
--cooling_status_counter_;
|
||||
}
|
||||
else
|
||||
{
|
||||
setFiringState(PlayerState::FIRING_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,18 +396,6 @@ void Player::update()
|
||||
updateScoreboard();
|
||||
}
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
int Player::getScore() const
|
||||
{
|
||||
return score_;
|
||||
}
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void Player::setScore(int score)
|
||||
{
|
||||
score_ = score;
|
||||
}
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
void Player::addScore(int score)
|
||||
{
|
||||
@@ -365,67 +405,23 @@ void Player::addScore(int score)
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si el jugador está jugando
|
||||
bool Player::isPlaying() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::PLAYING;
|
||||
}
|
||||
|
||||
// Indica si el jugador está continuando
|
||||
bool Player::isContinue() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::CONTINUE;
|
||||
}
|
||||
|
||||
// Indica si el jugador está esperando
|
||||
bool Player::isWaiting() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::WAITING;
|
||||
}
|
||||
|
||||
// Indica si el jugador está introduciendo su nombre
|
||||
bool Player::isEnteringName() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::ENTERING_NAME;
|
||||
}
|
||||
|
||||
// Indica si el jugador está muriendose
|
||||
bool Player::isDying() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::DYING;
|
||||
}
|
||||
|
||||
// Indica si el jugador ha terminado de morir
|
||||
bool Player::hasDied() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::DIED;
|
||||
}
|
||||
|
||||
// Indica si el jugador ya ha terminado de jugar
|
||||
bool Player::isGameOver() const
|
||||
{
|
||||
return status_playing_ == PlayerStatus::GAME_OVER;
|
||||
}
|
||||
|
||||
// Actualiza el panel del marcador
|
||||
void Player::updateScoreboard()
|
||||
{
|
||||
switch (status_playing_)
|
||||
switch (playing_state_)
|
||||
{
|
||||
|
||||
case PlayerStatus::CONTINUE:
|
||||
case PlayerState::CONTINUE:
|
||||
{
|
||||
Scoreboard::get()->setContinue(getScoreBoardPanel(), getContinueCounter());
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::ENTERING_NAME:
|
||||
case PlayerState::ENTERING_NAME:
|
||||
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
|
||||
{
|
||||
Scoreboard::get()->setRecordName(getScoreBoardPanel(), getRecordName());
|
||||
Scoreboard::get()->setRecordName(getScoreBoardPanel(), enter_name_->getName());
|
||||
Scoreboard::get()->setSelectorPos(getScoreBoardPanel(), getRecordNamePos());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -441,43 +437,38 @@ void Player::setScoreboardMode(ScoreboardMode mode)
|
||||
}
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void Player::setStatusPlaying(PlayerStatus value)
|
||||
void Player::setPlayingState(PlayerState state)
|
||||
{
|
||||
status_playing_ = value;
|
||||
playing_state_ = state;
|
||||
|
||||
switch (status_playing_)
|
||||
switch (playing_state_)
|
||||
{
|
||||
case PlayerStatus::PLAYING:
|
||||
case PlayerState::PLAYING:
|
||||
{
|
||||
init();
|
||||
status_playing_ = PlayerStatus::PLAYING;
|
||||
playing_state_ = PlayerState::PLAYING;
|
||||
setScoreboardMode(ScoreboardMode::SCORE);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::CONTINUE:
|
||||
case PlayerState::CONTINUE:
|
||||
{
|
||||
// Inicializa el contador de continuar
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_ = 9;
|
||||
enter_name_->init();
|
||||
setScoreboardMode(ScoreboardMode::CONTINUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::WAITING:
|
||||
case PlayerState::WAITING:
|
||||
{
|
||||
setScoreboardMode(ScoreboardMode::WAITING);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::ENTERING_NAME:
|
||||
case PlayerState::ENTERING_NAME:
|
||||
{
|
||||
setScoreboardMode(ScoreboardMode::ENTER_NAME);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::DYING:
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
// Activa la animación de morir
|
||||
player_sprite_->setAccelY(0.2f);
|
||||
@@ -485,43 +476,44 @@ void Player::setStatusPlaying(PlayerStatus value)
|
||||
rand() % 2 == 0 ? player_sprite_->setVelX(3.3f) : player_sprite_->setVelX(-3.3f);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::DIED:
|
||||
case PlayerState::DIED:
|
||||
{
|
||||
const auto nextPlayerStatus = IsEligibleForHighScore() ? PlayerStatus::ENTERING_NAME : PlayerStatus::CONTINUE;
|
||||
demo_ ? setStatusPlaying(PlayerStatus::WAITING) : setStatusPlaying(nextPlayerStatus);
|
||||
const auto nextPlayerStatus = IsEligibleForHighScore() ? PlayerState::ENTERING_NAME : PlayerState::CONTINUE;
|
||||
demo_ ? setPlayingState(PlayerState::WAITING) : setPlayingState(nextPlayerStatus);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::GAME_OVER:
|
||||
case PlayerState::GAME_OVER:
|
||||
{
|
||||
setScoreboardMode(ScoreboardMode::GAME_OVER);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerState::CELEBRATING:
|
||||
{
|
||||
setScoreboardMode(ScoreboardMode::SCORE);
|
||||
break;
|
||||
}
|
||||
case PlayerState::ENTERING_NAME_GAME_COMPLETED:
|
||||
{
|
||||
setWalkingState(PlayerState::WALKING_STOP);
|
||||
setFiringState(PlayerState::FIRING_NONE);
|
||||
setScoreboardMode(ScoreboardMode::ENTER_NAME);
|
||||
break;
|
||||
}
|
||||
case PlayerState::LEAVING_SCREEN:
|
||||
{
|
||||
setScoreboardMode(ScoreboardMode::GAME_COMPLETED);
|
||||
break;
|
||||
}
|
||||
case PlayerState::CREDITS:
|
||||
{
|
||||
vel_x_ = (walking_state_ == PlayerState::WALKING_RIGHT) ? BASE_SPEED_ : -BASE_SPEED_;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el estado del jugador en el juego
|
||||
PlayerStatus Player::getStatusPlaying() const
|
||||
{
|
||||
return status_playing_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float Player::getScoreMultiplier() const
|
||||
{
|
||||
return score_multiplier_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setScoreMultiplier(float value)
|
||||
{
|
||||
score_multiplier_ = value;
|
||||
}
|
||||
|
||||
// Aumenta el valor de la variable hasta un máximo
|
||||
void Player::incScoreMultiplier()
|
||||
{
|
||||
@@ -536,12 +528,6 @@ void Player::decScoreMultiplier()
|
||||
score_multiplier_ = std::max(score_multiplier_, 1.0f);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isInvulnerable() const
|
||||
{
|
||||
return invulnerable_;
|
||||
}
|
||||
|
||||
// Establece el valor del estado
|
||||
void Player::setInvulnerable(bool value)
|
||||
{
|
||||
@@ -549,18 +535,6 @@ void Player::setInvulnerable(bool value)
|
||||
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER_ : 0;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getInvulnerableCounter() const
|
||||
{
|
||||
return invulnerable_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerableCounter(int value)
|
||||
{
|
||||
invulnerable_counter_ = value;
|
||||
}
|
||||
|
||||
// Monitoriza el estado
|
||||
void Player::updateInvulnerable()
|
||||
{
|
||||
@@ -579,12 +553,6 @@ void Player::updateInvulnerable()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isPowerUp() const
|
||||
{
|
||||
return power_up_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUp()
|
||||
{
|
||||
@@ -592,18 +560,6 @@ void Player::setPowerUp()
|
||||
power_up_counter_ = POWERUP_COUNTER_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPowerUpCounter() const
|
||||
{
|
||||
return power_up_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUpCounter(int value)
|
||||
{
|
||||
power_up_counter_ = value;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUp()
|
||||
{
|
||||
@@ -614,12 +570,6 @@ void Player::updatePowerUp()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::hasExtraHit() const
|
||||
{
|
||||
return extra_hit_;
|
||||
}
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void Player::giveExtraHit()
|
||||
{
|
||||
@@ -644,18 +594,6 @@ void Player::removeExtraHit()
|
||||
extra_hit_ = coffees_ == 0 ? false : true;
|
||||
}
|
||||
|
||||
// Devuelve el número de cafes actuales
|
||||
int Player::getCoffees() const
|
||||
{
|
||||
return coffees_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &Player::getCollider()
|
||||
{
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void Player::shiftColliders()
|
||||
{
|
||||
@@ -670,16 +608,10 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getContinueCounter() const
|
||||
{
|
||||
return continue_counter_;
|
||||
}
|
||||
|
||||
// Actualiza el contador de continue
|
||||
void Player::updateContinueCounter()
|
||||
{
|
||||
if (status_playing_ == PlayerStatus::CONTINUE)
|
||||
if (playing_state_ == PlayerState::CONTINUE)
|
||||
{
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
if (SDL_GetTicks() - continue_ticks_ > TICKS_SPEED)
|
||||
@@ -692,7 +624,7 @@ void Player::updateContinueCounter()
|
||||
// Actualiza el contador de entrar nombre
|
||||
void Player::updateEnterNameCounter()
|
||||
{
|
||||
if (status_playing_ == PlayerStatus::ENTERING_NAME)
|
||||
if (playing_state_ == PlayerState::ENTERING_NAME || playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED)
|
||||
{
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
if (SDL_GetTicks() - enter_name_ticks_ > TICKS_SPEED)
|
||||
@@ -702,18 +634,6 @@ void Player::updateEnterNameCounter()
|
||||
}
|
||||
}
|
||||
|
||||
// Le asigna un panel en el marcador al jugador
|
||||
void Player::setScoreBoardPanel(int panel)
|
||||
{
|
||||
scoreboard_panel_ = panel;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getScoreBoardPanel() const
|
||||
{
|
||||
return scoreboard_panel_;
|
||||
}
|
||||
|
||||
// Decrementa el contador de continuar
|
||||
void Player::decContinueCounter()
|
||||
{
|
||||
@@ -721,7 +641,7 @@ void Player::decContinueCounter()
|
||||
--continue_counter_;
|
||||
if (continue_counter_ < 0)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::GAME_OVER);
|
||||
setPlayingState(PlayerState::GAME_OVER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -733,35 +653,18 @@ void Player::decEnterNameCounter()
|
||||
if (enter_name_counter_ < 0)
|
||||
{
|
||||
enter_name_counter_ = param.game.enter_name_seconds;
|
||||
setStatusPlaying(PlayerStatus::CONTINUE);
|
||||
if (playing_state_ == PlayerState::ENTERING_NAME)
|
||||
{
|
||||
setPlayingState(PlayerState::CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPlayingState(PlayerState::LEAVING_SCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el nombre del jugador
|
||||
void Player::setName(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void Player::setRecordName(const std::string &record_name)
|
||||
{
|
||||
record_name_ = record_name.substr(0, 8);
|
||||
}
|
||||
|
||||
// Obtiene el nombre del jugador
|
||||
std::string Player::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
|
||||
std::string Player::getRecordName() const
|
||||
{
|
||||
return record_name_;
|
||||
}
|
||||
|
||||
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
// Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
int Player::getRecordNamePos() const
|
||||
{
|
||||
if (enter_name_)
|
||||
@@ -772,32 +675,10 @@ int Player::getRecordNamePos() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Establece el mando que usará para ser controlado
|
||||
void Player::setController(int index)
|
||||
// Recoloca los sprites
|
||||
void Player::shiftSprite()
|
||||
{
|
||||
controller_index_ = index;
|
||||
}
|
||||
|
||||
// Obtiene el mando que usa para ser controlado
|
||||
int Player::getController() const
|
||||
{
|
||||
return controller_index_;
|
||||
}
|
||||
|
||||
// Obtiene el "id" del jugador
|
||||
int Player::getId() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
// Indica si el jugador se puede dibujar
|
||||
bool Player::isRenderable() const
|
||||
{
|
||||
return isPlaying() || isDying();
|
||||
}
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool Player::IsEligibleForHighScore()
|
||||
{
|
||||
return score_ > options.game.hi_score_table.back().score;
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
power_sprite_->setPosX(getPosX() - power_up_desp_x_);
|
||||
}
|
||||
287
source/player.h
@@ -1,19 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "enter_name.h" // Para EnterName
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture; // lines 12-12
|
||||
enum class InputType : int; // lines 13-13
|
||||
enum class ScoreboardMode; // lines 14-14
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
#include "enter_name.h" // Para EnterName
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
#include "options.h" // Para Options, OptionsGame, options
|
||||
#include "utils.h" // Para Circle
|
||||
class Texture; // lines 13-13
|
||||
enum class InputType : int; // lines 14-14
|
||||
enum class ScoreboardMode; // lines 15-15
|
||||
|
||||
// Estados del jugador
|
||||
enum class PlayerStatus
|
||||
enum class PlayerState
|
||||
{
|
||||
WALKING_LEFT,
|
||||
WALKING_RIGHT,
|
||||
@@ -24,16 +26,22 @@ enum class PlayerStatus
|
||||
FIRING_RIGHT,
|
||||
FIRING_NONE,
|
||||
|
||||
PLAYING,
|
||||
CONTINUE,
|
||||
WAITING,
|
||||
ENTERING_NAME,
|
||||
DYING,
|
||||
DIED,
|
||||
GAME_OVER,
|
||||
};
|
||||
COOLING_UP,
|
||||
COOLING_LEFT,
|
||||
COOLING_RIGHT,
|
||||
|
||||
// Variables del jugador
|
||||
PLAYING, // Está jugando
|
||||
CONTINUE, // Está con la cuenta atras para continuar
|
||||
WAITING, // No está jugando pero puede entrar a jugar
|
||||
ENTERING_NAME, // Introduciendo nombre
|
||||
DYING, // El cadaver está volando por ahi
|
||||
DIED, // El cadaver ha desaparecido por el fondo
|
||||
GAME_OVER, // No está jugando y no puede entrar a jugar
|
||||
CELEBRATING, // Poniendo pose de victoria
|
||||
ENTERING_NAME_GAME_COMPLETED, // Poniendo nombre en el tramo final del juego
|
||||
LEAVING_SCREEN, // Moviendose fuera de la pantalla
|
||||
CREDITS, // Estado para los creditos del juego
|
||||
};
|
||||
|
||||
// Clase Player
|
||||
class Player
|
||||
@@ -52,41 +60,44 @@ private:
|
||||
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
|
||||
|
||||
// Variables
|
||||
int id_; // Numero de identificación para el jugador. Player1 = 1, Player2 = 2
|
||||
SDL_Rect play_area_; // Rectangulo con la zona de juego
|
||||
float pos_x_ = 0.0f; // Posicion en el eje X
|
||||
int pos_y_ = 0; // Posicion en el eje Y
|
||||
float default_pos_x_; // Posición inicial para el jugador
|
||||
int default_pos_y_; // Posición inicial para el jugador
|
||||
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
int cooldown_ = 10; // Contador durante el cual no puede disparar
|
||||
int score_ = 0; // Puntos del jugador
|
||||
float score_multiplier_ = 1.0f; // Multiplicador de puntos
|
||||
PlayerStatus status_walking_ = PlayerStatus::WALKING_STOP; // Estado del jugador al moverse
|
||||
PlayerStatus status_firing_ = PlayerStatus::FIRING_NONE; // Estado del jugador al disparar
|
||||
PlayerStatus status_playing_ = PlayerStatus::WAITING; // Estado del jugador en el juego
|
||||
bool invulnerable_ = true; // Indica si el jugador es invulnerable
|
||||
int invulnerable_counter_ = INVULNERABLE_COUNTER_; // Contador para la invulnerabilidad
|
||||
bool extra_hit_ = false; // Indica si el jugador tiene un toque extra
|
||||
int coffees_ = 0; // Indica cuantos cafes lleva acumulados
|
||||
bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp
|
||||
int power_up_counter_ = POWERUP_COUNTER_; // Temporizador para el modo PowerUp
|
||||
int power_up_desp_x_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador
|
||||
int continue_counter_ = 10; // Contador para poder continuar
|
||||
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador
|
||||
std::string name_; // Nombre del jugador
|
||||
std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones
|
||||
int controller_index_ = 0; // Indice del array de mandos que utilizará para moverse
|
||||
bool demo_; // Para que el jugador sepa si está en el modo demostración
|
||||
int enter_name_counter_; // Contador para poner nombre
|
||||
Uint32 enter_name_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
||||
int id_; // Numero de identificación para el jugador. Player1 = 1, Player2 = 2
|
||||
SDL_Rect play_area_; // Rectangulo con la zona de juego
|
||||
float pos_x_ = 0.0f; // Posicion en el eje X
|
||||
int pos_y_ = 0; // Posicion en el eje Y
|
||||
float default_pos_x_; // Posición inicial para el jugador
|
||||
int default_pos_y_; // Posición inicial para el jugador
|
||||
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
int cooldown_ = 0; // Contador durante el cual no puede disparar
|
||||
int cooling_status_counter_ = 0; // Contador para la animación del estado cooling
|
||||
int score_ = 0; // Puntos del jugador
|
||||
float score_multiplier_ = 1.0f; // Multiplicador de puntos
|
||||
PlayerState walking_state_ = PlayerState::WALKING_STOP; // Estado del jugador al moverse
|
||||
PlayerState firing_state_ = PlayerState::FIRING_NONE; // Estado del jugador al disparar
|
||||
PlayerState playing_state_ = PlayerState::WAITING; // Estado del jugador en el juego
|
||||
bool invulnerable_ = true; // Indica si el jugador es invulnerable
|
||||
int invulnerable_counter_ = INVULNERABLE_COUNTER_; // Contador para la invulnerabilidad
|
||||
bool extra_hit_ = false; // Indica si el jugador tiene un toque extra
|
||||
int coffees_ = 0; // Indica cuantos cafes lleva acumulados
|
||||
bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp
|
||||
int power_up_counter_ = POWERUP_COUNTER_; // Temporizador para el modo PowerUp
|
||||
int power_up_desp_x_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador
|
||||
int continue_counter_ = 10; // Contador para poder continuar
|
||||
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador
|
||||
std::string name_; // Nombre del jugador
|
||||
int controller_index_ = 0; // Indice del array de mandos que utilizará para moverse
|
||||
bool demo_; // Para que el jugador sepa si está en el modo demostración
|
||||
int enter_name_counter_; // Contador para poner nombre
|
||||
Uint32 enter_name_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void shiftColliders();
|
||||
|
||||
// Recoloca el sprite
|
||||
void shiftSprite();
|
||||
|
||||
// Monitoriza el estado
|
||||
void updateInvulnerable();
|
||||
|
||||
@@ -99,18 +110,14 @@ private:
|
||||
// Decrementa el contador de entrar nombre
|
||||
void decEnterNameCounter();
|
||||
|
||||
// Indica si el jugador se puede dibujar
|
||||
bool isRenderable() const;
|
||||
|
||||
// Actualiza el panel del marcador
|
||||
void updateScoreboard();
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool IsEligibleForHighScore();
|
||||
|
||||
// Cambia el modo del marcador
|
||||
void setScoreboardMode(ScoreboardMode mode);
|
||||
|
||||
bool isRenderable() const { return !isWaiting() && !isGameOver(); }
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations);
|
||||
@@ -142,77 +149,17 @@ public:
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void move();
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setWalkingStatus(PlayerStatus status);
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setFiringStatus(PlayerStatus status);
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void setAnimation();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getPosX() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getPosY() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getWidth() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getHeight() const;
|
||||
|
||||
// Indica si el jugador puede disparar
|
||||
bool canFire() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFireCooldown(int time);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateCooldown();
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
int getScore() const;
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void setScore(int score);
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
void addScore(int score);
|
||||
|
||||
// Indica si el jugador está jugando
|
||||
bool isPlaying() const;
|
||||
|
||||
// Indica si el jugador está continuando
|
||||
bool isContinue() const;
|
||||
|
||||
// Indica si el jugador está esperando
|
||||
bool isWaiting() const;
|
||||
|
||||
// Indica si el jugador está introduciendo su nombre
|
||||
bool isEnteringName() const;
|
||||
|
||||
// Indica si el jugador está muriendose
|
||||
bool isDying() const;
|
||||
|
||||
// Indica si el jugador ha terminado de morir
|
||||
bool hasDied() const;
|
||||
|
||||
// Indica si el jugador ya ha terminado de jugar
|
||||
bool isGameOver() const;
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void setStatusPlaying(PlayerStatus value);
|
||||
|
||||
// Obtiene el estado del jugador en el juego
|
||||
PlayerStatus getStatusPlaying() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float getScoreMultiplier() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setScoreMultiplier(float value);
|
||||
void setPlayingState(PlayerState state);
|
||||
|
||||
// Aumenta el valor de la variable hasta un máximo
|
||||
void incScoreMultiplier();
|
||||
@@ -220,81 +167,73 @@ public:
|
||||
// Decrementa el valor de la variable hasta un mínimo
|
||||
void decScoreMultiplier();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isInvulnerable() const;
|
||||
|
||||
// Establece el valor del estado
|
||||
void setInvulnerable(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getInvulnerableCounter() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerableCounter(int value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isPowerUp() const;
|
||||
|
||||
// Establece el valor de la variable a verdadero
|
||||
void setPowerUp();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getPowerUpCounter() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPowerUpCounter(int value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUp();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool hasExtraHit() const;
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void giveExtraHit();
|
||||
|
||||
// Quita el toque extra al jugador
|
||||
void removeExtraHit();
|
||||
|
||||
// Devuelve el número de cafes actuales
|
||||
int getCoffees() const;
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &getCollider();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getContinueCounter() const;
|
||||
|
||||
// Le asigna un panel en el marcador al jugador
|
||||
void setScoreBoardPanel(int panel);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getScoreBoardPanel() const;
|
||||
|
||||
// Decrementa el contador de continuar
|
||||
void decContinueCounter();
|
||||
|
||||
// Establece el nombre del jugador
|
||||
void setName(const std::string &name);
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void setRecordName(const std::string &record_name);
|
||||
|
||||
// Obtiene el nombre del jugador
|
||||
std::string getName() const;
|
||||
|
||||
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
|
||||
std::string getRecordName() const;
|
||||
|
||||
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
// Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
int getRecordNamePos() const;
|
||||
|
||||
// Establece el mando que usará para ser controlado
|
||||
void setController(int index);
|
||||
// Comprobación de playing_state
|
||||
bool hasDied() const { return playing_state_ == PlayerState::DIED; }
|
||||
bool isCelebrating() const { return playing_state_ == PlayerState::CELEBRATING; }
|
||||
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
|
||||
bool isDying() const { return playing_state_ == PlayerState::DYING; }
|
||||
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
|
||||
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
|
||||
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
|
||||
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }
|
||||
bool isPlaying() const { return playing_state_ == PlayerState::PLAYING; }
|
||||
bool isWaiting() const { return playing_state_ == PlayerState::WAITING; }
|
||||
|
||||
// Obtiene el mando que usa para ser controlado
|
||||
int getController() const;
|
||||
// Getters
|
||||
bool canFire() const { return cooldown_ > 0 ? false : true; }
|
||||
bool hasExtraHit() const { return extra_hit_; }
|
||||
bool isCooling() { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; }
|
||||
bool IsEligibleForHighScore() { return score_ > options.game.hi_score_table.back().score; }
|
||||
bool isInvulnerable() const { return invulnerable_; }
|
||||
bool isPowerUp() const { return power_up_; }
|
||||
Circle &getCollider() { return collider_; }
|
||||
float getScoreMultiplier() const { return score_multiplier_; }
|
||||
int getCoffees() const { return coffees_; }
|
||||
int getContinueCounter() const { return continue_counter_; }
|
||||
int getController() const { return controller_index_; }
|
||||
int getHeight() const { return HEIGHT_; }
|
||||
int getId() const { return id_; }
|
||||
int getInvulnerableCounter() const { return invulnerable_counter_; }
|
||||
int getPosX() const { return static_cast<int>(pos_x_); }
|
||||
int getPosY() const { return pos_y_; }
|
||||
int getPowerUpCounter() const { return power_up_counter_; }
|
||||
std::string getRecordName() const { return enter_name_->getName(); }
|
||||
int getScore() const { return score_; }
|
||||
int getScoreBoardPanel() const { return scoreboard_panel_; }
|
||||
int getWidth() const { return WIDTH_; }
|
||||
PlayerState getPlayingState() const { return playing_state_; }
|
||||
std::string getName() const { return name_; }
|
||||
|
||||
// Obtiene el "id" del jugador
|
||||
int getId() const;
|
||||
// Setters
|
||||
void setController(int index) { controller_index_ = index; }
|
||||
void setFireCooldown(int time) { cooldown_ = time; }
|
||||
void setFiringState(PlayerState state) { firing_state_ = state; }
|
||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||
void setName(const std::string &name) { name_ = name; }
|
||||
void setPowerUpCounter(int value) { power_up_counter_ = value; }
|
||||
void setScore(int score) { score_ = score; }
|
||||
void setScoreBoardPanel(int panel) { scoreboard_panel_ = panel; }
|
||||
void setScoreMultiplier(float value) { score_multiplier_ = value; }
|
||||
void setWalkingState(PlayerState state) { walking_state_ = state; }
|
||||
};
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
#include <algorithm> // Para find_if
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <utility> // Para pair
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound
|
||||
#include "lang.h" // Para getText
|
||||
#include "screen.h" // Para Screen
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
#include "text.h" // Para Text, loadTextFile
|
||||
struct JA_Music_t; // lines 10-10
|
||||
struct JA_Sound_t; // lines 11-11
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Resource *Resource::resource_ = nullptr;
|
||||
@@ -31,6 +34,24 @@ Resource *Resource::get()
|
||||
|
||||
// Constructor
|
||||
Resource::Resource()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear()
|
||||
{
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
animations_.clear();
|
||||
demos_.clear();
|
||||
}
|
||||
|
||||
// Carga todos los recursos
|
||||
void Resource::load()
|
||||
{
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
@@ -40,17 +61,16 @@ Resource::Resource()
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
createText();
|
||||
createTextures();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Resource::~Resource()
|
||||
// Recarga todos los recursos
|
||||
void Resource::reload()
|
||||
{
|
||||
sounds_.clear();
|
||||
musics_.clear();
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
animations_.clear();
|
||||
clear();
|
||||
load();
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
@@ -113,6 +133,21 @@ std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != texts_.end())
|
||||
{
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Text no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
@@ -230,4 +265,100 @@ void Resource::addPalettes()
|
||||
|
||||
// Fuentes
|
||||
getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
|
||||
}
|
||||
|
||||
// Crea texturas
|
||||
void Resource::createTextures()
|
||||
{
|
||||
struct NameAndText
|
||||
{
|
||||
std::string name;
|
||||
std::string text;
|
||||
|
||||
// Constructor
|
||||
NameAndText(const std::string &name_init, const std::string &text_init)
|
||||
: name(name_init), text(text_init) {}
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXTURES" << std::endl;
|
||||
|
||||
// Tamaño normal
|
||||
std::vector<NameAndText> strings = {
|
||||
NameAndText("game_text_1000_points", "1.000"),
|
||||
NameAndText("game_text_2500_points", "2.500"),
|
||||
NameAndText("game_text_5000_points", "5.000"),
|
||||
NameAndText("game_text_powerup", lang::getText(117)),
|
||||
NameAndText("game_text_one_hit", lang::getText(118)),
|
||||
NameAndText("game_text_stop", lang::getText(119)),
|
||||
NameAndText("1000000_points", lang::getText(76))};
|
||||
|
||||
auto text = getText("04b_25");
|
||||
for (const auto &s : strings)
|
||||
{
|
||||
textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, 1, -2)));
|
||||
printWithDots("Texture : ", s.name, "[ DONE ]");
|
||||
}
|
||||
|
||||
// Tamaño doble
|
||||
std::vector<NameAndText> strings2X = {
|
||||
NameAndText("get_ready", lang::getText(75)),
|
||||
NameAndText("last_stage", lang::getText(79)),
|
||||
NameAndText("congratulations", lang::getText(50)),
|
||||
NameAndText("game_over", "Game Over")};
|
||||
|
||||
auto text2 = getText("04b_25_2x");
|
||||
for (const auto &s : strings2X)
|
||||
{
|
||||
textures_.emplace_back(ResourceTexture(s.name, text2->writeToTexture(s.text, 1, -4)));
|
||||
printWithDots("Texture : ", s.name, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Crea los objetos de texto
|
||||
void Resource::createText()
|
||||
{
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> resources = {
|
||||
{"04b_25", "04b_25.png"},
|
||||
{"04b_25_2x", "04b_25_2x.png"},
|
||||
{"8bithud", "8bithud.png"},
|
||||
{"nokia", "nokia.png"},
|
||||
{"smb2", "smb2.gif"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.first, std::make_shared<Text>(getTexture(resource.second), getTextFile(resource.first + ".txt"))));
|
||||
printWithDots("Text : ", resource.first, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Vacía el vector de sonidos
|
||||
void Resource::clearSounds()
|
||||
{
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
|
||||
for (auto &sound : sounds_)
|
||||
{
|
||||
if (sound.sound)
|
||||
{
|
||||
JA_DeleteSound(sound.sound);
|
||||
sound.sound = nullptr;
|
||||
}
|
||||
}
|
||||
sounds_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
|
||||
// Vacía el vector de musicas
|
||||
void Resource::clearMusics()
|
||||
{
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
|
||||
for (auto &music : musics_)
|
||||
{
|
||||
if (music.music)
|
||||
{
|
||||
JA_DeleteMusic(music.music);
|
||||
music.music = nullptr;
|
||||
}
|
||||
}
|
||||
musics_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
@@ -54,6 +54,17 @@ struct ResourceTextFile
|
||||
: name(name), text_file(text_file) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar objetos Text y su nombre
|
||||
struct ResourceText
|
||||
{
|
||||
std::string name; // Nombre del objeto
|
||||
std::shared_ptr<Text> text; // Objeto
|
||||
|
||||
// Constructor
|
||||
ResourceText(const std::string &name, std::shared_ptr<Text> text)
|
||||
: name(name), text(text) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation
|
||||
{
|
||||
@@ -75,6 +86,7 @@ private:
|
||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
|
||||
|
||||
@@ -99,13 +111,31 @@ private:
|
||||
// Añade paletas a las texturas
|
||||
void addPalettes();
|
||||
|
||||
// Crea texturas
|
||||
void createTextures();
|
||||
|
||||
// Crea los objetos de texto
|
||||
void createText();
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void clear();
|
||||
|
||||
// Carga todos los recursos
|
||||
void load();
|
||||
|
||||
// Vacía el vector de sonidos
|
||||
void clearSounds();
|
||||
|
||||
// Vacía el vector de musicas
|
||||
void clearMusics();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
Resource();
|
||||
|
||||
// Destructor
|
||||
~Resource();
|
||||
~Resource() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto resource con esta función estática
|
||||
@@ -129,9 +159,15 @@ public:
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> getText(const std::string &name);
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &getAnimation(const std::string &name);
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||
DemoData &getDemoData(int index);
|
||||
|
||||
// Recarga todos los recursos
|
||||
void reload();
|
||||
};
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text
|
||||
#include "enter_name.h"
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Scoreboard *Scoreboard::scoreboard_ = nullptr;
|
||||
@@ -37,7 +38,7 @@ Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_scoreboard_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt")))
|
||||
text_scoreboard_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
// Inicializa variables
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
@@ -119,76 +120,16 @@ void Scoreboard::render()
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setName(int panel_, const std::string &name_)
|
||||
void Scoreboard::setColor(Color color)
|
||||
{
|
||||
this->name_[panel_] = name_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setRecordName(int panel_, const std::string &record_name_)
|
||||
{
|
||||
this->record_name_[panel_] = record_name_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setSelectorPos(int panel_, int pos)
|
||||
{
|
||||
selector_pos_[panel_] = pos;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setScore(int panel_, int score_)
|
||||
{
|
||||
this->score_[panel_] = score_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setMult(int panel_, float mult_)
|
||||
{
|
||||
this->mult_[panel_] = mult_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setContinue(int panel_, int value)
|
||||
{
|
||||
continue_counter_[panel_] = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setStage(int stage_)
|
||||
{
|
||||
this->stage_ = stage_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setHiScore(int hi_score_)
|
||||
{
|
||||
this->hi_score_ = hi_score_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setPower(float power_)
|
||||
{
|
||||
this->power_ = power_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setHiScoreName(const std::string &name_)
|
||||
{
|
||||
hi_score_name_ = name_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setColor(Color color_)
|
||||
{
|
||||
this->color_ = color_;
|
||||
color_ = color;
|
||||
fillBackgroundTexture();
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Scoreboard::setPos(SDL_Rect rect_)
|
||||
void Scoreboard::setPos(SDL_Rect rect)
|
||||
{
|
||||
this->rect_ = rect_;
|
||||
rect_ = rect;
|
||||
|
||||
// Recalcula las anclas de los elementos
|
||||
recalculateAnchors();
|
||||
@@ -207,10 +148,10 @@ void Scoreboard::setPos(SDL_Rect rect_)
|
||||
void Scoreboard::fillPanelTextures()
|
||||
{
|
||||
// Guarda a donde apunta actualmente el renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
|
||||
// Genera el contenidoi de cada panel_
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
for (size_t i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
{
|
||||
// Cambia el destino del renderizador
|
||||
SDL_SetRenderTarget(renderer_, panel_texture_[i]);
|
||||
@@ -229,7 +170,7 @@ void Scoreboard::fillPanelTextures()
|
||||
|
||||
// MULT
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(55));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, std::to_string(mult_[i]).substr(0, 3));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, "x" + std::to_string(mult_[i]).substr(0, 3));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -288,7 +229,8 @@ void Scoreboard::fillPanelTextures()
|
||||
|
||||
// HI-SCORE
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(56));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, hi_score_name_ + " - " + updateScoreText(hi_score_));
|
||||
const std::string name = hi_score_name_ == "" ? "" : hi_score_name_ + " - ";
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y, name + updateScoreText(hi_score_));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -314,17 +256,9 @@ void Scoreboard::fillPanelTextures()
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106));
|
||||
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
SDL_SetRenderDrawColor(renderer_, 0xFF, 0xFF, 0xEB, 255);
|
||||
for (int j = 0; j < (int)record_name_[i].size(); ++j)
|
||||
for (size_t j = 0; j < record_name_[i].size(); ++j)
|
||||
{
|
||||
if (j == selector_pos_[i])
|
||||
{ // La letra seleccionada se pinta de forma intermitente
|
||||
if (counter_ % 3 > 0)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1));
|
||||
}
|
||||
}
|
||||
else
|
||||
if (j != selector_pos_[i] || counter_ % 3 == 0)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1));
|
||||
@@ -333,7 +267,18 @@ void Scoreboard::fillPanelTextures()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ScoreboardMode::GAME_COMPLETED:
|
||||
{
|
||||
// GAME OVER
|
||||
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
|
||||
|
||||
// SCORE
|
||||
if (counter_ % 10 < 8)
|
||||
{
|
||||
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(120));
|
||||
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[i]));
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -403,7 +348,7 @@ void Scoreboard::recalculateAnchors()
|
||||
slot4_4_ = {col, row4};
|
||||
|
||||
// Primer cuadrado para poner el nombre de record
|
||||
const int enterNameLenght = 8 * 7;
|
||||
const int enterNameLenght = NAME_LENGHT * 7;
|
||||
enter_name_pos_.x = (panelWidth - enterNameLenght) / 2;
|
||||
enter_name_pos_.y = row4;
|
||||
|
||||
@@ -415,12 +360,6 @@ void Scoreboard::recalculateAnchors()
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el modo del marcador
|
||||
void Scoreboard::setMode(int index, ScoreboardMode mode)
|
||||
{
|
||||
panel_[index].mode = mode;
|
||||
}
|
||||
|
||||
// Crea la textura de fondo
|
||||
void Scoreboard::createBackgroundTexture()
|
||||
{
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // para SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // para Uint32
|
||||
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
|
||||
#include <memory> // para unique_ptr, shared_ptr
|
||||
#include <string> // para string
|
||||
#include <vector> // para vector
|
||||
#include "utils.h" // para Color
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Texture, SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "utils.h" // Para Color
|
||||
class Sprite; // lines 11-11
|
||||
class Text; // lines 12-12
|
||||
class Texture; // lines 13-13
|
||||
|
||||
// Defines
|
||||
constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
||||
@@ -28,6 +29,7 @@ enum class ScoreboardMode : int
|
||||
GAME_OVER,
|
||||
DEMO,
|
||||
ENTER_NAME,
|
||||
GAME_COMPLETED,
|
||||
NUM_MODES,
|
||||
};
|
||||
|
||||
@@ -50,7 +52,7 @@ private:
|
||||
|
||||
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||
std::unique_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
std::shared_ptr<Text> text_scoreboard_; // Fuente para el marcador del juego
|
||||
|
||||
SDL_Texture *background_ = nullptr; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||
@@ -58,7 +60,7 @@ private:
|
||||
// Variables
|
||||
std::string name_[SCOREBOARD_MAX_PANELS] = {}; // Nom de cada jugador
|
||||
std::string record_name_[SCOREBOARD_MAX_PANELS] = {}; // Nombre introducido para la tabla de records
|
||||
int selector_pos_[SCOREBOARD_MAX_PANELS] = {}; // Posición del selector de letra para introducir el nombre
|
||||
size_t selector_pos_[SCOREBOARD_MAX_PANELS] = {}; // Posición del selector de letra para introducir el nombre
|
||||
int score_[SCOREBOARD_MAX_PANELS] = {}; // Puntuación de los jugadores
|
||||
float mult_[SCOREBOARD_MAX_PANELS] = {}; // Multiplicador de los jugadores
|
||||
int continue_counter_[SCOREBOARD_MAX_PANELS] = {}; // Tiempo para continuar de los jugadores
|
||||
@@ -124,42 +126,21 @@ public:
|
||||
// Pinta el marcador
|
||||
void render();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setName(int panel, const std::string &name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRecordName(int panel, const std::string &record_name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSelectorPos(int panel, int pos);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setScore(int panel, int score);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setMult(int panel, float mult);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setContinue(int panel, int score);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setStage(int stage);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHiScore(int hi_score);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPower(float power);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHiScoreName(const std::string &name);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setColor(Color color);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el modo del marcador
|
||||
void setMode(int index, ScoreboardMode mode);
|
||||
void setContinue(int panel, int continue_counter) { continue_counter_[panel] = continue_counter; }
|
||||
void setHiScore(int hi_score) { hi_score_ = hi_score; }
|
||||
void setHiScoreName(const std::string &name) { hi_score_name_ = name; }
|
||||
void setMode(int index, ScoreboardMode mode) { panel_[index].mode = mode; }
|
||||
void setMult(int panel, float mult) { mult_[panel] = mult; }
|
||||
void setName(int panel, const std::string &name) { name_[panel] = name; }
|
||||
void setPower(float power) { power_ = power; }
|
||||
void setRecordName(int panel, const std::string &record_name) { record_name_[panel] = record_name; }
|
||||
void setScore(int panel, int score) { score_[panel] = score; }
|
||||
void setSelectorPos(int panel, int pos) { selector_pos_[panel] = pos; }
|
||||
void setStage(int stage) { stage_ = stage; }
|
||||
};
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
#include <algorithm> // Para clamp, max, min
|
||||
#include <fstream> // Para basic_ifstream, ifstream
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <string> // Para allocator, operator+, to_string, char_t...
|
||||
#include <string> // Para allocator, operator+, char_traits, to_s...
|
||||
#include <vector> // Para vector
|
||||
#include "asset.h" // Para Asset
|
||||
#include "dbgtxt.h" // Para dbg_print
|
||||
#include "global_inputs.h" // Para service_pressed_counter
|
||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_RE...
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "on_screen_help.h" // Para OnScreenHelp
|
||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||
@@ -89,16 +88,16 @@ void Screen::blit()
|
||||
fps_counter_++;
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
doFlash();
|
||||
renderFlash();
|
||||
|
||||
// Atenua la pantalla
|
||||
doAttenuate();
|
||||
renderAttenuate();
|
||||
|
||||
// Muestra la ayuda por pantalla
|
||||
OnScreenHelp::get()->render();
|
||||
|
||||
// Muestra información por pantalla
|
||||
displayInfo();
|
||||
renderInfo();
|
||||
|
||||
// Muestra las notificaciones
|
||||
Notifier::get()->render();
|
||||
@@ -141,7 +140,7 @@ void Screen::blit()
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
if (shake_effect_.enabled)
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr); // Esta copia es para evitar que se vea negro por los laterales
|
||||
SDL_RenderCopy(renderer_, game_canvas_, &src_rect_, &dst_rect_);
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
@@ -201,7 +200,8 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
#ifndef NO_SHADERS
|
||||
std::ifstream f(Asset::get()->get("crtpi.glsl").c_str());
|
||||
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
shader::init(window_, shader_canvas_, source.c_str());
|
||||
@@ -210,7 +210,7 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
void Screen::toggleVideoMode()
|
||||
{
|
||||
options.video.mode = options.video.mode == ScreenVideoMode::WINDOW ? ScreenVideoMode::FULLSCREEN : ScreenVideoMode::WINDOW;
|
||||
setVideoMode(options.video.mode);
|
||||
@@ -255,77 +255,12 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
void Screen::update()
|
||||
{
|
||||
updateShakeEffect();
|
||||
updateFlash();
|
||||
Notifier::get()->update();
|
||||
updateFPS();
|
||||
OnScreenHelp::get()->update();
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Screen::checkInput()
|
||||
{
|
||||
#ifndef ARCADE
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
Notifier::get()->showText(mode + " mode");
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Comprueba el teclado para activar o desactivar los shaders
|
||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchShaders();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Comprueba el teclado para mostrar la información de debug
|
||||
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
show_info_ = !show_info_;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba los mandos para activar o desactivar los shaders
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
switchShaders();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba los mandos para mostrar la información de debug
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
show_info_ = !show_info_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Agita la pantalla
|
||||
void Screen::shake()
|
||||
{
|
||||
@@ -375,49 +310,51 @@ void Screen::updateShakeEffect()
|
||||
// Pone la pantalla de color
|
||||
void Screen::flash(Color color, int lenght)
|
||||
{
|
||||
flash_effect_.enabled = true;
|
||||
flash_effect_.counter = 0;
|
||||
flash_effect_.lenght = lenght;
|
||||
flash_effect_.color = color;
|
||||
flash_effect_ = FlashEffect(true, lenght, color);
|
||||
}
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void Screen::doFlash()
|
||||
void Screen::renderFlash()
|
||||
{
|
||||
if (flash_effect_.enabled)
|
||||
{
|
||||
// Dibuja el color del flash en la textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica del efecto
|
||||
flash_effect_.counter < flash_effect_.lenght ? flash_effect_.counter++ : flash_effect_.enabled = false;
|
||||
// Actualiza el efecto de flash
|
||||
void Screen::updateFlash()
|
||||
{
|
||||
if (flash_effect_.enabled)
|
||||
{
|
||||
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Atenua la pantalla
|
||||
void Screen::doAttenuate()
|
||||
void Screen::renderAttenuate()
|
||||
{
|
||||
if (attenuate_effect_)
|
||||
{
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 64);
|
||||
SDL_RenderFillRect(renderer_, nullptr);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Activa/desactiva los shaders
|
||||
void Screen::switchShaders()
|
||||
// Activa / desactiva los shaders
|
||||
void Screen::toggleShaders()
|
||||
{
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
const std::string value = options.video.shaders ? "on" : "off";
|
||||
Notifier::get()->showText("Shaders " + value);
|
||||
Notifier::get()->showText({"Shaders " + value});
|
||||
}
|
||||
|
||||
// Activa / desactiva la información de debug
|
||||
void Screen::toggleDebugInfo()
|
||||
{
|
||||
show_info_ = !show_info_;
|
||||
}
|
||||
|
||||
// Atenua la pantalla
|
||||
@@ -444,7 +381,7 @@ void Screen::updateFPS()
|
||||
}
|
||||
|
||||
// Muestra información por pantalla
|
||||
void Screen::displayInfo()
|
||||
void Screen::renderInfo()
|
||||
{
|
||||
if (show_info_)
|
||||
{
|
||||
@@ -456,7 +393,7 @@ void Screen::displayInfo()
|
||||
dbg_print(0, 0, info_resolution_.c_str(), 255, 255, 0);
|
||||
|
||||
// Contador de service_pressed_counter
|
||||
if (const int counter = globalInputs::service_pressed_counter[0]; counter > 0)
|
||||
if (const int counter = globalInputs::service_pressed_counter; counter > 0)
|
||||
dbg_print(0, 8, std::to_string(counter).c_str(), 255, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
int fps_ = 0; // Frames calculados en el último segundo
|
||||
std::string info_resolution_; // Texto con la informacion de la pantalla
|
||||
#ifdef DEBUG
|
||||
bool show_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||
bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||
#else
|
||||
bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||
#endif
|
||||
@@ -52,12 +52,11 @@ private:
|
||||
{
|
||||
bool enabled; // Indica si el efecto está activo
|
||||
int counter; // Contador para el efecto
|
||||
int lenght; // Duración del efecto
|
||||
Color color; // Color del efecto
|
||||
|
||||
// Constructor
|
||||
explicit FlashEffect(bool en = false, int cnt = 0, int len = 0, Color col = Color(0xFF, 0xFF, 0xFF))
|
||||
: enabled(en), counter(cnt), lenght(len), color(col) {}
|
||||
explicit FlashEffect(bool en = false, int cnt = 0, Color col = Color(0xFF, 0xFF, 0xFF))
|
||||
: enabled(en), counter(cnt), color(col) {}
|
||||
};
|
||||
|
||||
struct ShakeEffect
|
||||
@@ -83,17 +82,20 @@ private:
|
||||
// Actualiza la logica para agitar la pantalla
|
||||
void updateShakeEffect();
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void doFlash();
|
||||
// Dibuja el efecto de flash en la pantalla
|
||||
void renderFlash();
|
||||
|
||||
// Actualiza el efecto de flash
|
||||
void updateFlash();
|
||||
|
||||
// Atenua la pantalla
|
||||
void doAttenuate();
|
||||
void renderAttenuate();
|
||||
|
||||
// Calcula los frames por segundo
|
||||
void updateFPS();
|
||||
|
||||
// Muestra información por pantalla
|
||||
void displayInfo();
|
||||
void renderInfo();
|
||||
|
||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||
SDL_Point getNewPosition();
|
||||
@@ -119,9 +121,6 @@ public:
|
||||
// Actualiza la lógica de la clase
|
||||
void update();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Limpia la pantalla
|
||||
void clean(Color color = Color(0x00, 0x00, 0x00));
|
||||
|
||||
@@ -134,8 +133,8 @@ public:
|
||||
// Establece el modo de video
|
||||
void setVideoMode(ScreenVideoMode video_mode);
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void switchVideoMode();
|
||||
// Cambia entre pantalla completa y ventana
|
||||
void toggleVideoMode();
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void setWindowSize(int size);
|
||||
@@ -158,8 +157,11 @@ public:
|
||||
// Pone la pantalla de color
|
||||
void flash(Color color, int lenght);
|
||||
|
||||
// Activa/desactiva los shaders
|
||||
void switchShaders();
|
||||
// Activa / desactiva los shaders
|
||||
void toggleShaders();
|
||||
|
||||
// Activa / desactiva la información de debug
|
||||
void toggleDebugInfo();
|
||||
|
||||
// Atenua la pantalla
|
||||
void attenuate(bool value);
|
||||
|
||||
@@ -4,4 +4,5 @@ namespace section
|
||||
{
|
||||
Name name;
|
||||
Options options;
|
||||
AttractMode attract_mode;
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace section
|
||||
HI_SCORE_TABLE = 5,
|
||||
GAME_DEMO = 6,
|
||||
INSTRUCTIONS = 7,
|
||||
QUIT = 8,
|
||||
CREDITS = 8,
|
||||
QUIT = 9,
|
||||
};
|
||||
|
||||
// Opciones para la sección
|
||||
@@ -26,9 +27,18 @@ namespace section
|
||||
QUIT_WITH_KEYBOARD = 4,
|
||||
QUIT_WITH_CONTROLLER = 5,
|
||||
QUIT_FROM_EVENT = 6,
|
||||
NONE = 7,
|
||||
RELOAD = 7,
|
||||
NONE = 8,
|
||||
};
|
||||
|
||||
// Variables para el Attract Mode
|
||||
enum class AttractMode
|
||||
{
|
||||
TITLE_TO_DEMO,
|
||||
TITLE_TO_LOGO,
|
||||
};
|
||||
|
||||
extern Name name;
|
||||
extern Options options;
|
||||
extern AttractMode attract_mode;
|
||||
}
|
||||
@@ -19,31 +19,7 @@ Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_);
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getX() const
|
||||
{
|
||||
return pos_.x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getY() const
|
||||
{
|
||||
return pos_.y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth() const
|
||||
{
|
||||
return pos_.w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight() const
|
||||
{
|
||||
return pos_.h;
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
@@ -60,84 +36,6 @@ void Sprite::setPosition(SDL_Point p)
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPosition(SDL_Rect r)
|
||||
{
|
||||
pos_ = r;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setX(int x)
|
||||
{
|
||||
pos_.x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setY(int y)
|
||||
{
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
pos_.w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
pos_.h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip() const
|
||||
{
|
||||
return sprite_clip_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
sprite_clip_ = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
sprite_clip_ = (SDL_Rect){x, y, w, h};
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
std::shared_ptr<Texture> Sprite::getTexture() const
|
||||
{
|
||||
return texture_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
texture_ = texture;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getPosition() const
|
||||
{
|
||||
return pos_;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incX(int value)
|
||||
{
|
||||
pos_.x += value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incY(int value)
|
||||
{
|
||||
pos_.y += value;
|
||||
}
|
||||
|
||||
// Reinicia las variables a cero
|
||||
void Sprite::clear()
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ protected:
|
||||
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
|
||||
SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
double zoom_ = 1.0f; // Zoom aplicado a la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -28,40 +29,43 @@ public:
|
||||
// Reinicia las variables a cero
|
||||
virtual void clear();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getX() const;
|
||||
int getY() const;
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
// Obtiene la posición y el tamaño
|
||||
int getX() const { return pos_.x; }
|
||||
int getY() const { return pos_.y; }
|
||||
int getWidth() const { return pos_.w; }
|
||||
int getHeight() const { return pos_.h; }
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getPosition() const;
|
||||
SDL_Rect getPosition() const { return pos_; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setX(int x);
|
||||
void setY(int y);
|
||||
void setWidth(int w);
|
||||
void setHeight(int h);
|
||||
// Establece la posición y el tamaño
|
||||
void setX(int x) { pos_.x = x; }
|
||||
void setY(int y) { pos_.y = y; }
|
||||
void setWidth(int w) { pos_.w = w; }
|
||||
void setHeight(int h) { pos_.h = h; }
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(SDL_Point p);
|
||||
void setPosition(SDL_Rect r);
|
||||
void setPosition(SDL_Rect r) { pos_ = r; }
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incX(int value);
|
||||
void incY(int value);
|
||||
// Establece el nivel de zoom
|
||||
void setZoom(float zoom) { zoom_ = zoom; }
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip() const;
|
||||
// Aumenta o disminuye la posición
|
||||
void incX(int value) { pos_.x += value; }
|
||||
void incY(int value) { pos_.y += value; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
// Obtiene el rectangulo que se dibuja de la textura
|
||||
SDL_Rect getSpriteClip() const { return sprite_clip_; }
|
||||
|
||||
// Obten el valor de la variable
|
||||
std::shared_ptr<Texture> getTexture() const;
|
||||
// Establece el rectangulo que se dibuja de la textura
|
||||
void setSpriteClip(SDL_Rect rect) { sprite_clip_ = rect; }
|
||||
void setSpriteClip(int x, int y, int w, int h) { sprite_clip_ = (SDL_Rect){x, y, w, h}; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(std::shared_ptr<Texture> texture);
|
||||
// Obtiene un puntero a la textura
|
||||
std::shared_ptr<Texture> getTexture() const { return texture_; }
|
||||
|
||||
// Establece la textura a utilizar
|
||||
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
|
||||
};
|
||||
41
source/stage.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "stage.h"
|
||||
#include <algorithm> // Para min
|
||||
#include <vector> // Para vector
|
||||
|
||||
namespace Stage
|
||||
{
|
||||
|
||||
std::vector<Stage> stages; // Variable con los datos de cada pantalla
|
||||
int power = 0; // Poder acumulado en la fase
|
||||
int total_power = 0; // Poder total necesario para completar el juego
|
||||
int number = 0; // Fase actual
|
||||
|
||||
// Devuelve una fase
|
||||
Stage get(int index) { return stages.at(std::min(9, index)); }
|
||||
|
||||
// Inicializa las variables del namespace Stage
|
||||
void init()
|
||||
{
|
||||
stages.emplace_back(Stage(200, 7 + (4 * 1), 7 + (4 * 3)));
|
||||
stages.emplace_back(Stage(300, 7 + (4 * 2), 7 + (4 * 4)));
|
||||
stages.emplace_back(Stage(600, 7 + (4 * 3), 7 + (4 * 5)));
|
||||
stages.emplace_back(Stage(600, 7 + (4 * 3), 7 + (4 * 5)));
|
||||
stages.emplace_back(Stage(600, 7 + (4 * 4), 7 + (4 * 6)));
|
||||
stages.emplace_back(Stage(600, 7 + (4 * 4), 7 + (4 * 6)));
|
||||
stages.emplace_back(Stage(650, 7 + (4 * 5), 7 + (4 * 7)));
|
||||
stages.emplace_back(Stage(750, 7 + (4 * 5), 7 + (4 * 7)));
|
||||
stages.emplace_back(Stage(850, 7 + (4 * 6), 7 + (4 * 8)));
|
||||
stages.emplace_back(Stage(950, 7 + (4 * 7), 7 + (4 * 10)));
|
||||
|
||||
power = 0;
|
||||
total_power = 0;
|
||||
number = 0;
|
||||
}
|
||||
|
||||
// Añade poder
|
||||
void addPower(int amount)
|
||||
{
|
||||
power += amount;
|
||||
total_power += amount;
|
||||
}
|
||||
}
|
||||
31
source/stage.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Stage
|
||||
{
|
||||
struct Stage
|
||||
{
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
|
||||
// Constructor
|
||||
Stage(int power_to_complete, int min_menace, int max_menace)
|
||||
: power_to_complete(power_to_complete), min_menace(min_menace), max_menace(max_menace) {}
|
||||
};
|
||||
|
||||
extern std::vector<Stage> stages; // Variable con los datos de cada pantalla
|
||||
extern int power; // Poder acumulado en la fase
|
||||
extern int total_power; // Poder total necesario para completar el juego
|
||||
extern int number; // Fase actual
|
||||
|
||||
// Devuelve una fase
|
||||
Stage get(int index);
|
||||
|
||||
// Inicializa las variables del namespace Stage
|
||||
void init();
|
||||
|
||||
// Añade poder
|
||||
void addPower(int amount);
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
#include "text.h"
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <fstream> // Para basic_ifstream, basic_istream, basic_ostream
|
||||
#include <iostream> // Para cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, getFileName, printWithDots
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_TEXTUREACCESS_TARGET
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_ifstream, basic_istream, basic...
|
||||
#include <iostream> // Para cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, getFileName, printWithDots
|
||||
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||
@@ -45,9 +50,7 @@ std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
{
|
||||
tf->offset[index++].w = std::stoi(buffer);
|
||||
}
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
@@ -122,26 +125,52 @@ Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
{
|
||||
auto shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
if (lenght == -1)
|
||||
{
|
||||
lenght = text.length();
|
||||
}
|
||||
|
||||
sprite_->setY(y);
|
||||
const auto width = sprite_->getWidth();
|
||||
const auto height = sprite_->getHeight();
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
const auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
||||
auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, box_width_, box_height_);
|
||||
sprite_->setX(x + shift);
|
||||
sprite_->render();
|
||||
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
||||
shift += offset_[static_cast<int>(text[i])].w + kerning;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write2X(int x, int y, const std::string &text, int kerning)
|
||||
{
|
||||
int shift = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i)
|
||||
{
|
||||
auto index = static_cast<size_t>(text[i]);
|
||||
SDL_Rect rect = {offset_[index].x, offset_[index].y, box_width_, box_height_};
|
||||
sprite_->getTexture()->render(x + shift, y, &rect, 2.0f, 2.0f);
|
||||
shift += (offset_[index].w + kerning) * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en una textura
|
||||
std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int zoom, int kerning)
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = lenght(text, kerning) * zoom;
|
||||
auto height = box_height_ * zoom;
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
||||
{
|
||||
@@ -211,12 +240,9 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int Text::lenght(const std::string &text, int kerning) const
|
||||
{
|
||||
auto shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); ++i)
|
||||
{
|
||||
shift += (offset_[int(text[i])].w + kerning);
|
||||
}
|
||||
int shift = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i)
|
||||
shift += (offset_[static_cast<int>(text[i])].w + kerning);
|
||||
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
@@ -238,4 +264,13 @@ void Text::reLoadTexture()
|
||||
void Text::setFixedWidth(bool value)
|
||||
{
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Establece una paleta
|
||||
void Text::setPalette(int number)
|
||||
{
|
||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
sprite_->getTexture()->setPalette(number);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
}
|
||||
@@ -50,6 +50,10 @@ public:
|
||||
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
||||
void write2X(int x, int y, const std::string &text, int kerning = 1);
|
||||
|
||||
// Escribe el texto en una textura
|
||||
std::shared_ptr<Texture> writeToTexture(const std::string &text, int zoom = 1, int kerning = 1);
|
||||
|
||||
// Escribe el texto con colores
|
||||
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
||||
@@ -74,4 +78,7 @@ public:
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void setFixedWidth(bool value);
|
||||
|
||||
// Establece una paleta
|
||||
void setPalette(int number);
|
||||
};
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
|
||||
#include <fcntl.h> // Para SEEK_END, SEEK_SET
|
||||
#include <stdio.h> // Para fseek, fclose, fopen, fread, ftell, FILE
|
||||
#include <stdlib.h> // Para free, malloc
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
||||
#include <iostream> // Para cerr, cout
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string> // Para char_traits, operator<<, operator+
|
||||
#include <vector> // Para vector
|
||||
#include "gif.c" // Para LoadGif, LoadPalette
|
||||
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
|
||||
#include "utils.h" // Para getFileName, printWithDots
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
@@ -60,6 +60,9 @@ Texture::~Texture()
|
||||
// Carga una imagen desde un fichero
|
||||
bool Texture::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
if (file_path.empty())
|
||||
return false;
|
||||
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);
|
||||
@@ -187,8 +190,16 @@ void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, dou
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
// Calcula el zoom y las coordenadas
|
||||
if (zoomH != 1.0f || zoomW != 1.0f)
|
||||
{
|
||||
renderQuad.x = renderQuad.x + (renderQuad.w / 2);
|
||||
renderQuad.y = renderQuad.y + (renderQuad.h / 2);
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
renderQuad.x = renderQuad.x - (renderQuad.w / 2);
|
||||
renderQuad.y = renderQuad.y - (renderQuad.h / 2);
|
||||
}
|
||||
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer_, texture_, clip, &renderQuad, angle, center, flip);
|
||||
@@ -312,8 +323,8 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
|
||||
{
|
||||
std::vector<Uint32> palette;
|
||||
|
||||
FILE *f = fopen(file_path.c_str(), "rb");
|
||||
if (!f)
|
||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << std::endl;
|
||||
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
||||
@@ -323,21 +334,22 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
|
||||
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
Uint8 *buffer = static_cast<Uint8 *>(malloc(size));
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
auto size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
const auto *pal = LoadPalette(buffer);
|
||||
std::vector<Uint8> buffer(size);
|
||||
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||
{
|
||||
std::cerr << "Error: No se pudo leer completamente el fichero " << getFileName(file_path) << std::endl;
|
||||
throw std::runtime_error("Error al leer el fichero: " + getFileName(file_path));
|
||||
}
|
||||
|
||||
const auto pal = LoadPalette(buffer.data());
|
||||
if (!pal)
|
||||
{
|
||||
return palette;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
palette.push_back((pal[i] << 8) + 255);
|
||||
|
||||
169
source/title.cpp
@@ -1,10 +1,10 @@
|
||||
#include "title.h"
|
||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3
|
||||
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <string> // Para char_traits, operator+, to_string, bas...
|
||||
#include <utility> // Para move
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <string> // Para char_traits, operator+, basic_string
|
||||
#include <vector> // Para vector
|
||||
#include "define_buttons.h" // Para DefineButtons
|
||||
#include "fade.h" // Para Fade, FadeType
|
||||
@@ -18,27 +18,26 @@
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Options, options, name, Name
|
||||
#include "section.h" // Para Options, options, Name, name, AttractMode
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "text.h" // Para TEXT_CENTER, TEXT_SHADOW, Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
: text1_(std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"))),
|
||||
text2_(std::make_unique<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))),
|
||||
: text_(Resource::get()->getText("smb2")),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM)),
|
||||
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
|
||||
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
|
||||
mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())),
|
||||
define_buttons_(std::make_unique<DefineButtons>(std::move(text2_))),
|
||||
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
|
||||
define_buttons_(std::make_unique<DefineButtons>()),
|
||||
num_controllers_(Input::get()->getNumControllers())
|
||||
{
|
||||
// Configura objetos
|
||||
game_logo_->enable();
|
||||
mini_logo_sprite_->setX(param.game.game_area.center_x - mini_logo_sprite_->getWidth() / 2);
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
@@ -46,6 +45,9 @@ Title::Title()
|
||||
|
||||
// Asigna valores a otras variables
|
||||
section::options = section::Options::TITLE_1;
|
||||
const bool is_title_to_demo = (section::attract_mode == section::AttractMode::TITLE_TO_DEMO);
|
||||
next_section_ = is_title_to_demo ? section::Name::GAME_DEMO : section::Name::LOGO;
|
||||
section::attract_mode = is_title_to_demo ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -67,7 +69,10 @@ void Title::update()
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Comprueba el fade_ y si se ha acabado
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Comprueba el fundido y si se ha acabado
|
||||
fade_->update();
|
||||
if (fade_->hasEnded())
|
||||
{
|
||||
@@ -142,7 +147,7 @@ void Title::render()
|
||||
// 'PRESS TO PLAY'
|
||||
if (counter_ % 50 > 14 && !define_buttons_->isEnabled())
|
||||
{
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Mini logo
|
||||
@@ -152,7 +157,7 @@ void Title::render()
|
||||
mini_logo_sprite_->render();
|
||||
|
||||
// Texto con el copyright
|
||||
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
|
||||
}
|
||||
|
||||
// Define Buttons
|
||||
@@ -168,11 +173,13 @@ void Title::render()
|
||||
// Comprueba los eventos
|
||||
void Title::checkEvents()
|
||||
{
|
||||
// Comprueba el input para el resto de objetos
|
||||
define_buttons_->checkEvents();
|
||||
|
||||
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
SDL_Event event;
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
@@ -193,26 +200,36 @@ void Title::checkEvents()
|
||||
{
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_1:
|
||||
case SDLK_1: // Redefine los botones del mando #0
|
||||
{
|
||||
if (define_buttons_->enable(0))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_2:
|
||||
case SDLK_2: // Redefine los botones del mando #1
|
||||
{
|
||||
if (define_buttons_->enable(1))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_3:
|
||||
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
||||
{
|
||||
swapControllers();
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
case SDLK_4: // Intercambia la asignación del teclado
|
||||
{
|
||||
swapKeyboard();
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
case SDLK_5: // Muestra la asignacion de mandos y teclado
|
||||
{
|
||||
showControllers();
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -227,54 +244,38 @@ void Title::checkInput()
|
||||
// Comprueba los controladores solo si no se estan definiendo los botones
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
// Comprueba el teclado para empezar a jugar
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
// Comprueba los métodos de control
|
||||
for (const auto &controller : options.controllers)
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
!Input::get()->checkInput(InputType::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[0].player_id;
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = controller.player_id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los mandos
|
||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||
{
|
||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
swapControllers();
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba si algun mando quiere ser configurado
|
||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||
{
|
||||
define_buttons_->enable(i);
|
||||
define_buttons_->enable(controller.index);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comprueba el botón de START de los mandos
|
||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
// Si no está el botón de servicio activo
|
||||
if (!Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[i].player_id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
Screen::get()->checkInput();
|
||||
define_buttons_->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
}
|
||||
@@ -299,50 +300,52 @@ void Title::reLoadTextures()
|
||||
}
|
||||
|
||||
// Reinicia el contador interno
|
||||
void Title::resetCounter()
|
||||
{
|
||||
counter_ = 0;
|
||||
}
|
||||
void Title::resetCounter() { counter_ = 0; }
|
||||
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void Title::swapControllers()
|
||||
{
|
||||
const auto num_controllers = Input::get()->getNumControllers();
|
||||
|
||||
if (num_controllers == 0)
|
||||
{
|
||||
if (Input::get()->getNumControllers() == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
define_buttons_->swapControllers();
|
||||
swapOptionsControllers();
|
||||
showControllers();
|
||||
}
|
||||
|
||||
// Crea cadenas de texto vacias para un numero máximo de mandos
|
||||
constexpr int MAX_CONTROLLERS = 2;
|
||||
std::string text[MAX_CONTROLLERS];
|
||||
int playerControllerIndex[MAX_CONTROLLERS];
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
// Intercambia el teclado de jugador
|
||||
void Title::swapKeyboard()
|
||||
{
|
||||
swapOptionsKeyboard();
|
||||
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
|
||||
Notifier::get()->showText({text});
|
||||
}
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void Title::showControllers()
|
||||
{
|
||||
// Crea vectores de texto vacíos para un número máximo de mandos
|
||||
constexpr size_t NUM_CONTROLLERS = 2;
|
||||
std::vector<std::string> text(NUM_CONTROLLERS);
|
||||
std::vector<int> playerControllerIndex(NUM_CONTROLLERS, -1);
|
||||
|
||||
// Obtiene de cada jugador el índice del mando que tiene asignado
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
text[i].clear();
|
||||
playerControllerIndex[i] = -1;
|
||||
}
|
||||
|
||||
// Obtiene para cada jugador el índice del mando correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
{
|
||||
playerControllerIndex[options.controller[i].player_id - 1] = i;
|
||||
// Ejemplo: el jugador 1 tiene el mando 2
|
||||
playerControllerIndex.at(options.controllers.at(i).player_id - 1) = i;
|
||||
}
|
||||
|
||||
// Genera el texto correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
const int index = playerControllerIndex[i];
|
||||
if (options.controller[index].plugged)
|
||||
const size_t index = playerControllerIndex.at(i);
|
||||
if (options.controllers.at(index).plugged)
|
||||
{
|
||||
text[i] = lang::getText(101) + std::to_string(i + 1) + ": " + options.controller[index].name;
|
||||
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controllers.at(index).name;
|
||||
}
|
||||
}
|
||||
|
||||
Notifier::get()->showText(text[0], text[1]);
|
||||
|
||||
resetCounter();
|
||||
}
|
||||
// std::string spaces(lang::getText(100).length() + 3, ' ');
|
||||
// std::string kb_text = spaces + lang::getText(69);
|
||||
Notifier::get()->showText({text.at(0), text.at(1)});
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include "section.h" // Para Name
|
||||
class DefineButtons;
|
||||
class Fade;
|
||||
class GameLogo;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture; // lines 14-14
|
||||
class TiledBG;
|
||||
class DefineButtons; // lines 6-6
|
||||
class Fade; // lines 7-7
|
||||
class GameLogo; // lines 8-8
|
||||
class Sprite; // lines 9-9
|
||||
class Text; // lines 10-10
|
||||
class Texture; // lines 11-11
|
||||
class TiledBG; // lines 12-12
|
||||
namespace section
|
||||
{
|
||||
enum class Name;
|
||||
}
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||
@@ -37,21 +40,19 @@ class Title
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Text> text1_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::shared_ptr<Text> text_; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
|
||||
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||
std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
|
||||
std::unique_ptr<Sprite> mini_logo_sprite_; // Sprite con el logo de JailGames mini
|
||||
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
||||
|
||||
// Variable
|
||||
int counter_ = 0; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
section::Name next_section_ = section::Name::GAME_DEMO; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
int post_fade_ = 0; // Opción a realizar cuando termina el fundido
|
||||
int num_controllers_; // Número de mandos conectados
|
||||
int counter_ = 0; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
int post_fade_ = 0; // Opción a realizar cuando termina el fundido
|
||||
int num_controllers_; // Número de mandos conectados
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
@@ -74,6 +75,12 @@ private:
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void swapControllers();
|
||||
|
||||
// Intercambia el teclado de jugador
|
||||
void swapKeyboard();
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void showControllers();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title();
|
||||
|
||||