Compare commits

241 Commits

Author SHA1 Message Date
9825c7fb9b Pasaeta de include-what-you-use 2024-10-13 21:58:36 +02:00
d0a6e4c572 Afegits destructors virtuals en les classes Sprite 2024-10-13 21:23:15 +02:00
7c876e1d4d Acabat amb cppcheck
Arreglades les herencies de les classes Sprite
2024-10-13 21:00:33 +02:00
809c10048e Commit pa poder tornar a passar el cppcheck 2024-10-13 19:39:43 +02:00
babf02226c Mes recomanacions de cppcheck 2024-10-13 19:26:27 +02:00
46540ad7c3 Optimitzat el tema de comparacions i asignacions de strings buits. Mes que optimitzat, ara està mes mono 2024-10-13 14:25:05 +02:00
ba7c44ad06 Actualitzat Makefile 2024-10-13 14:24:15 +02:00
46b19ee82f Mes recomanacions de cppcheck aplicades
Abans de tocar unes cosetes de strings buits
2024-10-13 13:49:00 +02:00
b2122ac239 Eliminats fitxers que s'havien colat 2024-10-13 11:04:50 +02:00
c11a868289 Afegides recomanacions de cppcheck
Optimitzada la funció updateBalloonSpeed() i eliminades funcions sobrants o redundants
2024-10-13 11:03:50 +02:00
22d457285d Modificat .gitignore 2024-10-13 11:03:00 +02:00
b060f21696 Arreglades les herencies de Sprite
Abans de llevar mil coses que sobren i replantejar-se estes 4 classes
2024-10-13 10:01:07 +02:00
33ea8d90ca Acabat de renamar, encara que he descobert cosetes i tindré que fer altra pasaeta
Actualitzat stb_image.h a la última versió
2024-10-12 22:25:43 +02:00
cce14dba4d Mes renames. Mes ordre. 2024-10-12 12:03:19 +02:00
101e375fd3 Variables renombrades en input.cpp 2024-10-12 11:01:42 +02:00
4ef759772a game.cpp renombrat 2024-10-12 09:15:20 +02:00
07714aabc3 Abans de renombrar game.cpp 2024-10-12 07:26:41 +02:00
d50cf23721 Abans de renombrar player.cpp 2024-10-11 21:58:59 +02:00
3a6950f3a4 Menudo puto lio de renamar coses, a vore si tot va quedant al lloc que els structs i els enums estan revolant i duplicats per tots llocs 2024-10-11 20:12:50 +02:00
a9ca23138d Continuem estandaritzant noms 2024-10-11 13:54:43 +02:00
e1fa1d2102 Canviades certes opcions a parametres i afegides noves opcions 2024-10-11 09:03:57 +02:00
117b80bdfc idem 2024-10-10 20:59:39 +02:00
d6c3c89872 Estandaritzant noms segons convencions 2024-10-10 20:27:31 +02:00
9e5f41644e Açò ja no hi ha Cristo que ho pete 2024-10-10 13:48:53 +02:00
fc8fdc5fe5 Llevats uns punterets que sobraven en director.cpp 2024-10-10 09:23:16 +02:00
6fe294c59d Pos ja compila pero no es veu una puta merda ... 2024-10-10 08:06:36 +02:00
3fa5b227ae commit de anar a dormir 2024-10-09 23:01:44 +02:00
f2fa216b0d Commit pa que Mon arregle el codi mentre em dutxe 2024-10-09 21:48:01 +02:00
3c1dcad3ab Commit de anar al llit amb el portatil 2024-10-08 23:15:55 +02:00
bd3aa0bb06 Arreglos varios al codi 2024-10-08 22:38:58 +02:00
3e3d764b25 Commitet pa gastar el Cppcheck 2024-10-08 20:32:24 +02:00
c00f4326ae Commit de "guardar partida" 2024-10-08 18:07:54 +02:00
9ce0f16d33 Arreglats els constructors de Text 2024-10-08 18:07:44 +02:00
06a4f439c1 Posant make_uniques, s'ha quedat tot enmerdat per culpa d'un struct 2024-10-08 13:53:24 +02:00
9d41d14d68 Actualitzats els scripts de valgrind 2024-10-07 20:11:08 +02:00
0d0e49316f Afegit scripts a linux-utils 2024-10-07 18:44:18 +02:00
bf945ef14b Corregits 8.000.000 de segmentation faults en intro.cpp 2024-10-07 18:37:08 +02:00
0330fe6b74 Make uniques en intro.cpp 2024-10-07 17:28:34 +02:00
6305a67c84 Actualitzat .gitignore 2024-10-07 17:28:22 +02:00
5f18189269 Actualizado Makefile 2024-10-07 12:32:53 +02:00
7ebefd7b54 Les enum class passen a estar totes amb la inicial en majuscula 2024-10-07 12:30:46 +02:00
cffa4c3c92 Commitet pa valgrind, he aprofitat i posat mes make_unique i enum class 2024-10-07 10:49:29 +02:00
4f0ea9dcf2 Make_unique en title.cpp 2024-10-07 08:22:51 +02:00
b1f936a791 Pasaeta de include-what-you-use abans que es desmadre tot 2024-10-06 22:43:28 +02:00
1c0554d4df Actualitzat script check-includes.sh 2024-10-06 22:43:00 +02:00
8ba77d7d5d Demanada ajuda a la IA pa que m'arregle un poc la meua merda: Para optimizar este código y evitar duplicar la lógica para cada jugador, podemos extraer el código común en una función reutilizable. Así, reducimos la repetición y mejoramos la legibilidad. 2024-10-06 21:07:26 +02:00
6515ec6c7b Els panels dels marcadors ja passen a game over sense pasar per waiting un frame gracies a una parafernalia que he montat 2024-10-06 21:02:49 +02:00
b979c0f2b8 Mes textos 2024-10-06 21:02:12 +02:00
a95e5077e3 Els panels del marcador ara canvien de mode a petició i no a cada frame 2024-10-06 20:19:43 +02:00
6ea6f85e3e Nous textos 2024-10-06 20:14:37 +02:00
fe6e63e39f fix: la classe Screen ja ha recuperat un poc del lustro que tenia
shake effect ja no està fet "the torerous menner"
shake effect ja va amb shaders
2024-10-06 18:57:47 +02:00
afe092c742 Muntat a c++14 per a make_unique
Mes autos, const i constexpr perl codi
Ara la classe Screen es un poc pitjor
2024-10-06 14:58:00 +02:00
25a2753b13 Canviats defines per constexpr i enum class
Canviats punters a unique_ptr
Afegit const a alguns metodes de classse
fix: el segon jugador no podia unirse a la partida
new: Quan els dos jugadors han decidit no continuar, ja no poden continuar i el marcador així ho reflectix
fix: al posar el nom per segona vegada en la mateixa partida, no es reseteja la posició del selector
fix: el fade venetian no netejava la textura i de vegades eixien gràfics corruptes
fix: ara grava a disco cada vegada que es posa nom al morir
2024-10-05 23:53:42 +02:00
ee721ff573 debug 2024-10-03 19:35:58 +02:00
c07fd62037 Corregit bug en el text a l'hora d'intercanviar els mandos. Apareixia el nom del mando que te guardat a la configuració pero no estava connectat 2024-10-03 19:26:32 +02:00
fb74733f2c Correcció de textos 2024-10-03 18:16:20 +02:00
468bd0950c Modificat controllers.png 2024-10-03 18:13:48 +02:00
938e4ad011 La targeta d'ajuda ja ix amb els mandos i s'ha de deixar apretat el botó 2024-10-03 17:37:33 +02:00
71bd3bed52 Eliminades variables sobrants en director.cpp 2024-10-03 17:02:40 +02:00
5ebc58dd01 La tarjeta d'ajuda ja entra i ix amb animacions suavitzades 2024-10-02 18:03:20 +02:00
9b3e549876 Añadidas funciones de suavizado a utils.cpp 2024-10-02 18:00:21 +02:00
abc8a0b632 La tarjeta d'ajuda ix pero no s'amaga 2024-10-02 13:56:43 +02:00
3a84ea792c Ja dibuixa la tarjeta amb la ajuda per als botons de servei 2024-10-01 20:58:05 +02:00
3cabd5c675 Nous textos 2024-10-01 19:07:25 +02:00
2ec242b2c9 Afegit esqueleto per a la classe OnScreenHelp 2024-10-01 18:34:26 +02:00
d993a6def4 Afegit formato Allman a bullet.cpp 2024-10-01 18:16:08 +02:00
5913d7548a Modificat el temps posterior d'aparició de la Powerball 2024-10-01 18:15:42 +02:00
84f3952232 Afegit controllers.png 2024-10-01 18:15:11 +02:00
7dbddd5524 Afegides utilitats per a linux
Arreglats alguns includes
2024-10-01 17:24:38 +02:00
dee5bcb4e4 Canviada la classe bullet per la de chatGPT, aixina demà ho mire amb calma 2024-09-30 23:06:16 +02:00
af1c1051e6 Afegides implementacions (fora del codi) que ha fet chatGPT de la classe bullet 2024-09-30 20:28:20 +02:00
aaf6dc29a1 El joc ja no comença al pulsar la combinació de botons per eixir 2024-09-30 19:45:04 +02:00
0af441b5df Finalitzada la part de entrar nom. Falta posar un temporitzador i una animació 2024-09-30 19:35:41 +02:00
6acf0b7efc Modificada la posició de PULSA PER JUGAR al titol 2024-09-30 19:35:00 +02:00
e033fc8015 Canviat el missatge d'eixida del joc 2024-09-30 18:47:12 +02:00
2d5859b1c4 Ja es pot "enner llour neim". Falta decidir quin de tots els dissenys m'agrada mes 2024-09-29 22:25:31 +02:00
edc45b6cec Afegides funcions per oscurir o aclarir colors 2024-09-29 19:35:33 +02:00
fad6cddfb6 Nous textos 2024-09-29 17:06:26 +02:00
8ce09d1355 Acomodats els estats del jugador
El compte enrrere per a continuar ara ix al acabar la animació de morir
Afegit el estat "entering_name"
2024-09-29 10:40:35 +02:00
945eaa68e7 Actualizado Makefile 2024-09-29 08:01:47 +02:00
28df97ea94 Pasaeta de "include-what-you-use" per arreglar els includes
Renombrats alguns fitxers per consistencia
2024-09-29 06:24:11 +02:00
ac3340c39f Eliminat tots els options.console 2024-09-28 18:02:09 +02:00
4febe8b7c0 Afegit global_inputs.c
El audio no es podía mutejar amb el teclat, soles amb els mandos
2024-09-28 17:08:09 +02:00
289d01b0fa fix: no estava comprobantse el reset amb el teclat 2024-09-28 14:23:51 +02:00
2767696a3f Singletonejada la classe Input 2024-09-28 14:19:00 +02:00
fa82758ce1 Don melitonada la classe Asset 2024-09-28 13:49:00 +02:00
878518babe Eliminades les icones de les notificacions (herencia del CC original) 2024-09-28 12:46:53 +02:00
3f24f38a0c Reestructurada la carpeta gfx 2024-09-28 12:37:52 +02:00
1f6dfe5d92 Faltava un pixel d'altura en logo_jailgames_mini.png 2024-09-28 12:25:26 +02:00
92f7f540c0 Classe Screen melitonada 2024-09-28 11:11:11 +02:00
f2cc0dc352 Eliminat "const.h" 2024-09-28 10:16:35 +02:00
8d263931b2 Eliminat el punter a "section" 2024-09-28 09:28:22 +02:00
0a8d0479a0 Estandaritzats els accessos a fitxers 2024-09-27 19:41:45 +02:00
20de9e4b72 Un altre punteret a pendre per cul: options 2024-09-27 19:00:09 +02:00
0de9188547 Reballats tots els .h i .cpp en la mateixa carpeta 2024-09-27 17:57:00 +02:00
9d7e975952 Actualitzat Makefile 2024-09-27 17:56:45 +02:00
46b41757b2 Convertit "param" a variable global en lloc de anar marejant amb punterets i passant 8.000.000 de paràmetres 2024-09-27 17:42:25 +02:00
c1bf0b8aed Estandarizados los colores en hexadecimal 2024-09-27 16:52:26 +02:00
5ca4ee0bb8 Afegit estat pre-logo per a poder fer reset mes millor 2024-09-26 22:50:46 +02:00
05e3fddb8f Mil millons de miniarreglos
Afegides traduccions faltants
2024-09-26 22:13:20 +02:00
69027f96e6 Eliminada la classe Lang 2024-09-26 18:08:59 +02:00
6ad1bca29f Afegida confirmació per eixir del joc 2024-09-25 09:19:12 +02:00
2f152915ed fix: sense mandos no comprovava ni el teclat 2024-09-24 20:44:09 +02:00
998b151c00 Añadido #ifdef ANBERNIC 2024-09-23 19:11:16 +02:00
0cd14aa320 Actualizado Makefile 2024-09-23 19:05:07 +02:00
159a75a60e follat! 2024-09-16 22:21:57 +02:00
80425a5ed0 Aumentado el tiempo de visibilidad de las notificaciones 2024-09-16 18:33:43 +02:00
a00c2284b6 Commit amb la merda de hui 2024-09-15 19:32:20 +02:00
75f9d3f5cb Cambios en swapControllers 2024-09-15 18:14:51 +02:00
85a082d738 Añadida la función boolToOnOff 2024-09-15 18:11:20 +02:00
b6c5d06246 fix: no escribia las notificaciones con la primera cadena vacía 2024-09-15 17:40:39 +02:00
891d5a8f5e Se puede usar tanto la primera como la segunda cadena de texto para generar notificaciones 2024-09-15 17:14:53 +02:00
333c905b1a Correcciones en el botón de servicio 2024-09-15 15:27:12 +02:00
41e57064cb Al intercambiar los mandos de los jugadores se muestra el mando que corresponde a cada jugador 2024-09-15 14:30:58 +02:00
7ef75184a5 Las notificaciones se pueden configurar para que no se apilen 2024-09-15 14:11:37 +02:00
c40c59275a Guardada en el fichero de configuración la asignación de cada mando a cada jugador 2024-09-15 13:29:05 +02:00
8fc217f0e3 Corregido el texto de salida del programa 2024-09-15 13:09:00 +02:00
04935c652d Añadidas nuevas funciones al botón de servicio
El botón de servicio se puede usar en cualquier sección del juego
2024-09-15 13:03:53 +02:00
a435e3ed8c corregidos varios bugs 2024-09-11 20:42:21 +02:00
41c3e1f32c El joc cascava quan havia que baixar el multiplicador del jugador per "pedre" una bala. Arreglat abans d'anar-me'n 😎 2024-09-11 14:09:22 +02:00
3d41da0fdf Añadida opción para intercambiar los jugadores de los dos primeros mandos 2024-09-11 13:59:40 +02:00
ecf34558f4 Añadido campo ID al jugador
Las balas y los mandos utilizan ahora este ID
2024-09-11 12:15:18 +02:00
1e2f121d82 Llevada tota la merda que he posat este mati 2024-09-10 13:23:47 +02:00
c93e824f86 Canviat stc per std dins de un puto define que el vsc passa de mirar si estan les coses ben escrites o no 2024-09-10 13:01:28 +02:00
762a819711 Añadido SDL_GetError a SDL_SetWindowDisplayMode 2024-09-10 12:56:25 +02:00
a5060b928f Prueba de SDL_SetWindowDisplayMode 2024-09-10 12:16:18 +02:00
2398e4136b Pequeños ajustes de formato 2024-09-10 11:50:56 +02:00
b3b932edfc Actualizado Makefile 2024-09-10 11:43:38 +02:00
443cc6da8d Añadido "Display modes list" 2024-09-10 11:35:28 +02:00
46cdc2189e Se puede especificar con argumentos el fichero de parametros a utilizar 2024-09-10 10:19:56 +02:00
f071b60212 Añadida información de la pantalla antes de crear la ventana 2024-09-10 08:12:37 +02:00
824bc08077 Cambiado de showFps a showInfo 2024-09-09 22:51:26 +02:00
e1fb069010 No se podía empezar a jugar con el teclado 2024-09-09 22:30:35 +02:00
b114d75c69 Retoques de lo anterior para ser un poco mas eficiente y ordenado 2024-09-09 18:47:59 +02:00
8465ee87fb Añadida info de debug: resolucion de la pantalla 2024-09-09 18:41:03 +02:00
83fb2f30ba Implementado código de salida de la aplicación 2024-09-09 13:51:16 +02:00
922d146781 Renombrado "section->subsection" por el mas apropiado "section->options" 2024-09-09 13:38:56 +02:00
1b2d1c5786 Añadido botón de servicio al titulo 2024-09-09 13:31:37 +02:00
7e1085ea42 Añadida la unidad service.h 2024-09-09 11:28:24 +02:00
d4417d67d5 Eliminados inputs en desuso y añadido el input de "service" 2024-09-09 10:15:57 +02:00
14af141d8f Eliminada la clase Menu 2024-09-09 10:06:53 +02:00
870a83d688 Deshabilitado el sonido de las notificaciones por defecto 2024-09-09 10:02:23 +02:00
54a0d6c448 Corregido el mapeo para el mando Zero Delay 2024-09-06 18:08:23 +02:00
c50d8a8bec Corregido un pase de parametros en la creación de los objetos y las balas 2024-09-06 13:54:17 +02:00
ad8c16f834 El separador del marcador ahora lo gestiona el propio marcador 2024-09-06 12:25:06 +02:00
cc15b8afd1 Retocados los degradados de fondo para dar soporte a la nueva resolución de 320x256 2024-09-06 10:54:05 +02:00
770f0eb046 Faltaba corregir un error de reemplazo en item.cpp 2024-09-06 08:56:12 +02:00
62b1ba84ac Cambiados muchos DEFINEs por variables de param 2024-09-06 08:41:10 +02:00
c5bab7019c Modificado el tamaño de la textura 2024-09-03 19:48:30 +02:00
b3d9b72d1d Corregido el tamaño de la textura y de la ventana 2024-09-03 19:47:57 +02:00
ccfd864eab En modo ARCADE solo se puede usar el modo ventana en setVideoMode() 2024-09-03 18:52:56 +02:00
f5b866b8c5 Oculta el puntero del raton al compilar en modo ARCADE 2024-09-03 18:50:20 +02:00
1b160c0584 Actualizado Makefile 2024-09-03 18:44:01 +02:00
c72dfe5876 Deshabilitada la opción de cambio de modo de video con la directiva de compilador ARCADE 2024-09-03 14:05:55 +02:00
548976c955 Actualizado Makefile 2024-09-03 14:04:55 +02:00
2a303deff1 Renombradas las variables de param_t 2024-09-03 13:59:07 +02:00
fa76520c6d Movido 'autofire' de param.txt a config.txt 2024-09-02 11:40:50 +02:00
f57a307991 Añadido soporte para ejes en la clase Input 2024-09-02 10:19:28 +02:00
4f6c92c8d1 Añadido cambio de color en las nubes 2024-08-30 13:12:04 +02:00
1d847eae9f Eliminada la (innecesaria) referencia a Screen 2024-08-30 13:02:45 +02:00
48d876bcf1 Eliminada la opción de poner pausa desde el mando 2024-08-28 08:38:21 +02:00
d16c8239c4 Haciendo pruebas con el modo de video a pantalla completa 2024-08-27 23:16:10 +02:00
50b1acfe8b Eliminado todo el código para añadir un borde a la zona de juego. Eran restos del código del JDD 2024-08-27 23:04:59 +02:00
60cfc1e4d9 Eliminadas variables sin utilizar 2024-08-27 22:49:51 +02:00
0ed0a5c6b5 Restablecidos los SDL_RenderSetLogicalSize eliminados 2024-08-27 11:52:38 +02:00
5ea41d4fc7 Añadidos nuevos custom mappings en gamecontrollerdb.txt 2024-08-27 11:25:39 +02:00
982094264a Eliminados SDL_RenderSetLogicalSize innecesarios 2024-08-27 11:16:22 +02:00
7a3c2ffe71 Cambiado el modo de fullscreen a SDL_WINDOW_FULLSCREEN_DESKTOP (como estaba en el CC original) 2024-08-27 09:37:16 +02:00
49cffb3669 Cambiado el modo de funcionamiento de la pausa durante el juego para permitir que ciertos métodos se sigan ejecutando 2024-08-27 08:48:04 +02:00
149e422489 Ara es pot activar o desactivar el comptador de frames per segon amb una tecla 2024-08-26 10:52:59 +02:00
4c2528ba93 Afegit input_showfps a la classe Input 2024-08-26 10:42:52 +02:00
65b8988ba2 Afegit comptador de frames per segon a la classe Screen 2024-08-26 10:18:06 +02:00
c7cc5df920 fix: el mode demo havia deixat de dir que era el mode demo per culpa de checkPlayersStatusPlaying() 2024-08-16 12:49:06 +02:00
89979a8ddb moguts els dos metodes per llegir i escriure la tabla de puntuacions a fitxer a la classe ManageHiScoreTable
el fitxer amb les puntuacions ara nomes es llig al carregar el programa i no cada volta que començem a jugar
2024-08-16 12:42:34 +02:00
7d778a9cfa ja guarda i carrega la tabla de records en el disc 2024-08-16 11:57:58 +02:00
9012e3d79d el sprite del jugador s'invertiex en funció de cap on camina quan dispara recte 2024-08-16 07:52:34 +02:00
b09f07ef40 afegit debug per avançar rapidet per les fases 2024-08-15 12:53:17 +02:00
448da70ba8 fix: la variable hiScore es reinicialitzava a 10000 en lloc de pillar la original de la tabla de records 2024-08-14 21:26:23 +02:00
24b4eaa972 fix: la variable score no s'inicialitzava 2024-08-14 21:17:28 +02:00
59da8fd4c6 actualitzades les dos variables hiScore a una de tipo hiScoreEntry_t 2024-08-14 20:57:22 +02:00
f64b461d75 afegit un guionet entre el nom i la puntuació de la máxima puntuació en el marcador 2024-08-14 20:56:50 +02:00
b9a15bd8b4 modificats els comentaris en main.cpp 2024-08-14 20:55:44 +02:00
924fd375ff fix: el truncat de la tabla de records estava "mal" en stack overflow. arreglat per mi llegint els hints de les funcions 2024-08-14 20:23:18 +02:00
e50e7affb3 de moment en la tabla de records posa el nom generic del jugador. Ja farem per a poder triar nom 2024-08-14 20:22:04 +02:00
032c5e7129 fix: el jugador sempre s'inicialitzava en el stat "playing" en lloc de "waiting", per tant, sempre jugaven tots els jugadors 2024-08-14 19:59:54 +02:00
1839df142d fix: trampa per arreglar en linux que una textura del logo no canvia de color i no se sap perque 2024-08-14 19:24:20 +02:00
35749f7c1b actualitzat Makefile 2024-08-14 19:12:44 +02:00
e48dbb2d4e fix: ja no es pot continuar quan els dos jugadors han acabat el compte enrrere per continuar 2024-08-14 14:16:12 +02:00
7e60a742ca acabats els nous estats dels jugadors 2024-08-14 14:09:54 +02:00
5c7bb842ec fix: faltava passar el nom dels jugadors al marcador 2024-08-14 14:09:28 +02:00
6a9d0d1b2c ja es poden passar les dades del jugador per a cada panell 2024-08-14 13:42:42 +02:00
f8b6d0524d primera implementació dels estats nous del jugador: playing, continue, waiting 2024-08-14 13:05:09 +02:00
90706d5d0c enmig del berenjenal d'afegir estats nous al jugador 2024-08-14 11:59:16 +02:00
c246472098 fix: els panels del marcador estiraven els bitmaps al no coincidir srcRect amb dstRect 2024-08-14 09:24:57 +02:00
45ed1106cb fix: ja torna a funcionar el cicle de música per les diferents seccions 2024-08-14 08:38:19 +02:00
a5a3bb23da 4 putes merdes que no han servit pa res. Au demà miraré qué passa 2024-08-13 23:01:48 +02:00
054950f1d8 fix: havia un punter no inicialitzava a nullptr i en macos no passava res, pero en linux i windows si 2024-08-13 20:44:23 +02:00
ba8e068b80 fix: fallava al parar la musica al morir el jugador en el mode de demostració 2024-08-13 19:25:12 +02:00
3f3242393e varios ajustos 2024-08-13 18:51:55 +02:00
a2ce1f0dc3 fix: havia dos formacions que no tenien ben asignada la y inicial 2024-08-13 18:28:05 +02:00
887e8a7071 fix: la variable ballonsPopped no estava inicialitzada i passaven coses rares 2024-08-13 17:50:59 +02:00
7ed0393a9b fix: corregit el tamany i la posició dels panells del marcador 2024-08-13 17:26:52 +02:00
e51e3a5c43 treballant en els panels del marcador 2024-08-13 14:25:07 +02:00
eb9eaec61d arreglos en la powerball:
- quan apareix al centro, pot anar cap a l'esquerra o cap a la dreta
 - ara apareix a la altura que li toca als globos grans
 - tarda en generarse igual que la resta de globos
 - rebota igual que els globos grans (com feia abans de canviar les físiques dels globos grans)
