Compare commits
226 Commits
4f6c92c8d1
...
2024-10-28
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e2865a4a | |||
| 787cb6366f | |||
| 0fe371653a | |||
| 2cffe8dfc9 | |||
| 1dd96cfaff | |||
| d054e188b6 | |||
| ca6ff71a46 | |||
| b90ac65cfc | |||
| 759adbf6fd | |||
| 71f76fda05 | |||
| ddfb3672ea | |||
| 6235d0b684 | |||
| f750997b34 | |||
| de2a29b669 | |||
| f99f908c11 | |||
| d44bfd51de | |||
| 4f095ab018 | |||
| bffd2bdace | |||
| 24d09a2e3c | |||
| caf191672e | |||
| 43e7b83403 | |||
| a5c72a0f65 | |||
| ca464b2e81 | |||
| f26ecbd969 | |||
| 018bb68f9a | |||
| f36ff3d7fe | |||
| 8f33308f8d | |||
| 8c98430b68 | |||
| 6e2f80d8ce | |||
| 95478134dd | |||
| 528533fd9b | |||
| 5df85e1b1a | |||
| 1d0c2e01a5 | |||
| 236d6f58b6 | |||
| 898b551e06 | |||
| 84238032e0 | |||
| 2cb22ed013 | |||
| a3a583deb7 | |||
| b263e0c4be | |||
| 3bf61fc758 | |||
| 2377815c02 | |||
| 7434869894 | |||
| 848d61b5c0 | |||
| cbc9b3f071 | |||
| 8bca5095da | |||
| a4b4e188cd | |||
| f23dcae5b6 | |||
| b879673bc2 | |||
| a8701dbebc | |||
| afe835914e | |||
| 808f1595e9 | |||
| 8e8346b2ab | |||
| 1da8f33a5e | |||
| 50a376e582 | |||
| 59de566c5b | |||
| db884cb422 | |||
| 5585f996cb | |||
| 24556eeaa8 | |||
| dbffda491f | |||
| 53f5f3f8b0 | |||
| e0faa0890e | |||
| de6508c37c | |||
| e99c2c5265 | |||
| 942924c65c | |||
| 089da99b5b | |||
| 3fdd60c9e2 | |||
| 3b9885ab03 | |||
| 39a8c992e1 | |||
| 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 |
2
.gitignore
vendored
@@ -14,3 +14,5 @@ thumbs.db
|
||||
*config.bin
|
||||
*score.bin
|
||||
coffee_crisis*
|
||||
debug.txt
|
||||
cppcheck-result*
|
||||
38
Makefile
@@ -24,18 +24,18 @@ INCLUDES:= -I$(DIR_SOURCES)
|
||||
# Variables según el sistema operativo
|
||||
ifeq ($(OS),Windows_NT)
|
||||
FixPath = $(subst /,\,$1)
|
||||
SOURCES := source/*.cpp source/common/*.cpp
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
||||
RM = del /Q
|
||||
MKD:= mkdir
|
||||
else
|
||||
FixPath = $1
|
||||
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
|
||||
SOURCES := source/*.cpp source/common/*.cpp
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
|
||||
LDFLAGS := -lSDL2
|
||||
RM = rm -f
|
||||
MKD:= mkdir -p
|
||||
@@ -121,13 +121,12 @@ print-variables:
|
||||
|
||||
@echo RM: $(RM)
|
||||
|
||||
raspi3:
|
||||
$(CXX) $(SOURCES) -D NO_SHADERS -D VERBOSE $(CXXFLAGS) -lSDL2 -o $(TARGET_FILE)
|
||||
raspi:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
||||
|
||||
raspi5:
|
||||
$(CXX) $(SOURCES) -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
|
||||
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
|
||||
raspi_debug:
|
||||
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE -D DEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
@@ -226,7 +225,6 @@ linux:
|
||||
|
||||
linux_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:
|
||||
# Elimina carpetas previas
|
||||
@@ -249,4 +247,18 @@ linux_release:
|
||||
cd "$(RELEASE_FOLDER)" && tar -czvf "../$(LINUX_RELEASE)" *
|
||||
|
||||
# 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
|
||||
78
README.md
@@ -1,67 +1,39 @@
|
||||
# Coffee Crisis
|
||||
# Coffee Crisis Arcade Edition
|
||||
|
||||
Coffee Crisis es un juego arcade que pondrá a prueba tus reflejos. Empezado durante el verano de 2020 y terminado un año despues, en el verano de 2021. Intenta conseguir todos los puntos que puedas con una sola vida a traves de los 10 niveles de juego y ayuda a Bal1 a defender la UPV de la invasión de la cafeína esférica y saltarina.
|
||||
Coffee Crisis Arcade Edition es la versió ampliada i millorada del aclamat Coffee Crisis. Preparat per a jugar sense parar amn dos jugadors, nous gràfics i moltes sorpreses mes.
|
||||
|
||||

|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae_title.png" alt="Titol"
|
||||
</p>
|
||||
|
||||
## Teclado
|
||||
El juego se maneja con teclado, aunque tambien se puede conectar un mando de control.
|
||||
Las teclas son las siguientes:
|
||||
## Controls
|
||||
El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels jugadors pot utilitzar el teclat.
|
||||
Les tecles son les següents:
|
||||
|
||||
* **Cursores**: Mover al personaje, moverse por los menus
|
||||
* **Q, W, E**: Disparar a la izquierda, al centro y a la derecha respectivamente
|
||||
* **ESCAPE**: Pone en pausa el juego durante la partida. Sale de los menus. Cierra el juego
|
||||
* **ENTER**: Acepta las opciones en los menus
|
||||
* **Fletxes**: Mou al personatge
|
||||
* **Q, W, E**: Disparar a la esquerra, al centre i a la dreta respectivament
|
||||
|
||||

|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae1.png" alt="Joc"
|
||||
</p>
|
||||
|
||||
## Compilar
|
||||
## Altres tecles
|
||||
- **Tecla ESC**: Tancar el joc
|
||||
|
||||
Para compilar el código se necesitan tener las librerías SDL instaladas en el sistema y el compilador g++.
|
||||
- **Tecla F1**: Fa la finestra mes xicoteta
|
||||
|
||||
En Linux:
|
||||
```bash
|
||||
sudo apt install libsdl2-dev g++
|
||||
```
|
||||
- **Tecla F2**: Fa la finestra mes gran
|
||||
|
||||
En macOS se pueden instalar fácilmente con [brew](https://brew.sh):
|
||||
```bash
|
||||
brew install sdl2 g++
|
||||
```
|
||||
- **Tecla F3**: Alterna entre el mode de pantalla completa i el de finestra
|
||||
|
||||
Una vez instaladas las librerías SDL, se puede compilar utilizando el fichero Makefile suministrado.
|
||||
- **Tecla F4**: Activa o desactiva els shaders
|
||||
|
||||
En Linux:
|
||||
```bash
|
||||
make linux
|
||||
```
|
||||
- **Tecla F10**: Reset
|
||||
|
||||
En macOS:
|
||||
```bash
|
||||
make macos
|
||||
```
|
||||

|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae2.png" alt="Joc"
|
||||
</p>
|
||||
|
||||
## Como ejecutar
|
||||
|
||||
Para ejecutar el juego hay que escribir en la terminal la orden que se muestra a continuación.
|
||||
|
||||
En Linux:
|
||||
```bash
|
||||
./coffee_crisis_linux
|
||||
```
|
||||
|
||||
En macOS:
|
||||
```bash
|
||||
./coffee_crisis_macos
|
||||
```
|
||||
|
||||
En macOS tambien puedes hacer doble click sobre el archivo coffee_crisis_macos
|
||||
|
||||
## Agradecimientos
|
||||
A los jailers y a la jail. Y entre ellos, a JailDoctor por estar siempre ahí apoyándonos/obligándonos a sacar un Jailgame más.
|
||||
|
||||
Y por supuesto a ti por estar aquí.
|
||||
|
||||
## Licencia
|
||||
Usa el código para lo que quieras: aprender, reirte, curiosear... excepto para sacar beneficio económico. Si lo consigues, por favor avísame y vamos a medias.
|
||||
## Agraiments
|
||||
A chatGPT i sobretot a Copilot. Gracies per estar sempre quan vos he necesitat.
|
||||
@@ -7,7 +7,7 @@
|
||||
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,back:b5,
|
||||
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
|
||||
# Source: https://github.com/gabomdq/SDL_GameControllerDB
|
||||
|
||||
@@ -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
|
||||
53
data/config/param_320x240.txt
Normal file
@@ -0,0 +1,53 @@
|
||||
## GAME
|
||||
game.item_size 20 # Tamaño de los items del juego
|
||||
game.width 320 # Ancho de la resolucion nativa del juego
|
||||
game.height 240 # Alto de la resolucion nativa del juego
|
||||
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 200 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
|
||||
## 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
|
||||
54
data/config/param_320x256.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
## GAME
|
||||
game.item_size 20 # Tamaño de los items del juego
|
||||
game.width 320 # Ancho de la resolucion nativa del juego
|
||||
game.height 256 # Alto de la resolucion nativa del juego
|
||||
game.play_area.rect.x 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.y 0 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.w 320 # Rectangulo con la posición de la zona de juego
|
||||
game.play_area.rect.h 216 # Rectangulo con la posición de la zona de juego
|
||||
game.enter_name_seconds 30 # Duración en segundos para introducir el nombre al finalizar la partida
|
||||
game.game_text.dest_y
|
||||
|
||||
## 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
|
||||
|
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=10
|
||||
frameHeight=10
|
||||
frame_width=10
|
||||
frame_height=10
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=16
|
||||
frameHeight=16
|
||||
frame_width=16
|
||||
frame_height=16
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=26
|
||||
frameHeight=26
|
||||
frame_width=26
|
||||
frame_height=26
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=48
|
||||
frameHeight=48
|
||||
frame_width=48
|
||||
frame_height=48
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=10
|
||||
frameHeight=10
|
||||
frame_width=10
|
||||
frame_height=10
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 760 B After Width: | Height: | Size: 760 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=16
|
||||
frameHeight=16
|
||||
frame_width=16
|
||||
frame_height=16
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=26
|
||||
frameHeight=26
|
||||
frame_width=26
|
||||
frame_height=26
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=46
|
||||
frameHeight=46
|
||||
frame_width=46
|
||||
frame_height=46
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=46
|
||||
frameHeight=46
|
||||
frame_width=46
|
||||
frame_height=46
|
||||
|
||||
[animation]
|
||||
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 |
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 25 KiB 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: 3.5 KiB |
|
Before Width: | Height: | Size: 935 B |
BIN
data/gfx/game_text/game_text_1000_points.png
Normal file
|
After Width: | Height: | Size: 295 B |
BIN
data/gfx/game_text/game_text_2500_points.png
Normal file
|
After Width: | Height: | Size: 371 B |
BIN
data/gfx/game_text/game_text_5000_points.png
Normal file
|
After Width: | Height: | Size: 332 B |
BIN
data/gfx/game_text/game_text_one_hit.png
Normal file
|
After Width: | Height: | Size: 399 B |
BIN
data/gfx/game_text/game_text_powerup.png
Normal file
|
After Width: | Height: | Size: 453 B |
BIN
data/gfx/game_text/game_text_stop.png
Normal file
|
After Width: | Height: | Size: 392 B |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -1,5 +1,5 @@
|
||||
frameWidth=20
|
||||
frameHeight=20
|
||||
frame_width=20
|
||||
frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 400 B After Width: | Height: | Size: 400 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=20
|
||||
frameHeight=20
|
||||
frame_width=20
|
||||
frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 623 B After Width: | Height: | Size: 623 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=28
|
||||
frameHeight=37
|
||||
frame_width=28
|
||||
frame_height=37
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 835 B After Width: | Height: | Size: 835 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=20
|
||||
frameHeight=20
|
||||
frame_width=20
|
||||
frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 336 B After Width: | Height: | Size: 336 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=20
|
||||
frameHeight=20
|
||||
frame_width=20
|
||||
frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 506 B After Width: | Height: | Size: 506 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=20
|
||||
frameHeight=20
|
||||
frame_width=20
|
||||
frame_height=20
|
||||
|
||||
[animation]
|
||||
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
|
||||
frameHeight=30
|
||||
frame_width=30
|
||||
frame_height=30
|
||||
|
||||
[animation]
|
||||
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 |
BIN
data/gfx/player/player1_one_coffee_palette.pal
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
data/gfx/player/player1_power.png
Normal file
|
After Width: | Height: | Size: 929 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 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 |
BIN
data/gfx/player/player2_power.png
Normal file
|
After Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
@@ -1,5 +1,5 @@
|
||||
frameWidth=39
|
||||
frameHeight=44
|
||||
frame_width=39
|
||||
frame_height=44
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 173 B |
|
Before Width: | Height: | Size: 772 B |
|
Before Width: | Height: | Size: 772 B |
|
Before Width: | Height: | Size: 944 B |
|
Before 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
|
||||
frameHeight=16
|
||||
frame_width=16
|
||||
frame_height=16
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
|
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 212 B |
@@ -278,4 +278,73 @@ DEIXA BUIT PER A
|
||||
MODE FORA DE LINEA
|
||||
|
||||
## 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
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Torna a polsar per apagar el sistema
|
||||
@@ -278,4 +278,73 @@ LEAVE BLANK FOR
|
||||
OFFLINE MODE
|
||||
|
||||
## 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
|
||||
|
||||
## 116 - NOTIFICACIONES
|
||||
Press again to shutdown system
|
||||
@@ -278,4 +278,73 @@ DEJA EN BLANCO PARA
|
||||
MODO SIN CONEXION
|
||||
|
||||
## 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
|
||||
|
||||
## 94 - NOTIFICACIONES
|
||||
Pulsa otra vez para apagar el sistema
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -97,7 +97,8 @@ void main()
|
||||
#if defined(CURVATURE)
|
||||
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||
#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;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
@@ -146,7 +147,7 @@ float CalcScanLine(float dy)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 TextureSize = vec2(320.0, 240.0);
|
||||
vec2 TextureSize = vec2(320.0, 256.0);
|
||||
#if defined(CURVATURE)
|
||||
vec2 texcoord = Distort(TEX0);
|
||||
if (texcoord.x < 0.0)
|
||||
|
||||
6
linux_utils/build_time_tracker.sh
Normal 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."
|
||||
8
linux_utils/check_all_includes.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
SOURCEPATH=../source/
|
||||
|
||||
for i in "$SOURCEPATH"/*.cpp
|
||||
do
|
||||
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
|
||||
done
|
||||
10
linux_utils/check_includes.sh
Normal 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 -r -p "Presiona cualquier tecla para continuar..."
|
||||
clear
|
||||
done
|
||||
20
linux_utils/cppcheck_run.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# warning,style,performance
|
||||
#cppcheck --force --enable=warning,style,performance --std=c++20 \
|
||||
# --suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \
|
||||
# /home/sergio/gitea/coffee_crisis_arcade_edition/source/ \
|
||||
# 2>/home/sergio/cppcheck-result-warning-style-performance.txt
|
||||
|
||||
# all
|
||||
#cppcheck --force --enable=all -I /usr/include --std=c++20 \
|
||||
#--suppress=missingIncludeSystem \
|
||||
#--suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \
|
||||
#/home/sergio/gitea/coffee_crisis_arcade_edition/source/ \
|
||||
#2>/home/sergio/cppcheck-result-all.txt
|
||||
|
||||
# unusedFunction
|
||||
cppcheck --enable=style --std=c++20 \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
../source/ \
|
||||
2>/home/sergio/cppcheck-result-all.txt
|
||||
8
linux_utils/cppcheck_suppressions
Normal file
@@ -0,0 +1,8 @@
|
||||
*:/home/sergio/gitea/coffee_crisis_arcade_edition/source/stb*
|
||||
*:/home/sergio/gitea/coffee_crisis_arcade_edition/source/gif.c
|
||||
*:/home/sergio/gitea/coffee_crisis_arcade_edition/source/jail*
|
||||
*:/usr/include/*
|
||||
*:../source/stb*
|
||||
*:../source/gif.c
|
||||
*:../source/jail*
|
||||
*:/usr/include/*
|
||||
BIN
linux_utils/include-what-you-use
Normal file
6
linux_utils/run_valgrind.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/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.*
|
||||
}
|
||||
250
source/animated_sprite.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
#include "animated_sprite.h"
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para printWithDots
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path)
|
||||
{
|
||||
std::ifstream file(file_path);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
|
||||
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
|
||||
std::vector<std::string> buffer;
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (!line.empty())
|
||||
buffer.push_back(line);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
||||
: MovingSprite(texture)
|
||||
{
|
||||
// Carga las animaciones
|
||||
if (!file_path.empty())
|
||||
{
|
||||
AnimationsFileBuffer v = loadAnimationsFromFile(file_path);
|
||||
loadFromAnimationsFileBuffer(v);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations)
|
||||
: MovingSprite(texture)
|
||||
{
|
||||
if (!animations.empty())
|
||||
{
|
||||
loadFromAnimationsFileBuffer(animations);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(const std::string &name)
|
||||
{
|
||||
auto index = -1;
|
||||
|
||||
for (const auto &a : animations_)
|
||||
{
|
||||
index++;
|
||||
if (a.name == name)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (animations_[current_animation_].speed == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcula el frame actual a partir del contador
|
||||
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
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animations_[current_animation_].current_frame >= (int)animations_[current_animation_].frames.size())
|
||||
{
|
||||
if (animations_[current_animation_].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
||||
animations_[current_animation_].completed = true;
|
||||
}
|
||||
else
|
||||
{ // Si hay loop, vuelve al frame indicado
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
{
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
animations_[current_animation_].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool AnimatedSprite::animationIsCompleted()
|
||||
{
|
||||
return animations_[current_animation_].completed;
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||
{
|
||||
const auto new_animation = getIndex(name);
|
||||
if (current_animation_ != new_animation)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(int index)
|
||||
{
|
||||
const auto new_animation = index;
|
||||
if (current_animation_ != new_animation)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void AnimatedSprite::update()
|
||||
{
|
||||
animate();
|
||||
MovingSprite::update();
|
||||
}
|
||||
|
||||
// Reinicia la animación
|
||||
void AnimatedSprite::resetAnimation()
|
||||
{
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source)
|
||||
{
|
||||
int frame_width = 1;
|
||||
int frame_height = 1;
|
||||
int frames_per_row = 1;
|
||||
int max_tiles = 1;
|
||||
|
||||
size_t index = 0;
|
||||
while (index < source.size())
|
||||
{
|
||||
std::string line = source.at(index);
|
||||
|
||||
// Parsea el fichero para buscar variables y valores
|
||||
if (line != "[animation]")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
size_t pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string key = line.substr(0, pos);
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
if (key == "frame_width")
|
||||
frame_width = value;
|
||||
else if (key == "frame_height")
|
||||
frame_height = value;
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
const int w = texture_->getWidth() / frame_width;
|
||||
const int h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation animation;
|
||||
do
|
||||
{
|
||||
index++;
|
||||
line = source.at(index);
|
||||
size_t pos = line.find("=");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1);
|
||||
|
||||
if (key == "name")
|
||||
animation.name = value;
|
||||
else if (key == "speed")
|
||||
animation.speed = std::stoi(value);
|
||||
else if (key == "loop")
|
||||
animation.loop = std::stoi(value);
|
||||
else if (key == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(value);
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int num_tile = std::stoi(tmp);
|
||||
if (num_tile <= max_tiles)
|
||||
{
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
animation.frames.emplace_back(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations_.emplace_back(animation);
|
||||
}
|
||||
|
||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||
index++;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setWidth(frame_width);
|
||||
setHeight(frame_height);
|
||||
}
|
||||
66
source/animated_sprite.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
class Texture; // lines 9-9
|
||||
|
||||
struct Animation
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen 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
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int current_frame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
|
||||
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||
};
|
||||
|
||||
using AnimationsFileBuffer = std::vector<std::string>;
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
|
||||
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
protected:
|
||||
// Variables
|
||||
std::vector<Animation> animations_; // Vector con las diferentes animaciones
|
||||
int current_animation_ = 0; // Animacion activa
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations);
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture)
|
||||
: MovingSprite(texture) {}
|
||||
|
||||
// Destructor
|
||||
virtual ~AnimatedSprite() = default;
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(const std::string &name);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(const std::string &name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
};
|
||||
177
source/asset.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include "asset.h"
|
||||
#include <algorithm> // Para find_if, max
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream, endl
|
||||
#include <iostream> // Para cout
|
||||
#include <string> // Para allocator, char_traits, string, operator+, oper...
|
||||
#include "utils.h" // Para getFileName, printWithDots
|
||||
|
||||
// [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_;
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void Asset::add(const std::string &file, AssetType type, bool required, bool absolute)
|
||||
{
|
||||
file_list_.emplace_back(absolute ? file : executable_path_ + file, type, required);
|
||||
longest_name_ = std::max(longest_name_, static_cast<int>(file_list_.back().file.size()));
|
||||
}
|
||||
|
||||
// Devuelve la ruta completa a un fichero a partir de una cadena
|
||||
std::string Asset::get(const std::string &text) const
|
||||
{
|
||||
auto it = std::find_if(file_list_.begin(), file_list_.end(),
|
||||
[&text](const auto &f)
|
||||
{
|
||||
return getFileName(f.file) == text;
|
||||
});
|
||||
|
||||
if (it != file_list_.end())
|
||||
{
|
||||
return it->file;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << text << " not found" << std::endl;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
bool Asset::check() const
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
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;
|
||||
|
||||
// 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)
|
||||
{
|
||||
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
|
||||
|
||||
for (const auto &f : file_list_)
|
||||
{
|
||||
if (f.required && f.type == static_cast<AssetType>(type))
|
||||
{
|
||||
success &= checkFile(f.file);
|
||||
}
|
||||
}
|
||||
if (success)
|
||||
std::cout << " All files are OK." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Resultado
|
||||
std::cout << (success ? "\n** CHECKING FILES COMPLETED.\n" : "\n** CHECKING FILES FAILED.\n") << std::endl;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
bool Asset::checkFile(const std::string &path) const
|
||||
{
|
||||
std::ifstream file(path);
|
||||
bool success = file.good();
|
||||
file.close();
|
||||
|
||||
if (!success)
|
||||
printWithDots("Checking file : ", getFileName(path), "[ ERROR ]");
|
||||
|
||||
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;
|
||||
}
|
||||
79
source/asset.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // para string, basic_string
|
||||
#include <vector> // para vector
|
||||
#include "utils.h"
|
||||
|
||||
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 raíz del directorio
|
||||
AssetType type; // Indica el tipo de recurso
|
||||
bool required; // Indica si es un fichero que debe de existir
|
||||
|
||||
// Constructor
|
||||
AssetItem(const std::string &filePath, AssetType assetType, bool isRequired)
|
||||
: file(filePath), type(assetType), required(isRequired) {}
|
||||
};
|
||||
|
||||
// Variables
|
||||
int longest_name_ = 0; // 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)
|
||||
: executable_path_(getPath(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 la ruta completa a un fichero 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,177 +1,182 @@
|
||||
#include "background.h"
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // Para clamp, max
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
#include "param.h" // Para Param, ParamBackground, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param)
|
||||
Background::Background()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
|
||||
buildings_texture_(Resource::get()->getTexture("game_buildings.png")),
|
||||
top_clouds_texture_(Resource::get()->getTexture("game_clouds1.png")),
|
||||
bottom_clouds_texture_(Resource::get()->getTexture("game_clouds2.png")),
|
||||
grass_texture_(Resource::get()->getTexture("game_grass.png")),
|
||||
gradients_texture_(Resource::get()->getTexture("game_sky_colors.png")),
|
||||
|
||||
rect_({0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2}),
|
||||
src_rect_({0, 0, 320, 240}),
|
||||
dst_rect_({0, 0, 320, 240}),
|
||||
base_(rect_.h),
|
||||
color_(Color(param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b)),
|
||||
alpha_color_text_(param.background.attenuate_alpha),
|
||||
alpha_color_text_temp_(param.background.attenuate_alpha)
|
||||
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->param = param;
|
||||
|
||||
// Inicializa variables
|
||||
gradientNumber = 0;
|
||||
alpha = 0;
|
||||
cloudsSpeed = 0;
|
||||
transition = 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;
|
||||
|
||||
// Carga las texturas
|
||||
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
|
||||
topCloudsTexture = new Texture(renderer, asset->get("game_clouds1.png"));
|
||||
bottomCloudsTexture = new Texture(renderer, asset->get("game_clouds2.png"));
|
||||
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
|
||||
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
|
||||
|
||||
gradientRect[0] = {0, 0, rect.w, rect.h};
|
||||
gradientRect[1] = {rect.w, 0, rect.w, rect.h};
|
||||
gradientRect[2] = {0, rect.h, rect.w, rect.h};
|
||||
gradientRect[3] = {rect.w, rect.h, rect.w, rect.h};
|
||||
|
||||
const int topCloudsTextureHeight = topCloudsTexture->getHeight() / 4;
|
||||
const int bottomCloudsTextureHeight = bottomCloudsTexture->getHeight() / 4;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
topCloudsRect[i] = {0, i * topCloudsTextureHeight, topCloudsTexture->getWidth(), topCloudsTextureHeight};
|
||||
bottomCloudsRect[i] = {0, i * bottomCloudsTextureHeight, bottomCloudsTexture->getWidth(), bottomCloudsTextureHeight};
|
||||
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
|
||||
|
||||
const 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
|
||||
const int clouds1y = base - 165;
|
||||
const int clouds2y = base - 101;
|
||||
const float clouds1speed = 0.1f;
|
||||
const float clouds2speed = 0.05f;
|
||||
topCloudsSprite_A = new MovingSprite(0, clouds1y, rect.w, topCloudsTexture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
|
||||
topCloudsSprite_B = new MovingSprite(rect.w, clouds1y, rect.w, topCloudsTexture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
|
||||
{
|
||||
const int top_clouds_y = base_ - 165;
|
||||
const int bottom_clouds_y = base_ - 101;
|
||||
|
||||
bottomCloudsSprite_A = new MovingSprite(0, clouds2y, rect.w, bottomCloudsTexture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
|
||||
bottomCloudsSprite_B = new MovingSprite(rect.w, clouds2y, rect.w, bottomCloudsTexture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
|
||||
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
|
||||
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
|
||||
|
||||
buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture);
|
||||
gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture);
|
||||
grassSprite = new Sprite(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture);
|
||||
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
|
||||
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
|
||||
|
||||
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_, 0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight());
|
||||
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
|
||||
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
|
||||
}
|
||||
|
||||
// Inicializa objetos
|
||||
topCloudsSprite_A->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight());
|
||||
topCloudsSprite_B->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight());
|
||||
bottomCloudsSprite_A->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight());
|
||||
bottomCloudsSprite_B->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight());
|
||||
buildingsSprite->setPosY(base - buildingsSprite->getHeight());
|
||||
grassSprite->setPosY(base - grassSprite->getHeight());
|
||||
{
|
||||
constexpr float top_clouds_speed = 0.1f;
|
||||
constexpr float bottom_clouds_speed = 0.05f;
|
||||
|
||||
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_a_->setVelX(-top_clouds_speed);
|
||||
|
||||
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_b_->setVelX(-top_clouds_speed);
|
||||
|
||||
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_a_->setVelX(-bottom_clouds_speed);
|
||||
|
||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_b_->setVelX(-bottom_clouds_speed);
|
||||
|
||||
buildings_sprite_->setY(base_ - buildings_sprite_->getHeight());
|
||||
grass_sprite_->setY(base_ - grass_sprite_->getHeight());
|
||||
}
|
||||
|
||||
// Crea la textura para componer el fondo
|
||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
|
||||
canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea la textura para atenuar el fondo
|
||||
colorTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(colorTexture, SDL_BLENDMODE_BLEND);
|
||||
setColor(color);
|
||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorText);
|
||||
color_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
||||
setColor(color_);
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Background::~Background()
|
||||
{
|
||||
delete buildingsTexture;
|
||||
delete topCloudsTexture;
|
||||
delete bottomCloudsTexture;
|
||||
delete grassTexture;
|
||||
delete gradientsTexture;
|
||||
|
||||
delete topCloudsSprite_A;
|
||||
delete topCloudsSprite_B;
|
||||
delete bottomCloudsSprite_A;
|
||||
delete bottomCloudsSprite_B;
|
||||
delete buildingsSprite;
|
||||
delete gradientSprite;
|
||||
delete grassSprite;
|
||||
SDL_DestroyTexture(canvas);
|
||||
SDL_DestroyTexture(colorTexture);
|
||||
SDL_DestroyTexture(canvas_);
|
||||
SDL_DestroyTexture(color_texture_);
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
void Background::update()
|
||||
{
|
||||
// Actualiza el valor de alpha
|
||||
// Actualiza el valor de alpha_
|
||||
updateAlphaColorText();
|
||||
|
||||
// Actualiza las nubes
|
||||
updateClouds();
|
||||
|
||||
// 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
|
||||
alpha = std::max((255 - (int)(255 * transition)), 0);
|
||||
// Calcula el valor de alpha_
|
||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
++counter_;
|
||||
|
||||
// Compone todos los elementos del fondo en la textura
|
||||
fillCanvas();
|
||||
}
|
||||
|
||||
// Dibuja el gradiente de fondo
|
||||
void Background::renderGradient()
|
||||
{
|
||||
// Dibuja el gradiente 2
|
||||
gradientsTexture->setAlpha(255);
|
||||
gradientSprite->setSpriteClip(gradientRect[(gradientNumber + 1) % 4]);
|
||||
gradientSprite->render();
|
||||
// Dibuja el gradiente de detras
|
||||
gradients_texture_->setAlpha(255);
|
||||
gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]);
|
||||
gradient_sprite_->render();
|
||||
|
||||
// Dibuja el gradiente 1 con una opacidad cada vez menor
|
||||
gradientsTexture->setAlpha(alpha);
|
||||
gradientSprite->setSpriteClip(gradientRect[gradientNumber]);
|
||||
gradientSprite->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
|
||||
topCloudsTexture->setAlpha(255);
|
||||
topCloudsSprite_A->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]);
|
||||
topCloudsSprite_A->render();
|
||||
topCloudsSprite_B->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]);
|
||||
topCloudsSprite_B->render();
|
||||
// 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
|
||||
topCloudsTexture->setAlpha(alpha);
|
||||
topCloudsSprite_A->setSpriteClip(topCloudsRect[gradientNumber]);
|
||||
topCloudsSprite_A->render();
|
||||
topCloudsSprite_B->setSpriteClip(topCloudsRect[gradientNumber]);
|
||||
topCloudsSprite_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
|
||||
bottomCloudsTexture->setAlpha(255);
|
||||
bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]);
|
||||
bottomCloudsSprite_A->render();
|
||||
bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]);
|
||||
bottomCloudsSprite_B->render();
|
||||
// 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
|
||||
bottomCloudsTexture->setAlpha(alpha);
|
||||
bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[gradientNumber]);
|
||||
bottomCloudsSprite_A->render();
|
||||
bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[gradientNumber]);
|
||||
bottomCloudsSprite_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
|
||||
void Background::fillCanvas()
|
||||
{
|
||||
// Cambia el destino del renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, canvas);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, canvas_);
|
||||
|
||||
// Dibuja el gradiente de fondo
|
||||
renderGradient();
|
||||
@@ -183,117 +188,102 @@ void Background::fillCanvas()
|
||||
renderBottomClouds();
|
||||
|
||||
// Dibuja los edificios
|
||||
buildingsSprite->render();
|
||||
buildings_sprite_->render();
|
||||
|
||||
// Dibuja la hierba
|
||||
grassSprite->render();
|
||||
grass_sprite_->render();
|
||||
|
||||
// Deja el renderizador apuntando donde estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Dibuja el objeto
|
||||
void Background::render()
|
||||
{
|
||||
// Fondo
|
||||
SDL_RenderCopy(renderer, canvas, &srcRect, &dstRect);
|
||||
SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_);
|
||||
|
||||
// Atenuación
|
||||
SDL_RenderCopy(renderer, colorTexture, &srcRect, &dstRect);
|
||||
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
|
||||
}
|
||||
|
||||
// Vuelve a cargar las texturas
|
||||
void Background::reloadTextures()
|
||||
{
|
||||
buildingsTexture->reLoad();
|
||||
topCloudsTexture->reLoad();
|
||||
bottomCloudsTexture->reLoad();
|
||||
grassTexture->reLoad();
|
||||
gradientsTexture->reLoad();
|
||||
buildings_texture_->reLoad();
|
||||
top_clouds_texture_->reLoad();
|
||||
bottom_clouds_texture_->reLoad();
|
||||
grass_texture_->reLoad();
|
||||
gradients_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setCloudsSpeed(float value)
|
||||
{
|
||||
cloudsSpeed = value;
|
||||
clouds_speed_ = value;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setGradientNumber(int value)
|
||||
{
|
||||
gradientNumber = value % 4;
|
||||
gradient_number_ = value % 4;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setTransition(float value)
|
||||
{
|
||||
value = std::min(value, 1.0f);
|
||||
value = std::max(value, 0.0f);
|
||||
transition = value;
|
||||
transition_ = std::clamp(value, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// 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
|
||||
srcRect.w = rect.w;
|
||||
srcRect.h = rect.h;
|
||||
src_rect_.x = 0;
|
||||
src_rect_.y = rect_.h - pos.h;
|
||||
src_rect_.w = pos.w;
|
||||
src_rect_.h = pos.h;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setSrcRect(SDL_Rect value)
|
||||
// Establece el color_ de atenuación
|
||||
void Background::setColor(Color color)
|
||||
{
|
||||
srcRect = value;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setDstRect(SDL_Rect value)
|
||||
{
|
||||
dstRect = value;
|
||||
}
|
||||
|
||||
// Establece el color de atenuación
|
||||
void Background::setColor(color_t color)
|
||||
{
|
||||
this->color = color;
|
||||
color_ = color;
|
||||
|
||||
// Colorea la textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, colorTexture);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, color_texture_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Establece la transparencia de la atenuación
|
||||
void Background::setAlpha(int alpha)
|
||||
{
|
||||
// Evita que se asignen valores fuera de rango
|
||||
alpha = std::min(alpha, 255);
|
||||
alpha = std::max(alpha, 0);
|
||||
alpha_ = std::clamp(alpha, 0, 255);
|
||||
|
||||
// Guarda el valor actual
|
||||
alphaColorTextTemp = alphaColorText;
|
||||
|
||||
// Establece el nuevo valor
|
||||
alphaColorText = alpha;
|
||||
// Guarda el valor actual y establece el nuevo valor
|
||||
alpha_color_text_temp_ = alpha_color_text_;
|
||||
alpha_color_text_ = alpha_;
|
||||
}
|
||||
|
||||
// Actualiza el valor de alpha
|
||||
// Actualiza el valor de alpha_
|
||||
void Background::updateAlphaColorText()
|
||||
{
|
||||
if (alphaColorText == alphaColorTextTemp)
|
||||
if (alpha_color_text_ == alpha_color_text_temp_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
alphaColorText > alphaColorTextTemp ? alphaColorTextTemp++ : alphaColorTextTemp--;
|
||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorTextTemp);
|
||||
alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_;
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,35 +291,35 @@ void Background::updateAlphaColorText()
|
||||
void Background::updateClouds()
|
||||
{
|
||||
// Aplica la velocidad calculada a las nubes
|
||||
topCloudsSprite_A->setVelX(cloudsSpeed);
|
||||
topCloudsSprite_B->setVelX(cloudsSpeed);
|
||||
bottomCloudsSprite_A->setVelX(cloudsSpeed / 2);
|
||||
bottomCloudsSprite_B->setVelX(cloudsSpeed / 2);
|
||||
top_clouds_sprite_a_->setVelX(clouds_speed_);
|
||||
top_clouds_sprite_b_->setVelX(clouds_speed_);
|
||||
bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2);
|
||||
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
|
||||
|
||||
// Mueve las nubes
|
||||
topCloudsSprite_A->move();
|
||||
topCloudsSprite_B->move();
|
||||
bottomCloudsSprite_A->move();
|
||||
bottomCloudsSprite_B->move();
|
||||
top_clouds_sprite_a_->update();
|
||||
top_clouds_sprite_b_->update();
|
||||
bottom_clouds_sprite_a_->update();
|
||||
bottom_clouds_sprite_b_->update();
|
||||
|
||||
// Calcula el offset de las nubes
|
||||
if (topCloudsSprite_A->getPosX() < -topCloudsSprite_A->getWidth())
|
||||
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())
|
||||
{
|
||||
topCloudsSprite_A->setPosX(topCloudsSprite_A->getWidth());
|
||||
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
|
||||
}
|
||||
|
||||
if (topCloudsSprite_B->getPosX() < -topCloudsSprite_B->getWidth())
|
||||
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth())
|
||||
{
|
||||
topCloudsSprite_B->setPosX(topCloudsSprite_B->getWidth());
|
||||
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
|
||||
}
|
||||
|
||||
if (bottomCloudsSprite_A->getPosX() < -bottomCloudsSprite_A->getWidth())
|
||||
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth())
|
||||
{
|
||||
bottomCloudsSprite_A->setPosX(bottomCloudsSprite_A->getWidth());
|
||||
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
|
||||
}
|
||||
|
||||
if (bottomCloudsSprite_B->getPosX() < -bottomCloudsSprite_B->getWidth())
|
||||
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth())
|
||||
{
|
||||
bottomCloudsSprite_B->setPosX(bottomCloudsSprite_B->getWidth());
|
||||
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
|
||||
}
|
||||
}
|
||||