Compare commits
203 Commits
eb9eaec61d
...
2024-10-14
| Author | SHA1 | Date | |
|---|---|---|---|
| 9825c7fb9b | |||
| d0a6e4c572 | |||
| 7c876e1d4d | |||
| 809c10048e | |||
| babf02226c | |||
| 46540ad7c3 | |||
| ba7c44ad06 | |||
| 46b19ee82f | |||
| b2122ac239 | |||
| c11a868289 | |||
| 22d457285d | |||
| b060f21696 | |||
| 33ea8d90ca | |||
| cce14dba4d | |||
| 101e375fd3 | |||
| 4ef759772a | |||
| 07714aabc3 | |||
| d50cf23721 | |||
| 3a6950f3a4 | |||
| a9ca23138d | |||
| e1fa1d2102 | |||
| 117b80bdfc | |||
| d6c3c89872 | |||
| 9e5f41644e | |||
| fc8fdc5fe5 | |||
| 6fe294c59d | |||
| 3fa5b227ae | |||
| f2fa216b0d | |||
| 3c1dcad3ab | |||
| bd3aa0bb06 | |||
| 3e3d764b25 | |||
| c00f4326ae | |||
| 9ce0f16d33 | |||
| 06a4f439c1 | |||
| 9d41d14d68 | |||
| 0d0e49316f | |||
| bf945ef14b | |||
| 0330fe6b74 | |||
| 6305a67c84 | |||
| 5f18189269 | |||
| 7ebefd7b54 | |||
| cffa4c3c92 | |||
| 4f0ea9dcf2 | |||
| b1f936a791 | |||
| 1c0554d4df | |||
| 8ba77d7d5d | |||
| 6515ec6c7b | |||
| b979c0f2b8 | |||
| a95e5077e3 | |||
| 6ea6f85e3e | |||
| fe6e63e39f | |||
| afe092c742 | |||
| 25a2753b13 | |||
| ee721ff573 | |||
| c07fd62037 | |||
| fb74733f2c | |||
| 468bd0950c | |||
| 938e4ad011 | |||
| 71bd3bed52 | |||
| 5ebc58dd01 | |||
| 9b3e549876 | |||
| abc8a0b632 | |||
| 3a84ea792c | |||
| 3cabd5c675 | |||
| 2ec242b2c9 | |||
| d993a6def4 | |||
| 5913d7548a | |||
| 84f3952232 | |||
| 7dbddd5524 | |||
| dee5bcb4e4 | |||
| af1c1051e6 | |||
| aaf6dc29a1 | |||
| 0af441b5df | |||
| 6acf0b7efc | |||
| e033fc8015 | |||
| 2d5859b1c4 | |||
| edc45b6cec | |||
| fad6cddfb6 | |||
| 8ce09d1355 | |||
| 945eaa68e7 | |||
| 28df97ea94 | |||
| ac3340c39f | |||
| 4febe8b7c0 | |||
| 289d01b0fa | |||
| 2767696a3f | |||
| fa82758ce1 | |||
| 878518babe | |||
| 3f24f38a0c | |||
| 1f6dfe5d92 | |||
| 92f7f540c0 | |||
| f2cc0dc352 | |||
| 8d263931b2 | |||
| 0a8d0479a0 | |||
| 20de9e4b72 | |||
| 0de9188547 | |||
| 9d7e975952 | |||
| 46b41757b2 | |||
| c1bf0b8aed | |||
| 5ca4ee0bb8 | |||
| 05e3fddb8f | |||
| 69027f96e6 | |||
| 6ad1bca29f | |||
| 2f152915ed | |||
| 998b151c00 | |||
| 0cd14aa320 | |||
| 159a75a60e | |||
| 80425a5ed0 | |||
| a00c2284b6 | |||
| 75f9d3f5cb | |||
| 85a082d738 | |||
| b6c5d06246 | |||
| 891d5a8f5e | |||
| 333c905b1a | |||
| 41e57064cb | |||
| 7ef75184a5 | |||
| c40c59275a | |||
| 8fc217f0e3 | |||
| 04935c652d | |||
| a435e3ed8c | |||
| 41c3e1f32c | |||
| 3d41da0fdf | |||
| ecf34558f4 | |||
| 1e2f121d82 | |||
| c93e824f86 | |||
| 762a819711 | |||
| a5060b928f | |||
| 2398e4136b | |||
| b3b932edfc | |||
| 443cc6da8d | |||
| 46cdc2189e | |||
| f071b60212 | |||
| 824bc08077 | |||
| e1fb069010 | |||
| b114d75c69 | |||
| 8465ee87fb | |||
| 83fb2f30ba | |||
| 922d146781 | |||
| 1b2d1c5786 | |||
| 7e1085ea42 | |||
| d4417d67d5 | |||
| 14af141d8f | |||
| 870a83d688 | |||
| 54a0d6c448 | |||
| c50d8a8bec | |||
| ad8c16f834 | |||
| cc15b8afd1 | |||
| 770f0eb046 | |||
| 62b1ba84ac | |||
| c5bab7019c | |||
| b3d9b72d1d | |||
| ccfd864eab | |||
| f5b866b8c5 | |||
| 1b160c0584 | |||
| c72dfe5876 | |||
| 548976c955 | |||
| 2a303deff1 | |||
| fa76520c6d | |||
| f57a307991 | |||
| 4f6c92c8d1 | |||
| 1d847eae9f | |||
| 48d876bcf1 | |||
| d16c8239c4 | |||
| 50b1acfe8b | |||
| 60cfc1e4d9 | |||
| 0ed0a5c6b5 | |||
| 5ea41d4fc7 | |||
| 982094264a | |||
| 7a3c2ffe71 | |||
| 49cffb3669 | |||
| 149e422489 | |||
| 4c2528ba93 | |||
| 65b8988ba2 | |||
| c7cc5df920 | |||
| 89979a8ddb | |||
| 7d778a9cfa | |||
| 9012e3d79d | |||
| b09f07ef40 | |||
| 448da70ba8 | |||
| 24b4eaa972 | |||
| 59da8fd4c6 | |||
| f64b461d75 | |||
| b9a15bd8b4 | |||
| 924fd375ff | |||
| e50e7affb3 | |||
| 032c5e7129 | |||
| 1839df142d | |||
| 35749f7c1b | |||
| e48dbb2d4e | |||
| 7e60a742ca | |||
| 5c7bb842ec | |||
| 6a9d0d1b2c | |||
| f8b6d0524d | |||
| 90706d5d0c | |||
| c246472098 | |||
| 45ed1106cb | |||
| a5a3bb23da | |||
| 054950f1d8 | |||
| ba8e068b80 | |||
| 3f3242393e | |||
| a2ce1f0dc3 | |||
| 887e8a7071 | |||
| 7ed0393a9b | |||
| e51e3a5c43 |
2
.gitignore
vendored
@@ -14,3 +14,5 @@ thumbs.db
|
|||||||
*config.bin
|
*config.bin
|
||||||
*score.bin
|
*score.bin
|
||||||
coffee_crisis*
|
coffee_crisis*
|
||||||
|
debug.txt
|
||||||
|
cppcheck-result*
|
||||||
37
Makefile
@@ -24,17 +24,18 @@ INCLUDES:= -I$(DIR_SOURCES)
|
|||||||
# Variables según el sistema operativo
|
# Variables según el sistema operativo
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
FixPath = $(subst /,\,$1)
|
FixPath = $(subst /,\,$1)
|
||||||
SOURCES := source/*.cpp source/common/*.cpp
|
SOURCES := source/*.cpp
|
||||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||||
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
||||||
RM = del /Q
|
RM = del /Q
|
||||||
MKD:= mkdir
|
MKD:= mkdir
|
||||||
else
|
else
|
||||||
FixPath = $1
|
FixPath = $1
|
||||||
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
|
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
|
||||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections
|
SOURCES := source/*.cpp
|
||||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections
|
||||||
|
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||||
LDFLAGS := -lSDL2
|
LDFLAGS := -lSDL2
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
MKD:= mkdir -p
|
MKD:= mkdir -p
|
||||||
@@ -120,13 +121,12 @@ print-variables:
|
|||||||
|
|
||||||
@echo RM: $(RM)
|
@echo RM: $(RM)
|
||||||
|
|
||||||
raspi3:
|
raspi:
|
||||||
$(CXX) $(SOURCES) -D NO_SHADERS -D VERBOSE $(CXXFLAGS) -lSDL2 -o $(TARGET_FILE)
|
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
||||||
|
|
||||||
raspi5:
|
raspi_debug:
|
||||||
$(CXX) $(SOURCES) -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE -D DEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
||||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
@echo off
|
||||||
@@ -225,7 +225,6 @@ linux:
|
|||||||
|
|
||||||
linux_debug:
|
linux_debug:
|
||||||
$(CXX) $(SOURCES) -D DEBUG -D VERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
$(CXX) $(SOURCES) -D DEBUG -D VERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
||||||
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)_debug" --strip-unneeded
|
|
||||||
|
|
||||||
linux_release:
|
linux_release:
|
||||||
# Elimina carpetas previas
|
# Elimina carpetas previas
|
||||||
@@ -248,4 +247,18 @@ linux_release:
|
|||||||
cd "$(RELEASE_FOLDER)" && tar -czvf "../$(LINUX_RELEASE)" *
|
cd "$(RELEASE_FOLDER)" && tar -czvf "../$(LINUX_RELEASE)" *
|
||||||
|
|
||||||
# Elimina la carpeta temporal
|
# Elimina la carpeta temporal
|
||||||
$(RM) "$(RELEASE_FOLDER)"
|
$(RM) "$(RELEASE_FOLDER)"
|
||||||
|
|
||||||
|
anbernic:
|
||||||
|
# Elimina carpetas previas
|
||||||
|
$(RM) "$(RELEASE_FOLDER)"_anbernic
|
||||||
|
|
||||||
|
# Crea la carpeta temporal para realizar el lanzamiento
|
||||||
|
mkdir -p "$(RELEASE_FOLDER)"_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
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
# JailDesigner - Custom mappings
|
||||||
|
|
||||||
|
# RAP4
|
||||||
|
030086650d0f00008c000000140100003853140,Generic X-Box pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
|
||||||
|
|
||||||
|
# Mad Catz FightStick Alpha PS4
|
||||||
|
03007fcb380700008081000011010000184833152,Mad Catz FightStick Alpha PS4,platform:Linux,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b13,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
|
||||||
|
|
||||||
|
# Mando custom de Dani en madera + Agetec
|
||||||
|
030020617900000006000000100100001216,DragonRise Inc. Generic USB Joystick,platform:Linux,a:b2,b:b1,x:b0,y:b6,start:b5,leftx:a0,lefty:a1,
|
||||||
|
|
||||||
# Game Controller DB for SDL in 2.0.16 format
|
# Game Controller DB for SDL in 2.0.16 format
|
||||||
# Source: https://github.com/gabomdq/SDL_GameControllerDB
|
# Source: https://github.com/gabomdq/SDL_GameControllerDB
|
||||||
|
|
||||||
@@ -1724,8 +1735,6 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,
|
|||||||
xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,
|
xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,
|
||||||
03000000120c0000100e000011010000,Zeroplus P4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,
|
03000000120c0000100e000011010000,Zeroplus P4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,
|
||||||
03000000120c0000101e000011010000,Zeroplus P4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,
|
03000000120c0000101e000011010000,Zeroplus P4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,
|
||||||
030086650d0f00008c000000140100003853140,Generic X-Box pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
|
|
||||||
03007fcb380700008081000011010000184833152,Mad Catz FightStick Alpha PS4,platform:Linux,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b13,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
|
|
||||||
|
|
||||||
# Android
|
# Android
|
||||||
38653964633230666463343334313533,8BitDo Adapter,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:b17,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:b18,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
|
38653964633230666463343334313533,8BitDo Adapter,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:b17,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:b18,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Android,
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
## GAME
|
|
||||||
gameWidth 320
|
|
||||||
gameHeight 240
|
|
||||||
itemSize 20
|
|
||||||
autofire true
|
|
||||||
|
|
||||||
## FADE
|
|
||||||
numSquaresWidth 160
|
|
||||||
numSquaresHeight 120
|
|
||||||
fadeRandomSquaresDelay 1
|
|
||||||
fadeRandomSquaresMult 500
|
|
||||||
fadePostDuration 80
|
|
||||||
venetianSize 16
|
|
||||||
|
|
||||||
## SCOREBOARD
|
|
||||||
scoreboard.x 0
|
|
||||||
scoreboard.y 200
|
|
||||||
scoreboard.w 320
|
|
||||||
scoreboard.h 40
|
|
||||||
|
|
||||||
## TITLE
|
|
||||||
pressStart 170
|
|
||||||
titleCounter 800
|
|
||||||
arcadeEdition 123
|
|
||||||
titleCC 80
|
|
||||||
|
|
||||||
## BACKGROUND
|
|
||||||
backgroundAttenuateColor.r 255
|
|
||||||
backgroundAttenuateColor.g 255
|
|
||||||
backgroundAttenuateColor.b 255
|
|
||||||
backgroundAttenuateColor.a 0
|
|
||||||
|
|
||||||
## BALLOONS
|
|
||||||
balloon1.vel 2.75f
|
|
||||||
balloon1.grav 0.09f
|
|
||||||
balloon2.vel 3.70f
|
|
||||||
balloon2.grav 0.10f
|
|
||||||
balloon3.vel 4.70f
|
|
||||||
balloon3.grav 0.10f
|
|
||||||
balloon4.vel 5.45f
|
|
||||||
balloon4.grav 0.10f
|
|
||||||
52
data/config/param_320x240.txt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
## GAME
|
||||||
|
game.item_size 20
|
||||||
|
game.width 320
|
||||||
|
game.height 240
|
||||||
|
game.play_area.rect.x 0
|
||||||
|
game.play_area.rect.y 0
|
||||||
|
game.play_area.rect.w 320
|
||||||
|
game.play_area.rect.h 200
|
||||||
|
|
||||||
|
## FADE
|
||||||
|
fade.num_squares_width 160
|
||||||
|
fade.num_squares_height 120
|
||||||
|
fade.random_squares_delay 1
|
||||||
|
fade.random_squares_mult 500
|
||||||
|
fade.post_duration 80
|
||||||
|
fade.venetian_size 16
|
||||||
|
|
||||||
|
## SCOREBOARD
|
||||||
|
scoreboard.x 0
|
||||||
|
scoreboard.y 200
|
||||||
|
scoreboard.w 320
|
||||||
|
scoreboard.h 40
|
||||||
|
|
||||||
|
## TITLE
|
||||||
|
title.press_start_position 170
|
||||||
|
title.title_duration 800
|
||||||
|
title.arcade_edition_position 123
|
||||||
|
title.title_c_c_position 80
|
||||||
|
|
||||||
|
## BACKGROUND
|
||||||
|
background.attenuate_color.r 255
|
||||||
|
background.attenuate_color.g 255
|
||||||
|
background.attenuate_color.b 255
|
||||||
|
background.attenuate_alpha 0
|
||||||
|
|
||||||
|
## BALLOONS
|
||||||
|
balloon_1.vel 2.75f
|
||||||
|
balloon_1.grav 0.09f
|
||||||
|
balloon_2.vel 3.70f
|
||||||
|
balloon_2.grav 0.10f
|
||||||
|
balloon_3.vel 4.70f
|
||||||
|
balloon_3.grav 0.10f
|
||||||
|
balloon_4.vel 5.45f
|
||||||
|
balloon_4.grav 0.10f
|
||||||
|
|
||||||
|
## NOTIFICATION
|
||||||
|
notification.pos_v TOP
|
||||||
|
notification.pos_h LEFT
|
||||||
|
notification.sound false
|
||||||
|
notification.color.r 48
|
||||||
|
notification.color.g 48
|
||||||
|
notification.color.b 48
|
||||||
52
data/config/param_320x256.txt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
## GAME
|
||||||
|
game.item_size 20
|
||||||
|
game.width 320
|
||||||
|
game.height 256
|
||||||
|
game.play_area.rect.x 0
|
||||||
|
game.play_area.rect.y 0
|
||||||
|
game.play_area.rect.w 320
|
||||||
|
game.play_area.rect.h 216
|
||||||
|
|
||||||
|
## FADE
|
||||||
|
fade.num_squares_width 160
|
||||||
|
fade.num_squares_height 128
|
||||||
|
fade.random_squares_delay 1
|
||||||
|
fade.random_squares_mult 500
|
||||||
|
fade.post_duration 80
|
||||||
|
fade.venetian_size 16
|
||||||
|
|
||||||
|
## SCOREBOARD
|
||||||
|
scoreboard.x 0
|
||||||
|
scoreboard.y 216
|
||||||
|
scoreboard.w 320
|
||||||
|
scoreboard.h 40
|
||||||
|
|
||||||
|
## TITLE
|
||||||
|
title.press_start_position 180
|
||||||
|
title.title_duration 800
|
||||||
|
title.arcade_edition_position 123
|
||||||
|
title.title_c_c_position 80
|
||||||
|
|
||||||
|
## BACKGROUND
|
||||||
|
background.attenuate_color.r 255
|
||||||
|
background.attenuate_color.g 255
|
||||||
|
background.attenuate_color.b 255
|
||||||
|
background.attenuate_alpha 0
|
||||||
|
|
||||||
|
## BALLOONS
|
||||||
|
balloon_1.vel 2.75f
|
||||||
|
balloon_1.grav 0.09f
|
||||||
|
balloon_2.vel 3.70f
|
||||||
|
balloon_2.grav 0.10f
|
||||||
|
balloon_3.vel 4.70f
|
||||||
|
balloon_3.grav 0.10f
|
||||||
|
balloon_4.vel 5.45f
|
||||||
|
balloon_4.grav 0.10f
|
||||||
|
|
||||||
|
## NOTIFICATION
|
||||||
|
notification.pos_v TOP
|
||||||
|
notification.pos_h LEFT
|
||||||
|
notification.sound false
|
||||||
|
notification.color.r 48
|
||||||
|
notification.color.g 48
|
||||||
|
notification.color.b 48
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=10
|
frame_width=10
|
||||||
frameHeight=10
|
frame_height=10
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=orange
|
name=orange
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=16
|
frame_width=16
|
||||||
frameHeight=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=orange
|
name=orange
|
||||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=26
|
frame_width=26
|
||||||
frameHeight=26
|
frame_height=26
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=orange
|
name=orange
|
||||||
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=48
|
frame_width=48
|
||||||
frameHeight=48
|
frame_height=48
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=orange
|
name=orange
|
||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=10
|
frame_width=10
|
||||||
frameHeight=10
|
frame_height=10
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 760 B After Width: | Height: | Size: 760 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=16
|
frame_width=16
|
||||||
frameHeight=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=26
|
frame_width=26
|
||||||
frameHeight=26
|
frame_height=26
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=46
|
frame_width=46
|
||||||
frameHeight=46
|
frame_height=46
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=46
|
frame_width=46
|
||||||
frameHeight=46
|
frame_height=46
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=powerball
|
name=powerball
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 858 B After Width: | Height: | Size: 858 B |
BIN
data/gfx/controllers/controllers.png
Normal file
|
After Width: | Height: | Size: 799 B |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
data/gfx/game/game_clouds1.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
data/gfx/game/game_clouds2.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
BIN
data/gfx/game/game_sky_colors.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 935 B After Width: | Height: | Size: 935 B |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=20
|
frame_width=20
|
||||||
frameHeight=20
|
frame_height=20
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 400 B After Width: | Height: | Size: 400 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=20
|
frame_width=20
|
||||||
frameHeight=20
|
frame_height=20
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 623 B After Width: | Height: | Size: 623 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=28
|
frame_width=28
|
||||||
frameHeight=37
|
frame_height=37
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 835 B After Width: | Height: | Size: 835 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=20
|
frame_width=20
|
||||||
frameHeight=20
|
frame_height=20
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 336 B After Width: | Height: | Size: 336 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=20
|
frame_width=20
|
||||||
frameHeight=20
|
frame_height=20
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 506 B After Width: | Height: | Size: 506 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=20
|
frame_width=20
|
||||||
frameHeight=20
|
frame_height=20
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 492 B After Width: | Height: | Size: 492 B |
|
Before Width: | Height: | Size: 717 B After Width: | Height: | Size: 717 B |
BIN
data/gfx/logo/logo_jailgames_mini.png
Normal file
|
After Width: | Height: | Size: 720 B |
|
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
|
Before Width: | Height: | Size: 716 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=30
|
frame_width=30
|
||||||
frameHeight=30
|
frame_height=30
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=walk
|
name=walk
|
||||||
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 772 B |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
|
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 772 B |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=39
|
frame_width=39
|
||||||
frameHeight=44
|
frame_height=44
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 944 B After Width: | Height: | Size: 944 B |
|
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
@@ -1,5 +1,5 @@
|
|||||||
frameWidth=16
|
frame_width=16
|
||||||
frameHeight=16
|
frame_height=16
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=default
|
name=default
|
||||||
|
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 212 B |
@@ -278,4 +278,70 @@ DEIXA BUIT PER A
|
|||||||
MODE FORA DE LINEA
|
MODE FORA DE LINEA
|
||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
TAULER DE PUNTS
|
TAULER DE PUNTS
|
||||||
|
|
||||||
|
## 94 - NOTIFICACIONES
|
||||||
|
Torna a polsar per eixir ...
|
||||||
|
|
||||||
|
## 95 - DEFINE BUTTONS
|
||||||
|
Disparar cap a l'esquerra
|
||||||
|
|
||||||
|
## 96 - DEFINE BUTTONS
|
||||||
|
Disparar cap amunt
|
||||||
|
|
||||||
|
## 97 - DEFINE BUTTONS
|
||||||
|
Disparar cap a la dreta
|
||||||
|
|
||||||
|
## 98 - DEFINE BUTTONS
|
||||||
|
Start
|
||||||
|
|
||||||
|
## 99 - DEFINE BUTTONS
|
||||||
|
Servei
|
||||||
|
|
||||||
|
## 100 - DEFINE BUTTONS
|
||||||
|
Jugador
|
||||||
|
|
||||||
|
## 101 - MARCADOR
|
||||||
|
Mode demostracio
|
||||||
|
|
||||||
|
## 102 - MARCADOR
|
||||||
|
Game Over
|
||||||
|
|
||||||
|
## 103 - MARCADOR
|
||||||
|
Pulsa START
|
||||||
|
|
||||||
|
## 104 - MARCADOR
|
||||||
|
per jugar
|
||||||
|
|
||||||
|
## 105 - MARCADOR
|
||||||
|
Continuar?
|
||||||
|
|
||||||
|
## 106 - MARCADOR
|
||||||
|
Posa el nom
|
||||||
|
|
||||||
|
## 107 - AJUDA
|
||||||
|
Intercanviar mandos
|
||||||
|
|
||||||
|
## 108 - AJUDA
|
||||||
|
Configuracio
|
||||||
|
|
||||||
|
## 109 - AJUDA
|
||||||
|
Alternar el audio
|
||||||
|
|
||||||
|
## 110 - AJUDA
|
||||||
|
Filtres
|
||||||
|
|
||||||
|
## 111 - AJUDA
|
||||||
|
Reiniciar
|
||||||
|
|
||||||
|
## 112 - AJUDA
|
||||||
|
Pausar
|
||||||
|
|
||||||
|
## 113 - AJUDA
|
||||||
|
Eixir
|
||||||
|
|
||||||
|
## 114 - MARCADOR
|
||||||
|
Per favor
|
||||||
|
|
||||||
|
## 115 - MARCADOR
|
||||||
|
espere
|
||||||
@@ -278,4 +278,70 @@ LEAVE BLANK FOR
|
|||||||
OFFLINE MODE
|
OFFLINE MODE
|
||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
HISCORE TABLE
|
HISCORE TABLE
|
||||||
|
|
||||||
|
## 94 - NOTIFICACIONES
|
||||||
|
Press again to quit
|
||||||
|
|
||||||
|
## 95 - DEFINE BUTTONS
|
||||||
|
Fire left
|
||||||
|
|
||||||
|
## 96 - DEFINE BUTTONS
|
||||||
|
Fire up
|
||||||
|
|
||||||
|
## 97 - DEFINE BUTTONS
|
||||||
|
Fire right
|
||||||
|
|
||||||
|
## 98 - DEFINE BUTTONS
|
||||||
|
Start
|
||||||
|
|
||||||
|
## 99 - DEFINE BUTTONS
|
||||||
|
Service
|
||||||
|
|
||||||
|
## 100 - DEFINE BUTTONS
|
||||||
|
Player
|
||||||
|
|
||||||
|
## 101 - MARCADOR
|
||||||
|
Demo mode
|
||||||
|
|
||||||
|
## 102 - MARCADOR
|
||||||
|
Game Over
|
||||||
|
|
||||||
|
## 103 - MARCADOR
|
||||||
|
Press START
|
||||||
|
|
||||||
|
## 104 - MARCADOR
|
||||||
|
to play
|
||||||
|
|
||||||
|
## 105 - MARCADOR
|
||||||
|
Continue?
|
||||||
|
|
||||||
|
## 106 - MARCADOR
|
||||||
|
Enter name
|
||||||
|
|
||||||
|
## 107 - AJUDA
|
||||||
|
Swap Controllers
|
||||||
|
|
||||||
|
## 108 - AJUDA
|
||||||
|
Configuration
|
||||||
|
|
||||||
|
## 109 - AJUDA
|
||||||
|
Toggle audio
|
||||||
|
|
||||||
|
## 110 - AJUDA
|
||||||
|
Shaders
|
||||||
|
|
||||||
|
## 111 - AJUDA
|
||||||
|
Reset
|
||||||
|
|
||||||
|
## 112 - AJUDA
|
||||||
|
Pause
|
||||||
|
|
||||||
|
## 113 - AJUDA
|
||||||
|
Exit
|
||||||
|
|
||||||
|
## 114 - MARCADOR
|
||||||
|
Please
|
||||||
|
|
||||||
|
## 115 - MARCADOR
|
||||||
|
wait
|
||||||
@@ -278,4 +278,70 @@ DEJA EN BLANCO PARA
|
|||||||
MODO SIN CONEXION
|
MODO SIN CONEXION
|
||||||
|
|
||||||
## 93 - MENU OPCIONES
|
## 93 - MENU OPCIONES
|
||||||
TABLA DE PUNTUACIONES
|
TABLA DE PUNTUACIONES
|
||||||
|
|
||||||
|
## 94 - NOTIFICACIONES
|
||||||
|
Pulsa otra vez para salir
|
||||||
|
|
||||||
|
## 95 - DEFINE BUTTONS
|
||||||
|
Disparar a la izquierda
|
||||||
|
|
||||||
|
## 96 - DEFINE BUTTONS
|
||||||
|
Disparar hacia arriba
|
||||||
|
|
||||||
|
## 97 - DEFINE BUTTONS
|
||||||
|
Disparar hacia la derecha
|
||||||
|
|
||||||
|
## 98 - DEFINE BUTTONS
|
||||||
|
Start
|
||||||
|
|
||||||
|
## 99 - DEFINE BUTTONS
|
||||||
|
Servicio
|
||||||
|
|
||||||
|
## 100 - DEFINE BUTTONS
|
||||||
|
Jugador
|
||||||
|
|
||||||
|
## 101 - MARCADOR
|
||||||
|
Mode demostracion
|
||||||
|
|
||||||
|
## 102 - MARCADOR
|
||||||
|
Game Over
|
||||||
|
|
||||||
|
## 103 - MARCADOR
|
||||||
|
Pulsa START
|
||||||
|
|
||||||
|
## 104 - MARCADOR
|
||||||
|
para jugar
|
||||||
|
|
||||||
|
## 105 - MARCADOR
|
||||||
|
Continuar?
|
||||||
|
|
||||||
|
## 106 - MARCADOR
|
||||||
|
Pon tu nombre
|
||||||
|
|
||||||
|
## 107 - AJUDA
|
||||||
|
Intercambiar mandos
|
||||||
|
|
||||||
|
## 108 - AJUDA
|
||||||
|
Configuracion
|
||||||
|
|
||||||
|
## 109 - AJUDA
|
||||||
|
Alternar el audio
|
||||||
|
|
||||||
|
## 110 - AJUDA
|
||||||
|
Filtros
|
||||||
|
|
||||||
|
## 111 - AJUDA
|
||||||
|
Reiniciar
|
||||||
|
|
||||||
|
## 112 - AJUDA
|
||||||
|
Pausar
|
||||||
|
|
||||||
|
## 113 - AJUDA
|
||||||
|
Salir
|
||||||
|
|
||||||
|
## 114 - MARCADOR
|
||||||
|
Por favor
|
||||||
|
|
||||||
|
## 115 - MARCADOR
|
||||||
|
espere
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -97,7 +97,8 @@ void main()
|
|||||||
#if defined(CURVATURE)
|
#if defined(CURVATURE)
|
||||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||||
#endif
|
#endif
|
||||||
filterWidth = (768.0 / 240.0) / 3.0;
|
//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;
|
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
}
|
}
|
||||||
@@ -146,7 +147,7 @@ float CalcScanLine(float dy)
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 TextureSize = vec2(320.0, 240.0);
|
vec2 TextureSize = vec2(320.0, 256.0);
|
||||||
#if defined(CURVATURE)
|
#if defined(CURVATURE)
|
||||||
vec2 texcoord = Distort(TEX0);
|
vec2 texcoord = Distort(TEX0);
|
||||||
if (texcoord.x < 0.0)
|
if (texcoord.x < 0.0)
|
||||||
|
|||||||
10
linux-utils/check-includes.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SOURCEPATH=../source/
|
||||||
|
|
||||||
|
for i in "$SOURCEPATH"/*.cpp
|
||||||
|
do
|
||||||
|
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
|
||||||
|
read -p "Presiona cualquier tecla para continuar..."
|
||||||
|
clear
|
||||||
|
done
|
||||||
6
linux-utils/go.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SECONDS=0
|
||||||
|
make linux_debug
|
||||||
|
duration=$SECONDS
|
||||||
|
echo "$((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
|
||||||
BIN
linux-utils/include-what-you-use
Executable file
3
linux-utils/run_valgrind.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
valgrind --suppressions=valgrind_exceptions --leak-check=full ~/coffee_crisis_arcade_edition/coffee_crisis_arcade_edition_debug > ~/coffee_crisis_arcade_edition/debug.txt 2>&1
|
||||||
12
linux-utils/valgrind_exceptions
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
ignore_unversioned_libs
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:*/lib*/lib*.so
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ignore_versioned_libs
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:*/lib*/lib*.so.*
|
||||||
|
}
|
||||||
@@ -1,37 +1,48 @@
|
|||||||
#include "animatedsprite.h"
|
#include "animated_sprite.h"
|
||||||
|
#include <algorithm> // for copy
|
||||||
|
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
|
||||||
|
#include <iostream> // for cout
|
||||||
|
#include <iterator> // for back_insert_iterator, back_inserter
|
||||||
|
#include <sstream> // for basic_stringstream
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string file_path)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
animatedSprite_t as;
|
AnimatedFile af;
|
||||||
as.texture = texture;
|
af.texture = texture;
|
||||||
int framesPerRow = 0;
|
auto frames_per_row = 0;
|
||||||
int frameWidth = 0;
|
auto frame_width = 0;
|
||||||
int frameHeight = 0;
|
auto frame_height = 0;
|
||||||
int maxTiles = 0;
|
auto max_tiles = 0;
|
||||||
|
|
||||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
#ifdef VERBOSE
|
||||||
std::ifstream file(filePath);
|
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
#endif
|
||||||
|
std::ifstream file(file_path);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
// El fichero se puede abrir
|
// El fichero se puede abrir
|
||||||
if (file.good())
|
if (file.good())
|
||||||
{
|
{
|
||||||
// Procesa el fichero linea a linea
|
// Procesa el fichero linea a linea
|
||||||
if (verbose)
|
#ifdef VERBOSE
|
||||||
{
|
std::cout << "Animation loaded: " << file_name << std::endl;
|
||||||
std::cout << "Animation loaded: " << filename << std::endl;
|
#endif
|
||||||
}
|
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
if (line == "[animation]")
|
if (line == "[animation]")
|
||||||
{
|
{
|
||||||
animation_t buffer;
|
Animation buffer;
|
||||||
buffer.counter = 0;
|
buffer.counter = 0;
|
||||||
buffer.currentFrame = 0;
|
buffer.current_frame = 0;
|
||||||
buffer.completed = false;
|
buffer.completed = false;
|
||||||
|
buffer.name.clear();
|
||||||
|
buffer.speed = 5;
|
||||||
|
buffer.loop = 0;
|
||||||
|
buffer.frames.clear();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -41,7 +52,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
|
|
||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (pos != (int)line.npos)
|
if (pos != static_cast<int>(line.npos))
|
||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "name")
|
if (line.substr(0, pos) == "name")
|
||||||
{
|
{
|
||||||
@@ -63,26 +74,28 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||||
while (getline(ss, tmp, ','))
|
while (getline(ss, tmp, ','))
|
||||||
{
|
{
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
buffer.frames.push_back(rect);
|
buffer.frames.push_back(rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
#ifdef VERBOSE
|
||||||
|
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (line != "[/animation]");
|
} while (line != "[/animation]");
|
||||||
|
|
||||||
// Añade la animación al vector de animaciones
|
// Añade la animación al vector de animaciones
|
||||||
as.animations.push_back(buffer);
|
af.animations.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||||
@@ -94,37 +107,39 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (pos != (int)line.npos)
|
if (pos != (int)line.npos)
|
||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "framesPerRow")
|
if (line.substr(0, pos) == "frames_per_row")
|
||||||
{
|
{
|
||||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameWidth")
|
else if (line.substr(0, pos) == "frame_width")
|
||||||
{
|
{
|
||||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameHeight")
|
else if (line.substr(0, pos) == "frame_height")
|
||||||
{
|
{
|
||||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
#ifdef VERBOSE
|
||||||
|
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normaliza valores
|
// Normaliza valores
|
||||||
if (framesPerRow == 0 && frameWidth > 0)
|
if (frames_per_row == 0 && frame_width > 0)
|
||||||
{
|
{
|
||||||
framesPerRow = texture->getWidth() / frameWidth;
|
frames_per_row = texture->getWidth() / frame_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||||
{
|
{
|
||||||
const int w = texture->getWidth() / frameWidth;
|
const auto w = texture->getWidth() / frame_width;
|
||||||
const int h = texture->getHeight() / frameHeight;
|
const auto h = texture->getHeight() / frame_height;
|
||||||
maxTiles = w * h;
|
max_tiles = w * h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,74 +151,55 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (verbose)
|
#ifdef VERBOSE
|
||||||
{
|
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
|
||||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return as;
|
return af;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(Texture *texture, std::string file, std::vector<std::string> *buffer)
|
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
|
||||||
|
: MovingSprite(texture),
|
||||||
|
current_animation_(0)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
setTexture(texture);
|
|
||||||
|
|
||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
if (file != "")
|
if (!file.empty())
|
||||||
{
|
{
|
||||||
animatedSprite_t as = loadAnimationFromFile(texture, file);
|
AnimatedFile as = loadAnimationFromFile(texture, file);
|
||||||
|
|
||||||
// Copia los datos de las animaciones
|
// Copia los datos de las animaciones
|
||||||
for (auto animation : as.animations)
|
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
|
||||||
{
|
|
||||||
this->animation.push_back(animation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (buffer)
|
else if (buffer)
|
||||||
{
|
{
|
||||||
loadFromVector(buffer);
|
loadFromVector(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
currentAnimation = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(animatedSprite_t *animation)
|
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
|
||||||
|
: MovingSprite(animation->texture),
|
||||||
|
current_animation_(0)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
setTexture(animation->texture);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
currentAnimation = 0;
|
|
||||||
|
|
||||||
// Copia los datos de las animaciones
|
// Copia los datos de las animaciones
|
||||||
for (auto a : animation->animations)
|
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
|
||||||
{
|
|
||||||
this->animation.push_back(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
AnimatedSprite::~AnimatedSprite()
|
AnimatedSprite::~AnimatedSprite()
|
||||||
{
|
{
|
||||||
for (auto &a : animation)
|
animations_.clear();
|
||||||
{
|
|
||||||
a.frames.clear();
|
|
||||||
}
|
|
||||||
animation.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
int AnimatedSprite::getIndex(std::string name)
|
int AnimatedSprite::getIndex(const std::string &name)
|
||||||
{
|
{
|
||||||
int index = -1;
|
auto index = -1;
|
||||||
|
|
||||||
for (auto a : animation)
|
for (const auto &a : animations_)
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
if (a.name == name)
|
if (a.name == name)
|
||||||
@@ -211,147 +207,147 @@ int AnimatedSprite::getIndex(std::string name)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
// Calcula el frame correspondiente a la animación
|
||||||
void AnimatedSprite::animate()
|
void AnimatedSprite::animate()
|
||||||
{
|
{
|
||||||
if (!enabled || animation[currentAnimation].speed == 0)
|
if (animations_[current_animation_].speed == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el frame actual a partir del contador
|
// Calcula el frame actual a partir del contador
|
||||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
||||||
|
|
||||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||||
// en función de la variable loop y coloca el nuevo frame
|
// en función de la variable loop y coloca el nuevo frame
|
||||||
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
|
if (animations_[current_animation_].current_frame >= (int)animations_[current_animation_].frames.size())
|
||||||
{
|
{
|
||||||
if (animation[currentAnimation].loop == -1)
|
if (animations_[current_animation_].loop == -1)
|
||||||
{ // Si no hay loop, deja el último frame
|
{ // Si no hay loop, deja el último frame
|
||||||
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
||||||
animation[currentAnimation].completed = true;
|
animations_[current_animation_].completed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Si hay loop, vuelve al frame indicado
|
{ // Si hay loop, vuelve al frame indicado
|
||||||
animation[currentAnimation].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
|
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// En caso contrario
|
// En caso contrario
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Escoge el frame correspondiente de la animación
|
// Escoge el frame correspondiente de la animación
|
||||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||||
|
|
||||||
// Incrementa el contador de la animacion
|
// Incrementa el contador de la animacion
|
||||||
animation[currentAnimation].counter++;
|
animations_[current_animation_].counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el número de frames de la animación actual
|
// Obtiene el número de frames de la animación actual
|
||||||
int AnimatedSprite::getNumFrames()
|
int AnimatedSprite::getNumFrames()
|
||||||
{
|
{
|
||||||
return (int)animation[currentAnimation].frames.size();
|
return (int)animations_[current_animation_].frames.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el frame actual de la animación
|
// Establece el frame actual de la animación
|
||||||
void AnimatedSprite::setCurrentFrame(int num)
|
void AnimatedSprite::setCurrentFrame(int num)
|
||||||
{
|
{
|
||||||
// Descarta valores fuera de rango
|
// Descarta valores fuera de rango
|
||||||
if (num >= (int)animation[currentAnimation].frames.size())
|
if (num >= (int)animations_[current_animation_].frames.size())
|
||||||
{
|
{
|
||||||
num = 0;
|
num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el valor de la variable
|
// Cambia el valor de la variable
|
||||||
animation[currentAnimation].currentFrame = num;
|
animations_[current_animation_].current_frame = num;
|
||||||
animation[currentAnimation].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
|
|
||||||
// Escoge el frame correspondiente de la animación
|
// Escoge el frame correspondiente de la animación
|
||||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
void AnimatedSprite::setAnimationCounter(const std::string &name, int num)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].counter = num;
|
animations_[getIndex(name)].counter = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
void AnimatedSprite::setAnimationSpeed(const std::string &name, int speed)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].counter = speed;
|
animations_[getIndex(name)].counter = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||||
{
|
{
|
||||||
animation[index].counter = speed;
|
animations_[index].counter = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece si la animación se reproduce en bucle
|
// Establece si la animación se reproduce en bucle
|
||||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
void AnimatedSprite::setAnimationLoop(const std::string &name, int loop)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].loop = loop;
|
animations_[getIndex(name)].loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece si la animación se reproduce en bucle
|
// Establece si la animación se reproduce en bucle
|
||||||
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||||
{
|
{
|
||||||
animation[index].loop = loop;
|
animations_[index].loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
void AnimatedSprite::setAnimationCompleted(const std::string &name, bool value)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].completed = value;
|
animations_[getIndex(name)].completed = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// OLD - Establece el valor de la variable
|
// OLD - Establece el valor de la variable
|
||||||
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
||||||
{
|
{
|
||||||
animation[index].completed = value;
|
animations_[index].completed = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool AnimatedSprite::animationIsCompleted()
|
bool AnimatedSprite::animationIsCompleted()
|
||||||
{
|
{
|
||||||
return animation[currentAnimation].completed;
|
return animations_[current_animation_].completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
SDL_Rect AnimatedSprite::getAnimationClip(const std::string &name, Uint8 index)
|
||||||
{
|
{
|
||||||
return animation[getIndex(name)].frames[index];
|
return animations_[getIndex(name)].frames[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||||
{
|
{
|
||||||
return animation[indexA].frames[indexF];
|
return animations_[indexA].frames[indexF];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
// Carga la animación desde un vector
|
||||||
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
int framesPerRow = 0;
|
auto frames_per_row = 0;
|
||||||
int frameWidth = 0;
|
auto frame_width = 0;
|
||||||
int frameHeight = 0;
|
auto frame_height = 0;
|
||||||
int maxTiles = 0;
|
auto max_tiles = 0;
|
||||||
|
|
||||||
// Indicador de éxito en el proceso
|
// Indicador de éxito en el proceso
|
||||||
bool success = true;
|
auto success = true;
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
// Recorre todo el vector
|
// Recorre todo el vector
|
||||||
int index = 0;
|
auto index = 0;
|
||||||
while (index < (int)source->size())
|
while (index < (int)source->size())
|
||||||
{
|
{
|
||||||
// Lee desde el vector
|
// Lee desde el vector
|
||||||
@@ -360,10 +356,14 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
if (line == "[animation]")
|
if (line == "[animation]")
|
||||||
{
|
{
|
||||||
animation_t buffer;
|
Animation buffer;
|
||||||
buffer.counter = 0;
|
buffer.counter = 0;
|
||||||
buffer.currentFrame = 0;
|
buffer.current_frame = 0;
|
||||||
buffer.completed = false;
|
buffer.completed = false;
|
||||||
|
buffer.name.clear();
|
||||||
|
buffer.speed = 5;
|
||||||
|
buffer.loop = 0;
|
||||||
|
buffer.frames.clear();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -375,7 +375,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
|
|
||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (pos != (int)line.npos)
|
if (pos != static_cast<int>(line.npos))
|
||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "name")
|
if (line.substr(0, pos) == "name")
|
||||||
{
|
{
|
||||||
@@ -397,27 +397,29 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||||
while (getline(ss, tmp, ','))
|
while (getline(ss, tmp, ','))
|
||||||
{
|
{
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
|
||||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
buffer.frames.push_back(rect);
|
buffer.frames.push_back(rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
#endif
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (line != "[/animation]");
|
} while (line != "[/animation]");
|
||||||
|
|
||||||
// Añade la animación al vector de animaciones
|
// Añade la animación al vector de animaciones
|
||||||
animation.push_back(buffer);
|
animations_.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||||
@@ -429,38 +431,40 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (pos != (int)line.npos)
|
if (pos != (int)line.npos)
|
||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "framesPerRow")
|
if (line.substr(0, pos) == "frames_per_row")
|
||||||
{
|
{
|
||||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameWidth")
|
else if (line.substr(0, pos) == "frame_width")
|
||||||
{
|
{
|
||||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameHeight")
|
else if (line.substr(0, pos) == "frame_height")
|
||||||
{
|
{
|
||||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
#endif
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normaliza valores
|
// Normaliza valores
|
||||||
if (framesPerRow == 0 && frameWidth > 0)
|
if (frames_per_row == 0 && frame_width > 0)
|
||||||
{
|
{
|
||||||
framesPerRow = texture->getWidth() / frameWidth;
|
frames_per_row = texture_->getWidth() / frame_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||||
{
|
{
|
||||||
const int w = texture->getWidth() / frameWidth;
|
const int w = texture_->getWidth() / frame_width;
|
||||||
const int h = texture->getHeight() / frameHeight;
|
const int h = texture_->getHeight() / frame_height;
|
||||||
maxTiles = w * h;
|
max_tiles = w * h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,34 +474,34 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pone un valor por defecto
|
// Pone un valor por defecto
|
||||||
setRect({0, 0, frameWidth, frameHeight});
|
setPos((SDL_Rect){0, 0, frame_width, frame_height});
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void AnimatedSprite::setCurrentAnimation(std::string name)
|
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||||
{
|
{
|
||||||
const int newAnimation = getIndex(name);
|
const auto new_animation = getIndex(name);
|
||||||
if (currentAnimation != newAnimation)
|
if (current_animation_ != new_animation)
|
||||||
{
|
{
|
||||||
currentAnimation = newAnimation;
|
current_animation_ = new_animation;
|
||||||
animation[currentAnimation].currentFrame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animation[currentAnimation].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
animation[currentAnimation].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void AnimatedSprite::setCurrentAnimation(int index)
|
void AnimatedSprite::setCurrentAnimation(int index)
|
||||||
{
|
{
|
||||||
const int newAnimation = index;
|
const auto new_animation = index;
|
||||||
if (currentAnimation != newAnimation)
|
if (current_animation_ != new_animation)
|
||||||
{
|
{
|
||||||
currentAnimation = newAnimation;
|
current_animation_ = new_animation;
|
||||||
animation[currentAnimation].currentFrame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animation[currentAnimation].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
animation[currentAnimation].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,13 +515,13 @@ void AnimatedSprite::update()
|
|||||||
// Establece el rectangulo para un frame de una animación
|
// Establece el rectangulo para un frame de una animación
|
||||||
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
animation[index_animation].frames.push_back({x, y, w, h});
|
animations_[index_animation].frames.push_back({x, y, w, h});
|
||||||
}
|
}
|
||||||
|
|
||||||
// OLD - Establece el contador para todas las animaciones
|
// OLD - Establece el contador para todas las animaciones
|
||||||
void AnimatedSprite::setAnimationCounter(int value)
|
void AnimatedSprite::setAnimationCounter(int value)
|
||||||
{
|
{
|
||||||
for (auto &a : animation)
|
for (auto &a : animations_)
|
||||||
{
|
{
|
||||||
a.counter = value;
|
a.counter = value;
|
||||||
}
|
}
|
||||||
@@ -526,7 +530,7 @@ void AnimatedSprite::setAnimationCounter(int value)
|
|||||||
// Reinicia la animación
|
// Reinicia la animación
|
||||||
void AnimatedSprite::resetAnimation()
|
void AnimatedSprite::resetAnimation()
|
||||||
{
|
{
|
||||||
animation[currentAnimation].currentFrame = 0;
|
animations_[current_animation_].current_frame = 0;
|
||||||
animation[currentAnimation].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
animation[currentAnimation].completed = false;
|
animations_[current_animation_].completed = false;
|
||||||
}
|
}
|
||||||
@@ -1,47 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "movingsprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include <fstream>
|
#include <memory> // for shared_ptr
|
||||||
#include <iostream>
|
#include <string> // for string
|
||||||
#include <sstream>
|
#include <vector> // for vector
|
||||||
#include <string>
|
#include "moving_sprite.h" // for MovingSprite
|
||||||
#include <vector>
|
class Texture;
|
||||||
|
|
||||||
struct animation_t
|
struct Animation
|
||||||
{
|
{
|
||||||
std::string name; // Nombre de la animacion
|
std::string name; // Nombre de la animacion
|
||||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||||
int speed; // Velocidad de la animación
|
int speed; // Velocidad de la animación
|
||||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||||
bool completed; // Indica si ha finalizado la animación
|
bool completed; // Indica si ha finalizado la animación
|
||||||
int currentFrame; // Frame actual
|
int current_frame; // Frame actual
|
||||||
int counter; // Contador para las animaciones
|
int counter; // Contador para las animaciones
|
||||||
};
|
};
|
||||||
|
|
||||||
struct animatedSprite_t
|
struct AnimatedFile
|
||||||
{
|
{
|
||||||
std::vector<animation_t> animations; // Vector con las diferentes animaciones
|
std::vector<Animation> animations; // Vector con las diferentes animaciones
|
||||||
Texture *texture; // Textura con los graficos para el sprite
|
std::shared_ptr<Texture> texture; // Textura con los graficos para el sprite
|
||||||
};
|
};
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false);
|
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string filePath);
|
||||||
|
|
||||||
class AnimatedSprite : public MovingSprite
|
class AnimatedSprite : public MovingSprite
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<animation_t> animation; // Vector con las diferentes animaciones
|
std::vector<Animation> animations_; // Vector con las diferentes animaciones
|
||||||
int currentAnimation; // Animacion activa
|
int current_animation_; // Animacion activa
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite(Texture *texture = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string> *buffer = nullptr);
|
||||||
AnimatedSprite(animatedSprite_t *animation);
|
explicit AnimatedSprite(const AnimatedFile *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~AnimatedSprite();
|
virtual ~AnimatedSprite();
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación actual
|
// Calcula el frame correspondiente a la animación actual
|
||||||
void animate();
|
void animate();
|
||||||
@@ -53,39 +53,39 @@ public:
|
|||||||
void setCurrentFrame(int num);
|
void setCurrentFrame(int num);
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void setAnimationCounter(std::string name, int num);
|
void setAnimationCounter(const std::string &name, int num);
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void setAnimationSpeed(std::string name, int speed);
|
void setAnimationSpeed(const std::string &name, int speed);
|
||||||
void setAnimationSpeed(int index, int speed);
|
void setAnimationSpeed(int index, int speed);
|
||||||
|
|
||||||
// Establece el frame al que vuelve la animación al finalizar
|
// Establece el frame al que vuelve la animación al finalizar
|
||||||
void setAnimationLoop(std::string name, int loop);
|
void setAnimationLoop(const std::string &name, int loop);
|
||||||
void setAnimationLoop(int index, int loop);
|
void setAnimationLoop(int index, int loop);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAnimationCompleted(std::string name, bool value);
|
void setAnimationCompleted(const std::string &name, bool value);
|
||||||
void setAnimationCompleted(int index, bool value);
|
void setAnimationCompleted(int index, bool value);
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool animationIsCompleted();
|
bool animationIsCompleted();
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
|
SDL_Rect getAnimationClip(const std::string &name = "default", Uint8 index = 0);
|
||||||
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
|
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
int getIndex(std::string name);
|
int getIndex(const std::string &name);
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
// Carga la animación desde un vector
|
||||||
bool loadFromVector(std::vector<std::string> *source);
|
bool loadFromVector(std::vector<std::string> *source);
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void setCurrentAnimation(std::string name = "default");
|
void setCurrentAnimation(const std::string &name = "default");
|
||||||
void setCurrentAnimation(int index = 0);
|
void setCurrentAnimation(int index = 0);
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update() override;
|
||||||
|
|
||||||
// OLD - Establece el rectangulo para un frame de una animación
|
// OLD - Establece el rectangulo para un frame de una animación
|
||||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||||
207
source/asset.cpp
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
#include "asset.h"
|
||||||
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for SDL_max
|
||||||
|
#include <stddef.h> // for size_t
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
|
|
||||||
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
|
Asset *Asset::asset_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto asset con esta función estática
|
||||||
|
void Asset::init(const std::string &executable_path)
|
||||||
|
{
|
||||||
|
Asset::asset_ = new Asset(executable_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto asset con esta función estática
|
||||||
|
void Asset::destroy()
|
||||||
|
{
|
||||||
|
delete Asset::asset_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto asset y podemos trabajar con él
|
||||||
|
Asset *Asset::get()
|
||||||
|
{
|
||||||
|
return Asset::asset_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Asset::Asset(const std::string &executable_path)
|
||||||
|
: executable_path_(executable_path.substr(0, executable_path.find_last_of("\\/")))
|
||||||
|
{
|
||||||
|
longest_name_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade un elemento a la lista
|
||||||
|
void Asset::add(const std::string &file, AssetType type, bool required, bool absolute)
|
||||||
|
{
|
||||||
|
AssetItem ai;
|
||||||
|
ai.file = absolute ? file : executable_path_ + file;
|
||||||
|
ai.type = type;
|
||||||
|
ai.required = required;
|
||||||
|
file_list_.push_back(ai);
|
||||||
|
|
||||||
|
const std::string file_name = file.substr(file.find_last_of("\\/") + 1);
|
||||||
|
longest_name_ = SDL_max(longest_name_, file_name.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||||
|
std::string Asset::get(const std::string &text) const
|
||||||
|
{
|
||||||
|
for (const auto &f : file_list_)
|
||||||
|
{
|
||||||
|
const size_t last_index = f.file.find_last_of("/") + 1;
|
||||||
|
const std::string file = f.file.substr(last_index, std::string::npos);
|
||||||
|
|
||||||
|
if (file == text)
|
||||||
|
{
|
||||||
|
return f.file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||||
|
#endif
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba que existen todos los elementos
|
||||||
|
bool Asset::check() const
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout << "\n** Checking files" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||||
|
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
|
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
|
||||||
|
{
|
||||||
|
// Comprueba si hay ficheros de ese tipo
|
||||||
|
bool any = false;
|
||||||
|
|
||||||
|
for (const auto &f : file_list_)
|
||||||
|
{
|
||||||
|
if (f.required && f.type == static_cast<AssetType>(type))
|
||||||
|
{
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si hay ficheros de ese tipo, comprueba si existen
|
||||||
|
if (any)
|
||||||
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (const auto &f : file_list_)
|
||||||
|
{
|
||||||
|
if (f.required && f.type == static_cast<AssetType>(type))
|
||||||
|
{
|
||||||
|
success &= checkFile(f.file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resultado
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba que existe un fichero
|
||||||
|
bool Asset::checkFile(const std::string &path) const
|
||||||
|
{
|
||||||
|
auto success = false;
|
||||||
|
|
||||||
|
// Comprueba si existe el fichero
|
||||||
|
auto file = SDL_RWFromFile(path.c_str(), "rb");
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
|
||||||
|
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||||
|
std::cout << "Checking file: ";
|
||||||
|
std::cout.width(longest_name_ + 2);
|
||||||
|
std::cout.fill('.');
|
||||||
|
std::cout << file_name;
|
||||||
|
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el nombre del tipo de recurso
|
||||||
|
std::string Asset::getTypeName(AssetType type) const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case AssetType::BITMAP:
|
||||||
|
return "BITMAP";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::MUSIC:
|
||||||
|
return "MUSIC";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::SOUND:
|
||||||
|
return "SOUND";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::FONT:
|
||||||
|
return "FONT";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::LANG:
|
||||||
|
return "LANG";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::DATA:
|
||||||
|
return "DATA";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::ANIMATION:
|
||||||
|
return "ANIMATION";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::PALETTE:
|
||||||
|
return "PALETTE";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AssetType::ITEM:
|
||||||
|
return "ITEM";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "ERROR";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve la lista de recursos de un tipo
|
||||||
|
std::vector<std::string> Asset::getListByType(AssetType type) const
|
||||||
|
{
|
||||||
|
std::vector<std::string> list;
|
||||||
|
|
||||||
|
for (auto f : file_list_)
|
||||||
|
{
|
||||||
|
if (f.type == type)
|
||||||
|
{
|
||||||
|
list.push_back(f.file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
74
source/asset.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string> // for string, basic_string
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
|
enum class AssetType : int
|
||||||
|
{
|
||||||
|
BITMAP,
|
||||||
|
MUSIC,
|
||||||
|
SOUND,
|
||||||
|
FONT,
|
||||||
|
LANG,
|
||||||
|
DATA,
|
||||||
|
ANIMATION,
|
||||||
|
PALETTE,
|
||||||
|
ITEM,
|
||||||
|
MAX_ASSET_TYPE,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clase Asset
|
||||||
|
class Asset
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto asset privado para Don Melitón
|
||||||
|
static Asset *asset_;
|
||||||
|
|
||||||
|
// Estructura para definir un item
|
||||||
|
struct AssetItem
|
||||||
|
{
|
||||||
|
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||||
|
enum AssetType type; // Indica el tipo de recurso
|
||||||
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
|
// bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
int longest_name_; // Contiene la longitud del nombre de fichero mas largo
|
||||||
|
std::vector<AssetItem> file_list_; // Listado con todas las rutas a los ficheros
|
||||||
|
std::string executable_path_; // Ruta al ejecutable
|
||||||
|
|
||||||
|
// Comprueba que existe un fichero
|
||||||
|
bool checkFile(const std::string &path) const;
|
||||||
|
|
||||||
|
// Devuelve el nombre del tipo de recurso
|
||||||
|
std::string getTypeName(AssetType type) const;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit Asset(const std::string &executable_path);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Asset() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
|
static void init(const std::string &executable_path);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||||
|
static Asset *get();
|
||||||
|
|
||||||
|
// Añade un elemento a la lista
|
||||||
|
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
|
||||||
|
|
||||||
|
// Devuelve un elemento de la lista a partir de una cadena
|
||||||
|
std::string get(const std::string &text) const;
|
||||||
|
|
||||||
|
// Comprueba que existen todos los elementos
|
||||||
|
bool check() const;
|
||||||
|
|
||||||
|
// Devuelve la lista de recursos de un tipo
|
||||||
|
std::vector<std::string> getListByType(AssetType type) const;
|
||||||
|
};
|
||||||
@@ -1,285 +1,325 @@
|
|||||||
#include "background.h"
|
#include "background.h"
|
||||||
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <algorithm> // for clamp, max
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "moving_sprite.h" // for MovingSprite
|
||||||
|
#include "param.h" // for param
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param)
|
Background::Background(SDL_Renderer *renderer)
|
||||||
|
: renderer_(renderer),
|
||||||
|
buildings_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"))),
|
||||||
|
top_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"))),
|
||||||
|
bottom_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"))),
|
||||||
|
grass_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"))),
|
||||||
|
gradients_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png")))
|
||||||
|
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->param = param;
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
gradientNumber = 0;
|
gradient_number_ = 0;
|
||||||
alpha = 0;
|
alpha_ = 0;
|
||||||
cloudsSpeed = 0;
|
clouds_speed_ = 0;
|
||||||
transition = 0;
|
transition_ = 0;
|
||||||
counter = 0;
|
counter_ = 0;
|
||||||
rect = {0, 0, param->gameWidth, param->gameHeight};
|
|
||||||
srcRect = {playArea.x, rect.h - playArea.h, playArea.w, playArea.h};
|
|
||||||
dstRect = {0, 0, playArea.w, playArea.h};
|
|
||||||
base = rect.h;
|
|
||||||
color = {param->backgroundAttenuateColor.r, param->backgroundAttenuateColor.g, param->backgroundAttenuateColor.b};
|
|
||||||
alphaColorText = alphaColorTextTemp = param->backgroundAttenuateAlpha;
|
|
||||||
|
|
||||||
gradientRect[0] = {0, 0, rect.w, rect.h};
|
rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2};
|
||||||
gradientRect[1] = {rect.w, 0, rect.w, rect.h};
|
src_rect_ = {0, 0, 320, 240};
|
||||||
gradientRect[2] = {0, rect.h, rect.w, rect.h};
|
dst_rect_ = {0, 0, 320, 240};
|
||||||
gradientRect[3] = {rect.w, rect.h, rect.w, rect.h};
|
|
||||||
|
|
||||||
// Carga las texturas
|
base_ = rect_.h;
|
||||||
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
|
color_ = {param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
|
||||||
clouds1Texture = new Texture(renderer, asset->get("game_clouds1.png"));
|
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
|
||||||
clouds2Texture = new Texture(renderer, asset->get("game_clouds2.png"));
|
|
||||||
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
|
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||||
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
|
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||||
|
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||||
|
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
|
||||||
|
|
||||||
|
const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4;
|
||||||
|
const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height};
|
||||||
|
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height};
|
||||||
|
}
|
||||||
|
|
||||||
// Crea los sprites
|
// Crea los sprites
|
||||||
const int clouds1y = base - 165;
|
const int top_clouds_y = base_ - 165;
|
||||||
const int clouds2y = base - 101;
|
const int bottom_clouds_y = base_ - 101;
|
||||||
const float clouds1speed = 0.1f;
|
constexpr float top_clouds_speed = 0.1f;
|
||||||
const float clouds2speed = 0.05f;
|
constexpr float bottom_clouds_speed = 0.05f;
|
||||||
clouds1A = new MovingSprite(0, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture);
|
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||||
clouds1B = new MovingSprite(rect.w, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture);
|
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||||
|
|
||||||
clouds2A = new MovingSprite(0, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture);
|
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||||
clouds2B = new MovingSprite(rect.w, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture);
|
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||||
|
|
||||||
buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture);
|
buildings_sprite_ = std::make_unique<Sprite>(0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight(), buildings_texture_);
|
||||||
gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture);
|
gradient_sprite_ = std::make_unique<Sprite>(0, 0, rect_.w, rect_.h, gradients_texture_);
|
||||||
grassSprite = new Sprite(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture);
|
grass_sprite_ = std::make_unique<Sprite>(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_);
|
||||||
|
|
||||||
// Inicializa objetos
|
// Inicializa objetos
|
||||||
clouds1A->setSpriteClip(0, 0, clouds1Texture->getWidth(), clouds1Texture->getHeight());
|
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||||
clouds1B->setSpriteClip(0, 0, clouds1Texture->getWidth(), clouds1Texture->getHeight());
|
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||||
clouds2A->setSpriteClip(0, 0, clouds2Texture->getWidth(), clouds2Texture->getHeight());
|
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||||
clouds2B->setSpriteClip(0, 0, clouds2Texture->getWidth(), clouds2Texture->getHeight());
|
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||||
buildingsSprite->setPosY(base - buildingsSprite->getHeight());
|
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight());
|
||||||
grassSprite->setPosY(base - grassSprite->getHeight());
|
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight());
|
||||||
|
|
||||||
// Crea la textura para componer el fondo
|
// Crea la textura para componer el fondo
|
||||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||||
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Crea la textura para atenuar el fondo
|
// Crea la textura para atenuar el fondo
|
||||||
colorTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||||
SDL_SetTextureBlendMode(colorTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
||||||
setColor(color);
|
setColor(color_);
|
||||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorText);
|
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Background::~Background()
|
Background::~Background()
|
||||||
{
|
{
|
||||||
delete buildingsTexture;
|
SDL_DestroyTexture(canvas_);
|
||||||
delete clouds1Texture;
|
SDL_DestroyTexture(color_texture_);
|
||||||
delete clouds2Texture;
|
|
||||||
delete grassTexture;
|
|
||||||
delete gradientsTexture;
|
|
||||||
|
|
||||||
delete clouds1A;
|
|
||||||
delete clouds1B;
|
|
||||||
delete clouds2A;
|
|
||||||
delete clouds2B;
|
|
||||||
delete buildingsSprite;
|
|
||||||
delete gradientSprite;
|
|
||||||
delete grassSprite;
|
|
||||||
SDL_DestroyTexture(canvas);
|
|
||||||
SDL_DestroyTexture(colorTexture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
// Actualiza la lógica del objeto
|
||||||
void Background::update()
|
void Background::update()
|
||||||
{
|
{
|
||||||
// Actualiza el valor de alpha
|
// Actualiza el valor de alpha_
|
||||||
updateAlphaColorText();
|
updateAlphaColorText();
|
||||||
|
|
||||||
// Actualiza las nubes
|
// Actualiza las nubes
|
||||||
updateCLouds();
|
updateClouds();
|
||||||
|
|
||||||
// Calcula el frame de la hierba
|
// Calcula el frame de la hierba
|
||||||
grassSprite->setSpriteClip(0, (10 * (counter / 20 % 2)), 320, 10);
|
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
|
||||||
|
|
||||||
// Calcula el valor de alpha
|
// Calcula el valor de alpha_
|
||||||
alpha = std::max((255 - (int)(255 * transition)), 0);
|
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||||
|
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter++;
|
counter_++;
|
||||||
|
|
||||||
|
// Compone todos los elementos del fondo en la textura
|
||||||
fillCanvas();
|
fillCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dibuja el gradiente de fondo
|
||||||
|
void Background::renderGradient()
|
||||||
|
{
|
||||||
|
// Dibuja el gradiente de detras
|
||||||
|
gradients_texture_->setAlpha(255);
|
||||||
|
gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]);
|
||||||
|
gradient_sprite_->render();
|
||||||
|
|
||||||
|
// Dibuja el gradiente de delante con una opacidad cada vez menor
|
||||||
|
gradients_texture_->setAlpha(alpha_);
|
||||||
|
gradient_sprite_->setSpriteClip(gradient_rect_[gradient_number_]);
|
||||||
|
gradient_sprite_->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las nubes de arriba
|
||||||
|
void Background::renderTopClouds()
|
||||||
|
{
|
||||||
|
// Dibuja el primer conjunto de nubes, las de detras
|
||||||
|
top_clouds_texture_->setAlpha(255);
|
||||||
|
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||||
|
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||||
|
top_clouds_sprite_a_->render();
|
||||||
|
top_clouds_sprite_b_->render();
|
||||||
|
|
||||||
|
// Dibuja el segundo conjunto de nubes, las de delante
|
||||||
|
top_clouds_texture_->setAlpha(alpha_);
|
||||||
|
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||||
|
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||||
|
top_clouds_sprite_a_->render();
|
||||||
|
top_clouds_sprite_b_->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las nubes de abajo
|
||||||
|
void Background::renderBottomClouds()
|
||||||
|
{
|
||||||
|
// Dibuja el primer conjunto de nubes, las de detras
|
||||||
|
bottom_clouds_texture_->setAlpha(255);
|
||||||
|
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||||
|
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||||
|
bottom_clouds_sprite_a_->render();
|
||||||
|
bottom_clouds_sprite_b_->render();
|
||||||
|
|
||||||
|
// Dibuja el segundo conjunto de nubes, las de delante
|
||||||
|
bottom_clouds_texture_->setAlpha(alpha_);
|
||||||
|
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||||
|
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||||
|
bottom_clouds_sprite_a_->render();
|
||||||
|
bottom_clouds_sprite_b_->render();
|
||||||
|
}
|
||||||
|
|
||||||
// Compone todos los elementos del fondo en la textura
|
// Compone todos los elementos del fondo en la textura
|
||||||
void Background::fillCanvas()
|
void Background::fillCanvas()
|
||||||
{
|
{
|
||||||
// Cambia el destino del renderizador
|
// Cambia el destino del renderizador
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, canvas);
|
SDL_SetRenderTarget(renderer_, canvas_);
|
||||||
|
|
||||||
// Dibuja el gradiente 2
|
// Dibuja el gradiente de fondo
|
||||||
gradientSprite->setSpriteClip(gradientRect[(gradientNumber + 1) % 4]);
|
renderGradient();
|
||||||
gradientsTexture->setAlpha(255);
|
|
||||||
gradientSprite->render();
|
|
||||||
|
|
||||||
// Dibuja el gradiente 1 con una opacidad cada vez menor
|
// Dibuja las nubes de arriba
|
||||||
gradientSprite->setSpriteClip(gradientRect[gradientNumber]);
|
renderTopClouds();
|
||||||
gradientsTexture->setAlpha(alpha);
|
|
||||||
gradientSprite->render();
|
|
||||||
|
|
||||||
// Dibuja las nubes
|
// Dibuja las nubes de abajo
|
||||||
clouds1A->render();
|
renderBottomClouds();
|
||||||
clouds1B->render();
|
|
||||||
clouds2A->render();
|
|
||||||
clouds2B->render();
|
|
||||||
|
|
||||||
// Dibuja los edificios
|
// Dibuja los edificios
|
||||||
buildingsSprite->render();
|
buildings_sprite_->render();
|
||||||
|
|
||||||
// Dibuja la hierba
|
// Dibuja la hierba
|
||||||
grassSprite->render();
|
grass_sprite_->render();
|
||||||
|
|
||||||
// Deja el renderizador apuntando donde estaba
|
// Deja el renderizador apuntando donde estaba
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el objeto
|
// Dibuja el objeto
|
||||||
void Background::render()
|
void Background::render()
|
||||||
{
|
{
|
||||||
// Fondo
|
// Fondo
|
||||||
SDL_RenderCopy(renderer, canvas, &srcRect, &dstRect);
|
SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_);
|
||||||
|
|
||||||
// Atenuación
|
// Atenuación
|
||||||
SDL_RenderCopy(renderer, colorTexture, &srcRect, &dstRect);
|
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a cargar las texturas
|
// Vuelve a cargar las texturas
|
||||||
void Background::reloadTextures()
|
void Background::reloadTextures()
|
||||||
{
|
{
|
||||||
buildingsTexture->reLoad();
|
buildings_texture_->reLoad();
|
||||||
clouds1Texture->reLoad();
|
top_clouds_texture_->reLoad();
|
||||||
clouds2Texture->reLoad();
|
bottom_clouds_texture_->reLoad();
|
||||||
grassTexture->reLoad();
|
grass_texture_->reLoad();
|
||||||
gradientsTexture->reLoad();
|
gradients_texture_->reLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setCloudsSpeed(float value)
|
void Background::setCloudsSpeed(float value)
|
||||||
{
|
{
|
||||||
cloudsSpeed = value;
|
clouds_speed_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setGradientNumber(int value)
|
void Background::setGradientNumber(int value)
|
||||||
{
|
{
|
||||||
gradientNumber = value % 4;
|
gradient_number_ = value % 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setTransition(float value)
|
void Background::setTransition(float value)
|
||||||
{
|
{
|
||||||
value = std::min(value, 1.0f);
|
transition_ = std::clamp(value, 0.0f, 1.0f);
|
||||||
value = std::max(value, 0.0f);
|
|
||||||
transition = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void Background::setPos(SDL_Rect rect)
|
void Background::setPos(SDL_Rect pos)
|
||||||
{
|
{
|
||||||
dstRect = rect;
|
dst_rect_ = pos;
|
||||||
|
|
||||||
// Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen
|
// Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen
|
||||||
srcRect.w = rect.w;
|
src_rect_.x = 0;
|
||||||
srcRect.h = rect.h;
|
src_rect_.y = rect_.h - pos.h;
|
||||||
|
src_rect_.w = pos.w;
|
||||||
|
src_rect_.h = pos.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setSrcRect(SDL_Rect value)
|
void Background::setSrcRect(SDL_Rect value)
|
||||||
{
|
{
|
||||||
srcRect = value;
|
src_rect_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setDstRect(SDL_Rect value)
|
void Background::setDstRect(SDL_Rect value)
|
||||||
{
|
{
|
||||||
dstRect = value;
|
dst_rect_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color de atenuación
|
// Establece el color_ de atenuación
|
||||||
void Background::setColor(color_t color)
|
void Background::setColor(Color color)
|
||||||
{
|
{
|
||||||
this->color = color;
|
color_ = color;
|
||||||
|
|
||||||
// Colorea la textura
|
// Colorea la textura
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer, colorTexture);
|
SDL_SetRenderTarget(renderer_, color_texture_);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la transparencia de la atenuación
|
// Establece la transparencia de la atenuación
|
||||||
void Background::setAlpha(int alpha)
|
void Background::setAlpha(int alpha)
|
||||||
{
|
{
|
||||||
// Evita que se asignen valores fuera de rango
|
// Evita que se asignen valores fuera de rango
|
||||||
alpha = std::min(alpha, 255);
|
alpha_ = std::clamp(alpha, 0, 255);
|
||||||
alpha = std::max(alpha, 0);
|
|
||||||
|
|
||||||
// Guarda el valor actual
|
// Guarda el valor actual y establece el nuevo valor
|
||||||
alphaColorTextTemp = alphaColorText;
|
alpha_color_text_temp_ = alpha_color_text_;
|
||||||
|
alpha_color_text_ = alpha_;
|
||||||
// Establece el nuevo valor
|
|
||||||
alphaColorText = alpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de alpha
|
// Actualiza el valor de alpha_
|
||||||
void Background::updateAlphaColorText()
|
void Background::updateAlphaColorText()
|
||||||
{
|
{
|
||||||
if (alphaColorText == alphaColorTextTemp)
|
if (alpha_color_text_ == alpha_color_text_temp_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alphaColorText > alphaColorTextTemp ? alphaColorTextTemp++ : alphaColorTextTemp--;
|
alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_;
|
||||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorTextTemp);
|
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las nubes
|
// Actualiza las nubes
|
||||||
void Background::updateCLouds()
|
void Background::updateClouds()
|
||||||
{
|
{
|
||||||
// Aplica la velocidad calculada a las nubes
|
// Aplica la velocidad calculada a las nubes
|
||||||
clouds1A->setVelX(cloudsSpeed);
|
top_clouds_sprite_a_->setVelX(clouds_speed_);
|
||||||
clouds1B->setVelX(cloudsSpeed);
|
top_clouds_sprite_b_->setVelX(clouds_speed_);
|
||||||
clouds2A->setVelX(cloudsSpeed / 2);
|
bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2);
|
||||||
clouds2B->setVelX(cloudsSpeed / 2);
|
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
|
||||||
|
|
||||||
// Mueve las nubes
|
// Mueve las nubes
|
||||||
clouds1A->move();
|
top_clouds_sprite_a_->move();
|
||||||
clouds1B->move();
|
top_clouds_sprite_b_->move();
|
||||||
clouds2A->move();
|
bottom_clouds_sprite_a_->move();
|
||||||
clouds2B->move();
|
bottom_clouds_sprite_b_->move();
|
||||||
|
|
||||||
// Calcula el offset de las nubes
|
// Calcula el offset de las nubes
|
||||||
if (clouds1A->getPosX() < -clouds1A->getWidth())
|
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())
|
||||||
{
|
{
|
||||||
clouds1A->setPosX(clouds1A->getWidth());
|
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clouds1B->getPosX() < -clouds1B->getWidth())
|
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth())
|
||||||
{
|
{
|
||||||
clouds1B->setPosX(clouds1B->getWidth());
|
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clouds2A->getPosX() < -clouds2A->getWidth())
|
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth())
|
||||||
{
|
{
|
||||||
clouds2A->setPosX(clouds2A->getWidth());
|
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clouds2B->getPosX() < -clouds2B->getWidth())
|
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth())
|
||||||
{
|
{
|
||||||
clouds2B->setPosX(clouds2B->getWidth());
|
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "common/screen.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include "common/asset.h"
|
#include <memory> // for unique_ptr, shared_ptr
|
||||||
#include "common/movingsprite.h"
|
#include "utils.h" // for Color
|
||||||
|
class MovingSprite;
|
||||||
|
class Sprite;
|
||||||
|
class Texture;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase es la encargada de dibujar el fondo que aparece durante la sección
|
Esta clase es la encargada de dibujar el fondo que aparece durante la sección
|
||||||
@@ -14,9 +17,11 @@
|
|||||||
|
|
||||||
El objeto tiene un tamaño total definido en la variable "rect". En principio este
|
El objeto tiene un tamaño total definido en la variable "rect". En principio este
|
||||||
tamaño coincide con el tamaño de la ventana o resolución del juego, pero se pinta
|
tamaño coincide con el tamaño de la ventana o resolución del juego, pero se pinta
|
||||||
solo el rectangulo definido en srcRect en la posición de la pantalla definida en
|
solo el rectangulo definido en srcRect en la posición de la pantalla definida en
|
||||||
dstRect.
|
dstRect.
|
||||||
|
|
||||||
|
Ambos rectangulos han de coincidir en tamaño y por definición, el punto comun es el inferior derecho el rectangulo.
|
||||||
|
|
||||||
Utiliza varios métodos para definir su comportamiento:
|
Utiliza varios métodos para definir su comportamiento:
|
||||||
- setCloudsSpeed(float value)
|
- setCloudsSpeed(float value)
|
||||||
Velocidad a la que se desplazan las nubes cada frame
|
Velocidad a la que se desplazan las nubes cada frame
|
||||||
@@ -27,13 +32,13 @@
|
|||||||
- setTransition(float value)
|
- setTransition(float value)
|
||||||
Porcentaje (entre 0.0f (textura actual) y 1.0f (textura siguiente)) para mostrar entre la textura de fondo actual y la siguiente
|
Porcentaje (entre 0.0f (textura actual) y 1.0f (textura siguiente)) para mostrar entre la textura de fondo actual y la siguiente
|
||||||
|
|
||||||
- setSrcDest(SDL_Rect value)
|
- setSrcRect(SDL_Rect value)
|
||||||
Rectangulo de la textura de fondo que se desea mostrar
|
Rectangulo de la textura de fondo que se desea mostrar
|
||||||
|
|
||||||
- setDstDest(SDL_Rect value)
|
- setDstRecr(SDL_Rect value)
|
||||||
Rectangulo de destino donde se mostrará el rectángulo antrior
|
Rectangulo de destino donde se mostrará el rectángulo antrior. Automaticamente modifica srcRect para coincidor en tamaño con el destino.
|
||||||
|
|
||||||
- setColor(color_t color)
|
- setColor(Color color)
|
||||||
Establece el color de la textura de superposición
|
Establece el color de la textura de superposición
|
||||||
|
|
||||||
- setAlpha(int alpha)
|
- setAlpha(int alpha)
|
||||||
@@ -44,92 +49,99 @@
|
|||||||
class Background
|
class Background
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
|
|
||||||
Texture *buildingsTexture; // Textura con los edificios de fondo
|
std::shared_ptr<Texture> buildings_texture_; // Textura con los edificios de fondo
|
||||||
Texture *clouds1Texture; // Textura con las nubes de fondo
|
std::shared_ptr<Texture> top_clouds_texture_; // Textura con las nubes de fondo
|
||||||
Texture *clouds2Texture; // Textura con las nubes de fondo
|
std::shared_ptr<Texture> bottom_clouds_texture_; // Textura con las nubes de fondo
|
||||||
Texture *grassTexture; // Textura con la hierba del suelo
|
std::shared_ptr<Texture> grass_texture_; // Textura con la hierba del suelo
|
||||||
Texture *gradientsTexture; // Textura con los diferentes colores de fondo del juego
|
std::shared_ptr<Texture> gradients_texture_; // Textura con los diferentes colores de fondo del juego
|
||||||
|
|
||||||
MovingSprite *clouds1A; // Sprite para las nubes superiores
|
std::unique_ptr<MovingSprite> top_clouds_sprite_a_; // Sprite para las nubes superiores
|
||||||
MovingSprite *clouds1B; // Sprite para las nubes superiores
|
std::unique_ptr<MovingSprite> top_clouds_sprite_b_; // Sprite para las nubes superiores
|
||||||
MovingSprite *clouds2A; // Sprite para las nubes inferiores
|
std::unique_ptr<MovingSprite> bottom_clouds_sprite_a_; // Sprite para las nubes inferiores
|
||||||
MovingSprite *clouds2B; // Sprite para las nubes inferiores
|
std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite para las nubes inferiores
|
||||||
|
|
||||||
Sprite *buildingsSprite; // Sprite con los edificios de fondo
|
std::unique_ptr<Sprite> buildings_sprite_; // Sprite con los edificios de fondo
|
||||||
Sprite *gradientSprite; // Sprite con los graficos del degradado de color de fondo
|
std::unique_ptr<Sprite> gradient_sprite_; // Sprite con los graficos del degradado de color de fondo
|
||||||
Sprite *grassSprite; // Sprite para la hierba
|
std::unique_ptr<Sprite> grass_sprite_; // Sprite para la hierba
|
||||||
|
|
||||||
SDL_Texture *canvas; // Textura para componer el fondo
|
SDL_Texture *canvas_; // Textura para componer el fondo
|
||||||
SDL_Texture *colorTexture; // Textura para atenuar el fondo
|
SDL_Texture *color_texture_; // Textura para atenuar el fondo
|
||||||
|
|
||||||
param_t *param; // Puntero con todos los parametros del programa
|
// Variables
|
||||||
|
SDL_Rect gradient_rect_[4]; // Vector con las coordenadas de los 4 degradados para el cielo
|
||||||
|
SDL_Rect top_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de arriba
|
||||||
|
SDL_Rect bottom_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de abajo
|
||||||
|
int gradient_number_; // Indica el número de degradado de fondo que se va a dibujar
|
||||||
|
int alpha_; // Transparencia entre los dos degradados
|
||||||
|
float clouds_speed_; // Velocidad a la que se desplazan las nubes
|
||||||
|
float transition_; // Nivel de transición del fondo 0..1
|
||||||
|
int counter_; // Contador interno
|
||||||
|
SDL_Rect rect_; // Tamaño del objeto fondo
|
||||||
|
SDL_Rect src_rect_; // Parte del objeto fondo que se va a dibujará en pantalla
|
||||||
|
SDL_Rect dst_rect_; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla
|
||||||
|
int base_; // Linea de fondo coincidente con el area inferior de la zona de juego
|
||||||
|
Color color_; // Color para atenuar el fondo
|
||||||
|
int alpha_color_text_; // Alpha para atenuar el fondo
|
||||||
|
int alpha_color_text_temp_; // Valor temporal para hacer la transición de alpha
|
||||||
|
|
||||||
// Variables
|
// Dibuja el gradiente de fondo
|
||||||
SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 degradados para el cielo
|
void renderGradient();
|
||||||
int gradientNumber; // Indica el número de degradado de fondo que se va a dibujar
|
|
||||||
int alpha; // Transparencia entre los dos degradados
|
|
||||||
float cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
|
||||||
float transition; // Nivel de transición del fondo 0..1
|
|
||||||
int counter; // Contador interno
|
|
||||||
SDL_Rect rect; // Tamaño del objeto fondo
|
|
||||||
SDL_Rect srcRect; // Parte del objeto fondo que se va a dibujará en pantalla
|
|
||||||
SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla
|
|
||||||
int base; // Linea de fondo coincidente con el area inferior de la zona de juego
|
|
||||||
color_t color; // Color para atenuar el fondo
|
|
||||||
int alphaColorText; // Alpha para atenuar el fondo
|
|
||||||
int alphaColorTextTemp; // Valor temporal para hacer la transición de alpha
|
|
||||||
|
|
||||||
// Compone todos los elementos del fondo en la textura
|
// Dibuja las nubes de arriba
|
||||||
void fillCanvas();
|
void renderTopClouds();
|
||||||
|
|
||||||
// Actualiza el valor de alpha
|
// Dibuja las nubes de abajo
|
||||||
void updateAlphaColorText();
|
void renderBottomClouds();
|
||||||
|
|
||||||
// Actualiza las nubes
|
// Compone todos los elementos del fondo en la textura
|
||||||
void updateCLouds();
|
void fillCanvas();
|
||||||
|
|
||||||
|
// Actualiza el valor de alpha
|
||||||
|
void updateAlphaColorText();
|
||||||
|
|
||||||
|
// Actualiza las nubes
|
||||||
|
void updateClouds();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param);
|
explicit Background(SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Background();
|
~Background();
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
// Actualiza la lógica del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Dibuja el objeto
|
// Dibuja el objeto
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void setPos(SDL_Rect);
|
void setPos(SDL_Rect pos);
|
||||||
|
|
||||||
// Vuelve a cargar las texturas
|
// Vuelve a cargar las texturas
|
||||||
void reloadTextures();
|
void reloadTextures();
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setCloudsSpeed(float value);
|
void setCloudsSpeed(float value);
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setGradientNumber(int value);
|
void setGradientNumber(int value);
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setTransition(float value);
|
void setTransition(float value);
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setSrcRect(SDL_Rect value);
|
void setSrcRect(SDL_Rect value);
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setDstRect(SDL_Rect value);
|
void setDstRect(SDL_Rect value);
|
||||||
|
|
||||||
// Establece el color de atenuación
|
// Establece el color de atenuación
|
||||||
void setColor(color_t color);
|
void setColor(Color color);
|
||||||
|
|
||||||
// Establece la transparencia de la atenuación
|
// Establece la transparencia de la atenuación
|
||||||
void setAlpha(int alpha);
|
void setAlpha(int alpha);
|
||||||
};
|
};
|
||||||
195
source/balloon.h
@@ -1,76 +1,78 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||||
#include "common/animatedsprite.h"
|
#include <memory> // for shared_ptr, unique_ptr
|
||||||
#include "common/utils.h"
|
#include <string> // for string
|
||||||
#include <sstream>
|
#include <vector> // for vector
|
||||||
#include <vector>
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
|
#include "utils.h" // for Circle
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||||
#define MAX_BOUNCE 10
|
constexpr int MAX_BOUNCE = 10;
|
||||||
|
|
||||||
// Tipos de globo
|
// Tipos de globo
|
||||||
#define BALLOON_1 1
|
constexpr int BALLOON_1 = 1;
|
||||||
#define BALLOON_2 2
|
constexpr int BALLOON_2 = 2;
|
||||||
#define BALLOON_3 3
|
constexpr int BALLOON_3 = 3;
|
||||||
#define BALLOON_4 4
|
constexpr int BALLOON_4 = 4;
|
||||||
#define HEXAGON_1 5
|
constexpr int HEXAGON_1 = 5;
|
||||||
#define HEXAGON_2 6
|
constexpr int HEXAGON_2 = 6;
|
||||||
#define HEXAGON_3 7
|
constexpr int HEXAGON_3 = 7;
|
||||||
#define HEXAGON_4 8
|
constexpr int HEXAGON_4 = 8;
|
||||||
#define POWER_BALL 9
|
constexpr int POWER_BALL = 9;
|
||||||
|
|
||||||
// Puntos de globo
|
// Puntos de globo
|
||||||
#define BALLOON_SCORE_1 50
|
constexpr int BALLOON_SCORE_1 = 50;
|
||||||
#define BALLOON_SCORE_2 100
|
constexpr int BALLOON_SCORE_2 = 100;
|
||||||
#define BALLOON_SCORE_3 200
|
constexpr int BALLOON_SCORE_3 = 200;
|
||||||
#define BALLOON_SCORE_4 400
|
constexpr int BALLOON_SCORE_4 = 400;
|
||||||
|
|
||||||
// Tamaños de globo
|
// Tamaños de globo
|
||||||
#define BALLOON_SIZE_1 1
|
constexpr int BALLOON_SIZE_1 = 1;
|
||||||
#define BALLOON_SIZE_2 2
|
constexpr int BALLOON_SIZE_2 = 2;
|
||||||
#define BALLOON_SIZE_3 3
|
constexpr int BALLOON_SIZE_3 = 3;
|
||||||
#define BALLOON_SIZE_4 4
|
constexpr int BALLOON_SIZE_4 = 4;
|
||||||
|
|
||||||
// Clases de globo
|
// Clases de globo
|
||||||
#define BALLOON_CLASS 0
|
constexpr int BALLOON_CLASS = 0;
|
||||||
#define HEXAGON_CLASS 1
|
constexpr int HEXAGON_CLASS = 1;
|
||||||
|
|
||||||
// Velocidad del globo
|
// Velocidad del globo
|
||||||
#define BALLOON_VELX_POSITIVE 0.7f
|
constexpr float BALLOON_VELX_POSITIVE = 0.7f;
|
||||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
constexpr float BALLOON_VELX_NEGATIVE = -0.7f;
|
||||||
|
|
||||||
// Indice para las animaciones de los globos
|
// Indice para las animaciones de los globos
|
||||||
#define BALLOON_MOVING_ANIMATION 0
|
constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||||
#define BALLOON_POP_ANIMATION 1
|
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||||
#define BALLOON_BORN_ANIMATION 2
|
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||||
|
|
||||||
// Cantidad posible de globos
|
// Cantidad posible de globos
|
||||||
#define MAX_BALLOONS 100
|
constexpr int MAX_BALLOONS = 100;
|
||||||
|
|
||||||
// Velocidades a las que se mueven los globos
|
// Velocidades a las que se mueven los globos
|
||||||
#define BALLOON_SPEED_1 0.60f
|
constexpr float BALLOON_SPEED_1 = 0.60f;
|
||||||
#define BALLOON_SPEED_2 0.70f
|
constexpr float BALLOON_SPEED_2 = 0.70f;
|
||||||
#define BALLOON_SPEED_3 0.80f
|
constexpr float BALLOON_SPEED_3 = 0.80f;
|
||||||
#define BALLOON_SPEED_4 0.90f
|
constexpr float BALLOON_SPEED_4 = 0.90f;
|
||||||
#define BALLOON_SPEED_5 1.00f
|
constexpr float BALLOON_SPEED_5 = 1.00f;
|
||||||
|
|
||||||
// Tamaño de los globos
|
// Tamaño de los globos
|
||||||
#define BALLOON_WIDTH_1 10
|
constexpr int BALLOON_WIDTH_1 = 10;
|
||||||
#define BALLOON_WIDTH_2 16
|
constexpr int BALLOON_WIDTH_2 = 16;
|
||||||
#define BALLOON_WIDTH_3 26
|
constexpr int BALLOON_WIDTH_3 = 26;
|
||||||
#define BALLOON_WIDTH_4 46
|
constexpr int BALLOON_WIDTH_4 = 46;
|
||||||
|
|
||||||
// PowerBall
|
// PowerBall
|
||||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||||
#define POWERBALL_COUNTER 8
|
constexpr int POWERBALL_COUNTER = 8;
|
||||||
|
|
||||||
// Clase Balloon
|
// Clase Balloon
|
||||||
class Balloon
|
class Balloon
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Estructura para las variables para el efecto de los rebotes
|
// Estructura para las variables para el efecto de los rebotes
|
||||||
struct bouncing
|
struct Bouncing
|
||||||
{
|
{
|
||||||
bool enabled; // Si el efecto está activo
|
bool enabled; // Si el efecto está activo
|
||||||
Uint8 counter; // Countador para el efecto
|
Uint8 counter; // Countador para el efecto
|
||||||
@@ -84,38 +86,37 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
AnimatedSprite *sprite; // Sprite del objeto globo
|
std::unique_ptr<AnimatedSprite> sprite_; // Sprite del objeto globo
|
||||||
param_t *param; // Puntero con todos los parametros del programa
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
float posX; // Posición en el eje X
|
float pos_x_; // Posición en el eje X
|
||||||
float posY; // Posición en el eje Y
|
float pos_y_; // Posición en el eje Y
|
||||||
Uint8 width; // Ancho
|
Uint8 width_; // Ancho
|
||||||
Uint8 height; // Alto
|
Uint8 height_; // Alto
|
||||||
float velX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
float vel_x_; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||||
float velY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
float vel_y_; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||||
float gravity; // Aceleración en el eje Y. Modifica la velocidad
|
float gravity_; // Aceleración en el eje Y. Modifica la velocidad
|
||||||
float defaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo
|
float default_vel_y_; // Velocidad inicial que tienen al rebotar contra el suelo
|
||||||
float maxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y
|
float max_vel_y_; // Máxima velocidad que puede alcanzar el objeto en el eje Y
|
||||||
bool beingCreated; // Indica si el globo se está creando
|
bool being_created_; // Indica si el globo se está creando
|
||||||
bool blinking; // Indica si el globo está intermitente
|
bool blinking_; // Indica si el globo está intermitente
|
||||||
bool enabled; // Indica si el globo esta activo
|
bool enabled_; // Indica si el globo esta activo
|
||||||
bool invulnerable; // Indica si el globo es invulnerable
|
bool invulnerable_; // Indica si el globo es invulnerable
|
||||||
bool stopped; // Indica si el globo está parado
|
bool stopped_; // Indica si el globo está parado
|
||||||
bool visible; // Indica si el globo es visible
|
bool visible_; // Indica si el globo es visible
|
||||||
circle_t collider; // Circulo de colisión del objeto
|
Circle collider_; // Circulo de colisión del objeto
|
||||||
Uint16 creationCounter; // Temporizador para controlar el estado "creandose"
|
Uint16 creation_counter_; // Temporizador para controlar el estado "creandose"
|
||||||
Uint16 creationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose"
|
Uint16 creation_counter_ini_; // Valor inicial para el temporizador para controlar el estado "creandose"
|
||||||
Uint16 score; // Puntos que da el globo al ser destruido
|
Uint16 score_; // Puntos que da el globo al ser destruido
|
||||||
Uint16 stoppedCounter; // Contador para controlar el estado "parado"
|
Uint16 stopped_counter_; // Contador para controlar el estado "parado"
|
||||||
Uint8 kind; // Tipo de globo
|
Uint8 kind_; // Tipo de globo
|
||||||
Uint8 menace; // Cantidad de amenaza que genera el globo
|
Uint8 menace_; // Cantidad de amenaza que genera el globo
|
||||||
Uint32 counter; // Contador interno
|
Uint32 counter_; // Contador interno
|
||||||
float travelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
float travel_y_; // 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
|
float speed_; // Velocidad a la que se mueven los globos
|
||||||
Uint8 size; // Tamaño del globo
|
Uint8 size_; // Tamaño del globo
|
||||||
Uint8 power; // Cantidad de poder que alberga el globo
|
Uint8 power_; // Cantidad de poder que alberga el globo
|
||||||
bouncing bouncing; // Contiene las variables para el efecto de rebote
|
Bouncing bouncing_; // Contiene las variables para el efecto de rebote
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto globo
|
// Alinea el circulo de colisión con la posición del objeto globo
|
||||||
void updateColliders();
|
void updateColliders();
|
||||||
@@ -140,10 +141,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, param_t *param);
|
Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, std::vector<std::string> *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Balloon();
|
~Balloon() = default;
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
@@ -164,86 +165,86 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Comprueba si el globo está habilitado
|
// Comprueba si el globo está habilitado
|
||||||
bool isEnabled();
|
bool isEnabled() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getPosX();
|
float getPosX() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getPosY();
|
float getPosY() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getVelY();
|
float getVelY() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getWidth();
|
int getWidth() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getHeight();
|
int getHeight() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVelY(float velY);
|
void setVelY(float vel_y);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setSpeed(float speed);
|
void setSpeed(float speed);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getKind();
|
int getKind() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint8 getSize();
|
Uint8 getSize() const;
|
||||||
|
|
||||||
// Obtiene la clase a la que pertenece el globo
|
// Obtiene la clase a la que pertenece el globo
|
||||||
Uint8 getClass();
|
Uint8 getClass() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStop(bool value);
|
void setStop(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isStopped();
|
bool isStopped() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setBlink(bool value);
|
void setBlink(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBlinking();
|
bool isBlinking() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVisible(bool value);
|
void setVisible(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isVisible();
|
bool isVisible() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setInvulnerable(bool value);
|
void setInvulnerable(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isInvulnerable();
|
bool isInvulnerable() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBeingCreated();
|
bool isBeingCreated() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStoppedTimer(Uint16 time);
|
void setStoppedTimer(Uint16 time);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getStoppedTimer();
|
Uint16 getStoppedTimer() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getScore();
|
Uint16 getScore() const;
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
Circle &getCollider();
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getMenace();
|
Uint8 getMenace() const;
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getPower();
|
Uint8 getPower() const;
|
||||||
|
|
||||||
// Indica si el globo se puede explotar
|
// Indica si el globo se puede explotar
|
||||||
bool canBePopped();
|
bool canBePopped() const;
|
||||||
|
|
||||||
// Indica si el globo se puede destruir
|
// Indica si el globo se puede destruir
|
||||||
bool canBeDestroyed();
|
bool canBeDestroyed() const;
|
||||||
};
|
};
|
||||||
718
source/balloon_formations.cpp
Normal file
@@ -0,0 +1,718 @@
|
|||||||
|
#include "balloon_formations.h"
|
||||||
|
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||||
|
#include "param.h" // for param
|
||||||
|
#include "utils.h" // for ParamGame, Param, Zone, BLOCK
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
BalloonFormations::BalloonFormations()
|
||||||
|
{
|
||||||
|
initBalloonFormations();
|
||||||
|
initBalloonFormationPools();
|
||||||
|
initGameStages();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las formaciones enemigas
|
||||||
|
void BalloonFormations::initBalloonFormations()
|
||||||
|
{
|
||||||
|
constexpr int y4 = -BLOCK;
|
||||||
|
const int x4_0 = param.game.play_area.rect.x;
|
||||||
|
const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4;
|
||||||
|
|
||||||
|
constexpr int y3 = -BLOCK;
|
||||||
|
const int x3_0 = param.game.play_area.rect.x;
|
||||||
|
const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3;
|
||||||
|
|
||||||
|
constexpr int y2 = -BLOCK;
|
||||||
|
const int x2_0 = param.game.play_area.rect.x;
|
||||||
|
const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2;
|
||||||
|
|
||||||
|
constexpr int y1 = -BLOCK;
|
||||||
|
const int x1_0 = param.game.play_area.rect.x;
|
||||||
|
const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2);
|
||||||
|
const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1;
|
||||||
|
|
||||||
|
// Inicializa a cero las variables
|
||||||
|
for (int i = 0; i < NUMBER_OF_BALLOON_FORMATIONS; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[i].number_of_balloons = 0;
|
||||||
|
for (int j = 0; j < MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION; j++)
|
||||||
|
{
|
||||||
|
balloon_formation_[i].init[j].x = 0;
|
||||||
|
balloon_formation_[i].init[j].y = 0;
|
||||||
|
balloon_formation_[i].init[j].vel_x = 0;
|
||||||
|
balloon_formation_[i].init[j].kind = 0;
|
||||||
|
balloon_formation_[i].init[j].creation_counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int creation_time = 300;
|
||||||
|
int inc_x = 0;
|
||||||
|
int inc_time = 0;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
|
// #00 - Dos enemigos BALLOON4 uno a cada extremo
|
||||||
|
j = 0;
|
||||||
|
balloon_formation_[j].number_of_balloons = 2;
|
||||||
|
inc_x = x4_100;
|
||||||
|
inc_time = 0;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y4;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro
|
||||||
|
j = 1;
|
||||||
|
balloon_formation_[j].number_of_balloons = 2;
|
||||||
|
inc_x = param.game.play_area.center_x;
|
||||||
|
inc_time = 0;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y4;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||||
|
j = 2;
|
||||||
|
balloon_formation_[j].number_of_balloons = 4;
|
||||||
|
inc_x = BALLOON_WIDTH_2 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y2;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||||
|
j = 3;
|
||||||
|
balloon_formation_[j].number_of_balloons = 4;
|
||||||
|
inc_x = BALLOON_WIDTH_2 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y2;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
|
||||||
|
j = 4;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_3 * 2;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
|
||||||
|
j = 5;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_3 * 2;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
|
||||||
|
j = 6;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_3 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
|
||||||
|
j = 7;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_3 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
|
||||||
|
j = 8;
|
||||||
|
balloon_formation_[j].number_of_balloons = 6;
|
||||||
|
inc_x = BALLOON_WIDTH_1 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
|
||||||
|
j = 9;
|
||||||
|
balloon_formation_[j].number_of_balloons = 6;
|
||||||
|
inc_x = BALLOON_WIDTH_1 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
|
||||||
|
j = 10;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_4 + 1;
|
||||||
|
inc_time = 15;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y4;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #11 - Tres enemigos BALLOON4 seguidos desde la derecha
|
||||||
|
j = 11;
|
||||||
|
balloon_formation_[j].number_of_balloons = 3;
|
||||||
|
inc_x = BALLOON_WIDTH_4 + 1;
|
||||||
|
inc_time = 15;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x4_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y4;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
|
||||||
|
j = 12;
|
||||||
|
balloon_formation_[j].number_of_balloons = 6;
|
||||||
|
inc_x = BALLOON_WIDTH_2 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y2;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
|
||||||
|
j = 13;
|
||||||
|
balloon_formation_[j].number_of_balloons = 6;
|
||||||
|
inc_x = BALLOON_WIDTH_2 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y2;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
|
||||||
|
j = 14;
|
||||||
|
balloon_formation_[j].number_of_balloons = 5;
|
||||||
|
inc_x = BALLOON_WIDTH_3 * 2;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
|
||||||
|
j = 15;
|
||||||
|
balloon_formation_[j].number_of_balloons = 5;
|
||||||
|
inc_x = BALLOON_WIDTH_3 * 2;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
|
||||||
|
j = 16;
|
||||||
|
balloon_formation_[j].number_of_balloons = 5;
|
||||||
|
inc_x = BALLOON_WIDTH_3 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
|
||||||
|
j = 17;
|
||||||
|
balloon_formation_[j].number_of_balloons = 5;
|
||||||
|
inc_x = BALLOON_WIDTH_3 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
|
||||||
|
j = 18;
|
||||||
|
balloon_formation_[j].number_of_balloons = 12;
|
||||||
|
inc_x = BALLOON_WIDTH_1 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
|
||||||
|
j = 19;
|
||||||
|
balloon_formation_[j].number_of_balloons = 12;
|
||||||
|
inc_x = BALLOON_WIDTH_1 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_100 - (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
|
||||||
|
j = 20;
|
||||||
|
balloon_formation_[j].number_of_balloons = 4;
|
||||||
|
inc_x = BALLOON_WIDTH_4 + 1;
|
||||||
|
inc_time = 0;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x4_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x4_100 - ((i - half) * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y4;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_4;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
|
||||||
|
j = 21;
|
||||||
|
balloon_formation_[j].number_of_balloons = 10;
|
||||||
|
inc_x = BALLOON_WIDTH_2 + 1;
|
||||||
|
inc_time = 3;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y2;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos
|
||||||
|
j = 22;
|
||||||
|
balloon_formation_[j].number_of_balloons = 10;
|
||||||
|
inc_x = BALLOON_WIDTH_3 * 2;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos
|
||||||
|
j = 23;
|
||||||
|
balloon_formation_[j].number_of_balloons = 10;
|
||||||
|
inc_x = BALLOON_WIDTH_3 + 1;
|
||||||
|
inc_time = 10;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_0 + (i * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x);
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y3;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos
|
||||||
|
j = 24;
|
||||||
|
balloon_formation_[j].number_of_balloons = 30;
|
||||||
|
inc_time = 5;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_50;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_50;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half));
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// #25 - Treinta enemigos BALLOON1. Del centro hacia adentro. Juntos. Simetricos
|
||||||
|
j = 25;
|
||||||
|
balloon_formation_[j].number_of_balloons = 30;
|
||||||
|
inc_time = 5;
|
||||||
|
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
const int half = balloon_formation_[j].number_of_balloons / 2;
|
||||||
|
if (i < half)
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_50 + 20;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balloon_formation_[j].init[i].x = x1_50 - 20;
|
||||||
|
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE;
|
||||||
|
balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half));
|
||||||
|
}
|
||||||
|
balloon_formation_[j].init[i].y = y1;
|
||||||
|
balloon_formation_[j].init[i].kind = BALLOON_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea las mismas formaciones pero con hexagonos a partir de la posición 50 del vector
|
||||||
|
for (int k = 0; k < j + 1; k++)
|
||||||
|
{
|
||||||
|
balloon_formation_[k + 50].number_of_balloons = balloon_formation_[k].number_of_balloons;
|
||||||
|
for (int i = 0; i < balloon_formation_[k + 50].number_of_balloons; i++)
|
||||||
|
{
|
||||||
|
balloon_formation_[k + 50].init[i].x = balloon_formation_[k].init[i].x;
|
||||||
|
balloon_formation_[k + 50].init[i].y = balloon_formation_[k].init[i].y;
|
||||||
|
balloon_formation_[k + 50].init[i].vel_x = balloon_formation_[k].init[i].vel_x;
|
||||||
|
balloon_formation_[k + 50].init[i].creation_counter = balloon_formation_[k].init[i].creation_counter;
|
||||||
|
balloon_formation_[k + 50].init[i].kind = balloon_formation_[k].init[i].kind + 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TEST
|
||||||
|
balloon_formation_[99].number_of_balloons = 4;
|
||||||
|
|
||||||
|
balloon_formation_[99].init[0].x = 10;
|
||||||
|
balloon_formation_[99].init[0].y = y1;
|
||||||
|
balloon_formation_[99].init[0].vel_x = 0;
|
||||||
|
balloon_formation_[99].init[0].kind = BALLOON_1;
|
||||||
|
balloon_formation_[99].init[0].creation_counter = 200;
|
||||||
|
|
||||||
|
balloon_formation_[99].init[1].x = 50;
|
||||||
|
balloon_formation_[99].init[1].y = y1;
|
||||||
|
balloon_formation_[99].init[1].vel_x = 0;
|
||||||
|
balloon_formation_[99].init[1].kind = BALLOON_2;
|
||||||
|
balloon_formation_[99].init[1].creation_counter = 200;
|
||||||
|
|
||||||
|
balloon_formation_[99].init[2].x = 90;
|
||||||
|
balloon_formation_[99].init[2].y = y1;
|
||||||
|
balloon_formation_[99].init[2].vel_x = 0;
|
||||||
|
balloon_formation_[99].init[2].kind = BALLOON_3;
|
||||||
|
balloon_formation_[99].init[2].creation_counter = 200;
|
||||||
|
|
||||||
|
balloon_formation_[99].init[3].x = 140;
|
||||||
|
balloon_formation_[99].init[3].y = y1;
|
||||||
|
balloon_formation_[99].init[3].vel_x = 0;
|
||||||
|
balloon_formation_[99].init[3].kind = BALLOON_4;
|
||||||
|
balloon_formation_[99].init[3].creation_counter = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa los conjuntos de formaciones
|
||||||
|
void BalloonFormations::initBalloonFormationPools()
|
||||||
|
{
|
||||||
|
// EnemyPool #0
|
||||||
|
balloon_formation_pool_[0].set[0] = &balloon_formation_[0];
|
||||||
|
balloon_formation_pool_[0].set[1] = &balloon_formation_[1];
|
||||||
|
balloon_formation_pool_[0].set[2] = &balloon_formation_[2];
|
||||||
|
balloon_formation_pool_[0].set[3] = &balloon_formation_[3];
|
||||||
|
balloon_formation_pool_[0].set[4] = &balloon_formation_[4];
|
||||||
|
balloon_formation_pool_[0].set[5] = &balloon_formation_[5];
|
||||||
|
balloon_formation_pool_[0].set[6] = &balloon_formation_[6];
|
||||||
|
balloon_formation_pool_[0].set[7] = &balloon_formation_[7];
|
||||||
|
balloon_formation_pool_[0].set[8] = &balloon_formation_[8];
|
||||||
|
balloon_formation_pool_[0].set[9] = &balloon_formation_[9];
|
||||||
|
|
||||||
|
// EnemyPool #1
|
||||||
|
balloon_formation_pool_[1].set[0] = &balloon_formation_[10];
|
||||||
|
balloon_formation_pool_[1].set[1] = &balloon_formation_[11];
|
||||||
|
balloon_formation_pool_[1].set[2] = &balloon_formation_[12];
|
||||||
|
balloon_formation_pool_[1].set[3] = &balloon_formation_[13];
|
||||||
|
balloon_formation_pool_[1].set[4] = &balloon_formation_[14];
|
||||||
|
balloon_formation_pool_[1].set[5] = &balloon_formation_[15];
|
||||||
|
balloon_formation_pool_[1].set[6] = &balloon_formation_[16];
|
||||||
|
balloon_formation_pool_[1].set[7] = &balloon_formation_[17];
|
||||||
|
balloon_formation_pool_[1].set[8] = &balloon_formation_[18];
|
||||||
|
balloon_formation_pool_[1].set[9] = &balloon_formation_[19];
|
||||||
|
|
||||||
|
// EnemyPool #2
|
||||||
|
balloon_formation_pool_[2].set[0] = &balloon_formation_[0];
|
||||||
|
balloon_formation_pool_[2].set[1] = &balloon_formation_[1];
|
||||||
|
balloon_formation_pool_[2].set[2] = &balloon_formation_[2];
|
||||||
|
balloon_formation_pool_[2].set[3] = &balloon_formation_[3];
|
||||||
|
balloon_formation_pool_[2].set[4] = &balloon_formation_[4];
|
||||||
|
balloon_formation_pool_[2].set[5] = &balloon_formation_[55];
|
||||||
|
balloon_formation_pool_[2].set[6] = &balloon_formation_[56];
|
||||||
|
balloon_formation_pool_[2].set[7] = &balloon_formation_[57];
|
||||||
|
balloon_formation_pool_[2].set[8] = &balloon_formation_[58];
|
||||||
|
balloon_formation_pool_[2].set[9] = &balloon_formation_[59];
|
||||||
|
|
||||||
|
// EnemyPool #3
|
||||||
|
balloon_formation_pool_[3].set[0] = &balloon_formation_[50];
|
||||||
|
balloon_formation_pool_[3].set[1] = &balloon_formation_[51];
|
||||||
|
balloon_formation_pool_[3].set[2] = &balloon_formation_[52];
|
||||||
|
balloon_formation_pool_[3].set[3] = &balloon_formation_[53];
|
||||||
|
balloon_formation_pool_[3].set[4] = &balloon_formation_[54];
|
||||||
|
balloon_formation_pool_[3].set[5] = &balloon_formation_[5];
|
||||||
|
balloon_formation_pool_[3].set[6] = &balloon_formation_[6];
|
||||||
|
balloon_formation_pool_[3].set[7] = &balloon_formation_[7];
|
||||||
|
balloon_formation_pool_[3].set[8] = &balloon_formation_[8];
|
||||||
|
balloon_formation_pool_[3].set[9] = &balloon_formation_[9];
|
||||||
|
|
||||||
|
// EnemyPool #4
|
||||||
|
balloon_formation_pool_[4].set[0] = &balloon_formation_[60];
|
||||||
|
balloon_formation_pool_[4].set[1] = &balloon_formation_[61];
|
||||||
|
balloon_formation_pool_[4].set[2] = &balloon_formation_[62];
|
||||||
|
balloon_formation_pool_[4].set[3] = &balloon_formation_[63];
|
||||||
|
balloon_formation_pool_[4].set[4] = &balloon_formation_[64];
|
||||||
|
balloon_formation_pool_[4].set[5] = &balloon_formation_[65];
|
||||||
|
balloon_formation_pool_[4].set[6] = &balloon_formation_[66];
|
||||||
|
balloon_formation_pool_[4].set[7] = &balloon_formation_[67];
|
||||||
|
balloon_formation_pool_[4].set[8] = &balloon_formation_[68];
|
||||||
|
balloon_formation_pool_[4].set[9] = &balloon_formation_[69];
|
||||||
|
|
||||||
|
// EnemyPool #5
|
||||||
|
balloon_formation_pool_[5].set[0] = &balloon_formation_[10];
|
||||||
|
balloon_formation_pool_[5].set[1] = &balloon_formation_[61];
|
||||||
|
balloon_formation_pool_[5].set[2] = &balloon_formation_[12];
|
||||||
|
balloon_formation_pool_[5].set[3] = &balloon_formation_[63];
|
||||||
|
balloon_formation_pool_[5].set[4] = &balloon_formation_[14];
|
||||||
|
balloon_formation_pool_[5].set[5] = &balloon_formation_[65];
|
||||||
|
balloon_formation_pool_[5].set[6] = &balloon_formation_[16];
|
||||||
|
balloon_formation_pool_[5].set[7] = &balloon_formation_[67];
|
||||||
|
balloon_formation_pool_[5].set[8] = &balloon_formation_[18];
|
||||||
|
balloon_formation_pool_[5].set[9] = &balloon_formation_[69];
|
||||||
|
|
||||||
|
// EnemyPool #6
|
||||||
|
balloon_formation_pool_[6].set[0] = &balloon_formation_[60];
|
||||||
|
balloon_formation_pool_[6].set[1] = &balloon_formation_[11];
|
||||||
|
balloon_formation_pool_[6].set[2] = &balloon_formation_[62];
|
||||||
|
balloon_formation_pool_[6].set[3] = &balloon_formation_[13];
|
||||||
|
balloon_formation_pool_[6].set[4] = &balloon_formation_[64];
|
||||||
|
balloon_formation_pool_[6].set[5] = &balloon_formation_[15];
|
||||||
|
balloon_formation_pool_[6].set[6] = &balloon_formation_[66];
|
||||||
|
balloon_formation_pool_[6].set[7] = &balloon_formation_[17];
|
||||||
|
balloon_formation_pool_[6].set[8] = &balloon_formation_[68];
|
||||||
|
balloon_formation_pool_[6].set[9] = &balloon_formation_[19];
|
||||||
|
|
||||||
|
// EnemyPool #7
|
||||||
|
balloon_formation_pool_[7].set[0] = &balloon_formation_[20];
|
||||||
|
balloon_formation_pool_[7].set[1] = &balloon_formation_[21];
|
||||||
|
balloon_formation_pool_[7].set[2] = &balloon_formation_[22];
|
||||||
|
balloon_formation_pool_[7].set[3] = &balloon_formation_[23];
|
||||||
|
balloon_formation_pool_[7].set[4] = &balloon_formation_[24];
|
||||||
|
balloon_formation_pool_[7].set[5] = &balloon_formation_[65];
|
||||||
|
balloon_formation_pool_[7].set[6] = &balloon_formation_[66];
|
||||||
|
balloon_formation_pool_[7].set[7] = &balloon_formation_[67];
|
||||||
|
balloon_formation_pool_[7].set[8] = &balloon_formation_[68];
|
||||||
|
balloon_formation_pool_[7].set[9] = &balloon_formation_[69];
|
||||||
|
|
||||||
|
// EnemyPool #8
|
||||||
|
balloon_formation_pool_[8].set[0] = &balloon_formation_[70];
|
||||||
|
balloon_formation_pool_[8].set[1] = &balloon_formation_[71];
|
||||||
|
balloon_formation_pool_[8].set[2] = &balloon_formation_[72];
|
||||||
|
balloon_formation_pool_[8].set[3] = &balloon_formation_[73];
|
||||||
|
balloon_formation_pool_[8].set[4] = &balloon_formation_[74];
|
||||||
|
balloon_formation_pool_[8].set[5] = &balloon_formation_[15];
|
||||||
|
balloon_formation_pool_[8].set[6] = &balloon_formation_[16];
|
||||||
|
balloon_formation_pool_[8].set[7] = &balloon_formation_[17];
|
||||||
|
balloon_formation_pool_[8].set[8] = &balloon_formation_[18];
|
||||||
|
balloon_formation_pool_[8].set[9] = &balloon_formation_[19];
|
||||||
|
|
||||||
|
// EnemyPool #9
|
||||||
|
balloon_formation_pool_[9].set[0] = &balloon_formation_[20];
|
||||||
|
balloon_formation_pool_[9].set[1] = &balloon_formation_[21];
|
||||||
|
balloon_formation_pool_[9].set[2] = &balloon_formation_[22];
|
||||||
|
balloon_formation_pool_[9].set[3] = &balloon_formation_[23];
|
||||||
|
balloon_formation_pool_[9].set[4] = &balloon_formation_[24];
|
||||||
|
balloon_formation_pool_[9].set[5] = &balloon_formation_[70];
|
||||||
|
balloon_formation_pool_[9].set[6] = &balloon_formation_[71];
|
||||||
|
balloon_formation_pool_[9].set[7] = &balloon_formation_[72];
|
||||||
|
balloon_formation_pool_[9].set[8] = &balloon_formation_[73];
|
||||||
|
balloon_formation_pool_[9].set[9] = &balloon_formation_[74];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las fases del juego
|
||||||
|
void BalloonFormations::initGameStages()
|
||||||
|
{
|
||||||
|
// STAGE 1
|
||||||
|
stage_[0].number = 1;
|
||||||
|
stage_[0].power_to_complete = 200;
|
||||||
|
stage_[0].min_menace = 7 + (4 * 1);
|
||||||
|
stage_[0].max_menace = 7 + (4 * 3);
|
||||||
|
stage_[0].balloon_pool = &balloon_formation_pool_[0];
|
||||||
|
|
||||||
|
// STAGE 2
|
||||||
|
stage_[1].number = 2;
|
||||||
|
stage_[1].power_to_complete = 300;
|
||||||
|
stage_[1].min_menace = 7 + (4 * 2);
|
||||||
|
stage_[1].max_menace = 7 + (4 * 4);
|
||||||
|
stage_[1].balloon_pool = &balloon_formation_pool_[1];
|
||||||
|
|
||||||
|
// STAGE 3
|
||||||
|
stage_[2].number = 3;
|
||||||
|
stage_[2].power_to_complete = 600;
|
||||||
|
stage_[2].min_menace = 7 + (4 * 3);
|
||||||
|
stage_[2].max_menace = 7 + (4 * 5);
|
||||||
|
stage_[2].balloon_pool = &balloon_formation_pool_[2];
|
||||||
|
|
||||||
|
// STAGE 4
|
||||||
|
stage_[3].number = 4;
|
||||||
|
stage_[3].power_to_complete = 600;
|
||||||
|
stage_[3].min_menace = 7 + (4 * 3);
|
||||||
|
stage_[3].max_menace = 7 + (4 * 5);
|
||||||
|
stage_[3].balloon_pool = &balloon_formation_pool_[3];
|
||||||
|
|
||||||
|
// STAGE 5
|
||||||
|
stage_[4].number = 5;
|
||||||
|
stage_[4].power_to_complete = 600;
|
||||||
|
stage_[4].min_menace = 7 + (4 * 4);
|
||||||
|
stage_[4].max_menace = 7 + (4 * 6);
|
||||||
|
stage_[4].balloon_pool = &balloon_formation_pool_[4];
|
||||||
|
|
||||||
|
// STAGE 6
|
||||||
|
stage_[5].number = 6;
|
||||||
|
stage_[5].power_to_complete = 600;
|
||||||
|
stage_[5].min_menace = 7 + (4 * 4);
|
||||||
|
stage_[5].max_menace = 7 + (4 * 6);
|
||||||
|
stage_[5].balloon_pool = &balloon_formation_pool_[5];
|
||||||
|
|
||||||
|
// STAGE 7
|
||||||
|
stage_[6].number = 7;
|
||||||
|
stage_[6].power_to_complete = 650;
|
||||||
|
stage_[6].min_menace = 7 + (4 * 5);
|
||||||
|
stage_[6].max_menace = 7 + (4 * 7);
|
||||||
|
stage_[6].balloon_pool = &balloon_formation_pool_[6];
|
||||||
|
|
||||||
|
// STAGE 8
|
||||||
|
stage_[7].number = 8;
|
||||||
|
stage_[7].power_to_complete = 750;
|
||||||
|
stage_[7].min_menace = 7 + (4 * 5);
|
||||||
|
stage_[7].max_menace = 7 + (4 * 7);
|
||||||
|
stage_[7].balloon_pool = &balloon_formation_pool_[7];
|
||||||
|
|
||||||
|
// STAGE 9
|
||||||
|
stage_[8].number = 9;
|
||||||
|
stage_[8].power_to_complete = 850;
|
||||||
|
stage_[8].min_menace = 7 + (4 * 6);
|
||||||
|
stage_[8].max_menace = 7 + (4 * 8);
|
||||||
|
stage_[8].balloon_pool = &balloon_formation_pool_[8];
|
||||||
|
|
||||||
|
// STAGE 10
|
||||||
|
stage_[9].number = 10;
|
||||||
|
stage_[9].power_to_complete = 950;
|
||||||
|
stage_[9].min_menace = 7 + (4 * 7);
|
||||||
|
stage_[9].max_menace = 7 + (4 * 10);
|
||||||
|
stage_[9].balloon_pool = &balloon_formation_pool_[9];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve una fase
|
||||||
|
Stage BalloonFormations::getStage(int index) const
|
||||||
|
{
|
||||||
|
return stage_[index];
|
||||||
|
}
|
||||||
63
source/balloon_formations.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100;
|
||||||
|
constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50;
|
||||||
|
|
||||||
|
// Estructuras
|
||||||
|
struct BalloonFormationParams
|
||||||
|
{
|
||||||
|
int x; // Posición en el eje X donde crear al enemigo
|
||||||
|
int y; // Posición en el eje Y donde crear al enemigo
|
||||||
|
float vel_x; // Velocidad inicial en el eje X
|
||||||
|
int kind; // Tipo de enemigo
|
||||||
|
int creation_counter; // Temporizador para la creación del enemigo
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BalloonFormationUnit // Contiene la información de una formación enemiga
|
||||||
|
{
|
||||||
|
int number_of_balloons; // Cantidad de enemigos que forman la formación
|
||||||
|
BalloonFormationParams init[MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BalloonFormationPool
|
||||||
|
{
|
||||||
|
BalloonFormationUnit *set[10]; // Conjunto de formaciones de globos
|
||||||
|
};
|
||||||
|
|
||||||
|
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_[10]; // Variable con los datos de cada pantalla
|
||||||
|
BalloonFormationUnit balloon_formation_[NUMBER_OF_BALLOON_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||||
|
BalloonFormationPool balloon_formation_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||||
|
|
||||||
|
// Inicializa las formaciones enemigas
|
||||||
|
void initBalloonFormations();
|
||||||
|
|
||||||
|
// Inicializa los conjuntos de formaciones
|
||||||
|
void initBalloonFormationPools();
|
||||||
|
|
||||||
|
// Inicializa las fases del juego
|
||||||
|
void initGameStages();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
BalloonFormations();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~BalloonFormations() = default;
|
||||||
|
|
||||||
|
// Devuelve una fase
|
||||||
|
Stage getStage(int index) const;
|
||||||
|
};
|
||||||
@@ -1,213 +1,121 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
|
#include <memory> // for unique_ptr, make_unique, shared_ptr
|
||||||
|
#include "param.h" // for param
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
constexpr int BULLET_WIDTH = 12;
|
||||||
|
constexpr int BULLET_HEIGHT = 12;
|
||||||
|
constexpr int BULLET_VELY = -3;
|
||||||
|
constexpr int BULLET_VELX_LEFT = -2;
|
||||||
|
constexpr int BULLET_VELX_RIGHT = 2;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture)
|
Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture)
|
||||||
|
: sprite_(std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture)),
|
||||||
|
pos_x_(x),
|
||||||
|
pos_y_(y),
|
||||||
|
width_(BULLET_WIDTH),
|
||||||
|
height_(BULLET_HEIGHT),
|
||||||
|
vel_x_(0),
|
||||||
|
vel_y_(BULLET_VELY),
|
||||||
|
kind_(kind),
|
||||||
|
owner_(owner),
|
||||||
|
play_area_(play_area)
|
||||||
{
|
{
|
||||||
|
vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||||
|
: 0;
|
||||||
|
|
||||||
// Posición inicial del objeto
|
auto sprite_offset = powered_up ? 3 : 0;
|
||||||
posX = x;
|
auto kind_index = static_cast<int>(kind);
|
||||||
posY = y;
|
sprite_->setSpriteClip((kind_index + sprite_offset) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
collider_.r = width_ / 2;
|
||||||
width = 12;
|
shiftColliders();
|
||||||
height = 12;
|
|
||||||
|
|
||||||
// Crea el sprite
|
|
||||||
sprite = new Sprite({x, y, width, height}, texture);
|
|
||||||
|
|
||||||
// Velocidad inicial en el eje Y
|
|
||||||
velY = -3;
|
|
||||||
|
|
||||||
// Tipo de bala
|
|
||||||
this->kind = kind;
|
|
||||||
|
|
||||||
// Identificador del dueño del objeto
|
|
||||||
this->owner = owner;
|
|
||||||
|
|
||||||
// Valores especificos según el tipo
|
|
||||||
switch (kind)
|
|
||||||
{
|
|
||||||
case BULLET_UP:
|
|
||||||
// Establece la velocidad inicial
|
|
||||||
velX = 0;
|
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
|
||||||
if (!poweredUp)
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip(0 * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip((0 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BULLET_LEFT:
|
|
||||||
// Establece la velocidad inicial
|
|
||||||
velX = -2;
|
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
|
||||||
if (!poweredUp)
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip(1 * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip((1 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BULLET_RIGHT:
|
|
||||||
// Establece la velocidad inicial
|
|
||||||
velX = 2;
|
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
|
||||||
if (!poweredUp)
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip(2 * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite->setSpriteClip((2 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño del circulo de colisión
|
|
||||||
collider.r = width / 2;
|
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
|
||||||
shiftColliders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Implementación de render (llama al render del sprite_)
|
||||||
Bullet::~Bullet()
|
|
||||||
{
|
|
||||||
delete sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
|
||||||
void Bullet::render()
|
void Bullet::render()
|
||||||
{
|
{
|
||||||
sprite->render();
|
sprite_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición y estado del objeto en horizontal
|
// Implementación del movimiento usando BulletMoveStatus
|
||||||
Uint8 Bullet::move()
|
BulletMoveStatus Bullet::move()
|
||||||
{
|
{
|
||||||
// Variable con el valor de retorno
|
pos_x_ += vel_x_;
|
||||||
Uint8 msg = BULLET_MOVE_OK;
|
if (pos_x_ < param.game.play_area.rect.x - width_ || pos_x_ > play_area_->w)
|
||||||
|
{
|
||||||
|
disable();
|
||||||
|
return BulletMoveStatus::OUT;
|
||||||
|
}
|
||||||
|
|
||||||
// Mueve el objeto a su nueva posición
|
pos_y_ += vel_y_;
|
||||||
posX += velX;
|
if (pos_y_ < param.game.play_area.rect.y - height_)
|
||||||
|
{
|
||||||
|
disable();
|
||||||
|
return BulletMoveStatus::OUT;
|
||||||
|
}
|
||||||
|
|
||||||
// Si el objeto se sale del area de juego por los laterales
|
sprite_->setPosX(pos_x_);
|
||||||
if ((posX < PLAY_AREA_LEFT - width) || (posX > PLAY_AREA_RIGHT))
|
sprite_->setPosY(pos_y_);
|
||||||
{
|
shiftColliders();
|
||||||
// Se deshabilita
|
|
||||||
kind = NO_KIND;
|
|
||||||
|
|
||||||
// Mensaje de salida
|
return BulletMoveStatus::OK;
|
||||||
msg = BULLET_MOVE_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mueve el objeto a su nueva posición en vertical
|
|
||||||
posY += int(velY);
|
|
||||||
|
|
||||||
// Si el objeto se sale del area de juego por la parte superior
|
|
||||||
if (posY < PLAY_AREA_TOP - height)
|
|
||||||
{
|
|
||||||
// Se deshabilita
|
|
||||||
kind = NO_KIND;
|
|
||||||
|
|
||||||
// Mensaje de salida
|
|
||||||
msg = BULLET_MOVE_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
|
||||||
sprite->setPosX(posX);
|
|
||||||
sprite->setPosY(posY);
|
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
|
||||||
shiftColliders();
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el objeto está habilitado
|
bool Bullet::isEnabled() const
|
||||||
bool Bullet::isEnabled()
|
|
||||||
{
|
{
|
||||||
if (kind == NO_KIND)
|
return kind_ != BulletType::NONE;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita el objeto
|
|
||||||
void Bullet::disable()
|
void Bullet::disable()
|
||||||
{
|
{
|
||||||
kind = NO_KIND;
|
kind_ = BulletType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
int Bullet::getPosX() const
|
||||||
int Bullet::getPosX()
|
|
||||||
{
|
{
|
||||||
return posX;
|
return pos_x_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
int Bullet::getPosY() const
|
||||||
int Bullet::getPosY()
|
|
||||||
{
|
{
|
||||||
return posY;
|
return pos_y_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Bullet::setPosX(int x)
|
void Bullet::setPosX(int x)
|
||||||
{
|
{
|
||||||
posX = x;
|
pos_x_ = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Bullet::setPosY(int y)
|
void Bullet::setPosY(int y)
|
||||||
{
|
{
|
||||||
posY = y;
|
pos_y_ = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
int Bullet::getVelY() const
|
||||||
int Bullet::getVelY()
|
|
||||||
{
|
{
|
||||||
return velY;
|
return vel_y_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
BulletType Bullet::getKind() const
|
||||||
int Bullet::getKind()
|
|
||||||
{
|
{
|
||||||
return kind;
|
return kind_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
int Bullet::getOwner() const
|
||||||
int Bullet::getOwner()
|
|
||||||
{
|
{
|
||||||
return owner;
|
return owner_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
Circle &Bullet::getCollider()
|
||||||
circle_t &Bullet::getCollider()
|
|
||||||
{
|
{
|
||||||
return collider;
|
return collider_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
|
||||||
void Bullet::shiftColliders()
|
void Bullet::shiftColliders()
|
||||||
{
|
{
|
||||||
collider.x = posX + collider.r;
|
collider_.x = pos_x_ + collider_.r;
|
||||||
collider.y = posY + collider.r;
|
collider_.y = pos_y_ + collider_.r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +1,79 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include "common/sprite.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include "common/utils.h"
|
#include <memory> // for shared_ptr, unique_ptr
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "utils.h" // for Circle
|
||||||
|
class Texture;
|
||||||
|
|
||||||
// Tipos de bala
|
// Enumeración para los diferentes tipos de balas
|
||||||
#define BULLET_UP 1
|
enum class BulletType
|
||||||
#define BULLET_LEFT 2
|
{
|
||||||
#define BULLET_RIGHT 3
|
UP,
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
NONE
|
||||||
|
};
|
||||||
|
|
||||||
// Tipos de retorno de la funcion move de la bala
|
// Enumeración para los resultados del movimiento de la bala
|
||||||
#define BULLET_MOVE_OK 0
|
enum class BulletMoveStatus : Uint8
|
||||||
#define BULLET_MOVE_OUT 1
|
{
|
||||||
|
OK = 0,
|
||||||
|
OUT = 1
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Bullet
|
// Clase Bullet
|
||||||
class Bullet
|
class Bullet
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
std::unique_ptr<Sprite> sprite_; // Sprite con los gráficos y métodos de pintado
|
||||||
Sprite *sprite; // Sprite con los graficos y métodos de pintado
|
|
||||||
|
|
||||||
// Variables
|
int pos_x_; // Posición en el eje X
|
||||||
int posX; // Posición en el eje X
|
int pos_y_; // Posición en el eje Y
|
||||||
int posY; // Posición en el eje Y
|
Uint8 width_; // Ancho del objeto
|
||||||
Uint8 width; // Ancho del objeto
|
Uint8 height_; // Alto del objeto
|
||||||
Uint8 height; // Alto del objeto
|
|
||||||
int velX; // Velocidad en el eje X
|
|
||||||
int velY; // Velocidad en el eje Y
|
|
||||||
int kind; // Tipo de objeto
|
|
||||||
int owner; // Identificador del dueño del objeto
|
|
||||||
circle_t collider; // Circulo de colisión del objeto
|
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
int vel_x_; // Velocidad en el eje X
|
||||||
void shiftColliders();
|
int vel_y_; // Velocidad en el eje Y
|
||||||
|
|
||||||
|
BulletType kind_; // Tipo de objeto
|
||||||
|
int owner_; // Identificador del dueño del objeto
|
||||||
|
Circle collider_; // Círculo de colisión del objeto
|
||||||
|
SDL_Rect *play_area_; // Rectángulo con la zona de juego
|
||||||
|
|
||||||
|
void shiftColliders(); // Alinea el círculo de colisión con el objeto
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture);
|
Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Bullet();
|
~Bullet() = default;
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Actualiza la posición y estado del objeto
|
// Actualiza la posición y estado del objeto
|
||||||
Uint8 move();
|
BulletMoveStatus move();
|
||||||
|
|
||||||
// Comprueba si el objeto está habilitado
|
// Comprueba si el objeto está habilitado
|
||||||
bool isEnabled();
|
bool isEnabled() const;
|
||||||
|
|
||||||
// Deshabilita el objeto
|
// Deshabilita el objeto
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene la posición
|
||||||
int getPosX();
|
int getPosX() const;
|
||||||
|
int getPosY() const;
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Establece la posición
|
||||||
int getPosY();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setPosX(int x);
|
void setPosX(int x);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setPosY(int y);
|
void setPosY(int y);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene parámetros
|
||||||
int getVelY();
|
int getVelY() const;
|
||||||
|
BulletType getKind() const;
|
||||||
// Obtiene el valor de la variable
|
int getOwner() const;
|
||||||
int getKind();
|
Circle &getCollider();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
int getOwner();
|
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
|
||||||
circle_t &getCollider();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,206 +0,0 @@
|
|||||||
#include "asset.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Asset::Asset(std::string executablePath)
|
|
||||||
{
|
|
||||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
|
||||||
longestName = 0;
|
|
||||||
verbose = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
|
||||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
|
||||||
{
|
|
||||||
item_t temp;
|
|
||||||
temp.file = absolute ? file : executablePath + file;
|
|
||||||
temp.type = type;
|
|
||||||
temp.required = required;
|
|
||||||
fileList.push_back(temp);
|
|
||||||
|
|
||||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
|
||||||
longestName = SDL_max(longestName, filename.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
|
||||||
std::string Asset::get(std::string text)
|
|
||||||
{
|
|
||||||
for (auto f : fileList)
|
|
||||||
{
|
|
||||||
const size_t lastIndex = f.file.find_last_of("/") + 1;
|
|
||||||
const std::string file = f.file.substr(lastIndex, std::string::npos);
|
|
||||||
|
|
||||||
if (file == text)
|
|
||||||
{
|
|
||||||
return f.file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba que existen todos los elementos
|
|
||||||
bool Asset::check()
|
|
||||||
{
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "\n** Checking files" << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Executable path is: " << executablePath << std::endl;
|
|
||||||
std::cout << "Sample filepath: " << fileList.back().file << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
|
||||||
for (int type = 0; type < t_maxAssetType; ++type)
|
|
||||||
{
|
|
||||||
// Comprueba si hay ficheros de ese tipo
|
|
||||||
bool any = false;
|
|
||||||
|
|
||||||
for (auto f : fileList)
|
|
||||||
{
|
|
||||||
if ((f.required) && (f.type == type))
|
|
||||||
{
|
|
||||||
any = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si hay ficheros de ese tipo, comprueba si existen
|
|
||||||
if (any)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto f : fileList)
|
|
||||||
{
|
|
||||||
if ((f.required) && (f.type == type))
|
|
||||||
{
|
|
||||||
success &= checkFile(f.file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resultado
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
std::cout << "\n** All files OK.\n"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "\n** A file is missing. Exiting.\n"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
|
||||||
bool Asset::checkFile(std::string path)
|
|
||||||
{
|
|
||||||
bool success = false;
|
|
||||||
std::string result = "ERROR";
|
|
||||||
|
|
||||||
// Comprueba si existe el fichero
|
|
||||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
|
||||||
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb");
|
|
||||||
|
|
||||||
if (file != nullptr)
|
|
||||||
{
|
|
||||||
result = "OK";
|
|
||||||
success = true;
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
|
||||||
std::cout << "Checking file: ";
|
|
||||||
std::cout.width(longestName + 2);
|
|
||||||
std::cout.fill('.');
|
|
||||||
std::cout << filename + " ";
|
|
||||||
std::cout << " [" + result + "]" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve el nombre del tipo de recurso
|
|
||||||
std::string Asset::getTypeName(int type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case t_bitmap:
|
|
||||||
return "BITMAP";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_music:
|
|
||||||
return "MUSIC";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_sound:
|
|
||||||
return "SOUND";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_font:
|
|
||||||
return "FONT";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_lang:
|
|
||||||
return "LANG";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_data:
|
|
||||||
return "DATA";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_animation:
|
|
||||||
return "ANIMATION";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_palette:
|
|
||||||
return "PALETTE";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case t_item:
|
|
||||||
return "ITEM";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return "ERROR";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si ha de mostrar texto por pantalla
|
|
||||||
void Asset::setVerbose(bool value)
|
|
||||||
{
|
|
||||||
verbose = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve la lista de recursos de un tipo
|
|
||||||
std::vector<std::string> Asset::getListByType(assetType type)
|
|
||||||
{
|
|
||||||
std::vector<std::string> list;
|
|
||||||
|
|
||||||
for (auto f : fileList)
|
|
||||||
{
|
|
||||||
if (f.type == type)
|
|
||||||
{
|
|
||||||
list.push_back(f.file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
enum assetType
|
|
||||||
{
|
|
||||||
t_bitmap,
|
|
||||||
t_music,
|
|
||||||
t_sound,
|
|
||||||
t_font,
|
|
||||||
t_lang,
|
|
||||||
t_data,
|
|
||||||
t_animation,
|
|
||||||
t_palette,
|
|
||||||
t_item,
|
|
||||||
t_maxAssetType
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clase Asset
|
|
||||||
class Asset
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
// Estructura para definir un item
|
|
||||||
struct item_t
|
|
||||||
{
|
|
||||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
|
||||||
enum assetType type; // Indica el tipo de recurso
|
|
||||||
bool required; // Indica si es un fichero que debe de existir
|
|
||||||
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
|
||||||
};
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
|
||||||
std::vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
|
||||||
std::string executablePath; // Ruta al ejecutable
|
|
||||||
bool verbose; // Indica si ha de mostrar información por pantalla
|
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
|
||||||
bool checkFile(std::string executablePath);
|
|
||||||
|
|
||||||
// Devuelve el nombre del tipo de recurso
|
|
||||||
std::string getTypeName(int type);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Asset(std::string path);
|
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
|
||||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
|
||||||
|
|
||||||
// Devuelve un elemento de la lista a partir de una cadena
|
|
||||||
std::string get(std::string text);
|
|
||||||
|
|
||||||
// Comprueba que existen todos los elementos
|
|
||||||
bool check();
|
|
||||||
|
|
||||||
// Establece si ha de mostrar texto por pantalla
|
|
||||||
void setVerbose(bool value);
|
|
||||||
|
|
||||||
// Devuelve la lista de recursos de un tipo
|
|
||||||
std::vector<std::string> getListByType(assetType type);
|
|
||||||
};
|
|
||||||
@@ -1,496 +0,0 @@
|
|||||||
#include "input.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Input::Input(std::string file)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
verbose = false;
|
|
||||||
enabled = true;
|
|
||||||
|
|
||||||
// Fichero gamecontrollerdb.txt
|
|
||||||
dbPath = file;
|
|
||||||
|
|
||||||
// Busca si hay mandos conectados
|
|
||||||
discoverGameControllers();
|
|
||||||
|
|
||||||
// Inicializa las vectores
|
|
||||||
keyBindings_t kb;
|
|
||||||
kb.scancode = 0;
|
|
||||||
kb.active = false;
|
|
||||||
keyBindings.resize(input_number_of_inputs, kb);
|
|
||||||
|
|
||||||
GameControllerBindings_t gcb;
|
|
||||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
|
||||||
gcb.active = false;
|
|
||||||
gameControllerBindings.resize(numGamepads);
|
|
||||||
for (int i = 0; i < numGamepads; ++i)
|
|
||||||
{
|
|
||||||
gameControllerBindings[i].resize(input_number_of_inputs, gcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
|
|
||||||
gameInputs.clear();
|
|
||||||
gameInputs.push_back(input_fire_left);
|
|
||||||
gameInputs.push_back(input_fire_center);
|
|
||||||
gameInputs.push_back(input_fire_right);
|
|
||||||
gameInputs.push_back(input_up);
|
|
||||||
gameInputs.push_back(input_down);
|
|
||||||
gameInputs.push_back(input_left);
|
|
||||||
gameInputs.push_back(input_right);
|
|
||||||
|
|
||||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
|
||||||
buttonInputs.clear();
|
|
||||||
buttonInputs.push_back(input_fire_left);
|
|
||||||
buttonInputs.push_back(input_fire_center);
|
|
||||||
buttonInputs.push_back(input_fire_right);
|
|
||||||
buttonInputs.push_back(input_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
|
||||||
void Input::update()
|
|
||||||
{
|
|
||||||
if (disabledUntil == d_keyPressed && !checkAnyInput())
|
|
||||||
{
|
|
||||||
enable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
|
||||||
void Input::bindKey(inputs_e input, SDL_Scancode code)
|
|
||||||
{
|
|
||||||
keyBindings[input].scancode = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
|
||||||
void Input::bindGameControllerButton(int index, inputs_e input, SDL_GameControllerButton button)
|
|
||||||
{
|
|
||||||
if (index >= (int)connectedControllers.size())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gameControllerBindings[index][input].button = button;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
|
||||||
bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
|
|
||||||
{
|
|
||||||
if (!enabled)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool successKeyboard = false;
|
|
||||||
bool successGameController = false;
|
|
||||||
|
|
||||||
if (device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
|
||||||
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (keyStates[keyBindings[input].scancode] != 0)
|
|
||||||
{
|
|
||||||
successKeyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successKeyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!keyBindings[input].active)
|
|
||||||
{
|
|
||||||
if (keyStates[keyBindings[input].scancode] != 0)
|
|
||||||
{
|
|
||||||
keyBindings[input].active = true;
|
|
||||||
successKeyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successKeyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (keyStates[keyBindings[input].scancode] == 0)
|
|
||||||
{
|
|
||||||
keyBindings[input].active = false;
|
|
||||||
successKeyboard = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successKeyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameControllerFound() && index < numGamepads)
|
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
|
||||||
{
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
|
||||||
{
|
|
||||||
successGameController = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successGameController = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!gameControllerBindings[index][input].active)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) != 0)
|
|
||||||
{
|
|
||||||
gameControllerBindings[index][input].active = true;
|
|
||||||
successGameController = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successGameController = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][input].button) == 0)
|
|
||||||
{
|
|
||||||
gameControllerBindings[index][input].active = false;
|
|
||||||
successGameController = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
successGameController = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (successKeyboard || successGameController);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
|
||||||
bool Input::checkAnyInput(int device, int index)
|
|
||||||
{
|
|
||||||
if (device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)keyBindings.size(); ++i)
|
|
||||||
{
|
|
||||||
if (mKeystates[keyBindings[i].scancode] != 0 && !keyBindings[i].active)
|
|
||||||
{
|
|
||||||
keyBindings[i].active = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameControllerFound())
|
|
||||||
{
|
|
||||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[index][i].button) != 0 && !gameControllerBindings[index][i].active)
|
|
||||||
{
|
|
||||||
gameControllerBindings[index][i].active = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si hay algún botón pulsado. Devuelve 0 en caso de no encontrar nada o el indice del dispositivo + 1. Se hace así para poder gastar el valor devuelto como un valor "booleano"
|
|
||||||
int Input::checkAnyButtonPressed(bool repeat)
|
|
||||||
{
|
|
||||||
// Solo comprueba los botones
|
|
||||||
for (auto bi : buttonInputs)
|
|
||||||
{
|
|
||||||
// Comprueba el teclado
|
|
||||||
if (checkInput(bi, repeat, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los mandos
|
|
||||||
for (int i = 0; i < numGamepads; ++i)
|
|
||||||
{
|
|
||||||
if (checkInput(bi, repeat, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Busca si hay mandos conectados
|
|
||||||
bool Input::discoverGameControllers()
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
|
||||||
{
|
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
numJoysticks = SDL_NumJoysticks();
|
|
||||||
numGamepads = 0;
|
|
||||||
|
|
||||||
// Cuenta el número de mandos
|
|
||||||
joysticks.clear();
|
|
||||||
for (int i = 0; i < numJoysticks; ++i)
|
|
||||||
{
|
|
||||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
|
||||||
joysticks.push_back(joy);
|
|
||||||
if (SDL_IsGameController(i))
|
|
||||||
{
|
|
||||||
numGamepads++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
|
||||||
std::cout << numJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numGamepads > 0)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < numGamepads; i++)
|
|
||||||
{
|
|
||||||
// Abre el mando y lo añade a la lista
|
|
||||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
|
||||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
|
||||||
{
|
|
||||||
connectedControllers.push_back(pad);
|
|
||||||
const std::string separator(" #");
|
|
||||||
std::string name = SDL_GameControllerNameForIndex(i);
|
|
||||||
// name.resize(25);
|
|
||||||
// name = name + separator + std::to_string(i);
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << name << std::endl;
|
|
||||||
}
|
|
||||||
controllerNames.push_back(name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
|
||||||
bool Input::gameControllerFound()
|
|
||||||
{
|
|
||||||
if (numGamepads > 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
|
||||||
std::string Input::getControllerName(int index)
|
|
||||||
{
|
|
||||||
if (numGamepads > 0)
|
|
||||||
{
|
|
||||||
return controllerNames[index];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el número de mandos conectados
|
|
||||||
int Input::getNumControllers()
|
|
||||||
{
|
|
||||||
return numGamepads;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si ha de mostrar mensajes
|
|
||||||
void Input::setVerbose(bool value)
|
|
||||||
{
|
|
||||||
verbose = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deshabilita las entradas durante un periodo de tiempo
|
|
||||||
void Input::disableUntil(i_disable_e value)
|
|
||||||
{
|
|
||||||
disabledUntil = value;
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hablita las entradas
|
|
||||||
void Input::enable()
|
|
||||||
{
|
|
||||||
enabled = true;
|
|
||||||
disabledUntil = d_notDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el indice del controlador a partir de un event.id
|
|
||||||
int Input::getJoyIndex(int id)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < numJoysticks; ++i)
|
|
||||||
{
|
|
||||||
if (SDL_JoystickInstanceID(joysticks[i]) == id)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra por consola los controles asignados
|
|
||||||
void Input::printBindings(int device, int index)
|
|
||||||
{
|
|
||||||
if (device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_GAMECONTROLLER)
|
|
||||||
{
|
|
||||||
if (index >= numGamepads)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra el nombre del mando
|
|
||||||
std::cout << "\n"
|
|
||||||
<< controllerNames[index] << std::endl;
|
|
||||||
|
|
||||||
// Muestra los botones asignados
|
|
||||||
for (auto bi : buttonInputs)
|
|
||||||
{
|
|
||||||
std::cout << to_string(bi) << " : " << gameControllerBindings[index][bi].button << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
|
||||||
SDL_GameControllerButton Input::getControllerBinding(int index, inputs_e input)
|
|
||||||
{
|
|
||||||
return gameControllerBindings[index][input].button;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el indice a partir del nombre del mando
|
|
||||||
int Input::getIndexByName(std::string name)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < numGamepads; ++i)
|
|
||||||
{
|
|
||||||
if (controllerNames[i] == name)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convierte un inputs_e a std::string
|
|
||||||
std::string Input::to_string(inputs_e input)
|
|
||||||
{
|
|
||||||
if (input == input_fire_left)
|
|
||||||
{
|
|
||||||
return "input_fire_left";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input == input_fire_center)
|
|
||||||
{
|
|
||||||
return "input_fire_center";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input == input_fire_right)
|
|
||||||
{
|
|
||||||
return "input_fire_right";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input == input_start)
|
|
||||||
{
|
|
||||||
return "input_start";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convierte un std::string a inputs_e
|
|
||||||
inputs_e Input::to_inputs_e(std::string name)
|
|
||||||
{
|
|
||||||
if (name == "input_fire_left")
|
|
||||||
{
|
|
||||||
return input_fire_left;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_fire_center")
|
|
||||||
{
|
|
||||||
return input_fire_center;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_fire_right")
|
|
||||||
{
|
|
||||||
return input_fire_right;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_start")
|
|
||||||
{
|
|
||||||
return input_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
return input_null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
|
||||||
void Input::allActive(int index)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < (int)buttonInputs.size(); ++i)
|
|
||||||
{
|
|
||||||
gameControllerBindings[index][i].active = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/*
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum inputs_e
|
|
||||||
{
|
|
||||||
// Inputs obligatorios
|
|
||||||
input_null,
|
|
||||||
input_up,
|
|
||||||
input_down,
|
|
||||||
input_left,
|
|
||||||
input_right,
|
|
||||||
input_pause,
|
|
||||||
input_exit,
|
|
||||||
input_accept,
|
|
||||||
input_cancel,
|
|
||||||
|
|
||||||
// Inputs personalizados
|
|
||||||
input_fire_left,
|
|
||||||
input_fire_center,
|
|
||||||
input_fire_right,
|
|
||||||
input_start,
|
|
||||||
|
|
||||||
// Inputs estandar
|
|
||||||
input_window_fullscreen,
|
|
||||||
input_window_inc_size,
|
|
||||||
input_window_dec_size,
|
|
||||||
input_video_shaders,
|
|
||||||
input_reset,
|
|
||||||
input_mute,
|
|
||||||
|
|
||||||
// Input obligatorio
|
|
||||||
input_number_of_inputs
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ALLOW_REPEAT true
|
|
||||||
#define DO_NOT_ALLOW_REPEAT false
|
|
||||||
|
|
||||||
#define INPUT_USE_KEYBOARD 0
|
|
||||||
#define INPUT_USE_GAMECONTROLLER 1
|
|
||||||
#define INPUT_USE_ANY 2
|
|
||||||
|
|
||||||
enum i_disable_e
|
|
||||||
{
|
|
||||||
d_notDisabled,
|
|
||||||
d_forever,
|
|
||||||
d_keyPressed
|
|
||||||
};
|
|
||||||
|
|
||||||
class Input
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
struct keyBindings_t
|
|
||||||
{
|
|
||||||
Uint8 scancode; // Scancode asociado
|
|
||||||
bool active; // Indica si está activo
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GameControllerBindings_t
|
|
||||||
{
|
|
||||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
|
||||||
bool active; // Indica si está activo
|
|
||||||
};
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
|
||||||
std::vector<SDL_Joystick *> joysticks; // Vector con todos los joysticks conectados
|
|
||||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
|
||||||
std::vector<std::vector<GameControllerBindings_t>> gameControllerBindings; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
|
||||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
|
||||||
std::vector<inputs_e> gameInputs; // Inputs usados para jugar, normalmente direcciones y botones
|
|
||||||
std::vector<inputs_e> buttonInputs; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
|
||||||
int numJoysticks; // Número de joysticks conectados
|
|
||||||
int numGamepads; // Número de mandos conectados
|
|
||||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
|
||||||
bool verbose; // Indica si ha de mostrar mensajes
|
|
||||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
|
||||||
bool enabled; // Indica si está habilitado
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Input(std::string file);
|
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
|
||||||
void bindKey(inputs_e input, SDL_Scancode code);
|
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
|
||||||
void bindGameControllerButton(int index, inputs_e input, SDL_GameControllerButton button);
|
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
|
||||||
bool checkInput(inputs_e input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
|
||||||
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
|
||||||
|
|
||||||
// Comprueba si hay algún botón pulsado
|
|
||||||
int checkAnyButtonPressed(bool repeat = DO_NOT_ALLOW_REPEAT);
|
|
||||||
|
|
||||||
// Busca si hay mandos conectados
|
|
||||||
bool discoverGameControllers();
|
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
|
||||||
bool gameControllerFound();
|
|
||||||
|
|
||||||
// Obten el número de mandos conectados
|
|
||||||
int getNumControllers();
|
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
|
||||||
std::string getControllerName(int index);
|
|
||||||
|
|
||||||
// Establece si ha de mostrar mensajes
|
|
||||||
void setVerbose(bool value);
|
|
||||||
|
|
||||||
// Deshabilita las entradas durante un periodo de tiempo
|
|
||||||
void disableUntil(i_disable_e value);
|
|
||||||
|
|
||||||
// Hablita las entradas
|
|
||||||
void enable();
|
|
||||||
|
|
||||||
// Obtiene el indice del controlador a partir de un event.id
|
|
||||||
int getJoyIndex(int id);
|
|
||||||
|
|
||||||
// Muestra por consola los controles asignados
|
|
||||||
void printBindings(int device = INPUT_USE_KEYBOARD, int index = 0);
|
|
||||||
|
|
||||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
|
||||||
SDL_GameControllerButton getControllerBinding(int index, inputs_e input);
|
|
||||||
|
|
||||||
// Convierte un inputs_e a std::string
|
|
||||||
std::string to_string(inputs_e input);
|
|
||||||
|
|
||||||
// Convierte un std::string a inputs_e
|
|
||||||
inputs_e to_inputs_e(std::string name);
|
|
||||||
|
|
||||||
// Obtiene el indice a partir del nombre del mando
|
|
||||||
int getIndexByName(std::string name);
|
|
||||||
|
|
||||||
// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando
|
|
||||||
void allActive(int index);
|
|
||||||
};
|
|
||||||