2024-08-13 11:29:13 +02:00
8c7ff13bc2 modificat Makefile 2024-08-13 07:27:18 +02:00
88fe1a29fe afegits dos descriptors a gamecontrollerdb.txt per als mandos RAP4 y MadCatz SFV PS4 per a Linux 2024-08-12 20:38:21 +02:00
e009349464 el borde de la powerball no era transparent quan el globo està creant-se 2024-08-12 14:23:40 +02:00
4d1f1d2bc2 continuem afegint descripcions de lo que fa cada classe 2024-08-12 14:16:24 +02:00
9d5aee2562 Afegides mes descripcions a les classes
Eliminat el punter a renderer de les classes-estat que faltava
2024-08-12 08:55:41 +02:00
477891cac7 Afegida la funció getRenderer() a la classe Screen per tal d'estalviar altre parametre mes a molts constructors de classes-estat de joc 2024-08-12 08:03:30 +02:00
45731c8294 Afegides descripcions a algunes classes
Eliminats parámetres no necesaris als constructors de classes
2024-08-12 07:57:59 +02:00
4df505d263 retocat el disseny del efecte de powerUp en el jugador 2024-08-03 19:19:20 +02:00
ffef64b4fd ajustat el rebot de balloon1 2024-08-03 19:18:42 +02:00
2358b8e914 actualitzat Makefile 2024-08-03 19:12:46 +02:00
1f4d7ce042 afegida la opció de controlar el autofire 2024-08-03 17:55:18 +02:00
657d43de5a modificats els parametres de velocitat dels globos 2024-08-03 17:55:02 +02:00
735e5299f9 nou grafic per a les bales 2024-08-03 17:19:05 +02:00
bca688a9a7 afegida opció per habilitar o deshabilitar el audio desde el teclat. De moment soles desde el joc. En poder ho integraré en jail_audio 2024-08-03 14:12:40 +02:00
ad2d1cbd65 afegit input_mute 2024-08-03 14:01:43 +02:00
958a4d1d99 afegides notificacions per als inputs externs al joc 2024-08-03 13:55:16 +02:00
256959505d afegides opcions per defecte per a les notificacions 2024-08-03 12:10:41 +02:00
770a4d5f96 afegida la classe Notify 2024-08-03 12:10:22 +02:00
d3a13af94f afegida estructura per a les notificacions 2024-08-03 12:09:57 +02:00
82cb28a13e afegida una segona funció SetPos a la classe Sprite que accepta SDL_Rect com a entrada 2024-08-03 12:09:25 +02:00
a1fb7500f0 afegida tecla de reset 2024-08-03 08:05:43 +02:00
9ad6001046 añadido a param.txt los parametros de los globos para velocidad y gravedad 2024-08-03 07:56:26 +02:00
8390dfd8be Merge branch 'main' of https://gitea.sustancia.synology.me/JailDesigner/coffee_crisis_arcade_edition 2024-07-31 14:11:59 +02:00
2abde3593b gràfics arreglats per als globos 2024-07-31 14:11:50 +02:00
60f8819331 fix: currentPower no estava inicialitzat i feia coses rares, entre elles petar
fix: corregit el tamany de la powerball
2024-07-30 18:29:46 +02:00
884cacbc2e tornem a deixar els fitxers balloon.png com estaven 2024-07-30 12:02:15 +02:00
f4484b24f1 afegida (altra volta) la classe Surface 2024-07-29 17:49:12 +02:00
7b7300fda5 afegida la classe EnemyFormations 2024-07-29 16:30:25 +02:00
af60e2e587 commit de merda pq no m'han deixat acabar 2024-07-29 14:06:22 +02:00
8d9d0eaaf3 modificada la classe balloon: eliminat el estat popping i dibuixat desde fitxers gif, pero no funciona el canvi de paleta 2024-07-28 18:08:40 +02:00
f1159f2bf3 canviat dos tipos de recursos en la classe Asset 2024-07-28 16:47:26 +02:00
7dbed9ab8e finalitzada la classe Explosions 2024-07-28 13:49:46 +02:00
59680ce7c0 afegida la classe Explosions 2024-07-28 12:46:26 +02:00
2948684ad3 eliminat el punter al renderer de 50.000 llocs 2024-07-28 10:45:14 +02:00
7501b4936f canviats els núvols per els del Volcano 2024-07-27 10:07:27 +02:00
fe361f455a refinaments estétics 2024-07-26 16:16:07 +02:00
0610389745 preliminar: afegit al marcador el mode game over 2024-07-26 12:18:36 +02:00
209 changed files with 13922 additions and 12837 deletions

