Compare commits
18 Commits
2025-02-07
...
059a9c863a
| Author | SHA1 | Date | |
|---|---|---|---|
| 059a9c863a | |||
| be857cc8c8 | |||
| 482dc3de54 | |||
| 9d98d3ea6a | |||
| 9c1b3c45b0 | |||
| 79b2917112 | |||
| c88a277cba | |||
| e0c10f83d6 | |||
| 72cb39da78 | |||
| 9f8d1fbcd7 | |||
| e523692e99 | |||
| 83bdd67cee | |||
| 66e5105c84 | |||
| f8449ea6d1 | |||
| f43d18e6f0 | |||
| a42141ebd7 | |||
| 29c85fecad | |||
| 04ff428aa0 |
@@ -3,6 +3,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(coffee_crisis_arcade_edition VERSION 0.01)
|
project(coffee_crisis_arcade_edition VERSION 0.01)
|
||||||
|
|
||||||
|
# Establece las políticas
|
||||||
|
cmake_policy(SET CMP0072 NEW)
|
||||||
|
|
||||||
# Configuración de compilador para MinGW en Windows, si es necesario
|
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||||
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
set(CMAKE_CXX_COMPILER "g++")
|
set(CMAKE_CXX_COMPILER "g++")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Coffee Crisis Arcade Edition és una versió ampliada i millorada del aclamat Co
|
|||||||
Defensa el teu cafè contra les bambolles gegants en aquest trepidant joc d'arcade! 🍵
|
Defensa el teu cafè contra les bambolles gegants en aquest trepidant joc d'arcade! 🍵
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://php.sustancia.synology.me/images/ccae_title.png" alt="Títol" width="60%" />
|
<img src="https://php.sustancia.synology.me/images/ccae/ccae_title.png" alt="Títol" width="60%" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Controls
|
## Controls
|
||||||
@@ -25,8 +25,8 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
|
|||||||
> Nota: El joc suporta nomes un jugador amb teclat.
|
> Nota: El joc suporta nomes un jugador amb teclat.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://php.sustancia.synology.me/images/ccae1.png" alt="Joc" width="45%" />
|
<img src="https://php.sustancia.synology.me/images/ccae/ccae1.png" alt="Joc" width="45%" />
|
||||||
<img src="https://php.sustancia.synology.me/images/ccae3.png" alt="Joc" width="45%" />
|
<img src="https://php.sustancia.synology.me/images/ccae/ccae3.png" alt="Joc" width="45%" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Altres tecles
|
## Altres tecles
|
||||||
@@ -44,7 +44,7 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
|
|||||||
| **F10** | Reset del joc |
|
| **F10** | Reset del joc |
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://php.sustancia.synology.me/images/ccae2.png" alt="Joc" width="50%" />
|
<img src="https://php.sustancia.synology.me/images/ccae/ccae2.png" alt="Joc" width="50%" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Com instal·lar i jugar
|
## Com instal·lar i jugar
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 13 KiB |
BIN
data/gfx/intro/intro1.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
data/gfx/intro/intro2.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
data/gfx/intro/intro3.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
data/gfx/intro/intro4.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
data/gfx/intro/intro5.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
data/gfx/intro/intro6.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
@@ -372,3 +372,12 @@ MUSICA COMPOSADA PER
|
|||||||
|
|
||||||
## 124 - CREDITS
|
## 124 - CREDITS
|
||||||
EFECTES DE SO
|
EFECTES DE SO
|
||||||
|
|
||||||
|
## 125 - NOTIFICACIONES
|
||||||
|
Torna a polsar per reiniciar
|
||||||
|
|
||||||
|
## 126 - NOTIFICACIONES
|
||||||
|
Torna a polsar per canviar el idioma a
|
||||||
|
|
||||||
|
## 127 - NOTIFICACIONES
|
||||||
|
Idioma canviat a
|
||||||
@@ -372,3 +372,12 @@ MUSIC COMPOSED BY
|
|||||||
|
|
||||||
## 124 - CREDITS
|
## 124 - CREDITS
|
||||||
SOUND EFFECTS
|
SOUND EFFECTS
|
||||||
|
|
||||||
|
## 125 - NOTIFICACIONES
|
||||||
|
Press again to reset
|
||||||
|
|
||||||
|
## 126 - NOTIFICACIONES
|
||||||
|
Press again to change languaje to
|
||||||
|
|
||||||
|
## 127 - NOTIFICACIONES
|
||||||
|
Language set to
|
||||||
@@ -372,3 +372,12 @@ MUSICA COMPUESTA POR
|
|||||||
|
|
||||||
## 124 - CREDITS
|
## 124 - CREDITS
|
||||||
EFECTOS DE SONIDO
|
EFECTOS DE SONIDO
|
||||||
|
|
||||||
|
## 125 - NOTIFICACIONES
|
||||||
|
Vuelve a pulsar para reiniciar
|
||||||
|
|
||||||
|
## 126 - NOTIFICACIONES
|
||||||
|
Vuelve a pulsar para cambiar el idioma a
|
||||||
|
|
||||||
|
## 127 - NOTIFICACIONES
|
||||||
|
Idioma cambiado a
|
||||||
@@ -56,13 +56,13 @@ private:
|
|||||||
~Asset() = default;
|
~Asset() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
static void init(const std::string &executable_path);
|
static void init(const std::string &executable_path);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
static Asset *get();
|
static Asset *get();
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
|
|||||||
@@ -226,16 +226,6 @@ void Background::render()
|
|||||||
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
|
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a cargar las texturas
|
|
||||||
void Background::reloadTextures()
|
|
||||||
{
|
|
||||||
buildings_texture_->reLoad();
|
|
||||||
top_clouds_texture_->reLoad();
|
|
||||||
bottom_clouds_texture_->reLoad();
|
|
||||||
grass_texture_->reLoad();
|
|
||||||
gradients_texture_->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void Background::setCloudsSpeed(float value)
|
void Background::setCloudsSpeed(float value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -131,9 +131,6 @@ public:
|
|||||||
// Establece la posición del objeto
|
// Establece la posición del objeto
|
||||||
void setPos(SDL_Rect pos);
|
void setPos(SDL_Rect pos);
|
||||||
|
|
||||||
// Vuelve a cargar las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
// Ajusta el valor de la variable
|
// Ajusta el valor de la variable
|
||||||
void setCloudsSpeed(float value);
|
void setCloudsSpeed(float value);
|
||||||
|
|
||||||
|
|||||||
@@ -370,15 +370,6 @@ void BalloonManager::normalColorsToAllBalloons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void BalloonManager::reLoad()
|
|
||||||
{
|
|
||||||
for (auto &texture : balloon_textures_)
|
|
||||||
{
|
|
||||||
texture->reLoad();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea dos globos gordos
|
// Crea dos globos gordos
|
||||||
void BalloonManager::createTwoBigBalloons()
|
void BalloonManager::createTwoBigBalloons()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,9 +104,6 @@ public:
|
|||||||
// Cambia el color de todos los globos
|
// Cambia el color de todos los globos
|
||||||
void normalColorsToAllBalloons();
|
void normalColorsToAllBalloons();
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void reLoad();
|
|
||||||
|
|
||||||
// Crea dos globos gordos
|
// Crea dos globos gordos
|
||||||
void createTwoBigBalloons();
|
void createTwoBigBalloons();
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,14 @@
|
|||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // Para basic_string, string
|
#include <string> // Para basic_string, string
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
#include <array> // Para vector
|
||||||
#include "balloon_manager.h" // Para BalloonManager
|
#include "balloon_manager.h" // Para BalloonManager
|
||||||
#include "fade.h" // Para Fade, FadeType, FadeMode
|
#include "fade.h" // Para Fade, FadeType, FadeMode
|
||||||
#include "global_inputs.h" // Para check, update
|
#include "global_inputs.h" // Para check, update
|
||||||
#include "input.h" // Para Input
|
#include "input.h" // Para Input
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume
|
#include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "mouse.h" // Para handleEvent
|
#include "global_events.h" // Para handleEvent
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "player.h" // Para Player, PlayerState
|
#include "player.h" // Para Player, PlayerState
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
@@ -128,22 +129,11 @@ void Credits::render()
|
|||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Credits::checkEvents()
|
void Credits::checkEvents()
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
// Comprueba los eventos que hay en la cola
|
{
|
||||||
while (SDL_PollEvent(&event))
|
globalEvents::check(event);
|
||||||
{
|
}
|
||||||
// Evento de salida de la aplicación
|
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
@@ -177,7 +167,7 @@ void Credits::fillTextTexture()
|
|||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||||
SDL_RenderClear(Screen::get()->getRenderer());
|
SDL_RenderClear(Screen::get()->getRenderer());
|
||||||
|
|
||||||
std::vector<std::string> texts = {
|
const std::array<std::string, 10> TEXTS = {
|
||||||
lang::getText(121),
|
lang::getText(121),
|
||||||
lang::getText(122),
|
lang::getText(122),
|
||||||
lang::getText(123),
|
lang::getText(123),
|
||||||
@@ -189,50 +179,50 @@ void Credits::fillTextTexture()
|
|||||||
"WWW.KENNEY.NL",
|
"WWW.KENNEY.NL",
|
||||||
"JAILDOCTOR"};
|
"JAILDOCTOR"};
|
||||||
|
|
||||||
const int space_post_title = 3 + text->getCharacterSize();
|
const int SPACE_POST_TITLE = 3 + text->getCharacterSize();
|
||||||
const int space_pre_title = text->getCharacterSize() * 4;
|
const int SPACE_PRE_TITLE = text->getCharacterSize() * 4;
|
||||||
const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title;
|
const int TEXTS_HEIGHT = 1 * text->getCharacterSize() + 7 * SPACE_POST_TITLE + 3 * SPACE_PRE_TITLE;
|
||||||
credits_rect_dst_.h = credits_rect_src_.h = texts_height;
|
credits_rect_dst_.h = credits_rect_src_.h = TEXTS_HEIGHT;
|
||||||
|
|
||||||
int y = (param.game.height - texts_height) / 2;
|
int y = (param.game.height - TEXTS_HEIGHT) / 2;
|
||||||
y = 0;
|
y = 0;
|
||||||
text->setPalette(1);
|
text->setPalette(1);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(0), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(0), 1, no_color, 1, shdw_txt_color);
|
||||||
|
|
||||||
text->setPalette(0);
|
text->setPalette(0);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, no_color, 1, shdw_txt_color);
|
||||||
|
|
||||||
y += space_pre_title;
|
y += SPACE_PRE_TITLE;
|
||||||
text->setPalette(1);
|
text->setPalette(1);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(1), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(1), 1, no_color, 1, shdw_txt_color);
|
||||||
text->setPalette(0);
|
text->setPalette(0);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, no_color, 1, shdw_txt_color);
|
||||||
|
|
||||||
y += space_pre_title;
|
y += SPACE_PRE_TITLE;
|
||||||
text->setPalette(1);
|
text->setPalette(1);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(2), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(2), 1, no_color, 1, shdw_txt_color);
|
||||||
text->setPalette(0);
|
text->setPalette(0);
|
||||||
|
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(5), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(5), 1, no_color, 1, shdw_txt_color);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(6), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(6), 1, no_color, 1, shdw_txt_color);
|
||||||
|
|
||||||
y += space_pre_title;
|
y += SPACE_PRE_TITLE;
|
||||||
text->setPalette(1);
|
text->setPalette(1);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(3), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(3), 1, no_color, 1, shdw_txt_color);
|
||||||
text->setPalette(0);
|
text->setPalette(0);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(7), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(7), 1, no_color, 1, shdw_txt_color);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(8), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(8), 1, no_color, 1, shdw_txt_color);
|
||||||
y += space_post_title;
|
y += SPACE_POST_TITLE;
|
||||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(9), 1, no_color, 1, shdw_txt_color);
|
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(9), 1, no_color, 1, shdw_txt_color);
|
||||||
|
|
||||||
// Mini logo
|
// Mini logo
|
||||||
y += space_pre_title;
|
y += SPACE_PRE_TITLE;
|
||||||
mini_logo_rect_src_.y = y;
|
mini_logo_rect_src_.y = y;
|
||||||
auto mini_logo_sprite = std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"));
|
auto mini_logo_sprite = std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"));
|
||||||
mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y);
|
mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y);
|
||||||
|
|||||||
@@ -62,32 +62,11 @@ void DefineButtons::bindButtons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void DefineButtons::checkEvents()
|
void DefineButtons::checkEvents(const SDL_Event &event)
|
||||||
{
|
{
|
||||||
if (enabled_)
|
if (enabled_ && event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
doControllerButtonDown(event.cbutton);
|
||||||
|
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(&event))
|
|
||||||
{
|
|
||||||
switch (event.type)
|
|
||||||
{
|
|
||||||
case SDL_QUIT:
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDL_CONTROLLERBUTTONDOWN:
|
|
||||||
{
|
|
||||||
doControllerButtonDown(event.cbutton);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void checkEvents();
|
void checkEvents(const SDL_Event &event);
|
||||||
|
|
||||||
// Habilita el objeto
|
// Habilita el objeto
|
||||||
bool enable(int index);
|
bool enable(int index);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ Director::Director(int argc, const char *argv[])
|
|||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
#else // NORMAL GAME
|
#else // NORMAL GAME
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
|
section::options = section::Options::NONE;
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -97,6 +98,7 @@ void Director::init()
|
|||||||
|
|
||||||
// Inicializa y crea el resto de objetos
|
// Inicializa y crea el resto de objetos
|
||||||
initSDL();
|
initSDL();
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
initJailAudio();
|
initJailAudio();
|
||||||
dbg_init(renderer_);
|
dbg_init(renderer_);
|
||||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||||
@@ -303,12 +305,12 @@ bool Director::initSDL()
|
|||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
|
|
||||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||||
options.video.window.max_size = std::min(DM.w / param.game.width, DM.h / param.game.height);
|
options.video.window.max_zoom = std::min(DM.w / param.game.width, DM.h / param.game.height);
|
||||||
options.video.window.size = std::min(options.video.window.size, options.video.window.max_size);
|
options.video.window.zoom = std::min(options.video.window.zoom, options.video.window.max_zoom);
|
||||||
|
|
||||||
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
|
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
|
||||||
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||||
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.size << std::endl;
|
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.zoom << std::endl;
|
||||||
|
|
||||||
// Establece el filtro de la textura
|
// Establece el filtro de la textura
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||||
@@ -316,15 +318,13 @@ bool Director::initSDL()
|
|||||||
std::cout << "Warning: texture filtering not enabled!\n";
|
std::cout << "Warning: texture filtering not enabled!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: opengl not enabled!\n";
|
std::cout << "Warning: opengl not enabled!\n";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_HIDDEN);
|
||||||
if (!window_)
|
if (!window_)
|
||||||
{
|
{
|
||||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
@@ -339,10 +339,8 @@ bool Director::initSDL()
|
|||||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
// La aceleración se activa según el define
|
// La aceleración se activa según el define
|
||||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||||
#endif
|
|
||||||
|
|
||||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||||
|
|
||||||
@@ -356,6 +354,7 @@ bool Director::initSDL()
|
|||||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||||
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
||||||
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||||
|
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode));
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +476,12 @@ void Director::setFileList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ // Intro
|
{ // Intro
|
||||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
Asset::get()->add(prefix + "/data/gfx/intro/intro1.png", AssetType::BITMAP);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/intro/intro2.png", AssetType::BITMAP);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/intro/intro3.png", AssetType::BITMAP);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/intro/intro4.png", AssetType::BITMAP);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/intro/intro5.png", AssetType::BITMAP);
|
||||||
|
Asset::get()->add(prefix + "/data/gfx/intro/intro6.png", AssetType::BITMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Logo
|
{ // Logo
|
||||||
@@ -553,7 +557,9 @@ void Director::setFileList()
|
|||||||
|
|
||||||
// Si falta algun fichero, sale del programa
|
// Si falta algun fichero, sale del programa
|
||||||
if (!Asset::get()->check())
|
if (!Asset::get()->check())
|
||||||
|
{
|
||||||
throw std::runtime_error("Falta algun fichero");
|
throw std::runtime_error("Falta algun fichero");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ EnterName::EnterName()
|
|||||||
void EnterName::init(const std::string &name)
|
void EnterName::init(const std::string &name)
|
||||||
{
|
{
|
||||||
// No se pasa ningún nombre
|
// No se pasa ningún nombre
|
||||||
if (name == "")
|
if (name.empty())
|
||||||
{
|
{
|
||||||
name_ = "A";
|
name_ = "A";
|
||||||
position_ = 0;
|
position_ = 0;
|
||||||
@@ -24,7 +24,7 @@ void EnterName::init(const std::string &name)
|
|||||||
{
|
{
|
||||||
name_ = name;
|
name_ = name;
|
||||||
position_ = name_.length();
|
position_ = name_.length();
|
||||||
position_overflow_ = position_ >= NAME_LENGHT ? true : false;
|
position_overflow_ = position_ >= MAX_NAME_LENGHT ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el vector de indices con el nombre y espacios
|
// Inicializa el vector de indices con el nombre y espacios
|
||||||
@@ -42,15 +42,15 @@ void EnterName::incPosition()
|
|||||||
|
|
||||||
++position_;
|
++position_;
|
||||||
|
|
||||||
if (position_ >= NAME_LENGHT)
|
if (position_ >= MAX_NAME_LENGHT)
|
||||||
{
|
{
|
||||||
position_ = NAME_LENGHT; // Mantenemos en el índice máximo válido.
|
position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido.
|
||||||
position_overflow_ = true; // Activamos el flag de overflow.
|
position_overflow_ = true; // Activamos el flag de overflow.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Copiamos el índice del carácter anterior si es posible.
|
// Copiamos el índice del carácter anterior si es posible.
|
||||||
if (position_ > 0 && position_ < NAME_LENGHT)
|
if (position_ > 0 && position_ < MAX_NAME_LENGHT)
|
||||||
{
|
{
|
||||||
character_index_[position_] = character_index_[position_ - 1];
|
character_index_[position_] = character_index_[position_ - 1];
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ void EnterName::decPosition()
|
|||||||
{
|
{
|
||||||
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
|
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
|
||||||
position_overflow_ = false;
|
position_overflow_ = false;
|
||||||
position_ = NAME_LENGHT - 1;
|
position_ = MAX_NAME_LENGHT - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ void EnterName::decPosition()
|
|||||||
--position_;
|
--position_;
|
||||||
|
|
||||||
// Limpiamos el carácter siguiente si el índice es válido.
|
// Limpiamos el carácter siguiente si el índice es válido.
|
||||||
if (position_ + 1 < NAME_LENGHT)
|
if (position_ + 1 < MAX_NAME_LENGHT)
|
||||||
{
|
{
|
||||||
character_index_[position_ + 1] = 0;
|
character_index_[position_ + 1] = 0;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ void EnterName::decPosition()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
|
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
|
||||||
if (position_ < NAME_LENGHT)
|
if (position_ < MAX_NAME_LENGHT)
|
||||||
{
|
{
|
||||||
position_overflow_ = false;
|
position_overflow_ = false;
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,6 @@ void EnterName::decPosition()
|
|||||||
updateNameFromCharacterIndex();
|
updateNameFromCharacterIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Incrementa el índice
|
// Incrementa el índice
|
||||||
void EnterName::incIndex()
|
void EnterName::incIndex()
|
||||||
{
|
{
|
||||||
@@ -139,7 +138,7 @@ void EnterName::decIndex()
|
|||||||
void EnterName::updateNameFromCharacterIndex()
|
void EnterName::updateNameFromCharacterIndex()
|
||||||
{
|
{
|
||||||
name_.clear();
|
name_.clear();
|
||||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
for (int i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||||
{
|
{
|
||||||
name_.push_back(character_list_[character_index_[i]]);
|
name_.push_back(character_list_[character_index_[i]]);
|
||||||
}
|
}
|
||||||
@@ -150,13 +149,13 @@ void EnterName::updateNameFromCharacterIndex()
|
|||||||
void EnterName::initCharacterIndex(const std::string &name)
|
void EnterName::initCharacterIndex(const std::string &name)
|
||||||
{
|
{
|
||||||
// Rellena de espacios
|
// Rellena de espacios
|
||||||
for (size_t i = 0; i < NAME_LENGHT; ++i)
|
for (size_t i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||||
{
|
{
|
||||||
character_index_[i] = 0;
|
character_index_[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coloca los índices en función de los caracteres que forman el nombre
|
// Coloca los índices en función de los caracteres que forman el nombre
|
||||||
for (size_t i = 0; i < name.substr(0, NAME_LENGHT).size(); ++i)
|
for (size_t i = 0; i < name.substr(0, MAX_NAME_LENGHT).size(); ++i)
|
||||||
{
|
{
|
||||||
character_index_[i] = findIndex(name.at(i));
|
character_index_[i] = findIndex(name.at(i));
|
||||||
}
|
}
|
||||||
@@ -166,7 +165,11 @@ void EnterName::initCharacterIndex(const std::string &name)
|
|||||||
int EnterName::findIndex(char character) const
|
int EnterName::findIndex(char character) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < character_list_.size(); ++i)
|
for (size_t i = 0; i < character_list_.size(); ++i)
|
||||||
|
{
|
||||||
if (character == character_list_.at(i))
|
if (character == character_list_.at(i))
|
||||||
|
{
|
||||||
return i;
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
constexpr int NAME_LENGHT = 6;
|
constexpr int MAX_NAME_LENGHT = 6;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Un array, "characterList", contiene la lista de caracteres
|
Un array, "characterList", contiene la lista de caracteres
|
||||||
@@ -17,11 +17,11 @@ constexpr int NAME_LENGHT = 6;
|
|||||||
class EnterName
|
class EnterName
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||||
std::string name_; // Nombre introducido
|
std::string name_; // Nombre introducido
|
||||||
int position_ = 0; // Posición a editar del nombre
|
int position_ = 0; // Posición a editar del nombre
|
||||||
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
|
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
|
||||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
int character_index_[MAX_NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||||
|
|
||||||
// Actualiza el nombre a partir de la lista de índices
|
// Actualiza el nombre a partir de la lista de índices
|
||||||
void updateNameFromCharacterIndex();
|
void updateNameFromCharacterIndex();
|
||||||
|
|||||||
197
source/game.cpp
@@ -22,7 +22,7 @@
|
|||||||
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
|
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
|
||||||
#include "mouse.h" // Para handleEvent
|
#include "global_events.h" // Para handleEvent
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
|
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
|
||||||
@@ -1218,15 +1218,7 @@ void Game::checkEvents()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
if (event.type == SDL_WINDOWEVENT)
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (event.type == SDL_WINDOWEVENT)
|
|
||||||
{
|
{
|
||||||
switch (event.window.event)
|
switch (event.window.event)
|
||||||
{
|
{
|
||||||
@@ -1240,109 +1232,19 @@ void Game::checkEvents()
|
|||||||
pause(false);
|
pause(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
|
||||||
{
|
|
||||||
reloadTextures();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
checkDebugEvents(event);
|
||||||
{
|
|
||||||
switch (event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_1: // Crea una powerball
|
|
||||||
{
|
|
||||||
balloon_manager_->createPowerBall();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_2: // Crea dos globos gordos
|
|
||||||
{
|
|
||||||
balloon_manager_->createTwoBigBalloons();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
|
||||||
{
|
|
||||||
auto_pop_balloons_ = !auto_pop_balloons_;
|
|
||||||
Notifier::get()->showText({"auto advance: " + boolToString(auto_pop_balloons_)});
|
|
||||||
if (auto_pop_balloons_)
|
|
||||||
balloon_manager_->destroyAllBalloons();
|
|
||||||
balloon_manager_->setDeployBalloons(!auto_pop_balloons_);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_4: // Suelta un item
|
|
||||||
{
|
|
||||||
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_5: // 5.000
|
|
||||||
{
|
|
||||||
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
|
||||||
createItemText(x, game_text_textures_.at(2));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_6: // Crea un mensaje
|
|
||||||
{
|
|
||||||
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_7: // 100.000
|
|
||||||
{
|
|
||||||
// screen_->flash(flash_color, 3);
|
|
||||||
// tabe_->setState(TabeState::HIT);
|
|
||||||
const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
|
||||||
createItemText(x, game_text_textures_.at(6));
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_8:
|
|
||||||
{
|
|
||||||
for (auto player : players_)
|
|
||||||
{
|
|
||||||
if (player->isPlaying())
|
|
||||||
{
|
|
||||||
createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_9:
|
|
||||||
{
|
|
||||||
tabe_->enable();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
// Comprueba el cursor
|
globalEvents::check(event);
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void Game::reloadTextures()
|
|
||||||
{
|
|
||||||
for (auto &texture : item_textures_)
|
|
||||||
texture->reLoad();
|
|
||||||
|
|
||||||
for (auto &textures : player_textures_)
|
|
||||||
for (auto &texture : textures)
|
|
||||||
texture->reLoad();
|
|
||||||
|
|
||||||
for (auto &texture : game_text_textures_)
|
|
||||||
texture->reLoad();
|
|
||||||
|
|
||||||
bullet_texture_->reLoad();
|
|
||||||
background_->reloadTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el marcador
|
// Actualiza el marcador
|
||||||
void Game::updateScoreboard()
|
void Game::updateScoreboard()
|
||||||
{
|
{
|
||||||
@@ -1455,12 +1357,14 @@ void Game::checkPauseInput()
|
|||||||
{
|
{
|
||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||||
|
{
|
||||||
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
pause(!paused_);
|
pause(!paused_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado
|
||||||
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
@@ -1477,7 +1381,8 @@ void Game::handleDemoMode()
|
|||||||
for (const auto &player : players_)
|
for (const auto &player : players_)
|
||||||
{
|
{
|
||||||
if (player->isPlaying())
|
if (player->isPlaying())
|
||||||
{ // Maneja el input específico del jugador en modo demo.
|
{
|
||||||
|
// Maneja el input específico del jugador en modo demo.
|
||||||
handleDemoPlayerInput(player, index);
|
handleDemoPlayerInput(player, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1555,7 +1460,7 @@ void Game::handlePlayersInput()
|
|||||||
// Gestiona la continuación del jugador.
|
// Gestiona la continuación del jugador.
|
||||||
handlePlayerContinue(player);
|
handlePlayerContinue(player);
|
||||||
}
|
}
|
||||||
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
|
else if (player->isEnteringName() || player->isEnteringNameGameCompleted() || player->isShowingName())
|
||||||
{
|
{
|
||||||
// Gestiona la introducción del nombre del jugador.
|
// Gestiona la introducción del nombre del jugador.
|
||||||
handleNameInput(player);
|
handleNameInput(player);
|
||||||
@@ -1650,7 +1555,11 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
|||||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
if (player->getEnterNamePositionOverflow())
|
if (player->isShowingName())
|
||||||
|
{
|
||||||
|
player->setPlayingState(PlayerState::CONTINUE);
|
||||||
|
}
|
||||||
|
else if (player->getEnterNamePositionOverflow())
|
||||||
{
|
{
|
||||||
player->setInput(InputType::START);
|
player->setInput(InputType::START);
|
||||||
addScoreToScoreBoard(player);
|
addScoreToScoreBoard(player);
|
||||||
@@ -2066,3 +1975,79 @@ void Game::setState(GameState state)
|
|||||||
state_ = state;
|
state_ = state;
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
// Comprueba los eventos en el modo DEBUG
|
||||||
|
void Game::checkDebugEvents(const SDL_Event &event)
|
||||||
|
{
|
||||||
|
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
||||||
|
{
|
||||||
|
switch (event.key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_1: // Crea una powerball
|
||||||
|
{
|
||||||
|
balloon_manager_->createPowerBall();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_2: // Crea dos globos gordos
|
||||||
|
{
|
||||||
|
balloon_manager_->createTwoBigBalloons();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
||||||
|
{
|
||||||
|
auto_pop_balloons_ = !auto_pop_balloons_;
|
||||||
|
Notifier::get()->show({"auto advance: " + boolToString(auto_pop_balloons_)});
|
||||||
|
if (auto_pop_balloons_)
|
||||||
|
{
|
||||||
|
balloon_manager_->destroyAllBalloons();
|
||||||
|
}
|
||||||
|
balloon_manager_->setDeployBalloons(!auto_pop_balloons_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_4: // Suelta un item
|
||||||
|
{
|
||||||
|
createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_5: // 5.000
|
||||||
|
{
|
||||||
|
const int X = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||||
|
createItemText(X, game_text_textures_.at(2));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_6: // Crea un mensaje
|
||||||
|
{
|
||||||
|
createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_7: // 100.000
|
||||||
|
{
|
||||||
|
const int X = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2;
|
||||||
|
createItemText(X, game_text_textures_.at(6));
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_8:
|
||||||
|
{
|
||||||
|
for (auto player : players_)
|
||||||
|
{
|
||||||
|
if (player->isPlaying())
|
||||||
|
{
|
||||||
|
createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_9:
|
||||||
|
{
|
||||||
|
tabe_->enable();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include <memory> // Para shared_ptr, unique_ptr
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
@@ -173,6 +174,9 @@ private:
|
|||||||
GameState state_ = GameState::FADE_IN; // Estado
|
GameState state_ = GameState::FADE_IN; // Estado
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
|
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
|
||||||
|
|
||||||
|
// Comprueba los eventos en el modo DEBUG
|
||||||
|
void checkDebugEvents(const SDL_Event &event);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Actualiza el juego
|
// Actualiza el juego
|
||||||
@@ -298,9 +302,6 @@ private:
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
bool allPlayersAreNotPlaying();
|
bool allPlayersAreNotPlaying();
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
// Actualiza el marcador
|
// Actualiza el marcador
|
||||||
void updateScoreboard();
|
void updateScoreboard();
|
||||||
|
|
||||||
|
|||||||
@@ -244,15 +244,6 @@ bool GameLogo::hasFinished() const
|
|||||||
return post_finished_counter_ == 0;
|
return post_finished_counter_ == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void GameLogo::reLoad()
|
|
||||||
{
|
|
||||||
dust_texture_->reLoad();
|
|
||||||
coffee_texture_->reLoad();
|
|
||||||
crisis_texture_->reLoad();
|
|
||||||
arcade_edition_texture_->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el desplazamiento vertical inicial
|
// Calcula el desplazamiento vertical inicial
|
||||||
int GameLogo::getInitialVerticalDesp()
|
int GameLogo::getInitialVerticalDesp()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -94,7 +94,4 @@ public:
|
|||||||
|
|
||||||
// Indica si ha terminado la animación
|
// Indica si ha terminado la animación
|
||||||
bool hasFinished() const;
|
bool hasFinished() const;
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void reLoad();
|
|
||||||
};
|
};
|
||||||
@@ -1,93 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include "gif.h"
|
||||||
#include <stdlib.h>
|
#include <stdio.h> // for NULL, fprintf, stderr
|
||||||
#include <string.h>
|
#include <stdlib.h> // for malloc, realloc, exit, calloc, free
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#define EXTENSION_INTRODUCER 0x21
|
|
||||||
#define IMAGE_DESCRIPTOR 0x2C
|
|
||||||
#define TRAILER 0x3B
|
|
||||||
|
|
||||||
#define GRAPHIC_CONTROL 0xF9
|
|
||||||
#define APPLICATION_EXTENSION 0xFF
|
|
||||||
#define COMMENT_EXTENSION 0xFE
|
|
||||||
#define PLAINTEXT_EXTENSION 0x01
|
|
||||||
|
|
||||||
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned short width;
|
|
||||||
unsigned short height;
|
|
||||||
unsigned char fields;
|
|
||||||
unsigned char background_color_index;
|
|
||||||
unsigned char pixel_aspect_ratio;
|
|
||||||
}
|
|
||||||
screen_descriptor_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char r;
|
|
||||||
unsigned char g;
|
|
||||||
unsigned char b;
|
|
||||||
}
|
|
||||||
rgb;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned short image_left_position;
|
|
||||||
unsigned short image_top_position;
|
|
||||||
unsigned short image_width;
|
|
||||||
unsigned short image_height;
|
|
||||||
unsigned char fields;
|
|
||||||
}
|
|
||||||
image_descriptor_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char byte;
|
|
||||||
int prev;
|
|
||||||
int len;
|
|
||||||
}
|
|
||||||
dictionary_entry_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char extension_code;
|
|
||||||
unsigned char block_size;
|
|
||||||
}
|
|
||||||
extension_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char fields;
|
|
||||||
unsigned short delay_time;
|
|
||||||
unsigned char transparent_color_index;
|
|
||||||
}
|
|
||||||
graphic_control_extension_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned char application_id[ 8 ];
|
|
||||||
unsigned char version[ 3 ];
|
|
||||||
}
|
|
||||||
application_extension_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned short left;
|
|
||||||
unsigned short top;
|
|
||||||
unsigned short width;
|
|
||||||
unsigned short height;
|
|
||||||
unsigned char cell_width;
|
|
||||||
unsigned char cell_height;
|
|
||||||
unsigned char foreground_color;
|
|
||||||
unsigned char background_color;
|
|
||||||
}
|
|
||||||
plaintext_extension_t;
|
|
||||||
|
|
||||||
//static unsigned short width = 0;
|
|
||||||
//static unsigned short height = 0;
|
|
||||||
//static unsigned char* uncompressed_data = NULL;
|
|
||||||
|
|
||||||
void uncompress( int code_length,
|
void uncompress( int code_length,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
@@ -105,7 +18,6 @@ void uncompress( int code_length,
|
|||||||
int stop_code; // one more than clear code
|
int stop_code; // one more than clear code
|
||||||
int match_len;
|
int match_len;
|
||||||
|
|
||||||
|
|
||||||
clear_code = 1 << ( code_length );
|
clear_code = 1 << ( code_length );
|
||||||
stop_code = clear_code + 1;
|
stop_code = clear_code + 1;
|
||||||
// To handle clear codes
|
// To handle clear codes
|
||||||
@@ -142,7 +54,7 @@ void uncompress( int code_length,
|
|||||||
{
|
{
|
||||||
code = 0x0;
|
code = 0x0;
|
||||||
// Always read one more bit than the code length
|
// Always read one more bit than the code length
|
||||||
for ( i = 0; i < ( code_length + 1 ); ++i )
|
for ( i = 0; i < ( code_length + 1 ); i++ )
|
||||||
{
|
{
|
||||||
// This is different than in the file read example; that
|
// This is different than in the file read example; that
|
||||||
// was a call to "next_bit"
|
// was a call to "next_bit"
|
||||||
66
source/gif.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h> // for uint32_t
|
||||||
|
#include <string.h> // for memcpy
|
||||||
|
|
||||||
|
#define EXTENSION_INTRODUCER 0x21
|
||||||
|
#define IMAGE_DESCRIPTOR 0x2C
|
||||||
|
#define TRAILER 0x3B
|
||||||
|
#define GRAPHIC_CONTROL 0xF9
|
||||||
|
#define APPLICATION_EXTENSION 0xFF
|
||||||
|
#define COMMENT_EXTENSION 0xFE
|
||||||
|
#define PLAINTEXT_EXTENSION 0x01
|
||||||
|
|
||||||
|
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned short width;
|
||||||
|
unsigned short height;
|
||||||
|
unsigned char fields;
|
||||||
|
unsigned char background_color_index;
|
||||||
|
unsigned char pixel_aspect_ratio;
|
||||||
|
} screen_descriptor_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char r, g, b;
|
||||||
|
} rgb;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned short image_left_position;
|
||||||
|
unsigned short image_top_position;
|
||||||
|
unsigned short image_width;
|
||||||
|
unsigned short image_height;
|
||||||
|
unsigned char fields;
|
||||||
|
} image_descriptor_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char byte;
|
||||||
|
int prev;
|
||||||
|
int len;
|
||||||
|
} dictionary_entry_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char extension_code;
|
||||||
|
unsigned char block_size;
|
||||||
|
} extension_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char fields;
|
||||||
|
unsigned short delay_time;
|
||||||
|
unsigned char transparent_color_index;
|
||||||
|
} graphic_control_extension_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char application_id[8];
|
||||||
|
unsigned char version[3];
|
||||||
|
} application_extension_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned short left, top, width, height;
|
||||||
|
unsigned char cell_width, cell_height;
|
||||||
|
unsigned char foreground_color, background_color;
|
||||||
|
} plaintext_extension_t;
|
||||||
|
|
||||||
|
void uncompress(int code_length, const unsigned char *input, int input_length, unsigned char *out);
|
||||||
|
uint32_t* LoadPalette(unsigned char *buffer);
|
||||||
|
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h);
|
||||||
32
source/global_events.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "global_events.h"
|
||||||
|
#include "section.h"
|
||||||
|
#include "mouse.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
namespace globalEvents
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||||
|
void check(const SDL_Event &event)
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case SDL_QUIT: // Evento de salida de la aplicación
|
||||||
|
section::name = section::Name::QUIT;
|
||||||
|
section::options = section::Options::QUIT_FROM_EVENT;
|
||||||
|
return;
|
||||||
|
case SDL_RENDER_DEVICE_RESET:
|
||||||
|
case SDL_RENDER_TARGETS_RESET:
|
||||||
|
Resource::get()->reloadTextures();
|
||||||
|
break;
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
Resource::get()->reloadTextures();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Mouse::handleEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
source/global_events.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_events.h>
|
||||||
|
|
||||||
|
namespace globalEvents
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||||
|
void check(const SDL_Event &event);
|
||||||
|
}
|
||||||
@@ -21,9 +21,8 @@ namespace globalInputs
|
|||||||
// Termina
|
// Termina
|
||||||
void quit(section::Options code)
|
void quit(section::Options code)
|
||||||
{
|
{
|
||||||
const std::string exit_code = "QUIT";
|
const std::string CODE = "QUIT";
|
||||||
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
if (Notifier::get()->checkCode(CODE))
|
||||||
if (code_found)
|
|
||||||
{
|
{
|
||||||
// Si la notificación de salir está activa, cambia de sección
|
// Si la notificación de salir está activa, cambia de sección
|
||||||
section::name = section::Name::QUIT;
|
section::name = section::Name::QUIT;
|
||||||
@@ -33,10 +32,10 @@ namespace globalInputs
|
|||||||
{
|
{
|
||||||
// Si la notificación de salir no está activa, muestra la notificación
|
// Si la notificación de salir no está activa, muestra la notificación
|
||||||
#ifdef ARCADE
|
#ifdef ARCADE
|
||||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
const int INDEX = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||||
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
|
Notifier::get()->showText({lang::getText(INDEX), std::string()}, -1, CODE);
|
||||||
#else
|
#else
|
||||||
Notifier::get()->showText({lang::getText(94), std::string()}, -1, exit_code);
|
Notifier::get()->show({lang::getText(94), std::string()}, -1, CODE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,8 +43,16 @@ namespace globalInputs
|
|||||||
// Reinicia
|
// Reinicia
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
section::name = section::Name::INIT;
|
const std::string CODE = "RESET";
|
||||||
Notifier::get()->showText({"Reset"});
|
if (Notifier::get()->checkCode(CODE))
|
||||||
|
{
|
||||||
|
section::name = section::Name::INIT;
|
||||||
|
Notifier::get()->show({"Reset"});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Notifier::get()->show({lang::getText(125), std::string()}, -1, CODE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa o desactiva el audio
|
// Activa o desactiva el audio
|
||||||
@@ -62,7 +69,7 @@ namespace globalInputs
|
|||||||
JA_SetMusicVolume(0);
|
JA_SetMusicVolume(0);
|
||||||
JA_SetSoundVolume(0);
|
JA_SetSoundVolume(0);
|
||||||
}
|
}
|
||||||
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
|
Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene una fichero a partir de un lang::Code
|
// Obtiene una fichero a partir de un lang::Code
|
||||||
@@ -88,13 +95,13 @@ namespace globalInputs
|
|||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case lang::Code::ba_BA:
|
case lang::Code::ba_BA:
|
||||||
return "ba_BA";
|
return " \"ba_BA\"";
|
||||||
break;
|
break;
|
||||||
case lang::Code::es_ES:
|
case lang::Code::es_ES:
|
||||||
return "es_ES";
|
return " \"es_ES\"";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return "en_UK";
|
return " \"en_UK\"";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,18 +109,49 @@ namespace globalInputs
|
|||||||
// Cambia el idioma
|
// Cambia el idioma
|
||||||
void changeLang()
|
void changeLang()
|
||||||
{
|
{
|
||||||
options.game.language = lang::change(options.game.language);
|
const std::string CODE = "LANG";
|
||||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
if (Notifier::get()->checkCode(CODE))
|
||||||
section::name = section::Name::INIT;
|
{
|
||||||
section::options = section::Options::RELOAD;
|
options.game.language = lang::getNextLangCode(options.game.language);
|
||||||
Notifier::get()->showText({getLangName(options.game.language)});
|
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||||
|
section::name = section::Name::INIT;
|
||||||
|
section::options = section::Options::RELOAD;
|
||||||
|
Notifier::get()->show({lang::getText(127) + getLangName(options.game.language)});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto NEXT = lang::getNextLangCode(options.game.language);
|
||||||
|
Notifier::get()->show({lang::getText(126) + getLangName(NEXT), std::string()}, -1, CODE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el modo de disparo
|
// Cambia el modo de disparo
|
||||||
void toggleFireMode()
|
void toggleFireMode()
|
||||||
{
|
{
|
||||||
options.game.autofire = !options.game.autofire;
|
options.game.autofire = !options.game.autofire;
|
||||||
Notifier::get()->showText({"Autofire " + boolToOnOff(options.game.autofire)});
|
Notifier::get()->show({"Autofire " + boolToOnOff(options.game.autofire)});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Salta una sección del juego
|
||||||
|
void skip_section()
|
||||||
|
{
|
||||||
|
switch (section::name)
|
||||||
|
{
|
||||||
|
case section::Name::INTRO:
|
||||||
|
JA_StopMusic();
|
||||||
|
// Continua en el case de abajo
|
||||||
|
case section::Name::LOGO:
|
||||||
|
case section::Name::HI_SCORE_TABLE:
|
||||||
|
case section::Name::INSTRUCTIONS:
|
||||||
|
{
|
||||||
|
section::name = section::Name::TITLE;
|
||||||
|
section::options = section::Options::TITLE_1;
|
||||||
|
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
@@ -127,25 +165,27 @@ namespace globalInputs
|
|||||||
{
|
{
|
||||||
Screen::get()->toggleVideoMode();
|
Screen::get()->toggleVideoMode();
|
||||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||||
Notifier::get()->showText({mode + " mode"});
|
Notifier::get()->show({mode + " mode"});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
Screen::get()->decWindowSize();
|
if (Screen::get()->decWindowZoom())
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
{
|
||||||
Notifier::get()->showText({"Window size x" + size});
|
Notifier::get()->show({"Window zoom x" + std::to_string(options.video.window.zoom)});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
Screen::get()->incWindowSize();
|
if (Screen::get()->incWindowZoom())
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
{
|
||||||
Notifier::get()->showText({"Window size x" + size});
|
Notifier::get()->show({"Window zoom x" + std::to_string(options.video.window.zoom)});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -156,6 +196,13 @@ namespace globalInputs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saltar sección
|
||||||
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
|
{
|
||||||
|
skip_section();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
|
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
#include "mouse.h" // Para handleEvent
|
#include "global_events.h" // Para handleEvent
|
||||||
#include "options.h" // Para Options, OptionsGame, options
|
#include "options.h" // Para Options, OptionsGame, options
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
#include "path_sprite.h" // Para PathSprite, Path, PathType
|
#include "path_sprite.h" // Para PathSprite, Path, PathType
|
||||||
@@ -152,54 +152,19 @@ void HiScoreTable::render()
|
|||||||
Screen::get()->render();
|
Screen::get()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void HiScoreTable::reloadTextures()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void HiScoreTable::checkEvents()
|
void HiScoreTable::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
|
||||||
else if (event.type == SDL_WINDOWEVENT)
|
|
||||||
{
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
||||||
{
|
|
||||||
reloadTextures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void HiScoreTable::checkInput()
|
void HiScoreTable::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
|
||||||
{
|
|
||||||
// JA_StopMusic();
|
|
||||||
section::name = section::Name::TITLE;
|
|
||||||
section::options = section::Options::TITLE_1;
|
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,6 @@ private:
|
|||||||
// Dibuja los sprites en la textura
|
// Dibuja los sprites en la textura
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
// Gestiona el fade
|
// Gestiona el fade
|
||||||
void updateFade();
|
void updateFade();
|
||||||
|
|
||||||
|
|||||||
@@ -9,22 +9,22 @@
|
|||||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||||
#include <utility> // Para pair
|
#include <utility> // Para pair
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Input *Input::input_ = nullptr;
|
Input *Input::input_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Input::init(const std::string &game_controller_db_path)
|
void Input::init(const std::string &game_controller_db_path)
|
||||||
{
|
{
|
||||||
Input::input_ = new Input(game_controller_db_path);
|
Input::input_ = new Input(game_controller_db_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Input::destroy()
|
void Input::destroy()
|
||||||
{
|
{
|
||||||
delete Input::input_;
|
delete Input::input_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
Input *Input::get()
|
Input *Input::get()
|
||||||
{
|
{
|
||||||
return Input::input_;
|
return Input::input_;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ enum class InputDeviceToUse : int
|
|||||||
class Input
|
class Input
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// [SINGLETON] Objeto privado
|
||||||
static Input *input_;
|
static Input *input_;
|
||||||
|
|
||||||
struct KeyBindings
|
struct KeyBindings
|
||||||
@@ -109,13 +109,13 @@ private:
|
|||||||
~Input() = default;
|
~Input() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
static void init(const std::string &game_controller_db_path);
|
static void init(const std::string &game_controller_db_path);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
static Input *get();
|
static Input *get();
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
// Asigna inputs a teclas
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||||
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
||||||
#include "mouse.h"
|
#include "global_events.h"
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -236,20 +236,20 @@ void Instructions::update()
|
|||||||
view_.y = std::max(0, param.game.height - counter_ + 100);
|
view_.y = std::max(0, param.game.height - counter_ + 100);
|
||||||
|
|
||||||
// Verifica si view_.y == 0 y gestiona el temporizador
|
// Verifica si view_.y == 0 y gestiona el temporizador
|
||||||
if (view_.y == 0)
|
if (view_.y == 0)
|
||||||
{
|
{
|
||||||
if (!start_delay_triggered_)
|
if (!start_delay_triggered_)
|
||||||
{
|
{
|
||||||
// Activa el temporizador si no ha sido activado
|
// Activa el temporizador si no ha sido activado
|
||||||
start_delay_triggered_ = true;
|
start_delay_triggered_ = true;
|
||||||
start_delay_time_ = SDL_GetTicks();
|
start_delay_time_ = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
|
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
|
||||||
{
|
{
|
||||||
// Han pasado tres segundos, mover líneas
|
// Han pasado tres segundos, mover líneas
|
||||||
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
|
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el mosaico de fondo
|
// Actualiza el mosaico de fondo
|
||||||
tiled_bg_->update();
|
tiled_bg_->update();
|
||||||
@@ -293,60 +293,19 @@ void Instructions::render()
|
|||||||
Screen::get()->render();
|
Screen::get()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void Instructions::reloadTextures()
|
|
||||||
{
|
|
||||||
for (auto &texture : item_textures_)
|
|
||||||
{
|
|
||||||
texture->reLoad();
|
|
||||||
}
|
|
||||||
text_->reLoadTexture();
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Instructions::checkEvents()
|
void Instructions::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
|
||||||
else if (event.type == SDL_WINDOWEVENT)
|
|
||||||
{
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
||||||
{
|
|
||||||
reloadTextures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Instructions::checkInput()
|
void Instructions::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
|
||||||
{
|
|
||||||
// JA_StopMusic();
|
|
||||||
section::name = section::Name::TITLE;
|
|
||||||
section::options = section::Options::TITLE_1;
|
|
||||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,9 +87,6 @@ private:
|
|||||||
// Actualiza los sprites
|
// Actualiza los sprites
|
||||||
void updateSprites();
|
void updateSprites();
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
// Método para inicializar las líneas
|
// Método para inicializar las líneas
|
||||||
std::vector<Line> initializeLines(int height);
|
std::vector<Line> initializeLines(int height);
|
||||||
|
|
||||||
|
|||||||
201
source/intro.cpp
@@ -16,85 +16,90 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||||
#include "writer.h" // Para Writer
|
#include "writer.h" // Para Writer
|
||||||
#include "mouse.h"
|
#include "global_events.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro()
|
Intro::Intro()
|
||||||
: texture_(Resource::get()->getTexture("intro.png")),
|
|
||||||
text_(Resource::get()->getText("04b_25_metal"))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section::name = section::Name::INTRO;
|
section::name = section::Name::INTRO;
|
||||||
section::options = section::Options::NONE;
|
section::options = section::Options::NONE;
|
||||||
|
|
||||||
|
const std::array<std::string, 6> BITMAP_LIST = {
|
||||||
|
"intro1.png",
|
||||||
|
"intro2.png",
|
||||||
|
"intro3.png",
|
||||||
|
"intro4.png",
|
||||||
|
"intro5.png",
|
||||||
|
"intro6.png"};
|
||||||
|
|
||||||
|
auto texture = Resource::get()->getTexture(BITMAP_LIST.front());
|
||||||
|
const int BITMAP_WIDTH = texture->getWidth();
|
||||||
|
const int BITMAP_HEIGHT = texture->getHeight();
|
||||||
|
|
||||||
// Inicializa los bitmaps de la intro
|
// Inicializa los bitmaps de la intro
|
||||||
constexpr int totalBitmaps = 6;
|
constexpr int TOTAL_BITMAPS = 6;
|
||||||
for (int i = 0; i < totalBitmaps; ++i)
|
for (int i = 0; i < TOTAL_BITMAPS; ++i)
|
||||||
{
|
{
|
||||||
auto ss = std::make_unique<SmartSprite>(texture_);
|
auto ss = std::make_unique<SmartSprite>(Resource::get()->getTexture(BITMAP_LIST.at(i)));
|
||||||
ss->setWidth(128);
|
ss->setWidth(BITMAP_WIDTH);
|
||||||
ss->setHeight(96);
|
ss->setHeight(BITMAP_HEIGHT);
|
||||||
|
ss->setSpriteClip(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
|
||||||
ss->setFinishedCounter(20);
|
ss->setFinishedCounter(20);
|
||||||
ss->setDestX(param.game.game_area.center_x - 64);
|
ss->setDestX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||||
ss->setDestY(param.game.game_area.first_quarter_y - 24);
|
ss->setDestY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||||
bitmaps_.push_back(std::move(ss));
|
bitmaps_.push_back(std::move(ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmaps_[0]->setPosX(-128);
|
bitmaps_.at(0)->setPosX(-BITMAP_WIDTH);
|
||||||
bitmaps_[0]->setPosY(param.game.game_area.first_quarter_y - 24);
|
bitmaps_.at(0)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||||
bitmaps_[0]->setVelX(0.0f);
|
bitmaps_.at(0)->setVelX(0.0f);
|
||||||
bitmaps_[0]->setVelY(0.0f);
|
bitmaps_.at(0)->setVelY(0.0f);
|
||||||
bitmaps_[0]->setAccelX(0.6f);
|
bitmaps_.at(0)->setAccelX(0.6f);
|
||||||
bitmaps_[0]->setAccelY(0.0f);
|
bitmaps_.at(0)->setAccelY(0.0f);
|
||||||
bitmaps_[0]->setSpriteClip(0, 0, 128, 96);
|
|
||||||
|
|
||||||
bitmaps_[1]->setPosX(param.game.width);
|
bitmaps_.at(1)->setPosX(param.game.width);
|
||||||
bitmaps_[1]->setPosY(param.game.game_area.first_quarter_y - 24);
|
bitmaps_.at(1)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||||
bitmaps_[1]->setVelX(-1.0f);
|
bitmaps_.at(1)->setVelX(-1.0f);
|
||||||
bitmaps_[1]->setVelY(0.0f);
|
bitmaps_.at(1)->setVelY(0.0f);
|
||||||
bitmaps_[1]->setAccelX(-0.3f);
|
bitmaps_.at(1)->setAccelX(-0.3f);
|
||||||
bitmaps_[1]->setAccelY(0.0f);
|
bitmaps_.at(1)->setAccelY(0.0f);
|
||||||
bitmaps_[1]->setSpriteClip(128, 0, 128, 96);
|
|
||||||
|
|
||||||
bitmaps_[2]->setPosX(param.game.game_area.center_x - 64);
|
bitmaps_.at(2)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||||
bitmaps_[2]->setPosY(-96);
|
bitmaps_.at(2)->setPosY(-BITMAP_HEIGHT);
|
||||||
bitmaps_[2]->setVelX(0.0f);
|
bitmaps_.at(2)->setVelX(0.0f);
|
||||||
bitmaps_[2]->setVelY(3.0f);
|
bitmaps_.at(2)->setVelY(3.0f);
|
||||||
bitmaps_[2]->setAccelX(0.1f);
|
bitmaps_.at(2)->setAccelX(0.1f);
|
||||||
bitmaps_[2]->setAccelY(0.3f);
|
bitmaps_.at(2)->setAccelY(0.3f);
|
||||||
bitmaps_[2]->setSpriteClip(0, 96, 128, 96);
|
bitmaps_.at(2)->setFinishedCounter(250);
|
||||||
bitmaps_[2]->setFinishedCounter(250);
|
|
||||||
|
|
||||||
bitmaps_[3]->setPosX(param.game.game_area.center_x - 64);
|
bitmaps_.at(3)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||||
bitmaps_[3]->setPosY(param.game.height);
|
bitmaps_.at(3)->setPosY(param.game.height);
|
||||||
bitmaps_[3]->setVelX(0.0f);
|
bitmaps_.at(3)->setVelX(0.0f);
|
||||||
bitmaps_[3]->setVelY(-0.7f);
|
bitmaps_.at(3)->setVelY(-0.7f);
|
||||||
bitmaps_[3]->setAccelX(0.0f);
|
bitmaps_.at(3)->setAccelX(0.0f);
|
||||||
bitmaps_[3]->setAccelY(0.0f);
|
bitmaps_.at(3)->setAccelY(0.0f);
|
||||||
bitmaps_[3]->setSpriteClip(128, 96, 128, 96);
|
|
||||||
|
|
||||||
bitmaps_[4]->setPosX(param.game.game_area.center_x - 64);
|
bitmaps_.at(4)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||||
bitmaps_[4]->setPosY(-96);
|
bitmaps_.at(4)->setPosY(-BITMAP_HEIGHT);
|
||||||
bitmaps_[4]->setVelX(0.0f);
|
bitmaps_.at(4)->setVelX(0.0f);
|
||||||
bitmaps_[4]->setVelY(3.0f);
|
bitmaps_.at(4)->setVelY(3.0f);
|
||||||
bitmaps_[4]->setAccelX(0.1f);
|
bitmaps_.at(4)->setAccelX(0.1f);
|
||||||
bitmaps_[4]->setAccelY(0.3f);
|
bitmaps_.at(4)->setAccelY(0.3f);
|
||||||
bitmaps_[4]->setSpriteClip(0, 192, 128, 96);
|
|
||||||
|
|
||||||
bitmaps_[5]->setPosX(param.game.width);
|
bitmaps_.at(5)->setPosX(param.game.width);
|
||||||
bitmaps_[5]->setPosY(param.game.game_area.first_quarter_y - 24);
|
bitmaps_.at(5)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||||
bitmaps_[5]->setVelX(-0.7f);
|
bitmaps_.at(5)->setVelX(-0.7f);
|
||||||
bitmaps_[5]->setVelY(0.0f);
|
bitmaps_.at(5)->setVelY(0.0f);
|
||||||
bitmaps_[5]->setAccelX(0.0f);
|
bitmaps_.at(5)->setAccelX(0.0f);
|
||||||
bitmaps_[5]->setAccelY(0.0f);
|
bitmaps_.at(5)->setAccelY(0.0f);
|
||||||
bitmaps_[5]->setSpriteClip(128, 192, 128, 96);
|
|
||||||
|
|
||||||
// Inicializa los textos de la intro
|
// Inicializa los textos de la intro
|
||||||
constexpr int totalTexts = 9;
|
constexpr int TOTAL_TEXTS = 9;
|
||||||
for (int i = 0; i < totalTexts; ++i)
|
for (int i = 0; i < TOTAL_TEXTS; ++i)
|
||||||
{
|
{
|
||||||
auto w = std::make_unique<Writer>(text_);
|
auto w = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
|
||||||
w->setPosX(BLOCK * 0);
|
w->setPosX(BLOCK * 0);
|
||||||
w->setPosY(param.game.height - (BLOCK * 6));
|
w->setPosY(param.game.height - (BLOCK * 6));
|
||||||
w->setKerning(-2);
|
w->setKerning(-2);
|
||||||
@@ -104,100 +109,60 @@ Intro::Intro()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Un dia qualsevol de l'any 2000
|
// Un dia qualsevol de l'any 2000
|
||||||
texts_[0]->setCaption(lang::getText(27));
|
texts_.at(0)->setCaption(lang::getText(27));
|
||||||
texts_[0]->setSpeed(8);
|
texts_.at(0)->setSpeed(8);
|
||||||
|
|
||||||
// Tot esta tranquil a la UPV
|
// Tot esta tranquil a la UPV
|
||||||
texts_[1]->setCaption(lang::getText(28));
|
texts_.at(1)->setCaption(lang::getText(28));
|
||||||
texts_[1]->setSpeed(8);
|
texts_.at(1)->setSpeed(8);
|
||||||
|
|
||||||
// Fins que un desaprensiu...
|
// Fins que un desaprensiu...
|
||||||
texts_[2]->setCaption(lang::getText(29));
|
texts_.at(2)->setCaption(lang::getText(29));
|
||||||
texts_[2]->setSpeed(12);
|
texts_.at(2)->setSpeed(12);
|
||||||
|
|
||||||
// HEY! ME ANE A FERME UN CORTAET...
|
// HEY! ME ANE A FERME UN CORTAET...
|
||||||
texts_[3]->setCaption(lang::getText(30));
|
texts_.at(3)->setCaption(lang::getText(30));
|
||||||
texts_[3]->setSpeed(8);
|
texts_.at(3)->setSpeed(8);
|
||||||
|
|
||||||
// UAAAAAAAAAAAAA!!!
|
// UAAAAAAAAAAAAA!!!
|
||||||
texts_[4]->setCaption(lang::getText(31));
|
texts_.at(4)->setCaption(lang::getText(31));
|
||||||
texts_[4]->setSpeed(1);
|
texts_.at(4)->setSpeed(1);
|
||||||
|
|
||||||
// Espera un moment...
|
// Espera un moment...
|
||||||
texts_[5]->setCaption(lang::getText(32));
|
texts_.at(5)->setCaption(lang::getText(32));
|
||||||
texts_[5]->setSpeed(16);
|
texts_.at(5)->setSpeed(16);
|
||||||
|
|
||||||
// Si resulta que no tinc solt!
|
// Si resulta que no tinc solt!
|
||||||
texts_[6]->setCaption(lang::getText(33));
|
texts_.at(6)->setCaption(lang::getText(33));
|
||||||
texts_[6]->setSpeed(2);
|
texts_.at(6)->setSpeed(2);
|
||||||
|
|
||||||
// MERDA DE MAQUINA!
|
// MERDA DE MAQUINA!
|
||||||
texts_[7]->setCaption(lang::getText(34));
|
texts_.at(7)->setCaption(lang::getText(34));
|
||||||
texts_[7]->setSpeed(3);
|
texts_.at(7)->setSpeed(3);
|
||||||
|
|
||||||
// Blop... blop... blop...
|
// Blop... blop... blop...
|
||||||
texts_[8]->setCaption(lang::getText(35));
|
texts_.at(8)->setCaption(lang::getText(35));
|
||||||
texts_[8]->setSpeed(16);
|
texts_.at(8)->setSpeed(16);
|
||||||
|
|
||||||
for (auto &text : texts_)
|
for (auto &text : texts_)
|
||||||
|
{
|
||||||
text->center(param.game.game_area.center_x);
|
text->center(param.game.game_area.center_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void Intro::reloadTextures()
|
|
||||||
{
|
|
||||||
texture_->reLoad();
|
|
||||||
text_->reLoadTexture();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Intro::checkEvents()
|
void Intro::checkEvents()
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
switch (event.type)
|
globalEvents::check(event);
|
||||||
{
|
|
||||||
case SDL_QUIT:
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
{
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
||||||
{
|
|
||||||
reloadTextures();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Intro::checkInput()
|
void Intro::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
|
||||||
{
|
|
||||||
JA_StopMusic();
|
|
||||||
section::name = section::Name::TITLE;
|
|
||||||
section::options = section::Options::TITLE_1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ class Intro
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos
|
// Objetos
|
||||||
std::shared_ptr<Texture> texture_; // Textura con los graficos
|
|
||||||
std::shared_ptr<Text> text_; // Textos de la intro
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<SmartSprite>> bitmaps_; // Vector con los sprites inteligentes para los dibujos de la intro
|
std::vector<std::unique_ptr<SmartSprite>> bitmaps_; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||||
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
|
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
|
||||||
|
|
||||||
@@ -43,9 +40,6 @@ private:
|
|||||||
// Actualiza las escenas de la intro
|
// Actualiza las escenas de la intro
|
||||||
void updateScenes();
|
void updateScenes();
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro();
|
Intro();
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#ifndef NO_SHADERS
|
|
||||||
|
|
||||||
#include "jail_shader.h"
|
#include "jail_shader.h"
|
||||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||||
#include <stdlib.h> // para NULL, free, malloc, exit
|
#include <stdlib.h> // para NULL, free, malloc, exit
|
||||||
@@ -248,4 +246,3 @@ namespace shader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#ifndef NO_SHADERS
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // para SDL_Texture
|
#include <SDL2/SDL_render.h> // para SDL_Texture
|
||||||
@@ -45,4 +43,3 @@ namespace shader
|
|||||||
|
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -41,10 +41,10 @@ namespace lang
|
|||||||
return texts.at(index);
|
return texts.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
// Obtiene el codigo del idioma del siguiente idioma
|
||||||
Code change(Code current_lang)
|
Code getNextLangCode(Code lang)
|
||||||
{
|
{
|
||||||
auto index = static_cast<int>(current_lang);
|
auto index = static_cast<int>(lang);
|
||||||
index = (index + 1) % 3;
|
index = (index + 1) % 3;
|
||||||
return static_cast<Code>(index);
|
return static_cast<Code>(index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ namespace lang
|
|||||||
// Obtiene la cadena de texto del indice
|
// Obtiene la cadena de texto del indice
|
||||||
std::string getText(int index);
|
std::string getText(int index);
|
||||||
|
|
||||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
// Obtiene el codigo del idioma del siguiente idioma
|
||||||
Code change(Code current_lang);
|
Code getNextLangCode(Code lang);
|
||||||
}
|
}
|
||||||
149
source/logo.cpp
@@ -3,43 +3,42 @@
|
|||||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
|
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
|
||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
#include "global_inputs.h" // Para check
|
#include <iostream>
|
||||||
#include "input.h" // Para Input
|
#include "global_inputs.h" // Para check
|
||||||
#include "jail_audio.h" // Para JA_StopMusic
|
#include "input.h" // Para Input
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "jail_audio.h" // Para JA_StopMusic
|
||||||
#include "resource.h" // Para Resource
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "screen.h" // Para Screen
|
#include "resource.h" // Para Resource
|
||||||
#include "section.h" // Para Name, name, Options, options
|
#include "screen.h" // Para Screen
|
||||||
#include "sprite.h" // Para Sprite
|
#include "section.h" // Para Name, name, Options, options
|
||||||
#include "texture.h" // Para Texture
|
#include "sprite.h" // Para Sprite
|
||||||
#include "utils.h" // Para Color, Zone
|
#include "texture.h" // Para Texture
|
||||||
#include "mouse.h"
|
#include "utils.h" // Para Color, Zone
|
||||||
|
#include "global_events.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
||||||
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
||||||
jail_texture_(Resource::get()->getTexture("logo_jailgames.png")),
|
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
|
||||||
ticks_(0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter_ = 0;
|
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
||||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||||
since_sprite_->setPosition({(param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight()});
|
since_sprite_->setPosition({(param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight()});
|
||||||
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
|
||||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||||
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
since_texture_->setColor(0x00, 0x00, 0x00);
|
||||||
|
|
||||||
// Crea los sprites de cada linea
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < jail_texture_->getHeight(); ++i)
|
for (int i = 0; i < jail_texture_->getHeight(); ++i)
|
||||||
{
|
{
|
||||||
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
|
||||||
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
||||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
||||||
temp->setX(posX);
|
temp->setX(POS_X);
|
||||||
temp->setY(dest_.y + i);
|
temp->setY(dest_.y + i);
|
||||||
jail_sprite_.push_back(std::move(temp));
|
jail_sprite_.push_back(std::move(temp));
|
||||||
}
|
}
|
||||||
@@ -63,58 +62,23 @@ Logo::~Logo()
|
|||||||
JA_StopChannel(-1);
|
JA_StopChannel(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void Logo::reloadTextures()
|
|
||||||
{
|
|
||||||
jail_texture_->reLoad();
|
|
||||||
since_texture_->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Logo::checkEvents()
|
void Logo::checkEvents()
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
globalEvents::check(event);
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
|
||||||
else if (event.type == SDL_WINDOWEVENT)
|
|
||||||
{
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
|
||||||
{
|
|
||||||
reloadTextures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Logo::checkInput()
|
void Logo::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
|
||||||
{
|
|
||||||
section::name = section::Name::TITLE;
|
|
||||||
section::options = section::Options::TITLE_1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAMES
|
||||||
void Logo::updateJAILGAMES()
|
void Logo::updateJAILGAMES()
|
||||||
{
|
{
|
||||||
if (counter_ == 30)
|
if (counter_ == 30)
|
||||||
@@ -147,6 +111,19 @@ void Logo::updateJAILGAMES()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
||||||
|
{
|
||||||
|
state_ = LogoState::RETROWEEKEND;
|
||||||
|
ticks_start_ = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona el logo de RETROWEEKEND
|
||||||
|
void Logo::updateRETROWEEKEND()
|
||||||
|
{
|
||||||
|
section::name = section::Name::INTRO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
@@ -190,21 +167,24 @@ void Logo::update()
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
switch (state_)
|
||||||
updateJAILGAMES();
|
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
|
||||||
updateTextureColors();
|
|
||||||
|
|
||||||
// Gestiona el contador y sus eventos
|
|
||||||
counter_++;
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
|
||||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
|
||||||
{
|
{
|
||||||
section::name = section::Name::INTRO;
|
case LogoState::JAILGAMES:
|
||||||
|
updateJAILGAMES();
|
||||||
|
updateTextureColors();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogoState::RETROWEEKEND:
|
||||||
|
updateRETROWEEKEND();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gestiona el contador
|
||||||
|
counter_++;
|
||||||
|
|
||||||
// Actualiza las variables de globalInputs
|
// Actualiza las variables de globalInputs
|
||||||
globalInputs::update();
|
globalInputs::update();
|
||||||
}
|
}
|
||||||
@@ -213,24 +193,22 @@ void Logo::update()
|
|||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
void Logo::render()
|
void Logo::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
Screen::get()->clean();
|
Screen::get()->clean();
|
||||||
|
|
||||||
// Dibuja los sprites
|
switch (state_)
|
||||||
for (auto &sprite : jail_sprite_)
|
|
||||||
{
|
{
|
||||||
sprite->render();
|
case LogoState::JAILGAMES:
|
||||||
|
renderJAILGAMES();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogoState::RETROWEEKEND:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
|
||||||
{
|
|
||||||
since_sprite_->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
Screen::get()->render();
|
Screen::get()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,3 +226,18 @@ void Logo::run()
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renderiza el logo de JAILGAMES
|
||||||
|
void Logo::renderJAILGAMES()
|
||||||
|
{
|
||||||
|
// Dibuja los sprites
|
||||||
|
for (auto &sprite : jail_sprite_)
|
||||||
|
{
|
||||||
|
sprite->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
||||||
|
{
|
||||||
|
since_sprite_->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <memory> // Para shared_ptr, unique_ptr
|
#include <SDL2/SDL.h>
|
||||||
#include <vector> // Para vector
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
|
#include <vector> // Para vector
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture; // lines 9-9
|
class Texture; // lines 9-9
|
||||||
struct Color;
|
struct Color;
|
||||||
@@ -16,10 +17,31 @@ struct Color;
|
|||||||
ZX Spectrum
|
ZX Spectrum
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct Pixel
|
||||||
|
{
|
||||||
|
int x, y; // Coordenadas del píxel
|
||||||
|
Uint8 r, g, b, a; // Color del píxel
|
||||||
|
|
||||||
|
// Método para ascender y desvanecerse
|
||||||
|
void evaporate()
|
||||||
|
{
|
||||||
|
y -= 1; // Asciende hacia arriba
|
||||||
|
a = (a > 5) ? a - 5 : 0; // Desvanece el alfa (transparencia)
|
||||||
|
// Añadir movimiento zig-zag aleatorio
|
||||||
|
x += (rand() % 3 - 1); // Movimiento horizontal aleatorio (-1, 0, 1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Logo
|
// Clase Logo
|
||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
enum class LogoState
|
||||||
|
{
|
||||||
|
JAILGAMES,
|
||||||
|
RETROWEEKEND,
|
||||||
|
};
|
||||||
|
|
||||||
// Constantes
|
// Constantes
|
||||||
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
||||||
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
||||||
@@ -34,10 +56,12 @@ private:
|
|||||||
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Color> color_; // Vector con los colores para el fade
|
std::vector<Color> color_; // Vector con los colores para el fade
|
||||||
int counter_; // Contador
|
int counter_ = 0; // Contador
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
SDL_Point dest_; // Posición X donde dibujar el logo
|
SDL_Point dest_; // Posición X donde dibujar el logo
|
||||||
|
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando
|
||||||
|
Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -51,15 +75,21 @@ private:
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAMES
|
||||||
void updateJAILGAMES();
|
void updateJAILGAMES();
|
||||||
|
|
||||||
|
// Gestiona el logo de RETROWEEKEND
|
||||||
|
void updateRETROWEEKEND();
|
||||||
|
|
||||||
|
// Renderiza el logo de JAILGAMES
|
||||||
|
void renderJAILGAMES();
|
||||||
|
|
||||||
|
// Renderiza el logo de RETROWEEKEND
|
||||||
|
void renderRETROWEEKEND();
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
void updateTextureColors();
|
void updateTextureColors();
|
||||||
|
|
||||||
// Recarga todas las texturas
|
|
||||||
void reloadTextures();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo();
|
Logo();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
|
|||||||
rotate_(Rotate()),
|
rotate_(Rotate()),
|
||||||
zoom_w_(1.0f),
|
zoom_w_(1.0f),
|
||||||
zoom_h_(1.0f),
|
zoom_h_(1.0f),
|
||||||
flip_(SDL_FLIP_NONE) { Sprite::clear(); }
|
flip_(SDL_FLIP_NONE) {Sprite::clear(); }
|
||||||
|
|
||||||
// Reinicia todas las variables
|
// Reinicia todas las variables
|
||||||
void MovingSprite::clear()
|
void MovingSprite::clear()
|
||||||
@@ -73,46 +73,7 @@ void MovingSprite::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void MovingSprite::render()
|
void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); }
|
||||||
{
|
|
||||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setZoomW(float value)
|
|
||||||
{
|
|
||||||
zoom_w_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setZoomH(float value)
|
|
||||||
{
|
|
||||||
zoom_h_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setAngle(double value)
|
|
||||||
{
|
|
||||||
rotate_.angle = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setRotatingCenter(SDL_Point *point)
|
|
||||||
{
|
|
||||||
rotate_.center = point;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Incrementa el valor del ángulo
|
|
||||||
void MovingSprite::updateAngle()
|
|
||||||
{
|
|
||||||
rotate_.angle += rotate_.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool MovingSprite::isRotating() const
|
|
||||||
{
|
|
||||||
return rotate_.enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la rotacion
|
// Establece la rotacion
|
||||||
void MovingSprite::rotate()
|
void MovingSprite::rotate()
|
||||||
@@ -135,43 +96,6 @@ void MovingSprite::setRotate(bool enable)
|
|||||||
rotate_.counter = 0;
|
rotate_.counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setRotateSpeed(int value)
|
|
||||||
{
|
|
||||||
rotate_.speed = std::max(1, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setRotateAmount(double value)
|
|
||||||
{
|
|
||||||
rotate_.amount = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el sentido de la rotación
|
|
||||||
void MovingSprite::switchRotate()
|
|
||||||
{
|
|
||||||
rotate_.amount *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
|
||||||
{
|
|
||||||
flip_ = flip;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gira el sprite horizontalmente
|
|
||||||
void MovingSprite::flip()
|
|
||||||
{
|
|
||||||
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
SDL_RendererFlip MovingSprite::getFlip()
|
|
||||||
{
|
|
||||||
return flip_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Establece la posición y_ el tamaño del objeto
|
// Establece la posición y_ el tamaño del objeto
|
||||||
void MovingSprite::setPos(SDL_Rect rect)
|
void MovingSprite::setPos(SDL_Rect rect)
|
||||||
{
|
{
|
||||||
@@ -204,27 +128,3 @@ void MovingSprite::setPosY(float value)
|
|||||||
y_ = value;
|
y_ = value;
|
||||||
pos_.y = static_cast<int>(y_);
|
pos_.y = static_cast<int>(y_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setVelX(float value)
|
|
||||||
{
|
|
||||||
vx_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setVelY(float value)
|
|
||||||
{
|
|
||||||
vy_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setAccelX(float value)
|
|
||||||
{
|
|
||||||
ax_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void MovingSprite::setAccelY(float value)
|
|
||||||
{
|
|
||||||
ay_ = value;
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip
|
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip
|
||||||
#include <memory> // Para shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
|
#include <algorithm>
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
class Texture; // lines 8-8
|
class Texture; // lines 8-8
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ protected:
|
|||||||
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
||||||
|
|
||||||
// Incrementa el valor del ángulo
|
// Incrementa el valor del ángulo
|
||||||
void updateAngle();
|
void updateAngle() { rotate_.angle += rotate_.amount; }
|
||||||
|
|
||||||
// Mueve el sprite
|
// Mueve el sprite
|
||||||
void move();
|
void move();
|
||||||
@@ -73,40 +74,40 @@ public:
|
|||||||
float getAccelY() const { return ay_; }
|
float getAccelY() const { return ay_; }
|
||||||
|
|
||||||
// Establece la variable
|
// Establece la variable
|
||||||
void setVelX(float value);
|
void setVelX(float value) { vx_ = value; }
|
||||||
void setVelY(float value);
|
void setVelY(float value) { vy_ = value; }
|
||||||
void setAccelX(float value);
|
void setAccelX(float value) { ax_ = value; }
|
||||||
void setAccelY(float value);
|
void setAccelY(float value) { ay_ = value; }
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
bool isRotating() const;
|
bool isRotating() const { return rotate_.enabled; }
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setZoomW(float value);
|
void setZoomW(float value) { zoom_w_ = value; }
|
||||||
void setZoomH(float value);
|
void setZoomH(float value) { zoom_h_ = value; }
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAngle(double vaue);
|
void setAngle(double value) { rotate_.angle = value; }
|
||||||
void setRotatingCenter(SDL_Point *point);
|
void setRotatingCenter(SDL_Point *point) { rotate_.center = point; }
|
||||||
|
|
||||||
// Activa o desactiva el efecto de rotación
|
// Activa o desactiva el efecto de rotación
|
||||||
void setRotate(bool enable);
|
void setRotate(bool enable);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setRotateSpeed(int value);
|
void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); }
|
||||||
void setRotateAmount(double value);
|
void setRotateAmount(double value) { rotate_.amount = value; }
|
||||||
|
|
||||||
// Cambia el sentido de la rotación
|
// Cambia el sentido de la rotación
|
||||||
void switchRotate();
|
void switchRotate() { rotate_.amount *= -1; }
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setFlip(SDL_RendererFlip flip);
|
void setFlip(SDL_RendererFlip flip) { flip_ = flip; }
|
||||||
|
|
||||||
// Gira el sprite horizontalmente
|
// Gira el sprite horizontalmente
|
||||||
void flip();
|
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; }
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
SDL_RendererFlip getFlip();
|
SDL_RendererFlip getFlip() { return flip_; }
|
||||||
|
|
||||||
// Establece la posición y_ el tamaño del objeto
|
// Establece la posición y_ el tamaño del objeto
|
||||||
void setPos(SDL_Rect rect);
|
void setPos(SDL_Rect rect);
|
||||||
|
|||||||
@@ -12,22 +12,22 @@
|
|||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Notifier *Notifier::notifier_ = nullptr;
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
||||||
{
|
{
|
||||||
Notifier::notifier_ = new Notifier(icon_file, text);
|
Notifier::notifier_ = new Notifier(icon_file, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Notifier::destroy()
|
void Notifier::destroy()
|
||||||
{
|
{
|
||||||
delete Notifier::notifier_;
|
delete Notifier::notifier_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
Notifier *Notifier::get()
|
Notifier *Notifier::get()
|
||||||
{
|
{
|
||||||
return Notifier::notifier_;
|
return Notifier::notifier_;
|
||||||
@@ -153,7 +153,7 @@ void Notifier::clearFinishedNotifications()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notifier::showText(std::vector<std::string> texts, int icon, const std::string &code)
|
void Notifier::show(std::vector<std::string> texts, int icon, const std::string &code)
|
||||||
{
|
{
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (texts.empty())
|
if (texts.empty())
|
||||||
@@ -164,7 +164,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
|
|||||||
// Si las notificaciones no se apilan, elimina las anteriores
|
// Si las notificaciones no se apilan, elimina las anteriores
|
||||||
if (!stack_)
|
if (!stack_)
|
||||||
{
|
{
|
||||||
clearNotifications();
|
clearAllNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Elimina las cadenas vacías
|
// Elimina las cadenas vacías
|
||||||
@@ -298,7 +298,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
|
|||||||
bool Notifier::isActive() { return !notifications_.empty(); }
|
bool Notifier::isActive() { return !notifications_.empty(); }
|
||||||
|
|
||||||
// Finaliza y elimnina todas las notificaciones activas
|
// Finaliza y elimnina todas las notificaciones activas
|
||||||
void Notifier::clearNotifications()
|
void Notifier::clearAllNotifications()
|
||||||
{
|
{
|
||||||
for (auto ¬ification : notifications_)
|
for (auto ¬ification : notifications_)
|
||||||
{
|
{
|
||||||
@@ -318,3 +318,9 @@ std::vector<std::string> Notifier::getCodes()
|
|||||||
}
|
}
|
||||||
return codes;
|
return codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si hay alguna notificacion con un código
|
||||||
|
bool Notifier::checkCode(std::string code)
|
||||||
|
{
|
||||||
|
return stringInVector(getCodes(), code);
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ class Texture; // lines 11-11
|
|||||||
class Notifier
|
class Notifier
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto notifier privado para Don Melitón
|
// [SINGLETON] Objeto notifier
|
||||||
static Notifier *notifier_;
|
static Notifier *notifier_;
|
||||||
|
|
||||||
enum class NotificationStatus
|
enum class NotificationStatus
|
||||||
@@ -66,7 +66,7 @@ private:
|
|||||||
void clearFinishedNotifications();
|
void clearFinishedNotifications();
|
||||||
|
|
||||||
// Finaliza y elimnina todas las notificaciones activas
|
// Finaliza y elimnina todas las notificaciones activas
|
||||||
void clearNotifications();
|
void clearAllNotifications();
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||||
|
|
||||||
@@ -77,13 +77,13 @@ private:
|
|||||||
~Notifier() = default;
|
~Notifier() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto notifier y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
static Notifier *get();
|
static Notifier *get();
|
||||||
|
|
||||||
// Dibuja las notificaciones por pantalla
|
// Dibuja las notificaciones por pantalla
|
||||||
@@ -93,11 +93,14 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla
|
// Muestra una notificación de texto por pantalla
|
||||||
void showText(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
void show(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
// Obtiene los códigos de las notificaciones
|
// Obtiene los códigos de las notificaciones
|
||||||
std::vector<std::string> getCodes();
|
std::vector<std::string> getCodes();
|
||||||
|
|
||||||
|
// Comprueba si hay alguna notificacion con un código
|
||||||
|
bool checkCode(std::string code);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void initOptions()
|
|||||||
options.video.window.size = 3;
|
options.video.window.size = 3;
|
||||||
#else
|
#else
|
||||||
options.video.mode = ScreenVideoMode::WINDOW;
|
options.video.mode = ScreenVideoMode::WINDOW;
|
||||||
options.video.window.size = 2;
|
options.video.window.zoom = 2;
|
||||||
#endif
|
#endif
|
||||||
options.video.filter = ScreenFilter::NEAREST;
|
options.video.filter = ScreenFilter::NEAREST;
|
||||||
options.video.v_sync = true;
|
options.video.v_sync = true;
|
||||||
@@ -105,7 +105,7 @@ bool loadOptionsFile(std::string file_path)
|
|||||||
options.video.mode = ScreenVideoMode::WINDOW;
|
options.video.mode = ScreenVideoMode::WINDOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
options.video.window.size = std::clamp(options.video.window.size, 1, 4);
|
options.video.window.zoom = std::clamp(options.video.window.zoom, 1, 4);
|
||||||
|
|
||||||
if (options.game.language != lang::Code::en_UK &&
|
if (options.game.language != lang::Code::en_UK &&
|
||||||
options.game.language != lang::Code::ba_BA &&
|
options.game.language != lang::Code::ba_BA &&
|
||||||
@@ -137,7 +137,7 @@ bool saveOptionsFile(std::string file_path)
|
|||||||
file << "\n";
|
file << "\n";
|
||||||
|
|
||||||
file << "video.mode=" << static_cast<int>(options.video.mode) << "\n";
|
file << "video.mode=" << static_cast<int>(options.video.mode) << "\n";
|
||||||
file << "video.window.size=" << options.video.window.size << "\n";
|
file << "video.window.size=" << options.video.window.zoom << "\n";
|
||||||
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
|
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
|
||||||
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||||
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
||||||
@@ -204,10 +204,10 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
}
|
}
|
||||||
else if (var == "video.window.size")
|
else if (var == "video.window.size")
|
||||||
{
|
{
|
||||||
options.video.window.size = std::stoi(value);
|
options.video.window.zoom = std::stoi(value);
|
||||||
if ((options.video.window.size < 1) || (options.video.window.size > 4))
|
if ((options.video.window.zoom < 1) || (options.video.window.zoom > 4))
|
||||||
{
|
{
|
||||||
options.video.window.size = 3;
|
options.video.window.zoom = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (var == "video.filter")
|
else if (var == "video.filter")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "input.h" // Para InputType, InputDeviceToUse
|
#include "input.h" // Para InputType, InputDeviceToUse
|
||||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
enum class ScreenFilter : int; // lines 10-10
|
enum class ScreenFilter : int; // lines 10-10
|
||||||
enum class ScreenVideoMode : int; // lines 11-11
|
enum class ScreenVideoMode : Uint32; // lines 11-11
|
||||||
namespace lang
|
namespace lang
|
||||||
{
|
{
|
||||||
enum class Code : int;
|
enum class Code : int;
|
||||||
@@ -23,8 +23,8 @@ enum class GameDifficulty
|
|||||||
// Estructura para las opciones de la ventana
|
// Estructura para las opciones de la ventana
|
||||||
struct OptionsWindow
|
struct OptionsWindow
|
||||||
{
|
{
|
||||||
int size = 1; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
int zoom = 1; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||||
int max_size = 1; // Tamaño máximo para que el tamaño de la ventana no sea mayor que el tamaño de la pantalla
|
int max_zoom = 1; // Tamaño máximo para que el tamaño de la ventana no sea mayor que el tamaño de la pantalla
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura con opciones para el video
|
// Estructura con opciones para el video
|
||||||
@@ -64,18 +64,18 @@ struct OptionsAudio
|
|||||||
// Estructura para las opciones del juego
|
// Estructura para las opciones del juego
|
||||||
struct OptionsGame
|
struct OptionsGame
|
||||||
{
|
{
|
||||||
GameDifficulty difficulty; // Dificultad del juego
|
GameDifficulty difficulty; // Dificultad del juego
|
||||||
lang::Code language; // Idioma usado en el juego
|
lang::Code language; // Idioma usado en el juego
|
||||||
bool autofire; // Indicador de autofire
|
bool autofire; // Indicador de autofire
|
||||||
std::vector<HiScoreEntry> hi_score_table; // Tabla de mejores puntuaciones
|
std::vector<HiScoreEntry> hi_score_table; // Tabla de mejores puntuaciones
|
||||||
std::vector<int> last_hi_score_entry = { -1, -1 }; // Inicialización directa con dos elementos en -1
|
std::vector<int> last_hi_score_entry = {-1, -1}; // Inicialización directa con dos elementos en -1
|
||||||
|
|
||||||
// Método para reiniciar las últimas entradas de puntuación
|
// Método para reiniciar las últimas entradas de puntuación
|
||||||
void clear_last_hi_score_entries()
|
void clear_last_hi_score_entries()
|
||||||
{
|
{
|
||||||
last_hi_score_entry[0] = -1;
|
last_hi_score_entry[0] = -1;
|
||||||
last_hi_score_entry[1] = -1;
|
last_hi_score_entry[1] = -1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para los controles del juego
|
// Estructura para los controles del juego
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "stage.h"
|
#include "stage.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
||||||
@@ -149,6 +150,11 @@ void Player::setInputEnteringName(InputType input)
|
|||||||
break;
|
break;
|
||||||
case InputType::START:
|
case InputType::START:
|
||||||
last_enter_name_ = getRecordName();
|
last_enter_name_ = getRecordName();
|
||||||
|
if (last_enter_name_.empty())
|
||||||
|
{
|
||||||
|
const std::array<std::string, 8> NAMES = {"BAL1", "TABE", "DOC", "MON", "SAM1", "JORDI", "JDES", "PEPE"};
|
||||||
|
last_enter_name_ = NAMES.at(rand() % NAMES.size());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -166,9 +172,9 @@ void Player::move()
|
|||||||
pos_x_ += vel_x_;
|
pos_x_ += vel_x_;
|
||||||
|
|
||||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||||
const float min_x = play_area_.x - 5;
|
const float MIN_X = play_area_.x - 5;
|
||||||
const float max_x = play_area_.w + 5 - WIDTH_;
|
const float MAX_X = play_area_.w + 5 - WIDTH_;
|
||||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
|
||||||
|
|
||||||
shiftSprite();
|
shiftSprite();
|
||||||
break;
|
break;
|
||||||
@@ -176,12 +182,12 @@ void Player::move()
|
|||||||
case PlayerState::DYING:
|
case PlayerState::DYING:
|
||||||
{
|
{
|
||||||
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
||||||
const int x = player_sprite_->getPosX();
|
const int X = player_sprite_->getPosX();
|
||||||
const int min_x = play_area_.x;
|
const int MIN_X = play_area_.x;
|
||||||
const int max_x = play_area_.x + play_area_.w - WIDTH_;
|
const int MAX_X = play_area_.x + play_area_.w - WIDTH_;
|
||||||
if ((x < min_x) || (x > max_x))
|
if ((X < MIN_X) || (X > MAX_X))
|
||||||
{
|
{
|
||||||
player_sprite_->setPosX(std::clamp(x, min_x, max_x));
|
player_sprite_->setPosX(std::clamp(X, MIN_X, MAX_X));
|
||||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||||
playRandomBubbleSound();
|
playRandomBubbleSound();
|
||||||
}
|
}
|
||||||
@@ -287,7 +293,6 @@ void Player::move()
|
|||||||
{
|
{
|
||||||
pos_x_ = param.game.game_area.rect.w - WIDTH_;
|
pos_x_ = param.game.game_area.rect.w - WIDTH_;
|
||||||
vel_x_ *= -1;
|
vel_x_ *= -1;
|
||||||
// setInputPlaying(InputType::LEFT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -297,7 +302,6 @@ void Player::move()
|
|||||||
{
|
{
|
||||||
pos_x_ = param.game.game_area.rect.x;
|
pos_x_ = param.game.game_area.rect.x;
|
||||||
vel_x_ *= -1;
|
vel_x_ *= -1;
|
||||||
// setInputPlaying(InputType::RIGHT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,17 +360,20 @@ void Player::setAnimation()
|
|||||||
|
|
||||||
// Establece la animación a partir de las cadenas
|
// Establece la animación a partir de las cadenas
|
||||||
if (firing_state_ == PlayerState::FIRING_NONE)
|
if (firing_state_ == PlayerState::FIRING_NONE)
|
||||||
{ // No esta disparando
|
{
|
||||||
|
// No esta disparando
|
||||||
player_sprite_->setCurrentAnimation(a_walking);
|
player_sprite_->setCurrentAnimation(a_walking);
|
||||||
player_sprite_->setFlip(flip_walk);
|
player_sprite_->setFlip(flip_walk);
|
||||||
}
|
}
|
||||||
else if (isCooling())
|
else if (isCooling())
|
||||||
{ // Acaba de disparar
|
{
|
||||||
|
// Acaba de disparar
|
||||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
|
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
|
||||||
player_sprite_->setFlip(flip_cooling);
|
player_sprite_->setFlip(flip_cooling);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Está disparando
|
{
|
||||||
|
// Está disparando
|
||||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
|
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
|
||||||
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
||||||
// Si dispara recto, invierte el sprite segun hacia donde camina
|
// Si dispara recto, invierte el sprite segun hacia donde camina
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ public:
|
|||||||
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
|
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
|
||||||
bool isDying() const { return playing_state_ == PlayerState::DYING; }
|
bool isDying() const { return playing_state_ == PlayerState::DYING; }
|
||||||
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
|
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
|
||||||
|
bool isShowingName() const { return playing_state_ == PlayerState::SHOWING_NAME; }
|
||||||
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
|
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
|
||||||
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
|
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
|
||||||
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }
|
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }
|
||||||
|
|||||||
@@ -73,6 +73,14 @@ void Resource::reload()
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void Resource::reloadTextures()
|
||||||
|
{
|
||||||
|
loadTextures();
|
||||||
|
addPalettes();
|
||||||
|
createTextures();
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene el sonido a partir de un nombre
|
// Obtiene el sonido a partir de un nombre
|
||||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -170,4 +170,7 @@ public:
|
|||||||
|
|
||||||
// Recarga todos los recursos
|
// Recarga todos los recursos
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void reloadTextures();
|
||||||
};
|
};
|
||||||
@@ -263,7 +263,7 @@ void Scoreboard::fillPanelTextures()
|
|||||||
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||||
|
|
||||||
// Recorre todos los slots de letras del nombre
|
// Recorre todos los slots de letras del nombre
|
||||||
for (size_t j = 0; j < NAME_LENGHT; ++j)
|
for (size_t j = 0; j < MAX_NAME_LENGHT; ++j)
|
||||||
{
|
{
|
||||||
// Selecciona el color
|
// Selecciona el color
|
||||||
const Color color = j < selector_pos_[i] ? orange_soft_color.lighten() : Color(0xFF, 0xFF, 0xEB);
|
const Color color = j < selector_pos_[i] ? orange_soft_color.lighten() : Color(0xFF, 0xFF, 0xEB);
|
||||||
@@ -380,7 +380,7 @@ void Scoreboard::recalculateAnchors()
|
|||||||
slot4_4_ = {col, row4};
|
slot4_4_ = {col, row4};
|
||||||
|
|
||||||
// Primer cuadrado para poner el nombre de record
|
// Primer cuadrado para poner el nombre de record
|
||||||
const int enter_name_lenght = text_scoreboard_->lenght(std::string(NAME_LENGHT, 'A'));
|
const int enter_name_lenght = text_scoreboard_->lenght(std::string(MAX_NAME_LENGHT, 'A'));
|
||||||
enter_name_pos_.x = col - (enter_name_lenght / 2);
|
enter_name_pos_.x = col - (enter_name_lenght / 2);
|
||||||
enter_name_pos_.y = row4;
|
enter_name_pos_.y = row4;
|
||||||
|
|
||||||
|
|||||||
@@ -15,31 +15,19 @@
|
|||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
#include "jail_shader.h" // para init, render
|
#include "jail_shader.h" // para init, render
|
||||||
#endif
|
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON]
|
||||||
Screen *Screen::screen_ = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
void Screen::init(SDL_Window *window, SDL_Renderer *renderer) { Screen::screen_ = new Screen(window, renderer); }
|
||||||
{
|
|
||||||
Screen::screen_ = new Screen(window, renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
void Screen::destroy()
|
void Screen::destroy() { delete Screen::screen_; }
|
||||||
{
|
|
||||||
delete Screen::screen_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
Screen *Screen::get()
|
Screen *Screen::get() { return Screen::screen_; }
|
||||||
{
|
|
||||||
return Screen::screen_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
@@ -54,18 +42,15 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
|||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||||
|
|
||||||
// Establece el modo de video
|
// Inicializa los shaders
|
||||||
setVideoMode(options.video.mode);
|
initShaders();
|
||||||
|
|
||||||
// Muestra la ventana
|
// Muestra la ventana
|
||||||
SDL_ShowWindow(window_);
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen() { SDL_DestroyTexture(game_canvas_); }
|
||||||
{
|
|
||||||
SDL_DestroyTexture(game_canvas_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void Screen::clean(Color color)
|
void Screen::clean(Color color)
|
||||||
@@ -75,24 +60,13 @@ void Screen::clean(Color color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
void Screen::start()
|
void Screen::start() { SDL_SetRenderTarget(renderer_, game_canvas_); }
|
||||||
{
|
|
||||||
SDL_SetRenderTarget(renderer_, game_canvas_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::render()
|
void Screen::render()
|
||||||
{
|
{
|
||||||
// Actualiza el contador de FPS
|
// Renderiza todos los overlays y efectos
|
||||||
++fps_counter_;
|
renderOverlays();
|
||||||
|
|
||||||
// Dibuja efectos y elementos sobre el game_canvas_
|
|
||||||
renderFlash();
|
|
||||||
renderAttenuate();
|
|
||||||
renderShake();
|
|
||||||
OnScreenHelp::get()->render();
|
|
||||||
renderInfo();
|
|
||||||
Notifier::get()->render();
|
|
||||||
|
|
||||||
// Renderiza el contenido del game_canvas_
|
// Renderiza el contenido del game_canvas_
|
||||||
renderScreen();
|
renderScreen();
|
||||||
@@ -101,86 +75,31 @@ void Screen::render()
|
|||||||
// Renderiza el contenido del game_canvas_
|
// Renderiza el contenido del game_canvas_
|
||||||
void Screen::renderScreen()
|
void Screen::renderScreen()
|
||||||
{
|
{
|
||||||
// Restablece el objetivo de renderizado al buffer de pantalla predeterminado
|
|
||||||
SDL_SetRenderTarget(renderer_, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
clean();
|
clean();
|
||||||
|
|
||||||
#ifdef NO_SHADERS
|
|
||||||
// Actualiza la pantalla con el contenido del buffer de renderizado
|
|
||||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
|
||||||
SDL_RenderPresent(renderer_);
|
|
||||||
#else
|
|
||||||
if (options.video.shaders)
|
if (options.video.shaders)
|
||||||
{
|
{
|
||||||
// Aplica shaders y renderiza el contenido
|
|
||||||
shader::render();
|
shader::render();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Actualiza la pantalla con el contenido del buffer de renderizado
|
|
||||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderPresent(renderer_);
|
SDL_RenderPresent(renderer_);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void Screen::setVideoMode(ScreenVideoMode videoMode)
|
void Screen::setVideoMode(ScreenVideoMode video_mode)
|
||||||
{
|
{
|
||||||
#ifdef ARCADE
|
// Actualiza las opciones
|
||||||
options.video.mode = ScreenVideoMode::WINDOW;
|
options.video.mode = video_mode;
|
||||||
#else
|
|
||||||
options.video.mode = videoMode;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (options.video.mode)
|
// Configura el modo de pantalla
|
||||||
|
Uint32 flags = SDL_GetWindowFlags(window_);
|
||||||
|
if (flags != static_cast<Uint32>(options.video.mode))
|
||||||
{
|
{
|
||||||
case ScreenVideoMode::WINDOW:
|
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode));
|
||||||
{
|
|
||||||
// Cambia a modo de ventana
|
|
||||||
SDL_SetWindowFullscreen(window_, 0);
|
|
||||||
|
|
||||||
#ifdef ARCADE
|
|
||||||
// Oculta el puntero
|
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
|
||||||
#else
|
|
||||||
// Muestra el puntero
|
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
|
||||||
#endif
|
|
||||||
// Modifica el tamaño de la ventana
|
|
||||||
SDL_Point pos = getNewPosition();
|
|
||||||
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
|
||||||
SDL_SetWindowPosition(window_, pos.x, pos.y);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
|
||||||
case ScreenVideoMode::FULLSCREEN:
|
|
||||||
{
|
|
||||||
// Aplica el modo de video
|
|
||||||
SDL_SetWindowFullscreen(window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
||||||
|
|
||||||
// Oculta el puntero
|
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reinicia los shaders
|
|
||||||
if (options.video.shaders)
|
|
||||||
{
|
|
||||||
#ifndef NO_SHADERS
|
|
||||||
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
|
||||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
|
||||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
|
||||||
|
|
||||||
shader::init(window_, game_canvas_, source.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,43 +107,56 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
void Screen::toggleVideoMode()
|
void Screen::toggleVideoMode()
|
||||||
{
|
{
|
||||||
options.video.mode = options.video.mode == ScreenVideoMode::WINDOW ? ScreenVideoMode::FULLSCREEN : ScreenVideoMode::WINDOW;
|
options.video.mode = options.video.mode == ScreenVideoMode::WINDOW ? ScreenVideoMode::FULLSCREEN : ScreenVideoMode::WINDOW;
|
||||||
setVideoMode(options.video.mode);
|
setVideoMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
// Cambia el tamaño de la ventana
|
||||||
void Screen::setWindowSize(int size)
|
void Screen::setWindowZoom(int zoom)
|
||||||
{
|
{
|
||||||
options.video.window.size = size;
|
options.video.window.zoom = zoom;
|
||||||
setVideoMode(ScreenVideoMode::WINDOW);
|
adjustWindowSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce el tamaño de la ventana
|
// Reduce el tamaño de la ventana
|
||||||
void Screen::decWindowSize()
|
bool Screen::decWindowZoom()
|
||||||
{
|
{
|
||||||
--options.video.window.size;
|
if (options.video.mode == ScreenVideoMode::WINDOW)
|
||||||
options.video.window.size = std::max(options.video.window.size, 1);
|
{
|
||||||
setVideoMode(ScreenVideoMode::WINDOW);
|
const int PREVIOUS_ZOOM = options.video.window.zoom;
|
||||||
|
--options.video.window.zoom;
|
||||||
|
options.video.window.zoom = std::max(options.video.window.zoom, 1);
|
||||||
|
|
||||||
|
if (options.video.window.zoom != PREVIOUS_ZOOM)
|
||||||
|
{
|
||||||
|
adjustWindowSize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aumenta el tamaño de la ventana
|
// Aumenta el tamaño de la ventana
|
||||||
void Screen::incWindowSize()
|
bool Screen::incWindowZoom()
|
||||||
{
|
{
|
||||||
++options.video.window.size;
|
if (options.video.mode == ScreenVideoMode::WINDOW)
|
||||||
options.video.window.size = std::min(options.video.window.size, options.video.window.max_size);
|
{
|
||||||
setVideoMode(ScreenVideoMode::WINDOW);
|
const int PREVIOUS_ZOOM = options.video.window.zoom;
|
||||||
}
|
++options.video.window.zoom;
|
||||||
|
options.video.window.zoom = std::min(options.video.window.zoom, options.video.window.max_zoom);
|
||||||
|
|
||||||
// Cambia el color del borde
|
if (options.video.window.zoom != PREVIOUS_ZOOM)
|
||||||
void Screen::setBorderColor(Color color)
|
{
|
||||||
{
|
adjustWindowSize();
|
||||||
border_color_ = color;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
// Cambia el tipo de mezcla
|
||||||
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
void Screen::setBlendMode(SDL_BlendMode blendMode) { SDL_SetRenderDrawBlendMode(renderer_, blendMode); }
|
||||||
{
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, blendMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void Screen::update()
|
void Screen::update()
|
||||||
@@ -284,10 +216,7 @@ void Screen::updateShakeEffect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pone la pantalla de color
|
// Pone la pantalla de color
|
||||||
void Screen::flash(Color color, int lenght, int delay)
|
void Screen::flash(Color color, int lenght, int delay) { flash_effect_ = FlashEffect(true, lenght, delay, color); }
|
||||||
{
|
|
||||||
flash_effect_ = FlashEffect(true, lenght, delay, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
void Screen::renderFlash()
|
void Screen::renderFlash()
|
||||||
@@ -300,10 +229,7 @@ void Screen::renderFlash()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el efecto de flash
|
// Actualiza el efecto de flash
|
||||||
void Screen::updateFlash()
|
void Screen::updateFlash() { flash_effect_.update(); }
|
||||||
{
|
|
||||||
flash_effect_.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void Screen::renderAttenuate()
|
void Screen::renderAttenuate()
|
||||||
@@ -346,28 +272,14 @@ void Screen::renderShake()
|
|||||||
void Screen::toggleShaders()
|
void Screen::toggleShaders()
|
||||||
{
|
{
|
||||||
options.video.shaders = !options.video.shaders;
|
options.video.shaders = !options.video.shaders;
|
||||||
setVideoMode(options.video.mode);
|
Notifier::get()->show({"Shaders " + std::string(options.video.shaders ? "on" : "off")});
|
||||||
const std::string value = options.video.shaders ? "on" : "off";
|
|
||||||
Notifier::get()->showText({"Shaders " + value});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa / desactiva la información de debug
|
// Activa / desactiva la información de debug
|
||||||
void Screen::toggleDebugInfo()
|
void Screen::toggleDebugInfo() { show_debug_info_ = !show_debug_info_; }
|
||||||
{
|
|
||||||
show_info_ = !show_info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void Screen::attenuate(bool value)
|
void Screen::attenuate(bool value) { attenuate_effect_ = value; }
|
||||||
{
|
|
||||||
attenuate_effect_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
|
||||||
SDL_Renderer *Screen::getRenderer()
|
|
||||||
{
|
|
||||||
return renderer_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula los frames por segundo
|
// Calcula los frames por segundo
|
||||||
void Screen::updateFPS()
|
void Screen::updateFPS()
|
||||||
@@ -383,7 +295,7 @@ void Screen::updateFPS()
|
|||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void Screen::renderInfo()
|
void Screen::renderInfo()
|
||||||
{
|
{
|
||||||
if (show_info_)
|
if (show_debug_info_)
|
||||||
{
|
{
|
||||||
// FPS
|
// FPS
|
||||||
const std::string fpstext = std::to_string(fps_) + " FPS";
|
const std::string fpstext = std::to_string(fps_) + " FPS";
|
||||||
@@ -400,38 +312,77 @@ void Screen::renderInfo()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
// Reinicia los shaders
|
||||||
SDL_Point Screen::getNewPosition()
|
void Screen::initShaders()
|
||||||
{
|
{
|
||||||
// Obtiene la posición actual de la ventana
|
if (options.video.shaders)
|
||||||
SDL_Point current_position;
|
{
|
||||||
SDL_GetWindowPosition(window_, ¤t_position.x, ¤t_position.y);
|
const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
||||||
|
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
|
||||||
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
// Obtiene las dimensiones actuales de la ventana
|
shader::init(window_, game_canvas_, source.c_str());
|
||||||
int current_width, current_height;
|
}
|
||||||
SDL_GetWindowSize(window_, ¤t_width, ¤t_height);
|
}
|
||||||
|
|
||||||
// Obtiene las dimesiones que tendrá la ventana
|
// Calcula el tamaño de la ventana
|
||||||
const int new_width = param.game.width * options.video.window.size;
|
void Screen::adjustWindowSize()
|
||||||
const int new_height = param.game.height * options.video.window.size;
|
{
|
||||||
|
options.video.window.max_zoom = getMaxZoom();
|
||||||
|
|
||||||
// Obtiene el centro de la ventana actual
|
// Establece el nuevo tamaño
|
||||||
SDL_Point center;
|
if (options.video.mode == ScreenVideoMode::WINDOW)
|
||||||
center.x = current_position.x + current_width / 2;
|
{
|
||||||
center.y = current_position.y + current_height / 2;
|
const int WIDTH = param.game.width * options.video.window.zoom;
|
||||||
|
const int HEIGHT = param.game.height * options.video.window.zoom;
|
||||||
|
|
||||||
// Calcula la nueva posición a partir del centro y las nuevas diemsiones
|
int old_width, old_height;
|
||||||
SDL_Point new_pos;
|
SDL_GetWindowSize(window_, &old_width, &old_height);
|
||||||
new_pos.x = center.x - new_width / 2;
|
|
||||||
new_pos.y = center.y - new_height / 2;
|
|
||||||
|
|
||||||
// Obtiene las dimensiones del escritorio
|
int old_pos_x, old_pos_y;
|
||||||
|
SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y);
|
||||||
|
|
||||||
|
const int NEW_POS_X = old_pos_x + (old_width - WIDTH) / 2;
|
||||||
|
const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2;
|
||||||
|
|
||||||
|
SDL_Rect viewport = {0, 0, WIDTH, HEIGHT};
|
||||||
|
SDL_RenderSetViewport(renderer_, &viewport);
|
||||||
|
|
||||||
|
SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
|
||||||
|
SDL_SetWindowSize(window_, WIDTH, HEIGHT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajusta el tamaño lógico del renderizador
|
||||||
|
void Screen::adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height); }
|
||||||
|
|
||||||
|
// Obtiene el tamaño máximo de zoom posible para la ventana
|
||||||
|
int Screen::getMaxZoom()
|
||||||
|
{
|
||||||
|
// Obtiene información sobre la pantalla
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
|
|
||||||
// Evita que la ventana quede fuera del escritorio
|
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||||
new_pos.x = std::clamp(new_pos.x, 30, DM.w - new_width);
|
const int MAX_ZOOM = std::min(DM.w / param.game.width, (DM.h - WINDOWS_DECORATIONS_) / param.game.height);
|
||||||
new_pos.y = std::clamp(new_pos.y, 30, DM.h - new_height);
|
|
||||||
|
|
||||||
return new_pos;
|
// Normaliza los valores de zoom
|
||||||
|
options.video.window.zoom = std::min(options.video.window.zoom, MAX_ZOOM);
|
||||||
|
|
||||||
|
return MAX_ZOOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderiza todos los overlays y efectos
|
||||||
|
void Screen::renderOverlays()
|
||||||
|
{
|
||||||
|
// Actualiza el contador de FPS
|
||||||
|
++fps_counter_;
|
||||||
|
|
||||||
|
// Dibuja efectos y elementos sobre el game_canvas_
|
||||||
|
renderShake();
|
||||||
|
renderFlash();
|
||||||
|
renderAttenuate();
|
||||||
|
OnScreenHelp::get()->render();
|
||||||
|
renderInfo();
|
||||||
|
Notifier::get()->render();
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "utils.h" // Para Color
|
#include "utils.h" // Para Color
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
enum class ScreenFilter : int
|
enum class ScreenFilter : int
|
||||||
{
|
{
|
||||||
@@ -15,16 +16,19 @@ enum class ScreenFilter : int
|
|||||||
LINEAL = 1,
|
LINEAL = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ScreenVideoMode : int
|
enum class ScreenVideoMode : Uint32
|
||||||
{
|
{
|
||||||
WINDOW = 0,
|
WINDOW = 0,
|
||||||
FULLSCREEN = 1,
|
FULLSCREEN = SDL_WINDOW_FULLSCREEN_DESKTOP,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
// Constantes
|
||||||
|
static constexpr int WINDOWS_DECORATIONS_ = 35;
|
||||||
|
|
||||||
|
// [SINGLETON] Objeto privado
|
||||||
static Screen *screen_;
|
static Screen *screen_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
@@ -35,7 +39,6 @@ private:
|
|||||||
// Variables
|
// Variables
|
||||||
SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
||||||
SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
Color border_color_ = Color(); // Color del borde añadido a la textura de juego para rellenar la pantalla
|
|
||||||
bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada
|
bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada
|
||||||
Uint32 fps_ticks_ = 0; // Ticks para contar los frames por segundo
|
Uint32 fps_ticks_ = 0; // Ticks para contar los frames por segundo
|
||||||
int fps_counter_ = 0; // Contador de frames por segundo
|
int fps_counter_ = 0; // Contador de frames por segundo
|
||||||
@@ -44,7 +47,7 @@ private:
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||||
#else
|
#else
|
||||||
bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct FlashEffect
|
struct FlashEffect
|
||||||
@@ -107,16 +110,23 @@ private:
|
|||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void renderInfo();
|
void renderInfo();
|
||||||
|
|
||||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
|
||||||
SDL_Point getNewPosition();
|
|
||||||
|
|
||||||
// Actualiza la pantalla con el contenido del game_canvas_
|
|
||||||
void presentGameCanvas();
|
|
||||||
|
|
||||||
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
|
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
|
||||||
void renderScreen();
|
void renderScreen();
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
// Reinicia los shaders
|
||||||
|
void initShaders();
|
||||||
|
|
||||||
|
// Calcula el tamaño de la ventana
|
||||||
|
void adjustWindowSize();
|
||||||
|
|
||||||
|
// Ajusta el tamaño lógico del renderizador
|
||||||
|
void adjustRenderLogicalSize();
|
||||||
|
|
||||||
|
// Obtiene el tamaño máximo de zoom posible para la ventana
|
||||||
|
int getMaxZoom();
|
||||||
|
|
||||||
|
// Renderiza todos los overlays y efectos
|
||||||
|
void renderOverlays();
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
@@ -125,13 +135,13 @@ private:
|
|||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
static void init(SDL_Window *window, SDL_Renderer *renderer);
|
static void init(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
static Screen *get();
|
static Screen *get();
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
@@ -147,22 +157,19 @@ public:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(ScreenVideoMode video_mode);
|
void setVideoMode(ScreenVideoMode video_mode = options.video.mode);
|
||||||
|
|
||||||
// Cambia entre pantalla completa y ventana
|
// Cambia entre pantalla completa y ventana
|
||||||
void toggleVideoMode();
|
void toggleVideoMode();
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
// Cambia el tamaño de la ventana
|
||||||
void setWindowSize(int size);
|
void setWindowZoom(int size);
|
||||||
|
|
||||||
// Reduce el tamaño de la ventana
|
// Reduce el tamaño de la ventana
|
||||||
void decWindowSize();
|
bool decWindowZoom();
|
||||||
|
|
||||||
// Aumenta el tamaño de la ventana
|
// Aumenta el tamaño de la ventana
|
||||||
void incWindowSize();
|
bool incWindowZoom();
|
||||||
|
|
||||||
// Cambia el color del borde
|
|
||||||
void setBorderColor(Color color);
|
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
// Cambia el tipo de mezcla
|
||||||
void setBlendMode(SDL_BlendMode blend_mode);
|
void setBlendMode(SDL_BlendMode blend_mode);
|
||||||
@@ -182,6 +189,12 @@ public:
|
|||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void attenuate(bool value);
|
void attenuate(bool value);
|
||||||
|
|
||||||
// Obtiene el puntero al renderizador
|
// Getters
|
||||||
SDL_Renderer *getRenderer();
|
SDL_Renderer *getRenderer() { return renderer_; }
|
||||||
|
|
||||||
|
// Muestra la ventana
|
||||||
|
void show() { SDL_ShowWindow(window_); }
|
||||||
|
|
||||||
|
// Oculta la ventana
|
||||||
|
void hide() { SDL_HideWindow(window_); }
|
||||||
};
|
};
|
||||||
@@ -2,10 +2,6 @@
|
|||||||
#include "moving_sprite.h" // Para MovingSprite
|
#include "moving_sprite.h" // Para MovingSprite
|
||||||
class Texture; // lines 2-2
|
class Texture; // lines 2-2
|
||||||
|
|
||||||
// Constructor
|
|
||||||
SmartSprite::SmartSprite(std::shared_ptr<Texture> texture)
|
|
||||||
: AnimatedSprite(texture) {}
|
|
||||||
|
|
||||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
void SmartSprite::update()
|
void SmartSprite::update()
|
||||||
{
|
{
|
||||||
@@ -17,22 +13,13 @@ void SmartSprite::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Dibuja el sprite
|
||||||
void SmartSprite::setFinishedCounter(int value)
|
void SmartSprite::render()
|
||||||
{
|
{
|
||||||
finished_counter_ = value;
|
if (enabled_)
|
||||||
}
|
{
|
||||||
|
MovingSprite::render();
|
||||||
// Establece el valor de la variable
|
}
|
||||||
void SmartSprite::setDestX(int x)
|
|
||||||
{
|
|
||||||
dest_x_ = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void SmartSprite::setDestY(int y)
|
|
||||||
{
|
|
||||||
dest_y_ = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el movimiento
|
// Comprueba el movimiento
|
||||||
@@ -115,21 +102,3 @@ void SmartSprite::checkFinished()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool SmartSprite::isOnDestination() const
|
|
||||||
{
|
|
||||||
return on_destination_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool SmartSprite::hasFinished() const
|
|
||||||
{
|
|
||||||
return finished_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Habilita el objeto
|
|
||||||
void SmartSprite::setEnabled(bool value)
|
|
||||||
{
|
|
||||||
enabled_ = value;
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit SmartSprite(std::shared_ptr<Texture> texture);
|
explicit SmartSprite(std::shared_ptr<Texture> texture)
|
||||||
|
: AnimatedSprite(texture) {}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~SmartSprite() = default;
|
~SmartSprite() = default;
|
||||||
@@ -32,27 +33,18 @@ public:
|
|||||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Dibuja el sprite
|
||||||
void setFinishedCounter(int value);
|
void render() override;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Getters
|
||||||
void setDestX(int x);
|
int getDestX() const { return dest_x_; }
|
||||||
|
int getDestY() const { return dest_y_; }
|
||||||
|
bool isOnDestination() const { return on_destination_; }
|
||||||
|
bool hasFinished() const { return finished_; }
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Setters
|
||||||
void setDestY(int y);
|
void setFinishedCounter(int value) { finished_counter_ = value; }
|
||||||
|
void setDestX(int x) { dest_x_ = x; }
|
||||||
// Obtiene el valor de la variable
|
void setDestY(int y) { dest_y_ = y; }
|
||||||
int getDestX() const;
|
void setEnabled(bool value) { enabled_ = value; }
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
int getDestY() const;
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool isOnDestination() const;
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool hasFinished() const;
|
|
||||||
|
|
||||||
// Habilita el objeto
|
|
||||||
void setEnabled(bool value);
|
|
||||||
};
|
};
|
||||||
@@ -275,12 +275,6 @@ int Text::getCharacterSize() const
|
|||||||
return box_width_;
|
return box_width_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void Text::reLoadTexture()
|
|
||||||
{
|
|
||||||
sprite_->getTexture()->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void Text::setFixedWidth(bool value)
|
void Text::setFixedWidth(bool value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,9 +76,6 @@ public:
|
|||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int getCharacterSize() const;
|
int getCharacterSize() const;
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void reLoadTexture();
|
|
||||||
|
|
||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void setFixedWidth(bool value);
|
void setFixedWidth(bool value);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // Para char_traits, operator<<, operator+
|
#include <string> // Para char_traits, operator<<, operator+
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "gif.c" // Para LoadGif, LoadPalette
|
#include "gif.h" // Para LoadGif, LoadPalette
|
||||||
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
|
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
|
||||||
#include "utils.h" // Para getFileName, printWithDots
|
#include "utils.h" // Para getFileName, printWithDots
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,3 @@ void TiledBG::update()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void TiledBG::reLoad()
|
|
||||||
{
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
@@ -52,7 +52,4 @@ public:
|
|||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void reLoad();
|
|
||||||
};
|
};
|
||||||
111
source/title.cpp
@@ -12,7 +12,7 @@
|
|||||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R...
|
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R...
|
||||||
#include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
|
#include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "mouse.h" // Para handleEvent
|
#include "global_events.h" // Para handleEvent
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "options.h" // Para OptionsController, Options, options
|
#include "options.h" // Para OptionsController, Options, options
|
||||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||||
@@ -46,9 +46,9 @@ Title::Title()
|
|||||||
|
|
||||||
// Asigna valores a otras variables
|
// Asigna valores a otras variables
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
const bool is_title_to_demo = (section::attract_mode == section::AttractMode::TITLE_TO_DEMO);
|
const bool IS_TITLE_TO_DEMO = (section::attract_mode == section::AttractMode::TITLE_TO_DEMO);
|
||||||
next_section_ = is_title_to_demo ? section::Name::GAME_DEMO : section::Name::LOGO;
|
next_section_ = IS_TITLE_TO_DEMO ? section::Name::GAME_DEMO : section::Name::LOGO;
|
||||||
section::attract_mode = is_title_to_demo ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO;
|
section::attract_mode = IS_TITLE_TO_DEMO ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -213,71 +213,51 @@ void Title::render()
|
|||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Title::checkEvents()
|
void Title::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba el input para el resto de objetos
|
SDL_Event event;
|
||||||
define_buttons_->checkEvents();
|
while (SDL_PollEvent(&event))
|
||||||
|
|
||||||
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
|
||||||
if (!define_buttons_->isEnabled())
|
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
||||||
while (SDL_PollEvent(&event))
|
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
bool should_reset = false;
|
||||||
if (event.type == SDL_QUIT)
|
|
||||||
|
switch (event.key.keysym.sym)
|
||||||
{
|
{
|
||||||
section::name = section::Name::QUIT;
|
case SDLK_1: // Redefine los botones del mando #0
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
should_reset = define_buttons_->enable(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_2: // Redefine los botones del mando #1
|
||||||
|
should_reset = define_buttons_->enable(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
||||||
|
swapControllers();
|
||||||
|
should_reset = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_4: // Intercambia la asignación del teclado
|
||||||
|
swapKeyboard();
|
||||||
|
should_reset = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_5: // Muestra la asignación de mandos y teclado
|
||||||
|
showControllers();
|
||||||
|
should_reset = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
// Resetear el contador si es necesario
|
||||||
else if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
if (should_reset)
|
||||||
{
|
{
|
||||||
reLoadTextures();
|
resetCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
|
||||||
{
|
|
||||||
switch (event.key.keysym.sym)
|
|
||||||
{
|
|
||||||
case SDLK_1: // Redefine los botones del mando #0
|
|
||||||
{
|
|
||||||
if (define_buttons_->enable(0))
|
|
||||||
resetCounter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_2: // Redefine los botones del mando #1
|
|
||||||
{
|
|
||||||
if (define_buttons_->enable(1))
|
|
||||||
resetCounter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
|
||||||
{
|
|
||||||
swapControllers();
|
|
||||||
resetCounter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_4: // Intercambia la asignación del teclado
|
|
||||||
{
|
|
||||||
swapKeyboard();
|
|
||||||
resetCounter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDLK_5: // Muestra la asignacion de mandos y teclado
|
|
||||||
{
|
|
||||||
showControllers();
|
|
||||||
resetCounter();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el cursor
|
|
||||||
Mouse::handleEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalEvents::check(event);
|
||||||
|
define_buttons_->checkEvents(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,13 +330,6 @@ void Title::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void Title::reLoadTextures()
|
|
||||||
{
|
|
||||||
game_logo_->reLoad();
|
|
||||||
tiled_bg_->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reinicia el contador interno
|
// Reinicia el contador interno
|
||||||
void Title::resetCounter() { counter_ = 0; }
|
void Title::resetCounter() { counter_ = 0; }
|
||||||
|
|
||||||
@@ -375,7 +348,7 @@ void Title::swapKeyboard()
|
|||||||
{
|
{
|
||||||
swapOptionsKeyboard();
|
swapOptionsKeyboard();
|
||||||
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
|
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
|
||||||
Notifier::get()->showText({text});
|
Notifier::get()->show({text});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra información sobre los controles y los jugadores
|
// Muestra información sobre los controles y los jugadores
|
||||||
@@ -404,5 +377,5 @@ void Title::showControllers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra la notificación
|
// Muestra la notificación
|
||||||
Notifier::get()->showText({text.at(0), text.at(1)});
|
Notifier::get()->show({text.at(0), text.at(1)});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ private:
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
// Recarga las texturas
|
|
||||||
void reLoadTextures();
|
|
||||||
|
|
||||||
// Reinicia el contador interno
|
// Reinicia el contador interno
|
||||||
void resetCounter();
|
void resetCounter();
|
||||||
|
|
||||||
|
|||||||
@@ -32,20 +32,20 @@ const Color green_sky_color = Color(0X00, 0X79, 0X6B);
|
|||||||
// Obtiene un color del vector de colores imitando al Coche Fantástico
|
// Obtiene un color del vector de colores imitando al Coche Fantástico
|
||||||
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_)
|
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_)
|
||||||
{
|
{
|
||||||
int cycle_length = colors.size() * 2 - 2;
|
int cycle_length = colors.size() * 2 - 2;
|
||||||
size_t n = counter_ % cycle_length;
|
size_t n = counter_ % cycle_length;
|
||||||
|
|
||||||
size_t index;
|
size_t index;
|
||||||
if (n < colors.size())
|
if (n < colors.size())
|
||||||
{
|
{
|
||||||
index = n; // Avanza: 0,1,2,3
|
index = n; // Avanza: 0,1,2,3
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1
|
index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1
|
||||||
}
|
}
|
||||||
|
|
||||||
return colors[index];
|
return colors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||