Compare commits
150 Commits
v1.4
...
b092d3f86a
| Author | SHA1 | Date | |
|---|---|---|---|
| b092d3f86a | |||
| 837bcbd1da | |||
| 26bc47d9f6 | |||
| 9e089e9092 | |||
| 25616e1e6c | |||
| ed67e429d8 | |||
| 4ebd034b59 | |||
| 38f3e2e4d3 | |||
| 6493b73f4f | |||
| 6637ba9f10 | |||
| a74c8d5122 | |||
| 4df0db088f | |||
| 27cb772933 | |||
| 778b07cce1 | |||
| 1fa5c75466 | |||
| 0b00acf31b | |||
| 2979a6752c | |||
| f6494e69c8 | |||
| 5167a5857d | |||
| 28fe1130cf | |||
| e92b7eab4e | |||
| 14f7a79927 | |||
| 4f6a6a4918 | |||
| f5b35cee6b | |||
| 454791fe96 | |||
| 3f165be114 | |||
| 778672a6f5 | |||
| 8c919abc9d | |||
| 7e37da3999 | |||
| 842d5dd56b | |||
| ea3f16b8ac | |||
| 3fe0861e4f | |||
| b28d798545 | |||
| bdf092d46e | |||
| 09421a093d | |||
| a7d7cdd047 | |||
| bffefcad77 | |||
| b408de5fa0 | |||
| f70145a0bf | |||
| 02c7790835 | |||
| 2d10e640bd | |||
| 737829cb68 | |||
| d3f17bc93a | |||
| b7490ed1c1 | |||
| 836deb720d | |||
| 7e9a1cb049 | |||
| f928195a05 | |||
| 84b09a4987 | |||
| f0b9a1d134 | |||
| 64369921ec | |||
| 70ae7f67a9 | |||
| 2ea86ef39f | |||
| 658bb71441 | |||
| 0b996ea321 | |||
| cf072424c6 | |||
| 42c0f19c68 | |||
| 8d1cabb288 | |||
| 87aeaab6b8 | |||
| ad5fb0fc22 | |||
| 8e6d546b97 | |||
| f916381a9b | |||
| fd94aea99b | |||
| cda4d3a566 | |||
| 22ca349171 | |||
| 74c08884ae | |||
| 005eab5694 | |||
| 56dd646dde | |||
| eb7f534b3b | |||
| 384cfa7156 | |||
| 224b176108 | |||
| 02b528ea8c | |||
| 4de3d69bb8 | |||
| c373d10720 | |||
| 88e5303d28 | |||
| 697e5d796f | |||
| 0baf73b9ae | |||
| 0341a0fe9d | |||
| e9fcacd7c6 | |||
| 502835453a | |||
| 914b9e4123 | |||
| 946ab62c30 | |||
| 13be9df131 | |||
| a54d71c990 | |||
| cc8ef6e927 | |||
| 3f53ba333b | |||
| aac11d05aa | |||
| acbdcf2fc1 | |||
| c12a7dc885 | |||
| ff0102256c | |||
| 75031038c8 | |||
| 70324570c8 | |||
| 5d6047b642 | |||
| 97d5140ef9 | |||
| dafba0648f | |||
| d240f8123c | |||
| 3cb822ee6c | |||
| 6d2fd16ec2 | |||
| e93aba2522 | |||
| 5768c1f7a2 | |||
| 30c8a31a48 | |||
| a2a6262ffe | |||
| dbd22fa719 | |||
| 5bb5022ebf | |||
| 3440dea0a5 | |||
| 36eaf1de4f | |||
| c3d560a9b6 | |||
| 09cee79122 | |||
| 03cbc67cfb | |||
| 23d9bb0e3d | |||
| f9d6917770 | |||
| bf45482c10 | |||
| 39a59336e4 | |||
| 7c0201f913 | |||
| b61fd84e22 | |||
| 52ea512eab | |||
|
|
26ac51b1be | ||
| fb1ff3c97a | |||
| 943fb7bf27 | |||
| 2fd4334259 | |||
| eb8f84a4b8 | |||
| e793e08e85 | |||
| 837306f16e | |||
| 182631b2b7 | |||
| 5cc9b16d59 | |||
| 6224ed2779 | |||
| fc3a4efc5f | |||
| 2be1e566b2 | |||
| 017f691841 | |||
| 43c5ddcd1e | |||
| ef9f855785 | |||
| a70402ab5e | |||
| 91bed82fd2 | |||
| 90812f2140 | |||
| 0c0b677474 | |||
| 63bae5c504 | |||
| 5847c79ffb | |||
| 176d0d4f90 | |||
| a0e94035db | |||
| 9b5eaf36e1 | |||
| f97291110f | |||
| e9ff516b1d | |||
| 2330820a15 | |||
| 36bb6b8fe8 | |||
| d84137daa7 | |||
| 4980c0f712 | |||
| b8cc628dd7 | |||
| b663916a59 | |||
| 6c1c6cbc42 | |||
| bcb012fc65 | |||
| 67acc46222 |
10
.gitignore
vendored
@@ -1,11 +1,5 @@
|
|||||||
|
.vscode
|
||||||
|
*.DS_Store
|
||||||
bin
|
bin
|
||||||
dll
|
|
||||||
icon
|
|
||||||
media_work
|
|
||||||
releases
|
|
||||||
resources
|
|
||||||
scripts
|
|
||||||
.DS_Store
|
|
||||||
todo.txt
|
|
||||||
data/config.bin
|
data/config.bin
|
||||||
data/score.bin
|
data/score.bin
|
||||||
19
.vscode/c_cpp_properties.json
vendored
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Mac",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"macFrameworkPath": [
|
|
||||||
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
|
|
||||||
],
|
|
||||||
"compilerPath": "/usr/bin/clang",
|
|
||||||
"intelliSenseMode": "macos-clang-x64",
|
|
||||||
"cStandard": "c11",
|
|
||||||
"cppStandard": "c++11"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
21
.vscode/launch.json
vendored
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "g++ - Build and debug",
|
|
||||||
"type": "cppdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/bin/coffee_crisis_macos_debug",
|
|
||||||
"args": [],
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"cwd": "${workspaceFolder}/bin",
|
|
||||||
"environment": [],
|
|
||||||
"externalConsole": false,
|
|
||||||
"MIMode": "lldb",
|
|
||||||
"preLaunchTask": "C/C++: g++ build"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
19
.vscode/settings.json
vendored
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"__tuple": "cpp",
|
|
||||||
"array": "cpp",
|
|
||||||
"algorithm": "cpp",
|
|
||||||
"__bit_reference": "cpp",
|
|
||||||
"__hash_table": "cpp",
|
|
||||||
"__split_buffer": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"stdexcept": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
31
.vscode/tasks.json
vendored
@@ -1,31 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "shell",
|
|
||||||
"label": "C/C++: g++ build",
|
|
||||||
"command": "/usr/bin/g++",
|
|
||||||
"args": [
|
|
||||||
"-g",
|
|
||||||
"${workspaceFolder}/source/*.cpp",
|
|
||||||
"-std=c++11",
|
|
||||||
"-Wall",
|
|
||||||
"-O2",
|
|
||||||
"-lSDL2",
|
|
||||||
"-o",
|
|
||||||
"${workspaceFolder}/bin/coffee_crisis_macos_debug"
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
},
|
|
||||||
"problemMatcher": [
|
|
||||||
"$gcc"
|
|
||||||
],
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
},
|
|
||||||
"detail": "compiler: /usr/bin/g++"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
11
Makefile
@@ -1,6 +1,13 @@
|
|||||||
|
executable = coffee_crisis
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
g++ -std=c++11 -Wall -O2 source/*.cpp -o bin/coffee_crisis_macos -lSDL2
|
g++ -std=c++11 -Wall -O2 source/*.cpp -o bin/$(executable)_macos -lSDL2
|
||||||
linux:
|
linux:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
g++ -std=c++11 -Wall -O2 source/*.cpp -o bin/coffee_crisis_linux -lSDL2
|
g++ source/*.cpp -std=c++11 -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o bin/$(executable)_linux
|
||||||
|
strip -s -R .comment -R .gnu.version bin/$(executable)_linux --strip-unneeded
|
||||||
|
opendingux:
|
||||||
|
mkdir -p bin
|
||||||
|
/opt/gcw0-toolchain/usr/bin/mipsel-linux-gcc -D GCWZERO -O2 -std=c++11 -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -lstdc++ source/*.cpp -o bin/$(executable)_opendingux
|
||||||
|
/opt/gcw0-toolchain/usr/bin/mksquashfs ./default.gcw0.desktop ./icon.png ./bin ./data ./media coffee_crisis.opk -all-root -noappend -no-exports -no-xattrs
|
||||||
24
README.md
@@ -1,6 +1,6 @@
|
|||||||
# Coffee Crisis
|
# Coffee Crisis
|
||||||
|
|
||||||
Coffe Crisis es un juego arcade que pondrá a prueba tus reflejos. Realizado entre el verano de 2020 y el invierno de 2021. Intenta conseguir todos los puntos que puedas con una sola vida y ayuda a Bal1 a defender la UPV ante la invasión de la cafeína.
|
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.
|
||||||
|
|
||||||
## Compilar
|
## Compilar
|
||||||
|
|
||||||
@@ -8,10 +8,10 @@ Para compilar el código se necesitan tener las librerías SDL instaladas en el
|
|||||||
|
|
||||||
En Linux:
|
En Linux:
|
||||||
```bash
|
```bash
|
||||||
sudo apt install lib-SDL2 g++
|
sudo apt install libsdl2-dev g++
|
||||||
```
|
```
|
||||||
|
|
||||||
En macos es más facil instalarlas con [brew](https://brew.sh):
|
En macOS se pueden instalar fácilmente con [brew](https://brew.sh):
|
||||||
```bash
|
```bash
|
||||||
brew install sdl2 g++
|
brew install sdl2 g++
|
||||||
```
|
```
|
||||||
@@ -23,21 +23,31 @@ En Linux:
|
|||||||
make linux
|
make linux
|
||||||
```
|
```
|
||||||
|
|
||||||
En macos:
|
En macOS:
|
||||||
```bash
|
```bash
|
||||||
make macos
|
make macos
|
||||||
```
|
```
|
||||||
|
|
||||||
## Como ejecutar
|
## Como ejecutar
|
||||||
|
|
||||||
|
Para ejecutar el juego hay que escribir en la terminal la orden que se muestra a continuación.
|
||||||
|
|
||||||
|
En Linux:
|
||||||
```bash
|
```bash
|
||||||
./bin/coffee_crisis
|
bin/coffee_crisis_linux
|
||||||
```
|
```
|
||||||
|
|
||||||
|
En macOS:
|
||||||
|
```bash
|
||||||
|
bin/coffee_crisis_macos
|
||||||
|
```
|
||||||
|
|
||||||
|
En macOS tambien puedes hacer doble click sobre el archivo coffee_crisis_macos que hay en la carpeta bin
|
||||||
|
|
||||||
## Agradecimientos
|
## 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.
|
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í.
|
Y por supuesto a ti por estar aquí.
|
||||||
|
|
||||||
## License
|
## Licencia
|
||||||
Buscar una licencia para que quiera haga con el código lo que le de la gana, menos sacar beneficio económico... que si lo hacen me expliquen como.
|
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.
|
||||||
1144
data/gamecontrollerdb.txt
Normal file
BIN
media/.DS_Store
vendored
BIN
media/font/8bithud.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
194
media/font/8bithud.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
8
|
||||||
|
# box height
|
||||||
|
8
|
||||||
|
# 32 espacio ( )
|
||||||
|
2
|
||||||
|
# 33 !
|
||||||
|
2
|
||||||
|
# 34 "
|
||||||
|
5
|
||||||
|
# 35 #
|
||||||
|
6
|
||||||
|
# 36 $
|
||||||
|
6
|
||||||
|
# 37 %
|
||||||
|
6
|
||||||
|
# 38 &
|
||||||
|
6
|
||||||
|
# 39 '
|
||||||
|
2
|
||||||
|
# 40 (
|
||||||
|
3
|
||||||
|
# 41 )
|
||||||
|
3
|
||||||
|
# 42 *
|
||||||
|
4
|
||||||
|
# 43 +
|
||||||
|
3
|
||||||
|
# 44 ,
|
||||||
|
2
|
||||||
|
# 45 -
|
||||||
|
3
|
||||||
|
# 46 .
|
||||||
|
2
|
||||||
|
# 47 /
|
||||||
|
4
|
||||||
|
# 48 0
|
||||||
|
6
|
||||||
|
# 49 1
|
||||||
|
6
|
||||||
|
# 50 2
|
||||||
|
6
|
||||||
|
# 51 3
|
||||||
|
6
|
||||||
|
# 52 4
|
||||||
|
6
|
||||||
|
# 53 5
|
||||||
|
6
|
||||||
|
# 54 6
|
||||||
|
6
|
||||||
|
# 55 7
|
||||||
|
6
|
||||||
|
# 56 8
|
||||||
|
6
|
||||||
|
# 57 9
|
||||||
|
6
|
||||||
|
# 58 :
|
||||||
|
2
|
||||||
|
# 59 ;
|
||||||
|
2
|
||||||
|
# 60 <
|
||||||
|
4
|
||||||
|
# 61 =
|
||||||
|
3
|
||||||
|
# 62 >
|
||||||
|
4
|
||||||
|
# 63 ?
|
||||||
|
6
|
||||||
|
# 64 @
|
||||||
|
8
|
||||||
|
# 65 A
|
||||||
|
6
|
||||||
|
# 66 B
|
||||||
|
6
|
||||||
|
# 67 C
|
||||||
|
6
|
||||||
|
# 68 D
|
||||||
|
6
|
||||||
|
# 69 E
|
||||||
|
6
|
||||||
|
# 70 F
|
||||||
|
6
|
||||||
|
# 71 G
|
||||||
|
6
|
||||||
|
# 72 H
|
||||||
|
6
|
||||||
|
# 73 I
|
||||||
|
6
|
||||||
|
# 74 J
|
||||||
|
6
|
||||||
|
# 75 K
|
||||||
|
6
|
||||||
|
# 76 L
|
||||||
|
6
|
||||||
|
# 77 M
|
||||||
|
6
|
||||||
|
# 78 N
|
||||||
|
6
|
||||||
|
# 79 O
|
||||||
|
6
|
||||||
|
# 80 P
|
||||||
|
6
|
||||||
|
# 81 Q
|
||||||
|
6
|
||||||
|
# 82 R
|
||||||
|
6
|
||||||
|
# 83 S
|
||||||
|
6
|
||||||
|
# 84 T
|
||||||
|
6
|
||||||
|
# 85 U
|
||||||
|
6
|
||||||
|
# 86 V
|
||||||
|
5
|
||||||
|
# 87 W
|
||||||
|
6
|
||||||
|
# 88 X
|
||||||
|
6
|
||||||
|
# 89 Y
|
||||||
|
6
|
||||||
|
# 90 Z
|
||||||
|
6
|
||||||
|
# 91 [
|
||||||
|
3
|
||||||
|
# 92 \
|
||||||
|
5
|
||||||
|
# 93 ]
|
||||||
|
3
|
||||||
|
# 94 ^
|
||||||
|
4
|
||||||
|
# 95 _
|
||||||
|
6
|
||||||
|
# 96 `
|
||||||
|
2
|
||||||
|
# 97 a
|
||||||
|
5
|
||||||
|
# 98 b
|
||||||
|
5
|
||||||
|
# 99 c
|
||||||
|
5
|
||||||
|
# 100 d
|
||||||
|
5
|
||||||
|
# 101 e
|
||||||
|
5
|
||||||
|
# 102 f
|
||||||
|
5
|
||||||
|
# 103 g
|
||||||
|
5
|
||||||
|
# 104 h
|
||||||
|
5
|
||||||
|
# 105 i
|
||||||
|
4
|
||||||
|
# 106 j
|
||||||
|
5
|
||||||
|
# 107 k
|
||||||
|
5
|
||||||
|
# 108 l
|
||||||
|
5
|
||||||
|
# 109 m
|
||||||
|
6
|
||||||
|
# 110 n
|
||||||
|
5
|
||||||
|
# 111 o
|
||||||
|
5
|
||||||
|
# 112 p
|
||||||
|
5
|
||||||
|
# 113 q
|
||||||
|
5
|
||||||
|
# 114 r
|
||||||
|
5
|
||||||
|
# 115 s
|
||||||
|
5
|
||||||
|
# 116 t
|
||||||
|
4
|
||||||
|
# 117 u
|
||||||
|
5
|
||||||
|
# 118 v
|
||||||
|
5
|
||||||
|
# 119 w
|
||||||
|
6
|
||||||
|
# 120 x
|
||||||
|
4
|
||||||
|
# 121 y
|
||||||
|
4
|
||||||
|
# 122 z
|
||||||
|
5
|
||||||
|
# 123 {
|
||||||
|
3
|
||||||
|
# 124 |
|
||||||
|
2
|
||||||
|
# 125 }
|
||||||
|
3
|
||||||
|
# 126 ~
|
||||||
|
3
|
||||||
BIN
media/font/nokia.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
194
media/font/nokia.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
10
|
||||||
|
# box height
|
||||||
|
10
|
||||||
|
# 32 espacio ( )
|
||||||
|
5
|
||||||
|
# 33 !
|
||||||
|
4
|
||||||
|
# 34 "
|
||||||
|
5
|
||||||
|
# 35 #
|
||||||
|
7
|
||||||
|
# 36 $
|
||||||
|
7
|
||||||
|
# 37 %
|
||||||
|
8
|
||||||
|
# 38 &
|
||||||
|
8
|
||||||
|
# 39 '
|
||||||
|
3
|
||||||
|
# 40 (
|
||||||
|
5
|
||||||
|
# 41 )
|
||||||
|
5
|
||||||
|
# 42 *
|
||||||
|
7
|
||||||
|
# 43 +
|
||||||
|
7
|
||||||
|
# 44 ,
|
||||||
|
4
|
||||||
|
# 45 -
|
||||||
|
6
|
||||||
|
# 46 .
|
||||||
|
4
|
||||||
|
# 47 /
|
||||||
|
5
|
||||||
|
# 48 0
|
||||||
|
7
|
||||||
|
# 49 1
|
||||||
|
5
|
||||||
|
# 50 2
|
||||||
|
7
|
||||||
|
# 51 3
|
||||||
|
7
|
||||||
|
# 52 4
|
||||||
|
7
|
||||||
|
# 53 5
|
||||||
|
7
|
||||||
|
# 54 6
|
||||||
|
7
|
||||||
|
# 55 7
|
||||||
|
7
|
||||||
|
# 56 8
|
||||||
|
7
|
||||||
|
# 57 9
|
||||||
|
7
|
||||||
|
# 58 :
|
||||||
|
4
|
||||||
|
# 59 ;
|
||||||
|
4
|
||||||
|
# 60 <
|
||||||
|
6
|
||||||
|
# 61 =
|
||||||
|
6
|
||||||
|
# 62 >
|
||||||
|
6
|
||||||
|
# 63 ?
|
||||||
|
7
|
||||||
|
# 64 @
|
||||||
|
8
|
||||||
|
# 65 A
|
||||||
|
7
|
||||||
|
# 66 B
|
||||||
|
7
|
||||||
|
# 67 C
|
||||||
|
7
|
||||||
|
# 68 D
|
||||||
|
7
|
||||||
|
# 69 E
|
||||||
|
7
|
||||||
|
# 70 F
|
||||||
|
7
|
||||||
|
# 71 G
|
||||||
|
7
|
||||||
|
# 72 H
|
||||||
|
7
|
||||||
|
# 73 I
|
||||||
|
4
|
||||||
|
# 74 J
|
||||||
|
6
|
||||||
|
# 75 K
|
||||||
|
8
|
||||||
|
# 76 L
|
||||||
|
6
|
||||||
|
# 77 M
|
||||||
|
9
|
||||||
|
# 78 N
|
||||||
|
8
|
||||||
|
# 79 O
|
||||||
|
8
|
||||||
|
# 80 P
|
||||||
|
7
|
||||||
|
# 81 Q
|
||||||
|
8
|
||||||
|
# 82 R
|
||||||
|
7
|
||||||
|
# 83 S
|
||||||
|
6
|
||||||
|
# 84 T
|
||||||
|
8
|
||||||
|
# 85 U
|
||||||
|
7
|
||||||
|
# 86 V
|
||||||
|
8
|
||||||
|
# 87 W
|
||||||
|
9
|
||||||
|
# 88 X
|
||||||
|
8
|
||||||
|
# 89 Y
|
||||||
|
8
|
||||||
|
# 90 Z
|
||||||
|
7
|
||||||
|
# 91 [
|
||||||
|
4
|
||||||
|
# 92 \
|
||||||
|
5
|
||||||
|
# 93 ]
|
||||||
|
4
|
||||||
|
# 94 ^
|
||||||
|
5
|
||||||
|
# 95 _
|
||||||
|
8
|
||||||
|
# 96 `
|
||||||
|
4
|
||||||
|
# 97 a
|
||||||
|
7
|
||||||
|
# 98 b
|
||||||
|
7
|
||||||
|
# 99 c
|
||||||
|
6
|
||||||
|
# 100 d
|
||||||
|
7
|
||||||
|
# 101 e
|
||||||
|
7
|
||||||
|
# 102 f
|
||||||
|
5
|
||||||
|
# 103 g
|
||||||
|
7
|
||||||
|
# 104 h
|
||||||
|
7
|
||||||
|
# 105 i
|
||||||
|
4
|
||||||
|
# 106 j
|
||||||
|
5
|
||||||
|
# 107 k
|
||||||
|
7
|
||||||
|
# 108 l
|
||||||
|
4
|
||||||
|
# 109 m
|
||||||
|
10
|
||||||
|
# 110 n
|
||||||
|
7
|
||||||
|
# 111 o
|
||||||
|
7
|
||||||
|
# 112 p
|
||||||
|
7
|
||||||
|
# 113 q
|
||||||
|
7
|
||||||
|
# 114 r
|
||||||
|
6
|
||||||
|
# 115 s
|
||||||
|
6
|
||||||
|
# 116 t
|
||||||
|
5
|
||||||
|
# 117 u
|
||||||
|
7
|
||||||
|
# 118 v
|
||||||
|
7
|
||||||
|
# 119 w
|
||||||
|
9
|
||||||
|
# 120 x
|
||||||
|
7
|
||||||
|
# 121 y
|
||||||
|
7
|
||||||
|
# 122 z
|
||||||
|
7
|
||||||
|
# 123 { -> ñ
|
||||||
|
7
|
||||||
|
# 124 | -> ç
|
||||||
|
7
|
||||||
|
# 125 }
|
||||||
|
0
|
||||||
|
# 126 ~
|
||||||
|
0
|
||||||
BIN
media/font/nokia2.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
194
media/font/nokia2.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
10
|
||||||
|
# box height
|
||||||
|
10
|
||||||
|
# 32 espacio ( )
|
||||||
|
5
|
||||||
|
# 33 !
|
||||||
|
4
|
||||||
|
# 34 "
|
||||||
|
5
|
||||||
|
# 35 #
|
||||||
|
7
|
||||||
|
# 36 $
|
||||||
|
7
|
||||||
|
# 37 %
|
||||||
|
8
|
||||||
|
# 38 &
|
||||||
|
8
|
||||||
|
# 39 '
|
||||||
|
3
|
||||||
|
# 40 (
|
||||||
|
5
|
||||||
|
# 41 )
|
||||||
|
5
|
||||||
|
# 42 *
|
||||||
|
7
|
||||||
|
# 43 +
|
||||||
|
7
|
||||||
|
# 44 ,
|
||||||
|
4
|
||||||
|
# 45 -
|
||||||
|
6
|
||||||
|
# 46 .
|
||||||
|
4
|
||||||
|
# 47 /
|
||||||
|
5
|
||||||
|
# 48 0
|
||||||
|
7
|
||||||
|
# 49 1
|
||||||
|
5
|
||||||
|
# 50 2
|
||||||
|
7
|
||||||
|
# 51 3
|
||||||
|
7
|
||||||
|
# 52 4
|
||||||
|
7
|
||||||
|
# 53 5
|
||||||
|
7
|
||||||
|
# 54 6
|
||||||
|
7
|
||||||
|
# 55 7
|
||||||
|
7
|
||||||
|
# 56 8
|
||||||
|
7
|
||||||
|
# 57 9
|
||||||
|
7
|
||||||
|
# 58 :
|
||||||
|
4
|
||||||
|
# 59 ;
|
||||||
|
4
|
||||||
|
# 60 <
|
||||||
|
6
|
||||||
|
# 61 =
|
||||||
|
6
|
||||||
|
# 62 >
|
||||||
|
6
|
||||||
|
# 63 ?
|
||||||
|
7
|
||||||
|
# 64 @
|
||||||
|
8
|
||||||
|
# 65 A
|
||||||
|
7
|
||||||
|
# 66 B
|
||||||
|
7
|
||||||
|
# 67 C
|
||||||
|
7
|
||||||
|
# 68 D
|
||||||
|
7
|
||||||
|
# 69 E
|
||||||
|
7
|
||||||
|
# 70 F
|
||||||
|
7
|
||||||
|
# 71 G
|
||||||
|
7
|
||||||
|
# 72 H
|
||||||
|
7
|
||||||
|
# 73 I
|
||||||
|
4
|
||||||
|
# 74 J
|
||||||
|
6
|
||||||
|
# 75 K
|
||||||
|
8
|
||||||
|
# 76 L
|
||||||
|
6
|
||||||
|
# 77 M
|
||||||
|
9
|
||||||
|
# 78 N
|
||||||
|
8
|
||||||
|
# 79 O
|
||||||
|
8
|
||||||
|
# 80 P
|
||||||
|
7
|
||||||
|
# 81 Q
|
||||||
|
8
|
||||||
|
# 82 R
|
||||||
|
7
|
||||||
|
# 83 S
|
||||||
|
6
|
||||||
|
# 84 T
|
||||||
|
8
|
||||||
|
# 85 U
|
||||||
|
7
|
||||||
|
# 86 V
|
||||||
|
8
|
||||||
|
# 87 W
|
||||||
|
9
|
||||||
|
# 88 X
|
||||||
|
8
|
||||||
|
# 89 Y
|
||||||
|
8
|
||||||
|
# 90 Z
|
||||||
|
7
|
||||||
|
# 91 [
|
||||||
|
4
|
||||||
|
# 92 \
|
||||||
|
5
|
||||||
|
# 93 ]
|
||||||
|
4
|
||||||
|
# 94 ^
|
||||||
|
5
|
||||||
|
# 95 _
|
||||||
|
8
|
||||||
|
# 96 `
|
||||||
|
4
|
||||||
|
# 97 a
|
||||||
|
7
|
||||||
|
# 98 b
|
||||||
|
7
|
||||||
|
# 99 c
|
||||||
|
6
|
||||||
|
# 100 d
|
||||||
|
7
|
||||||
|
# 101 e
|
||||||
|
7
|
||||||
|
# 102 f
|
||||||
|
5
|
||||||
|
# 103 g
|
||||||
|
7
|
||||||
|
# 104 h
|
||||||
|
7
|
||||||
|
# 105 i
|
||||||
|
4
|
||||||
|
# 106 j
|
||||||
|
5
|
||||||
|
# 107 k
|
||||||
|
7
|
||||||
|
# 108 l
|
||||||
|
4
|
||||||
|
# 109 m
|
||||||
|
10
|
||||||
|
# 110 n
|
||||||
|
7
|
||||||
|
# 111 o
|
||||||
|
7
|
||||||
|
# 112 p
|
||||||
|
7
|
||||||
|
# 113 q
|
||||||
|
7
|
||||||
|
# 114 r
|
||||||
|
6
|
||||||
|
# 115 s
|
||||||
|
6
|
||||||
|
# 116 t
|
||||||
|
5
|
||||||
|
# 117 u
|
||||||
|
7
|
||||||
|
# 118 v
|
||||||
|
7
|
||||||
|
# 119 w
|
||||||
|
9
|
||||||
|
# 120 x
|
||||||
|
7
|
||||||
|
# 121 y
|
||||||
|
7
|
||||||
|
# 122 z
|
||||||
|
7
|
||||||
|
# 123 { -> ñ
|
||||||
|
7
|
||||||
|
# 124 | -> ç
|
||||||
|
7
|
||||||
|
# 125 }
|
||||||
|
0
|
||||||
|
# 126 ~
|
||||||
|
0
|
||||||
BIN
media/font/nokia_big2.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
194
media/font/nokia_big2.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
20
|
||||||
|
# box height
|
||||||
|
20
|
||||||
|
# 32 espacio ( )
|
||||||
|
8
|
||||||
|
# 33 !
|
||||||
|
8
|
||||||
|
# 34 "
|
||||||
|
10
|
||||||
|
# 35 #
|
||||||
|
14
|
||||||
|
# 36 $
|
||||||
|
14
|
||||||
|
# 37 %
|
||||||
|
16
|
||||||
|
# 38 &
|
||||||
|
16
|
||||||
|
# 39 '
|
||||||
|
6
|
||||||
|
# 40 (
|
||||||
|
10
|
||||||
|
# 41 )
|
||||||
|
10
|
||||||
|
# 42 *
|
||||||
|
14
|
||||||
|
# 43 +
|
||||||
|
14
|
||||||
|
# 44 ,
|
||||||
|
8
|
||||||
|
# 45 -
|
||||||
|
12
|
||||||
|
# 46 .
|
||||||
|
8
|
||||||
|
# 47 /
|
||||||
|
10
|
||||||
|
# 48 0
|
||||||
|
14
|
||||||
|
# 49 1
|
||||||
|
10
|
||||||
|
# 50 2
|
||||||
|
14
|
||||||
|
# 51 6
|
||||||
|
14
|
||||||
|
# 52 8
|
||||||
|
14
|
||||||
|
# 53 10
|
||||||
|
14
|
||||||
|
# 54 12
|
||||||
|
14
|
||||||
|
# 55 14
|
||||||
|
14
|
||||||
|
# 56 16
|
||||||
|
14
|
||||||
|
# 57 18
|
||||||
|
14
|
||||||
|
# 58 :
|
||||||
|
8
|
||||||
|
# 59 ;
|
||||||
|
8
|
||||||
|
# 60 <
|
||||||
|
12
|
||||||
|
# 61 =
|
||||||
|
12
|
||||||
|
# 62 >
|
||||||
|
12
|
||||||
|
# 63 ?
|
||||||
|
14
|
||||||
|
# 64 @
|
||||||
|
16
|
||||||
|
# 65 A
|
||||||
|
14
|
||||||
|
# 66 B
|
||||||
|
14
|
||||||
|
# 67 C
|
||||||
|
14
|
||||||
|
# 68 D
|
||||||
|
14
|
||||||
|
# 69 E
|
||||||
|
14
|
||||||
|
# 70 F
|
||||||
|
14
|
||||||
|
# 71 G
|
||||||
|
14
|
||||||
|
# 72 H
|
||||||
|
14
|
||||||
|
# 73 I
|
||||||
|
8
|
||||||
|
# 74 J
|
||||||
|
12
|
||||||
|
# 75 K
|
||||||
|
16
|
||||||
|
# 76 L
|
||||||
|
12
|
||||||
|
# 77 M
|
||||||
|
18
|
||||||
|
# 78 N
|
||||||
|
16
|
||||||
|
# 79 O
|
||||||
|
16
|
||||||
|
# 80 P
|
||||||
|
14
|
||||||
|
# 81 Q
|
||||||
|
16
|
||||||
|
# 82 R
|
||||||
|
14
|
||||||
|
# 83 S
|
||||||
|
12
|
||||||
|
# 84 T
|
||||||
|
16
|
||||||
|
# 85 U
|
||||||
|
14
|
||||||
|
# 86 V
|
||||||
|
16
|
||||||
|
# 87 W
|
||||||
|
18
|
||||||
|
# 88 X
|
||||||
|
16
|
||||||
|
# 89 Y
|
||||||
|
16
|
||||||
|
# 90 Z
|
||||||
|
14
|
||||||
|
# 91 [
|
||||||
|
8
|
||||||
|
# 92 \
|
||||||
|
10
|
||||||
|
# 93 ]
|
||||||
|
8
|
||||||
|
# 94 ^
|
||||||
|
10
|
||||||
|
# 95 _
|
||||||
|
16
|
||||||
|
# 96 `
|
||||||
|
8
|
||||||
|
# 97 a
|
||||||
|
14
|
||||||
|
# 98 b
|
||||||
|
14
|
||||||
|
# 99 c
|
||||||
|
12
|
||||||
|
# 100 d
|
||||||
|
14
|
||||||
|
# 101 e
|
||||||
|
14
|
||||||
|
# 102 f
|
||||||
|
10
|
||||||
|
# 103 g
|
||||||
|
14
|
||||||
|
# 104 h
|
||||||
|
14
|
||||||
|
# 105 i
|
||||||
|
8
|
||||||
|
# 106 j
|
||||||
|
10
|
||||||
|
# 107 k
|
||||||
|
14
|
||||||
|
# 108 l
|
||||||
|
8
|
||||||
|
# 109 m
|
||||||
|
20
|
||||||
|
# 110 n
|
||||||
|
14
|
||||||
|
# 111 o
|
||||||
|
14
|
||||||
|
# 112 p
|
||||||
|
14
|
||||||
|
# 113 q
|
||||||
|
14
|
||||||
|
# 114 r
|
||||||
|
12
|
||||||
|
# 115 s
|
||||||
|
12
|
||||||
|
# 116 t
|
||||||
|
10
|
||||||
|
# 117 u
|
||||||
|
14
|
||||||
|
# 118 v
|
||||||
|
14
|
||||||
|
# 119 w
|
||||||
|
18
|
||||||
|
# 120 x
|
||||||
|
14
|
||||||
|
# 121 y
|
||||||
|
14
|
||||||
|
# 122 z
|
||||||
|
14
|
||||||
|
# 123 { -> ñ
|
||||||
|
14
|
||||||
|
# 124 | -> ç
|
||||||
|
14
|
||||||
|
# 125 }
|
||||||
|
0
|
||||||
|
# 126 ~
|
||||||
|
0
|
||||||
BIN
media/font/smb2.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
194
media/font/smb2.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
8
|
||||||
|
# box height
|
||||||
|
8
|
||||||
|
# 32 espacio ( )
|
||||||
|
7
|
||||||
|
# 33 !
|
||||||
|
7
|
||||||
|
# 34 "
|
||||||
|
7
|
||||||
|
# 35 #
|
||||||
|
7
|
||||||
|
# 36 $
|
||||||
|
7
|
||||||
|
# 37 %
|
||||||
|
7
|
||||||
|
# 38 &
|
||||||
|
7
|
||||||
|
# 39 '
|
||||||
|
7
|
||||||
|
# 40 (
|
||||||
|
7
|
||||||
|
# 41 )
|
||||||
|
7
|
||||||
|
# 42 *
|
||||||
|
7
|
||||||
|
# 43 +
|
||||||
|
7
|
||||||
|
# 44 ,
|
||||||
|
7
|
||||||
|
# 45 -
|
||||||
|
7
|
||||||
|
# 46 .
|
||||||
|
7
|
||||||
|
# 47 /
|
||||||
|
7
|
||||||
|
# 48 0
|
||||||
|
7
|
||||||
|
# 49 1
|
||||||
|
7
|
||||||
|
# 50 2
|
||||||
|
7
|
||||||
|
# 51 3
|
||||||
|
7
|
||||||
|
# 52 4
|
||||||
|
7
|
||||||
|
# 53 5
|
||||||
|
7
|
||||||
|
# 54 6
|
||||||
|
7
|
||||||
|
# 55 7
|
||||||
|
7
|
||||||
|
# 56 8
|
||||||
|
7
|
||||||
|
# 57 9
|
||||||
|
7
|
||||||
|
# 58 :
|
||||||
|
7
|
||||||
|
# 59 ;
|
||||||
|
7
|
||||||
|
# 60 <
|
||||||
|
7
|
||||||
|
# 61 =
|
||||||
|
7
|
||||||
|
# 62 >
|
||||||
|
7
|
||||||
|
# 63 ?
|
||||||
|
7
|
||||||
|
# 64 @
|
||||||
|
7
|
||||||
|
# 65 A
|
||||||
|
7
|
||||||
|
# 66 B
|
||||||
|
7
|
||||||
|
# 67 C
|
||||||
|
7
|
||||||
|
# 68 D
|
||||||
|
7
|
||||||
|
# 69 E
|
||||||
|
7
|
||||||
|
# 70 F
|
||||||
|
7
|
||||||
|
# 71 G
|
||||||
|
7
|
||||||
|
# 72 H
|
||||||
|
7
|
||||||
|
# 73 I
|
||||||
|
7
|
||||||
|
# 74 J
|
||||||
|
7
|
||||||
|
# 75 K
|
||||||
|
7
|
||||||
|
# 76 L
|
||||||
|
7
|
||||||
|
# 77 M
|
||||||
|
7
|
||||||
|
# 78 N
|
||||||
|
7
|
||||||
|
# 79 O
|
||||||
|
7
|
||||||
|
# 80 P
|
||||||
|
7
|
||||||
|
# 81 Q
|
||||||
|
7
|
||||||
|
# 82 R
|
||||||
|
7
|
||||||
|
# 83 S
|
||||||
|
7
|
||||||
|
# 84 T
|
||||||
|
7
|
||||||
|
# 85 U
|
||||||
|
7
|
||||||
|
# 86 V
|
||||||
|
7
|
||||||
|
# 87 W
|
||||||
|
7
|
||||||
|
# 88 X
|
||||||
|
7
|
||||||
|
# 89 Y
|
||||||
|
7
|
||||||
|
# 90 Z
|
||||||
|
7
|
||||||
|
# 91 [
|
||||||
|
7
|
||||||
|
# 92 \
|
||||||
|
7
|
||||||
|
# 93 ]
|
||||||
|
7
|
||||||
|
# 94 ^
|
||||||
|
7
|
||||||
|
# 95 _
|
||||||
|
7
|
||||||
|
# 96 `
|
||||||
|
7
|
||||||
|
# 97 a
|
||||||
|
7
|
||||||
|
# 98 b
|
||||||
|
7
|
||||||
|
# 99 c
|
||||||
|
7
|
||||||
|
# 100 d
|
||||||
|
7
|
||||||
|
# 101 e
|
||||||
|
7
|
||||||
|
# 102 f
|
||||||
|
7
|
||||||
|
# 103 g
|
||||||
|
7
|
||||||
|
# 104 h
|
||||||
|
7
|
||||||
|
# 105 i
|
||||||
|
7
|
||||||
|
# 106 j
|
||||||
|
7
|
||||||
|
# 107 k
|
||||||
|
7
|
||||||
|
# 108 l
|
||||||
|
7
|
||||||
|
# 109 m
|
||||||
|
7
|
||||||
|
# 110 n
|
||||||
|
7
|
||||||
|
# 111 o
|
||||||
|
7
|
||||||
|
# 112 p
|
||||||
|
7
|
||||||
|
# 113 q
|
||||||
|
7
|
||||||
|
# 114 r
|
||||||
|
7
|
||||||
|
# 115 s
|
||||||
|
7
|
||||||
|
# 116 t
|
||||||
|
7
|
||||||
|
# 117 u
|
||||||
|
7
|
||||||
|
# 118 v
|
||||||
|
7
|
||||||
|
# 119 w
|
||||||
|
7
|
||||||
|
# 120 x
|
||||||
|
7
|
||||||
|
# 121 y
|
||||||
|
7
|
||||||
|
# 122 z
|
||||||
|
7
|
||||||
|
# 123 {
|
||||||
|
7
|
||||||
|
# 124 |
|
||||||
|
7
|
||||||
|
# 125 }
|
||||||
|
7
|
||||||
|
# 126 ~
|
||||||
|
7
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
194
media/font/smb2_big.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
16
|
||||||
|
# box height
|
||||||
|
16
|
||||||
|
# 32 espacio ( )
|
||||||
|
16
|
||||||
|
# 33 !
|
||||||
|
16
|
||||||
|
# 34 "
|
||||||
|
16
|
||||||
|
# 35 #
|
||||||
|
16
|
||||||
|
# 36 $
|
||||||
|
16
|
||||||
|
# 37 %
|
||||||
|
16
|
||||||
|
# 38 &
|
||||||
|
16
|
||||||
|
# 39 '
|
||||||
|
16
|
||||||
|
# 40 (
|
||||||
|
16
|
||||||
|
# 41 )
|
||||||
|
16
|
||||||
|
# 42 *
|
||||||
|
16
|
||||||
|
# 43 +
|
||||||
|
16
|
||||||
|
# 44 ,
|
||||||
|
16
|
||||||
|
# 45 -
|
||||||
|
16
|
||||||
|
# 46 .
|
||||||
|
16
|
||||||
|
# 47 /
|
||||||
|
16
|
||||||
|
# 48 0
|
||||||
|
16
|
||||||
|
# 49 1
|
||||||
|
16
|
||||||
|
# 50 2
|
||||||
|
16
|
||||||
|
# 51 3
|
||||||
|
16
|
||||||
|
# 52 4
|
||||||
|
16
|
||||||
|
# 53 5
|
||||||
|
16
|
||||||
|
# 54 6
|
||||||
|
16
|
||||||
|
# 55 7
|
||||||
|
16
|
||||||
|
# 56 8
|
||||||
|
16
|
||||||
|
# 57 9
|
||||||
|
16
|
||||||
|
# 58 :
|
||||||
|
16
|
||||||
|
# 59 ;
|
||||||
|
16
|
||||||
|
# 60 <
|
||||||
|
16
|
||||||
|
# 61 =
|
||||||
|
16
|
||||||
|
# 62 >
|
||||||
|
16
|
||||||
|
# 63 ?
|
||||||
|
16
|
||||||
|
# 64 @
|
||||||
|
16
|
||||||
|
# 65 A
|
||||||
|
16
|
||||||
|
# 66 B
|
||||||
|
16
|
||||||
|
# 67 C
|
||||||
|
16
|
||||||
|
# 68 D
|
||||||
|
16
|
||||||
|
# 69 E
|
||||||
|
16
|
||||||
|
# 70 F
|
||||||
|
16
|
||||||
|
# 71 G
|
||||||
|
16
|
||||||
|
# 72 H
|
||||||
|
16
|
||||||
|
# 73 I
|
||||||
|
16
|
||||||
|
# 74 J
|
||||||
|
16
|
||||||
|
# 75 K
|
||||||
|
16
|
||||||
|
# 76 L
|
||||||
|
16
|
||||||
|
# 77 M
|
||||||
|
16
|
||||||
|
# 78 N
|
||||||
|
16
|
||||||
|
# 79 O
|
||||||
|
16
|
||||||
|
# 80 P
|
||||||
|
16
|
||||||
|
# 81 Q
|
||||||
|
16
|
||||||
|
# 82 R
|
||||||
|
16
|
||||||
|
# 83 S
|
||||||
|
16
|
||||||
|
# 84 T
|
||||||
|
16
|
||||||
|
# 85 U
|
||||||
|
16
|
||||||
|
# 86 V
|
||||||
|
16
|
||||||
|
# 87 W
|
||||||
|
16
|
||||||
|
# 88 X
|
||||||
|
16
|
||||||
|
# 89 Y
|
||||||
|
16
|
||||||
|
# 90 Z
|
||||||
|
16
|
||||||
|
# 91 [
|
||||||
|
16
|
||||||
|
# 92 \
|
||||||
|
16
|
||||||
|
# 93 ]
|
||||||
|
16
|
||||||
|
# 94 ^
|
||||||
|
16
|
||||||
|
# 95 _
|
||||||
|
16
|
||||||
|
# 96 `
|
||||||
|
16
|
||||||
|
# 97 a
|
||||||
|
16
|
||||||
|
# 98 b
|
||||||
|
16
|
||||||
|
# 99 c
|
||||||
|
16
|
||||||
|
# 100 d
|
||||||
|
16
|
||||||
|
# 101 e
|
||||||
|
16
|
||||||
|
# 102 f
|
||||||
|
16
|
||||||
|
# 103 g
|
||||||
|
16
|
||||||
|
# 104 h
|
||||||
|
16
|
||||||
|
# 105 i
|
||||||
|
16
|
||||||
|
# 106 j
|
||||||
|
16
|
||||||
|
# 107 k
|
||||||
|
16
|
||||||
|
# 108 l
|
||||||
|
16
|
||||||
|
# 109 m
|
||||||
|
16
|
||||||
|
# 110 n
|
||||||
|
16
|
||||||
|
# 111 o
|
||||||
|
16
|
||||||
|
# 112 p
|
||||||
|
16
|
||||||
|
# 113 q
|
||||||
|
16
|
||||||
|
# 114 r
|
||||||
|
16
|
||||||
|
# 115 s
|
||||||
|
16
|
||||||
|
# 116 t
|
||||||
|
16
|
||||||
|
# 117 u
|
||||||
|
16
|
||||||
|
# 118 v
|
||||||
|
16
|
||||||
|
# 119 w
|
||||||
|
16
|
||||||
|
# 120 x
|
||||||
|
16
|
||||||
|
# 121 y
|
||||||
|
16
|
||||||
|
# 122 z
|
||||||
|
16
|
||||||
|
# 123 {
|
||||||
|
16
|
||||||
|
# 124 |
|
||||||
|
16
|
||||||
|
# 125 }
|
||||||
|
16
|
||||||
|
# 126 ~
|
||||||
|
16
|
||||||
BIN
media/gfx/.DS_Store
vendored
|
Before Width: | Height: | Size: 348 B After Width: | Height: | Size: 644 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 146 B |
BIN
media/gfx/player1_body.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
media/gfx/player1_death.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
media/gfx/player1_head.png
Normal file
|
After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 785 B After Width: | Height: | Size: 785 B |
BIN
media/gfx/player2_body.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
media/gfx/player2_death.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
media/gfx/player2_head.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
media/gfx/player2_legs.png
Normal file
|
After Width: | Height: | Size: 654 B |
|
Before Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 672 B |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 71 KiB |
160
media/lang/ba_BA.txt
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
## 0 - MENU DEL TITULO
|
||||||
|
JUGAR
|
||||||
|
## 1 - MENU DEL TITULO
|
||||||
|
OPCIONS
|
||||||
|
## 2 - MENU DEL TITULO
|
||||||
|
INSTRUCCIONS
|
||||||
|
## 3 - MENU DEL TITULO
|
||||||
|
EIXIR
|
||||||
|
## 4 - MENU DE OPCIONES
|
||||||
|
FINESTRA
|
||||||
|
## 5 - MENU DE OPCIONES
|
||||||
|
PANTALLA COMPLETA
|
||||||
|
## 6 - MENU DE OPCIONES
|
||||||
|
PANTALLA COMPLETA FALSA
|
||||||
|
## 7 - MENU DE OPCIONES
|
||||||
|
TAMANY DE FINESTRA
|
||||||
|
## 8 - MENU DE OPCIONES
|
||||||
|
IDIOMA
|
||||||
|
## 9 - MENU DE OPCIONES
|
||||||
|
[ ACEPTAR ]
|
||||||
|
## 10 - MENU DE OPCIONES
|
||||||
|
[ CANCELAR ]
|
||||||
|
## 11 - INSTRUCCIONES
|
||||||
|
OBJECTIU
|
||||||
|
## 12 - INSTRUCCIONES
|
||||||
|
HAS D'EXPLOTAR
|
||||||
|
## 13 - INSTRUCCIONES
|
||||||
|
TANTS GLOBUS COM PUGUES
|
||||||
|
## 14 - INSTRUCCIONES
|
||||||
|
LA DIFICULTAT AUGMENTA
|
||||||
|
## 15 - INSTRUCCIONES
|
||||||
|
A MESURA QUE VAS PUNTUANT
|
||||||
|
## 16 - INSTRUCCIONES
|
||||||
|
OBJECTES
|
||||||
|
## 17 - INSTRUCCIONES
|
||||||
|
1.000 PUNTS
|
||||||
|
## 18 - INSTRUCCIONES
|
||||||
|
2.500 PUNTS
|
||||||
|
## 19 - INSTRUCCIONES
|
||||||
|
5.000 PUNTS
|
||||||
|
## 20 - INSTRUCCIONES
|
||||||
|
PARA EL TEMPS
|
||||||
|
## 21 - INSTRUCCIONES
|
||||||
|
VIDA EXTRA
|
||||||
|
## 22 - INSTRUCCIONES
|
||||||
|
PREM UNA TECLA PER A TORNAR
|
||||||
|
## 23 - TITULO
|
||||||
|
PREM QUALSEVOL TECLA
|
||||||
|
## 24 - MENU SELECCION DE IDIOMA
|
||||||
|
ESPA{OL (ESPANYOL)
|
||||||
|
## 25 - MENU SELECCION DE IDIOMA
|
||||||
|
BALOONCIA
|
||||||
|
## 26 - MENU SELECCION DE IDIOMA
|
||||||
|
ENGLISH (ANGLES)
|
||||||
|
## 27 - INTRO
|
||||||
|
Un dia qualsevol de l'any 2000
|
||||||
|
## 28 - INTRO
|
||||||
|
Tot esta tranquil a la UPV
|
||||||
|
## 29 - INTRO
|
||||||
|
Fins que un desaprensiu...
|
||||||
|
## 30 - INTRO
|
||||||
|
HEY! ME ANE A FERME UN CORTAET...
|
||||||
|
## 31 - INTRO
|
||||||
|
UAAAAAAAAAAAAA!!!
|
||||||
|
## 32 - INTRO
|
||||||
|
Espera un moment...
|
||||||
|
## 33 - INTRO
|
||||||
|
Si resulta que no tinc solt!
|
||||||
|
## 34 - INTRO
|
||||||
|
MERDA DE MAQUINA!
|
||||||
|
## 35 - INTRO
|
||||||
|
Blop... blop... blop...
|
||||||
|
## 36 - TEXTOS DEL JUEGO
|
||||||
|
Temps detes:
|
||||||
|
## 37 - TEXTOS DEL JUEGO
|
||||||
|
D E M O
|
||||||
|
## 38 - TEXTOS DEL JUEGO
|
||||||
|
fases mes!
|
||||||
|
## 39 -
|
||||||
|
|
||||||
|
## 40 -
|
||||||
|
|
||||||
|
## 41 -
|
||||||
|
|
||||||
|
## 42 -
|
||||||
|
|
||||||
|
## 43 - PANTALLA DE GAME OVER
|
||||||
|
FI DEL JOC
|
||||||
|
## 44 - PANTALLA DE GAME OVER
|
||||||
|
ELS TEUS PUNTS:
|
||||||
|
## 45 - PANTALLA DE GAME OVER
|
||||||
|
CONTINUAR?
|
||||||
|
## 46 - MENU DE PAUSA
|
||||||
|
CONTINUAR
|
||||||
|
## 47 - MENU DE PAUSA
|
||||||
|
EIXIR DEL JOC
|
||||||
|
## 48 - MENU GAME OVER
|
||||||
|
SI
|
||||||
|
## 49 - MENU GAME OVER
|
||||||
|
NO
|
||||||
|
## 50 - TEXTO DE COMPLETAR EL JUEGO
|
||||||
|
Felicitats!!
|
||||||
|
## 51 - MENU DEL TITULO
|
||||||
|
1 JUGADOR
|
||||||
|
## 52 - MENU DEL TITULO
|
||||||
|
2 JUGADORS
|
||||||
|
## 53 MARCADOR
|
||||||
|
jugador 1
|
||||||
|
## 54 MARCADOR
|
||||||
|
jugador 2
|
||||||
|
## 55 MARCADOR
|
||||||
|
mult
|
||||||
|
## 56 MARCADOR
|
||||||
|
max. puntuacio
|
||||||
|
## 57 MARCADOR
|
||||||
|
fase
|
||||||
|
## 58 - MENU DE OPCIONES
|
||||||
|
MODE DE VISUALITZACIO
|
||||||
|
## 59 - MENU DE OPCIONES
|
||||||
|
DIFICULTAT
|
||||||
|
## 60 - MENU DE OPCIONES
|
||||||
|
FILTRE
|
||||||
|
## 61 - MENU DE OPCIONES
|
||||||
|
SINC. VERTICAL
|
||||||
|
## 62 - MENU DE OPCIONES
|
||||||
|
CONTROLS DEL JUGADOR 1
|
||||||
|
## 63 - MENU DE OPCIONES
|
||||||
|
CONTROLS DEL JUGADOR 2
|
||||||
|
## 64 -
|
||||||
|
|
||||||
|
## 65 -
|
||||||
|
|
||||||
|
## 66 - MENU DE OPCIONES
|
||||||
|
FACIL
|
||||||
|
## 67 - MENU DE OPCIONES
|
||||||
|
NORMAL
|
||||||
|
## 68 - MENU DE OPCIONES
|
||||||
|
DIFICIL
|
||||||
|
## 69 - MENU DE OPCIONES
|
||||||
|
TECLAT
|
||||||
|
## 70 - MENU DE OPCIONES
|
||||||
|
MANDO
|
||||||
|
## 71 - MENU DE OPCIONES
|
||||||
|
LINEAL
|
||||||
|
## 72 - MENU DE OPCIONES
|
||||||
|
NEAREST
|
||||||
|
## 73 - MENU DE OPCIONES
|
||||||
|
ACTIVADA
|
||||||
|
## 74 - MENU DE OPCIONES
|
||||||
|
DESACTIVADA
|
||||||
|
## 75 - JUEGO
|
||||||
|
Endavant!
|
||||||
|
## 76 - JUEGO
|
||||||
|
1.000.000 de punts!
|
||||||
|
## 77 - PANTALLA DE GAME OVER
|
||||||
|
PUNTS J1:
|
||||||
|
## 78 - PANTALLA DE GAME OVER
|
||||||
|
PUNTS J2:
|
||||||
|
## 79 - TEXTOS DEL JUEGO
|
||||||
|
Ultima fase!
|
||||||
160
media/lang/en_UK.txt
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
## 0 - MENU DEL TITULO
|
||||||
|
PLAY
|
||||||
|
## 1 - MENU DEL TITULO
|
||||||
|
OPTIONS
|
||||||
|
## 2 - MENU DEL TITULO
|
||||||
|
HOW TO PLAY
|
||||||
|
## 3 - MENU DEL TITULO
|
||||||
|
QUIT
|
||||||
|
## 4 - MENU DE OPCIONES
|
||||||
|
WINDOW
|
||||||
|
## 5 - MENU DE OPCIONES
|
||||||
|
FULLSCREEN
|
||||||
|
## 6 - MENU DE OPCIONES
|
||||||
|
FAKE FULLSCREEN
|
||||||
|
## 7 - MENU DE OPCIONES
|
||||||
|
WINDOW SIZE
|
||||||
|
## 8 - MENU DE OPCIONES
|
||||||
|
LANGUAGE
|
||||||
|
## 9 - MENU DE OPCIONES
|
||||||
|
[ ACCEPT ]
|
||||||
|
## 10 - MENU DE OPCIONES
|
||||||
|
[ CANCEL ]
|
||||||
|
## 11 - INSTRUCCIONES
|
||||||
|
OBJECTIVE
|
||||||
|
## 12 - INSTRUCCIONES
|
||||||
|
YOU HAVE TO POP AS MANY
|
||||||
|
## 13 - INSTRUCCIONES
|
||||||
|
BALLOONS AS YOU CAN
|
||||||
|
## 14 - INSTRUCCIONES
|
||||||
|
DIFFICULTY WILL BE INCREASED
|
||||||
|
## 15 - INSTRUCCIONES
|
||||||
|
AS YOU SCORE POINTS
|
||||||
|
## 16 - INSTRUCCIONES
|
||||||
|
ITEMS
|
||||||
|
## 17 - INSTRUCCIONES
|
||||||
|
1.000 POINTS
|
||||||
|
## 18 - INSTRUCCIONES
|
||||||
|
2.500 POINTS
|
||||||
|
## 19 - INSTRUCCIONES
|
||||||
|
5.000 POINTS
|
||||||
|
## 20 - INSTRUCCIONES
|
||||||
|
TIME STOPPER
|
||||||
|
## 21 - INSTRUCCIONES
|
||||||
|
EXTRA HIT
|
||||||
|
## 22 - INSTRUCCIONES
|
||||||
|
PRESS ANY KEY TO RETURN
|
||||||
|
## 23 - TITULO
|
||||||
|
PRESS ANY KEY
|
||||||
|
## 24 - MENU SELECCION DE IDIOMA
|
||||||
|
ESPA{OL (SPANISH)
|
||||||
|
## 25 - MENU SELECCION DE IDIOMA
|
||||||
|
BALOONCIA (VALENCIAN)
|
||||||
|
## 26 - MENU SELECCION DE IDIOMA
|
||||||
|
ENGLISH
|
||||||
|
## 27 - INTRO
|
||||||
|
Any day of the year 2000
|
||||||
|
## 28 - INTRO
|
||||||
|
Everything is quiet at the UPV
|
||||||
|
## 29 - INTRO
|
||||||
|
Until a bastard arrives...
|
||||||
|
## 30 - INTRO
|
||||||
|
YO! GONNA TAKE A CAFELITO...
|
||||||
|
## 31 - INTRO
|
||||||
|
AAAAAAAARGHHHH!!!
|
||||||
|
## 32 - INTRO
|
||||||
|
Wait a moment...
|
||||||
|
## 33 - INTRO
|
||||||
|
I don't have any loose!
|
||||||
|
## 34 - INTRO
|
||||||
|
FUCKING MACHINE!
|
||||||
|
## 35 - INTRO
|
||||||
|
Blop... blop... blop...
|
||||||
|
## 36 - TEXTOS DEL JUEGO
|
||||||
|
Time stopped:
|
||||||
|
## 37 - TEXTOS DEL JUEGO
|
||||||
|
D E M O
|
||||||
|
## 38 - TEXTOS DEL JUEGO
|
||||||
|
stages left!
|
||||||
|
## 39 -
|
||||||
|
|
||||||
|
## 40 -
|
||||||
|
|
||||||
|
## 41 -
|
||||||
|
|
||||||
|
## 42 -
|
||||||
|
|
||||||
|
## 43 - PANTALLA DE GAME OVER
|
||||||
|
GAME OVER
|
||||||
|
## 44 - PANTALLA DE GAME OVER
|
||||||
|
YOUR SCORE:
|
||||||
|
## 45 - PANTALLA DE GAME OVER
|
||||||
|
CONTINUE?
|
||||||
|
## 46 - MENU DE PAUSA
|
||||||
|
CONTINUE
|
||||||
|
## 47 - MENU DE PAUSA
|
||||||
|
LEAVE GAME
|
||||||
|
## 48 - MENU GAME OVER
|
||||||
|
YES
|
||||||
|
## 49 - MENU GAME OVER
|
||||||
|
NO
|
||||||
|
## 50 - TEXTO DE COMPLETAR EL JUEGO
|
||||||
|
Congratulations!!
|
||||||
|
## 51 - MENU DEL TITULO
|
||||||
|
1 PLAYER
|
||||||
|
## 52 - MENU DEL TITULO
|
||||||
|
2 PLAYERS
|
||||||
|
## 53 - MARCADOR
|
||||||
|
player 1
|
||||||
|
## 54 - MARCADOR
|
||||||
|
player 2
|
||||||
|
## 55 - MARCADOR
|
||||||
|
mult
|
||||||
|
## 56 - MARCADOR
|
||||||
|
high score
|
||||||
|
## 57 - MARCADOR
|
||||||
|
stage
|
||||||
|
## 58 - MENU DE OPCIONES
|
||||||
|
DISPLAY MODE
|
||||||
|
## 59 - MENU DE OPCIONES
|
||||||
|
DIFFICULTY
|
||||||
|
## 60 - MENU DE OPCIONES
|
||||||
|
FILTER
|
||||||
|
## 61 - MENU DE OPCIONES
|
||||||
|
VSYNC
|
||||||
|
## 62 - MENU DE OPCIONES
|
||||||
|
PLAYER 1 CONTROLS
|
||||||
|
## 63 - MENU DE OPCIONES
|
||||||
|
PLAYER 2 CONTROLS
|
||||||
|
## 64 -
|
||||||
|
|
||||||
|
## 65 -
|
||||||
|
|
||||||
|
## 66 - MENU DE OPCIONES
|
||||||
|
EASY
|
||||||
|
## 67 - MENU DE OPCIONES
|
||||||
|
NORMAL
|
||||||
|
## 68 - MENU DE OPCIONES
|
||||||
|
HARD
|
||||||
|
## 69 - MENU DE OPCIONES
|
||||||
|
KEYBOARD
|
||||||
|
## 70 - MENU DE OPCIONES
|
||||||
|
GAME CONTROLLER
|
||||||
|
## 71 - MENU DE OPCIONES
|
||||||
|
LINEAL
|
||||||
|
## 72 - MENU DE OPCIONES
|
||||||
|
NEAREST
|
||||||
|
## 73 - MENU DE OPCIONES
|
||||||
|
ON
|
||||||
|
## 74 - MENU DE OPCIONES
|
||||||
|
OFF
|
||||||
|
## 75 - JUEGO
|
||||||
|
Get Ready!
|
||||||
|
## 76 - JUEGO
|
||||||
|
1.000.000 points!
|
||||||
|
## 77 - PANTALLA DE GAME OVER
|
||||||
|
PLAYER1 SCORE:
|
||||||
|
## 78 - PANTALLA DE GAME OVER
|
||||||
|
PLAYER2 SCORE:
|
||||||
|
## 79 - TEXTOS DEL JUEGO
|
||||||
|
Last stage!
|
||||||
160
media/lang/es_ES.txt
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
## 0 - MENU DEL TITULO
|
||||||
|
JUGAR
|
||||||
|
## 1 - MENU DEL TITULO
|
||||||
|
OPCIONES
|
||||||
|
## 2 - MENU DEL TITULO
|
||||||
|
INSTRUCCIONES
|
||||||
|
## 3 - MENU DEL TITULO
|
||||||
|
SALIR
|
||||||
|
## 4 - MENU DE OPCIONES
|
||||||
|
VENTANA
|
||||||
|
## 5 - MENU DE OPCIONES
|
||||||
|
PANTALLA COMPLETA
|
||||||
|
## 6 - MENU DE OPCIONES
|
||||||
|
PANTALLA COMPLETA FALSA
|
||||||
|
## 7 - MENU DE OPCIONES
|
||||||
|
TAMA{O DE VENTANA
|
||||||
|
## 8 - MENU DE OPCIONES
|
||||||
|
IDIOMA
|
||||||
|
## 9 - MENU DE OPCIONES
|
||||||
|
[ ACEPTAR ]
|
||||||
|
## 10 - MENU DE OPCIONES
|
||||||
|
[ CANCELAR ]
|
||||||
|
## 11 - INSTRUCCIONES
|
||||||
|
OBJETIVO
|
||||||
|
## 12 - INSTRUCCIONES
|
||||||
|
TIENES QUE EXPLOTAR
|
||||||
|
## 13 - INSTRUCCIONES
|
||||||
|
TANTOS GLOBOS COMO PUEDAS
|
||||||
|
## 14 - INSTRUCCIONES
|
||||||
|
LA DIFICULTAD SE INCREMENTA
|
||||||
|
## 15 - INSTRUCCIONES
|
||||||
|
A MEDIDA QUE VAS PUNTUANDO
|
||||||
|
## 16 - INSTRUCCIONES
|
||||||
|
OBJETOS
|
||||||
|
## 17 - INSTRUCCIONES
|
||||||
|
1.000 PUNTOS
|
||||||
|
## 18 - INSTRUCCIONES
|
||||||
|
2.500 PUNTOS
|
||||||
|
## 19 - INSTRUCCIONES
|
||||||
|
5.000 PUNTOS
|
||||||
|
## 20 - INSTRUCCIONES
|
||||||
|
DETIENE EL TIEMPO
|
||||||
|
## 21 - INSTRUCCIONES
|
||||||
|
VIDA EXTRA
|
||||||
|
## 22 - INSTRUCCIONES
|
||||||
|
PULSA UNA TECLA PARA VOLVER
|
||||||
|
## 23 - TITULO
|
||||||
|
PULSA CUALQUIER TECLA
|
||||||
|
## 24 - MENU SELECCION DE IDIOMA
|
||||||
|
ESPA{OL
|
||||||
|
## 25 - MENU SELECCION DE IDIOMA
|
||||||
|
BALOONCIA (VALENCIANO)
|
||||||
|
## 26 - MENU SELECCION DE IDIOMA
|
||||||
|
ENGLISH (INGLES)
|
||||||
|
## 27 - INTRO
|
||||||
|
Un dia cualquiera del a{o 2000
|
||||||
|
## 28 - INTRO
|
||||||
|
Todo esta tranquilo en la UPV
|
||||||
|
## 29 - INTRO
|
||||||
|
Hasta que un desaprensivo...
|
||||||
|
## 30 - INTRO
|
||||||
|
HEY! VOY A SACARME UN TALLADET...
|
||||||
|
## 31 - INTRO
|
||||||
|
UAAAAAAAAAAAAA!!!
|
||||||
|
## 32 - INTRO
|
||||||
|
Espera un momento...
|
||||||
|
## 33 - INTRO
|
||||||
|
Si no llevo suelto encima!
|
||||||
|
## 34 - INTRO
|
||||||
|
MIERDA DE MAQUINA!
|
||||||
|
## 35 - INTRO
|
||||||
|
Blop... blop... blop...
|
||||||
|
## 36 - TEXTOS DEL JUEGO
|
||||||
|
Tiempo:
|
||||||
|
## 37 - TEXTOS DEL JUEGO
|
||||||
|
D E M O
|
||||||
|
## 38 - TEXTOS DEL JUEGO
|
||||||
|
fases mas!
|
||||||
|
## 39 -
|
||||||
|
|
||||||
|
## 40 -
|
||||||
|
|
||||||
|
## 41 -
|
||||||
|
|
||||||
|
## 42 -
|
||||||
|
|
||||||
|
## 43 - PANTALLA DE GAME OVER
|
||||||
|
FIN DE JUEGO
|
||||||
|
## 44 - PANTALLA DE GAME OVER
|
||||||
|
TU PUNTUACION:
|
||||||
|
## 45 - PANTALLA DE GAME OVER
|
||||||
|
CONTINUAR?
|
||||||
|
## 46 - MENU DE PAUSA
|
||||||
|
CONTINUAR
|
||||||
|
## 47 - MENU DE PAUSA
|
||||||
|
SALIR DEL JUEGO
|
||||||
|
## 48 - MENU GAME OVER
|
||||||
|
SI
|
||||||
|
## 49 - MENU GAME OVER
|
||||||
|
NO
|
||||||
|
## 50 - TEXTO DE COMPLETAR EL JUEGO
|
||||||
|
Felicidades!!
|
||||||
|
## 51 - MENU DEL TITULO
|
||||||
|
1 JUGADOR
|
||||||
|
## 52 - MENU DEL TITULO
|
||||||
|
2 JUGADORES
|
||||||
|
## 53 - MARCADOR
|
||||||
|
jugador 1
|
||||||
|
## 54 - MARCADOR
|
||||||
|
jugador 2
|
||||||
|
## 55 - MARCADOR
|
||||||
|
mult
|
||||||
|
## 56 - MARCADOR
|
||||||
|
max. puntuacion
|
||||||
|
## 57 - MARCADOR
|
||||||
|
FASE
|
||||||
|
## 58 - MENU DE OPCIONES
|
||||||
|
MODO DE VISUALIZACION
|
||||||
|
## 59 - MENU DE OPCIONES
|
||||||
|
DIFICULTAD
|
||||||
|
## 60 - MENU DE OPCIONES
|
||||||
|
FILTRO
|
||||||
|
## 61 - MENU DE OPCIONES
|
||||||
|
SINC. VERTICAL
|
||||||
|
## 62 - MENU DE OPCIONES
|
||||||
|
CONTROLES DEL JUGADOR 1
|
||||||
|
## 63 - MENU DE OPCIONES
|
||||||
|
CONTROLES DEL JUGADOR 2
|
||||||
|
## 64 -
|
||||||
|
|
||||||
|
## 65 -
|
||||||
|
|
||||||
|
## 66 - MENU DE OPCIONES
|
||||||
|
FACIL
|
||||||
|
## 67 - MENU DE OPCIONES
|
||||||
|
NORMAL
|
||||||
|
## 68 - MENU DE OPCIONES
|
||||||
|
DIFICIL
|
||||||
|
## 69 - MENU DE OPCIONES
|
||||||
|
TECLADO
|
||||||
|
## 70 - MENU DE OPCIONES
|
||||||
|
MANDO
|
||||||
|
## 71 - MENU DE OPCIONES
|
||||||
|
LINEAL
|
||||||
|
## 72 - MENU DE OPCIONES
|
||||||
|
NEAREST
|
||||||
|
## 73 - MENU DE OPCIONES
|
||||||
|
ACTIVADA
|
||||||
|
## 74 - MENU DE OPCIONES
|
||||||
|
DESACTIVADA
|
||||||
|
## 75 - JUEGO
|
||||||
|
Adelante!
|
||||||
|
## 76 - JUEGO
|
||||||
|
1.000.000 de puntos!
|
||||||
|
## 77 - PANTALLA DE GAME OVER
|
||||||
|
PUNTUACION J1:
|
||||||
|
## 78 - PANTALLA DE GAME OVER
|
||||||
|
PUNTUACION J2:
|
||||||
|
## 79 - TEXTOS DEL JUEGO
|
||||||
|
Ultima fase!
|
||||||
BIN
media/music/.DS_Store
vendored
@@ -1,10 +0,0 @@
|
|||||||
playing.ogg
|
|
||||||
ARCADE GOBLINS
|
|
||||||
https://soundimage.org/chiptunes-3/
|
|
||||||
|
|
||||||
title.ogg
|
|
||||||
ARCADE STORIES
|
|
||||||
https://soundimage.org/chiptunes-3/
|
|
||||||
|
|
||||||
intro.ogg
|
|
||||||
JailDoctor
|
|
||||||
BIN
media/sound/clock.wav
Normal file
@@ -1,59 +0,0 @@
|
|||||||
bullet.wav
|
|
||||||
Gun11.wav
|
|
||||||
http://www.themotionmonkey.co.uk/free-resources/retro-arcade-sounds/
|
|
||||||
|
|
||||||
balloon.wav
|
|
||||||
Impact3.wav
|
|
||||||
http://www.themotionmonkey.co.uk/free-resources/retro-arcade-sounds/
|
|
||||||
|
|
||||||
player_collision.wav
|
|
||||||
Impact5.wav
|
|
||||||
http://www.themotionmonkey.co.uk/free-resources/retro-arcade-sounds/
|
|
||||||
|
|
||||||
title.wav
|
|
||||||
Explosion2.wav
|
|
||||||
http://www.themotionmonkey.co.uk/free-resources/retro-arcade-sounds/
|
|
||||||
|
|
||||||
menu_select.wav
|
|
||||||
kenney_digitalaudio/powerUp2.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
menu_move.wav
|
|
||||||
kenney_uiaudio/switch11.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
hiscore.wav
|
|
||||||
kenney_digitalaudio/powerUp1.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
itemdrop.wav
|
|
||||||
kenney_digitalaudio/PowerUp10.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
itempickup.wav
|
|
||||||
kenney_digitalaudio/PowerUp7.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
coffeeout.wav
|
|
||||||
kenney_digitalaudio/lowDown.ogg
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
stage_change.wav
|
|
||||||
JailDoctor
|
|
||||||
|
|
||||||
menu_cancel.wav
|
|
||||||
kenney_digitalaudio/lowRandom.ogg
|
|
||||||
kenney_digitalaudio/pepSound1.ogg <-
|
|
||||||
www.kenney.nl
|
|
||||||
|
|
||||||
bubble1.wav
|
|
||||||
JailDoctor
|
|
||||||
|
|
||||||
bubble2.wav
|
|
||||||
JailDoctor
|
|
||||||
|
|
||||||
bubble3.wav
|
|
||||||
JailDoctor
|
|
||||||
|
|
||||||
bubble4.wav
|
|
||||||
JailDoctor
|
|
||||||
BIN
media/sound/powerball.wav
Normal file
BIN
source/.DS_Store
vendored
@@ -1,125 +1,333 @@
|
|||||||
#include "const.h"
|
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite()
|
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file)
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr);
|
// Copia los punteros
|
||||||
|
setTexture(texture);
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
// Carga las animaciones
|
||||||
|
load(file);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
currentAnimation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
AnimatedSprite::~AnimatedSprite()
|
AnimatedSprite::~AnimatedSprite()
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr);
|
for (auto &a : animation)
|
||||||
|
{
|
||||||
|
a.frames.clear();
|
||||||
|
}
|
||||||
|
animation.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
void AnimatedSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
int AnimatedSprite::getIndex(std::string name)
|
||||||
{
|
{
|
||||||
mRenderer = renderer;
|
int index = -1;
|
||||||
mTexture = texture;
|
|
||||||
for (Uint8 i = 0; i < 20; i++)
|
for (auto a : animation)
|
||||||
{
|
{
|
||||||
mAnimation[i].numFrames = 0;
|
index++;
|
||||||
mAnimation[i].speed = 0;
|
if (a.name == name)
|
||||||
mAnimation[i].loop = true;
|
|
||||||
mAnimation[i].completed = false;
|
|
||||||
for (Uint8 j = 0; i < 20; i++)
|
|
||||||
{
|
{
|
||||||
mAnimation[i].frames[j].x = 0;
|
return index;
|
||||||
mAnimation[i].frames[j].y = 0;
|
|
||||||
mAnimation[i].frames[j].w = 0;
|
|
||||||
mAnimation[i].frames[j].h = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCurrentFrame = 0;
|
|
||||||
mAnimationCounter = 0;
|
printf("** Warning: could not find \"%s\" animation\n", name.c_str());
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
// Calcula el frame correspondiente a la animación
|
||||||
void AnimatedSprite::animate(int index)
|
void AnimatedSprite::animate()
|
||||||
{
|
{
|
||||||
// Calculamos el frame actual a partir del contador
|
if (!enabled || animation[currentAnimation].speed == 0)
|
||||||
mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
|
|
||||||
|
|
||||||
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación
|
|
||||||
// en función de la variable loop
|
|
||||||
if (mCurrentFrame >= mAnimation[index].numFrames)
|
|
||||||
{
|
{
|
||||||
if (mAnimation[index].loop)
|
return;
|
||||||
{
|
}
|
||||||
mAnimationCounter = 0;
|
|
||||||
|
// Calcula el frame actual a partir del contador
|
||||||
|
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].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 (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
|
||||||
|
{
|
||||||
|
if (animation[currentAnimation].loop == -1)
|
||||||
|
{ // Si no hay loop, deja el último frame
|
||||||
|
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
||||||
|
animation[currentAnimation].completed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ // Si hay loop, vuelve al frame indicado
|
||||||
mCurrentFrame = mAnimation[index].numFrames;
|
animation[currentAnimation].counter = 0;
|
||||||
|
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// En caso contrario
|
// En caso contrario
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Escogemos el frame correspondiente de la animación
|
// Escoge el frame correspondiente de la animación
|
||||||
setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
|
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||||
|
|
||||||
// Incrementamos el contador de la animacion
|
// Incrementa el contador de la animacion
|
||||||
++mAnimationCounter;
|
animation[currentAnimation].counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el frame actual de la animación
|
// Establece el frame actual de la animación
|
||||||
void AnimatedSprite::setCurrentFrame(Uint8 num)
|
void AnimatedSprite::setCurrentFrame(int num)
|
||||||
{
|
{
|
||||||
mCurrentFrame = num;
|
// Descarta valores fuera de rango
|
||||||
|
if (num >= (int)animation[currentAnimation].frames.size())
|
||||||
|
{
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el valor de la variable
|
||||||
|
animation[currentAnimation].counter = animation[currentAnimation].speed * num;
|
||||||
|
|
||||||
|
// Escoge el frame correspondiente de la animación
|
||||||
|
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void AnimatedSprite::setAnimationCounter(Uint16 num)
|
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||||
{
|
{
|
||||||
mAnimationCounter = num;
|
animation[getIndex(name)].counter = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la velocidad de una animación
|
||||||
|
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||||
|
{
|
||||||
|
animation[getIndex(name)].counter = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la velocidad de una animación
|
||||||
|
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||||
|
{
|
||||||
|
animation[index].counter = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si la animación se reproduce en bucle
|
||||||
|
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||||
|
{
|
||||||
|
animation[getIndex(name)].loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si la animación se reproduce en bucle
|
||||||
|
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||||
|
{
|
||||||
|
animation[index].loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||||
|
{
|
||||||
|
animation[getIndex(name)].completed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD - Establece el valor de la variable
|
||||||
|
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
||||||
|
{
|
||||||
|
animation[index].completed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado la animación
|
||||||
|
bool AnimatedSprite::animationIsCompleted()
|
||||||
|
{
|
||||||
|
return animation[currentAnimation].completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
|
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||||
|
{
|
||||||
|
return animation[getIndex(name)].frames[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la animación desde un fichero
|
||||||
|
bool AnimatedSprite::load(std::string filePath)
|
||||||
|
{
|
||||||
|
int frames_per_row = 0;
|
||||||
|
int frame_width = 0;
|
||||||
|
int frame_height = 0;
|
||||||
|
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
// El fichero se puede abrir
|
||||||
|
if (file.good())
|
||||||
|
{
|
||||||
|
// Procesa el fichero linea a linea
|
||||||
|
printf("Reading file %s\n", filename.c_str());
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
|
if (line == "[animation]")
|
||||||
|
{
|
||||||
|
t_animation buffer;
|
||||||
|
buffer.counter = 0;
|
||||||
|
buffer.currentFrame = 0;
|
||||||
|
buffer.completed = false;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
std::getline(file, line);
|
||||||
|
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (pos != (int)line.npos)
|
||||||
|
{
|
||||||
|
if (line.substr(0, pos) == "name")
|
||||||
|
{
|
||||||
|
buffer.name = line.substr(pos + 1, line.length());
|
||||||
|
}
|
||||||
|
else if (line.substr(0, pos) == "speed")
|
||||||
|
{
|
||||||
|
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
else if (line.substr(0, pos) == "loop")
|
||||||
|
{
|
||||||
|
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
else if (line.substr(0, pos) == "frames")
|
||||||
|
{
|
||||||
|
// Se introducen los valores separados por comas en un vector
|
||||||
|
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
|
std::string tmp;
|
||||||
|
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||||
|
while (getline(ss, tmp, ','))
|
||||||
|
{
|
||||||
|
int num_tile = std::stoi(tmp);
|
||||||
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
|
buffer.frames.push_back(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (line != "[/animation]");
|
||||||
|
|
||||||
|
// Añade la animación al vector de animaciones
|
||||||
|
animation.push_back(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (pos != (int)line.npos)
|
||||||
|
{
|
||||||
|
if (line.substr(0, pos) == "frames_per_row")
|
||||||
|
{
|
||||||
|
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frame_width")
|
||||||
|
{
|
||||||
|
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
|
||||||
|
// Normaliza valores
|
||||||
|
if (frames_per_row == 0)
|
||||||
|
{
|
||||||
|
frames_per_row = texture->getWidth() / frame_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frame_height")
|
||||||
|
{
|
||||||
|
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
printf("Closing file %s\n\n", filename.c_str());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
// El fichero no se puede abrir
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone un valor por defecto
|
||||||
|
setPos({0, 0, frame_width, frame_height});
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la animacion actual
|
||||||
|
void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||||
|
{
|
||||||
|
const int newAnimation = getIndex(name);
|
||||||
|
if (currentAnimation != newAnimation)
|
||||||
|
{
|
||||||
|
currentAnimation = newAnimation;
|
||||||
|
animation[currentAnimation].currentFrame = 0;
|
||||||
|
animation[currentAnimation].counter = 0;
|
||||||
|
animation[currentAnimation].completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la animacion actual
|
||||||
|
void AnimatedSprite::setCurrentAnimation(int index)
|
||||||
|
{
|
||||||
|
const int newAnimation = index;
|
||||||
|
if (currentAnimation != newAnimation)
|
||||||
|
{
|
||||||
|
currentAnimation = newAnimation;
|
||||||
|
animation[currentAnimation].currentFrame = 0;
|
||||||
|
animation[currentAnimation].counter = 0;
|
||||||
|
animation[currentAnimation].completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables del objeto
|
||||||
|
void AnimatedSprite::update()
|
||||||
|
{
|
||||||
|
animate();
|
||||||
|
MovingSprite::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)
|
||||||
{
|
{
|
||||||
mAnimation[index_animation].frames[index_frame].x = x;
|
animation[index_animation].frames.push_back({x, y, w, h});
|
||||||
mAnimation[index_animation].frames[index_frame].y = y;
|
|
||||||
mAnimation[index_animation].frames[index_frame].w = w;
|
|
||||||
mAnimation[index_animation].frames[index_frame].h = h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// OLD - Establece el contador para todas las animaciones
|
||||||
void AnimatedSprite::setAnimationSpeed(Uint8 index, Uint8 speed)
|
void AnimatedSprite::setAnimationCounter(int value)
|
||||||
{
|
{
|
||||||
mAnimation[index].speed = speed;
|
for (auto &a:animation)
|
||||||
}
|
{
|
||||||
|
a.counter = value;
|
||||||
// Establece el numero de frames de una animación
|
}
|
||||||
void AnimatedSprite::setAnimationNumFrames(Uint8 index, Uint8 num)
|
|
||||||
{
|
|
||||||
mAnimation[index].numFrames = num;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si la animación se reproduce en bucle
|
|
||||||
void AnimatedSprite::setAnimationLoop(Uint8 index, bool loop)
|
|
||||||
{
|
|
||||||
mAnimation[index].loop = loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void AnimatedSprite::setCompleted(Uint8 index, bool value)
|
|
||||||
{
|
|
||||||
mAnimation[index].completed = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
|
||||||
bool AnimatedSprite::isCompleted(Uint8 index)
|
|
||||||
{
|
|
||||||
return mAnimation[index].completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
|
||||||
SDL_Rect AnimatedSprite::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
|
|
||||||
{
|
|
||||||
return mAnimation[index_animation].frames[index_frame];
|
|
||||||
}
|
}
|
||||||
@@ -1,69 +1,84 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#ifndef ANIMATEDSPRITE_H
|
#ifndef ANIMATEDSPRITE_H
|
||||||
#define ANIMATEDSPRITE_H
|
#define ANIMATEDSPRITE_H
|
||||||
|
|
||||||
#define MAX_FRAMES 30
|
|
||||||
#define MAX_ANIMATIONS 20
|
|
||||||
|
|
||||||
// Clase AnimatedSprite
|
// Clase AnimatedSprite
|
||||||
class AnimatedSprite : public MovingSprite
|
class AnimatedSprite : public MovingSprite
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct sAnimation
|
struct t_animation
|
||||||
{
|
{
|
||||||
SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación
|
std::string name; // Nombre de la animacion
|
||||||
Uint8 numFrames; // Numero de frames que componen la animación
|
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||||
Uint8 speed; // Velocidad de la animación
|
int speed; // Velocidad de la animación
|
||||||
bool loop; // Indica si la animación se reproduce en bucle
|
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 counter; // Contador para las animaciones
|
||||||
};
|
};
|
||||||
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones
|
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
||||||
|
int currentAnimation; // Animacion activa
|
||||||
Uint8 mCurrentFrame; // Frame actual
|
|
||||||
Uint16 mAnimationCounter; // Contador para las animaciones
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite();
|
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "");
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~AnimatedSprite();
|
~AnimatedSprite();
|
||||||
|
|
||||||
// Iniciador
|
// Calcula el frame correspondiente a la animación actual
|
||||||
void init(LTexture *texture, SDL_Renderer *renderer);
|
void animate();
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
|
||||||
void animate(int index);
|
|
||||||
|
|
||||||
// Establece el frame actual de la animación
|
// Establece el frame actual de la animación
|
||||||
void setCurrentFrame(Uint8 num);
|
void setCurrentFrame(int num);
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void setAnimationCounter(Uint16 num);
|
void setAnimationCounter(std::string name, int num);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void setAnimationSpeed(Uint8 index, Uint8 speed);
|
void setAnimationSpeed(std::string name, int speed);
|
||||||
|
void setAnimationSpeed(int index, int speed);
|
||||||
|
|
||||||
// Establece el numero de frames de una animación
|
// Establece el frame al que vuelve la animación al finalizar
|
||||||
void setAnimationNumFrames(Uint8 index, Uint8 num);
|
void setAnimationLoop(std::string name, int loop);
|
||||||
|
void setAnimationLoop(int index, int loop);
|
||||||
// Establece si la animación se reproduce en bucle
|
|
||||||
void setAnimationLoop(Uint8 index, bool loop);
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setCompleted(Uint8 index, bool value);
|
void setAnimationCompleted(std::string name, bool value);
|
||||||
|
void setAnimationCompleted(int index, bool value);
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool isCompleted(Uint8 index);
|
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(Uint8 index_animation, Uint8 index_frame);
|
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||||
|
|
||||||
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
|
int getIndex(std::string name);
|
||||||
|
|
||||||
|
// Carga la animación desde un fichero
|
||||||
|
bool load(std::string filePath);
|
||||||
|
|
||||||
|
// Establece la animacion actual
|
||||||
|
void setCurrentAnimation(std::string name = "default");
|
||||||
|
void setCurrentAnimation(int index = 0);
|
||||||
|
|
||||||
|
// Actualiza las variables del objeto
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// OLD - Establece el contador para todas las animaciones
|
||||||
|
void setAnimationCounter(int value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
160
source/asset.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
#include "asset.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Asset::Asset(std::string path)
|
||||||
|
{
|
||||||
|
executablePath = path;
|
||||||
|
longest_name = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Asset::~Asset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade un elemento a la lista
|
||||||
|
void Asset::add(std::string file, enum assetType type, bool required)
|
||||||
|
{
|
||||||
|
item_t temp;
|
||||||
|
temp.file = executablePath + file;
|
||||||
|
temp.type = type;
|
||||||
|
temp.required = required;
|
||||||
|
fileList.push_back(temp);
|
||||||
|
|
||||||
|
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||||
|
longest_name = SDL_max(longest_name, 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)
|
||||||
|
{
|
||||||
|
if (f.file.find(text) != std::string::npos)
|
||||||
|
{
|
||||||
|
return f.file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Warning: file %s not found\n", text.c_str());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba que existen todos los elementos
|
||||||
|
bool Asset::check()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
printf("\n** Checking files.\n");
|
||||||
|
|
||||||
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
|
for (int type = 0; type < 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)
|
||||||
|
{
|
||||||
|
printf("\n>> %s FILES\n", getTypeName(type).c_str());
|
||||||
|
|
||||||
|
for (auto f : fileList)
|
||||||
|
{
|
||||||
|
if ((f.required) && (f.type == type))
|
||||||
|
{
|
||||||
|
success &= checkFile(f.file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resultado
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
printf("\n** All files OK.\n\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\n** A file is missing. Exiting.\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
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(), "r+b");
|
||||||
|
|
||||||
|
if (file != nullptr)
|
||||||
|
{
|
||||||
|
result = "OK";
|
||||||
|
success = true;
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
|
||||||
|
printf(s.c_str(), filename.c_str());
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el nombre del tipo de recurso
|
||||||
|
std::string Asset::getTypeName(int type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case bitmap:
|
||||||
|
return "BITMAP";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case music:
|
||||||
|
return "MUSIC";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sound:
|
||||||
|
return "SOUND";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case font:
|
||||||
|
return "FONT";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case lang:
|
||||||
|
return "LANG";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case data:
|
||||||
|
return "DATA";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case room:
|
||||||
|
return "ROOM";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case enemy:
|
||||||
|
return "ENEMY";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case item:
|
||||||
|
return "ITEM";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "ERROR";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
64
source/asset.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef ASSET_H
|
||||||
|
#define ASSET_H
|
||||||
|
|
||||||
|
enum assetType
|
||||||
|
{
|
||||||
|
bitmap,
|
||||||
|
music,
|
||||||
|
sound,
|
||||||
|
font,
|
||||||
|
lang,
|
||||||
|
data,
|
||||||
|
room,
|
||||||
|
enemy,
|
||||||
|
item,
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
int longest_name; // Contiene la longitud del nombre de fichero mas largo
|
||||||
|
|
||||||
|
std::vector<item_t> fileList;
|
||||||
|
std::string executablePath;
|
||||||
|
|
||||||
|
// Comprueba que existe un fichero
|
||||||
|
bool checkFile(std::string path);
|
||||||
|
|
||||||
|
// Devuelve el nombre del tipo de recurso
|
||||||
|
std::string getTypeName(int type);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Asset(std::string path);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Asset();
|
||||||
|
|
||||||
|
// Añade un elemento a la lista
|
||||||
|
void add(std::string file, enum assetType type, bool required = true);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,6 +12,7 @@ Balloon::Balloon()
|
|||||||
Balloon::~Balloon()
|
Balloon::~Balloon()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
@@ -34,8 +35,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_1;
|
mWidth = BALLOON_WIDTH_1;
|
||||||
mHeight = BALLOON_SIZE_1;
|
mHeight = BALLOON_WIDTH_1;
|
||||||
|
mSize = BALLOON_SIZE_1;
|
||||||
|
mPower = 1;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -45,20 +48,26 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = 2.6f;
|
mDefaultVelY = 2.6f;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 50;
|
mScore = BALLOON_SCORE_1;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 1;
|
mMenace = 1;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
|
{
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
|
{
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
|
{
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -66,8 +75,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_2;
|
mWidth = BALLOON_WIDTH_2;
|
||||||
mHeight = BALLOON_SIZE_2;
|
mHeight = BALLOON_WIDTH_2;
|
||||||
|
mSize = BALLOON_SIZE_2;
|
||||||
|
mPower = 3;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -77,19 +88,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = 3.5f;
|
mDefaultVelY = 3.5f;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 100;
|
mScore = BALLOON_SCORE_2;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 2;
|
mMenace = 2;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -98,8 +109,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_3;
|
mWidth = BALLOON_WIDTH_3;
|
||||||
mHeight = BALLOON_SIZE_3;
|
mHeight = BALLOON_WIDTH_3;
|
||||||
|
mSize = BALLOON_SIZE_3;
|
||||||
|
mPower = 7;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -109,19 +122,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = 4.50f;
|
mDefaultVelY = 4.50f;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 200;
|
mScore = BALLOON_SCORE_3;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 4;
|
mMenace = 4;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -130,8 +143,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_4;
|
mWidth = BALLOON_WIDTH_4;
|
||||||
mHeight = BALLOON_SIZE_4;
|
mHeight = BALLOON_WIDTH_4;
|
||||||
|
mSize = BALLOON_SIZE_4;
|
||||||
|
mPower = 15;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -141,19 +156,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = 4.95f;
|
mDefaultVelY = 4.95f;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 400;
|
mScore = BALLOON_SCORE_4;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 8;
|
mMenace = 8;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -162,8 +177,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_1;
|
mWidth = BALLOON_WIDTH_1;
|
||||||
mHeight = BALLOON_SIZE_1;
|
mHeight = BALLOON_WIDTH_1;
|
||||||
|
mSize = BALLOON_SIZE_1;
|
||||||
|
mPower = 1;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -173,19 +190,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = abs(velx) * 2;
|
mDefaultVelY = abs(velx) * 2;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 50;
|
mScore = BALLOON_SCORE_1;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 1;
|
mMenace = 1;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -194,8 +211,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_2;
|
mWidth = BALLOON_WIDTH_2;
|
||||||
mHeight = BALLOON_SIZE_2;
|
mHeight = BALLOON_WIDTH_2;
|
||||||
|
mSize = BALLOON_SIZE_2;
|
||||||
|
mPower = 3;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -205,19 +224,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = abs(velx) * 2;
|
mDefaultVelY = abs(velx) * 2;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 100;
|
mScore = BALLOON_SCORE_2;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 2;
|
mMenace = 2;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -226,8 +245,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_3;
|
mWidth = BALLOON_WIDTH_3;
|
||||||
mHeight = BALLOON_SIZE_3;
|
mHeight = BALLOON_WIDTH_3;
|
||||||
|
mSize = BALLOON_SIZE_3;
|
||||||
|
mPower = 7;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -237,19 +258,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = abs(velx) * 2;
|
mDefaultVelY = abs(velx) * 2;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 200;
|
mScore = BALLOON_SCORE_3;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 4;
|
mMenace = 4;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -258,8 +279,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_4;
|
mWidth = BALLOON_WIDTH_4;
|
||||||
mHeight = BALLOON_SIZE_4;
|
mHeight = BALLOON_WIDTH_4;
|
||||||
|
mSize = BALLOON_SIZE_4;
|
||||||
|
mPower = 15;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -269,19 +292,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mDefaultVelY = abs(velx) * 2;
|
mDefaultVelY = abs(velx) * 2;
|
||||||
|
|
||||||
// Puntos que da el globo al ser destruido
|
// Puntos que da el globo al ser destruido
|
||||||
mScore = 400;
|
mScore = BALLOON_SCORE_4;
|
||||||
|
|
||||||
// Amenaza que genera el globo
|
// Amenaza que genera el globo
|
||||||
mMenace = 8;
|
mMenace = 8;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -290,8 +313,10 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = BALLOON_SIZE_4;
|
mWidth = BALLOON_WIDTH_4;
|
||||||
mHeight = BALLOON_SIZE_4;
|
mHeight = BALLOON_WIDTH_4;
|
||||||
|
mSize = 4;
|
||||||
|
mPower = 0;
|
||||||
|
|
||||||
// Inicializa los valores de velocidad y gravedad
|
// Inicializa los valores de velocidad y gravedad
|
||||||
mVelX = velx;
|
mVelX = velx;
|
||||||
@@ -307,15 +332,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mMenace = 0;
|
mMenace = 0;
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||||
|
|
||||||
|
// Añade rotación al sprite
|
||||||
|
mSprite->setRotate(false);
|
||||||
|
mSprite->setRotateSpeed(1);
|
||||||
|
mSprite->setRotateAmount(2.0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -328,13 +357,16 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
|
|
||||||
mBouncing.enabled = false; // Si el efecto está activo
|
// Valores para el efecto de rebote
|
||||||
mBouncing.counter = 0; // Countador para el efecto
|
mBouncing.enabled = false;
|
||||||
mBouncing.speed = 0; // Velocidad a la que transcurre el efecto
|
mBouncing.counter = 0;
|
||||||
mBouncing.zoomW = 1.0f; // Zoom aplicado a la anchura
|
mBouncing.speed = 0;
|
||||||
mBouncing.zoomH = 1.0f; // Zoom aplicado a la altura
|
mBouncing.zoomW = 1.0f;
|
||||||
mBouncing.despX = 0.0f; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
mBouncing.zoomH = 1.0f;
|
||||||
|
mBouncing.despX = 0.0f;
|
||||||
mBouncing.despY = 0.0f;
|
mBouncing.despY = 0.0f;
|
||||||
|
mBouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
||||||
|
mBouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
||||||
|
|
||||||
// Textura con los gráficos del sprite
|
// Textura con los gráficos del sprite
|
||||||
mSprite->setTexture(texture);
|
mSprite->setTexture(texture);
|
||||||
@@ -381,13 +413,13 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mKind = kind;
|
mKind = kind;
|
||||||
|
|
||||||
// Inicializa las variables para la animación
|
// Inicializa las variables para la animación
|
||||||
mSprite->setCurrentFrame(0);
|
// mSprite->setCurrentFrame(0);
|
||||||
mSprite->setAnimationCounter(0);
|
// mSprite->setAnimationCounter(0);
|
||||||
|
|
||||||
// Establece el numero de frames de cada animacion
|
// Establece el numero de frames de cada animacion
|
||||||
mSprite->setAnimationNumFrames(BALLOON_MOVING_ANIMATION, NUM_FRAMES_BALLON);
|
// mSprite->setAnimationNumFrames(BALLOON_MOVING_ANIMATION, NUM_FRAMES_BALLON);
|
||||||
mSprite->setAnimationNumFrames(BALLOON_POP_ANIMATION, NUM_FRAMES_BALLON_POP);
|
// mSprite->setAnimationNumFrames(BALLOON_POP_ANIMATION, NUM_FRAMES_BALLON_POP);
|
||||||
mSprite->setAnimationNumFrames(BALLOON_BORN_ANIMATION, NUM_FRAMES_BALLON_BORN);
|
// mSprite->setAnimationNumFrames(BALLOON_BORN_ANIMATION, NUM_FRAMES_BALLON_BORN);
|
||||||
|
|
||||||
// Establece la velocidad de cada animación
|
// Establece la velocidad de cada animación
|
||||||
mSprite->setAnimationSpeed(BALLOON_MOVING_ANIMATION, 10);
|
mSprite->setAnimationSpeed(BALLOON_MOVING_ANIMATION, 10);
|
||||||
@@ -409,13 +441,9 @@ void Balloon::allignTo(int x)
|
|||||||
mPosX = float(x - (mWidth / 2));
|
mPosX = float(x - (mWidth / 2));
|
||||||
|
|
||||||
if (mPosX < PLAY_AREA_LEFT)
|
if (mPosX < PLAY_AREA_LEFT)
|
||||||
{
|
|
||||||
mPosX = PLAY_AREA_LEFT + 1;
|
mPosX = PLAY_AREA_LEFT + 1;
|
||||||
}
|
|
||||||
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
||||||
{
|
|
||||||
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
|
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
|
||||||
}
|
|
||||||
|
|
||||||
// Posición X,Y del sprite
|
// Posición X,Y del sprite
|
||||||
mSprite->setPosX(getPosX());
|
mSprite->setPosX(getPosX());
|
||||||
@@ -471,6 +499,9 @@ void Balloon::move()
|
|||||||
// Invierte sentido
|
// Invierte sentido
|
||||||
mVelX = -mVelX;
|
mVelX = -mVelX;
|
||||||
|
|
||||||
|
// Invierte la rotación
|
||||||
|
mSprite->switchRotate();
|
||||||
|
|
||||||
// Activa el efecto de rebote
|
// Activa el efecto de rebote
|
||||||
bounceStart();
|
bounceStart();
|
||||||
}
|
}
|
||||||
@@ -505,10 +536,12 @@ void Balloon::move()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
|
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
|
||||||
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
|
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
|
||||||
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
|
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
|
||||||
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
|
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Incrementa la variable que calcula la distancia acumulada en Y
|
// Incrementa la variable que calcula la distancia acumulada en Y
|
||||||
@@ -524,11 +557,6 @@ void Balloon::move()
|
|||||||
mVelY += mGravity;
|
mVelY += mGravity;
|
||||||
std::min(mVelY, mMaxVelY);
|
std::min(mVelY, mMaxVelY);
|
||||||
}
|
}
|
||||||
// Aplica la gravedad al objeto
|
|
||||||
//if (mVelY > mMaxVelY)
|
|
||||||
// mVelY = mMaxVelY;
|
|
||||||
//else if (mCounter % 1 == 0)
|
|
||||||
// mVelY += mGravity;
|
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSprite->setPosX(getPosX());
|
mSprite->setPosX(getPosX());
|
||||||
@@ -539,33 +567,38 @@ void Balloon::move()
|
|||||||
// Deshabilita el globo y pone a cero todos los valores
|
// Deshabilita el globo y pone a cero todos los valores
|
||||||
void Balloon::disable()
|
void Balloon::disable()
|
||||||
{
|
{
|
||||||
mEnabled = false;
|
|
||||||
|
|
||||||
mPosX = 0.0f;
|
|
||||||
mPosY = 0.0f;
|
|
||||||
mWidth = 0;
|
|
||||||
mHeight = 0;
|
|
||||||
mVelX = 0.0f;
|
|
||||||
mVelY = 0.0f;
|
|
||||||
mGravity = 0.0f;
|
|
||||||
mDefaultVelY = 0.0f;
|
|
||||||
mMaxVelY = 0.0f;
|
|
||||||
mBeingCreated = false;
|
mBeingCreated = false;
|
||||||
mBlinking = false;
|
mBlinking = false;
|
||||||
mInvulnerable = false;
|
mCollider.r = 0;
|
||||||
mPopping = false;
|
|
||||||
mStopped = false;
|
|
||||||
mVisible = false;
|
|
||||||
mCollider.x = 0;
|
mCollider.x = 0;
|
||||||
mCollider.y = 0;
|
mCollider.y = 0;
|
||||||
mCollider.r = 0;
|
mCounter = 0;
|
||||||
mCreationCounter = 0;
|
mCreationCounter = 0;
|
||||||
mCreationCounterIni = 0;
|
mCreationCounterIni = 0;
|
||||||
|
mDefaultVelY = 0.0f;
|
||||||
|
mEnabled = false;
|
||||||
|
mGravity = 0.0f;
|
||||||
|
mHeight = 0;
|
||||||
|
mInvulnerable = false;
|
||||||
|
mKind = 0;
|
||||||
|
mMaxVelY = 0.0f;
|
||||||
|
mMenace = 0;
|
||||||
|
mPopping = false;
|
||||||
|
mPosX = 0.0f;
|
||||||
|
mPosY = 0.0f;
|
||||||
|
mPower = 0;
|
||||||
mScore = 0;
|
mScore = 0;
|
||||||
|
mSize = 0;
|
||||||
|
mSpeed = 0;
|
||||||
|
mStopped = false;
|
||||||
mStoppedCounter = 0;
|
mStoppedCounter = 0;
|
||||||
mTimeToLive = 0;
|
mTimeToLive = 0;
|
||||||
mKind = 0;
|
mTravelY = 0;
|
||||||
mMenace = 0;
|
mVelX = 0.0f;
|
||||||
|
mVelY = 0.0f;
|
||||||
|
mVisible = false;
|
||||||
|
mWidth = 0;
|
||||||
|
mSprite->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explosiona el globo
|
// Explosiona el globo
|
||||||
@@ -573,6 +606,7 @@ void Balloon::pop()
|
|||||||
{
|
{
|
||||||
setPopping(true);
|
setPopping(true);
|
||||||
mSprite->setAnimationCounter(0);
|
mSprite->setAnimationCounter(0);
|
||||||
|
mSprite->disableRotate();
|
||||||
setTimeToLive(120);
|
setTimeToLive(120);
|
||||||
setStop(true);
|
setStop(true);
|
||||||
setStoppedTimer(2000);
|
setStoppedTimer(2000);
|
||||||
@@ -585,6 +619,7 @@ void Balloon::update()
|
|||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
{
|
{
|
||||||
|
mSprite->MovingSprite::update();
|
||||||
move();
|
move();
|
||||||
updateAnimation();
|
updateAnimation();
|
||||||
updateColliders();
|
updateColliders();
|
||||||
@@ -602,9 +637,9 @@ void Balloon::updateState()
|
|||||||
{
|
{
|
||||||
setInvulnerable(true);
|
setInvulnerable(true);
|
||||||
setStop(true);
|
setStop(true);
|
||||||
if (mSprite->isCompleted(BALLOON_POP_ANIMATION))
|
if (mSprite->animationIsCompleted())
|
||||||
{
|
{
|
||||||
mSprite->setCompleted(BALLOON_POP_ANIMATION, false);
|
mSprite->setAnimationCompleted(BALLOON_POP_ANIMATION, false);
|
||||||
mTimeToLive = 0;
|
mTimeToLive = 0;
|
||||||
disable();
|
disable();
|
||||||
}
|
}
|
||||||
@@ -646,12 +681,6 @@ void Balloon::updateState()
|
|||||||
updateColliders();
|
updateColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hace visible el globo de forma intermitente
|
|
||||||
//if (mCreationCounter > 100)
|
|
||||||
// setVisible(mCreationCounter / 10 % 2 == 0);
|
|
||||||
//else
|
|
||||||
// setVisible(mCreationCounter / 5 % 2 == 0);
|
|
||||||
|
|
||||||
mCreationCounter--;
|
mCreationCounter--;
|
||||||
}
|
}
|
||||||
// El contador ha llegado a cero
|
// El contador ha llegado a cero
|
||||||
@@ -661,6 +690,14 @@ void Balloon::updateState()
|
|||||||
setStop(false);
|
setStop(false);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setInvulnerable(false);
|
setInvulnerable(false);
|
||||||
|
if (mKind == POWER_BALL)
|
||||||
|
{
|
||||||
|
mSprite->setRotate(true);
|
||||||
|
if (mVelX > 0.0f)
|
||||||
|
mSprite->setRotateAmount(2.0);
|
||||||
|
else
|
||||||
|
mSprite->setRotateAmount(-2.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Solo comprueba el estado detenido cuando no se está creando
|
// Solo comprueba el estado detenido cuando no se está creando
|
||||||
@@ -668,10 +705,14 @@ void Balloon::updateState()
|
|||||||
{
|
{
|
||||||
// Si está detenido, reduce el contador
|
// Si está detenido, reduce el contador
|
||||||
if (mStoppedCounter > 0)
|
if (mStoppedCounter > 0)
|
||||||
|
{
|
||||||
mStoppedCounter--;
|
mStoppedCounter--;
|
||||||
|
}
|
||||||
// Si el contador ha llegado a cero, ya no está detenido
|
// Si el contador ha llegado a cero, ya no está detenido
|
||||||
else if (!isPopping()) // Quitarles el estado "detenido" si no estan explosionandoxq
|
else if (!isPopping())
|
||||||
|
{ // Quitarles el estado "detenido" si no estan explosionando
|
||||||
setStop(false);
|
setStop(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -680,11 +721,19 @@ void Balloon::updateAnimation()
|
|||||||
{
|
{
|
||||||
// Establece el frame de animación
|
// Establece el frame de animación
|
||||||
if (isPopping())
|
if (isPopping())
|
||||||
mSprite->animate(BALLOON_POP_ANIMATION);
|
{
|
||||||
|
mSprite->setCurrentAnimation(BALLOON_POP_ANIMATION);
|
||||||
|
}
|
||||||
else if (isBeingCreated())
|
else if (isBeingCreated())
|
||||||
mSprite->animate(BALLOON_BORN_ANIMATION);
|
{
|
||||||
|
mSprite->setCurrentAnimation(BALLOON_BORN_ANIMATION);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mSprite->animate(BALLOON_MOVING_ANIMATION);
|
{
|
||||||
|
mSprite->setCurrentAnimation(BALLOON_MOVING_ANIMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
mSprite->animate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el globo está habilitado
|
// Comprueba si el globo está habilitado
|
||||||
@@ -741,6 +790,12 @@ int Balloon::getKind()
|
|||||||
return mKind;
|
return mKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene del valor de la variable
|
||||||
|
Uint8 Balloon::getSize()
|
||||||
|
{
|
||||||
|
return mSize;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene la clase a la que pertenece el globo
|
// Obtiene la clase a la que pertenece el globo
|
||||||
Uint8 Balloon::getClass()
|
Uint8 Balloon::getClass()
|
||||||
{
|
{
|
||||||
@@ -863,7 +918,6 @@ circle_t &Balloon::getCollider()
|
|||||||
// 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 Balloon::updateColliders()
|
void Balloon::updateColliders()
|
||||||
{
|
{
|
||||||
// Align collider to center of balloon
|
|
||||||
mCollider.x = Uint16(mPosX + mCollider.r);
|
mCollider.x = Uint16(mPosX + mCollider.r);
|
||||||
mCollider.y = mPosY + mCollider.r;
|
mCollider.y = mPosY + mCollider.r;
|
||||||
}
|
}
|
||||||
@@ -877,6 +931,12 @@ Uint8 Balloon::getMenace()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene le valor de la variable
|
||||||
|
Uint8 Balloon::getPower()
|
||||||
|
{
|
||||||
|
return mPower;
|
||||||
|
}
|
||||||
|
|
||||||
void Balloon::bounceStart()
|
void Balloon::bounceStart()
|
||||||
{
|
{
|
||||||
mBouncing.enabled = true;
|
mBouncing.enabled = true;
|
||||||
@@ -887,6 +947,7 @@ void Balloon::bounceStart()
|
|||||||
mBouncing.despX = 0;
|
mBouncing.despX = 0;
|
||||||
mBouncing.despY = 0;
|
mBouncing.despY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Balloon::bounceStop()
|
void Balloon::bounceStop()
|
||||||
{
|
{
|
||||||
mBouncing.enabled = false;
|
mBouncing.enabled = false;
|
||||||
@@ -898,6 +959,7 @@ void Balloon::bounceStop()
|
|||||||
mBouncing.despX = 0.0f;
|
mBouncing.despX = 0.0f;
|
||||||
mBouncing.despY = 0.0f;
|
mBouncing.despY = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Balloon::updateBounce()
|
void Balloon::updateBounce()
|
||||||
{
|
{
|
||||||
if (mBouncing.enabled)
|
if (mBouncing.enabled)
|
||||||
|
|||||||
132
source/balloon.h
@@ -1,16 +1,90 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef BALLOON_H
|
#ifndef BALLOON_H
|
||||||
#define BALLOON_H
|
#define BALLOON_H
|
||||||
|
|
||||||
|
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||||
#define MAX_BOUNCE 10
|
#define MAX_BOUNCE 10
|
||||||
|
|
||||||
// Clase globo
|
// Tipos de globo
|
||||||
|
#define BALLOON_1 1
|
||||||
|
#define BALLOON_2 2
|
||||||
|
#define BALLOON_3 3
|
||||||
|
#define BALLOON_4 4
|
||||||
|
#define HEXAGON_1 5
|
||||||
|
#define HEXAGON_2 6
|
||||||
|
#define HEXAGON_3 7
|
||||||
|
#define HEXAGON_4 8
|
||||||
|
#define POWER_BALL 9
|
||||||
|
|
||||||
|
// Puntos de globo
|
||||||
|
#define BALLOON_SCORE_1 50
|
||||||
|
#define BALLOON_SCORE_2 100
|
||||||
|
#define BALLOON_SCORE_3 200
|
||||||
|
#define BALLOON_SCORE_4 400
|
||||||
|
|
||||||
|
// Tamaños de globo
|
||||||
|
#define BALLOON_SIZE_1 1
|
||||||
|
#define BALLOON_SIZE_2 2
|
||||||
|
#define BALLOON_SIZE_3 3
|
||||||
|
#define BALLOON_SIZE_4 4
|
||||||
|
|
||||||
|
// Clases de globo
|
||||||
|
#define BALLOON_CLASS 0
|
||||||
|
#define HEXAGON_CLASS 1
|
||||||
|
|
||||||
|
// Velocidad del globo
|
||||||
|
#define BALLOON_VELX_POSITIVE 0.7f
|
||||||
|
#define BALLOON_VELX_NEGATIVE -0.7f
|
||||||
|
|
||||||
|
// Indice para las animaciones de los globos
|
||||||
|
#define BALLOON_MOVING_ANIMATION 0
|
||||||
|
#define BALLOON_POP_ANIMATION 1
|
||||||
|
#define BALLOON_BORN_ANIMATION 2
|
||||||
|
|
||||||
|
// Cantidad posible de globos
|
||||||
|
#define MAX_BALLOONS 100
|
||||||
|
|
||||||
|
// Velocidades a las que se mueven los globos
|
||||||
|
#define BALLOON_SPEED_1 0.60f
|
||||||
|
#define BALLOON_SPEED_2 0.70f
|
||||||
|
#define BALLOON_SPEED_3 0.80f
|
||||||
|
#define BALLOON_SPEED_4 0.90f
|
||||||
|
#define BALLOON_SPEED_5 1.00f
|
||||||
|
|
||||||
|
// Tamaño de los globos
|
||||||
|
#define BALLOON_WIDTH_1 8
|
||||||
|
#define BALLOON_WIDTH_2 13
|
||||||
|
#define BALLOON_WIDTH_3 21
|
||||||
|
#define BALLOON_WIDTH_4 37
|
||||||
|
|
||||||
|
// PowerBall
|
||||||
|
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
||||||
|
#define POWERBALL_COUNTER 8
|
||||||
|
|
||||||
|
// Clase Balloon
|
||||||
class Balloon
|
class Balloon
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Estructura para las variables para el efecto de los rebotes
|
||||||
|
struct bouncing
|
||||||
|
{
|
||||||
|
bool enabled; // Si el efecto está activo
|
||||||
|
Uint8 counter; // Countador para el efecto
|
||||||
|
Uint8 speed; // Velocidad a la que transcurre el efecto
|
||||||
|
float zoomW; // Zoom aplicado a la anchura
|
||||||
|
float zoomH; // Zoom aplicado a la altura
|
||||||
|
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||||
|
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
||||||
|
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
|
||||||
|
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
|
||||||
|
};
|
||||||
|
|
||||||
float mPosX; // Posición en el eje X
|
float mPosX; // Posición en el eje X
|
||||||
float mPosY; // Posición en el eje Y
|
float mPosY; // Posición en el eje Y
|
||||||
Uint8 mWidth; // Ancho
|
Uint8 mWidth; // Ancho
|
||||||
@@ -39,32 +113,36 @@ private:
|
|||||||
Uint32 mCounter; // Contador interno
|
Uint32 mCounter; // Contador interno
|
||||||
float mTravelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
float mTravelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
|
||||||
float mSpeed; // Velocidad a la que se mueven los globos
|
float mSpeed; // Velocidad a la que se mueven los globos
|
||||||
|
Uint8 mSize; // Tamaño del globo
|
||||||
|
Uint8 mPower; // Cantidad de poder que alberga el globo
|
||||||
|
bouncing mBouncing; // Contiene las variables para el efecto de rebote
|
||||||
|
|
||||||
struct bouncing // Estructura para las variables para el efecto de los rebotes
|
// Alinea el circulo de colisión con la posición del objeto globo
|
||||||
{
|
void updateColliders();
|
||||||
bool enabled; // Si el efecto está activo
|
|
||||||
Uint8 counter; // Countador para el efecto
|
|
||||||
Uint8 speed; // Velocidad a la que transcurre el efecto
|
|
||||||
float zoomW; // Zoom aplicado a la anchura
|
|
||||||
float zoomH; // Zoom aplicado a la altura
|
|
||||||
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
|
||||||
float despY; // idem
|
|
||||||
|
|
||||||
// Vector con los valores de zoom para el ancho y alto del globo
|
// Activa el efecto
|
||||||
float w[MAX_BOUNCE] = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
void bounceStart();
|
||||||
float h[MAX_BOUNCE] = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
|
||||||
};
|
|
||||||
bouncing mBouncing;
|
|
||||||
|
|
||||||
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
|
// Detiene el efecto
|
||||||
void bounceStart(); // Activa el efecto
|
void bounceStop();
|
||||||
void bounceStop(); // Detiene el efecto
|
|
||||||
void updateBounce(); // Aplica el efecto
|
// Aplica el efecto
|
||||||
void updateState(); // Actualiza los estados del globo
|
void updateBounce();
|
||||||
void updateAnimation(); // Establece la animación correspondiente
|
|
||||||
void setBeingCreated(bool state); // Establece el valor de la variable
|
// Actualiza los estados del globo
|
||||||
void setTimeToLive(Uint16 time); // Establece el valor de la variable
|
void updateState();
|
||||||
Uint16 getTimeToLive(); // Obtiene del valor de la variable
|
|
||||||
|
// Establece la animación correspondiente
|
||||||
|
void updateAnimation();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setBeingCreated(bool state);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setTimeToLive(Uint16 time);
|
||||||
|
|
||||||
|
// Obtiene del valor de la variable
|
||||||
|
Uint16 getTimeToLive();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -121,6 +199,9 @@ public:
|
|||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getKind();
|
int getKind();
|
||||||
|
|
||||||
|
// Obtiene del valor de la variable
|
||||||
|
Uint8 getSize();
|
||||||
|
|
||||||
// Obtiene la clase a la que pertenece el globo
|
// Obtiene la clase a la que pertenece el globo
|
||||||
Uint8 getClass();
|
Uint8 getClass();
|
||||||
|
|
||||||
@@ -171,6 +252,9 @@ public:
|
|||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getMenace();
|
Uint8 getMenace();
|
||||||
|
|
||||||
|
// Obtiene le valor de la variable
|
||||||
|
Uint8 getPower();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,18 +5,18 @@
|
|||||||
Bullet::Bullet()
|
Bullet::Bullet()
|
||||||
{
|
{
|
||||||
mSprite = new Sprite();
|
mSprite = new Sprite();
|
||||||
init(0, 0, NO_KIND, nullptr, nullptr);
|
mKind = NO_KIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Bullet::~Bullet()
|
Bullet::~Bullet()
|
||||||
{
|
{
|
||||||
init(0, 0, NO_KIND, nullptr, nullptr);
|
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *renderer)
|
void Bullet::init(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
// Posición inicial del objeto
|
// Posición inicial del objeto
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
@@ -32,6 +32,9 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
|||||||
// Tipo de bala
|
// Tipo de bala
|
||||||
mKind = kind;
|
mKind = kind;
|
||||||
|
|
||||||
|
// Identificador del dueño del objeto
|
||||||
|
mOwner = owner;
|
||||||
|
|
||||||
// Textura con los gráficos del objeto
|
// Textura con los gráficos del objeto
|
||||||
mSprite->setTexture(texture);
|
mSprite->setTexture(texture);
|
||||||
|
|
||||||
@@ -54,7 +57,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
|||||||
mVelX = 0;
|
mVelX = 0;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
if (!poweredUp)
|
||||||
|
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
else
|
||||||
|
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_LEFT:
|
case BULLET_LEFT:
|
||||||
@@ -62,7 +68,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
|||||||
mVelX = -2;
|
mVelX = -2;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
if (!poweredUp)
|
||||||
|
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
else
|
||||||
|
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_RIGHT:
|
case BULLET_RIGHT:
|
||||||
@@ -70,7 +79,10 @@ void Bullet::init(int x, int y, int kind, LTexture *texture, SDL_Renderer *rende
|
|||||||
mVelX = 2;
|
mVelX = 2;
|
||||||
|
|
||||||
// Rectangulo con los gráficos del objeto
|
// Rectangulo con los gráficos del objeto
|
||||||
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
if (!poweredUp)
|
||||||
|
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
else
|
||||||
|
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -94,7 +106,7 @@ void Bullet::render()
|
|||||||
Uint8 Bullet::move()
|
Uint8 Bullet::move()
|
||||||
{
|
{
|
||||||
// Variable con el valor de retorno
|
// Variable con el valor de retorno
|
||||||
Uint8 msg = MSG_OK;
|
Uint8 msg = BULLET_MOVE_OK;
|
||||||
|
|
||||||
// Mueve el objeto a su nueva posición
|
// Mueve el objeto a su nueva posición
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
@@ -106,7 +118,7 @@ Uint8 Bullet::move()
|
|||||||
mKind = NO_KIND;
|
mKind = NO_KIND;
|
||||||
|
|
||||||
// Mensaje de salida
|
// Mensaje de salida
|
||||||
msg = MSG_BULLET_OUT;
|
msg = BULLET_MOVE_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el objeto a su nueva posición en vertical
|
// Mueve el objeto a su nueva posición en vertical
|
||||||
@@ -119,7 +131,7 @@ Uint8 Bullet::move()
|
|||||||
mKind = NO_KIND;
|
mKind = NO_KIND;
|
||||||
|
|
||||||
// Mensaje de salida
|
// Mensaje de salida
|
||||||
msg = MSG_BULLET_OUT;
|
msg = BULLET_MOVE_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
@@ -132,35 +144,19 @@ Uint8 Bullet::move()
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
|
||||||
void Bullet::testMove()
|
|
||||||
{
|
|
||||||
// Update sprite position
|
|
||||||
mSprite->setPosX(mPosX);
|
|
||||||
mSprite->setPosY(mPosY);
|
|
||||||
|
|
||||||
// Update circle colliders
|
|
||||||
shiftColliders();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Deshabilita el objeto
|
// Deshabilita el objeto
|
||||||
void Bullet::erase()
|
void Bullet::erase()
|
||||||
{
|
{
|
||||||
init(0, 0, 0, nullptr, nullptr);
|
init(0, 0, 0, false, -1, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el objeto está activo
|
// Comprueba si el objeto está activo
|
||||||
bool Bullet::isActive()
|
bool Bullet::isActive()
|
||||||
{
|
{
|
||||||
if (mKind == NO_KIND)
|
if (mKind == NO_KIND)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
@@ -199,6 +195,12 @@ int Bullet::getKind()
|
|||||||
return mKind;
|
return mKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Bullet::getOwner()
|
||||||
|
{
|
||||||
|
return mOwner;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &Bullet::getCollider()
|
circle_t &Bullet::getCollider()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
#ifndef BULLET_H
|
#ifndef BULLET_H
|
||||||
#define BULLET_H
|
#define BULLET_H
|
||||||
|
|
||||||
// Clase bala
|
// Tipos de bala
|
||||||
|
#define BULLET_UP 1
|
||||||
|
#define BULLET_LEFT 2
|
||||||
|
#define BULLET_RIGHT 3
|
||||||
|
|
||||||
|
// Tipos de retorno de la funcion move de la bala
|
||||||
|
#define BULLET_MOVE_OK 0
|
||||||
|
#define BULLET_MOVE_OUT 1
|
||||||
|
|
||||||
|
// Clase Bullet
|
||||||
class Bullet
|
class Bullet
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
int mPosX; // Posición en el eje X
|
||||||
|
int mPosY; // Posición en el eje Y
|
||||||
|
Uint8 mWidth; // Ancho del objeto
|
||||||
|
Uint8 mHeight; // Alto del objeto
|
||||||
|
int mVelX; // Velocidad en el eje X
|
||||||
|
int mVelY; // Velocidad en el eje Y
|
||||||
|
int mKind; // Tipo de objeto
|
||||||
|
int mOwner; // Identificador del dueño del objeto
|
||||||
|
Sprite *mSprite; // Sprite con los graficos y métodos de pintado
|
||||||
|
circle_t mCollider; // Circulo de colisión del objeto
|
||||||
|
|
||||||
|
// Alinea el circulo de colisión con el objeto
|
||||||
|
void shiftColliders();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Bullet();
|
Bullet();
|
||||||
@@ -16,7 +42,7 @@ public:
|
|||||||
~Bullet();
|
~Bullet();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init(int x, int y, int kind, LTexture* texture, SDL_Renderer *renderer);
|
void init(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
@@ -48,33 +74,11 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getKind();
|
int getKind();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getOwner();
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
private:
|
|
||||||
// Posición X/Y del objeto
|
|
||||||
int mPosX;
|
|
||||||
int mPosY;
|
|
||||||
|
|
||||||
// Alto y ancho el objeto
|
|
||||||
Uint8 mWidth;
|
|
||||||
Uint8 mHeight;
|
|
||||||
|
|
||||||
// Velocidad del objeto
|
|
||||||
int mVelX;
|
|
||||||
int mVelY;
|
|
||||||
|
|
||||||
// Tipo de objeto
|
|
||||||
int mKind;
|
|
||||||
|
|
||||||
// Sprite con los graficos y métodos de pintado
|
|
||||||
Sprite *mSprite;
|
|
||||||
|
|
||||||
// Balloon's collision circle
|
|
||||||
circle_t mCollider;
|
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
|
||||||
void shiftColliders();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
#ifndef COFFEEDROP_H
|
#ifndef COFFEEDROP_H
|
||||||
|
|||||||
274
source/const.h
@@ -1,81 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
#include <string>
|
#include <SDL2/SDL.h>
|
||||||
|
#include "utils.h"
|
||||||
|
#include "lang.h"
|
||||||
|
|
||||||
#ifndef CONST_H
|
#ifndef CONST_H
|
||||||
#define CONST_H
|
#define CONST_H
|
||||||
|
|
||||||
// Textos
|
|
||||||
#define WINDOW_CAPTION "Coffee Crisis"
|
|
||||||
#define TEXT_COPYRIGHT "@2020,2021 JAILDESIGNER (V1.4)"
|
|
||||||
|
|
||||||
// Recursos
|
|
||||||
#define BINFILE_SCORE 0
|
|
||||||
#define BINFILE_DEMO 1
|
|
||||||
#define BINFILE_CONFIG 2
|
|
||||||
|
|
||||||
#define TOTAL_BINFILE 3
|
|
||||||
|
|
||||||
#define MUSIC_INTRO 0
|
|
||||||
#define MUSIC_PLAYING 1
|
|
||||||
#define MUSIC_TITLE 2
|
|
||||||
|
|
||||||
#define TOTAL_MUSIC 3
|
|
||||||
|
|
||||||
#define SOUND_BALLOON 0
|
|
||||||
#define SOUND_BUBBLE1 1
|
|
||||||
#define SOUND_BUBBLE2 2
|
|
||||||
#define SOUND_BUBBLE3 3
|
|
||||||
#define SOUND_BUBBLE4 4
|
|
||||||
#define SOUND_BULLET 5
|
|
||||||
#define SOUND_COFFEE_OUT 6
|
|
||||||
#define SOUND_HISCORE 7
|
|
||||||
#define SOUND_ITEM_DROP 8
|
|
||||||
#define SOUND_ITEM_PICKUP 9
|
|
||||||
#define SOUND_MENU_CANCEL 10
|
|
||||||
#define SOUND_MENU_MOVE 11
|
|
||||||
#define SOUND_MENU_SELECT 12
|
|
||||||
#define SOUND_PLAYER_COLLISION 13
|
|
||||||
#define SOUND_STAGE_CHANGE 14
|
|
||||||
#define SOUND_TITLE 15
|
|
||||||
|
|
||||||
#define TOTAL_SOUND 16
|
|
||||||
|
|
||||||
#define TEXTURE_BALLOON 0
|
|
||||||
#define TEXTURE_BULLET 1
|
|
||||||
#define TEXTURE_FONT_BLACK 2
|
|
||||||
#define TEXTURE_FONT_BLACK_X2 3
|
|
||||||
#define TEXTURE_FONT_NOKIA 4
|
|
||||||
#define TEXTURE_FONT_WHITE 5
|
|
||||||
#define TEXTURE_FONT_WHITE_X2 6
|
|
||||||
#define TEXTURE_GAME_BG 7
|
|
||||||
#define TEXTURE_GAME_TEXT 8
|
|
||||||
#define TEXTURE_INTRO 9
|
|
||||||
#define TEXTURE_ITEMS 10
|
|
||||||
#define TEXTURE_LOGO 11
|
|
||||||
#define TEXTURE_MENU 12
|
|
||||||
#define TEXTURE_PLAYER_BODY 13
|
|
||||||
#define TEXTURE_PLAYER_DEATH 14
|
|
||||||
#define TEXTURE_PLAYER_LEGS 15
|
|
||||||
#define TEXTURE_TITLE 16
|
|
||||||
|
|
||||||
#define TOTAL_TEXTURE 17
|
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
#define BLOCK 8
|
#define BLOCK 8
|
||||||
#define HALF_BLOCK BLOCK / 2
|
#define HALF_BLOCK BLOCK / 2
|
||||||
|
|
||||||
// Tamaño de la pantalla real
|
// Tamaño de la pantalla de juego
|
||||||
#define SCREEN_WIDTH 256
|
#define SCREEN_WIDTH 256
|
||||||
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4;
|
#define SCREEN_HEIGHT 192
|
||||||
|
|
||||||
// Tamaño de la pantalla que se muestra
|
|
||||||
const int VIEW_WIDTH = SCREEN_WIDTH * 3;
|
|
||||||
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
|
|
||||||
|
|
||||||
// Cantidad de enteros a escribir en los ficheros de datos
|
|
||||||
#define TOTAL_SCORE_DATA 3
|
|
||||||
#define TOTAL_DEMO_DATA 2000
|
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
@@ -99,206 +37,34 @@ const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
|
|||||||
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
|
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
|
||||||
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Opciones de menu
|
|
||||||
#define MENU_NO_OPTION -1
|
|
||||||
#define MENU_OPTION_START 0
|
|
||||||
#define MENU_OPTION_QUIT 1
|
|
||||||
#define MENU_OPTION_TOTAL 2
|
|
||||||
|
|
||||||
// Tipos de fondos para el menu
|
|
||||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
|
||||||
#define MENU_BACKGROUND_SOLID 1
|
|
||||||
|
|
||||||
// Estados del jugador
|
|
||||||
#define PLAYER_STATUS_WALKING_LEFT 0
|
|
||||||
#define PLAYER_STATUS_WALKING_RIGHT 1
|
|
||||||
#define PLAYER_STATUS_WALKING_STOP 2
|
|
||||||
|
|
||||||
#define PLAYER_STATUS_FIRING_UP 0
|
|
||||||
#define PLAYER_STATUS_FIRING_LEFT 1
|
|
||||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
|
||||||
#define PLAYER_STATUS_FIRING_NO 3
|
|
||||||
|
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
|
||||||
|
|
||||||
#define PLAYER_ANIMATION_BODY_WALKING_LEFT 0
|
|
||||||
#define PLAYER_ANIMATION_BODY_FIRING_LEFT 1
|
|
||||||
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT 2
|
|
||||||
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
|
|
||||||
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
|
|
||||||
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
|
|
||||||
|
|
||||||
// Variables del jugador
|
|
||||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
|
||||||
|
|
||||||
// Secciones del programa
|
// Secciones del programa
|
||||||
#define PROG_SECTION_LOGO 0
|
#define PROG_SECTION_LOGO 0
|
||||||
#define PROG_SECTION_INTRO 1
|
#define PROG_SECTION_INTRO 1
|
||||||
#define PROG_SECTION_TITLE 2
|
#define PROG_SECTION_TITLE 2
|
||||||
#define PROG_SECTION_GAME 3
|
#define PROG_SECTION_GAME 3
|
||||||
|
#define PROG_SECTION_QUIT 4
|
||||||
|
|
||||||
// Secciones del juego
|
// Subsecciones
|
||||||
#define GAME_SECTION_PLAY 0
|
#define GAME_SECTION_PLAY_1P 0
|
||||||
#define GAME_SECTION_PAUSE 1
|
#define GAME_SECTION_PLAY_2P 1
|
||||||
#define GAME_SECTION_GAMEOVER 2
|
#define GAME_SECTION_PAUSE 2
|
||||||
|
#define GAME_SECTION_GAMEOVER 3
|
||||||
// Secciones del titulo
|
#define TITLE_SECTION_1 3
|
||||||
#define TITLE_SECTION_1 0
|
#define TITLE_SECTION_2 4
|
||||||
#define TITLE_SECTION_2 1
|
#define TITLE_SECTION_3 5
|
||||||
#define TITLE_SECTION_3 2
|
#define TITLE_SECTION_INSTRUCTIONS 6
|
||||||
#define TITLE_SECTION_INSTRUCTIONS 3
|
|
||||||
|
|
||||||
// Estados de cada elemento que pertenece a un evento
|
// Estados de cada elemento que pertenece a un evento
|
||||||
#define EVENT_WAITING 1
|
#define EVENT_WAITING 1
|
||||||
#define EVENT_RUNNING 2
|
#define EVENT_RUNNING 2
|
||||||
#define EVENT_COMPLETED 3
|
#define EVENT_COMPLETED 3
|
||||||
|
|
||||||
// Cantidad de eventos de la intro
|
|
||||||
#define INTRO_TOTAL_BITMAPS 6
|
|
||||||
#define INTRO_TOTAL_TEXTS 9
|
|
||||||
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
|
|
||||||
|
|
||||||
// Cantidad de eventos de la pantalla de titulo
|
|
||||||
#define TITLE_TOTAL_EVENTS 2
|
|
||||||
|
|
||||||
// Relaciones de Id con nomnbres
|
|
||||||
#define BITMAP0 0
|
|
||||||
#define BITMAP1 1
|
|
||||||
#define BITMAP2 2
|
|
||||||
#define BITMAP3 3
|
|
||||||
#define BITMAP4 4
|
|
||||||
#define BITMAP5 5
|
|
||||||
#define TEXT0 6
|
|
||||||
#define TEXT1 7
|
|
||||||
#define TEXT2 8
|
|
||||||
#define TEXT3 9
|
|
||||||
#define TEXT4 10
|
|
||||||
#define TEXT5 11
|
|
||||||
#define TEXT6 12
|
|
||||||
#define TEXT7 13
|
|
||||||
#define TEXT8 14
|
|
||||||
|
|
||||||
// Anclajes para el marcador de puntos
|
|
||||||
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
|
|
||||||
const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
|
||||||
const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - ((6 * BLOCK) / 2);
|
|
||||||
const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
|
||||||
|
|
||||||
const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
|
|
||||||
const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
|
||||||
const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - ((6 * BLOCK) / 2);
|
|
||||||
const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
|
||||||
|
|
||||||
const int MULTIPLIER_WORD_X = (SCREEN_WIDTH / 2) - ((4 * BLOCK) / 2);
|
|
||||||
const int MULTIPLIER_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
|
||||||
const int MULTIPLIER_NUMBER_X = (SCREEN_WIDTH / 2) - ((3 * BLOCK) / 2);
|
|
||||||
const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
|
||||||
|
|
||||||
// Ningun tipo
|
// Ningun tipo
|
||||||
#define NO_KIND 0
|
#define NO_KIND 0
|
||||||
|
|
||||||
// Tipos de globo
|
// Colores
|
||||||
#define BALLOON_1 1
|
const color_t bgColor = {0x27, 0x27, 0x36};
|
||||||
#define BALLOON_2 2
|
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
||||||
#define BALLOON_3 3
|
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
||||||
#define BALLOON_4 4
|
|
||||||
#define HEXAGON_1 5
|
|
||||||
#define HEXAGON_2 6
|
|
||||||
#define HEXAGON_3 7
|
|
||||||
#define HEXAGON_4 8
|
|
||||||
#define POWER_BALL 9
|
|
||||||
|
|
||||||
// Clases de globo
|
|
||||||
#define BALLOON_CLASS 0
|
|
||||||
#define HEXAGON_CLASS 1
|
|
||||||
|
|
||||||
// Velocidad del globo
|
|
||||||
#define BALLOON_VELX_POSITIVE 0.7f
|
|
||||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
|
||||||
|
|
||||||
// Indice para las animaciones de los globos
|
|
||||||
#define BALLOON_MOVING_ANIMATION 0
|
|
||||||
#define BALLOON_POP_ANIMATION 1
|
|
||||||
#define BALLOON_BORN_ANIMATION 2
|
|
||||||
|
|
||||||
// Cantidad posible de globos
|
|
||||||
#define MAX_BALLOONS 100
|
|
||||||
|
|
||||||
// Velocidades a las que se mueven los enemigos
|
|
||||||
#define BALLOON_SPEED_1 0.60f
|
|
||||||
#define BALLOON_SPEED_2 0.70f
|
|
||||||
#define BALLOON_SPEED_3 0.80f
|
|
||||||
#define BALLOON_SPEED_4 0.90f
|
|
||||||
#define BALLOON_SPEED_5 1.00f
|
|
||||||
|
|
||||||
// Tamaño de los globos
|
|
||||||
#define BALLOON_SIZE_1 8
|
|
||||||
#define BALLOON_SIZE_2 13
|
|
||||||
#define BALLOON_SIZE_3 21
|
|
||||||
#define BALLOON_SIZE_4 37
|
|
||||||
|
|
||||||
// Tipos de bala
|
|
||||||
#define BULLET_UP 1
|
|
||||||
#define BULLET_LEFT 2
|
|
||||||
#define BULLET_RIGHT 3
|
|
||||||
|
|
||||||
// Cantidad posible de globos
|
|
||||||
#define MAX_BULLETS 50
|
|
||||||
|
|
||||||
// Tipos de objetos
|
|
||||||
#define ITEM_POINTS_1_DISK 1
|
|
||||||
#define ITEM_POINTS_2_GAVINA 2
|
|
||||||
#define ITEM_POINTS_3_PACMAR 3
|
|
||||||
#define ITEM_CLOCK 4
|
|
||||||
#define ITEM_TNT 5
|
|
||||||
#define ITEM_COFFEE 6
|
|
||||||
#define ITEM_POWER_BALL 7
|
|
||||||
|
|
||||||
// Cantidad de objetos simultaneos
|
|
||||||
#define MAX_ITEMS 5
|
|
||||||
|
|
||||||
// Valores para las variables asociadas a los objetos
|
|
||||||
#define REMAINING_EXPLOSIONS 3
|
|
||||||
#define REMAINING_EXPLOSIONS_COUNTER 50
|
|
||||||
#define TIME_STOPPED_COUNTER 300
|
|
||||||
|
|
||||||
// Estados de entrada
|
|
||||||
#define NO_INPUT 0
|
|
||||||
#define INPUT_UP 1
|
|
||||||
#define INPUT_DOWN 2
|
|
||||||
#define INPUT_LEFT 3
|
|
||||||
#define INPUT_RIGHT 4
|
|
||||||
#define INPUT_ACCEPT 5
|
|
||||||
#define INPUT_CANCEL 6
|
|
||||||
#define INPUT_FIRE_UP 7
|
|
||||||
#define INPUT_FIRE_LEFT 8
|
|
||||||
#define INPUT_FIRE_RIGHT 9
|
|
||||||
#define INPUT_PAUSE 10
|
|
||||||
|
|
||||||
// Zona muerta del mando analógico
|
|
||||||
#define JOYSTICK_DEAD_ZONE 8000
|
|
||||||
|
|
||||||
// Tipos de mensajes para el retorno de las funciones
|
|
||||||
#define MSG_OK 0
|
|
||||||
#define MSG_BULLET_OUT 1
|
|
||||||
|
|
||||||
// Tipos de texto
|
|
||||||
#define TEXT_FIXED 0
|
|
||||||
#define TEXT_VARIABLE 1
|
|
||||||
|
|
||||||
// Cantidad de elementos del vector de SmartSprites
|
|
||||||
#define MAX_SMART_SPRITES 10
|
|
||||||
|
|
||||||
// Cantidad máxima de gotas de café
|
|
||||||
#define MAX_COFFEE_DROPS 100
|
|
||||||
|
|
||||||
// Contadores
|
|
||||||
#define TITLE_COUNTER 800
|
|
||||||
#define STAGE_COUNTER 200
|
|
||||||
#define INSTRUCTIONS_COUNTER 600
|
|
||||||
#define DEATH_COUNTER 350
|
|
||||||
#define SHAKE_COUNTER 10
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
535
source/director.cpp
Normal file
@@ -0,0 +1,535 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "director.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Director::Director(std::string path)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
|
mAsset = new Asset(path.substr(0, path.find_last_of("\\/")) + "../");
|
||||||
|
|
||||||
|
// Establece la lista de ficheros
|
||||||
|
Uint8 section = PROG_SECTION_LOGO;
|
||||||
|
if (!setFileList())
|
||||||
|
{// Si falta algún fichero no inicies el programa
|
||||||
|
section = PROG_SECTION_QUIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea el objeto de idioma
|
||||||
|
mLang = new Lang(mAsset);
|
||||||
|
|
||||||
|
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||||
|
mOptions = new options_t;
|
||||||
|
loadConfigFile();
|
||||||
|
|
||||||
|
// Crea los objetos
|
||||||
|
mInput = new Input(mAsset->get("controllerdb.txt"));
|
||||||
|
|
||||||
|
// Inicializa SDL
|
||||||
|
initSDL();
|
||||||
|
|
||||||
|
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
||||||
|
mScreen = new Screen(mWindow, mRenderer, mOptions);
|
||||||
|
|
||||||
|
// Inicializa JailAudio
|
||||||
|
initJailAudio();
|
||||||
|
|
||||||
|
// Aplica las opciones
|
||||||
|
mLang->setLang(mOptions->language);
|
||||||
|
|
||||||
|
// Inicializa el resto de variables
|
||||||
|
init(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
Director::~Director()
|
||||||
|
{
|
||||||
|
saveConfigFile();
|
||||||
|
|
||||||
|
delete mAsset;
|
||||||
|
mAsset = nullptr;
|
||||||
|
|
||||||
|
delete mInput;
|
||||||
|
mInput = nullptr;
|
||||||
|
|
||||||
|
delete mScreen;
|
||||||
|
mScreen = nullptr;
|
||||||
|
|
||||||
|
delete mLang;
|
||||||
|
mLang = nullptr;
|
||||||
|
|
||||||
|
delete mOptions;
|
||||||
|
mOptions = nullptr;
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(mRenderer);
|
||||||
|
SDL_DestroyWindow(mWindow);
|
||||||
|
mRenderer = nullptr;
|
||||||
|
mWindow = nullptr;
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicia las variables necesarias para arrancar el programa
|
||||||
|
void Director::init(Uint8 name)
|
||||||
|
{
|
||||||
|
// Sección
|
||||||
|
mSection.name = name;
|
||||||
|
mSection.subsection = 0;
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
mLang->setLang(mOptions->language);
|
||||||
|
|
||||||
|
// Controles
|
||||||
|
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||||
|
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||||
|
mInput->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||||
|
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||||
|
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||||
|
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||||
|
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||||
|
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||||
|
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||||
|
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||||
|
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||||
|
|
||||||
|
mInput->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||||
|
mInput->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||||
|
mInput->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||||
|
mInput->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||||
|
mInput->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
||||||
|
mInput->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
||||||
|
mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||||
|
mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||||
|
mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||||
|
mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||||
|
mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa JailAudio
|
||||||
|
void Director::initJailAudio()
|
||||||
|
{
|
||||||
|
JA_Init(48000, AUDIO_S16, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arranca SDL y crea la ventana
|
||||||
|
bool Director::initSDL()
|
||||||
|
{
|
||||||
|
// Indicador de éxito
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Inicializa SDL
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||||
|
{
|
||||||
|
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Inicia el generador de numeros aleatorios
|
||||||
|
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||||
|
|
||||||
|
// Establece el filtro de la textura
|
||||||
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str()))
|
||||||
|
{
|
||||||
|
printf("Warning: Nearest texture filtering not enabled!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea la ventana
|
||||||
|
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
|
if (mWindow == nullptr)
|
||||||
|
{
|
||||||
|
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||||
|
if (mOptions->vSync)
|
||||||
|
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
|
else
|
||||||
|
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
|
if (mRenderer == nullptr)
|
||||||
|
{
|
||||||
|
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Inicializa el color de renderizado
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
|
// Establece el tamaño del buffer de renderizado
|
||||||
|
SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight);
|
||||||
|
|
||||||
|
// Establece el modo de mezcla
|
||||||
|
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea el indice de ficheros
|
||||||
|
bool Director::setFileList()
|
||||||
|
{
|
||||||
|
// Ficheros binarios
|
||||||
|
mAsset->add("data/score.bin", data, false);
|
||||||
|
mAsset->add("data/demo.bin", data);
|
||||||
|
mAsset->add("data/config.bin", data, false);
|
||||||
|
|
||||||
|
// Musicas
|
||||||
|
mAsset->add("media/music/intro.ogg", music);
|
||||||
|
mAsset->add("media/music/playing.ogg", music);
|
||||||
|
mAsset->add("media/music/title.ogg", music);
|
||||||
|
|
||||||
|
// Sonidos
|
||||||
|
mAsset->add("media/sound/balloon.wav", sound);
|
||||||
|
mAsset->add("media/sound/bubble1.wav", sound);
|
||||||
|
mAsset->add("media/sound/bubble2.wav", sound);
|
||||||
|
mAsset->add("media/sound/bubble3.wav", sound);
|
||||||
|
mAsset->add("media/sound/bubble4.wav", sound);
|
||||||
|
mAsset->add("media/sound/bullet.wav", sound);
|
||||||
|
mAsset->add("media/sound/coffeeout.wav", sound);
|
||||||
|
mAsset->add("media/sound/hiscore.wav", sound);
|
||||||
|
mAsset->add("media/sound/itemdrop.wav", sound);
|
||||||
|
mAsset->add("media/sound/itempickup.wav", sound);
|
||||||
|
mAsset->add("media/sound/menu_cancel.wav", sound);
|
||||||
|
mAsset->add("media/sound/menu_move.wav", sound);
|
||||||
|
mAsset->add("media/sound/menu_select.wav", sound);
|
||||||
|
mAsset->add("media/sound/player_collision.wav", sound);
|
||||||
|
mAsset->add("media/sound/stage_change.wav", sound);
|
||||||
|
mAsset->add("media/sound/title.wav", sound);
|
||||||
|
mAsset->add("media/sound/clock.wav", sound);
|
||||||
|
mAsset->add("media/sound/powerball.wav", sound);
|
||||||
|
|
||||||
|
// Texturas
|
||||||
|
mAsset->add("media/gfx/balloon.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/bullet.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/game_bg.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/game_text.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/intro.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/items.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/logo.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player1_body.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player1_death.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player1_legs.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/title.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player1_head.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player2_body.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player2_death.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player2_legs.png", bitmap);
|
||||||
|
mAsset->add("media/gfx/player2_head.png", bitmap);
|
||||||
|
|
||||||
|
// Fuentes
|
||||||
|
mAsset->add("media/font/8bithud.png", font);
|
||||||
|
mAsset->add("media/font/8bithud.txt", font);
|
||||||
|
mAsset->add("media/font/nokia.png", font);
|
||||||
|
mAsset->add("media/font/nokia_big2.png", font);
|
||||||
|
mAsset->add("media/font/nokia.txt", font);
|
||||||
|
mAsset->add("media/font/nokia2.png", font);
|
||||||
|
mAsset->add("media/font/nokia2.txt", font);
|
||||||
|
mAsset->add("media/font/nokia_big2.txt", font);
|
||||||
|
mAsset->add("media/font/smb2_big.png", font);
|
||||||
|
mAsset->add("media/font/smb2_big.txt", font);
|
||||||
|
mAsset->add("media/font/smb2.png", font);
|
||||||
|
mAsset->add("media/font/smb2.txt", font);
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
mAsset->add("media/lang/es_ES.txt", lang);
|
||||||
|
mAsset->add("media/lang/en_UK.txt", lang);
|
||||||
|
mAsset->add("media/lang/ba_BA.txt", lang);
|
||||||
|
|
||||||
|
// DATA
|
||||||
|
mAsset->add("data/gamecontrollerdb.txt", data);
|
||||||
|
|
||||||
|
return mAsset->check();
|
||||||
|
|
||||||
|
// Inicializa el vector
|
||||||
|
/*for (int i = 0; i < MAX_FILE_LIST; i++)
|
||||||
|
mFileList[i] = "";
|
||||||
|
|
||||||
|
// Ficheros binarios
|
||||||
|
mFileList[0] = mExecutablePath + "/" + "../data/score.bin";
|
||||||
|
mFileList[1] = mExecutablePath + "/" + "../data/demo.bin";
|
||||||
|
mFileList[2] = mExecutablePath + "/" + "../data/config.bin";
|
||||||
|
|
||||||
|
// Musicas
|
||||||
|
mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg";
|
||||||
|
mFileList[4] = mExecutablePath + "/" + "../media/music/playing.ogg";
|
||||||
|
mFileList[5] = mExecutablePath + "/" + "../media/music/title.ogg";
|
||||||
|
|
||||||
|
// Sonidos
|
||||||
|
mFileList[6] = mExecutablePath + "/" + "../media/sound/balloon.wav";
|
||||||
|
mFileList[7] = mExecutablePath + "/" + "../media/sound/bubble1.wav";
|
||||||
|
mFileList[8] = mExecutablePath + "/" + "../media/sound/bubble2.wav";
|
||||||
|
mFileList[9] = mExecutablePath + "/" + "../media/sound/bubble3.wav";
|
||||||
|
mFileList[10] = mExecutablePath + "/" + "../media/sound/bubble4.wav";
|
||||||
|
mFileList[11] = mExecutablePath + "/" + "../media/sound/bullet.wav";
|
||||||
|
mFileList[12] = mExecutablePath + "/" + "../media/sound/coffeeout.wav";
|
||||||
|
mFileList[13] = mExecutablePath + "/" + "../media/sound/hiscore.wav";
|
||||||
|
mFileList[14] = mExecutablePath + "/" + "../media/sound/itemdrop.wav";
|
||||||
|
mFileList[15] = mExecutablePath + "/" + "../media/sound/itempickup.wav";
|
||||||
|
mFileList[16] = mExecutablePath + "/" + "../media/sound/menu_cancel.wav";
|
||||||
|
mFileList[17] = mExecutablePath + "/" + "../media/sound/menu_move.wav";
|
||||||
|
mFileList[18] = mExecutablePath + "/" + "../media/sound/menu_select.wav";
|
||||||
|
mFileList[19] = mExecutablePath + "/" + "../media/sound/player_collision.wav";
|
||||||
|
mFileList[20] = mExecutablePath + "/" + "../media/sound/stage_change.wav";
|
||||||
|
mFileList[21] = mExecutablePath + "/" + "../media/sound/title.wav";
|
||||||
|
mFileList[22] = mExecutablePath + "/" + "../media/sound/clock.wav";
|
||||||
|
mFileList[23] = mExecutablePath + "/" + "../media/sound/powerball.wav";
|
||||||
|
|
||||||
|
// Texturas
|
||||||
|
mFileList[24] = mExecutablePath + "/" + "../media/gfx/balloon.png";
|
||||||
|
mFileList[25] = mExecutablePath + "/" + "../media/gfx/bullet.png";
|
||||||
|
mFileList[31] = mExecutablePath + "/" + "../media/gfx/game_bg.png";
|
||||||
|
mFileList[32] = mExecutablePath + "/" + "../media/gfx/game_text.png";
|
||||||
|
mFileList[33] = mExecutablePath + "/" + "../media/gfx/intro.png";
|
||||||
|
mFileList[34] = mExecutablePath + "/" + "../media/gfx/items.png";
|
||||||
|
mFileList[35] = mExecutablePath + "/" + "../media/gfx/logo.png";
|
||||||
|
mFileList[37] = mExecutablePath + "/" + "../media/gfx/player1_body.png";
|
||||||
|
mFileList[38] = mExecutablePath + "/" + "../media/gfx/player1_death.png";
|
||||||
|
mFileList[39] = mExecutablePath + "/" + "../media/gfx/player1_legs.png";
|
||||||
|
mFileList[40] = mExecutablePath + "/" + "../media/gfx/title.png";
|
||||||
|
mFileList[41] = mExecutablePath + "/" + "../media/gfx/player1_head.png";
|
||||||
|
mFileList[42] = mExecutablePath + "/" + "../media/gfx/player2_body.png";
|
||||||
|
mFileList[43] = mExecutablePath + "/" + "../media/gfx/player2_death.png";
|
||||||
|
mFileList[44] = mExecutablePath + "/" + "../media/gfx/player2_legs.png";
|
||||||
|
mFileList[45] = mExecutablePath + "/" + "../media/gfx/player2_head.png";
|
||||||
|
|
||||||
|
// Fuentes
|
||||||
|
mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png";
|
||||||
|
mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt";
|
||||||
|
mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png";
|
||||||
|
mFileList[54] = mExecutablePath + "/" + "../media/font/nokia_big2.png";
|
||||||
|
mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt";
|
||||||
|
mFileList[56] = mExecutablePath + "/" + "../media/font/nokia2.png";
|
||||||
|
mFileList[57] = mExecutablePath + "/" + "../media/font/nokia2.txt";
|
||||||
|
mFileList[55] = mExecutablePath + "/" + "../media/font/nokia_big2.txt";
|
||||||
|
mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png";
|
||||||
|
mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt";
|
||||||
|
mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png";
|
||||||
|
mFileList[48] = mExecutablePath + "/" + "../media/font/smb2.txt";
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
mFileList[49] = mExecutablePath + "/" + "../media/lang/es_ES.txt";
|
||||||
|
mFileList[50] = mExecutablePath + "/" + "../media/lang/en_UK.txt";
|
||||||
|
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
||||||
|
|
||||||
|
// DATA
|
||||||
|
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el fichero de configuración
|
||||||
|
bool Director::loadConfigFile()
|
||||||
|
{
|
||||||
|
// Pone unos valores por defecto
|
||||||
|
mOptions->fullScreenMode = 0;
|
||||||
|
mOptions->windowSize = 3;
|
||||||
|
mOptions->language = ba_BA;
|
||||||
|
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||||
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
|
mOptions->filter = FILTER_NEAREST;
|
||||||
|
mOptions->vSync = true;
|
||||||
|
mOptions->screenWidth = SCREEN_WIDTH;
|
||||||
|
mOptions->screenHeight = SCREEN_HEIGHT;
|
||||||
|
mOptions->integerScale = true;
|
||||||
|
mOptions->keepAspect = true;
|
||||||
|
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
const std::string p = mAsset->get("config.bin");
|
||||||
|
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
|
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||||
|
|
||||||
|
// El fichero no existe
|
||||||
|
if (file == nullptr)
|
||||||
|
{
|
||||||
|
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||||
|
|
||||||
|
// Crea el fichero para escritura
|
||||||
|
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||||
|
if (file != nullptr)
|
||||||
|
{
|
||||||
|
printf("New file (%s) created!\n", filename.c_str());
|
||||||
|
|
||||||
|
// Escribe los datos
|
||||||
|
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Error: Unable to create file %s\n", filename.c_str());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// El fichero existe
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Carga los datos
|
||||||
|
printf("Reading file %s\n", filename.c_str());
|
||||||
|
SDL_RWread(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||||
|
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
|
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
|
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
|
SDL_RWread(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||||
|
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
|
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
|
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
SDL_RWread(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||||
|
|
||||||
|
// Normaliza los valores
|
||||||
|
if (!((mOptions->fullScreenMode == 0) ||
|
||||||
|
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN) ||
|
||||||
|
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)))
|
||||||
|
mOptions->fullScreenMode = 0;
|
||||||
|
if ((mOptions->windowSize < 1) || (mOptions->windowSize > 4))
|
||||||
|
mOptions->windowSize = 3;
|
||||||
|
if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES))
|
||||||
|
mOptions->language = en_UK;
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guarda el fichero de configuración
|
||||||
|
bool Director::saveConfigFile()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
const std::string p = mAsset->get("config.bin");
|
||||||
|
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
|
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||||
|
if (file != nullptr)
|
||||||
|
{
|
||||||
|
// Guarda los datos
|
||||||
|
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||||
|
|
||||||
|
printf("Writing file %s\n", filename.c_str());
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Error: Unable to save %s file! %s\n", filename.c_str(), SDL_GetError());
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 Director::getSubsection()
|
||||||
|
{
|
||||||
|
return mSection.subsection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 Director::getSection()
|
||||||
|
{
|
||||||
|
return mSection.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Director::setSection(section_t section)
|
||||||
|
{
|
||||||
|
mSection = section;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director::runLogo()
|
||||||
|
{
|
||||||
|
mLogo = new Logo(mRenderer, mScreen, mAsset);
|
||||||
|
setSection(mLogo->run());
|
||||||
|
delete mLogo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director::runIntro()
|
||||||
|
{
|
||||||
|
mIntro = new Intro(mRenderer, mScreen, mAsset, mLang);
|
||||||
|
setSection(mIntro->run());
|
||||||
|
delete mIntro;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director::runTitle()
|
||||||
|
{
|
||||||
|
mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mAsset, mOptions, mLang);
|
||||||
|
setSection(mTitle->run(mSection.subsection));
|
||||||
|
delete mTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director::runGame()
|
||||||
|
{
|
||||||
|
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
||||||
|
{
|
||||||
|
mGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
||||||
|
{
|
||||||
|
mGame = new Game(2, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSection(mGame->run());
|
||||||
|
delete mGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director::run()
|
||||||
|
{
|
||||||
|
// Bucle principal
|
||||||
|
while (!(getSection() == PROG_SECTION_QUIT))
|
||||||
|
{
|
||||||
|
switch (getSection())
|
||||||
|
{
|
||||||
|
case PROG_SECTION_LOGO:
|
||||||
|
runLogo();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROG_SECTION_INTRO:
|
||||||
|
runIntro();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROG_SECTION_TITLE:
|
||||||
|
runTitle();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROG_SECTION_GAME:
|
||||||
|
runGame();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
101
source/director.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "balloon.h"
|
||||||
|
#include "bullet.h"
|
||||||
|
#include "coffeedrop.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "fade.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "intro.h"
|
||||||
|
#include "item.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "logo.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "movingsprite.h"
|
||||||
|
#include "player.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "smartsprite.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "title.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "writer.h"
|
||||||
|
|
||||||
|
#ifndef DIRECTOR_H
|
||||||
|
#define DIRECTOR_H
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
#define WINDOW_CAPTION "Coffee Crisis"
|
||||||
|
|
||||||
|
// Clase Director
|
||||||
|
class Director
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Window *mWindow; // La ventana donde dibujamos
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Logo *mLogo; // Objeto para la sección del logo
|
||||||
|
Intro *mIntro; // Objeto para la sección de la intro
|
||||||
|
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||||
|
Game *mGame; // Objeto para la sección del juego
|
||||||
|
Input *mInput; // Objeto Input para gestionar las entradas
|
||||||
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
struct options_t *mOptions; // Variable con todas las opciones del programa
|
||||||
|
std::string mExecutablePath; // Path del ejecutable
|
||||||
|
section_t mSection; // Sección y subsección actual del programa;
|
||||||
|
|
||||||
|
// Inicializa jail_audio
|
||||||
|
void initJailAudio();
|
||||||
|
|
||||||
|
// Arranca SDL y crea la ventana
|
||||||
|
bool initSDL();
|
||||||
|
|
||||||
|
// Crea el indice de ficheros
|
||||||
|
bool setFileList();
|
||||||
|
|
||||||
|
// Carga el fichero de configuración
|
||||||
|
bool loadConfigFile();
|
||||||
|
|
||||||
|
// Guarda el fichero de configuración
|
||||||
|
bool saveConfigFile();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getSubsection();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getSection();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setSection(section_t section);
|
||||||
|
|
||||||
|
// Ejecuta la seccion de juego con el logo
|
||||||
|
void runLogo();
|
||||||
|
|
||||||
|
// Ejecuta la seccion de juego de la introducción
|
||||||
|
void runIntro();
|
||||||
|
|
||||||
|
// Ejecuta la seccion de juego con el titulo y los menus
|
||||||
|
void runTitle();
|
||||||
|
|
||||||
|
// Ejecuta la seccion de juego donde se juega
|
||||||
|
void runGame();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Director(std::string path);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Director();
|
||||||
|
|
||||||
|
// Inicia las variables necesarias para arrancar el programa
|
||||||
|
void init(Uint8 name);
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
160
source/fade.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
#include "fade.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Fade::Fade(SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
mRenderer = renderer;
|
||||||
|
|
||||||
|
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
if (mBackbuffer == nullptr)
|
||||||
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Fade::~Fade()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(mBackbuffer);
|
||||||
|
mBackbuffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void Fade::init(Uint8 r, Uint8 g, Uint8 b)
|
||||||
|
{
|
||||||
|
mFadeType = FADE_CENTER;
|
||||||
|
mEnabled = false;
|
||||||
|
mFinished = false;
|
||||||
|
mCounter = 0;
|
||||||
|
mR = r;
|
||||||
|
mG = g;
|
||||||
|
mB = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta una transición en pantalla
|
||||||
|
void Fade::render()
|
||||||
|
{
|
||||||
|
if (mEnabled && !mFinished)
|
||||||
|
{
|
||||||
|
switch (mFadeType)
|
||||||
|
{
|
||||||
|
case FADE_FULLSCREEN:
|
||||||
|
mRect1 = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
|
|
||||||
|
for (int i = 0; i < 256; i += 4)
|
||||||
|
{
|
||||||
|
// Dibujamos sobre el renderizador
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
|
// Copia el backbuffer con la imagen que había al renderizador
|
||||||
|
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, i);
|
||||||
|
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||||
|
|
||||||
|
// Vuelca el renderizador en pantalla
|
||||||
|
SDL_RenderPresent(mRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja todos los buffers del mismo color
|
||||||
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FADE_CENTER:
|
||||||
|
mRect1 = {0, 0, SCREEN_WIDTH, 0};
|
||||||
|
mRect2 = {0, 0, SCREEN_WIDTH, 0};
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
|
||||||
|
|
||||||
|
for (int i = 0; i < mCounter; i++)
|
||||||
|
{
|
||||||
|
mRect1.h = mRect2.h = i * 4;
|
||||||
|
mRect2.y = SCREEN_HEIGHT - (i * 4);
|
||||||
|
|
||||||
|
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||||
|
SDL_RenderFillRect(mRenderer, &mRect2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mCounter * 4) > SCREEN_HEIGHT)
|
||||||
|
mFinished = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FADE_RANDOM_SQUARE:
|
||||||
|
mRect1 = {0, 0, 32, 32};
|
||||||
|
|
||||||
|
for (Uint16 i = 0; i < 50; i++)
|
||||||
|
{
|
||||||
|
// Crea un color al azar
|
||||||
|
mR = 255 * (rand() % 2);
|
||||||
|
mG = 255 * (rand() % 2);
|
||||||
|
mB = 255 * (rand() % 2);
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
|
||||||
|
|
||||||
|
// Dibujamos sobre el backbuffer
|
||||||
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
|
|
||||||
|
mRect1.x = rand() % (SCREEN_WIDTH - mRect1.w);
|
||||||
|
mRect1.y = rand() % (SCREEN_HEIGHT - mRect1.h);
|
||||||
|
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||||
|
|
||||||
|
// Volvemos a usar el renderizador de forma normal
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
|
// Copiamos el backbuffer al renderizador
|
||||||
|
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||||
|
|
||||||
|
// Volcamos el renderizador en pantalla
|
||||||
|
SDL_RenderPresent(mRenderer);
|
||||||
|
SDL_Delay(100);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mFinished)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables internas
|
||||||
|
void Fade::update()
|
||||||
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
mCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void Fade::activateFade()
|
||||||
|
{
|
||||||
|
mEnabled = true;
|
||||||
|
mFinished = false;
|
||||||
|
mCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si está activo
|
||||||
|
bool Fade::isEnabled()
|
||||||
|
{
|
||||||
|
return mEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado la transicion
|
||||||
|
bool Fade::hasEnded()
|
||||||
|
{
|
||||||
|
return mFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tipo de fade
|
||||||
|
void Fade::setFadeType(Uint8 fadeType)
|
||||||
|
{
|
||||||
|
mFadeType = fadeType;
|
||||||
|
}
|
||||||
57
source/fade.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "ltexture.h"
|
||||||
|
|
||||||
|
#ifndef FADE_H
|
||||||
|
#define FADE_H
|
||||||
|
|
||||||
|
// Tipos de fundido
|
||||||
|
#define FADE_FULLSCREEN 0
|
||||||
|
#define FADE_CENTER 1
|
||||||
|
#define FADE_RANDOM_SQUARE 2
|
||||||
|
|
||||||
|
// Clase Fade
|
||||||
|
class Fade
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
||||||
|
Uint8 mFadeType; // Tipo de fade a realizar
|
||||||
|
Uint16 mCounter; // Contador interno
|
||||||
|
bool mEnabled; // Indica si el fade está activo
|
||||||
|
bool mFinished; // Indica si ha terminado la transición
|
||||||
|
Uint8 mR, mG, mB; // Colores para el fade
|
||||||
|
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición
|
||||||
|
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Fade(SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Fade();
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init(Uint8 r, Uint8 g, Uint8 b);
|
||||||
|
|
||||||
|
// Pinta una transición en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza las variables internas
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void activateFade();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado la transicion
|
||||||
|
bool hasEnded();
|
||||||
|
|
||||||
|
// Comprueba si está activo
|
||||||
|
bool isEnabled();
|
||||||
|
|
||||||
|
// Establece el tipo de fade
|
||||||
|
void setFadeType(Uint8 fadeType);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
3623
source/game.cpp
Normal file
526
source/game.h
Normal file
@@ -0,0 +1,526 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "balloon.h"
|
||||||
|
#include "bullet.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "fade.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "item.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "movingsprite.h"
|
||||||
|
#include "player.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "smartsprite.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "writer.h"
|
||||||
|
|
||||||
|
#ifndef GAME_H
|
||||||
|
#define GAME_H
|
||||||
|
|
||||||
|
// Cantidad de elementos a escribir en los ficheros de datos
|
||||||
|
#define TOTAL_SCORE_DATA 3
|
||||||
|
#define TOTAL_DEMO_DATA 2000
|
||||||
|
|
||||||
|
// Contadores
|
||||||
|
#define STAGE_COUNTER 200
|
||||||
|
#define SHAKE_COUNTER 10
|
||||||
|
#define HELP_COUNTER 1000
|
||||||
|
|
||||||
|
// Formaciones enemigas
|
||||||
|
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
||||||
|
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
||||||
|
|
||||||
|
// Cantidad de elementos del vector de SmartSprites
|
||||||
|
#define MAX_SMART_SPRITES 10
|
||||||
|
|
||||||
|
// Cantidad máxima posible de balas
|
||||||
|
#define MAX_BULLETS 50
|
||||||
|
|
||||||
|
// Porcentaje de aparición de los objetos
|
||||||
|
#define ITEM_POINTS_1_DISK_ODDS 10
|
||||||
|
#define ITEM_POINTS_2_GAVINA_ODDS 6
|
||||||
|
#define ITEM_POINTS_3_PACMAR_ODDS 3
|
||||||
|
#define ITEM_CLOCK_ODDS 5
|
||||||
|
#define ITEM_COFFEE_ODDS 5
|
||||||
|
#define ITEM_POWER_BALL_ODDS 0
|
||||||
|
#define ITEM_COFFEE_MACHINE_ODDS 4
|
||||||
|
|
||||||
|
// Cantidad de objetos simultaneos
|
||||||
|
#define MAX_ITEMS 10
|
||||||
|
|
||||||
|
// Valores para las variables asociadas a los objetos
|
||||||
|
#define TIME_STOPPED_COUNTER 300
|
||||||
|
|
||||||
|
// Clase Game
|
||||||
|
class Game
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct enemyInits_t
|
||||||
|
{
|
||||||
|
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 velX; // Velocidad inicial en el eje X
|
||||||
|
Uint8 kind; // Tipo de enemigo
|
||||||
|
Uint16 creationCounter; // Temporizador para la creación del enemigo
|
||||||
|
};
|
||||||
|
|
||||||
|
struct enemyFormation_t // Contiene la información de una formación enemiga
|
||||||
|
{
|
||||||
|
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
|
||||||
|
enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||||
|
};
|
||||||
|
|
||||||
|
struct enemyPool_t
|
||||||
|
{
|
||||||
|
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
|
||||||
|
};
|
||||||
|
|
||||||
|
struct stage_t // Contiene todas las variables relacionadas con una fase
|
||||||
|
{
|
||||||
|
enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase
|
||||||
|
Uint16 currentPower; // Cantidad actual de poder
|
||||||
|
Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase
|
||||||
|
Uint8 maxMenace; // Umbral máximo de amenaza de la fase
|
||||||
|
Uint8 minMenace; // Umbral mínimo de amenaza de la fase
|
||||||
|
Uint8 number; // Numero de fase
|
||||||
|
};
|
||||||
|
|
||||||
|
struct effect_t
|
||||||
|
{
|
||||||
|
bool flash; // Indica si se ha de pintar la pantalla de blanco
|
||||||
|
bool shake; // Indica si se ha de agitar la pantalla
|
||||||
|
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
|
||||||
|
};
|
||||||
|
|
||||||
|
struct helper_t
|
||||||
|
{
|
||||||
|
bool needCoffee; // Indica si se necesitan cafes
|
||||||
|
bool needCoffeeMachine; // Indica si se necesita PowerUp
|
||||||
|
bool needPowerBall; // Indica si se necesita una PowerBall
|
||||||
|
int counter; // Contador para no dar ayudas consecutivas
|
||||||
|
int itemPoints1Odds; // Probabilidad de aparición del objeto
|
||||||
|
int itemPoints2Odds; // Probabilidad de aparición del objeto
|
||||||
|
int itemPoints3Odds; // Probabilidad de aparición del objeto
|
||||||
|
int itemClockOdds; // Probabilidad de aparición del objeto
|
||||||
|
int itemCoffeeOdds; // Probabilidad de aparición del objeto
|
||||||
|
int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto
|
||||||
|
};
|
||||||
|
|
||||||
|
struct demo_t
|
||||||
|
{
|
||||||
|
bool enabled; // Indica si está activo el modo demo
|
||||||
|
bool recording; // Indica si está activado el modo para grabar la demo
|
||||||
|
Uint16 counter; // Contador para el modo demo
|
||||||
|
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
|
||||||
|
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
|
||||||
|
};
|
||||||
|
|
||||||
|
struct debug_t
|
||||||
|
{
|
||||||
|
bool enabled; // Indica si se va a mostrar la información de debug
|
||||||
|
Uint8 enemySet; // Escoge el set enemigo a generar
|
||||||
|
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
|
||||||
|
float hudW, hudH; // Multiplica el tamaño del hud de debug;
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
|
||||||
|
int mNumPlayers; // Numero de jugadores
|
||||||
|
Player *mPlayer[2]; // Vector con los jugadores jugador
|
||||||
|
Input *mInput; // Manejador de entrada
|
||||||
|
|
||||||
|
Balloon *mBalloon[MAX_BALLOONS]; // Vector con los objetos globo
|
||||||
|
Bullet *mBullet[MAX_BULLETS]; // Vector con los objetos bala
|
||||||
|
Item *mItem[MAX_ITEMS]; // Vector con los objetos item
|
||||||
|
SmartSprite *mSmartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
|
||||||
|
|
||||||
|
LTexture *mTextureBalloon; // Textura para los enemigos
|
||||||
|
LTexture *mTextureBullet; // Textura para las balas
|
||||||
|
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
||||||
|
LTexture *mTextureGameText; // Textura para los sprites con textos
|
||||||
|
LTexture *mTextureItems; // Textura para los items
|
||||||
|
LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1
|
||||||
|
LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1
|
||||||
|
LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1
|
||||||
|
LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador
|
||||||
|
LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2
|
||||||
|
LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2
|
||||||
|
LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2
|
||||||
|
LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador
|
||||||
|
|
||||||
|
Text *mText; // Fuente para los textos del juego
|
||||||
|
Text *mTextBig; // Fuente de texto grande
|
||||||
|
Text *mTextScoreBoard; // Fuente para el marcador del juego
|
||||||
|
Text *mTextNokia2; // Otra fuente de texto para mesajes
|
||||||
|
Text *mTextNokiaBig2; // Y la versión en grande
|
||||||
|
|
||||||
|
Menu *mMenuGameOver; // Menú de la pantalla de game over
|
||||||
|
Menu *mMenuPause; // Menú de la pantalla de pausa
|
||||||
|
|
||||||
|
Fade *mFade; // Objeto para renderizar fades
|
||||||
|
SDL_Event *mEventHandler; // Manejador de eventos
|
||||||
|
|
||||||
|
MovingSprite *mClouds1a; // Sprite para las nubes superiores
|
||||||
|
MovingSprite *mClouds1b; // Sprite para las nubes superiores
|
||||||
|
MovingSprite *mClouds2a; // Sprite para las nubes inferiores
|
||||||
|
MovingSprite *mClouds2b; // Sprite para las nubes inferiores
|
||||||
|
SmartSprite *m1000Bitmap; // Sprite con el texto 1.000
|
||||||
|
SmartSprite *m2500Bitmap; // Sprite con el texto 2.500
|
||||||
|
SmartSprite *m5000Bitmap; // Sprite con el texto 5.000
|
||||||
|
Sprite *mSpriteBackground; // Sprite con los graficos frontales del fondo
|
||||||
|
Sprite *mSpriteGetReady; // Sprite para el texto de GetReady del principio de la partida
|
||||||
|
Sprite *mSpriteGradient; // Sprite con los graficos del degradado de color de fondo
|
||||||
|
Sprite *mSpriteGrass; // Sprite para la hierba
|
||||||
|
Sprite *mSpritePowerMeter; // Sprite para el medidor de poder de la fase
|
||||||
|
Sprite *mSpriteScoreBoard; // Sprite para el fondo del marcador
|
||||||
|
|
||||||
|
JA_Sound mSoundBalloon; // Sonido para la explosión del globo
|
||||||
|
JA_Sound mSoundBullet; // Sonido para los disparos
|
||||||
|
JA_Sound mSoundPlayerCollision; // Sonido para la colisión del jugador con un enemigo
|
||||||
|
JA_Sound mSoundHiScore; // Sonido para cuando se alcanza la máxima puntuación
|
||||||
|
JA_Sound mSoundItemDrop; // Sonido para cuando se genera un item
|
||||||
|
JA_Sound mSoundItemPickup; // Sonido para cuando se recoge un item
|
||||||
|
JA_Sound mSoundCoffeeOut; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
||||||
|
JA_Sound mSoundStageChange; // Sonido para cuando se cambia de fase
|
||||||
|
JA_Sound mSoundBubble1; // Sonido para cuando el jugador muere
|
||||||
|
JA_Sound mSoundBubble2; // Sonido para cuando el jugador muere
|
||||||
|
JA_Sound mSoundBubble3; // Sonido para cuando el jugador muere
|
||||||
|
JA_Sound mSoundBubble4; // Sonido para cuando el jugador muere
|
||||||
|
JA_Sound mSoundClock; // Sonido para cuando se detiene el tiempo con el item reloj
|
||||||
|
JA_Sound mSoundPowerBall; // Sonido para cuando se explota una Power Ball
|
||||||
|
JA_Sound mSoundCollision; // Sonido para cuando la máquina de café toca el suelo
|
||||||
|
|
||||||
|
JA_Music mMusicPlaying; // Musica de fondo
|
||||||
|
|
||||||
|
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
|
||||||
|
Uint32 mHiScore; // Puntuación máxima
|
||||||
|
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||||
|
section_t mSection; // Seccion actual dentro del juego
|
||||||
|
stage_t mStage[10]; // Variable con los datos de cada pantalla
|
||||||
|
Uint8 mCurrentStage; // Indica la fase actual
|
||||||
|
Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage
|
||||||
|
float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
||||||
|
float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
||||||
|
Uint16 mDeathCounter; // Contador para la animación de muerte del jugador
|
||||||
|
Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
|
||||||
|
Uint8 mMenaceCurrent; // Nivel de amenaza actual
|
||||||
|
Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
||||||
|
bool mTimeStopped; // Indica si el tiempo está detenido
|
||||||
|
Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
||||||
|
Uint32 mCounter; // Contador para el juego
|
||||||
|
Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
||||||
|
SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes
|
||||||
|
Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados
|
||||||
|
Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||||
|
int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||||
|
float mEnemySpeed; // Velocidad a la que se mueven los enemigos
|
||||||
|
float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
|
||||||
|
effect_t mEffect; // Variable para gestionar los efectos visuales
|
||||||
|
helper_t mHelper; // Variable para gestionar las ayudas
|
||||||
|
bool mPowerBallEnabled; // Indica si hay una powerball ya activa
|
||||||
|
Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||||
|
bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
|
||||||
|
Uint8 mPostFade; // Qué hacer al acabar el fade
|
||||||
|
float mSin[360]; // Vector con los valores del seno para 360 grados
|
||||||
|
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||||
|
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||||
|
Uint8 mDifficulty; // Dificultad del juego
|
||||||
|
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||||
|
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||||
|
Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones
|
||||||
|
enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||||
|
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||||
|
Uint8 mLastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
||||||
|
|
||||||
|
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
|
||||||
|
debug_t mDebug; // Variable con las opciones de debug
|
||||||
|
|
||||||
|
// Inicializa el vector con los valores del seno
|
||||||
|
void initSin();
|
||||||
|
|
||||||
|
// Inicializa las variables necesarias para la sección 'Game'
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Carga los recursos necesarios para la sección 'Game'
|
||||||
|
bool loadMedia();
|
||||||
|
|
||||||
|
// Carga el fichero de puntos
|
||||||
|
bool loadScoreFile();
|
||||||
|
|
||||||
|
// Carga el fichero de datos para la demo
|
||||||
|
bool loadDemoFile();
|
||||||
|
|
||||||
|
// Guarda el fichero de puntos
|
||||||
|
bool saveScoreFile();
|
||||||
|
|
||||||
|
// Guarda el fichero de datos para la demo
|
||||||
|
bool saveDemoFile();
|
||||||
|
|
||||||
|
// Inicializa las formaciones enemigas
|
||||||
|
void initEnemyFormations();
|
||||||
|
|
||||||
|
// Inicializa los conjuntos de formaciones
|
||||||
|
void initEnemyPools();
|
||||||
|
|
||||||
|
// Inicializa las fases del juego
|
||||||
|
void initGameStages();
|
||||||
|
|
||||||
|
// Crea una formación de enemigos
|
||||||
|
void deployEnemyFormation();
|
||||||
|
|
||||||
|
// Aumenta el poder de la fase
|
||||||
|
void increaseStageCurrentPower(Uint8 power);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setHiScore(Uint32 score);
|
||||||
|
|
||||||
|
// Actualiza el valor de HiScore en caso necesario
|
||||||
|
void updateHiScore();
|
||||||
|
|
||||||
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
|
std::string updateScoreText(Uint32 num);
|
||||||
|
|
||||||
|
// Pinta el marcador en pantalla usando un objeto texto
|
||||||
|
void renderScoreBoard();
|
||||||
|
|
||||||
|
// Actualiza las variables del jugador
|
||||||
|
void updatePlayer();
|
||||||
|
|
||||||
|
// Actualiza las variables de la fase
|
||||||
|
void updateStage();
|
||||||
|
|
||||||
|
// Actualiza el estado de muerte
|
||||||
|
void updateDeath();
|
||||||
|
|
||||||
|
// Renderiza el fade final cuando se acaba la partida
|
||||||
|
void renderDeathFade(int counter);
|
||||||
|
|
||||||
|
// Actualiza los globos
|
||||||
|
void updateBalloons();
|
||||||
|
|
||||||
|
// Pinta en pantalla todos los globos activos
|
||||||
|
void renderBalloons();
|
||||||
|
|
||||||
|
// Devuelve el primer indice no activo del vector de globos
|
||||||
|
Uint8 getBalloonFreeIndex();
|
||||||
|
|
||||||
|
// Crea un globo nuevo en el vector de globos
|
||||||
|
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
|
||||||
|
|
||||||
|
// Crea una PowerBall
|
||||||
|
void createPowerBall();
|
||||||
|
|
||||||
|
// Establece a cero todos los valores del vector de objetos globo
|
||||||
|
void resetBalloons();
|
||||||
|
|
||||||
|
// Establece la velocidad de los globos
|
||||||
|
void setBalloonSpeed(float speed);
|
||||||
|
|
||||||
|
// Incrementa la velocidad de los globos
|
||||||
|
void incBalloonSpeed();
|
||||||
|
|
||||||
|
// Decrementa la velocidad de los globos
|
||||||
|
void decBalloonSpeed();
|
||||||
|
|
||||||
|
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||||
|
void updateBalloonSpeed();
|
||||||
|
|
||||||
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
|
void popBalloon(Uint8 index);
|
||||||
|
|
||||||
|
// Explosiona un globo. Lo destruye
|
||||||
|
void destroyBalloon(Uint8 index);
|
||||||
|
|
||||||
|
// Explosiona todos los globos
|
||||||
|
void popAllBalloons();
|
||||||
|
|
||||||
|
// Destruye todos los globos
|
||||||
|
void destroyAllBalloons();
|
||||||
|
|
||||||
|
// Detiene todos los globos
|
||||||
|
void stopAllBalloons(Uint16 time);
|
||||||
|
|
||||||
|
// Pone en marcha todos los globos
|
||||||
|
void startAllBalloons();
|
||||||
|
|
||||||
|
// Obtiene el numero de globos activos
|
||||||
|
Uint8 countBalloons();
|
||||||
|
|
||||||
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
|
bool checkPlayerBalloonCollision(int index);
|
||||||
|
|
||||||
|
// Comprueba la colisión entre el jugador y los items
|
||||||
|
void checkPlayerItemCollision(int index);
|
||||||
|
|
||||||
|
// Comprueba la colisión entre las balas y los globos
|
||||||
|
void checkBulletBalloonCollision();
|
||||||
|
|
||||||
|
// Mueve las balas activas
|
||||||
|
void moveBullets();
|
||||||
|
|
||||||
|
// Pinta las balas activas
|
||||||
|
void renderBullets();
|
||||||
|
|
||||||
|
// Devuelve el primer indice no activo del vector de balas
|
||||||
|
Uint8 getBulletFreeIndex();
|
||||||
|
|
||||||
|
// Establece a cero todos los valores del vector de objetos bala
|
||||||
|
void resetBullets();
|
||||||
|
|
||||||
|
// Crea un objeto bala
|
||||||
|
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
|
||||||
|
|
||||||
|
// Actualiza los items
|
||||||
|
void updateItems();
|
||||||
|
|
||||||
|
// Pinta los items activos
|
||||||
|
void renderItems();
|
||||||
|
|
||||||
|
// Devuelve el primer indice no activo del vector de items
|
||||||
|
Uint8 getItemFreeIndex();
|
||||||
|
|
||||||
|
// Establece a cero todos los valores del vector de objetos item
|
||||||
|
void resetItems();
|
||||||
|
|
||||||
|
// Devuelve un item en función del azar
|
||||||
|
Uint8 dropItem();
|
||||||
|
|
||||||
|
// Crea un objeto item
|
||||||
|
void createItem(int x, int y, Uint8 kind);
|
||||||
|
|
||||||
|
// Crea un objeto SmartSprite
|
||||||
|
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
||||||
|
|
||||||
|
// Dibuja el efecto de flash
|
||||||
|
void renderFlashEffect();
|
||||||
|
|
||||||
|
// Actualiza el efecto de agitar la pantalla
|
||||||
|
void updateShakeEffect();
|
||||||
|
|
||||||
|
// Crea un SmartSprite para arrojar el item café al recibir un impacto
|
||||||
|
void throwCoffee(int x, int y);
|
||||||
|
|
||||||
|
// Crea un SmartSprite para arrojar al jugador al morir
|
||||||
|
void throwPlayer(int x, int y, int index);
|
||||||
|
|
||||||
|
// Actualiza los SmartSprites
|
||||||
|
void updateSmartSprites();
|
||||||
|
|
||||||
|
// Pinta los SmartSprites activos
|
||||||
|
void renderSmartSprites();
|
||||||
|
|
||||||
|
// Devuelve el primer indice no activo del vector de SmartSprites
|
||||||
|
Uint8 getSmartSpriteFreeIndex();
|
||||||
|
|
||||||
|
// Establece a cero todos los valores del vector de objetos SmafrtSprite
|
||||||
|
void resetSmartSprites();
|
||||||
|
|
||||||
|
// Acciones a realizar cuando el jugador muere
|
||||||
|
void killPlayer(int index);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getSubsection();
|
||||||
|
|
||||||
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
|
void evaluateAndSetMenace();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getMenace();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setTimeStopped(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isTimeStopped();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setTimeStoppedCounter(Uint16 value);
|
||||||
|
|
||||||
|
// Incrementa el valor de la variable
|
||||||
|
void incTimeStoppedCounter(Uint16 value);
|
||||||
|
|
||||||
|
// Actualiza la variable EnemyDeployCounter
|
||||||
|
void updateEnemyDeployCounter();
|
||||||
|
|
||||||
|
// Actualiza y comprueba el valor de la variable
|
||||||
|
void updateTimeStoppedCounter();
|
||||||
|
|
||||||
|
// Gestiona el nivel de amenaza
|
||||||
|
void updateMenace();
|
||||||
|
|
||||||
|
// Actualiza el campo de juego
|
||||||
|
void updatePlayField();
|
||||||
|
|
||||||
|
// Actualiza el fondo
|
||||||
|
void updateBackground();
|
||||||
|
|
||||||
|
// Dibuja el fondo
|
||||||
|
void renderBackground();
|
||||||
|
|
||||||
|
// Dibuja el campo de juego
|
||||||
|
void renderPlayField();
|
||||||
|
|
||||||
|
// Gestiona la entrada durante el juego
|
||||||
|
void checkGameInput();
|
||||||
|
|
||||||
|
// Pinta diferentes mensajes en la pantalla
|
||||||
|
void renderMessages();
|
||||||
|
|
||||||
|
// Habilita el efecto del item de detener el tiempo
|
||||||
|
void enableTimeStopItem();
|
||||||
|
|
||||||
|
// Deshabilita el efecto del item de detener el tiempo
|
||||||
|
void disableTimeStopItem();
|
||||||
|
|
||||||
|
// Agita la pantalla
|
||||||
|
void shakeScreen();
|
||||||
|
|
||||||
|
// Bucle para el menu de pausa del juego
|
||||||
|
void runPausedGame();
|
||||||
|
|
||||||
|
// Bucle para la pantalla de game over
|
||||||
|
void runGameOverScreen();
|
||||||
|
|
||||||
|
// Dibuja la informacion de debug en pantalla
|
||||||
|
void renderDebugInfo();
|
||||||
|
|
||||||
|
// Indica si se puede crear una powerball
|
||||||
|
bool canPowerBallBeCreated();
|
||||||
|
|
||||||
|
// Calcula el poder actual de los globos en pantalla
|
||||||
|
int calculateScreenPower();
|
||||||
|
|
||||||
|
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||||
|
void initPaths();
|
||||||
|
|
||||||
|
// Actualiza el tramo final de juego, una vez completado
|
||||||
|
void updateGameCompleted();
|
||||||
|
|
||||||
|
// Actualiza las variables de ayuda
|
||||||
|
void updateHelper();
|
||||||
|
|
||||||
|
// Comprueba si todos los jugadores han muerto
|
||||||
|
bool allPlayersAreDead();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang, Input *input, bool demo, options_t *options);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Game();
|
||||||
|
|
||||||
|
// Bucle para el juego
|
||||||
|
section_t run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,665 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "ifdefs.h"
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "movingsprite.h"
|
|
||||||
#include "smartsprite.h"
|
|
||||||
#include "player.h"
|
|
||||||
#include "balloon.h"
|
|
||||||
#include "bullet.h"
|
|
||||||
#include "coffeedrop.h"
|
|
||||||
#include "item.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "text2.h"
|
|
||||||
#include "menu.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifndef GAMEDIRECTOR_H
|
|
||||||
#define GAMEDIRECTOR_H
|
|
||||||
|
|
||||||
// GameDirector
|
|
||||||
class GameDirector
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
SDL_Window *mWindow; // La ventana donde dibujamos
|
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
|
||||||
SDL_Event *mEventHandler; // Manejador de eventos
|
|
||||||
|
|
||||||
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
|
||||||
SDL_Texture *mTitleSurface; // Textura para dibujar el fondo de la pantalla de título
|
|
||||||
SDL_Texture *mInstructionsSurface; // Textura donde dibujar las instrucciones
|
|
||||||
|
|
||||||
SDL_Joystick *mGameController; // Manejador para el mando 1
|
|
||||||
SDL_Haptic *mControllerHaptic; // Manejador para el mando con vibración
|
|
||||||
bool mGameControllerFound; // Variable para saber si hay un mando conectado
|
|
||||||
|
|
||||||
#ifndef UNUSED
|
|
||||||
CoffeeDrop *mCoffeeDrop[MAX_COFFEE_DROPS]; // Vector con todas ls gotas de café;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct text_t
|
|
||||||
{
|
|
||||||
Text *white; // Texto blanco de 8x8
|
|
||||||
Text *whiteX2; // Texto blanco de 16x16
|
|
||||||
Text *black; // Texto negro de 8x8
|
|
||||||
Text *blackX2; // Texto negro de 16x16
|
|
||||||
Text *nokia; // Texto de anchura variable y 10px de alto
|
|
||||||
};
|
|
||||||
text_t mText; // Variable con todos los objetos de texto
|
|
||||||
|
|
||||||
struct menu_t
|
|
||||||
{
|
|
||||||
Menu *title; // Menu de la pantalla de título
|
|
||||||
Menu *pause; // Menú de la pantalla de pausa
|
|
||||||
Menu *gameOver; // Menú de la pantalla de game over
|
|
||||||
Menu *options; // Menú de la pantalla de opciones
|
|
||||||
Menu *active; // Menu activo (de momento para la pantalla del titulo)
|
|
||||||
bool keyPressed; // Variable para evitar la repetición de teclas en los menus
|
|
||||||
};
|
|
||||||
menu_t mMenu; // Variable con todos los objetos menus y sus variables
|
|
||||||
|
|
||||||
struct intro_t
|
|
||||||
{
|
|
||||||
SmartSprite *bitmap[INTRO_TOTAL_BITMAPS]; // Vector con los sprites inteligentes para los dibujos de la intro
|
|
||||||
Text2 *text[INTRO_TOTAL_TEXTS]; // Textos de la intro
|
|
||||||
Uint8 events[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
|
|
||||||
};
|
|
||||||
intro_t mIntro; // Contiene todas las variables de la sección 'Intro'
|
|
||||||
|
|
||||||
struct enemyInits_t
|
|
||||||
{
|
|
||||||
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 velX; // Velocidad inicial en el eje X
|
|
||||||
Uint8 kind; // Tipo de enemigo
|
|
||||||
Uint16 creationCounter; // Temporizador para la creación del enemigo
|
|
||||||
};
|
|
||||||
|
|
||||||
struct enemyFormation_t // Contiene la información de una formación enemiga
|
|
||||||
{
|
|
||||||
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
|
|
||||||
enemyInits_t init[50]; // Vector con todas las inicializaciones de los enemigos de la formación
|
|
||||||
};
|
|
||||||
enemyFormation_t mEnemyFormation[100]; // Vector con todas las formaciones enemigas
|
|
||||||
|
|
||||||
struct enemyPool_t
|
|
||||||
{
|
|
||||||
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
|
|
||||||
};
|
|
||||||
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
|
||||||
|
|
||||||
struct stage_t // Contiene todas las variables relacionadas con una fase
|
|
||||||
{
|
|
||||||
enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase
|
|
||||||
Uint16 currentPower; // Cantidad actual de poder
|
|
||||||
Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase
|
|
||||||
Uint8 maxMenace; // Umbral máximo de amenaza de la fase
|
|
||||||
Uint8 minMenace; // Umbral mínimo de amenaza de la fase
|
|
||||||
Uint8 number; // Numero de fase
|
|
||||||
};
|
|
||||||
|
|
||||||
struct effect_t
|
|
||||||
{
|
|
||||||
bool flash; // Indica si se ha de pintar la pantalla de blanco
|
|
||||||
bool shake; // Indica si se ha de agitar la pantalla
|
|
||||||
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
|
|
||||||
};
|
|
||||||
|
|
||||||
struct game_t
|
|
||||||
{
|
|
||||||
Uint32 score; // Puntuación actual
|
|
||||||
Uint32 hiScore; // Puntuación máxima
|
|
||||||
Uint8 section; // Seccion actual dentro del juego
|
|
||||||
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
|
||||||
Uint8 currentStage; // Indica la fase actual
|
|
||||||
stage_t stage[10]; // Variable con los datos de cada pantalla
|
|
||||||
Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage
|
|
||||||
float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
|
||||||
float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
|
||||||
Uint16 deathCounter; // Contador para la animación de muerte del jugador
|
|
||||||
Uint8 deathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
|
|
||||||
Uint8 menaceCurrent; // Nivel de amenaza actual
|
|
||||||
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
|
||||||
bool timeStopped; // Indica si el tiempo está detenido
|
|
||||||
Uint16 timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
|
||||||
Uint8 remainingExplosions; // Cantidad de explosiones restantes
|
|
||||||
Uint16 remainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes
|
|
||||||
bool explosionTime; // Indica si las explosiones estan en marcha
|
|
||||||
Uint32 counter; // Contador para el juego
|
|
||||||
Uint32 scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
|
||||||
Sprite *getReadyBitmap; // Sprite para el texto de GetReady del principio de la partida
|
|
||||||
SmartSprite *_1000Bitmap; // Sprite con el texto 1.000
|
|
||||||
SmartSprite *_2500Bitmap; // Sprite con el texto 2.500
|
|
||||||
SmartSprite *_5000Bitmap; // Sprite con el texto 5.000
|
|
||||||
Sprite *background; // Sprite con los graficos frontales del fondo
|
|
||||||
Sprite *gradient; // Sprite con los graficos del degradado de color de fondo
|
|
||||||
SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 gradientes
|
|
||||||
Uint16 balloonsPopped; // Lleva la cuenta de los globos explotados
|
|
||||||
MovingSprite *clouds1a; // Sprite para las nubes superiores
|
|
||||||
MovingSprite *clouds1b; // Sprite para las nubes superiores
|
|
||||||
MovingSprite *clouds2a; // Sprite para las nubes inferiores
|
|
||||||
MovingSprite *clouds2b; // Sprite para las nubes inferiores
|
|
||||||
Sprite *grass; // Sprite para la hierba
|
|
||||||
Sprite *scoreBoard; // Sprite para el fondo del marcador
|
|
||||||
Sprite *powerMeter; // Sprite para el medidor de poder de la fase
|
|
||||||
Player *player; // El jugador
|
|
||||||
Balloon *balloon[MAX_BALLOONS]; // Vector con los objetos globo
|
|
||||||
Bullet *bullet[MAX_BULLETS]; // Vector con los objetos bala
|
|
||||||
Item *item[MAX_ITEMS]; // Vector con los objetos item
|
|
||||||
SmartSprite *smartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
|
|
||||||
Uint8 lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
|
|
||||||
Uint8 enemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
|
||||||
float enemySpeed; // Velocidad a la que se mueven los enemigos
|
|
||||||
effect_t effect; // Variable para gestionar los efectos visuales
|
|
||||||
};
|
|
||||||
game_t mGame; // Variable con todas las variables usadas durante el juego
|
|
||||||
|
|
||||||
struct title_t
|
|
||||||
{
|
|
||||||
Uint16 counter; // Temporizador para la pantalla de titulo
|
|
||||||
Uint16 backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
|
|
||||||
Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo
|
|
||||||
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
|
|
||||||
Sprite *tile; // Sprite para dibujar el fondo de pantalla del título
|
|
||||||
SDL_Rect backgroundWindow; // Ventana visible para la textura de fondo del titulo
|
|
||||||
Uint8 section; // Indicador para el bucle del titulo
|
|
||||||
Uint8 nextProgSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
|
||||||
Uint8 events[TITLE_TOTAL_EVENTS]; // Vector para coordinar los eventos de la pantalla de titulo
|
|
||||||
Uint16 instructionsCounter; // Contador para las instrucciones
|
|
||||||
SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
|
|
||||||
SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
|
|
||||||
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
|
||||||
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
|
||||||
};
|
|
||||||
title_t mTitle; // Variable con todas las variables de la pantalla de titulo
|
|
||||||
|
|
||||||
struct demo_t
|
|
||||||
{
|
|
||||||
bool enabled; // Indica si está activo el modo demo
|
|
||||||
bool recording; // Indica si está activado el modo para grabar la demo
|
|
||||||
Uint16 counter; // Contador para el modo demo
|
|
||||||
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
|
|
||||||
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
|
|
||||||
};
|
|
||||||
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
|
|
||||||
|
|
||||||
struct options_t
|
|
||||||
{
|
|
||||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
|
||||||
Uint32 fullScreenModePrevious;
|
|
||||||
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
|
||||||
Uint8 windowSizePrevious;
|
|
||||||
bool displayCoffeeDrops; // Indica si se han de mostar las gotas de cafe
|
|
||||||
};
|
|
||||||
options_t mOptions; // Variable con todas las variables de las opciones del programa
|
|
||||||
|
|
||||||
struct logo_t
|
|
||||||
{
|
|
||||||
Uint16 counter; // Contador
|
|
||||||
Sprite *sprite; // Sprite con la textura del logo
|
|
||||||
};
|
|
||||||
logo_t mLogo; // Variable con las variables para el logo
|
|
||||||
|
|
||||||
struct prog_t
|
|
||||||
{
|
|
||||||
bool quit; // Indica si hay que salir del programa
|
|
||||||
input_t keyboard; // Almacena los códigos de teclado correspondientes
|
|
||||||
input_t keyboardBuffer; // Buffer para teclas pulsadas
|
|
||||||
std::string executablePath; // Path del ejecutable
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
|
||||||
Uint8 section; // Sección actual del programa;
|
|
||||||
Uint8 subsection; // Subseccion dentro de la sección;
|
|
||||||
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
};
|
|
||||||
prog_t mProg; // Contiene todas las variables globales del programa
|
|
||||||
|
|
||||||
struct debug_t
|
|
||||||
{
|
|
||||||
bool enabled; // Indica si se va a mostrar la información de debug
|
|
||||||
Uint8 enemySet; // Escoge el set enemigo a generar
|
|
||||||
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
|
|
||||||
float hudW, hudH; // Multiplica el tamaño del hud de debug;
|
|
||||||
};
|
|
||||||
debug_t mDebug;
|
|
||||||
|
|
||||||
struct resourceBinFile_t
|
|
||||||
{
|
|
||||||
std::string file; // Ruta al fichero
|
|
||||||
};
|
|
||||||
resourceBinFile_t mBinFile[TOTAL_BINFILE]; // Todos los ficheros binarios
|
|
||||||
|
|
||||||
struct resourceSound_t
|
|
||||||
{
|
|
||||||
std::string file; // Ruta al fichero
|
|
||||||
JA_Sound sound; // Variable con el sonido
|
|
||||||
};
|
|
||||||
resourceSound_t mSound[TOTAL_SOUND]; // Todos los sonidos
|
|
||||||
|
|
||||||
struct resourceMusic_t
|
|
||||||
{
|
|
||||||
std::string file; // Ruta al fichero
|
|
||||||
JA_Music music; // Variable con la música
|
|
||||||
};
|
|
||||||
resourceMusic_t mMusic[TOTAL_MUSIC]; // Todas las músicas
|
|
||||||
|
|
||||||
struct resourceTexture_t
|
|
||||||
{
|
|
||||||
std::string file; // Ruta al fichero
|
|
||||||
LTexture *texture; // Variable con la textura
|
|
||||||
};
|
|
||||||
resourceTexture_t mTexture[TOTAL_TEXTURE]; // Todos los gráficos
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
GameDirector(std::string path);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~GameDirector();
|
|
||||||
|
|
||||||
// Inicia las variables necesarias para arrancar el programa
|
|
||||||
void initProg();
|
|
||||||
|
|
||||||
// Carga los recursos necesarios para el programa
|
|
||||||
bool loadMediaProg();
|
|
||||||
|
|
||||||
// Libera las variables del programa
|
|
||||||
void quitProg();
|
|
||||||
|
|
||||||
// Inicializa jail_audio
|
|
||||||
void initJailAudio();
|
|
||||||
|
|
||||||
// Arranca SDL y crea la ventana
|
|
||||||
bool initSDL();
|
|
||||||
|
|
||||||
// Inicializa el vector con los valores del seno
|
|
||||||
void initSin();
|
|
||||||
|
|
||||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
|
||||||
void initPaths();
|
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Logo'
|
|
||||||
void initLogo();
|
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Logo'
|
|
||||||
bool loadMediaLogo();
|
|
||||||
|
|
||||||
// Libera las variables necesarias para la sección 'Logo'
|
|
||||||
void quitLogo();
|
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Intro'
|
|
||||||
void initIntro();
|
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Intro'
|
|
||||||
bool loadMediaIntro();
|
|
||||||
|
|
||||||
// Libera las variables necesarias para la sección 'Intro'
|
|
||||||
void quitIntro();
|
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Title'
|
|
||||||
void initTitle(Uint8 subsection = TITLE_SECTION_1);
|
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Title'
|
|
||||||
bool loadMediaTitle();
|
|
||||||
|
|
||||||
// Libera las variables necesarias para la sección 'Title'
|
|
||||||
void quitTitle();
|
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Game'
|
|
||||||
void initGame();
|
|
||||||
|
|
||||||
// Inicializa las variables especificas de la sección 'Game' para empezar una nueva partida
|
|
||||||
void resetGame();
|
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Game'
|
|
||||||
bool loadMediaGame();
|
|
||||||
|
|
||||||
// Libera las variables necesarias para la sección 'Game'
|
|
||||||
void quitGame();
|
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
|
||||||
void setFileList();
|
|
||||||
|
|
||||||
// Comprueba que todos los ficheros existen
|
|
||||||
bool checkFileList();
|
|
||||||
|
|
||||||
// Carga el fichero de puntos
|
|
||||||
bool loadScoreFile();
|
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
|
||||||
bool loadConfigFile();
|
|
||||||
|
|
||||||
// Carga el fichero de datos para la demo
|
|
||||||
bool loadDemoFile();
|
|
||||||
|
|
||||||
// Guarda el fichero de puntos
|
|
||||||
bool saveScoreFile();
|
|
||||||
|
|
||||||
// Guarda el fichero de configuración
|
|
||||||
bool saveConfigFile();
|
|
||||||
|
|
||||||
// Guarda el fichero de datos para la demo
|
|
||||||
bool saveDemoFile();
|
|
||||||
|
|
||||||
// Carga un archivo de imagen en una textura
|
|
||||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
|
|
||||||
|
|
||||||
// Comprueba el valor de la variable 'quit'
|
|
||||||
bool exit();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setExecutablePath(std::string path);
|
|
||||||
|
|
||||||
// Inicializa las formaciones enemigas
|
|
||||||
void initEnemyFormations();
|
|
||||||
|
|
||||||
// Inicializa los conjuntos de formaciones
|
|
||||||
void initEnemyPools();
|
|
||||||
|
|
||||||
// Inicializa las fases del juego
|
|
||||||
void initGameStages();
|
|
||||||
|
|
||||||
// Crea una formación de enemigos
|
|
||||||
void deployEnemyFormation();
|
|
||||||
|
|
||||||
// Aumenta el poder de la fase
|
|
||||||
void increaseStageCurrentPower();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setScore(Uint32 score);
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setHiScore(Uint32 score);
|
|
||||||
|
|
||||||
// Actualiza el valor de HiScore en caso necesario
|
|
||||||
void updateHiScore();
|
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string updateScoreText(Uint32 num);
|
|
||||||
|
|
||||||
// Pinta el marcador en pantalla usando un objeto texto
|
|
||||||
void renderScoreBoard();
|
|
||||||
|
|
||||||
// Actualiza las variables del jugador
|
|
||||||
void updatePlayer();
|
|
||||||
|
|
||||||
// Actualiza las variables de la fase
|
|
||||||
void updateStage();
|
|
||||||
|
|
||||||
// Actualiza el estado de muerte
|
|
||||||
void updateDeath();
|
|
||||||
|
|
||||||
// Renderiza el fade final cuando se acaba la partida
|
|
||||||
void renderDeathFade();
|
|
||||||
|
|
||||||
// Actualiza los globos
|
|
||||||
void updateBalloons();
|
|
||||||
|
|
||||||
// Pinta en pantalla todos los globos activos
|
|
||||||
void renderBalloons();
|
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de globos
|
|
||||||
Uint8 getBalloonFreeIndex();
|
|
||||||
|
|
||||||
// Crea un globo nuevo en el vector de globos
|
|
||||||
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
|
|
||||||
|
|
||||||
// Crea una PowerBall
|
|
||||||
void createPowerBall();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos globo
|
|
||||||
void resetBalloons();
|
|
||||||
|
|
||||||
// Establece la velocidad de los globos
|
|
||||||
void setBalloonSpeed(float speed);
|
|
||||||
|
|
||||||
// Incrementa la velocidad de los globos
|
|
||||||
void incBalloonSpeed();
|
|
||||||
|
|
||||||
// Decrementa la velocidad de los globos
|
|
||||||
void decBalloonSpeed();
|
|
||||||
|
|
||||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
|
||||||
void updateBalloonSpeed();
|
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
|
||||||
void popBalloon(Uint8 index);
|
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye
|
|
||||||
void destroyBalloon(Uint8 index);
|
|
||||||
|
|
||||||
// Explosiona todos los globos
|
|
||||||
void popAllBalloons();
|
|
||||||
|
|
||||||
// Destruye todos los globos
|
|
||||||
void destroyAllBalloons();
|
|
||||||
|
|
||||||
// Detiene todos los globos
|
|
||||||
void stopAllBalloons(Uint16 time);
|
|
||||||
|
|
||||||
// Pone en marcha todos los globos
|
|
||||||
void startAllBalloons();
|
|
||||||
|
|
||||||
// Obtiene el numero de globos activos
|
|
||||||
Uint8 countBalloons();
|
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
|
||||||
bool checkPlayerBalloonCollision();
|
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los items
|
|
||||||
void checkPlayerItemCollision();
|
|
||||||
|
|
||||||
// Comprueba la colisión entre las balas y los globos
|
|
||||||
void checkBulletBalloonCollision();
|
|
||||||
|
|
||||||
// Mueve las balas activas
|
|
||||||
void moveBullets();
|
|
||||||
|
|
||||||
// Pinta las balas activas
|
|
||||||
void renderBullets();
|
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de balas
|
|
||||||
Uint8 getBulletFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos bala
|
|
||||||
void resetBullets();
|
|
||||||
|
|
||||||
// Crea un objeto bala
|
|
||||||
void createBullet(int x, int y, Uint8 kind);
|
|
||||||
|
|
||||||
// Actualiza los items
|
|
||||||
void updateItems();
|
|
||||||
|
|
||||||
// Pinta los items activos
|
|
||||||
void renderItems();
|
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de items
|
|
||||||
Uint8 getItemFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos item
|
|
||||||
void resetItems();
|
|
||||||
|
|
||||||
// Devuelve un item en función del azar
|
|
||||||
Uint8 dropItem();
|
|
||||||
|
|
||||||
// Crea un objeto item
|
|
||||||
void createItem(int x, int y, Uint8 kind);
|
|
||||||
|
|
||||||
// Crea un objeto SmartSprite
|
|
||||||
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
|
||||||
|
|
||||||
// Crea un objeto de bonus en función del azar
|
|
||||||
void dropBonus();
|
|
||||||
|
|
||||||
// Dibuja el efecto de flash
|
|
||||||
void renderFlashEffect();
|
|
||||||
|
|
||||||
// Actualiza el efecto de agitar la pantalla
|
|
||||||
void updateShakeEffect();
|
|
||||||
|
|
||||||
// Crea un SmartSprite para arrojar el item café al recibir un impacto
|
|
||||||
void throwCoffee(int x, int y);
|
|
||||||
|
|
||||||
// Crea un SmartSprite para arrojar al jugador al morir
|
|
||||||
void throwPlayer(int x, int y);
|
|
||||||
|
|
||||||
// Actualiza los SmartSprites
|
|
||||||
void updateSmartSprites();
|
|
||||||
|
|
||||||
// Pinta los SmartSprites activos
|
|
||||||
void renderSmartSprites();
|
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de SmartSprites
|
|
||||||
Uint8 getSmartSpriteFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos SmafrtSprite
|
|
||||||
void resetSmartSprites();
|
|
||||||
|
|
||||||
#ifndef UNUSED
|
|
||||||
// Deshabilita todas las gotas de café
|
|
||||||
void resetCoffeeDrops();
|
|
||||||
|
|
||||||
// Actualiza las gotas de cafe
|
|
||||||
void updateCoffeeDrops();
|
|
||||||
|
|
||||||
// Dibuja las gotas de cafe
|
|
||||||
void renderCoffeeDrops();
|
|
||||||
|
|
||||||
// Devuelve el primer indice libre del vector de CoffeeDrops
|
|
||||||
Uint8 getCoffeDropFreeIndex();
|
|
||||||
|
|
||||||
// Crea un numero de gotas de cafe
|
|
||||||
void createCoffeDrops(Uint8 num, int x, int y);
|
|
||||||
#endif
|
|
||||||
// Acciones a realizar cuando el jugador muere
|
|
||||||
void killPlayer();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getSubsection();
|
|
||||||
|
|
||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
|
||||||
void setMenace();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getMenace();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setTimeStopped(bool value);
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool isTimeStopped();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setTimeStoppedCounter(Uint16 value);
|
|
||||||
|
|
||||||
// Actualiza la variable EnemyDeployCounter
|
|
||||||
void updateEnemyDeployCounter();
|
|
||||||
|
|
||||||
// Actualiza y comprueba el valor de la variable
|
|
||||||
void updateTimeStoppedCounter();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setExplosionTime(bool value);
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool isExplosionTime();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setRemainingExplosions(Uint8 value);
|
|
||||||
|
|
||||||
// Actualiza y comprueba el valor de la variable
|
|
||||||
void updateRemainingExplosionsCounter();
|
|
||||||
|
|
||||||
// Gestiona el nivel de amenaza
|
|
||||||
void old_updateMenace();
|
|
||||||
|
|
||||||
// Gestiona el nivel de amenaza
|
|
||||||
void updateMenace();
|
|
||||||
|
|
||||||
// Actualiza el campo de juego
|
|
||||||
void updatePlayField();
|
|
||||||
|
|
||||||
// Actualiza el fondo
|
|
||||||
void updateBackground();
|
|
||||||
|
|
||||||
// Dibuja el fondo
|
|
||||||
void renderBackground();
|
|
||||||
|
|
||||||
// Dibuja el campo de juego
|
|
||||||
void renderPlayField();
|
|
||||||
|
|
||||||
// Gestiona las entradas desde el mando de juego
|
|
||||||
bool checkGameController(Uint8 state);
|
|
||||||
|
|
||||||
// Gestiona la entrada durante el juego
|
|
||||||
void checkGameInput();
|
|
||||||
|
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
|
||||||
void checkMenuInput(Menu *menu);
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getProgSection();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setProgSection(Uint8 section, Uint8 subsection = 0);
|
|
||||||
|
|
||||||
// Pinta una transición en pantalla
|
|
||||||
void renderFade(Uint8 index);
|
|
||||||
|
|
||||||
// Pinta diferentes mensajes en la pantalla
|
|
||||||
void renderMessages();
|
|
||||||
|
|
||||||
// Habilita el efecto del item de detener el tiempo
|
|
||||||
void enableTimeStopItem();
|
|
||||||
|
|
||||||
// Deshabilita el efecto del item de detener el tiempo
|
|
||||||
void disableTimeStopItem();
|
|
||||||
|
|
||||||
// Cambia el valor de la variable de modo de pantalla completa
|
|
||||||
void changeFullScreenMode();
|
|
||||||
|
|
||||||
// Actualiza los elementos del menu de opciones
|
|
||||||
void updateOptionsMenu();
|
|
||||||
|
|
||||||
// Agita la pantalla
|
|
||||||
void shakeScreen();
|
|
||||||
|
|
||||||
// Agita la pantalla
|
|
||||||
void shakeScreen2();
|
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
|
||||||
void runLogo();
|
|
||||||
|
|
||||||
// Bucle para la intro del juego
|
|
||||||
void runIntro();
|
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
|
||||||
void runTitle(Uint8 subsection = TITLE_SECTION_1);
|
|
||||||
|
|
||||||
// Bucle para el juego
|
|
||||||
void runGame();
|
|
||||||
|
|
||||||
// Bucle para el menu de pausa del juego
|
|
||||||
void runPausedGame();
|
|
||||||
|
|
||||||
// Bucle para la pantalla de instrucciones
|
|
||||||
void runInstructions();
|
|
||||||
|
|
||||||
// Bucle para la pantalla de game over
|
|
||||||
void runGameOverScreen();
|
|
||||||
|
|
||||||
// Activa el modo Demo
|
|
||||||
void enableDemoMode();
|
|
||||||
|
|
||||||
// Desactiva el modo Demo
|
|
||||||
void disableDemoMode();
|
|
||||||
|
|
||||||
// Intercambia el proximo estado del juego despues del titulo
|
|
||||||
void toogleTitleNextGS();
|
|
||||||
|
|
||||||
// Dibuja la informacion de debug en pantalla
|
|
||||||
void renderDebugInfo();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifdef _WIN64
|
|
||||||
#include "C:\mingw_dev_lib\include\SDL2\SDL.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "C:\mingw_dev_lib\include\SDL2\SDL.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include "/Library/Frameworks/SDL2.framework/Versions/A/Headers/SDL.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include "/usr/include/SDL2/SDL.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UNUSED
|
|
||||||
206
source/input.cpp
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
#include "input.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Input::Input(std::string file)
|
||||||
|
{
|
||||||
|
// Fichero gamecontrollerdb.txt
|
||||||
|
mDBpath = file;
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
for (int i = 0; i < 17; i++)
|
||||||
|
{
|
||||||
|
mKeyBindings[i].scancode = 0;
|
||||||
|
mKeyBindings[i].active = false;
|
||||||
|
|
||||||
|
mGameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
|
mGameControllerBindings[i].active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
discoverGameController();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Input::~Input()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mNumGamepads; i++)
|
||||||
|
mConnectedControllers[i] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||||
|
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||||
|
{
|
||||||
|
mKeyBindings[input].scancode = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asigna uno de los posibles inputs a un botón del mando
|
||||||
|
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||||
|
{
|
||||||
|
mGameControllerBindings[input].button = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si un input esta activo
|
||||||
|
bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||||
|
{
|
||||||
|
bool successKeyboard = false;
|
||||||
|
bool successGameController = false;
|
||||||
|
|
||||||
|
if (device == INPUT_USE_ANY)
|
||||||
|
index = 0;
|
||||||
|
|
||||||
|
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
||||||
|
{
|
||||||
|
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
|
if (repeat)
|
||||||
|
{
|
||||||
|
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||||
|
successKeyboard = true;
|
||||||
|
else
|
||||||
|
successKeyboard = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!mKeyBindings[input].active)
|
||||||
|
{
|
||||||
|
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||||
|
{
|
||||||
|
mKeyBindings[input].active = true;
|
||||||
|
successKeyboard = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successKeyboard = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mKeystates[mKeyBindings[input].scancode] == 0)
|
||||||
|
{
|
||||||
|
mKeyBindings[input].active = false;
|
||||||
|
successKeyboard = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successKeyboard = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameControllerFound())
|
||||||
|
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||||
|
{
|
||||||
|
if (repeat)
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||||
|
successGameController = true;
|
||||||
|
else
|
||||||
|
successGameController = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!mGameControllerBindings[input].active)
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||||
|
{
|
||||||
|
mGameControllerBindings[input].active = true;
|
||||||
|
successGameController = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successGameController = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
|
||||||
|
{
|
||||||
|
mGameControllerBindings[input].active = false;
|
||||||
|
successGameController = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successGameController = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (successKeyboard || successGameController);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si hay un mando conectado
|
||||||
|
bool Input::discoverGameController()
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||||
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
|
||||||
|
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
|
||||||
|
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
||||||
|
|
||||||
|
int nJoysticks = SDL_NumJoysticks();
|
||||||
|
mNumGamepads = 0;
|
||||||
|
|
||||||
|
// Cuenta el numero de mandos
|
||||||
|
for (int i = 0; i < nJoysticks; i++)
|
||||||
|
if (SDL_IsGameController(i))
|
||||||
|
mNumGamepads++;
|
||||||
|
|
||||||
|
printf("\nChecking for game controllers...\n");
|
||||||
|
printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads);
|
||||||
|
|
||||||
|
if (mNumGamepads > 0)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < mNumGamepads; i++)
|
||||||
|
{
|
||||||
|
// Abre el mando y lo añade a la lista
|
||||||
|
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||||
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
|
{
|
||||||
|
mConnectedControllers.push_back(pad);
|
||||||
|
std::string separator(" #");
|
||||||
|
std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
|
name.resize(25);
|
||||||
|
name = name + separator + std::to_string(i);
|
||||||
|
std::cout << name << std::endl;
|
||||||
|
mControllerNames.push_back(name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mGameController = mConnectedControllers[0];
|
||||||
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si hay algun mando conectado
|
||||||
|
bool Input::gameControllerFound()
|
||||||
|
{
|
||||||
|
if (mNumGamepads > 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el nombre de un mando de juego
|
||||||
|
std::string Input::getControllerName(int index)
|
||||||
|
{
|
||||||
|
if (mNumGamepads > 0)
|
||||||
|
return mControllerNames[index];
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el numero de mandos conectados
|
||||||
|
int Input::getNumControllers()
|
||||||
|
{
|
||||||
|
return mNumGamepads;
|
||||||
|
}
|
||||||
87
source/input.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef INPUT_H
|
||||||
|
#define INPUT_H
|
||||||
|
|
||||||
|
#define INPUT_NULL 0
|
||||||
|
#define INPUT_UP 1
|
||||||
|
#define INPUT_DOWN 2
|
||||||
|
#define INPUT_LEFT 3
|
||||||
|
#define INPUT_RIGHT 4
|
||||||
|
#define INPUT_ACCEPT 5
|
||||||
|
#define INPUT_CANCEL 6
|
||||||
|
#define INPUT_BUTTON_1 7
|
||||||
|
#define INPUT_BUTTON_2 8
|
||||||
|
#define INPUT_BUTTON_3 9
|
||||||
|
#define INPUT_BUTTON_4 10
|
||||||
|
#define INPUT_BUTTON_5 11
|
||||||
|
#define INPUT_BUTTON_6 12
|
||||||
|
#define INPUT_BUTTON_7 13
|
||||||
|
#define INPUT_BUTTON_8 14
|
||||||
|
#define INPUT_BUTTON_PAUSE 15
|
||||||
|
#define INPUT_BUTTON_ESCAPE 16
|
||||||
|
|
||||||
|
#define REPEAT_TRUE true
|
||||||
|
#define REPEAT_FALSE false
|
||||||
|
|
||||||
|
#define INPUT_USE_KEYBOARD 0
|
||||||
|
#define INPUT_USE_GAMECONTROLLER 1
|
||||||
|
#define INPUT_USE_ANY 2
|
||||||
|
|
||||||
|
// Clase Input
|
||||||
|
class Input
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct keyBindings_t
|
||||||
|
{
|
||||||
|
Uint8 scancode; // Scancode asociado
|
||||||
|
bool active; // Indica si está activo
|
||||||
|
};
|
||||||
|
keyBindings_t mKeyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
|
||||||
|
struct GameControllerBindings_t
|
||||||
|
{
|
||||||
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||||
|
bool active; // Indica si está activo
|
||||||
|
};
|
||||||
|
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
|
||||||
|
std::vector<SDL_GameController *> mConnectedControllers; // Vector con todos los mandos conectados
|
||||||
|
std::vector<std::string> mControllerNames; // Vector con los nombres de los mandos
|
||||||
|
int mNumGamepads; // Numero de mandos conectados
|
||||||
|
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt
|
||||||
|
|
||||||
|
// Comprueba si hay un mando conectado
|
||||||
|
bool discoverGameController();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Input(std::string file);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Input();
|
||||||
|
|
||||||
|
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||||
|
void bindKey(Uint8 input, SDL_Scancode code);
|
||||||
|
|
||||||
|
// Asigna uno de los posibles inputs a un botón del mando
|
||||||
|
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||||
|
|
||||||
|
// Comprueba si un input esta activo
|
||||||
|
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
|
||||||
|
|
||||||
|
// Comprueba si hay algun mando conectado
|
||||||
|
bool gameControllerFound();
|
||||||
|
|
||||||
|
// Obten el numero de mandos conectados
|
||||||
|
int getNumControllers();
|
||||||
|
|
||||||
|
// Obten el nombre de un mando de juego
|
||||||
|
std::string getControllerName(int index);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
227
source/instructions.cpp
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
#include "instructions.h"
|
||||||
|
|
||||||
|
const Uint8 SELF = 0;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang)
|
||||||
|
{
|
||||||
|
// Copia los punteros
|
||||||
|
mRenderer = renderer;
|
||||||
|
mScreen = screen;
|
||||||
|
this->mAsset = mAsset;
|
||||||
|
mLang = lang;
|
||||||
|
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
mEventHandler = new SDL_Event();
|
||||||
|
mItemTexture = new LTexture(mRenderer);
|
||||||
|
mSprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mItemTexture, mRenderer);
|
||||||
|
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||||
|
|
||||||
|
// Crea un backbuffer para el renderizador
|
||||||
|
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
if (mBackbuffer == nullptr)
|
||||||
|
{
|
||||||
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Instructions::~Instructions()
|
||||||
|
{
|
||||||
|
mRenderer = nullptr;
|
||||||
|
mScreen = nullptr;
|
||||||
|
mAsset = nullptr;
|
||||||
|
mLang = nullptr;
|
||||||
|
|
||||||
|
mItemTexture->unload();
|
||||||
|
delete mItemTexture;
|
||||||
|
mItemTexture = nullptr;
|
||||||
|
|
||||||
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
|
|
||||||
|
delete mEventHandler;
|
||||||
|
mEventHandler = nullptr;
|
||||||
|
|
||||||
|
delete mText;
|
||||||
|
mText = nullptr;
|
||||||
|
|
||||||
|
SDL_DestroyTexture(mBackbuffer);
|
||||||
|
mBackbuffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los recursos necesarios para la sección 'Instructions'
|
||||||
|
bool Instructions::loadMedia()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
success &= loadTextureFromFile(mItemTexture, mAsset->get("items.png"), mRenderer);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables necesarias para la sección 'Instructions'
|
||||||
|
void Instructions::init()
|
||||||
|
{
|
||||||
|
// Carga los recursos
|
||||||
|
loadMedia();
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
mSection.name = SELF;
|
||||||
|
mTicks = 0;
|
||||||
|
mTicksSpeed = 15;
|
||||||
|
mManualQuit = false;
|
||||||
|
mCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para la pantalla de instrucciones
|
||||||
|
void Instructions::run(Uint8 mode)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
while (mSection.name == SELF)
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que hay en la cola
|
||||||
|
while (SDL_PollEvent(mEventHandler) != 0)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (mEventHandler->type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
mSection.name = PROG_SECTION_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
|
{
|
||||||
|
JA_StopMusic();
|
||||||
|
mSection.name = PROG_SECTION_TITLE;
|
||||||
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mManualQuit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
mTicks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Modo automático
|
||||||
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
|
{
|
||||||
|
mCounter++;
|
||||||
|
|
||||||
|
if (mCounter == INSTRUCTIONS_COUNTER)
|
||||||
|
{
|
||||||
|
mSection.name = PROG_SECTION_TITLE;
|
||||||
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Modo manual
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++mCounter %= 60000;
|
||||||
|
|
||||||
|
if (mManualQuit)
|
||||||
|
{
|
||||||
|
mSection.name = PROG_SECTION_TITLE;
|
||||||
|
mSection.subsection = TITLE_SECTION_3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta en pantalla
|
||||||
|
SDL_Rect window = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
|
SDL_Rect srcRect = {0, 0, 16, 16};
|
||||||
|
|
||||||
|
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||||
|
|
||||||
|
const SDL_Rect destRect1 = {60, 88 + (16 * 0), 16, 16}; // Disquito
|
||||||
|
const SDL_Rect destRect2 = {60, 88 + (16 * 1), 16, 16}; // Gavineixon
|
||||||
|
const SDL_Rect destRect3 = {60, 88 + (16 * 2), 16, 16}; // Pacmar
|
||||||
|
const SDL_Rect destRect4 = {60, 88 + (16 * 3), 16, 16}; // Time Stopper
|
||||||
|
const SDL_Rect destRect5 = {60, 88 + (16 * 4), 16, 16}; // Coffee
|
||||||
|
|
||||||
|
// Pinta en el backbuffer el texto y los sprites
|
||||||
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
|
// Escribe el texto
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 8, mLang->getText(11), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 24, mLang->getText(12), 1, noColor, 1, shdwTxtColor);
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 34, mLang->getText(13), 1, noColor, 1, shdwTxtColor);
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 48, mLang->getText(14), 1, noColor, 1, shdwTxtColor);
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 58, mLang->getText(15), 1, noColor, 1, shdwTxtColor);
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 75, mLang->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
|
||||||
|
mText->writeShadowed(84, 92, mLang->getText(17), shdwTxtColor);
|
||||||
|
mText->writeShadowed(84, 108, mLang->getText(18), shdwTxtColor);
|
||||||
|
mText->writeShadowed(84, 124, mLang->getText(19), shdwTxtColor);
|
||||||
|
mText->writeShadowed(84, 140, mLang->getText(20), shdwTxtColor);
|
||||||
|
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
|
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
||||||
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
|
||||||
|
// Disquito
|
||||||
|
mSprite->setPos(destRect1);
|
||||||
|
srcRect.x = 0;
|
||||||
|
srcRect.y = 16 * (((mCounter + 12) / 36) % 2);
|
||||||
|
mSprite->setSpriteClip(srcRect);
|
||||||
|
mSprite->render();
|
||||||
|
|
||||||
|
// Gavineixon
|
||||||
|
mSprite->setPos(destRect2);
|
||||||
|
srcRect.x += srcRect.w;
|
||||||
|
srcRect.y = 16 * (((mCounter + 9) / 36) % 2);
|
||||||
|
mSprite->setSpriteClip(srcRect);
|
||||||
|
mSprite->render();
|
||||||
|
|
||||||
|
// Pacmar
|
||||||
|
mSprite->setPos(destRect3);
|
||||||
|
srcRect.x += srcRect.w;
|
||||||
|
srcRect.y = 16 * (((mCounter + 6) / 36) % 2);
|
||||||
|
mSprite->setSpriteClip(srcRect);
|
||||||
|
mSprite->render();
|
||||||
|
|
||||||
|
// Time Stopper
|
||||||
|
mSprite->setPos(destRect4);
|
||||||
|
srcRect.x += srcRect.w;
|
||||||
|
srcRect.y = 16 * (((mCounter + 3) / 36) % 2);
|
||||||
|
mSprite->setSpriteClip(srcRect);
|
||||||
|
mSprite->render();
|
||||||
|
|
||||||
|
// Coffee
|
||||||
|
mSprite->setPos(destRect5);
|
||||||
|
srcRect.x += (srcRect.w * 2); // Se salta el icono del TNT
|
||||||
|
srcRect.y = 16 * (((mCounter + 0) / 36) % 2);
|
||||||
|
mSprite->setSpriteClip(srcRect);
|
||||||
|
mSprite->render();
|
||||||
|
|
||||||
|
// Cambia el destino de renderizado
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
mScreen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
mScreen->clean(bgColor);
|
||||||
|
|
||||||
|
// Establece la ventana del backbuffer
|
||||||
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
|
window.y = std::max(8, SCREEN_HEIGHT - mCounter + 100);
|
||||||
|
else
|
||||||
|
window.y = 0;
|
||||||
|
|
||||||
|
// Copia el backbuffer al renderizador
|
||||||
|
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
mScreen->blit();
|
||||||
|
}
|
||||||
|
}
|
||||||
64
source/instructions.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#ifndef INSTRUCTIONS_H
|
||||||
|
#define INSTRUCTIONS_H
|
||||||
|
|
||||||
|
// Contadores
|
||||||
|
#define INSTRUCTIONS_COUNTER 600
|
||||||
|
|
||||||
|
// Modo para las instrucciones
|
||||||
|
#define INSTRUCTIONS_MODE_MANUAL 0
|
||||||
|
#define INSTRUCTIONS_MODE_AUTO 1
|
||||||
|
|
||||||
|
// Clase Instructions
|
||||||
|
class Instructions
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||||
|
LTexture *mItemTexture; // Textura con los graficos
|
||||||
|
SDL_Event *mEventHandler; // Manejador de eventos
|
||||||
|
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
||||||
|
Sprite *mSprite; // Sprite con la textura de las instrucciones
|
||||||
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
Text *mText; // Objeto para escribir texto
|
||||||
|
Uint16 mCounter; // Contador
|
||||||
|
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
bool mManualQuit; // Indica si se quiere salir del modo manual
|
||||||
|
|
||||||
|
// Carga los recursos
|
||||||
|
bool loadMedia();
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Pinta en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Instructions();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
void run(Uint8 mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
383
source/intro.cpp
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
#include "intro.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang)
|
||||||
|
{
|
||||||
|
// Copia los punteros
|
||||||
|
mRenderer = renderer;
|
||||||
|
mScreen = screen;
|
||||||
|
mLang = lang;
|
||||||
|
this->mAsset = mAsset;
|
||||||
|
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
mEventHandler = new SDL_Event();
|
||||||
|
mBitmapTexture = new LTexture(mRenderer);
|
||||||
|
mText = new Text(mAsset->get("nokia.png"), mAsset->get("nokia.txt"), mRenderer);
|
||||||
|
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
|
{
|
||||||
|
mBitmap[i] = new SmartSprite();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
|
{
|
||||||
|
mWriter[i] = new Writer(mText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Intro::~Intro()
|
||||||
|
{
|
||||||
|
mRenderer = nullptr;
|
||||||
|
mScreen = nullptr;
|
||||||
|
mAsset = nullptr;
|
||||||
|
mLang = nullptr;
|
||||||
|
|
||||||
|
delete mEventHandler;
|
||||||
|
mEventHandler = nullptr;
|
||||||
|
|
||||||
|
mBitmapTexture->unload();
|
||||||
|
delete mBitmapTexture;
|
||||||
|
mBitmapTexture = nullptr;
|
||||||
|
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
|
{
|
||||||
|
delete mBitmap[i];
|
||||||
|
mBitmap[i] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
|
{
|
||||||
|
delete mWriter[i];
|
||||||
|
mWriter[i] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_DeleteMusic(mMusic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void Intro::init()
|
||||||
|
{
|
||||||
|
// Carga los recursos
|
||||||
|
loadMedia();
|
||||||
|
|
||||||
|
mSection = {PROG_SECTION_INTRO, 0};
|
||||||
|
mTicks = 0;
|
||||||
|
mTicksSpeed = 15;
|
||||||
|
|
||||||
|
// Inicializa el vector de eventos de la intro
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_EVENTS; i++)
|
||||||
|
mEvents[i] = EVENT_WAITING;
|
||||||
|
|
||||||
|
// Inicializa los bitmaps de la intro
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
|
{
|
||||||
|
mBitmap[i]->init(mBitmapTexture, mRenderer);
|
||||||
|
mBitmap[i]->setId(i);
|
||||||
|
mBitmap[i]->setIntroEvents(&mEvents[0]);
|
||||||
|
mBitmap[i]->setWidth(128);
|
||||||
|
mBitmap[i]->setHeight(96);
|
||||||
|
mBitmap[i]->setEnabled(false);
|
||||||
|
mBitmap[i]->setEnabledTimer(20);
|
||||||
|
mBitmap[i]->setDestX(SCREEN_CENTER_X - 64);
|
||||||
|
mBitmap[i]->setDestY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBitmap[0]->setPosX(-128);
|
||||||
|
mBitmap[0]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
|
mBitmap[0]->setVelX(0.0f);
|
||||||
|
mBitmap[0]->setVelY(0.0f);
|
||||||
|
mBitmap[0]->setAccelX(0.6f);
|
||||||
|
mBitmap[0]->setAccelY(0.0f);
|
||||||
|
mBitmap[0]->setSpriteClip(0, 0, 128, 96);
|
||||||
|
|
||||||
|
mBitmap[1]->setPosX(SCREEN_WIDTH);
|
||||||
|
mBitmap[1]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
|
mBitmap[1]->setVelX(-1.0f);
|
||||||
|
mBitmap[1]->setVelY(0.0f);
|
||||||
|
mBitmap[1]->setAccelX(-0.3f);
|
||||||
|
mBitmap[1]->setAccelY(0.0f);
|
||||||
|
mBitmap[1]->setSpriteClip(128, 0, 128, 96);
|
||||||
|
|
||||||
|
mBitmap[2]->setPosX(SCREEN_CENTER_X - 64);
|
||||||
|
mBitmap[2]->setPosY(-96);
|
||||||
|
mBitmap[2]->setVelX(0.0f);
|
||||||
|
mBitmap[2]->setVelY(3.0f);
|
||||||
|
mBitmap[2]->setAccelX(0.1f);
|
||||||
|
mBitmap[2]->setAccelY(0.3f);
|
||||||
|
mBitmap[2]->setSpriteClip(0, 96, 128, 96);
|
||||||
|
|
||||||
|
mBitmap[2]->setEnabledTimer(250);
|
||||||
|
|
||||||
|
mBitmap[3]->setPosX(SCREEN_CENTER_X - 64);
|
||||||
|
mBitmap[3]->setPosY(SCREEN_HEIGHT);
|
||||||
|
mBitmap[3]->setVelX(0.0f);
|
||||||
|
mBitmap[3]->setVelY(-0.7f);
|
||||||
|
mBitmap[3]->setAccelX(0.0f);
|
||||||
|
mBitmap[3]->setAccelY(0.0f);
|
||||||
|
mBitmap[3]->setSpriteClip(128, 96, 128, 96);
|
||||||
|
|
||||||
|
mBitmap[4]->setPosX(SCREEN_CENTER_X - 64);
|
||||||
|
mBitmap[4]->setPosY(-96);
|
||||||
|
mBitmap[4]->setVelX(0.0f);
|
||||||
|
mBitmap[4]->setVelY(3.0f);
|
||||||
|
mBitmap[4]->setAccelX(0.1f);
|
||||||
|
mBitmap[4]->setAccelY(0.3f);
|
||||||
|
mBitmap[4]->setSpriteClip(0, 192, 128, 96);
|
||||||
|
|
||||||
|
mBitmap[5]->setPosX(SCREEN_WIDTH);
|
||||||
|
mBitmap[5]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
|
mBitmap[5]->setVelX(-0.7f);
|
||||||
|
mBitmap[5]->setVelY(0.0f);
|
||||||
|
mBitmap[5]->setAccelX(0.0f);
|
||||||
|
mBitmap[5]->setAccelY(0.0f);
|
||||||
|
mBitmap[5]->setSpriteClip(128, 192, 128, 96);
|
||||||
|
|
||||||
|
// Inicializa los textos de la intro
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
|
{
|
||||||
|
mWriter[i]->init();
|
||||||
|
mWriter[i]->setId(6 + i);
|
||||||
|
mWriter[i]->setIntroEvents(&mEvents[0]);
|
||||||
|
mWriter[i]->setPosX(BLOCK * 0);
|
||||||
|
mWriter[i]->setPosY(SCREEN_HEIGHT - (BLOCK * 6));
|
||||||
|
mWriter[i]->setKerning(-1);
|
||||||
|
mWriter[i]->setEnabled(false);
|
||||||
|
mWriter[i]->setEnabledTimer(180);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un dia qualsevol de l'any 2000
|
||||||
|
mWriter[0]->setCaption(mLang->getText(27));
|
||||||
|
mWriter[0]->setSpeed(10);
|
||||||
|
|
||||||
|
// Tot esta tranquil a la UPV
|
||||||
|
mWriter[1]->setCaption(mLang->getText(28));
|
||||||
|
mWriter[1]->setSpeed(10);
|
||||||
|
|
||||||
|
// Fins que un desaprensiu...
|
||||||
|
mWriter[2]->setCaption(mLang->getText(29));
|
||||||
|
mWriter[2]->setSpeed(15);
|
||||||
|
|
||||||
|
// HEY! ME ANE A FERME UN CORTAET...
|
||||||
|
mWriter[3]->setCaption(mLang->getText(30));
|
||||||
|
mWriter[3]->setSpeed(10);
|
||||||
|
|
||||||
|
// UAAAAAAAAAAAAA!!!
|
||||||
|
mWriter[4]->setCaption(mLang->getText(31));
|
||||||
|
mWriter[4]->setSpeed(1);
|
||||||
|
|
||||||
|
// Espera un moment...
|
||||||
|
mWriter[5]->setCaption(mLang->getText(32));
|
||||||
|
mWriter[5]->setSpeed(20);
|
||||||
|
|
||||||
|
// Si resulta que no tinc solt!
|
||||||
|
mWriter[6]->setCaption(mLang->getText(33));
|
||||||
|
mWriter[6]->setSpeed(2);
|
||||||
|
|
||||||
|
// MERDA DE MAQUINA!
|
||||||
|
mWriter[7]->setCaption(mLang->getText(34));
|
||||||
|
mWriter[7]->setSpeed(3);
|
||||||
|
|
||||||
|
// Blop... blop... blop...
|
||||||
|
mWriter[8]->setCaption(mLang->getText(35));
|
||||||
|
mWriter[8]->setSpeed(20);
|
||||||
|
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
|
mWriter[i]->center(SCREEN_CENTER_X);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los recursos
|
||||||
|
bool Intro::loadMedia()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Texturas
|
||||||
|
success &= loadTextureFromFile(mBitmapTexture, mAsset->get("intro.png"), mRenderer);
|
||||||
|
|
||||||
|
// Musicas
|
||||||
|
mMusic = JA_LoadMusic(mAsset->get("intro.ogg").c_str());
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
section_t Intro::run()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
// Si la música no está sonando la hace sonar
|
||||||
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
|
{
|
||||||
|
JA_PlayMusic(mMusic, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mSection.name == PROG_SECTION_INTRO)
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que hay en la cola
|
||||||
|
while (SDL_PollEvent(mEventHandler) != 0)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (mEventHandler->type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
mSection.name = PROG_SECTION_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
JA_StopMusic();
|
||||||
|
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
mTicks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza los objetos
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
|
{
|
||||||
|
mBitmap[i]->update();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
|
{
|
||||||
|
mWriter[i]->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guión de eventos
|
||||||
|
// Primera imagen - UPV
|
||||||
|
if (mEvents[BITMAP0] == EVENT_WAITING)
|
||||||
|
{
|
||||||
|
mBitmap[0]->setEnabled(true);
|
||||||
|
mEvents[BITMAP0] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Primer texto de la primera imagen
|
||||||
|
if ((mEvents[BITMAP0] == EVENT_COMPLETED) && (mEvents[TEXT0] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[0]->setEnabled(true);
|
||||||
|
mEvents[TEXT0] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Segundo texto de la primera imagen
|
||||||
|
if ((mEvents[TEXT0] == EVENT_COMPLETED) && (mEvents[TEXT1] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[0]->setEnabled(false);
|
||||||
|
mWriter[1]->setEnabled(true);
|
||||||
|
mEvents[TEXT1] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tercer texto de la primera imagen
|
||||||
|
if ((mEvents[TEXT1] == EVENT_COMPLETED) && (mEvents[TEXT2] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[1]->setEnabled(false);
|
||||||
|
mWriter[2]->setEnabled(true);
|
||||||
|
mEvents[TEXT2] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Segunda imagen - Máquina
|
||||||
|
if ((mEvents[TEXT2] == EVENT_COMPLETED) && (mEvents[BITMAP1] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mBitmap[0]->setEnabled(false);
|
||||||
|
mWriter[2]->setEnabled(false);
|
||||||
|
mBitmap[1]->setEnabled(true);
|
||||||
|
mEvents[BITMAP1] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Primer texto de la segunda imagen
|
||||||
|
if ((mEvents[BITMAP1] == EVENT_COMPLETED) && (mEvents[TEXT3] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[3]->setEnabled(true);
|
||||||
|
mEvents[TEXT3] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tercera imagen junto con primer texto - GRITO
|
||||||
|
if ((mEvents[TEXT3] == EVENT_COMPLETED) && (mEvents[BITMAP2] == EVENT_WAITING) && (mEvents[TEXT4] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mBitmap[1]->setEnabled(false);
|
||||||
|
mWriter[3]->setEnabled(false);
|
||||||
|
mBitmap[2]->setEnabled(true);
|
||||||
|
mWriter[4]->setEnabled(true);
|
||||||
|
mEvents[BITMAP2] = EVENT_RUNNING;
|
||||||
|
mEvents[TEXT4] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cuarta imagen junto con primer texto - Reflexión
|
||||||
|
if ((mEvents[TEXT4] == EVENT_COMPLETED) && (mEvents[BITMAP3] == EVENT_WAITING) && (mEvents[TEXT5] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mBitmap[2]->setEnabled(false);
|
||||||
|
mWriter[4]->setEnabled(false);
|
||||||
|
mBitmap[3]->setEnabled(true);
|
||||||
|
mWriter[5]->setEnabled(true);
|
||||||
|
mEvents[BITMAP3] = EVENT_RUNNING;
|
||||||
|
mEvents[TEXT5] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Segundo texto de la cuarta imagen
|
||||||
|
if ((mEvents[TEXT5] == EVENT_COMPLETED) && (mEvents[TEXT6] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[5]->setEnabled(false);
|
||||||
|
mWriter[6]->setEnabled(true);
|
||||||
|
mEvents[TEXT6] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quinta imagen - Patada
|
||||||
|
if ((mEvents[TEXT6] == EVENT_COMPLETED) && (mEvents[BITMAP4] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mBitmap[3]->setEnabled(false);
|
||||||
|
mWriter[6]->setEnabled(false);
|
||||||
|
mBitmap[4]->setEnabled(true);
|
||||||
|
mEvents[BITMAP4] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Primer texto de la quinta imagen
|
||||||
|
if ((mEvents[BITMAP4] == EVENT_COMPLETED) && (mEvents[TEXT7] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mWriter[7]->setEnabled(true);
|
||||||
|
mEvents[TEXT7] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sexta imagen junto con texto - Globos de café
|
||||||
|
if ((mEvents[TEXT7] == EVENT_COMPLETED) && (mEvents[BITMAP5] == EVENT_WAITING) && (mEvents[TEXT8] == EVENT_WAITING))
|
||||||
|
{
|
||||||
|
mBitmap[4]->setEnabled(false);
|
||||||
|
mWriter[7]->setEnabled(false);
|
||||||
|
mBitmap[5]->setEnabled(true);
|
||||||
|
mWriter[8]->setEnabled(true);
|
||||||
|
mEvents[BITMAP5] = EVENT_RUNNING;
|
||||||
|
mEvents[TEXT8] = EVENT_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Acaba el último texto
|
||||||
|
if (mEvents[TEXT8] == EVENT_COMPLETED)
|
||||||
|
{
|
||||||
|
mWriter[8]->setEnabled(false);
|
||||||
|
JA_StopMusic();
|
||||||
|
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
mScreen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
mScreen->clean(bgColor);
|
||||||
|
|
||||||
|
// Dibuja los objetos
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; ++i)
|
||||||
|
{
|
||||||
|
mBitmap[i]->render();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; ++i)
|
||||||
|
{
|
||||||
|
mWriter[i]->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
mScreen->blit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mSection;
|
||||||
|
}
|
||||||
73
source/intro.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "smartsprite.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "writer.h"
|
||||||
|
|
||||||
|
#ifndef INTRO_H
|
||||||
|
#define INTRO_H
|
||||||
|
|
||||||
|
// Cantidad de eventos de la intro
|
||||||
|
#define INTRO_TOTAL_BITMAPS 6
|
||||||
|
#define INTRO_TOTAL_TEXTS 9
|
||||||
|
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
|
||||||
|
|
||||||
|
// Relaciones de Id con nombres
|
||||||
|
#define BITMAP0 0
|
||||||
|
#define BITMAP1 1
|
||||||
|
#define BITMAP2 2
|
||||||
|
#define BITMAP3 3
|
||||||
|
#define BITMAP4 4
|
||||||
|
#define BITMAP5 5
|
||||||
|
#define TEXT0 6
|
||||||
|
#define TEXT1 7
|
||||||
|
#define TEXT2 8
|
||||||
|
#define TEXT3 9
|
||||||
|
#define TEXT4 10
|
||||||
|
#define TEXT5 11
|
||||||
|
#define TEXT6 12
|
||||||
|
#define TEXT7 13
|
||||||
|
#define TEXT8 14
|
||||||
|
|
||||||
|
// Clase Intro
|
||||||
|
class Intro
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||||
|
LTexture *mBitmapTexture; // Textura con los graficos
|
||||||
|
SDL_Event *mEventHandler; // Manejador de eventos
|
||||||
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
SmartSprite *mBitmap[INTRO_TOTAL_BITMAPS]; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||||
|
Writer *mWriter[INTRO_TOTAL_TEXTS]; // Textos de la intro
|
||||||
|
Text *mText; // Textos de la intro
|
||||||
|
Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
|
||||||
|
JA_Music mMusic; // Musica para la intro
|
||||||
|
|
||||||
|
// Carga los recursos
|
||||||
|
bool loadMedia();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Intro(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Intro();
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
section_t run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,22 +2,11 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item()
|
Item::Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
mSprite = new AnimatedSprite();
|
mSprite = new AnimatedSprite(texture, renderer);
|
||||||
init(NO_KIND, 0, 0, nullptr, nullptr);
|
mClass = NO_KIND;
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Item::~Item()
|
|
||||||
{
|
|
||||||
init(NO_KIND, 0, 0, nullptr, nullptr);
|
|
||||||
delete mSprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iniciador
|
|
||||||
void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer)
|
|
||||||
{
|
|
||||||
mClass = value;
|
mClass = value;
|
||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
mTimeToLive = 600;
|
mTimeToLive = 600;
|
||||||
@@ -29,18 +18,19 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
|
|||||||
mVelY = -4.0f;
|
mVelY = -4.0f;
|
||||||
mAccelX = 0.0f;
|
mAccelX = 0.0f;
|
||||||
mAccelY = 0.2f;
|
mAccelY = 0.2f;
|
||||||
|
mFloorCollision = false;
|
||||||
mCollider.r = mWidth / 2;
|
mCollider.r = mWidth / 2;
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
|
|
||||||
mSprite->init(texture, renderer);
|
|
||||||
mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight);
|
||||||
mSprite->setCurrentFrame(0);
|
mSprite->setCurrentFrame(0);
|
||||||
mSprite->setAnimationCounter(0);
|
mSprite->setAnimationCounter(0);
|
||||||
mSprite->setAnimationNumFrames(0, 2);
|
|
||||||
mSprite->setAnimationSpeed(0, 10);
|
mSprite->setAnimationSpeed(0, 10);
|
||||||
mSprite->setAnimationLoop(0, true);
|
mSprite->setAnimationLoop(0, true);
|
||||||
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
||||||
|
mSprite->setPosX(mPosX);
|
||||||
|
mSprite->setPosY(mPosY);
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
@@ -54,36 +44,63 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
|
|||||||
mVelX = 0;
|
mVelX = 0;
|
||||||
mVelY = 0;
|
mVelY = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_1_DISK:
|
case ITEM_POINTS_1_DISK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
case ITEM_POINTS_2_GAVINA:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
case ITEM_POINTS_3_PACMAR:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_CLOCK:
|
case ITEM_CLOCK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight);
|
||||||
break;
|
break;
|
||||||
case ITEM_TNT:
|
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 4, 16 * 0, mWidth, mHeight);
|
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 4, 16 * 1, mWidth, mHeight);
|
|
||||||
break;
|
|
||||||
case ITEM_COFFEE:
|
case ITEM_COFFEE:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight);
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight);
|
mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ITEM_COFFEE_MACHINE:
|
||||||
|
mWidth = 32;
|
||||||
|
mHeight = 32;
|
||||||
|
mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth - 5)) + 2;
|
||||||
|
mPosY = PLAY_AREA_TOP - mHeight;
|
||||||
|
mVelX = 0.0f;
|
||||||
|
mVelY = -0.1f;
|
||||||
|
mAccelY = 0.1f;
|
||||||
|
mSprite->setAnimationFrames(0, 0, 32 * 0, 16 * 2, mWidth, mHeight);
|
||||||
|
mSprite->setAnimationFrames(0, 1, 32 * 1, 16 * 2, mWidth, mHeight);
|
||||||
|
mSprite->setAnimationFrames(0, 2, 32 * 2, 16 * 2, mWidth, mHeight);
|
||||||
|
mSprite->setAnimationFrames(0, 3, 32 * 3, 16 * 2, mWidth, mHeight);
|
||||||
|
mSprite->setPosX(mPosX);
|
||||||
|
mSprite->setPosY(mPosY);
|
||||||
|
mCollider.r = 10;
|
||||||
|
shiftColliders();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Destructor
|
||||||
|
Item::~Item()
|
||||||
|
{
|
||||||
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Centra el objeto en la posición X
|
||||||
void Item::allignTo(int x)
|
void Item::allignTo(int x)
|
||||||
{
|
{
|
||||||
mPosX = float(x - (mWidth / 2));
|
mPosX = float(x - (mWidth / 2));
|
||||||
@@ -105,7 +122,7 @@ void Item::allignTo(int x)
|
|||||||
shiftColliders();
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el globo en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void Item::render()
|
void Item::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
@@ -121,9 +138,11 @@ void Item::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición y estados del globo
|
// Actualiza la posición y estados del objeto
|
||||||
void Item::move()
|
void Item::move()
|
||||||
{
|
{
|
||||||
|
mFloorCollision = false;
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
mPosX += mVelX;
|
mPosX += mVelX;
|
||||||
mPosY += mVelY;
|
mPosY += mVelY;
|
||||||
@@ -142,8 +161,8 @@ void Item::move()
|
|||||||
mVelX = -mVelX;
|
mVelX = -mVelX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se sale por arriba
|
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||||
if (mPosY < PLAY_AREA_TOP)
|
if ((mPosY < PLAY_AREA_TOP) && !(mClass == ITEM_COFFEE_MACHINE))
|
||||||
{
|
{
|
||||||
// Corrige
|
// Corrige
|
||||||
mPosY = PLAY_AREA_TOP;
|
mPosY = PLAY_AREA_TOP;
|
||||||
@@ -164,6 +183,8 @@ void Item::move()
|
|||||||
mAccelX = 0;
|
mAccelX = 0;
|
||||||
mAccelY = 0;
|
mAccelY = 0;
|
||||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
||||||
|
if (mClass == ITEM_COFFEE_MACHINE)
|
||||||
|
mFloorCollision = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
@@ -174,7 +195,7 @@ void Item::move()
|
|||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void Item::erase()
|
void Item::erase()
|
||||||
{
|
{
|
||||||
init(NO_KIND, 0, 0, nullptr, nullptr);
|
//init(NO_KIND, 0, 0, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||||
@@ -195,7 +216,7 @@ void Item::updateTimeToLive()
|
|||||||
{
|
{
|
||||||
if (mTimeToLive > 0)
|
if (mTimeToLive > 0)
|
||||||
{
|
{
|
||||||
--mTimeToLive;
|
mTimeToLive--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +224,7 @@ void Item::updateTimeToLive()
|
|||||||
void Item::checkTimeToLive()
|
void Item::checkTimeToLive()
|
||||||
{
|
{
|
||||||
if (mTimeToLive == 0)
|
if (mTimeToLive == 0)
|
||||||
{
|
|
||||||
erase();
|
erase();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
@@ -259,6 +278,12 @@ circle_t &Item::getCollider()
|
|||||||
// Alinea el circulo de colisión con la posición del objeto
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
void Item::shiftColliders()
|
void Item::shiftColliders()
|
||||||
{
|
{
|
||||||
mCollider.x = Uint16(mPosX + mCollider.r);
|
mCollider.x = int(mPosX + (mWidth / 2));
|
||||||
mCollider.y = Uint16(mPosY + mCollider.r);
|
mCollider.y = int(mPosY + (mHeight / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
|
bool Item::floorCollision()
|
||||||
|
{
|
||||||
|
return mFloorCollision;
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,53 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef ITEM_H
|
#ifndef ITEM_H
|
||||||
#define ITEM_H
|
#define ITEM_H
|
||||||
|
|
||||||
// Clase AnimatedSprite
|
// Tipos de objetos
|
||||||
|
#define ITEM_POINTS_1_DISK 1
|
||||||
|
#define ITEM_POINTS_2_GAVINA 2
|
||||||
|
#define ITEM_POINTS_3_PACMAR 3
|
||||||
|
#define ITEM_CLOCK 4
|
||||||
|
#define ITEM_COFFEE 5
|
||||||
|
#define ITEM_POWER_BALL 6
|
||||||
|
#define ITEM_COFFEE_MACHINE 7
|
||||||
|
|
||||||
|
// Clase Item
|
||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
float mPosX; // Posición X del objeto
|
||||||
|
float mPosY; // Posición Y del objeto
|
||||||
|
Uint8 mWidth; // Ancho del objeto
|
||||||
|
Uint8 mHeight; // Alto del objeto
|
||||||
|
float mVelX; // Velocidad en el eje X
|
||||||
|
float mVelY; // Velocidad en el eje Y
|
||||||
|
float mAccelX; // Aceleración en el eje X
|
||||||
|
float mAccelY; // Aceleración en el eje Y
|
||||||
|
bool mFloorCollision; // Indica si el objeto colisiona con el suelo
|
||||||
|
|
||||||
|
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
|
||||||
|
|
||||||
|
Uint8 mClass; // Especifica el tipo de objeto que es
|
||||||
|
bool mEnabled; // Especifica si el objeto está habilitado
|
||||||
|
circle_t mCollider; // Circulo de colisión del objeto
|
||||||
|
|
||||||
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
|
void shiftColliders();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item();
|
Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Item();
|
~Item();
|
||||||
|
|
||||||
// Iniciador
|
|
||||||
void init(Uint8 value, float x, float y, LTexture* texture, SDL_Renderer *renderer);
|
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
@@ -64,40 +93,8 @@ public:
|
|||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
// Temporizador con el tiempo que el objeto está presente
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
Uint16 mTimeToLive;
|
bool floorCollision();
|
||||||
|
|
||||||
private:
|
|
||||||
// Posición X,Y del objeto
|
|
||||||
float mPosX;
|
|
||||||
float mPosY;
|
|
||||||
|
|
||||||
// Alto y ancho del objeto
|
|
||||||
Uint8 mWidth;
|
|
||||||
Uint8 mHeight;
|
|
||||||
|
|
||||||
// Variables para controlar la velocidad del objeto
|
|
||||||
float mVelX;
|
|
||||||
float mVelY;
|
|
||||||
|
|
||||||
// Aceleración
|
|
||||||
float mAccelX;
|
|
||||||
float mAccelY;
|
|
||||||
|
|
||||||
// Sprite con los graficos del objeto
|
|
||||||
AnimatedSprite *mSprite;
|
|
||||||
|
|
||||||
// Especifica el tipo de objeto que es
|
|
||||||
Uint8 mClass;
|
|
||||||
|
|
||||||
// Especifica si está habilitado el objeto
|
|
||||||
bool mEnabled;
|
|
||||||
|
|
||||||
// Circulo de colisión del objeto
|
|
||||||
circle_t mCollider;
|
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto
|
|
||||||
void shiftColliders();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "stb_vorbis.c"
|
#include "stb_vorbis.c"
|
||||||
//#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||||
|
|
||||||
@@ -30,16 +31,17 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
|||||||
int JA_freq {48000};
|
int JA_freq {48000};
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||||
Uint8 JA_channels {2};
|
Uint8 JA_channels {2};
|
||||||
|
int JA_volume = 128;
|
||||||
|
|
||||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||||
SDL_memset(stream, 0, len);
|
SDL_memset(stream, 0, len);
|
||||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
||||||
SDL_memcpy(stream, current_music->output+current_music->pos, size);
|
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
||||||
current_music->pos += size/2;
|
current_music->pos += size/2;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (current_music->times != 0) {
|
if (current_music->times != 0) {
|
||||||
SDL_memcpy(stream+size, current_music->output, len-size);
|
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
||||||
current_music->pos = (len-size)/2;
|
current_music->pos = (len-size)/2;
|
||||||
if (current_music->times > 0) current_music->times--;
|
if (current_music->times > 0) current_music->times--;
|
||||||
} else {
|
} else {
|
||||||
@@ -52,11 +54,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, 64);
|
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
||||||
channels[i].pos += size;
|
channels[i].pos += size;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (channels[i].times != 0) {
|
if (channels[i].times != 0) {
|
||||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64);
|
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
||||||
channels[i].pos = len-size;
|
channels[i].pos = len-size;
|
||||||
if (channels[i].times > 0) channels[i].times--;
|
if (channels[i].times > 0) channels[i].times--;
|
||||||
} else {
|
} else {
|
||||||
@@ -79,7 +81,19 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|||||||
JA_Music JA_LoadMusic(const char* filename) {
|
JA_Music JA_LoadMusic(const char* filename) {
|
||||||
int chan, samplerate;
|
int chan, samplerate;
|
||||||
JA_Music music = new JA_Music_t();
|
JA_Music music = new JA_Music_t();
|
||||||
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
|
||||||
|
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||||
|
FILE *f = fopen(filename, "rb");
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long fsize = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
|
||||||
|
fread(buffer, fsize, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
||||||
|
free(buffer);
|
||||||
|
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||||
|
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
SDL_AudioCVT cvt;
|
||||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||||
@@ -134,6 +148,13 @@ void JA_DeleteMusic(JA_Music music) {
|
|||||||
delete music;
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||||
|
JA_Sound sound = new JA_Sound_t();
|
||||||
|
sound->buffer = buffer;
|
||||||
|
sound->length = length;
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
JA_Sound JA_LoadSound(const char* filename) {
|
JA_Sound JA_LoadSound(const char* filename) {
|
||||||
JA_Sound sound = new JA_Sound_t();
|
JA_Sound sound = new JA_Sound_t();
|
||||||
SDL_AudioSpec wavSpec;
|
SDL_AudioSpec wavSpec;
|
||||||
@@ -211,3 +232,7 @@ JA_Channel_state JA_GetChannelState(const int channel) {
|
|||||||
return channels[channel].state;
|
return channels[channel].state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume) {
|
||||||
|
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||||
|
return JA_volume;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
||||||
@@ -17,6 +17,7 @@ void JA_StopMusic();
|
|||||||
JA_Music_state JA_GetMusicState();
|
JA_Music_state JA_GetMusicState();
|
||||||
void JA_DeleteMusic(JA_Music music);
|
void JA_DeleteMusic(JA_Music music);
|
||||||
|
|
||||||
|
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length);
|
||||||
JA_Sound JA_LoadSound(const char* filename);
|
JA_Sound JA_LoadSound(const char* filename);
|
||||||
int JA_PlaySound(JA_Sound sound, const int loop = 0);
|
int JA_PlaySound(JA_Sound sound, const int loop = 0);
|
||||||
void JA_PauseChannel(const int channel);
|
void JA_PauseChannel(const int channel);
|
||||||
@@ -24,3 +25,5 @@ void JA_ResumeChannel(const int channel);
|
|||||||
void JA_StopChannel(const int channel);
|
void JA_StopChannel(const int channel);
|
||||||
JA_Channel_state JA_GetChannelState(const int channel);
|
JA_Channel_state JA_GetChannelState(const int channel);
|
||||||
void JA_DeleteSound(JA_Sound sound);
|
void JA_DeleteSound(JA_Sound sound);
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume);
|
||||||
73
source/lang.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#include "lang.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Lang::Lang(Asset *mAsset)
|
||||||
|
{
|
||||||
|
this->mAsset = mAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Lang::~Lang()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa los textos del juego en el idioma seleccionado
|
||||||
|
bool Lang::setLang(Uint8 lang)
|
||||||
|
{
|
||||||
|
std::string file;
|
||||||
|
|
||||||
|
switch (lang)
|
||||||
|
{
|
||||||
|
case es_ES:
|
||||||
|
file = mAsset->get("es_ES.txt");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case en_UK:
|
||||||
|
file = mAsset->get("en_UK.txt");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ba_BA:
|
||||||
|
file = mAsset->get("ba_BA.txt");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
file = mAsset->get("en_UK.txt");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_TEXT_STRINGS; i++)
|
||||||
|
mTextStrings[i] = "";
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
std::ifstream rfile(file);
|
||||||
|
if (rfile.is_open() && rfile.good())
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
|
// lee el resto de datos del fichero
|
||||||
|
int index = 0;
|
||||||
|
int line_read = 0;
|
||||||
|
while (std::getline(rfile, buffer))
|
||||||
|
{
|
||||||
|
// Almacena solo las lineas impares
|
||||||
|
if (line_read % 2 == 1)
|
||||||
|
mTextStrings[index++] = buffer;
|
||||||
|
|
||||||
|
// Limpia el buffer
|
||||||
|
buffer.clear();
|
||||||
|
line_read++;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la cadena de texto del indice
|
||||||
|
std::string Lang::getText(int index)
|
||||||
|
{
|
||||||
|
return mTextStrings[index];
|
||||||
|
}
|
||||||
39
source/lang.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifndef LANG_H
|
||||||
|
#define LANG_H
|
||||||
|
|
||||||
|
// Códigos de idioma
|
||||||
|
#define es_ES 0
|
||||||
|
#define ba_BA 1
|
||||||
|
#define en_UK 2
|
||||||
|
#define MAX_LANGUAGES 3
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
#define MAX_TEXT_STRINGS 100
|
||||||
|
|
||||||
|
// Clase Lang
|
||||||
|
class Lang
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
std::string mTextStrings[MAX_TEXT_STRINGS]; // Vector con los textos
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Lang(Asset *mAsset);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Lang();
|
||||||
|
|
||||||
|
// Inicializa los textos del juego en el idioma seleccionado
|
||||||
|
bool setLang(Uint8 lang);
|
||||||
|
|
||||||
|
// Obtiene la cadena de texto del indice
|
||||||
|
std::string getText(int index);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
157
source/logo.cpp
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#include "logo.h"
|
||||||
|
|
||||||
|
#define INIT_FADE 100
|
||||||
|
#define END_LOGO 200
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||||
|
{
|
||||||
|
// Copia la dirección de los objetos
|
||||||
|
this->renderer = renderer;
|
||||||
|
this->screen = screen;
|
||||||
|
this->asset = asset;
|
||||||
|
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
eventHandler = new SDL_Event();
|
||||||
|
texture = new LTexture(renderer,asset->get("logo.png");
|
||||||
|
sprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, texture, renderer);
|
||||||
|
|
||||||
|
// Crea un backbuffer para el renderizador
|
||||||
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
if (backbuffer == nullptr)
|
||||||
|
{
|
||||||
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
counter = 0;
|
||||||
|
section.name = PROG_SECTION_LOGO;
|
||||||
|
section.subsection = 0;
|
||||||
|
ticks = 0;
|
||||||
|
ticksSpeed = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Logo::~Logo()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(backbuffer);
|
||||||
|
|
||||||
|
texture->unload();
|
||||||
|
delete texture;
|
||||||
|
|
||||||
|
delete sprite;
|
||||||
|
delete eventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
void Logo::checkLogoEnd()
|
||||||
|
{
|
||||||
|
if (counter == 0)
|
||||||
|
{
|
||||||
|
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
||||||
|
{
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter == END_LOGO + 20)
|
||||||
|
{
|
||||||
|
counter = 0;
|
||||||
|
section.name = PROG_SECTION_INTRO;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba los eventos
|
||||||
|
void Logo::checkEventHandler()
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que hay en la cola
|
||||||
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (eventHandler->type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
section.name = PROG_SECTION_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cualquier tecla pulsada
|
||||||
|
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
section.name = PROG_SECTION_TITLE;
|
||||||
|
section.subsection = TITLE_SECTION_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void Logo::renderFade()
|
||||||
|
{
|
||||||
|
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
|
const int fadeLenght = END_LOGO - INIT_FADE;
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
if (counter >= INIT_FADE)
|
||||||
|
{
|
||||||
|
const Uint16 alpha = (255 * (counter - INIT_FADE)) / fadeLenght;
|
||||||
|
if (alpha < 256)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
|
}
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables del objeto
|
||||||
|
void Logo::update()
|
||||||
|
{
|
||||||
|
checkEventHandler();
|
||||||
|
|
||||||
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
checkLogoEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el objeto en pantalla
|
||||||
|
void Logo::render()
|
||||||
|
{
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
screen->clean(bgColor);
|
||||||
|
|
||||||
|
// Dibuja los objetos
|
||||||
|
sprite->render();
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
renderFade();
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para el logo del juego
|
||||||
|
section_t Logo::run()
|
||||||
|
{
|
||||||
|
while (section.name == PROG_SECTION_LOGO)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
56
source/logo.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "asset.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#ifndef LOGO_H
|
||||||
|
#define LOGO_H
|
||||||
|
|
||||||
|
// Clase Logo
|
||||||
|
class Logo
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
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
|
||||||
|
LTexture *texture; // Textura con los graficos
|
||||||
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
|
Sprite *sprite; // Sprite con la textura del logo
|
||||||
|
int counter; // Contador
|
||||||
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
|
||||||
|
// Actualiza las variables del objeto
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja el objeto en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
void checkLogoEnd();
|
||||||
|
|
||||||
|
// Comprueba los eventos
|
||||||
|
void checkEventHandler();
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void renderFade();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Logo(SDL_Renderer *renderer, Screen *screen, Asset *mAsset);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Logo();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
section_t run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,30 +1,41 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string>
|
|
||||||
#include "const.h"
|
|
||||||
#include "ltexture.h"
|
#include "ltexture.h"
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
LTexture::LTexture()
|
// Constructor
|
||||||
|
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||||
{
|
{
|
||||||
// Initialize
|
// Copia punteros
|
||||||
mTexture = NULL;
|
this->renderer = renderer;
|
||||||
mWidth = 0;
|
this->path = path;
|
||||||
mHeight = 0;
|
|
||||||
|
// Inicializa
|
||||||
|
texture = nullptr;
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
|
||||||
|
// Carga el fichero en la textura
|
||||||
|
if (path != "")
|
||||||
|
{
|
||||||
|
loadFromFile(path, renderer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
LTexture::~LTexture()
|
LTexture::~LTexture()
|
||||||
{
|
{
|
||||||
// Deallocate
|
// Libera memoria
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga una imagen desde un fichero
|
||||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
int req_format = STBI_rgb_alpha;
|
int req_format = STBI_rgb_alpha;
|
||||||
int width, height, orig_format;
|
int width, height, orig_format;
|
||||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||||
if (data == NULL)
|
if (data == nullptr)
|
||||||
{
|
{
|
||||||
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -35,7 +46,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
|||||||
if (req_format == STBI_rgb)
|
if (req_format == STBI_rgb)
|
||||||
{
|
{
|
||||||
depth = 24;
|
depth = 24;
|
||||||
pitch = 3 * width; // 3 bytes per pixel * pixels per row
|
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -45,100 +56,99 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
|||||||
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get rid of preexisting texture
|
// Limpia
|
||||||
unload();
|
unload();
|
||||||
|
|
||||||
// The final texture
|
// La textura final
|
||||||
SDL_Texture *newTexture = NULL;
|
SDL_Texture *newTexture = nullptr;
|
||||||
|
|
||||||
// Load image at specified path
|
// Carga la imagen desde una ruta específica
|
||||||
//SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
|
||||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||||
if (loadedSurface == NULL)
|
if (loadedSurface == nullptr)
|
||||||
{
|
{
|
||||||
printf("Unable to load image %s!\n", path.c_str());
|
printf("Unable to load image %s!\n", path.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Color key image
|
// Crea la textura desde los pixels de la surface
|
||||||
//SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
|
||||||
|
|
||||||
// Create texture from surface pixels
|
|
||||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||||
if (newTexture == NULL)
|
if (newTexture == nullptr)
|
||||||
{
|
{
|
||||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Get image dimensions
|
// Obtiene las dimensiones de la imagen
|
||||||
mWidth = loadedSurface->w;
|
this->width = loadedSurface->w;
|
||||||
mHeight = loadedSurface->h;
|
this->height = loadedSurface->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get rid of old loaded surface
|
// Elimina la textura cargada
|
||||||
SDL_FreeSurface(loadedSurface);
|
SDL_FreeSurface(loadedSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return success
|
// Return success
|
||||||
mTexture = newTexture;
|
texture = newTexture;
|
||||||
return mTexture != NULL;
|
return texture != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Crea una textura en blanco
|
||||||
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||||
{
|
{
|
||||||
// Create uninitialized texture
|
// Crea una textura sin inicializar
|
||||||
mTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||||
if (mTexture == NULL)
|
if (texture == nullptr)
|
||||||
{
|
{
|
||||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mWidth = width;
|
this->width = width;
|
||||||
mHeight = height;
|
this->height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mTexture != NULL;
|
return texture != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Libera la memoria de la textura
|
||||||
void LTexture::unload()
|
void LTexture::unload()
|
||||||
{
|
{
|
||||||
// Free texture if it exists
|
// Libera la textura si existe
|
||||||
if (mTexture != NULL)
|
if (texture != nullptr)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(mTexture);
|
SDL_DestroyTexture(texture);
|
||||||
mTexture = NULL;
|
texture = nullptr;
|
||||||
mWidth = 0;
|
width = 0;
|
||||||
mHeight = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el color para la modulacion
|
||||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||||
{
|
{
|
||||||
// Modulate texture rgb
|
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||||
SDL_SetTextureColorMod(mTexture, red, green, blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el blending
|
||||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||||
{
|
{
|
||||||
// Set blending function
|
SDL_SetTextureBlendMode(texture, blending);
|
||||||
SDL_SetTextureBlendMode(mTexture, blending);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el alpha para la modulación
|
||||||
void LTexture::setAlpha(Uint8 alpha)
|
void LTexture::setAlpha(Uint8 alpha)
|
||||||
{
|
{
|
||||||
// Modulate texture alpha
|
SDL_SetTextureAlphaMod(texture, alpha);
|
||||||
SDL_SetTextureAlphaMod(mTexture, alpha);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renderiza la textura en un punto específico
|
||||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||||
{
|
{
|
||||||
// Set rendering space and render to screen
|
// Establece el destini de renderizado en la pantalla
|
||||||
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
SDL_Rect renderQuad = {x, y, width, height};
|
||||||
|
|
||||||
// Set clip rendering dimensions
|
// Obtiene las dimesiones del clip de renderizado
|
||||||
if (clip != NULL)
|
if (clip != nullptr)
|
||||||
{
|
{
|
||||||
renderQuad.w = clip->w;
|
renderQuad.w = clip->w;
|
||||||
renderQuad.h = clip->h;
|
renderQuad.h = clip->h;
|
||||||
@@ -147,22 +157,30 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
|
|||||||
renderQuad.w = renderQuad.w * zoomW;
|
renderQuad.w = renderQuad.w * zoomW;
|
||||||
renderQuad.h = renderQuad.h * zoomH;
|
renderQuad.h = renderQuad.h * zoomH;
|
||||||
|
|
||||||
// Render to screen
|
// Renderiza a pantalla
|
||||||
SDL_RenderCopyEx(renderer, mTexture, clip, &renderQuad, angle, center, flip);
|
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece la textura como objetivo de renderizado
|
||||||
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
// Make self render target
|
SDL_SetRenderTarget(renderer, texture);
|
||||||
SDL_SetRenderTarget(renderer, mTexture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene el ancho de la imagen
|
||||||
int LTexture::getWidth()
|
int LTexture::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene el alto de la imagen
|
||||||
int LTexture::getHeight()
|
int LTexture::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recarga la textura
|
||||||
|
bool LTexture::reLoad()
|
||||||
|
{
|
||||||
|
return loadFromFile(path, renderer);
|
||||||
}
|
}
|
||||||
@@ -1,66 +1,61 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef LTEXTURE_H
|
#ifndef LTEXTURE_H
|
||||||
#define LTEXTURE_H
|
#define LTEXTURE_H
|
||||||
|
|
||||||
// Texture wrapper class
|
// Clase LTexture
|
||||||
class LTexture
|
class LTexture
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
// Initializes variables
|
SDL_Texture *texture; // La textura
|
||||||
LTexture();
|
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||||
|
int width; // Ancho de la imagen
|
||||||
|
int height; // Alto de la imagen
|
||||||
|
std::string path; // Ruta de la imagen de la textura
|
||||||
|
|
||||||
// Deallocates memory
|
public:
|
||||||
|
// Constructor
|
||||||
|
LTexture(SDL_Renderer *renderer, std::string path = "");
|
||||||
|
|
||||||
|
// Destructor
|
||||||
~LTexture();
|
~LTexture();
|
||||||
|
|
||||||
// Loads image at specified path
|
// Carga una imagen desde un fichero
|
||||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Creates blank texture
|
// Crea una textura en blanco
|
||||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||||
|
|
||||||
// Deallocates texture
|
// Libera la memoria de la textura
|
||||||
void unload();
|
void unload();
|
||||||
|
|
||||||
// Set color modulation
|
// Establece el color para la modulacion
|
||||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||||
|
|
||||||
// Set blending
|
// Establece el blending
|
||||||
void setBlendMode(SDL_BlendMode blending);
|
void setBlendMode(SDL_BlendMode blending);
|
||||||
|
|
||||||
// Set alpha modulation
|
// Establece el alpha para la modulación
|
||||||
void setAlpha(Uint8 alpha);
|
void setAlpha(Uint8 alpha);
|
||||||
|
|
||||||
// Renders texture at given point
|
// Renderiza la textura en un punto específico
|
||||||
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = NULL, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
||||||
|
|
||||||
// Set self as render target
|
// Establece la textura como objetivo de renderizado
|
||||||
void setAsRenderTarget(SDL_Renderer *renderer);
|
void setAsRenderTarget(SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Gets image dimensions
|
// Obtiene el ancho de la imagen
|
||||||
int getWidth();
|
int getWidth();
|
||||||
|
|
||||||
|
// Obtiene el alto de la imagen
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
// Pixel manipulators
|
// Recarga la textura
|
||||||
bool lockTexture();
|
bool reLoad();
|
||||||
bool unlockTexture();
|
|
||||||
void *getPixels();
|
|
||||||
void copyPixels(void *pixels);
|
|
||||||
int getPitch();
|
|
||||||
Uint32 getPixel32(unsigned int x, unsigned int y);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// The actual hardware texture
|
|
||||||
SDL_Texture *mTexture;
|
|
||||||
void *mPixels;
|
|
||||||
int mPitch;
|
|
||||||
|
|
||||||
// Image dimensions
|
|
||||||
int mWidth;
|
|
||||||
int mHeight;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source code copyrighted by JailDesigner (2020)
|
Código fuente creado por JailDesigner (2020)
|
||||||
started on Castalla 15-07-2020.
|
Empezado en Castalla el 15/07/2020.
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Descripción del enfoque utilizado para crear el juego.
|
Descripción del enfoque utilizado para crear el juego.
|
||||||
|
|
||||||
El programa contine una serie de clases/objetos básicos: la clase sprite
|
El programa contine una serie de clases/objetos básicos: la clase sprite
|
||||||
@@ -17,11 +15,11 @@ A continuación tenemos las clases enfocadas a la lógica del juego, la clase pl
|
|||||||
contiene la información del jugador, la clase balloon la de los enemigos y la
|
contiene la información del jugador, la clase balloon la de los enemigos y la
|
||||||
clase bullet para las balas que dispara el jugador. La clase background es
|
clase bullet para las balas que dispara el jugador. La clase background es
|
||||||
muy simple y sirve para pintar el fondo de la pantalla. Por ultimo, la clase
|
muy simple y sirve para pintar el fondo de la pantalla. Por ultimo, la clase
|
||||||
gamedirector es la que realiza toda la lógica y se encarga de hacer interactuar
|
mDirector es la que realiza toda la lógica y se encarga de hacer interactuar
|
||||||
al resto de objetos entre si.
|
al resto de objetos entre si.
|
||||||
|
|
||||||
El objeto gamedirector tiene tres estados: titulo, juego y pausa. Segun su estado
|
El objeto mDirector tiene tres estados: titulo, juego y pausa. Segun su estado
|
||||||
el bucle que recorre es distinto. En el bucle juego, el objeto gamedirector
|
el bucle que recorre es distinto. En el bucle juego, el objeto mDirector
|
||||||
tiene un objeto jugador, un vector con los objetos globo y un vector con los
|
tiene un objeto jugador, un vector con los objetos globo y un vector con los
|
||||||
objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
||||||
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
||||||
@@ -36,46 +34,24 @@ En los vectores que contienen objetos, se considera activos los objetos que tien
|
|||||||
un tipo asociado diferente a NO_KIND
|
un tipo asociado diferente a NO_KIND
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ifdefs.h"
|
#include "director.h"
|
||||||
#include "const.h"
|
|
||||||
#include "gamedirector.h"
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
int main(int argc, char *args[])
|
int main(int argc, char *args[])
|
||||||
{
|
{
|
||||||
// Inicia el generador de numeros aleatorios
|
|
||||||
srand(time(nullptr));
|
|
||||||
|
|
||||||
// Crea el objeto gameDirector
|
|
||||||
GameDirector *gameDirector = new GameDirector(args[0]);
|
|
||||||
printf("Starting the game...\n\n");
|
printf("Starting the game...\n\n");
|
||||||
|
|
||||||
// Mientras no se quiera salir del juego
|
// Crea el objeto Director
|
||||||
while (!(gameDirector->exit()))
|
Director *mDirector = new Director(args[0]);
|
||||||
{
|
|
||||||
switch (gameDirector->getProgSection())
|
|
||||||
{
|
|
||||||
case PROG_SECTION_LOGO:
|
|
||||||
gameDirector->runLogo();
|
|
||||||
break;
|
|
||||||
case PROG_SECTION_INTRO:
|
|
||||||
gameDirector->runIntro();
|
|
||||||
break;
|
|
||||||
case PROG_SECTION_TITLE:
|
|
||||||
gameDirector->runTitle(gameDirector->getSubsection());
|
|
||||||
break;
|
|
||||||
case PROG_SECTION_GAME:
|
|
||||||
gameDirector->runGame();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Libera todos los recursos y cierra SDL
|
// Bucle principal
|
||||||
delete gameDirector;
|
mDirector->run();
|
||||||
gameDirector = nullptr;
|
|
||||||
printf("Shutting down the game...\n");
|
// Destruye el objeto Director
|
||||||
|
delete mDirector;
|
||||||
|
mDirector = nullptr;
|
||||||
|
|
||||||
|
printf("\nShutting down the game...\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
1020
source/menu.cpp
334
source/menu.h
@@ -1,71 +1,112 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <vector>
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "asset.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#ifndef MENU_H
|
#ifndef MENU_H
|
||||||
#define MENU_H
|
#define MENU_H
|
||||||
|
|
||||||
// Clase menu
|
// Tipos de fondos para el menu
|
||||||
|
#define MENU_BACKGROUND_TRANSPARENT 0
|
||||||
|
#define MENU_BACKGROUND_SOLID 1
|
||||||
|
|
||||||
|
// Tipos de archivos de audio
|
||||||
|
#define SOUND_ACCEPT 0
|
||||||
|
#define SOUND_MOVE 1
|
||||||
|
#define SOUND_CANCEL 2
|
||||||
|
|
||||||
|
// Opciones de menu
|
||||||
|
#define MENU_NO_OPTION -1
|
||||||
|
|
||||||
|
// Clase Menu
|
||||||
class Menu
|
class Menu
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Menu();
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Menu();
|
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void init(std::string name, int x, int y, int backgroundType, LTexture *texture, SDL_Renderer *renderer, Text *text);
|
|
||||||
|
|
||||||
// Obtiene el nombre del menu
|
|
||||||
std::string getName();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getItemSelected();
|
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
// Deja el menu sin elemento seleccionado
|
|
||||||
void deselectItem();
|
|
||||||
|
|
||||||
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
|
||||||
bool checkInput(Uint8 input);
|
|
||||||
|
|
||||||
// Actualiza la logica del menu
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Pinta el menu en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Establece el color del rectangulo de fondo
|
|
||||||
void setBackgroundColor(int r, int g, int b, int alpha);
|
|
||||||
|
|
||||||
// Establece el color del rectangulo del selector
|
|
||||||
void setSelectorColor(int r, int g, int b, int alpha);
|
|
||||||
|
|
||||||
// Establece el color del texto del selector
|
|
||||||
void setSelectorTextColor(int r, int g, int b);
|
|
||||||
|
|
||||||
// Centra el menu respecto a un punto
|
|
||||||
void centerMenu(int value);
|
|
||||||
|
|
||||||
// Centra los elementos del menu
|
|
||||||
void centerMenuElements();
|
|
||||||
|
|
||||||
// Añade un item al menu
|
|
||||||
void addItem(std::string text, const Uint8 hPaddingUp = 0, const Uint8 hPaddingDown = 0);
|
|
||||||
|
|
||||||
// Cambia el texto de un item
|
|
||||||
void setItemCaption(Uint8 index, std::string text);
|
|
||||||
|
|
||||||
// Establece el indice del item que se usará por defecto al cancelar el menu
|
|
||||||
void setDefaultActionWhenCancel(Uint8 item);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Establece el valor de la variable
|
struct rectangle_t
|
||||||
void setTotalItems(int num);
|
{
|
||||||
|
SDL_Rect rect; // Rectangulo
|
||||||
|
color_t color; // Color
|
||||||
|
int a; // Transparencia
|
||||||
|
};
|
||||||
|
|
||||||
|
struct item_t
|
||||||
|
{
|
||||||
|
std::string label; // Texto
|
||||||
|
SDL_Rect rect; // Rectangulo que delimita el elemento
|
||||||
|
int hPaddingDown; // Espaciado bajo el elemento
|
||||||
|
bool selectable; // Indica si se puede seleccionar
|
||||||
|
bool greyed; // Indica si ha de aparecer con otro color mas oscuro
|
||||||
|
bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector
|
||||||
|
bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector
|
||||||
|
};
|
||||||
|
|
||||||
|
struct selector_t
|
||||||
|
{
|
||||||
|
float originY; // Coordenada de origen
|
||||||
|
float targetY; // Coordenada de destino
|
||||||
|
float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps
|
||||||
|
bool moving; // Indica si el selector está avanzando hacia el destino
|
||||||
|
float originH; // Altura de origen
|
||||||
|
float targetH; // Altura de destino
|
||||||
|
float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto
|
||||||
|
bool resizing; // Indica si el selector está cambiando de tamaño
|
||||||
|
float y; // Coordenada actual, usado para el desplazamiento
|
||||||
|
float h; // Altura actual, usado para el cambio de tamaño
|
||||||
|
int numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||||
|
int index; // Elemento del menu que tiene el foco
|
||||||
|
SDL_Rect rect; // Rectangulo del selector
|
||||||
|
color_t color; // Color del selector
|
||||||
|
color_t itemColor; // Color del item
|
||||||
|
int a; // Cantidad de transparencia para el rectangulo del selector
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string name; // Nombre del menu
|
||||||
|
int x; // Posición en el eje X de la primera letra del primer elemento
|
||||||
|
int y; // Posición en el eje Y de la primera letra del primer elemento
|
||||||
|
int h; // Altura del menu
|
||||||
|
int w; // Anchura del menu
|
||||||
|
int itemSelected; // Índice del item del menu que ha sido seleccionado
|
||||||
|
int defaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu
|
||||||
|
int backgroundType; // Tipo de fondo para el menu
|
||||||
|
int centerX; // Centro del menu en el eje X
|
||||||
|
int centerY; // Centro del menu en el eje Y
|
||||||
|
bool isCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X
|
||||||
|
bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
|
||||||
|
bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
|
||||||
|
int widestItem; // Anchura del elemento más ancho
|
||||||
|
JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
|
||||||
|
JA_Sound soundCancel; // Sonido al cancelar el menu
|
||||||
|
JA_Sound soundMove; // Sonido al mover el selector
|
||||||
|
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||||
|
Text *text; // Texto para poder escribir los items del menu
|
||||||
|
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
||||||
|
Asset *asset; // Objeto para gestionar los ficheros de recursos
|
||||||
|
color_t colorGreyed; // Color para los elementos agrisados
|
||||||
|
rectangle_t rectBG; // Rectangulo de fondo del menu
|
||||||
|
std::vector<item_t> item; // Estructura para cada elemento del menu
|
||||||
|
selector_t selector; // Variables para pintar el selector del menu
|
||||||
|
std::string font_png;
|
||||||
|
std::string font_txt;
|
||||||
|
|
||||||
|
// Carga la configuración del menu desde un archivo de texto
|
||||||
|
bool load(std::string file_path);
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool setVars(std::string var, std::string value);
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool setItem(item_t *item, std::string var, std::string value);
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu
|
// Establece el rectangulo de fondo del menu
|
||||||
void setRectSize();
|
void setRectSize();
|
||||||
@@ -79,112 +120,105 @@ private:
|
|||||||
// Deja el menu apuntando al elemento anterior
|
// Deja el menu apuntando al elemento anterior
|
||||||
bool decreaseSelectorIndex();
|
bool decreaseSelectorIndex();
|
||||||
|
|
||||||
// Mueve el grafico del selector al elemento seleccionado
|
|
||||||
//void moveSelectorSprite(int pos);
|
|
||||||
|
|
||||||
// Actualiza la posicion y el estado del selector
|
// Actualiza la posicion y el estado del selector
|
||||||
void updateSelector();
|
void updateSelector();
|
||||||
|
|
||||||
// Establece el origen del selector
|
// Obtiene la anchura del elemento más ancho del menu
|
||||||
void setSelectorOrigin(int value);
|
int getWidestItem();
|
||||||
|
|
||||||
// Establece el destino del selector
|
// Gestiona la entrada de teclado y mando durante el menu
|
||||||
void setSelectorTarget(int value);
|
void checkMenuInput(Menu *menu);
|
||||||
|
|
||||||
|
// Calcula el ancho del menu
|
||||||
|
int findWidth();
|
||||||
|
|
||||||
|
// Calcula el alto del menu
|
||||||
|
int findHeight();
|
||||||
|
|
||||||
|
// Recoloca los elementos del menu en el eje Y
|
||||||
|
void replaceElementsOnY();
|
||||||
|
|
||||||
|
// Calcula la altura del selector
|
||||||
|
int getSelectorHeight(int value);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file="");
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Menu();
|
||||||
|
|
||||||
|
// Carga los ficheros de audio
|
||||||
|
void loadAudioFile(std::string file, int sound);
|
||||||
|
|
||||||
|
// Obtiene el nombre del menu
|
||||||
|
std::string getName();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getItemSelected();
|
||||||
|
|
||||||
|
// Deja el menu apuntando al primer elemento
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// Gestiona la entrada de teclado y mando durante el menu
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
|
// Actualiza la logica del menu
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Pinta el menu en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Establece el color del rectangulo de fondo
|
||||||
|
void setBackgroundColor(color_t color, int alpha);
|
||||||
|
|
||||||
|
// Establece el color del rectangulo del selector
|
||||||
|
void setSelectorColor(color_t color, int alpha);
|
||||||
|
|
||||||
|
// Establece el color del texto del selector
|
||||||
|
void setSelectorTextColor(color_t color);
|
||||||
|
|
||||||
|
// Centra el menu respecto a un punto en el eje X
|
||||||
|
void centerMenuOnX(int value);
|
||||||
|
|
||||||
|
// Centra el menu respecto a un punto en el eje Y
|
||||||
|
void centerMenuOnY(int value);
|
||||||
|
|
||||||
|
// Centra los elementos del menu en el eje X
|
||||||
|
void centerMenuElementsOnX();
|
||||||
|
|
||||||
|
// Añade un item al menu
|
||||||
|
void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
||||||
|
|
||||||
|
// Cambia el texto de un item
|
||||||
|
void setItemCaption(int index, std::string text);
|
||||||
|
|
||||||
|
// Establece el indice del item que se usará por defecto al cancelar el menu
|
||||||
|
void setDefaultActionWhenCancel(int item);
|
||||||
|
|
||||||
// Coloca el selector en una posición específica
|
// Coloca el selector en una posición específica
|
||||||
void setSelectorPos(Uint8 index);
|
void setSelectorPos(int index);
|
||||||
|
|
||||||
// Obtiene la anchura del elemento más ancho del menu
|
// Establece el estado seleccionable de un item
|
||||||
Uint16 getWidestItem();
|
void setSelectable(int index, bool value);
|
||||||
|
|
||||||
// Posicion X/Y del texto del primer elemento del menu
|
// Establece el estado agrisado de un item
|
||||||
int mPosX; // En esta posición se pinta la primera letra del primer elemento
|
void setGreyed(int index, bool value);
|
||||||
int mPosY;
|
|
||||||
|
|
||||||
// Nombre del menu
|
// Establece el estado de enlace de un item
|
||||||
std::string mName;
|
void setLinkedDown(int index, bool value);
|
||||||
|
|
||||||
// Numero de items del menu
|
// Establece el nombre del menu
|
||||||
Uint8 mTotalItems;
|
void setName(std::string name);
|
||||||
|
|
||||||
// Item del menu que ha sido seleccionado
|
// Establece la posición del menu
|
||||||
Uint8 mItemSelected;
|
void setPos(int x, int y);
|
||||||
|
|
||||||
// Item del menu seleccionado cuando se cancela el menu
|
// Establece el tipo de fondo del menu
|
||||||
Uint8 mDefaultActionWhenCancel;
|
void setBackgroundType(int value);
|
||||||
|
|
||||||
// Espacio de separacion entre items
|
|
||||||
Uint8 mVerticalPadding;
|
|
||||||
|
|
||||||
// Tipo de fondo para el menu
|
// hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo
|
||||||
Uint8 mBackgroundType;
|
|
||||||
|
|
||||||
// Sprite con los graficos del selector
|
|
||||||
//Sprite mSelectorSprite;
|
|
||||||
|
|
||||||
struct rectangle
|
|
||||||
{
|
|
||||||
SDL_Rect rect;
|
|
||||||
Uint8 r; // Rojo
|
|
||||||
Uint8 g; // Verde
|
|
||||||
Uint8 b; // Azul
|
|
||||||
Uint8 a; // Transparencia
|
|
||||||
};
|
|
||||||
|
|
||||||
rectangle mRectBG; // Rectangulo de fondo del menu
|
|
||||||
|
|
||||||
// Estructura para cada elemento del menu
|
|
||||||
struct item
|
|
||||||
{
|
|
||||||
std::string label;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
Uint8 w;
|
|
||||||
Uint8 h;
|
|
||||||
Uint8 hPaddingUp;
|
|
||||||
Uint8 hPaddingDown;
|
|
||||||
};
|
|
||||||
|
|
||||||
item mItem[10];
|
|
||||||
|
|
||||||
// Texto para poder escribir los items del menu
|
|
||||||
Text *mText;
|
|
||||||
|
|
||||||
// Puntero al renderizador de la ventana
|
|
||||||
SDL_Renderer *mRenderer;
|
|
||||||
|
|
||||||
// Variable para saber si el menu debe estar centrado respecto a un punto
|
|
||||||
bool mIsCentered;
|
|
||||||
|
|
||||||
// Centro del menu
|
|
||||||
int mCenter;
|
|
||||||
|
|
||||||
// Variable para saber si los elementos van centrados
|
|
||||||
bool mAreElementsCentered;
|
|
||||||
|
|
||||||
// Anchura del elemento más ancho
|
|
||||||
Uint16 mWidestItem;
|
|
||||||
|
|
||||||
struct selector
|
|
||||||
{
|
|
||||||
double origin; // Coordenada de origen
|
|
||||||
double target; // Coordenada de destino
|
|
||||||
double y; // Coordenada actual
|
|
||||||
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino
|
|
||||||
double despY; // (target - origin) / numJumps
|
|
||||||
bool moving; // Indica si el selector está avanzando hacia el destino
|
|
||||||
Uint8 index; // Elemento del menu que tiene el foco
|
|
||||||
SDL_Rect rect;
|
|
||||||
Uint8 r; // Rojo
|
|
||||||
Uint8 g; // Verde
|
|
||||||
Uint8 b; // Azul
|
|
||||||
Uint8 a; // Transparencia
|
|
||||||
Uint8 itemR; // Rojo
|
|
||||||
Uint8 itemG; // Verde
|
|
||||||
Uint8 itemB; // Azul
|
|
||||||
};
|
|
||||||
|
|
||||||
selector mSelector;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,161 +1,365 @@
|
|||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite::MovingSprite()
|
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
// Copia los punteros
|
||||||
}
|
this->texture = texture;
|
||||||
|
this->renderer = renderer;
|
||||||
|
|
||||||
|
// Establece el alto y el ancho del sprite
|
||||||
|
this->w = w;
|
||||||
|
this->h = h;
|
||||||
|
|
||||||
|
// Establece la posición X,Y del sprite
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
xPrev = x;
|
||||||
|
yPrev = y;
|
||||||
|
|
||||||
|
// Establece la velocidad X,Y del sprite
|
||||||
|
vx = velx;
|
||||||
|
vy = vely;
|
||||||
|
|
||||||
|
// Establece la aceleración X,Y del sprite
|
||||||
|
ax = accelx;
|
||||||
|
ay = accely;
|
||||||
|
|
||||||
|
// Establece el zoom W,H del sprite
|
||||||
|
zoomW = 1;
|
||||||
|
zoomH = 1;
|
||||||
|
|
||||||
|
// Establece el angulo con el que se dibujará
|
||||||
|
angle = (double)0;
|
||||||
|
|
||||||
|
// Establece los valores de rotacion
|
||||||
|
rotateEnabled = false;
|
||||||
|
rotateSpeed = 0;
|
||||||
|
rotateAmount = (double)0;
|
||||||
|
|
||||||
|
// Contador interno
|
||||||
|
counter = 0;
|
||||||
|
|
||||||
|
// Establece el rectangulo de donde coger la imagen
|
||||||
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
|
// Establece el centro de rotación
|
||||||
|
center = {0, 0};
|
||||||
|
|
||||||
|
// Establece el tipo de volteado
|
||||||
|
currentFlip = SDL_FLIP_NONE;
|
||||||
|
};
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
MovingSprite::~MovingSprite()
|
MovingSprite::~MovingSprite()
|
||||||
{
|
{
|
||||||
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Reinicia todas las variables
|
||||||
void MovingSprite::init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
void MovingSprite::clear()
|
||||||
{
|
{
|
||||||
// Establece el alto y el ancho del sprite
|
x = 0.0f; // Posición en el eje X
|
||||||
setWidth(w);
|
y = 0.0f; // Posición en el eje Y
|
||||||
setHeight(h);
|
|
||||||
|
|
||||||
// Establece la posición X,Y del sprite
|
vx = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||||
setPosX(x);
|
vy = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||||
setPosY(y);
|
|
||||||
|
|
||||||
// Establece la velocidad X,Y del sprite
|
ax = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||||
setVelX(velx);
|
ay = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||||
setVelY(vely);
|
|
||||||
|
|
||||||
// Establece la aceleración X,Y del sprite
|
zoomW = 1.0f; // Zoom aplicado a la anchura
|
||||||
setAccelX(accelx);
|
zoomH = 1.0f; // Zoom aplicado a la altura
|
||||||
setAccelY(accely);
|
|
||||||
|
|
||||||
// Establece el zoom W,H del sprite
|
angle = 0.0; // Angulo para dibujarlo
|
||||||
setZoomW(1);
|
rotateEnabled = false; // Indica si ha de rotar
|
||||||
setZoomH(1);
|
center = {0, 0}; // Centro de rotación
|
||||||
|
rotateSpeed = 0; // Velocidad de giro
|
||||||
|
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||||
|
counter = 0; // Contador interno
|
||||||
|
|
||||||
// Establece la textura donde están los gráficos para el sprite
|
currentFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||||
setTexture(texture);
|
|
||||||
|
|
||||||
// Establece el renderizador
|
|
||||||
setRenderer(renderer);
|
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
|
||||||
setSpriteClip(0, 0, w, h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el sprite
|
// Mueve el sprite
|
||||||
void MovingSprite::move()
|
void MovingSprite::move()
|
||||||
{
|
{
|
||||||
mPosX += mVelX;
|
if (enabled)
|
||||||
mPosY += mVelY;
|
{
|
||||||
|
xPrev = x;
|
||||||
|
yPrev = y;
|
||||||
|
|
||||||
mVelX += mAccelX;
|
x += vx;
|
||||||
mVelY += mAccelY;
|
y += vy;
|
||||||
|
|
||||||
|
vx += ax;
|
||||||
|
vy += ay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void MovingSprite::render()
|
void MovingSprite::render()
|
||||||
{
|
{
|
||||||
//mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip);
|
if (enabled)
|
||||||
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH);
|
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, ¢er, currentFlip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getPosX()
|
float MovingSprite::getPosX()
|
||||||
{
|
{
|
||||||
return mPosX;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getPosY()
|
float MovingSprite::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getVelX()
|
float MovingSprite::getVelX()
|
||||||
{
|
{
|
||||||
return mVelX;
|
return vx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getVelY()
|
float MovingSprite::getVelY()
|
||||||
{
|
{
|
||||||
return mVelY;
|
return vy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getAccelX()
|
float MovingSprite::getAccelX()
|
||||||
{
|
{
|
||||||
return mAccelX;
|
return ax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getAccelY()
|
float MovingSprite::getAccelY()
|
||||||
{
|
{
|
||||||
return mAccelY;
|
return ay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getZoomW()
|
float MovingSprite::getZoomW()
|
||||||
{
|
{
|
||||||
return mZoomW;
|
return zoomW;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float MovingSprite::getZoomH()
|
float MovingSprite::getZoomH()
|
||||||
{
|
{
|
||||||
return mZoomH;
|
return zoomH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
double MovingSprite::getAngle()
|
||||||
|
{
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la posición del objeto
|
||||||
|
void MovingSprite::setPos(SDL_Rect rect)
|
||||||
|
{
|
||||||
|
x = (float)rect.x;
|
||||||
|
y = (float)rect.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setPosX(float x)
|
void MovingSprite::setPosX(float value)
|
||||||
{
|
{
|
||||||
mPosX = x;
|
x = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setPosY(float y)
|
void MovingSprite::setPosY(float value)
|
||||||
{
|
{
|
||||||
mPosY = y;
|
y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setVelX(float x)
|
void MovingSprite::setVelX(float value)
|
||||||
{
|
{
|
||||||
mVelX = x;
|
vx = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setVelY(float y)
|
void MovingSprite::setVelY(float value)
|
||||||
{
|
{
|
||||||
mVelY = y;
|
vy = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setAccelX(float x)
|
void MovingSprite::setAccelX(float value)
|
||||||
{
|
{
|
||||||
mAccelX = x;
|
ax = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setAccelY(float y)
|
void MovingSprite::setAccelY(float value)
|
||||||
{
|
{
|
||||||
mAccelY = y;
|
ay = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setZoomW(float w)
|
void MovingSprite::setZoomW(float value)
|
||||||
{
|
{
|
||||||
mZoomW = w;
|
zoomW = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setZoomH(float h)
|
void MovingSprite::setZoomH(float value)
|
||||||
{
|
{
|
||||||
mZoomH = h;
|
zoomH = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setAngle(double value)
|
||||||
|
{
|
||||||
|
angle = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incrementa el valor de la variable
|
||||||
|
void MovingSprite::incAngle(double value)
|
||||||
|
{
|
||||||
|
angle += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrementa el valor de la variable
|
||||||
|
void MovingSprite::decAngle(double value)
|
||||||
|
{
|
||||||
|
angle -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool MovingSprite::getRotate()
|
||||||
|
{
|
||||||
|
return rotateEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 MovingSprite::getRotateSpeed()
|
||||||
|
{
|
||||||
|
return rotateSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la rotacion
|
||||||
|
void MovingSprite::rotate()
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
if (rotateEnabled)
|
||||||
|
{
|
||||||
|
if (counter % rotateSpeed == 0)
|
||||||
|
{
|
||||||
|
incAngle(rotateAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setRotate(bool value)
|
||||||
|
{
|
||||||
|
rotateEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setRotateSpeed(int value)
|
||||||
|
{
|
||||||
|
rotateSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setRotateAmount(double value)
|
||||||
|
{
|
||||||
|
rotateAmount = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::disableRotate()
|
||||||
|
{
|
||||||
|
rotateEnabled = false;
|
||||||
|
angle = (double)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables internas del objeto
|
||||||
|
void MovingSprite::update()
|
||||||
|
{
|
||||||
|
move();
|
||||||
|
rotate();
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
++counter %= 60000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el sentido de la rotación
|
||||||
|
void MovingSprite::switchRotate()
|
||||||
|
{
|
||||||
|
rotateAmount *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||||
|
{
|
||||||
|
currentFlip = flip;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gira el sprite horizontalmente
|
||||||
|
void MovingSprite::flip()
|
||||||
|
{
|
||||||
|
currentFlip = (currentFlip == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
SDL_RendererFlip MovingSprite::getFlip()
|
||||||
|
{
|
||||||
|
return currentFlip;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el rectangulo donde está el sprite
|
||||||
|
SDL_Rect MovingSprite::getRect()
|
||||||
|
{
|
||||||
|
const SDL_Rect rect = {(int)x, (int)y, w, h};
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece los valores de posición y tamaño del sprite
|
||||||
|
void MovingSprite::setRect(SDL_Rect rect)
|
||||||
|
{
|
||||||
|
x = (float)rect.x;
|
||||||
|
y = (float)rect.y;
|
||||||
|
w = rect.w;
|
||||||
|
h = rect.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deshace el último movimiento
|
||||||
|
void MovingSprite::undoMove()
|
||||||
|
{
|
||||||
|
x = xPrev;
|
||||||
|
y = yPrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deshace el último movimiento en el eje X
|
||||||
|
void MovingSprite::undoMoveX()
|
||||||
|
{
|
||||||
|
x = xPrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deshace el último movimiento en el eje Y
|
||||||
|
void MovingSprite::undoMoveY()
|
||||||
|
{
|
||||||
|
y = yPrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone a cero las velocidades de desplacamiento
|
||||||
|
void MovingSprite::clearVel()
|
||||||
|
{
|
||||||
|
vx = vy = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el incremento en el eje X en pixels
|
||||||
|
int MovingSprite::getIncX()
|
||||||
|
{
|
||||||
|
return (int)x - (int)xPrev;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
#ifndef MOVINGSPRITE_H
|
#ifndef MOVINGSPRITE_H
|
||||||
@@ -8,32 +9,49 @@
|
|||||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||||
class MovingSprite : public Sprite
|
class MovingSprite : public Sprite
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
float mPosX; // Posición en el eje X
|
float x; // Posición en el eje X
|
||||||
float mPosY; // Posición en el eje Y
|
float y; // Posición en el eje Y
|
||||||
|
|
||||||
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
float xPrev; // Posición anterior en el eje X
|
||||||
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
float yPrev; // Posición anterior en el eje Y
|
||||||
|
|
||||||
float mAccelX; // Aceleración en el eje X. Variación de la velocidad
|
float vx; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||||
float mAccelY; // Aceleración en el eje Y. Variación de la velocidad
|
float vy; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||||
|
|
||||||
float mZoomW; // Zoom aplicado a la anchura
|
float ax; // Aceleración en el eje X. Variación de la velocidad
|
||||||
float mZoomH; // Zoom aplicado a la altura
|
float ay; // Aceleración en el eje Y. Variación de la velocidad
|
||||||
|
|
||||||
|
float zoomW; // Zoom aplicado a la anchura
|
||||||
|
float zoomH; // Zoom aplicado a la altura
|
||||||
|
|
||||||
|
double angle; // Angulo para dibujarlo
|
||||||
|
bool rotateEnabled; // Indica si ha de rotar
|
||||||
|
int rotateSpeed; // Velocidad de giro
|
||||||
|
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||||
|
int counter; // Contador interno
|
||||||
|
SDL_Point center; // Centro de rotación
|
||||||
|
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite();
|
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~MovingSprite();
|
~MovingSprite();
|
||||||
|
|
||||||
// Iniciador
|
|
||||||
void init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer);
|
|
||||||
|
|
||||||
// Mueve el sprite
|
// Mueve el sprite
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
|
// Rota el sprite
|
||||||
|
void rotate();
|
||||||
|
|
||||||
|
// Actualiza las variables internas del objeto
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Reinicia todas las variables
|
||||||
|
void clear();
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
@@ -61,29 +79,95 @@ public:
|
|||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
float getZoomH();
|
float getZoomH();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Obten el valor de la variable
|
||||||
void setPosX(float x);
|
double getAngle();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool getRotate();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 getRotateSpeed();
|
||||||
|
|
||||||
|
// Establece la posición del objeto
|
||||||
|
void setPos(SDL_Rect rect);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosY(float y);
|
void setPosX(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVelX(float x);
|
void setPosY(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVelY(float y);
|
void setVelX(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAccelX(float x);
|
void setVelY(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAccelY(float y);
|
void setAccelX(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setZoomW(float w);
|
void setAccelY(float value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setZoomH(float h);
|
void setZoomW(float value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setZoomH(float value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setAngle(double vaue);
|
||||||
|
|
||||||
|
// Incrementa el valor de la variable
|
||||||
|
void incAngle(double value);
|
||||||
|
|
||||||
|
// Decrementa el valor de la variable
|
||||||
|
void decAngle(double value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setRotate(bool value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setRotateSpeed(int value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setRotateAmount(double value);
|
||||||
|
|
||||||
|
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
|
||||||
|
void disableRotate();
|
||||||
|
|
||||||
|
// Cambia el sentido de la rotación
|
||||||
|
void switchRotate();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setFlip(SDL_RendererFlip flip);
|
||||||
|
|
||||||
|
// Gira el sprite horizontalmente
|
||||||
|
void flip();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
SDL_RendererFlip getFlip();
|
||||||
|
|
||||||
|
// Devuelve el rectangulo donde está el sprite
|
||||||
|
SDL_Rect getRect();
|
||||||
|
|
||||||
|
// Establece los valores de posición y tamaño del sprite
|
||||||
|
void setRect(SDL_Rect rect);
|
||||||
|
|
||||||
|
// Deshace el último movimiento
|
||||||
|
void undoMove();
|
||||||
|
|
||||||
|
// Deshace el último movimiento en el eje X
|
||||||
|
void undoMoveX();
|
||||||
|
|
||||||
|
// Deshace el último movimiento en el eje Y
|
||||||
|
void undoMoveY();
|
||||||
|
|
||||||
|
// Pone a cero las velocidades de desplacamiento
|
||||||
|
void clearVel();
|
||||||
|
|
||||||
|
// Devuelve el incremento en el eje X en pixels
|
||||||
|
int getIncX();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,29 +7,38 @@ Player::Player()
|
|||||||
mSpriteLegs = new AnimatedSprite();
|
mSpriteLegs = new AnimatedSprite();
|
||||||
mSpriteBody = new AnimatedSprite();
|
mSpriteBody = new AnimatedSprite();
|
||||||
mSpriteHead = new AnimatedSprite();
|
mSpriteHead = new AnimatedSprite();
|
||||||
init(0, 0, nullptr, nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
init(0, 0, nullptr, nullptr, nullptr);
|
|
||||||
mSpriteLegs = nullptr;
|
|
||||||
mSpriteBody = nullptr;
|
|
||||||
delete mSpriteLegs;
|
delete mSpriteLegs;
|
||||||
|
mSpriteLegs = nullptr;
|
||||||
|
|
||||||
delete mSpriteBody;
|
delete mSpriteBody;
|
||||||
|
mSpriteBody = nullptr;
|
||||||
|
|
||||||
delete mSpriteHead;
|
delete mSpriteHead;
|
||||||
|
mSpriteHead = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer)
|
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
// Copia punteros
|
||||||
|
mPlayerDeadTexture = textureDead;
|
||||||
|
|
||||||
// Inicializa variables de estado
|
// Inicializa variables de estado
|
||||||
mAlive = true;
|
mAlive = true;
|
||||||
|
mDeathCounter = DEATH_COUNTER;
|
||||||
|
mDeathIndex = 0;
|
||||||
mStatusWalking = PLAYER_STATUS_WALKING_STOP;
|
mStatusWalking = PLAYER_STATUS_WALKING_STOP;
|
||||||
mStatusFiring = PLAYER_STATUS_FIRING_NO;
|
mStatusFiring = PLAYER_STATUS_FIRING_NO;
|
||||||
mInvulnerable = false;
|
mInvulnerable = false;
|
||||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||||
|
mPowerUp = false;
|
||||||
|
mPowerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||||
|
mPowerUpHeadOffset = 0;
|
||||||
mExtraHit = false;
|
mExtraHit = false;
|
||||||
mCoffees = 0;
|
mCoffees = 0;
|
||||||
mInput = true;
|
mInput = true;
|
||||||
@@ -65,8 +74,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mCooldown = 10;
|
mCooldown = 10;
|
||||||
|
|
||||||
// Inicia el sprite
|
// Inicia el sprite
|
||||||
mSpriteLegs->init(textureLegs, renderer);
|
mSpriteLegs->init();
|
||||||
mSpriteBody->init(textureBody, renderer);
|
mSpriteBody->init(textureBody, renderer);
|
||||||
|
mSpriteHead->init(textureHead, renderer);
|
||||||
|
|
||||||
// Establece el alto y ancho del sprite
|
// Establece el alto y ancho del sprite
|
||||||
mSpriteLegs->setWidth(mWidth);
|
mSpriteLegs->setWidth(mWidth);
|
||||||
@@ -75,6 +85,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setWidth(mWidth);
|
mSpriteBody->setWidth(mWidth);
|
||||||
mSpriteBody->setHeight(mHeight);
|
mSpriteBody->setHeight(mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setWidth(mWidth);
|
||||||
|
mSpriteHead->setHeight(mHeight);
|
||||||
|
|
||||||
// Establece la posición del sprite
|
// Establece la posición del sprite
|
||||||
mSpriteLegs->setPosX(int(mPosX));
|
mSpriteLegs->setPosX(int(mPosX));
|
||||||
mSpriteLegs->setPosY(mPosY);
|
mSpriteLegs->setPosY(mPosY);
|
||||||
@@ -82,6 +95,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setPosX(int(mPosX));
|
mSpriteBody->setPosX(int(mPosX));
|
||||||
mSpriteBody->setPosY(mPosY);
|
mSpriteBody->setPosY(mPosY);
|
||||||
|
|
||||||
|
mSpriteHead->setPosX(int(mPosX));
|
||||||
|
mSpriteHead->setPosY(mPosY);
|
||||||
|
|
||||||
// Inicializa las variables para la animación
|
// Inicializa las variables para la animación
|
||||||
mSpriteLegs->setCurrentFrame(0);
|
mSpriteLegs->setCurrentFrame(0);
|
||||||
mSpriteLegs->setAnimationCounter(0);
|
mSpriteLegs->setAnimationCounter(0);
|
||||||
@@ -89,6 +105,9 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setCurrentFrame(0);
|
mSpriteBody->setCurrentFrame(0);
|
||||||
mSpriteBody->setAnimationCounter(0);
|
mSpriteBody->setAnimationCounter(0);
|
||||||
|
|
||||||
|
mSpriteHead->setCurrentFrame(0);
|
||||||
|
mSpriteHead->setAnimationCounter(0);
|
||||||
|
|
||||||
// Establece el numero de frames de cada animacion
|
// Establece el numero de frames de cada animacion
|
||||||
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 4);
|
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 4);
|
||||||
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 4);
|
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 4);
|
||||||
@@ -101,6 +120,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
|
||||||
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 4);
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 4);
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 4);
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 4);
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 4);
|
||||||
|
mSpriteHead->setAnimationNumFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 4);
|
||||||
|
|
||||||
// Establece la velocidad de cada animación
|
// Establece la velocidad de cada animación
|
||||||
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
|
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
|
||||||
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5);
|
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5);
|
||||||
@@ -113,6 +139,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
|
||||||
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 5);
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 5);
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 5);
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 5);
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_WALKING_STOP, 10);
|
||||||
|
mSpriteHead->setAnimationSpeed(PLAYER_ANIMATION_HEAD_FIRING_UP, 5);
|
||||||
|
|
||||||
// Establece si la animación se reproduce en bucle
|
// Establece si la animación se reproduce en bucle
|
||||||
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
|
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
|
||||||
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true);
|
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true);
|
||||||
@@ -125,6 +158,13 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
|
||||||
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_LEFT, true);
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_LEFT, true);
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, true);
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, true);
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_WALKING_STOP, true);
|
||||||
|
mSpriteHead->setAnimationLoop(PLAYER_ANIMATION_HEAD_FIRING_UP, true);
|
||||||
|
|
||||||
// Establece los frames de cada animación
|
// Establece los frames de cada animación
|
||||||
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
|
||||||
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight);
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight);
|
||||||
@@ -171,9 +211,40 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
|
||||||
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 0, mWidth * 0, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 1, mWidth * 1, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 2, mWidth * 2, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, 3, mWidth * 3, mHeight * 2, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 0, mWidth * 0, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 1, mWidth * 1, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 2, mWidth * 2, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, 3, mWidth * 3, mHeight * 3, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0, mWidth * 0, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 1, mWidth * 1, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 2, mWidth * 2, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, 3, mWidth * 3, mHeight * 4, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 0, mWidth * 0, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 1, mWidth * 1, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
|
||||||
|
|
||||||
// Selecciona un frame para pintar
|
// Selecciona un frame para pintar
|
||||||
mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
|
mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
|
||||||
mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
|
mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
|
||||||
|
mSpriteHead->setSpriteClip(mSpriteHead->getAnimationClip(PLAYER_ANIMATION_HEAD_WALKING_STOP, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actua en consecuencia de la entrada recibida
|
// Actua en consecuencia de la entrada recibida
|
||||||
@@ -191,15 +262,15 @@ void Player::setInput(Uint8 input)
|
|||||||
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_FIRE_UP:
|
case INPUT_BUTTON_2:
|
||||||
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_FIRE_LEFT:
|
case INPUT_BUTTON_1:
|
||||||
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_FIRE_RIGHT:
|
case INPUT_BUTTON_3:
|
||||||
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -220,10 +291,7 @@ void Player::move()
|
|||||||
|
|
||||||
// Si el jugador abandona el area de juego por los laterales
|
// Si el jugador abandona el area de juego por los laterales
|
||||||
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
|
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
|
||||||
{
|
mPosX -= mVelX; // Restaura su posición
|
||||||
// Restaura su posición
|
|
||||||
mPosX -= mVelX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSpriteLegs->setPosX(getPosX());
|
mSpriteLegs->setPosX(getPosX());
|
||||||
@@ -231,6 +299,9 @@ void Player::move()
|
|||||||
|
|
||||||
mSpriteBody->setPosX(getPosX());
|
mSpriteBody->setPosX(getPosX());
|
||||||
mSpriteBody->setPosY(mPosY);
|
mSpriteBody->setPosY(mPosY);
|
||||||
|
|
||||||
|
mSpriteHead->setPosX(getPosX());
|
||||||
|
mSpriteHead->setPosY(mPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,12 +316,14 @@ void Player::render()
|
|||||||
{
|
{
|
||||||
mSpriteLegs->render();
|
mSpriteLegs->render();
|
||||||
mSpriteBody->render();
|
mSpriteBody->render();
|
||||||
|
mSpriteHead->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSpriteLegs->render();
|
mSpriteLegs->render();
|
||||||
mSpriteBody->render();
|
mSpriteBody->render();
|
||||||
|
mSpriteHead->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,6 +347,7 @@ void Player::setFiringStatus(Uint8 status)
|
|||||||
{
|
{
|
||||||
mStatusFiring = status;
|
mStatusFiring = status;
|
||||||
mSpriteBody->setCurrentFrame(0);
|
mSpriteBody->setCurrentFrame(0);
|
||||||
|
mSpriteHead->setCurrentFrame(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +355,7 @@ void Player::setFiringStatus(Uint8 status)
|
|||||||
void Player::setAnimation()
|
void Player::setAnimation()
|
||||||
{
|
{
|
||||||
// Actualiza los frames de la animación en función del número de cafes
|
// Actualiza los frames de la animación en función del número de cafes
|
||||||
for (Uint8 i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, mWidth * i, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, mWidth * i, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, mWidth * i, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, mWidth * i, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
@@ -291,6 +365,17 @@ void Player::setAnimation()
|
|||||||
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, mWidth * i, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, mWidth * i, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza los frames de la animación en función de si se tiene el PowerUp
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
||||||
|
}
|
||||||
|
|
||||||
switch (mStatusWalking)
|
switch (mStatusWalking)
|
||||||
{
|
{
|
||||||
case PLAYER_STATUS_WALKING_LEFT:
|
case PLAYER_STATUS_WALKING_LEFT:
|
||||||
@@ -299,22 +384,27 @@ void Player::setAnimation()
|
|||||||
{
|
{
|
||||||
case PLAYER_STATUS_FIRING_UP:
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_LEFT:
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_RIGHT:
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_NO:
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -325,22 +415,27 @@ void Player::setAnimation()
|
|||||||
{
|
{
|
||||||
case PLAYER_STATUS_FIRING_UP:
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_LEFT:
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_RIGHT:
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_NO:
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -351,22 +446,27 @@ void Player::setAnimation()
|
|||||||
{
|
{
|
||||||
case PLAYER_STATUS_FIRING_UP:
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_UP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_LEFT:
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_RIGHT:
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_FIRING_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_FIRING_NO:
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
mSpriteHead->animate(PLAYER_ANIMATION_HEAD_WALKING_STOP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -406,13 +506,9 @@ bool Player::canFire()
|
|||||||
{
|
{
|
||||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||||
if (mCooldown > 0)
|
if (mCooldown > 0)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -426,7 +522,9 @@ void Player::updateCooldown()
|
|||||||
{
|
{
|
||||||
if (mCooldown > 0)
|
if (mCooldown > 0)
|
||||||
{
|
{
|
||||||
--mCooldown;
|
mCooldown--;
|
||||||
|
if (mPowerUp)
|
||||||
|
mCooldown--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -441,23 +539,26 @@ void Player::update()
|
|||||||
setAnimation();
|
setAnimation();
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
updateCooldown();
|
updateCooldown();
|
||||||
|
updatePowerUpCounter();
|
||||||
updateInvulnerableCounter();
|
updateInvulnerableCounter();
|
||||||
|
updateDeathCounter();
|
||||||
|
updatePowerUpHeadOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la puntuación del jugador
|
// Obtiene la puntuación del jugador
|
||||||
int Player::getScore()
|
Uint32 Player::getScore()
|
||||||
{
|
{
|
||||||
return mScore;
|
return mScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna un valor a la puntuación del jugador
|
// Asigna un valor a la puntuación del jugador
|
||||||
void Player::setScore(int score)
|
void Player::setScore(Uint32 score)
|
||||||
{
|
{
|
||||||
mScore = score;
|
mScore = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa la puntuación del jugador
|
// Incrementa la puntuación del jugador
|
||||||
void Player::addScore(int score)
|
void Player::addScore(Uint32 score)
|
||||||
{
|
{
|
||||||
mScore += score;
|
mScore += score;
|
||||||
}
|
}
|
||||||
@@ -490,18 +591,18 @@ void Player::setScoreMultiplier(float value)
|
|||||||
void Player::incScoreMultiplier()
|
void Player::incScoreMultiplier()
|
||||||
{
|
{
|
||||||
if (mScoreMultiplier < 5.0f)
|
if (mScoreMultiplier < 5.0f)
|
||||||
{
|
|
||||||
mScoreMultiplier += 0.1f;
|
mScoreMultiplier += 0.1f;
|
||||||
}
|
else
|
||||||
|
mScoreMultiplier = 5.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrementa el valor de la variable hasta un mínimo
|
// Decrementa el valor de la variable hasta un mínimo
|
||||||
void Player::decScoreMultiplier()
|
void Player::decScoreMultiplier()
|
||||||
{
|
{
|
||||||
if (mScoreMultiplier > 1.0f)
|
if (mScoreMultiplier > 1.0f)
|
||||||
{
|
|
||||||
mScoreMultiplier -= 0.1f;
|
mScoreMultiplier -= 0.1f;
|
||||||
}
|
else
|
||||||
|
mScoreMultiplier = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
@@ -531,14 +632,63 @@ void Player::setInvulnerableCounter(Uint16 value)
|
|||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void Player::updateInvulnerableCounter()
|
void Player::updateInvulnerableCounter()
|
||||||
{
|
{
|
||||||
if (mInvulnerableCounter > 0)
|
if (mInvulnerable)
|
||||||
{
|
{
|
||||||
--mInvulnerableCounter;
|
if (mInvulnerableCounter > 0)
|
||||||
|
{
|
||||||
|
mInvulnerableCounter--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInvulnerable = false;
|
||||||
|
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void Player::updateDeathCounter()
|
||||||
|
{
|
||||||
|
if (!mAlive)
|
||||||
|
if (mDeathCounter > 0)
|
||||||
|
mDeathCounter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::isPowerUp()
|
||||||
|
{
|
||||||
|
return mPowerUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setPowerUp(bool value)
|
||||||
|
{
|
||||||
|
mPowerUp = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 Player::getPowerUpCounter()
|
||||||
|
{
|
||||||
|
return mPowerUpCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setPowerUpCounter(Uint16 value)
|
||||||
|
{
|
||||||
|
mPowerUpCounter = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void Player::updatePowerUpCounter()
|
||||||
|
{
|
||||||
|
if ((mPowerUpCounter > 0) && (mPowerUp))
|
||||||
|
{
|
||||||
|
mPowerUpCounter--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mInvulnerable = false;
|
mPowerUp = false;
|
||||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
mPowerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,6 +745,36 @@ circle_t &Player::getCollider()
|
|||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
void Player::shiftColliders()
|
void Player::shiftColliders()
|
||||||
{
|
{
|
||||||
mCollider.x = Uint16(mPosX + (mWidth / 2));
|
mCollider.x = int(mPosX + (mWidth / 2));
|
||||||
mCollider.y = mPosY + (mHeight / 2);
|
mCollider.y = int(mPosY + (mHeight / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||||
|
LTexture *Player::getDeadTexture()
|
||||||
|
{
|
||||||
|
return mPlayerDeadTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 Player::getDeathCounter()
|
||||||
|
{
|
||||||
|
return mDeathCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void Player::updatePowerUpHeadOffset()
|
||||||
|
{
|
||||||
|
if (!mPowerUp)
|
||||||
|
mPowerUpHeadOffset = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPowerUpHeadOffset = 96;
|
||||||
|
if (mPowerUpCounter < 300)
|
||||||
|
{
|
||||||
|
if (mPowerUpCounter % 10 > 4)
|
||||||
|
mPowerUpHeadOffset = 96;
|
||||||
|
else
|
||||||
|
mPowerUpHeadOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,49 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "input.h"
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
// The player
|
// Contadores
|
||||||
|
#define DEATH_COUNTER 350
|
||||||
|
|
||||||
|
// Estados del jugador
|
||||||
|
#define PLAYER_STATUS_WALKING_LEFT 0
|
||||||
|
#define PLAYER_STATUS_WALKING_RIGHT 1
|
||||||
|
#define PLAYER_STATUS_WALKING_STOP 2
|
||||||
|
|
||||||
|
#define PLAYER_STATUS_FIRING_UP 0
|
||||||
|
#define PLAYER_STATUS_FIRING_LEFT 1
|
||||||
|
#define PLAYER_STATUS_FIRING_RIGHT 2
|
||||||
|
#define PLAYER_STATUS_FIRING_NO 3
|
||||||
|
|
||||||
|
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
||||||
|
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
||||||
|
|
||||||
|
#define PLAYER_ANIMATION_BODY_WALKING_LEFT 0
|
||||||
|
#define PLAYER_ANIMATION_BODY_FIRING_LEFT 1
|
||||||
|
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT 2
|
||||||
|
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
|
||||||
|
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
|
||||||
|
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
|
||||||
|
|
||||||
|
#define PLAYER_ANIMATION_HEAD_WALKING_LEFT 0
|
||||||
|
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
|
||||||
|
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
|
||||||
|
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
||||||
|
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
||||||
|
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
||||||
|
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
||||||
|
|
||||||
|
// Variables del jugador
|
||||||
|
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||||
|
#define PLAYER_POWERUP_COUNTER 1500
|
||||||
|
|
||||||
|
// Clase Player
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -28,20 +66,36 @@ private:
|
|||||||
Uint8 mStatusFiring; // Estado del jugador
|
Uint8 mStatusFiring; // Estado del jugador
|
||||||
|
|
||||||
bool mAlive; // Indica si el jugador está vivo
|
bool mAlive; // Indica si el jugador está vivo
|
||||||
|
Uint16 mDeathCounter; // Contador para la animación de morirse
|
||||||
bool mInvulnerable; // Indica si el jugador es invulnerable
|
bool mInvulnerable; // Indica si el jugador es invulnerable
|
||||||
Uint16 mInvulnerableCounter; // Temporizador para la invulnerabilidad
|
Uint16 mInvulnerableCounter; // Contador para la invulnerabilidad
|
||||||
bool mExtraHit; // Indica si el jugador tiene un toque extra
|
bool mExtraHit; // Indica si el jugador tiene un toque extra
|
||||||
Uint8 mCoffees; // Indica cuantos cafes lleva acumulados
|
Uint8 mCoffees; // Indica cuantos cafes lleva acumulados
|
||||||
|
bool mPowerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||||
|
Uint8 mPowerUpHeadOffset; // Variable para dibujar la cabeza normal o la del powerup
|
||||||
bool mInput; // Indica si puede recibir ordenes de entrada
|
bool mInput; // Indica si puede recibir ordenes de entrada
|
||||||
|
|
||||||
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
|
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
|
||||||
AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo
|
AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo
|
||||||
AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza
|
AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza
|
||||||
|
LTexture *mPlayerDeadTexture; // Textura con los gráficos para la animación de muerte
|
||||||
|
|
||||||
circle_t mCollider; // Circulo de colisión del jugador
|
circle_t mCollider; // Circulo de colisión del jugador
|
||||||
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
|
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void updateInvulnerableCounter();
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void updateDeathCounter();
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void updatePowerUpHeadOffset();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Uint8 mDeathIndex; // Apaño rapidito. Indice de SmartSprite donde esta ubicado el sprite de morirse
|
||||||
|
Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player();
|
Player();
|
||||||
|
|
||||||
@@ -49,7 +103,7 @@ public:
|
|||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer);
|
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Actua en consecuencia de la entrada recibida
|
// Actua en consecuencia de la entrada recibida
|
||||||
void setInput(Uint8 input);
|
void setInput(Uint8 input);
|
||||||
@@ -62,6 +116,8 @@ public:
|
|||||||
|
|
||||||
// Establece el estado del jugador
|
// Establece el estado del jugador
|
||||||
void setWalkingStatus(Uint8 status);
|
void setWalkingStatus(Uint8 status);
|
||||||
|
|
||||||
|
// Establece el estado del jugador
|
||||||
void setFiringStatus(Uint8 status);
|
void setFiringStatus(Uint8 status);
|
||||||
|
|
||||||
// Establece la animación correspondiente al estado
|
// Establece la animación correspondiente al estado
|
||||||
@@ -92,13 +148,13 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Obtiene la puntuación del jugador
|
// Obtiene la puntuación del jugador
|
||||||
int getScore();
|
Uint32 getScore();
|
||||||
|
|
||||||
// Asigna un valor a la puntuación del jugador
|
// Asigna un valor a la puntuación del jugador
|
||||||
void setScore(int score);
|
void setScore(Uint32 score);
|
||||||
|
|
||||||
// Incrementa la puntuación del jugador
|
// Incrementa la puntuación del jugador
|
||||||
void addScore(int score);
|
void addScore(Uint32 score);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool isAlive();
|
bool isAlive();
|
||||||
@@ -130,8 +186,20 @@ public:
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setInvulnerableCounter(Uint16 value);
|
void setInvulnerableCounter(Uint16 value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isPowerUp();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPowerUp(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 getPowerUpCounter();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPowerUpCounter(Uint16 value);
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
void updateInvulnerableCounter();
|
void updatePowerUpCounter();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool hasExtraHit();
|
bool hasExtraHit();
|
||||||
@@ -153,6 +221,12 @@ public:
|
|||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
|
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||||
|
LTexture *getDeadTexture();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 getDeathCounter();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
133
source/screen.cpp
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
mWindow = window;
|
||||||
|
mRenderer = renderer;
|
||||||
|
mOptions = options;
|
||||||
|
|
||||||
|
mGameCanvasWidth = SCREEN_WIDTH;
|
||||||
|
mGameCanvasHeight = SCREEN_HEIGHT;
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
setVideoMode(mOptions->fullScreenMode);
|
||||||
|
|
||||||
|
// Define el color del borde para el modo de pantalla completa
|
||||||
|
mBorderColor = {0x27, 0x27, 0x36};
|
||||||
|
mBorderColor = {0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
// Crea la textura donde se dibujan los graficos del juego
|
||||||
|
mGameCanvas = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mGameCanvasWidth, mGameCanvasHeight);
|
||||||
|
if (mGameCanvas == nullptr)
|
||||||
|
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Screen::~Screen()
|
||||||
|
{
|
||||||
|
mRenderer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
void Screen::clean(color_t color)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, color.r, color.g, color.b, 0xFF);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
void Screen::start()
|
||||||
|
{
|
||||||
|
SDL_SetRenderTarget(mRenderer, mGameCanvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
void Screen::blit()
|
||||||
|
{
|
||||||
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
|
// Borra el contenido previo
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
|
SDL_RenderCopy(mRenderer, mGameCanvas, nullptr, &mDest);
|
||||||
|
|
||||||
|
// Muestra por pantalla el renderizador
|
||||||
|
SDL_RenderPresent(mRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
void Screen::setVideoMode(int fullScreenMode)
|
||||||
|
{
|
||||||
|
// Aplica el modo de video
|
||||||
|
SDL_SetWindowFullscreen(mWindow, fullScreenMode);
|
||||||
|
|
||||||
|
// Si está activo el modo ventana quita el borde
|
||||||
|
if (fullScreenMode == 0)
|
||||||
|
{
|
||||||
|
mScreenWidth = mGameCanvasWidth;
|
||||||
|
mScreenHeight = mGameCanvasHeight;
|
||||||
|
mDest = {0, 0, mGameCanvasWidth, mGameCanvasHeight};
|
||||||
|
|
||||||
|
// Modifica el tamaño del renderizador y de la ventana
|
||||||
|
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
||||||
|
SDL_SetWindowSize(mWindow, mScreenWidth * mOptions->windowSize, mScreenHeight * mOptions->windowSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
|
if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
|
{
|
||||||
|
// Obten el alto y el ancho de la ventana
|
||||||
|
SDL_GetWindowSize(mWindow, &mScreenWidth, &mScreenHeight);
|
||||||
|
|
||||||
|
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||||
|
if (mOptions->integerScale)
|
||||||
|
{
|
||||||
|
// Calcula el tamaño de la escala máxima
|
||||||
|
int scale = 0;
|
||||||
|
while (((mGameCanvasWidth * (scale + 1)) <= mScreenWidth) && ((mGameCanvasHeight * (scale + 1)) <= mScreenHeight))
|
||||||
|
{
|
||||||
|
scale++;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDest.w = mGameCanvasWidth * scale;
|
||||||
|
mDest.h = mGameCanvasHeight * scale;
|
||||||
|
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||||
|
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||||
|
}
|
||||||
|
else if (mOptions->keepAspect)
|
||||||
|
{
|
||||||
|
float ratio = (float)mGameCanvasWidth / (float)mGameCanvasHeight;
|
||||||
|
if ((mScreenWidth - mGameCanvasWidth) >= (mScreenHeight - mGameCanvasHeight))
|
||||||
|
{
|
||||||
|
mDest.h = mScreenHeight;
|
||||||
|
mDest.w = (int)((mScreenHeight * ratio) + 0.5f);
|
||||||
|
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||||
|
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mDest.w = mScreenWidth;
|
||||||
|
mDest.h = (int)((mScreenWidth / ratio) + 0.5f);
|
||||||
|
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||||
|
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mDest.w = mScreenWidth;
|
||||||
|
mDest.h = mScreenHeight;
|
||||||
|
mDest.x = mDest.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifica el tamaño del renderizador
|
||||||
|
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
source/screen.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#ifndef SCREEN_H
|
||||||
|
#define SCREEN_H
|
||||||
|
|
||||||
|
// Clase Screen
|
||||||
|
class Screen
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Window *mWindow; // Ventana de la aplicación
|
||||||
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
|
SDL_Texture *mGameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||||
|
options_t *mOptions; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
|
int mScreenWidth; // Ancho de la pantalla
|
||||||
|
int mScreenHeight; // Alto de la pantalla
|
||||||
|
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
||||||
|
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
||||||
|
SDL_Rect mDest; // Coordenadas donde se va a dibujar la textura del juego
|
||||||
|
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Screen();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
void clean(color_t color);
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
void start();
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
void blit();
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
void setVideoMode(int fullScreenMode);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,13 +4,11 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
SmartSprite::SmartSprite()
|
SmartSprite::SmartSprite()
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
SmartSprite::~SmartSprite()
|
SmartSprite::~SmartSprite()
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
@@ -38,6 +36,12 @@ void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
|||||||
mDestX = 0;
|
mDestX = 0;
|
||||||
mDestY = 0;
|
mDestY = 0;
|
||||||
|
|
||||||
|
setRotate(false);
|
||||||
|
setRotateSpeed(0);
|
||||||
|
setRotateAmount(0.0);
|
||||||
|
|
||||||
|
mCounter = 0;
|
||||||
|
|
||||||
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
|
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
|
||||||
mId = -1;
|
mId = -1;
|
||||||
|
|
||||||
@@ -65,13 +69,13 @@ void SmartSprite::setEnabled(bool state)
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint16 SmartSprite::getEnabledTimer()
|
Uint16 SmartSprite::getEnabledTimer()
|
||||||
{
|
{
|
||||||
return mEnabledTimer;
|
return mEnabledCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setEnabledTimer(Uint16 time)
|
void SmartSprite::setEnabledTimer(Uint16 time)
|
||||||
{
|
{
|
||||||
mEnabledTimer = time;
|
mEnabledCounter = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -103,12 +107,12 @@ bool SmartSprite::update()
|
|||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
{
|
{
|
||||||
move();
|
MovingSprite::update();
|
||||||
|
|
||||||
// Comprueba si se desplaza en el eje X hacia la derecha
|
// Comprueba si se desplaza en el eje X hacia la derecha
|
||||||
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si hemos llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosX() > mDestX)
|
if (getPosX() > mDestX)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
@@ -119,11 +123,10 @@ bool SmartSprite::update()
|
|||||||
setAccelX(0.0f);
|
setAccelX(0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se desplaza en el eje X hacia la izquierda
|
// Comprueba si se desplaza en el eje X hacia la izquierda
|
||||||
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si hemos llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosX() < mDestX)
|
if (getPosX() < mDestX)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
@@ -138,7 +141,7 @@ bool SmartSprite::update()
|
|||||||
// Comprueba si se desplaza en el eje Y hacia abajo
|
// Comprueba si se desplaza en el eje Y hacia abajo
|
||||||
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si hemos llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosY() > mDestY)
|
if (getPosY() > mDestY)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
@@ -152,7 +155,7 @@ bool SmartSprite::update()
|
|||||||
// Comprueba si se desplaza en el eje Y hacia arriba
|
// Comprueba si se desplaza en el eje Y hacia arriba
|
||||||
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si hemos llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosY() < mDestY)
|
if (getPosY() < mDestY)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
@@ -166,24 +169,20 @@ bool SmartSprite::update()
|
|||||||
|
|
||||||
// Comprueba si ha llegado a su destino
|
// Comprueba si ha llegado a su destino
|
||||||
if ((getPosX() == mDestX) && (getPosY() == mDestY))
|
if ((getPosX() == mDestX) && (getPosY() == mDestY))
|
||||||
{
|
|
||||||
mIsOnDestination = true;
|
mIsOnDestination = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
mIsOnDestination = false;
|
mIsOnDestination = false;
|
||||||
}
|
|
||||||
|
|
||||||
// Si esta en el destino comprueba su contador
|
// Si esta en el destino comprueba su contador
|
||||||
if (mIsOnDestination)
|
if (mIsOnDestination)
|
||||||
{
|
{
|
||||||
// Si el contador es mayor que cero, lo decrementa
|
// Si el contador es mayor que cero, lo decrementa
|
||||||
if (mEnabledTimer > 0)
|
if (mEnabledCounter > 0)
|
||||||
{
|
{
|
||||||
--mEnabledTimer;
|
mEnabledCounter--;
|
||||||
}
|
}
|
||||||
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
||||||
else if (mEnabledTimer == 0)
|
else if (mEnabledCounter == 0)
|
||||||
{
|
{
|
||||||
if (mId < 0)
|
if (mId < 0)
|
||||||
{
|
{
|
||||||
@@ -210,9 +209,7 @@ bool SmartSprite::isOnDestination()
|
|||||||
void SmartSprite::render()
|
void SmartSprite::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
{
|
|
||||||
MovingSprite::render();
|
MovingSprite::render();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
@@ -8,6 +10,15 @@
|
|||||||
// Clase SmartSprite
|
// Clase SmartSprite
|
||||||
class SmartSprite : public AnimatedSprite
|
class SmartSprite : public AnimatedSprite
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
bool mEnabled; // Indica si esta habilitado
|
||||||
|
bool mIsOnDestination; // Indica si está en el destino
|
||||||
|
int mDestX; // Posicion de destino en el eje X
|
||||||
|
int mDestY; // Posicion de destino en el eje Y
|
||||||
|
int mId; // Identificador
|
||||||
|
Uint16 mEnabledCounter; // Contador para deshabilitarlo
|
||||||
|
Uint8 *mIntroEvents; // Dirección del array de eventos donde notificar el estado
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
SmartSprite();
|
SmartSprite();
|
||||||
@@ -59,26 +70,6 @@ public:
|
|||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setIntroEvents(Uint8 *value);
|
void setIntroEvents(Uint8 *value);
|
||||||
|
|
||||||
private:
|
|
||||||
// Indica si esta habilitado
|
|
||||||
bool mEnabled;
|
|
||||||
|
|
||||||
// Contador
|
|
||||||
Uint16 mEnabledTimer;
|
|
||||||
|
|
||||||
// Indica si está en el destino
|
|
||||||
bool mIsOnDestination;
|
|
||||||
|
|
||||||
// Posicion de destino
|
|
||||||
int mDestX;
|
|
||||||
int mDestY;
|
|
||||||
|
|
||||||
// Identificador
|
|
||||||
int mId;
|
|
||||||
|
|
||||||
// Dirección del array de eventos donde notificar el estado
|
|
||||||
Uint8 *mIntroEvents;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||