2
.gitignore vendored
View File

@@ -14,3 +14,5 @@ thumbs.db
*config.bin
*score.bin
coffee_crisis*
debug.txt
cppcheck-result*

View File

@@ -24,16 +24,18 @@ INCLUDES:= -I$(DIR_SOURCES)
# Variables según el sistema operativo
ifeq ($(OS),Windows_NT)
FixPath = $(subst /,\,$1)
SOURCES := source/*.cpp source/common/*.cpp
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
CXXFLAGS2:= -std=c++11 -Wall -static-libstdc++
SOURCES := source/*.cpp
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
RM = del /Q
MKD:= mkdir
else
FixPath = $1
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections
SOURCES := source/*.cpp
CXXFLAGS:= -std=c++20 -Wall -Os -ffunction-sections -fdata-sections
CXXFLAGS_DEBUG:= -std=c++20 -Wall -g
LDFLAGS := -lSDL2
RM = rm -f
MKD:= mkdir -p
@@ -43,6 +45,7 @@ else
endif
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -Wno-deprecated
CXXFLAGS_DEBUG += -Wno-deprecated
LDFLAGS += -framework OpenGL
endif
endif
@@ -118,13 +121,12 @@ print-variables:
@echo RM: $(RM)
raspi3:
$(CXX) $(SOURCES) -D NO_SHADERS $(CXXFLAGS) -lSDL2 -o $(TARGET_FILE)
raspi:
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
raspi5:
$(CXX) $(SOURCES) -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(TARGET_FILE)
strip -s -R .comment -R .gnu.version $(TARGET_FILE) --strip-unneeded
raspi_debug:
$(CXX) $(SOURCES) -D ARCADE -D VERBOSE -D DEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
windows:
@echo off
@@ -137,7 +139,7 @@ windows_rec:
windows_debug:
@echo off
$(CXX) $(SOURCES) -D VERBOSE $(CXXFLAGS2) $(LDFLAGS) -o "$(TARGET_FILE)_debug.exe"
$(CXX) $(SOURCES) -D DEBUG -D VERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug.exe"
windows_release:
@echo off
@@ -168,11 +170,8 @@ windows_release:
macos:
$(CXX) $(SOURCES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
macos_fast:
$(CXX) $(SOURCES) -D VERBOSE -std=c++11 -Wall -Wno-deprecated -lSDL2 -framework OpenGL -o "$(TARGET_FILE)"
macos_debug:
$(CXX) $(SOURCES) -D DEBUG $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
$(CXX) $(SOURCES) -D DEBUG -D VERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
macos_release:
# Elimina datos de compilaciones anteriores
@@ -225,8 +224,7 @@ linux:
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded
linux_debug:
$(CXX) $(SOURCES) -D DEBUG $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)_debug" --strip-unneeded
$(CXX) $(SOURCES) -D DEBUG -D VERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
linux_release:
# Elimina carpetas previas
@@ -249,4 +247,18 @@ linux_release:
cd "$(RELEASE_FOLDER)" && tar -czvf "../$(LINUX_RELEASE)" *
# Elimina la carpeta temporal
$(RM) "$(RELEASE_FOLDER)"
$(RM) "$(RELEASE_FOLDER)"
anbernic:
# Elimina carpetas previas
$(RM) "$(RELEASE_FOLDER)"_anbernic
# Crea la carpeta temporal para realizar el lanzamiento
mkdir -p "$(RELEASE_FOLDER)"_anbernic
# Copia ficheros
cp -R data "$(RELEASE_FOLDER)"_anbernic
# Complia
$(CXX) $(SOURCES) -D ANBERNIC -D NO_SHADERS -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME)
$(CXX) $(SOURCES) -D ANBERNIC -D ARCADE -D VERBOSE $(CXXFLAGS) $(LDFLAGS) -o $(RELEASE_FOLDER)_anbernic/$(TARGET_NAME).shaders

View File

@@ -1,3 +1,14 @@
# JailDesigner - Custom mappings
# RAP4
030086650d0f00008c000000140100003853140,Generic X-Box pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
# Mad Catz FightStick Alpha PS4
03007fcb380700008081000011010000184833152,Mad Catz FightStick Alpha PS4,platform:Linux,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b13,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,
# Mando custom de Dani en madera + Agetec
030020617900000006000000100100001216,DragonRise Inc. Generic USB Joystick,platform:Linux,a:b2,b:b1,x:b0,y:b6,start:b5,leftx:a0,lefty:a1,
# Game Controller DB for SDL in 2.0.16 format
# Source: https://github.com/gabomdq/SDL_GameControllerDB

View File

@@ -1,30 +0,0 @@
# GAME
gameWidth 320
gameHeight 240
itemSize 20
# FADE
numSquaresWidth 160
numSquaresHeight 120
fadeRandomSquaresDelay 1
fadeRandomSquaresMult 500
fadePostDuration 80
venetianSize 16
# SCOREBOARD
scoreboard.x 0
scoreboard.y 200
scoreboard.w 320
scoreboard.h 40
# TITLE
pressStart 170
titleCounter 800
arcadeEdition 123
titleCC 80
# BACKGROUND
backgroundAttenuateColor.r 255
backgroundAttenuateColor.g 255
backgroundAttenuateColor.b 255
backgroundAttenuateColor.a 0

View File

@@ -0,0 +1,52 @@
## GAME
game.item_size 20
game.width 320
game.height 240
game.play_area.rect.x 0
game.play_area.rect.y 0
game.play_area.rect.w 320
game.play_area.rect.h 200
## FADE
fade.num_squares_width 160
fade.num_squares_height 120
fade.random_squares_delay 1
fade.random_squares_mult 500
fade.post_duration 80
fade.venetian_size 16
## SCOREBOARD
scoreboard.x 0
scoreboard.y 200
scoreboard.w 320
scoreboard.h 40
## TITLE
title.press_start_position 170
title.title_duration 800
title.arcade_edition_position 123
title.title_c_c_position 80
## BACKGROUND
background.attenuate_color.r 255
background.attenuate_color.g 255
background.attenuate_color.b 255
background.attenuate_alpha 0
## BALLOONS
balloon_1.vel 2.75f
balloon_1.grav 0.09f
balloon_2.vel 3.70f
balloon_2.grav 0.10f
balloon_3.vel 4.70f
balloon_3.grav 0.10f
balloon_4.vel 5.45f
balloon_4.grav 0.10f
## NOTIFICATION
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48

View File

@@ -0,0 +1,52 @@
## GAME
game.item_size 20
game.width 320
game.height 256
game.play_area.rect.x 0
game.play_area.rect.y 0
game.play_area.rect.w 320
game.play_area.rect.h 216
## FADE
fade.num_squares_width 160
fade.num_squares_height 128
fade.random_squares_delay 1
fade.random_squares_mult 500
fade.post_duration 80
fade.venetian_size 16
## SCOREBOARD
scoreboard.x 0
scoreboard.y 216
scoreboard.w 320
scoreboard.h 40
## TITLE
title.press_start_position 180
title.title_duration 800
title.arcade_edition_position 123
title.title_c_c_position 80
## BACKGROUND
background.attenuate_color.r 255
background.attenuate_color.g 255
background.attenuate_color.b 255
background.attenuate_alpha 0
## BALLOONS
balloon_1.vel 2.75f
balloon_1.grav 0.09f
balloon_2.vel 3.70f
balloon_2.grav 0.10f
balloon_3.vel 4.70f
balloon_3.grav 0.10f
balloon_4.vel 5.45f
balloon_4.grav 0.10f
## NOTIFICATION
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=10
frame_height=10
[animation]
name=orange
@@ -12,26 +12,19 @@ frames=0,1,2,3,4,5,6,7,8,9
name=blue
speed=20
loop=0
frames=12,13,14,15,16,17,18,19,20,21
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
loop=0
frames=24,25,26,27,28,29,30,31,32,33
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
loop=0
frames=36,37,38,39,40,41,42,43,44,45
[/animation]
[animation]
name=pop
speed=5
loop=-1
frames=48,49,50,51,52,53,54,55,56,57,58,59
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,5 +1,5 @@
frameWidth=13
frameHeight=13
frame_width=16
frame_height=16
[animation]
name=orange
@@ -12,26 +12,19 @@ frames=0,1,2,3,4,5,6,7,8,9
name=blue
speed=20
loop=0
frames=12,13,14,15,16,17,18,19,20,21
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
loop=0
frames=24,25,26,27,28,29,30,31,32,33
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
loop=0
frames=36,37,38,39,40,41,42,43,44,45
[/animation]
[animation]
name=pop
speed=5
loop=-1
frames=48,49,50,51,52,53,54,55,56,57,58,59
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -1,5 +1,5 @@
frameWidth=21
frameHeight=21
frame_width=26
frame_height=26
[animation]
name=orange
@@ -12,26 +12,19 @@ frames=0,1,2,3,4,5,6,7,8,9
name=blue
speed=20
loop=0
frames=12,13,14,15,16,17,18,19,20,21
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
loop=0
frames=24,25,26,27,28,29,30,31,32,33
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
loop=0
frames=36,37,38,39,40,41,42,43,44,45
[/animation]
[animation]
name=pop
speed=5
loop=-1
frames=48,49,50,51,52,53,54,55,56,57,58,59
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -0,0 +1,30 @@
frame_width=48
frame_height=48
[animation]
name=orange
speed=10
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
loop=0
frames=10,11,12,13,14,15,16,17,18,19
[/animation]
[animation]
name=green
speed=10
loop=0
frames=20,21,22,23,24,25,26,27,28,29
[/animation]
[animation]
name=red
speed=20
loop=0
frames=30,31,32,33,34,35,36,37,38,39
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,9 @@
frame_width=10
frame_height=10
[animation]
name=default
speed=5
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

View File

@@ -0,0 +1,9 @@
frame_width=16
frame_height=16
[animation]
name=default
speed=5
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,9 @@
frame_width=26
frame_height=26
[animation]
name=default
speed=5
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -0,0 +1,9 @@
frame_width=46
frame_height=46
[animation]
name=default
speed=5
loop=-1
frames=0,1,2,3,4,5,6,7,8,9
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,9 @@
frame_width=46
frame_height=46
[animation]
name=powerball
speed=10
loop=-1
frames=0
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -1,44 +0,0 @@
frameWidth=37
frameHeight=37
[animation]
name=orange
speed=10
loop=0
frames=0,1,2,3,4,5,6,7,8,9
[/animation]
[animation]
name=blue
speed=20
loop=0
frames=12,13,14,15,16,17,18,19,20,21
[/animation]
[animation]
name=green
speed=10
loop=0
frames=24,25,26,27,28,29,30,31,32,33
[/animation]
[animation]
name=red
speed=20
loop=0
frames=36,37,38,39,40,41,42,43,44,45
[/animation]
[animation]
name=powerball
speed=10
loop=0
frames=10
[/animation]
[animation]
name=pop
speed=5
loop=-1
frames=48,49,50,51,52,53,54,55,56,57,58,59
[/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 644 B

BIN
data/gfx/bullet/bullet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 935 B

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -1,5 +1,5 @@
frameWidth=20
frameHeight=20
frame_width=20
frame_height=20
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

View File

@@ -1,5 +1,5 @@
frameWidth=20
frameHeight=20
frame_width=20
frame_height=20
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 623 B

After

Width:  |  Height:  |  Size: 623 B

View File

@@ -1,5 +1,5 @@
frameWidth=28
frameHeight=37
frame_width=28
frame_height=37
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 835 B

After

Width:  |  Height:  |  Size: 835 B

View File

@@ -1,5 +1,5 @@
frameWidth=20
frameHeight=20
frame_width=20
frame_height=20
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 336 B

After

Width:  |  Height:  |  Size: 336 B

View File

@@ -1,5 +1,5 @@
frameWidth=20
frameHeight=20
frame_width=20
frame_height=20
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 506 B

After

Width:  |  Height:  |  Size: 506 B

View File

@@ -1,5 +1,5 @@
frameWidth=20
frameHeight=20
frame_width=20
frame_height=20
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 492 B

After

Width:  |  Height:  |  Size: 492 B

View File

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

View File

Before

Width:  |  Height:  |  Size: 561 B

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -1,5 +1,5 @@
frameWidth=30
frameHeight=30
frame_width=30
frame_height=30
[animation]
name=walk

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 173 B

View File

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 173 B

View File

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 173 B

View File

Before

Width:  |  Height:  |  Size: 772 B

After

Width:  |  Height:  |  Size: 772 B

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

View File

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 172 B

View File

Before

Width:  |  Height:  |  Size: 772 B

After

Width:  |  Height:  |  Size: 772 B

View File

@@ -1,5 +1,5 @@
frameWidth=35
frameHeight=40
frame_width=39
frame_height=44
[animation]
name=default

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

Before

Width:  |  Height:  |  Size: 212 B

After

Width:  |  Height:  |  Size: 212 B

View File

@@ -278,4 +278,70 @@ DEIXA BUIT PER A
MODE FORA DE LINEA
## 93 - MENU OPCIONES
TAULER DE PUNTS
TAULER DE PUNTS
## 94 - NOTIFICACIONES
Torna a polsar per eixir ...
## 95 - DEFINE BUTTONS
Disparar cap a l'esquerra
## 96 - DEFINE BUTTONS
Disparar cap amunt
## 97 - DEFINE BUTTONS
Disparar cap a la dreta
## 98 - DEFINE BUTTONS
Start
## 99 - DEFINE BUTTONS
Servei
## 100 - DEFINE BUTTONS
Jugador
## 101 - MARCADOR
Mode demostracio
## 102 - MARCADOR
Game Over
## 103 - MARCADOR
Pulsa START
## 104 - MARCADOR
per jugar
## 105 - MARCADOR
Continuar?
## 106 - MARCADOR
Posa el nom
## 107 - AJUDA
Intercanviar mandos
## 108 - AJUDA
Configuracio
## 109 - AJUDA
Alternar el audio
## 110 - AJUDA
Filtres
## 111 - AJUDA
Reiniciar
## 112 - AJUDA
Pausar
## 113 - AJUDA
Eixir
## 114 - MARCADOR
Per favor
## 115 - MARCADOR
espere

View File

@@ -278,4 +278,70 @@ LEAVE BLANK FOR
OFFLINE MODE
## 93 - MENU OPCIONES
HISCORE TABLE
HISCORE TABLE
## 94 - NOTIFICACIONES
Press again to quit
## 95 - DEFINE BUTTONS
Fire left
## 96 - DEFINE BUTTONS
Fire up
## 97 - DEFINE BUTTONS
Fire right
## 98 - DEFINE BUTTONS
Start
## 99 - DEFINE BUTTONS
Service
## 100 - DEFINE BUTTONS
Player
## 101 - MARCADOR
Demo mode
## 102 - MARCADOR
Game Over
## 103 - MARCADOR
Press START
## 104 - MARCADOR
to play
## 105 - MARCADOR
Continue?
## 106 - MARCADOR
Enter name
## 107 - AJUDA
Swap Controllers
## 108 - AJUDA
Configuration
## 109 - AJUDA
Toggle audio
## 110 - AJUDA
Shaders
## 111 - AJUDA
Reset
## 112 - AJUDA
Pause
## 113 - AJUDA
Exit
## 114 - MARCADOR
Please
## 115 - MARCADOR
wait

View File

@@ -278,4 +278,70 @@ DEJA EN BLANCO PARA
MODO SIN CONEXION
## 93 - MENU OPCIONES
TABLA DE PUNTUACIONES
TABLA DE PUNTUACIONES
## 94 - NOTIFICACIONES
Pulsa otra vez para salir
## 95 - DEFINE BUTTONS
Disparar a la izquierda
## 96 - DEFINE BUTTONS
Disparar hacia arriba
## 97 - DEFINE BUTTONS
Disparar hacia la derecha
## 98 - DEFINE BUTTONS
Start
## 99 - DEFINE BUTTONS
Servicio
## 100 - DEFINE BUTTONS
Jugador
## 101 - MARCADOR
Mode demostracion
## 102 - MARCADOR
Game Over
## 103 - MARCADOR
Pulsa START
## 104 - MARCADOR
para jugar
## 105 - MARCADOR
Continuar?
## 106 - MARCADOR
Pon tu nombre
## 107 - AJUDA
Intercambiar mandos
## 108 - AJUDA
Configuracion
## 109 - AJUDA
Alternar el audio
## 110 - AJUDA
Filtros
## 111 - AJUDA
Reiniciar
## 112 - AJUDA
Pausar
## 113 - AJUDA
Salir
## 114 - MARCADOR
Por favor
## 115 - MARCADOR
espere

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -97,7 +97,8 @@ void main()
#if defined(CURVATURE)
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
#endif
filterWidth = (768.0 / 240.0) / 3.0;
//filterWidth = (768.0 / 240.0) / 3.0;
filterWidth = (768.0 / 256.0) / 3.0;
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
@@ -146,7 +147,7 @@ float CalcScanLine(float dy)
void main()
{
vec2 TextureSize = vec2(320.0, 240.0);
vec2 TextureSize = vec2(320.0, 256.0);
#if defined(CURVATURE)
vec2 texcoord = Distort(TEX0);
if (texcoord.x < 0.0)

Binary file not shown.

Binary file not shown.

10
linux-utils/check-includes.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
SOURCEPATH=../source/
for i in "$SOURCEPATH"/*.cpp
do
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
read -p "Presiona cualquier tecla para continuar..."
clear
done

6
linux-utils/go.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
SECONDS=0
make linux_debug
duration=$SECONDS
echo "$((duration / 60)) minutes and $((duration % 60)) seconds elapsed."

BIN
linux-utils/include-what-you-use Executable file

Binary file not shown.

View File

@@ -0,0 +1,3 @@
#!/bin/bash
valgrind --suppressions=valgrind_exceptions --leak-check=full ~/coffee_crisis_arcade_edition/coffee_crisis_arcade_edition_debug > ~/coffee_crisis_arcade_edition/debug.txt 2>&1

View File

@@ -0,0 +1,12 @@
{
ignore_unversioned_libs
Memcheck:Leak
...
obj:*/lib*/lib*.so
}
{
ignore_versioned_libs
Memcheck:Leak
...
obj:*/lib*/lib*.so.*
}

