El responsable de comprobar si se ha pulsado alguna tecla para cambiar el tamaño de la venta, el modo de pantalla completa o la activación de los shaders pasa a ser la clase screen
This commit is contained in:
@@ -8,13 +8,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->options = options;
|
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
this->input = input;
|
||||||
|
this->options = options;
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
|
SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
|
||||||
@@ -80,7 +81,20 @@ void Screen::blit()
|
|||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
doAttenuate();
|
doAttenuate();
|
||||||
|
|
||||||
#ifndef RASPI
|
#ifdef RASPI
|
||||||
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
|
// Borra el contenido previo
|
||||||
|
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
|
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||||
|
|
||||||
|
// Muestra por pantalla el renderizador
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
#else
|
||||||
if (options->video.shaders)
|
if (options->video.shaders)
|
||||||
{
|
{
|
||||||
shader::render();
|
shader::render();
|
||||||
@@ -100,19 +114,6 @@ void Screen::blit()
|
|||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Borra el contenido previo
|
|
||||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +201,9 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef RASPI
|
#ifdef RASPI
|
||||||
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
|
#else
|
||||||
// Reinicia los shaders
|
// Reinicia los shaders
|
||||||
if (options->video.shaders)
|
if (options->video.shaders)
|
||||||
{
|
{
|
||||||
@@ -215,8 +218,6 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
{
|
{
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Actualiza las opciones
|
// Actualiza las opciones
|
||||||
@@ -369,6 +370,30 @@ void Screen::update()
|
|||||||
updateShake();
|
updateShake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void Screen::checkInput()
|
||||||
|
{
|
||||||
|
if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
switchVideoMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
decWindowSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
incWindowSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input->checkInput(input_video_shaders, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
switchShaders();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void Screen::shake()
|
void Screen::shake()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "input.h"
|
||||||
#include "../const.h"
|
#include "../const.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ private:
|
|||||||
SDL_Window *window; // Ventana de la aplicación
|
SDL_Window *window; // Ventana de la aplicación
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Asset *asset; // Objeto con el listado de recursos
|
Asset *asset; // Objeto con el listado de recursos
|
||||||
|
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Screen();
|
~Screen();
|
||||||
@@ -89,6 +91,9 @@ public:
|
|||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void clean(color_t color = {0x00, 0x00, 0x00});
|
void clean(color_t color = {0x00, 0x00, 0x00});
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,17 @@ Director::Director(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section = new section_t();
|
section = new section_t();
|
||||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
section->name = SECTION_PROG_LOGO;
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
createSystemFolder("jailgames");
|
createSystemFolder("jailgames");
|
||||||
#ifndef DEBUG
|
#ifdef DEBUG
|
||||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
|
||||||
#else
|
|
||||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition_debug");
|
createSystemFolder("jailgames/coffee_crisis_arcade_edition_debug");
|
||||||
|
#else
|
||||||
|
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Inicializa las opciones del programa
|
// Inicializa las opciones del programa
|
||||||
@@ -61,7 +61,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
initInput();
|
initInput();
|
||||||
|
|
||||||
screen = new Screen(window, renderer, asset, options);
|
screen = new Screen(window, renderer, asset, input, options);
|
||||||
|
|
||||||
// Carga los sonidos del juego
|
// Carga los sonidos del juego
|
||||||
loadSounds();
|
loadSounds();
|
||||||
|
|||||||
@@ -169,13 +169,11 @@ void Game::init(int playerID)
|
|||||||
// Crea los jugadores
|
// Crea los jugadores
|
||||||
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[0], playerAnimations);
|
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[0], playerAnimations);
|
||||||
players.push_back(player1);
|
players.push_back(player1);
|
||||||
|
|
||||||
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[1], playerAnimations);
|
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[1], playerAnimations);
|
||||||
players.push_back(player2);
|
players.push_back(player2);
|
||||||
|
|
||||||
numPlayers = 2;
|
numPlayers = 2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Variables relacionadas con la dificultad
|
// Variables relacionadas con la dificultad
|
||||||
switch (difficulty)
|
switch (difficulty)
|
||||||
@@ -1630,7 +1628,7 @@ void Game::updateDeath()
|
|||||||
fade->activate();
|
fade->activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fade->hasEnded())
|
if (fade->hasEnded())
|
||||||
{
|
{
|
||||||
// section->subsection = SUBSECTION_GAME_GAMEOVER;
|
// section->subsection = SUBSECTION_GAME_GAMEOVER;
|
||||||
@@ -2504,6 +2502,9 @@ void Game::update()
|
|||||||
// Actualiza el contador de juego
|
// Actualiza el contador de juego
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
// Comprueba si la música ha de estar sonando
|
||||||
|
checkMusicStatus();
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen->update();
|
screen->update();
|
||||||
|
|
||||||
@@ -2693,26 +2694,6 @@ void Game::checkGameInput()
|
|||||||
pause(!paused);
|
pause(!paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_video_shaders, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchShaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modo Demo activo
|
// Modo Demo activo
|
||||||
if (demo.enabled)
|
if (demo.enabled)
|
||||||
{
|
{
|
||||||
@@ -2885,6 +2866,9 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta diferentes mensajes en la pantalla
|
// Pinta diferentes mensajes en la pantalla
|
||||||
@@ -2981,39 +2965,32 @@ void Game::disableTimeStopItem()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si la música ha de estar sonando
|
||||||
|
void Game::checkMusicStatus()
|
||||||
|
{
|
||||||
|
// Si la música no está sonando
|
||||||
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
|
{
|
||||||
|
// Reproduce la música
|
||||||
|
if (!gameCompleted)
|
||||||
|
{
|
||||||
|
if (players[0]->isAlive() || players[1]->isAlive())
|
||||||
|
{
|
||||||
|
JA_PlayMusic(music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void Game::run()
|
void Game::run()
|
||||||
{
|
{
|
||||||
while (section->name == SECTION_PROG_GAME)
|
while (section->name == SECTION_PROG_GAME)
|
||||||
{
|
{
|
||||||
// Sección juego jugando
|
checkGameInput();
|
||||||
if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P))
|
update();
|
||||||
{
|
checkEvents(); // Tiene que ir antes del render
|
||||||
// Si la música no está sonando
|
render();
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
{
|
|
||||||
// Reproduce la música
|
|
||||||
if (!gameCompleted)
|
|
||||||
{
|
|
||||||
if (players[0]->isAlive())
|
|
||||||
{
|
|
||||||
JA_PlayMusic(music);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el teclado/mando
|
|
||||||
checkGameInput();
|
|
||||||
|
|
||||||
// Actualiza la lógica del juego
|
|
||||||
update();
|
|
||||||
|
|
||||||
// Comprueba los eventos que hay en cola
|
|
||||||
checkEvents();
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3198,6 +3175,11 @@ void Game::checkEvents()
|
|||||||
{
|
{
|
||||||
pause(false);
|
pause(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
reloadTextures();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -467,6 +467,9 @@ private:
|
|||||||
// Pausa el juego
|
// Pausa el juego
|
||||||
void pause(bool value);
|
void pause(bool value);
|
||||||
|
|
||||||
|
// Comprueba si la música ha de estar sonando
|
||||||
|
void checkMusicStatus();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
|
Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
|
||||||
|
|||||||
@@ -58,12 +58,6 @@ HiScoreTable::~HiScoreTable()
|
|||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void HiScoreTable::update()
|
void HiScoreTable::update()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos
|
|
||||||
checkEventHandler();
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
checkInput();
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
{
|
{
|
||||||
@@ -144,8 +138,15 @@ void HiScoreTable::render()
|
|||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void HiScoreTable::reloadTextures()
|
||||||
|
{
|
||||||
|
text->reLoadTexture();
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void HiScoreTable::checkEventHandler()
|
void HiScoreTable::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
// Comprueba los eventos que hay en la cola
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
@@ -156,6 +157,15 @@ void HiScoreTable::checkEventHandler()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||||
|
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||||
|
{
|
||||||
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
reloadTextures();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,27 +177,15 @@ void HiScoreTable::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para la pantalla de instrucciones
|
// Bucle para la pantalla de instrucciones
|
||||||
@@ -195,7 +193,9 @@ void HiScoreTable::run()
|
|||||||
{
|
{
|
||||||
while (section->name == SECTION_PROG_HI_SCORE_TABLE)
|
while (section->name == SECTION_PROG_HI_SCORE_TABLE)
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
update();
|
update();
|
||||||
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
@@ -59,6 +59,9 @@ private:
|
|||||||
// Crea el contenido de la textura con la lista de puntuaciones
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void reloadTextures();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);
|
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
|
|||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
|
||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section->name = SECTION_PROG_INSTRUCTIONS;
|
section->name = SECTION_PROG_INSTRUCTIONS;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
@@ -35,7 +33,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
|
|||||||
counter = 0;
|
counter = 0;
|
||||||
counterEnd = 700;
|
counterEnd = 700;
|
||||||
view = {0, 0, param->gameWidth, param->gameHeight};
|
view = {0, 0, param->gameWidth, param->gameHeight};
|
||||||
spritePos = {0,0};
|
spritePos = {0, 0};
|
||||||
|
|
||||||
// Rellena la textura de texto
|
// Rellena la textura de texto
|
||||||
fillTexture();
|
fillTexture();
|
||||||
@@ -153,17 +151,17 @@ void Instructions::fillTexture()
|
|||||||
|
|
||||||
// Calcula cual es el texto más largo de las descripciones de los items
|
// Calcula cual es el texto más largo de las descripciones de los items
|
||||||
int lenght = 0;
|
int lenght = 0;
|
||||||
for (int i= 17; i <=21;++i)
|
for (int i = 17; i <= 21; ++i)
|
||||||
{
|
{
|
||||||
const int l = text->lenght(lang->getText(i));
|
const int l = text->lenght(lang->getText(i));
|
||||||
lenght = l > lenght? l : lenght;
|
lenght = l > lenght ? l : lenght;
|
||||||
}
|
}
|
||||||
const int anchorItem = (param->gameWidth - (lenght + 24)) / 2;
|
const int anchorItem = (param->gameWidth - (lenght + 24)) / 2;
|
||||||
|
|
||||||
// BORRAR ESTO
|
// BORRAR ESTO
|
||||||
//SDL_SetRenderDrawColor(renderer, 255, 255, 255, 32);
|
// SDL_SetRenderDrawColor(renderer, 255, 255, 255, 32);
|
||||||
//SDL_Rect rect = {10, firstLine, param->gameWidth - 20, size};
|
// SDL_Rect rect = {10, firstLine, param->gameWidth - 20, size};
|
||||||
//SDL_RenderFillRect(renderer, &rect);
|
// SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
// Escribe el texto de las instrucciones
|
// Escribe el texto de las instrucciones
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, firstLine, lang->getText(11), 1, orangeColor, 1, shdwTxtColor);
|
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, firstLine, lang->getText(11), 1, orangeColor, 1, shdwTxtColor);
|
||||||
@@ -179,11 +177,11 @@ void Instructions::fillTexture()
|
|||||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, anchor2, lang->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, anchor2, lang->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
|
||||||
const int anchor3 = anchor2 + spacePostHeader;
|
const int anchor3 = anchor2 + spacePostHeader;
|
||||||
text->writeShadowed(anchorItem+24, anchor3 + spaceBetweenItemLines * 0, lang->getText(17), shdwTxtColor);
|
text->writeShadowed(anchorItem + 24, anchor3 + spaceBetweenItemLines * 0, lang->getText(17), shdwTxtColor);
|
||||||
text->writeShadowed(anchorItem+24, anchor3 + spaceBetweenItemLines * 1, lang->getText(18), shdwTxtColor);
|
text->writeShadowed(anchorItem + 24, anchor3 + spaceBetweenItemLines * 1, lang->getText(18), shdwTxtColor);
|
||||||
text->writeShadowed(anchorItem+24, anchor3 + spaceBetweenItemLines * 2, lang->getText(19), shdwTxtColor);
|
text->writeShadowed(anchorItem + 24, anchor3 + spaceBetweenItemLines * 2, lang->getText(19), shdwTxtColor);
|
||||||
text->writeShadowed(anchorItem+24, anchor3 + spaceBetweenItemLines * 3, lang->getText(20), shdwTxtColor);
|
text->writeShadowed(anchorItem + 24, anchor3 + spaceBetweenItemLines * 3, lang->getText(20), shdwTxtColor);
|
||||||
text->writeShadowed(anchorItem+24, anchor3 + spaceBetweenItemLines * 4, lang->getText(21), shdwTxtColor);
|
text->writeShadowed(anchorItem + 24, anchor3 + spaceBetweenItemLines * 4, lang->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
// Deja el renderizador como estaba
|
// Deja el renderizador como estaba
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
@@ -220,9 +218,6 @@ void Instructions::fillBackbuffer()
|
|||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void Instructions::update()
|
void Instructions::update()
|
||||||
{
|
{
|
||||||
// Comprueba las entradas
|
|
||||||
checkInput();
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
{
|
{
|
||||||
@@ -271,6 +266,17 @@ void Instructions::render()
|
|||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void Instructions::reloadTextures()
|
||||||
|
{
|
||||||
|
for (auto tex : itemTextures)
|
||||||
|
{
|
||||||
|
tex->reLoad();
|
||||||
|
}
|
||||||
|
text->reLoadTexture();
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Instructions::checkEvents()
|
void Instructions::checkEvents()
|
||||||
{
|
{
|
||||||
@@ -283,6 +289,15 @@ void Instructions::checkEvents()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||||
|
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||||
|
{
|
||||||
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
reloadTextures();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,27 +309,15 @@ void Instructions::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para la pantalla de instrucciones
|
// Bucle para la pantalla de instrucciones
|
||||||
@@ -322,8 +325,9 @@ void Instructions::run()
|
|||||||
{
|
{
|
||||||
while (section->name == SECTION_PROG_INSTRUCTIONS)
|
while (section->name == SECTION_PROG_INSTRUCTIONS)
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ private:
|
|||||||
// Actualiza los sprites
|
// Actualiza los sprites
|
||||||
void updateSprites();
|
void updateSprites();
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void reloadTextures();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section);
|
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section);
|
||||||
|
|||||||
@@ -161,6 +161,13 @@ Intro::~Intro()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void Intro::reloadTextures()
|
||||||
|
{
|
||||||
|
texture->reLoad();
|
||||||
|
text->reLoadTexture();
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Intro::checkEvents()
|
void Intro::checkEvents()
|
||||||
{
|
{
|
||||||
@@ -173,6 +180,15 @@ void Intro::checkEvents()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||||
|
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||||
|
{
|
||||||
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
reloadTextures();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,27 +200,15 @@ void Intro::checkInput()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las escenas de la intro
|
// Actualiza las escenas de la intro
|
||||||
@@ -366,8 +370,6 @@ void Intro::updateScenes()
|
|||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Intro::update()
|
void Intro::update()
|
||||||
{
|
{
|
||||||
checkInput();
|
|
||||||
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
@@ -420,8 +422,9 @@ void Intro::run()
|
|||||||
|
|
||||||
while (section->name == SECTION_PROG_INTRO)
|
while (section->name == SECTION_PROG_INTRO)
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ 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(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);
|
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ Logo::~Logo()
|
|||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recarga todas las texturas
|
||||||
|
void Logo::reloadTextures()
|
||||||
|
{
|
||||||
|
jailTexture->reLoad();
|
||||||
|
sinceTexture->reLoad();
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Logo::checkEvents()
|
void Logo::checkEvents()
|
||||||
{
|
{
|
||||||
@@ -79,6 +86,15 @@ void Logo::checkEvents()
|
|||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||||
|
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||||
|
{
|
||||||
|
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
|
{
|
||||||
|
reloadTextures();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,22 +103,7 @@ void Logo::checkInput()
|
|||||||
{
|
{
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_QUIT;
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkAnyInput())
|
else if (input->checkAnyInput())
|
||||||
@@ -110,6 +111,9 @@ void Logo::checkInput()
|
|||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
screen->checkInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAME
|
||||||
@@ -288,8 +292,9 @@ void Logo::run()
|
|||||||
|
|
||||||
while (section->name == SECTION_PROG_LOGO)
|
while (section->name == SECTION_PROG_LOGO)
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,9 @@ private:
|
|||||||
// 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(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section);
|
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section);
|
||||||
|
|||||||
@@ -243,25 +243,8 @@ void Title::checkInput()
|
|||||||
postFade = 0;
|
postFade = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
|
// Comprueba el input para el resto de objetos
|
||||||
{
|
screen->checkInput();
|
||||||
screen->switchVideoMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->decWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->incWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (input->checkInput(input_video_shaders, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
screen->switchShaders();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
@@ -271,7 +254,7 @@ void Title::run()
|
|||||||
{
|
{
|
||||||
checkInput();
|
checkInput();
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user