View File

@@ -1,37 +1,48 @@
#include "animatedsprite.h"
#include "animated_sprite.h"
#include <algorithm> // for copy
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
#include <iostream> // for cout
#include <iterator> // for back_insert_iterator, back_inserter
#include <sstream> // for basic_stringstream
#include "texture.h" // for Texture
// Carga la animación desde un fichero
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string file_path)
{
// Inicializa variables
animatedSprite_t as;
as.texture = texture;
int framesPerRow = 0;
int frameWidth = 0;
int frameHeight = 0;
int maxTiles = 0;
AnimatedFile af;
af.texture = texture;
auto frames_per_row = 0;
auto frame_width = 0;
auto frame_height = 0;
auto max_tiles = 0;
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
std::ifstream file(filePath);
#ifdef VERBOSE
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
#endif
std::ifstream file(file_path);
std::string line;
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
if (verbose)
{
std::cout << "Animation loaded: " << filename << std::endl;
}
#ifdef VERBOSE
std::cout << "Animation loaded: " << file_name << std::endl;
#endif
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]")
{
animation_t buffer;
Animation buffer;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.current_frame = 0;
buffer.completed = false;
buffer.name.clear();
buffer.speed = 5;
buffer.loop = 0;
buffer.frames.clear();
do
{
@@ -41,7 +52,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
int pos = line.find("=");
// Procesa las dos subcadenas
if (pos != (int)line.npos)
if (pos != static_cast<int>(line.npos))
{
if (line.substr(0, pos) == "name")
{
@@ -63,26 +74,28 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
// Se introducen los valores separados por comas en un vector
std::stringstream ss(line.substr(pos + 1, line.length()));
std::string tmp;
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
SDL_Rect rect = {0, 0, frame_width, frame_height};
while (getline(ss, tmp, ','))
{
// Comprueba que el tile no sea mayor que el maximo indice permitido
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
rect.x = (numTile % framesPerRow) * frameWidth;
rect.y = (numTile / framesPerRow) * frameHeight;
const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : 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
{
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
#ifdef VERBOSE
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
#endif
}
}
} while (line != "[/animation]");
// Añade la animación al vector de animaciones
as.animations.push_back(buffer);
af.animations.push_back(buffer);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -94,37 +107,39 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
// Procesa las dos subcadenas
if (pos != (int)line.npos)
{
if (line.substr(0, pos) == "framesPerRow")
if (line.substr(0, pos) == "frames_per_row")
{
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frameWidth")
else if (line.substr(0, pos) == "frame_width")
{
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
frame_width = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frameHeight")
else if (line.substr(0, pos) == "frame_height")
{
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
frame_height = std::stoi(line.substr(pos + 1, line.length()));
}
else
{
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
#ifdef VERBOSE
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
#endif
}
// Normaliza valores
if (framesPerRow == 0 && frameWidth > 0)
if (frames_per_row == 0 && frame_width > 0)
{
framesPerRow = texture->getWidth() / frameWidth;
frames_per_row = texture->getWidth() / frame_width;
}
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
{
const int w = texture->getWidth() / frameWidth;
const int h = texture->getHeight() / frameHeight;
maxTiles = w * h;
const auto w = texture->getWidth() / frame_width;
const auto h = texture->getHeight() / frame_height;
max_tiles = w * h;
}
}
}
@@ -136,76 +151,55 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
// El fichero no se puede abrir
else
{
if (verbose)
{
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
}
#ifdef VERBOSE
std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
#endif
}
return as;
return af;
}
// Constructor
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
: MovingSprite(texture),
current_animation_(0)
{
// Copia los punteros
setTexture(texture);
setRenderer(renderer);
// Carga las animaciones
if (file != "")
if (!file.empty())
{
animatedSprite_t as = loadAnimationFromFile(texture, file);
AnimatedFile as = loadAnimationFromFile(texture, file);
// Copia los datos de las animaciones
for (auto animation : as.animations)
{
this->animation.push_back(animation);
}
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
}
else if (buffer)
{
loadFromVector(buffer);
}
// Inicializa variables
currentAnimation = 0;
}
// Constructor
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
: MovingSprite(animation->texture),
current_animation_(0)
{
// Copia los punteros
setTexture(animation->texture);
setRenderer(renderer);
// Inicializa variables
currentAnimation = 0;
// Copia los datos de las animaciones
for (auto a : animation->animations)
{
this->animation.push_back(a);
}
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
}
// Destructor
AnimatedSprite::~AnimatedSprite()
{
for (auto &a : animation)
{
a.frames.clear();
}
animation.clear();
animations_.clear();
}
// Obtiene el indice de la animación a partir del nombre
int AnimatedSprite::getIndex(std::string name)
int AnimatedSprite::getIndex(const std::string &name)
{
int index = -1;
auto index = -1;
for (auto a : animation)
for (const auto &a : animations_)
{
index++;
if (a.name == name)
@@ -213,147 +207,147 @@ int AnimatedSprite::getIndex(std::string name)
return index;
}
}
#ifdef VERBOSE
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
#endif
return -1;
}
// Calcula el frame correspondiente a la animación
void AnimatedSprite::animate()
{
if (!enabled || animation[currentAnimation].speed == 0)
if (animations_[current_animation_].speed == 0)
{
return;
}
// Calcula el frame actual a partir del contador
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
// Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop y coloca el nuevo frame
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
if (animations_[current_animation_].current_frame >= (int)animations_[current_animation_].frames.size())
{
if (animation[currentAnimation].loop == -1)
if (animations_[current_animation_].loop == -1)
{ // Si no hay loop, deja el último frame
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
animation[currentAnimation].completed = true;
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
animations_[current_animation_].completed = true;
}
else
{ // Si hay loop, vuelve al frame indicado
animation[currentAnimation].counter = 0;
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
animations_[current_animation_].counter = 0;
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
}
}
// En caso contrario
else
{
// Escoge el frame correspondiente de la animación
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
// Incrementa el contador de la animacion
animation[currentAnimation].counter++;
animations_[current_animation_].counter++;
}
}
// Obtiene el número de frames de la animación actual
int AnimatedSprite::getNumFrames()
{
return (int)animation[currentAnimation].frames.size();
return (int)animations_[current_animation_].frames.size();
}
// Establece el frame actual de la animación
void AnimatedSprite::setCurrentFrame(int num)
{
// Descarta valores fuera de rango
if (num >= (int)animation[currentAnimation].frames.size())
if (num >= (int)animations_[current_animation_].frames.size())
{
num = 0;
}
// Cambia el valor de la variable
animation[currentAnimation].currentFrame = num;
animation[currentAnimation].counter = 0;
animations_[current_animation_].current_frame = num;
animations_[current_animation_].counter = 0;
// Escoge el frame correspondiente de la animación
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
// Establece el valor del contador
void AnimatedSprite::setAnimationCounter(std::string name, int num)
void AnimatedSprite::setAnimationCounter(const std::string &name, int num)
{
animation[getIndex(name)].counter = num;
animations_[getIndex(name)].counter = num;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
void AnimatedSprite::setAnimationSpeed(const std::string &name, int speed)
{
animation[getIndex(name)].counter = speed;
animations_[getIndex(name)].counter = speed;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(int index, int speed)
{
animation[index].counter = speed;
animations_[index].counter = speed;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
void AnimatedSprite::setAnimationLoop(const std::string &name, int loop)
{
animation[getIndex(name)].loop = loop;
animations_[getIndex(name)].loop = loop;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(int index, int loop)
{
animation[index].loop = loop;
animations_[index].loop = loop;
}
// Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
void AnimatedSprite::setAnimationCompleted(const std::string &name, bool value)
{
animation[getIndex(name)].completed = value;
animations_[getIndex(name)].completed = value;
}
// OLD - Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(int index, bool value)
{
animation[index].completed = value;
animations_[index].completed = value;
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::animationIsCompleted()
{
return animation[currentAnimation].completed;
return animations_[current_animation_].completed;
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
SDL_Rect AnimatedSprite::getAnimationClip(const std::string &name, Uint8 index)
{
return animation[getIndex(name)].frames[index];
return animations_[getIndex(name)].frames[index];
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
{
return animation[indexA].frames[indexF];
return animations_[indexA].frames[indexF];
}
// Carga la animación desde un vector
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
{
// Inicializa variables
int framesPerRow = 0;
int frameWidth = 0;
int frameHeight = 0;
int maxTiles = 0;
auto frames_per_row = 0;
auto frame_width = 0;
auto frame_height = 0;
auto max_tiles = 0;
// Indicador de éxito en el proceso
bool success = true;
auto success = true;
std::string line;
// Recorre todo el vector
int index = 0;
auto index = 0;
while (index < (int)source->size())
{
// Lee desde el vector
@@ -362,10 +356,14 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
animation_t buffer;
Animation buffer;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.current_frame = 0;
buffer.completed = false;
buffer.name.clear();
buffer.speed = 5;
buffer.loop = 0;
buffer.frames.clear();
do
{
@@ -377,7 +375,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
int pos = line.find("=");
// Procesa las dos subcadenas
if (pos != (int)line.npos)
if (pos != static_cast<int>(line.npos))
{
if (line.substr(0, pos) == "name")
{
@@ -399,27 +397,29 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
// 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, frameWidth, frameHeight};
SDL_Rect rect = {0, 0, frame_width, frame_height};
while (getline(ss, tmp, ','))
{
// Comprueba que el tile no sea mayor que el maximo indice permitido
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
rect.x = (numTile % framesPerRow) * frameWidth;
rect.y = (numTile / framesPerRow) * frameHeight;
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : 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
{
#ifdef VERBOSE
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
#endif
success = false;
}
}
} while (line != "[/animation]");
// Añade la animación al vector de animaciones
animation.push_back(buffer);
animations_.push_back(buffer);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -431,38 +431,40 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
// Procesa las dos subcadenas
if (pos != (int)line.npos)
{
if (line.substr(0, pos) == "framesPerRow")
if (line.substr(0, pos) == "frames_per_row")
{
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frameWidth")
else if (line.substr(0, pos) == "frame_width")
{
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
frame_width = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frameHeight")
else if (line.substr(0, pos) == "frame_height")
{
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
frame_height = std::stoi(line.substr(pos + 1, line.length()));
}
else
{
#ifdef VERBOSE
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
#endif
success = false;
}
// Normaliza valores
if (framesPerRow == 0 && frameWidth > 0)
if (frames_per_row == 0 && frame_width > 0)
{
framesPerRow = texture->getWidth() / frameWidth;
frames_per_row = texture_->getWidth() / frame_width;
}
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
{
const int w = texture->getWidth() / frameWidth;
const int h = texture->getHeight() / frameHeight;
maxTiles = w * h;
const int w = texture_->getWidth() / frame_width;
const int h = texture_->getHeight() / frame_height;
max_tiles = w * h;
}
}
}
@@ -472,34 +474,34 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
}
// Pone un valor por defecto
setRect({0, 0, frameWidth, frameHeight});
setPos((SDL_Rect){0, 0, frame_width, frame_height});
return success;
}
// Establece la animacion actual
void AnimatedSprite::setCurrentAnimation(std::string name)
void AnimatedSprite::setCurrentAnimation(const std::string &name)
{
const int newAnimation = getIndex(name);
if (currentAnimation != newAnimation)
const auto new_animation = getIndex(name);
if (current_animation_ != new_animation)
{
currentAnimation = newAnimation;
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
current_animation_ = new_animation;
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false;
}
}
// Establece la animacion actual
void AnimatedSprite::setCurrentAnimation(int index)
{
const int newAnimation = index;
if (currentAnimation != newAnimation)
const auto new_animation = index;
if (current_animation_ != new_animation)
{
currentAnimation = newAnimation;
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
current_animation_ = new_animation;
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false;
}
}
@@ -513,13 +515,13 @@ void AnimatedSprite::update()
// 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)
{
animation[index_animation].frames.push_back({x, y, w, h});
animations_[index_animation].frames.push_back({x, y, w, h});
}
// OLD - Establece el contador para todas las animaciones
void AnimatedSprite::setAnimationCounter(int value)
{
for (auto &a : animation)
for (auto &a : animations_)
{
a.counter = value;
}
@@ -528,7 +530,7 @@ void AnimatedSprite::setAnimationCounter(int value)
// Reinicia la animación
void AnimatedSprite::resetAnimation()
{
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false;
}

View File

@@ -1,47 +1,47 @@
#pragma once
#include <SDL2/SDL.h>
#include "movingsprite.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_stdinc.h> // for Uint8
#include <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "moving_sprite.h" // for MovingSprite
class Texture;
struct animation_t
struct Animation
{
std::string name; // Nombre de la animacion
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
int speed; // Velocidad de la animación
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
bool completed; // Indica si ha finalizado la animación
int currentFrame; // Frame actual
int current_frame; // Frame actual
int counter; // Contador para las animaciones
};
struct animatedSprite_t
struct AnimatedFile
{
std::vector<animation_t> animations; // Vector con las diferentes animaciones
Texture *texture; // Textura con los graficos para el sprite
std::vector<Animation> animations; // Vector con las diferentes animaciones
std::shared_ptr<Texture> texture; // Textura con los graficos para el sprite
};
// Carga la animación desde un fichero
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false);
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string filePath);
class AnimatedSprite : public MovingSprite
{
private:
protected:
// Variables
std::vector<animation_t> animation; // Vector con las diferentes animaciones
int currentAnimation; // Animacion activa
std::vector<Animation> animations_; // Vector con las diferentes animaciones
int current_animation_; // Animacion activa
public:
// Constructor
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string> *buffer = nullptr);
explicit AnimatedSprite(const AnimatedFile *animation);
// Destructor
~AnimatedSprite();
virtual ~AnimatedSprite();
// Calcula el frame correspondiente a la animación actual
void animate();
@@ -53,39 +53,39 @@ public:
void setCurrentFrame(int num);
// Establece el valor del contador
void setAnimationCounter(std::string name, int num);
void setAnimationCounter(const std::string &name, int num);
// Establece la velocidad de una animación
void setAnimationSpeed(std::string name, int speed);
void setAnimationSpeed(const std::string &name, int speed);
void setAnimationSpeed(int index, int speed);
// Establece el frame al que vuelve la animación al finalizar
void setAnimationLoop(std::string name, int loop);
void setAnimationLoop(const std::string &name, int loop);
void setAnimationLoop(int index, int loop);
// Establece el valor de la variable
void setAnimationCompleted(std::string name, bool value);
void setAnimationCompleted(const std::string &name, bool value);
void setAnimationCompleted(int index, bool value);
// Comprueba si ha terminado la animación
bool animationIsCompleted();
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
SDL_Rect getAnimationClip(const std::string &name = "default", Uint8 index = 0);
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
// Obtiene el indice de la animación a partir del nombre
int getIndex(std::string name);
int getIndex(const std::string &name);
// Carga la animación desde un vector
bool loadFromVector(std::vector<std::string> *source);
// Establece la animacion actual
void setCurrentAnimation(std::string name = "default");
void setCurrentAnimation(const std::string &name = "default");
void setCurrentAnimation(int index = 0);
// Actualiza las variables del objeto
void update();
void update() override;
// 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);

207
source/asset.cpp Normal file
View File

@@ -0,0 +1,207 @@
#include "asset.h"
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWops
#include <SDL2/SDL_stdinc.h> // for SDL_max
#include <stddef.h> // for size_t
#include <iostream> // for basic_ostream, operator<<, cout, endl
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Asset *Asset::asset_ = nullptr;
// [SINGLETON] Crearemos el objeto asset con esta función estática
void Asset::init(const std::string &executable_path)
{
Asset::asset_ = new Asset(executable_path);
}
// [SINGLETON] Destruiremos el objeto asset con esta función estática
void Asset::destroy()
{
delete Asset::asset_;
}
// [SINGLETON] Con este método obtenemos el objeto asset y podemos trabajar con él
Asset *Asset::get()
{
return Asset::asset_;
}
// Constructor
Asset::Asset(const std::string &executable_path)
: executable_path_(executable_path.substr(0, executable_path.find_last_of("\\/")))
{
longest_name_ = 0;
}
// Añade un elemento a la lista
void Asset::add(const std::string &file, AssetType type, bool required, bool absolute)
{
AssetItem ai;
ai.file = absolute ? file : executable_path_ + file;
ai.type = type;
ai.required = required;
file_list_.push_back(ai);
const std::string file_name = file.substr(file.find_last_of("\\/") + 1);
longest_name_ = SDL_max(longest_name_, file_name.size());
}
// Devuelve el fichero de un elemento de la lista a partir de una cadena
std::string Asset::get(const std::string &text) const
{
for (const auto &f : file_list_)
{
const size_t last_index = f.file.find_last_of("/") + 1;
const std::string file = f.file.substr(last_index, std::string::npos);
if (file == text)
{
return f.file;
}
}
#ifdef VERBOSE
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
#endif
return "";
}
// Comprueba que existen todos los elementos
bool Asset::check() const
{
bool success = true;
#ifdef VERBOSE
std::cout << "\n** Checking files" << std::endl;
std::cout << "Executable path is: " << executable_path_ << std::endl;
std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
#endif
// Comprueba la lista de ficheros clasificandolos por tipo
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
{
// Comprueba si hay ficheros de ese tipo
bool any = false;
for (const auto &f : file_list_)
{
if (f.required && f.type == static_cast<AssetType>(type))
{
any = true;
}
}
// Si hay ficheros de ese tipo, comprueba si existen
if (any)
{
#ifdef VERBOSE
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
#endif
for (const auto &f : file_list_)
{
if (f.required && f.type == static_cast<AssetType>(type))
{
success &= checkFile(f.file);
}
}
}
}
// Resultado
#ifdef VERBOSE
std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl;
#endif
return success;
}
// Comprueba que existe un fichero
bool Asset::checkFile(const std::string &path) const
{
auto success = false;
// Comprueba si existe el fichero
auto file = SDL_RWFromFile(path.c_str(), "rb");
if (file)
{
success = true;
SDL_RWclose(file);
}
#ifdef VERBOSE
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
std::cout.setf(std::ios::left, std::ios::adjustfield);
std::cout << "Checking file: ";
std::cout.width(longest_name_ + 2);
std::cout.fill('.');
std::cout << file_name;
std::cout << (success ? " [OK]" : " [ERROR]") << std::endl;
#endif
return success;
}
// Devuelve el nombre del tipo de recurso
std::string Asset::getTypeName(AssetType type) const
{
switch (type)
{
case AssetType::BITMAP:
return "BITMAP";
break;
case AssetType::MUSIC:
return "MUSIC";
break;
case AssetType::SOUND:
return "SOUND";
break;
case AssetType::FONT:
return "FONT";
break;
case AssetType::LANG:
return "LANG";
break;
case AssetType::DATA:
return "DATA";
break;
case AssetType::ANIMATION:
return "ANIMATION";
break;
case AssetType::PALETTE:
return "PALETTE";
break;
case AssetType::ITEM:
return "ITEM";
break;
default:
return "ERROR";
break;
}
}
// Devuelve la lista de recursos de un tipo
std::vector<std::string> Asset::getListByType(AssetType type) const
{
std::vector<std::string> list;
for (auto f : file_list_)
{
if (f.type == type)
{
list.push_back(f.file);
}
}
return list;
}

74
source/asset.h Normal file
View File

@@ -0,0 +1,74 @@
#pragma once
#include <string> // for string, basic_string
#include <vector> // for vector
enum class AssetType : int
{
BITMAP,
MUSIC,
SOUND,
FONT,
LANG,
DATA,
ANIMATION,
PALETTE,
ITEM,
MAX_ASSET_TYPE,
};
// Clase Asset
class Asset
{
private:
// [SINGLETON] Objeto asset privado para Don Melitón
static Asset *asset_;
// Estructura para definir un item
struct AssetItem
{
std::string file; // Ruta del fichero desde la raiz del directorio
enum AssetType type; // Indica el tipo de recurso
bool required; // Indica si es un fichero que debe de existir
// bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
};
// Variables
int longest_name_; // Contiene la longitud del nombre de fichero mas largo
std::vector<AssetItem> file_list_; // Listado con todas las rutas a los ficheros
std::string executable_path_; // Ruta al ejecutable
// Comprueba que existe un fichero
bool checkFile(const std::string &path) const;
// Devuelve el nombre del tipo de recurso
std::string getTypeName(AssetType type) const;
// Constructor
explicit Asset(const std::string &executable_path);
// Destructor
~Asset() = default;
public:
// [SINGLETON] Crearemos el objeto screen con esta función estática
static void init(const std::string &executable_path);
// [SINGLETON] Destruiremos el objeto screen con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
static Asset *get();
// Añade un elemento a la lista
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
// Devuelve un elemento de la lista a partir de una cadena
std::string get(const std::string &text) const;
// Comprueba que existen todos los elementos
bool check() const;
// Devuelve la lista de recursos de un tipo
std::vector<std::string> getListByType(AssetType type) const;
};

View File

@@ -1,279 +1,325 @@
#include "background.h"
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <algorithm> // for clamp, max
#include "asset.h" // for Asset
#include "moving_sprite.h" // for MovingSprite
#include "param.h" // for param
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
// Constructor
Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param)
Background::Background(SDL_Renderer *renderer)
: renderer_(renderer),
buildings_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"))),
top_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"))),
bottom_clouds_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"))),
grass_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"))),
gradients_texture_(std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png")))
{
// Copia los punteros
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->param = param;
// Inicializa variables
gradientNumber = 0;
alpha = 0;
cloudsSpeed = 0;
transition = 0;
counter = 0;
rect = {0, 0, param->gameWidth, param->gameHeight};
srcRect = {playArea.x, rect.h - playArea.h, playArea.w, playArea.h};
dstRect = {0, 0, playArea.w, playArea.h};
base = rect.h;
color = {param->backgroundAttenuateColor.r, param->backgroundAttenuateColor.g, param->backgroundAttenuateColor.b};
alphaColorText = alphaColorTextTemp = param->backgroundAttenuateAlpha;
gradient_number_ = 0;
alpha_ = 0;
clouds_speed_ = 0;
transition_ = 0;
counter_ = 0;
gradientRect[0] = {0, 0, rect.w, rect.h};
gradientRect[1] = {rect.w, 0, rect.w, rect.h};
gradientRect[2] = {0, rect.h, rect.w, rect.h};
gradientRect[3] = {rect.w, rect.h, rect.w, rect.h};
rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2};
src_rect_ = {0, 0, 320, 240};
dst_rect_ = {0, 0, 320, 240};
// Carga las texturas
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
cloudsTexture = new Texture(renderer, asset->get("game_clouds.png"));
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
base_ = rect_.h;
color_ = {param.background.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4;
const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4;
for (int i = 0; i < 4; ++i)
{
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height};
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height};
}
// Crea los sprites
const int cloudsHeight = base - 196;
clouds1A = new MovingSprite(0, cloudsHeight, rect.w, 52, -0.4f, 0.0f, 0.0f, 0.0f, cloudsTexture, renderer);
clouds1B = new MovingSprite(rect.w, cloudsHeight, rect.w, 52, -0.4f, 0.0f, 0.0f, 0.0f, cloudsTexture, renderer);
clouds2A = new MovingSprite(0, cloudsHeight + 57, rect.w, 32, -0.2f, 0.0f, 0.0f, 0.0f, cloudsTexture, renderer);
clouds2B = new MovingSprite(rect.w, cloudsHeight + 57, rect.w, 32, -0.2f, 0.0f, 0.0f, 0.0f, cloudsTexture, renderer);
const int top_clouds_y = base_ - 165;
const int bottom_clouds_y = base_ - 101;
constexpr float top_clouds_speed = 0.1f;
constexpr float bottom_clouds_speed = 0.05f;
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
buildingsSprite = new Sprite(0, 0, rect.w, 135, buildingsTexture, renderer);
gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture, renderer);
grassSprite = new Sprite(0, 0, 320, 10, grassTexture, renderer);
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
buildings_sprite_ = std::make_unique<Sprite>(0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight(), buildings_texture_);
gradient_sprite_ = std::make_unique<Sprite>(0, 0, rect_.w, rect_.h, gradients_texture_);
grass_sprite_ = std::make_unique<Sprite>(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_);
// Inicializa objetos
clouds1A->setSpriteClip(0, 0, cloudsTexture->getWidth(), 52);
clouds1B->setSpriteClip(0, 0, cloudsTexture->getWidth(), 52);
clouds2A->setSpriteClip(0, 52, cloudsTexture->getWidth(), 32);
clouds2B->setSpriteClip(0, 52, cloudsTexture->getWidth(), 32);
buildingsSprite->setPosY(base - buildingsSprite->getHeight());
grassSprite->setPosY(base - grassSprite->getHeight());
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight());
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight());
// Crea la textura para componer el fondo
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
// Crea la textura para atenuar el fondo
colorText = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
SDL_SetTextureBlendMode(colorText, SDL_BLENDMODE_BLEND);
setColor(color);
SDL_SetTextureAlphaMod(colorText, alphaColorText);
color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
setColor(color_);
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
}
// Destructor
Background::~Background()
{
buildingsTexture->unload();
delete buildingsTexture;
cloudsTexture->unload();
delete cloudsTexture;
grassTexture->unload();
delete grassTexture;
gradientsTexture->unload();
delete gradientsTexture;
delete clouds1A;
delete clouds1B;
delete clouds2A;
delete clouds2B;
delete buildingsSprite;
delete gradientSprite;
delete grassSprite;
SDL_DestroyTexture(canvas);
SDL_DestroyTexture(colorText);
SDL_DestroyTexture(canvas_);
SDL_DestroyTexture(color_texture_);
}
// Actualiza la lógica del objeto
void Background::update()
{
// Actualiza el valor de alpha
// Actualiza el valor de alpha_
updateAlphaColorText();
// Actualiza las nubes
updateCLouds();
updateClouds();
// Calcula el frame de la hierba
grassSprite->setSpriteClip(0, (10 * (counter / 20 % 2)), 320, 10);
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
// Calcula el valor de alpha
alpha = std::max((255 - (int)(255 * transition)), 0);
// Calcula el valor de alpha_
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
// Incrementa el contador
counter++;
counter_++;
// Compone todos los elementos del fondo en la textura
fillCanvas();
}
// Dibuja el gradiente de fondo
void Background::renderGradient()
{
// Dibuja el gradiente de detras
gradients_texture_->setAlpha(255);
gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]);
gradient_sprite_->render();
// Dibuja el gradiente de delante con una opacidad cada vez menor
gradients_texture_->setAlpha(alpha_);
gradient_sprite_->setSpriteClip(gradient_rect_[gradient_number_]);
gradient_sprite_->render();
}
// Dibuja las nubes de arriba
void Background::renderTopClouds()
{
// Dibuja el primer conjunto de nubes, las de detras
top_clouds_texture_->setAlpha(255);
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
top_clouds_sprite_a_->render();
top_clouds_sprite_b_->render();
// Dibuja el segundo conjunto de nubes, las de delante
top_clouds_texture_->setAlpha(alpha_);
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[gradient_number_]);
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[gradient_number_]);
top_clouds_sprite_a_->render();
top_clouds_sprite_b_->render();
}
// Dibuja las nubes de abajo
void Background::renderBottomClouds()
{
// Dibuja el primer conjunto de nubes, las de detras
bottom_clouds_texture_->setAlpha(255);
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
bottom_clouds_sprite_a_->render();
bottom_clouds_sprite_b_->render();
// Dibuja el segundo conjunto de nubes, las de delante
bottom_clouds_texture_->setAlpha(alpha_);
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
bottom_clouds_sprite_a_->render();
bottom_clouds_sprite_b_->render();
}
// Compone todos los elementos del fondo en la textura
void Background::fillCanvas()
{
// Cambia el destino del renderizador
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
SDL_SetRenderTarget(renderer, canvas);
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, canvas_);
// Dibuja el gradiente 2
gradientSprite->setSpriteClip(gradientRect[(gradientNumber + 1) % 4]);
gradientsTexture->setAlpha(255);
gradientSprite->render();
// Dibuja el gradiente de fondo
renderGradient();
// Dibuja el gradiente 1 con una opacidad cada vez menor
gradientSprite->setSpriteClip(gradientRect[gradientNumber]);
gradientsTexture->setAlpha(alpha);
gradientSprite->render();
// Dibuja las nubes de arriba
renderTopClouds();
// Dibuja las nubes
clouds1A->render();
clouds1B->render();
clouds2A->render();
clouds2B->render();
// Dibuja las nubes de abajo
renderBottomClouds();
// Dibuja los edificios
buildingsSprite->render();
buildings_sprite_->render();
// Dibuja la hierba
grassSprite->render();
grass_sprite_->render();
// Deja el renderizador apuntando donde estaba
SDL_SetRenderTarget(renderer, temp);
SDL_SetRenderTarget(renderer_, temp);
}
// Dibuja el objeto
void Background::render()
{
// Fondo
SDL_RenderCopy(renderer, canvas, &srcRect, &dstRect);
SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_);
// Atenuación
SDL_RenderCopy(renderer, colorText, &srcRect, &dstRect);
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
}
// Vuelve a cargar las texturas
void Background::reloadTextures()
{
buildingsTexture->reLoad();
cloudsTexture->reLoad();
grassTexture->reLoad();
gradientsTexture->reLoad();
buildings_texture_->reLoad();
top_clouds_texture_->reLoad();
bottom_clouds_texture_->reLoad();
grass_texture_->reLoad();
gradients_texture_->reLoad();
}
// Ajusta el valor de la variable
void Background::setCloudsSpeed(float value)
{
cloudsSpeed = value;
clouds_speed_ = value;
}
// Ajusta el valor de la variable
void Background::setGradientNumber(int value)
{
gradientNumber = value % 4;
gradient_number_ = value % 4;
}
// Ajusta el valor de la variable
void Background::setTransition(float value)
{
transition = value;
transition_ = std::clamp(value, 0.0f, 1.0f);
}
// Establece la posición del objeto
void Background::setPos(SDL_Rect rect)
void Background::setPos(SDL_Rect pos)
{
dstRect = rect;
dst_rect_ = pos;
// Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen
srcRect.w = rect.w;
srcRect.h = rect.h;
src_rect_.x = 0;
src_rect_.y = rect_.h - pos.h;
src_rect_.w = pos.w;
src_rect_.h = pos.h;
}
// Ajusta el valor de la variable
void Background::setSrcDest(SDL_Rect value)
void Background::setSrcRect(SDL_Rect value)
{
srcRect = value;
src_rect_ = value;
}
// Ajusta el valor de la variable
void Background::setDstDest(SDL_Rect value)
void Background::setDstRect(SDL_Rect value)
{
dstRect = value;
dst_rect_ = value;
}
// Establece el color de atenuación
void Background::setColor(color_t color)
// Establece el color_ de atenuación
void Background::setColor(Color color)
{
this->color = color;
color_ = color;
// Colorea la textura
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
SDL_SetRenderTarget(renderer, colorText);
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, color_texture_);
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255);
SDL_RenderClear(renderer_);
SDL_SetRenderTarget(renderer, temp);
SDL_SetRenderTarget(renderer_, temp);
}
// Establece la transparencia de la atenuación
void Background::setAlpha(int alpha)
{
// Guarda el valor actual
alphaColorTextTemp = alphaColorText;
// Evita que se asignen valores fuera de rango
alpha_ = std::clamp(alpha, 0, 255);
// Establece el nuevo valor
alphaColorText = alpha;
// Guarda el valor actual y establece el nuevo valor
alpha_color_text_temp_ = alpha_color_text_;
alpha_color_text_ = alpha_;
}
// Actualiza el valor de alpha
// Actualiza el valor de alpha_
void Background::updateAlphaColorText()
{
if (alphaColorText == alphaColorTextTemp)
if (alpha_color_text_ == alpha_color_text_temp_)
{
return;
}
else
{
alphaColorText > alphaColorTextTemp ? alphaColorTextTemp++ : alphaColorTextTemp--;
SDL_SetTextureAlphaMod(colorText, alphaColorTextTemp);
alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_;
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_);
}
}
// Actualiza las nubes
void Background::updateCLouds()
void Background::updateClouds()
{
// Aplica la velocidad calculada a las nubes
clouds1A->setVelX(cloudsSpeed);
clouds1B->setVelX(cloudsSpeed);
clouds2A->setVelX(cloudsSpeed / 2);
clouds2B->setVelX(cloudsSpeed / 2);
top_clouds_sprite_a_->setVelX(clouds_speed_);
top_clouds_sprite_b_->setVelX(clouds_speed_);
bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2);
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
// Mueve las nubes
clouds1A->move();
clouds1B->move();
clouds2A->move();
clouds2B->move();
top_clouds_sprite_a_->move();
top_clouds_sprite_b_->move();
bottom_clouds_sprite_a_->move();
bottom_clouds_sprite_b_->move();
// Calcula el offset de las nubes
if (clouds1A->getPosX() < -clouds1A->getWidth())
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())
{
clouds1A->setPosX(clouds1A->getWidth());
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
}
if (clouds1B->getPosX() < -clouds1B->getWidth())
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth())
{
clouds1B->setPosX(clouds1B->getWidth());
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
}
if (clouds2A->getPosX() < -clouds2A->getWidth())
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth())
{
clouds2A->setPosX(clouds2A->getWidth());
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
}
if (clouds2B->getPosX() < -clouds2B->getWidth())
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth())
{
clouds2B->setPosX(clouds2B->getWidth());
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
}
}

View File

@@ -1,99 +1,147 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/screen.h"
#include "common/asset.h"
#include "common/movingsprite.h"
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <memory> // for unique_ptr, shared_ptr
#include "utils.h" // for Color
class MovingSprite;
class Sprite;
class Texture;
/*
Esta clase es la encargada de dibujar el fondo que aparece durante la sección
jugable.
Utiliza una textura donde compone la imagen y luego tiene una textura superior
rellena de un color sólido cuya opacidad se puede modificar.
El objeto tiene un tamaño total definido en la variable "rect". En principio este
tamaño coincide con el tamaño de la ventana o resolución del juego, pero se pinta
solo el rectangulo definido en srcRect en la posición de la pantalla definida en
dstRect.
Ambos rectangulos han de coincidir en tamaño y por definición, el punto comun es el inferior derecho el rectangulo.
Utiliza varios métodos para definir su comportamiento:
- setCloudsSpeed(float value)
Velocidad a la que se desplazan las nubes cada frame
- setGradientNumber(int value)
Escoge el índice de la textura de fondo a usar (el color del cielo)
- setTransition(float value)
Porcentaje (entre 0.0f (textura actual) y 1.0f (textura siguiente)) para mostrar entre la textura de fondo actual y la siguiente
- setSrcRect(SDL_Rect value)
Rectangulo de la textura de fondo que se desea mostrar
- setDstRecr(SDL_Rect value)
Rectangulo de destino donde se mostrará el rectángulo antrior. Automaticamente modifica srcRect para coincidor en tamaño con el destino.
- setColor(Color color)
Establece el color de la textura de superposición
- setAlpha(int alpha)
Establece la transparencia de la textura de superposición
*/
// Clase Background
class Background
{
private:
// Objetos y punteros
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
// Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana
Texture *buildingsTexture; // Textura con los edificios de fondo
Texture *cloudsTexture; // Textura con las nubes de fondo
Texture *grassTexture; // Textura con la hierba del suelo
Texture *gradientsTexture; // Textura con los diferentes colores de fondo del juego
std::shared_ptr<Texture> buildings_texture_; // Textura con los edificios de fondo
std::shared_ptr<Texture> top_clouds_texture_; // Textura con las nubes de fondo
std::shared_ptr<Texture> bottom_clouds_texture_; // Textura con las nubes de fondo
std::shared_ptr<Texture> grass_texture_; // Textura con la hierba del suelo
std::shared_ptr<Texture> gradients_texture_; // Textura con los diferentes colores de fondo del juego
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
std::unique_ptr<MovingSprite> top_clouds_sprite_a_; // Sprite para las nubes superiores
std::unique_ptr<MovingSprite> top_clouds_sprite_b_; // Sprite para las nubes superiores
std::unique_ptr<MovingSprite> bottom_clouds_sprite_a_; // Sprite para las nubes inferiores
std::unique_ptr<MovingSprite> bottom_clouds_sprite_b_; // Sprite para las nubes inferiores
Sprite *buildingsSprite; // Sprite con los edificios de fondo
Sprite *gradientSprite; // Sprite con los graficos del degradado de color de fondo
Sprite *grassSprite; // Sprite para la hierba
std::unique_ptr<Sprite> buildings_sprite_; // Sprite con los edificios de fondo
std::unique_ptr<Sprite> gradient_sprite_; // Sprite con los graficos del degradado de color de fondo
std::unique_ptr<Sprite> grass_sprite_; // Sprite para la hierba
SDL_Texture *canvas; // Textura para componer el fondo
SDL_Texture *colorText; // Textura para atenuar el fondo
SDL_Texture *canvas_; // Textura para componer el fondo
SDL_Texture *color_texture_; // Textura para atenuar el fondo
param_t *param; // Puntero con todos los parametros del programa
// Variables
SDL_Rect gradient_rect_[4]; // Vector con las coordenadas de los 4 degradados para el cielo
SDL_Rect top_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de arriba
SDL_Rect bottom_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de abajo
int gradient_number_; // Indica el número de degradado de fondo que se va a dibujar
int alpha_; // Transparencia entre los dos degradados
float clouds_speed_; // Velocidad a la que se desplazan las nubes
float transition_; // Nivel de transición del fondo 0..1
int counter_; // Contador interno
SDL_Rect rect_; // Tamaño del objeto fondo
SDL_Rect src_rect_; // Parte del objeto fondo que se va a dibujará en pantalla
SDL_Rect dst_rect_; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla
int base_; // Linea de fondo coincidente con el area inferior de la zona de juego
Color color_; // Color para atenuar el fondo
int alpha_color_text_; // Alpha para atenuar el fondo
int alpha_color_text_temp_; // Valor temporal para hacer la transición de alpha
// Variables
SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 degradados para el cielo
int gradientNumber; // Indica el número de degradado de fondo que se va a dibujar
int alpha; // Transparencia entre los dos degradados
float cloudsSpeed; // Velocidad a la que se desplazan las nubes
float transition; // Nivel de transición del fondo 0..1
int counter; // Contador interno
SDL_Rect rect; // Tamaño del objeto fondo
SDL_Rect srcRect; // Parte del objeto fondo que se va a dibujará en pantalla
SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla
int base; // Linea de fondo coincidente con el area inferior de la zona de juego
color_t color; // Color para atenuar el fondo
int alphaColorText; // Alpha para atenuar el fondo
int alphaColorTextTemp; // Valor temporal para hacer la transición de alpha
// Dibuja el gradiente de fondo
void renderGradient();
// Compone todos los elementos del fondo en la textura
void fillCanvas();
// Dibuja las nubes de arriba
void renderTopClouds();
// Actualiza el valor de alpha
void updateAlphaColorText();
// Dibuja las nubes de abajo
void renderBottomClouds();
// Actualiza las nubes
void updateCLouds();
// Compone todos los elementos del fondo en la textura
void fillCanvas();
// Actualiza el valor de alpha
void updateAlphaColorText();
// Actualiza las nubes
void updateClouds();
public:
// Constructor
Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t *param);
// Constructor
explicit Background(SDL_Renderer *renderer);
// Destructor
~Background();
// Destructor
~Background();
// Actualiza la lógica del objeto
void update();
// Actualiza la lógica del objeto
void update();
// Dibuja el objeto
void render();
// Dibuja el objeto
void render();
// Establece la posición del objeto
void setPos(SDL_Rect);
// Establece la posición del objeto
void setPos(SDL_Rect pos);
// Vuelve a cargar las texturas
void reloadTextures();
// Vuelve a cargar las texturas
void reloadTextures();
// Ajusta el valor de la variable
void setCloudsSpeed(float value);
// Ajusta el valor de la variable
void setCloudsSpeed(float value);
// Ajusta el valor de la variable
void setGradientNumber(int value);
// Ajusta el valor de la variable
void setGradientNumber(int value);
// Ajusta el valor de la variable
void setTransition(float value);
// Ajusta el valor de la variable
void setTransition(float value);
// Ajusta el valor de la variable
void setSrcDest(SDL_Rect value);
// Ajusta el valor de la variable
void setSrcRect(SDL_Rect value);
// Ajusta el valor de la variable
void setDstDest(SDL_Rect value);
// Ajusta el valor de la variable
void setDstRect(SDL_Rect value);
// Establece el color de atenuación
void setColor(color_t color);
// Establece el color de atenuación
void setColor(Color color);
// Establece la transparencia de la atenuación
void setAlpha(int alpha);
// Establece la transparencia de la atenuación
void setAlpha(int alpha);
};

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More