Compare commits
2 Commits
2ac425483b
...
3ba4293e8a
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ba4293e8a | |||
| 8ae686a70b |
@@ -44,24 +44,6 @@ constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
|
||||
// Secciones del programa
|
||||
constexpr int SECTION_LOGO = 0;
|
||||
constexpr int SECTION_LOADING_SCREEN = 1;
|
||||
constexpr int SECTION_TITLE = 2;
|
||||
constexpr int SECTION_CREDITS = 3;
|
||||
constexpr int SECTION_GAME = 4;
|
||||
constexpr int SECTION_DEMO = 5;
|
||||
constexpr int SECTION_GAME_OVER = 6;
|
||||
constexpr int SECTION_ENDING = 7;
|
||||
constexpr int SECTION_ENDING2 = 8;
|
||||
constexpr int SECTION_QUIT = 9;
|
||||
|
||||
// Subsecciones
|
||||
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
|
||||
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
|
||||
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
|
||||
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
|
||||
|
||||
// Colores
|
||||
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||
const color_t black = {0xFF, 0xFF, 0xFF};
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||
#include "asset.h"
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
class Asset;
|
||||
|
||||
// Constructor
|
||||
@@ -77,54 +79,14 @@ void Credits::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::checkInput()
|
||||
{
|
||||
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_TITLE;
|
||||
options.section.subsection = 0;
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Inicializa los textos
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "utils.h" // Para color_t, stringToColor, options_t, secti...
|
||||
#include "options.h"
|
||||
#include "debug.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Demo::Demo()
|
||||
@@ -74,58 +76,14 @@ void Demo::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
screen->setBorderColor(stringToColor(options.palette, "black"));
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Demo::checkInput()
|
||||
{
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->decWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->incWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_TITLE;
|
||||
options.section.subsection = 0;
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Ending::Ending()
|
||||
@@ -160,49 +162,14 @@ void Ending::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending::checkInput()
|
||||
{
|
||||
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_LOGO;
|
||||
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Inicializa los textos
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for color_t, stringToColor, options_t
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Ending2::Ending2()
|
||||
@@ -190,49 +192,14 @@ void Ending2::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending2::checkInput()
|
||||
{
|
||||
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_LOGO;
|
||||
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "utils.h" // for options_t, cheat_t, stringToColor
|
||||
#include "options.h"
|
||||
#include "notifier.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Game::Game()
|
||||
@@ -130,24 +132,13 @@ void Game::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
||||
{
|
||||
reLoadTextures();
|
||||
}
|
||||
globalEvents::check(event);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
||||
{
|
||||
switch (event.key.keysym.scancode)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
case SDL_SCANCODE_G:
|
||||
debug_->switchEnabled();
|
||||
options.cheat.invincible = debug_->getEnabled();
|
||||
@@ -190,23 +181,18 @@ void Game::checkEvents()
|
||||
case SDL_SCANCODE_F9:
|
||||
Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 5);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el teclado
|
||||
void Game::checkInput()
|
||||
{
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_TITLE;
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||
if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||
{
|
||||
board_.music = !board_.music;
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
@@ -217,39 +203,7 @@ void Game::checkInput()
|
||||
switchPause();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleBorder();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleVideoMode();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleShaders();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen_->decWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen_->incWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
@@ -506,7 +460,7 @@ void Game::killPlayer()
|
||||
setBlackScreen();
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room_ = new Room(resource_->getRoom(current_room_),item_tracker_, &board_.items, board_.jailEnabled);
|
||||
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jailEnabled);
|
||||
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||
#include "texture.h" // Para Texture
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
GameOver::GameOver()
|
||||
@@ -126,49 +128,14 @@ void GameOver::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
options.section.subsection = 0;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void GameOver::checkInput()
|
||||
{
|
||||
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
|
||||
24
source/global_events.cpp
Normal file
24
source/global_events.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "global_events.h"
|
||||
#include "options.h" // Para Options, options, OptionsGame, OptionsAudio
|
||||
#include "mouse.h"
|
||||
|
||||
namespace globalEvents
|
||||
{
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||
void check(const SDL_Event &event)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
||||
{
|
||||
//reLoadTextures();
|
||||
}
|
||||
|
||||
Mouse::handleEvent(event);
|
||||
}
|
||||
}
|
||||
9
source/global_events.h
Normal file
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);
|
||||
}
|
||||
80
source/global_inputs.cpp
Normal file
80
source/global_inputs.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "global_inputs.h"
|
||||
#include "input.h" // Para Input, InputDeviceToUse, InputType, INPU...
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "options.h" // Para Options, options, OptionsGame, OptionsAudio
|
||||
#include "screen.h" // Para Screen, ScreenVideoMode
|
||||
|
||||
namespace globalInputs
|
||||
{
|
||||
// Cambia la paleta
|
||||
void switchPalette()
|
||||
{
|
||||
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||
}
|
||||
|
||||
// Cambia de seccion
|
||||
void skip_section()
|
||||
{
|
||||
switch (options.section.name)
|
||||
{
|
||||
case SECTION_LOGO:
|
||||
case SECTION_LOADING_SCREEN:
|
||||
case SECTION_CREDITS:
|
||||
case SECTION_DEMO:
|
||||
case SECTION_GAME_OVER:
|
||||
case SECTION_ENDING:
|
||||
case SECTION_ENDING2:
|
||||
options.section.name = SECTION_TITLE;
|
||||
options.section.subsection = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check()
|
||||
{
|
||||
if (Input::get()->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_accept, REPEAT_FALSE))
|
||||
{
|
||||
skip_section();
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->toggleBorder();
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->toggleVideoMode();
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->decWindowSize();
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->incWindowSize();
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
{
|
||||
Screen::get()->toggleShaders();
|
||||
Notifier::get()->show("HOLA");
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
source/global_inputs.h
Normal file
7
source/global_inputs.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace globalInputs
|
||||
{
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
void check();
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for options_t, section_t, color_t, stringToC...
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
LoadingScreen::LoadingScreen()
|
||||
@@ -80,54 +82,14 @@ void LoadingScreen::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void LoadingScreen::checkInput()
|
||||
{
|
||||
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_TITLE;
|
||||
options.section.subsection = 0;
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Gestiona el contador de carga
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "utils.h" // for color_t, section_t, options_t, stringToC...
|
||||
#include "asset.h"
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
class Asset; // lines 11-11
|
||||
|
||||
// Constructor
|
||||
@@ -75,53 +77,14 @@ void Logo::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput()
|
||||
{
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
options.section.name = SECTION_TITLE;
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleVideoMode();
|
||||
}
|
||||
|
||||
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_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||
{
|
||||
options.section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||
endSection();
|
||||
}
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
@@ -310,12 +273,6 @@ void Logo::run()
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia la paleta
|
||||
void Logo::switchPalette()
|
||||
{
|
||||
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||
}
|
||||
|
||||
// Termina la sección
|
||||
void Logo::endSection()
|
||||
{
|
||||
|
||||
@@ -55,9 +55,6 @@ private:
|
||||
// Gestiona el color de las texturas
|
||||
void updateTextureColors();
|
||||
|
||||
// Cambia la paleta
|
||||
void switchPalette();
|
||||
|
||||
// Termina la sección
|
||||
void endSection();
|
||||
|
||||
|
||||
33
source/mouse.cpp
Normal file
33
source/mouse.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "mouse.h"
|
||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
|
||||
namespace Mouse
|
||||
{
|
||||
Uint32 cursor_hide_time = 3000; // Tiempo en milisegundos para ocultar el cursor
|
||||
Uint32 last_mouse_move_time = 0; // Última vez que el ratón se movió
|
||||
bool cursor_visible = true; // Estado del cursor
|
||||
|
||||
void handleEvent(const SDL_Event &event)
|
||||
{
|
||||
if (event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
last_mouse_move_time = SDL_GetTicks();
|
||||
if (!cursor_visible)
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
cursor_visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateCursorVisibility()
|
||||
{
|
||||
Uint32 current_time = SDL_GetTicks();
|
||||
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time))
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
cursor_visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
source/mouse.h
Normal file
14
source/mouse.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
|
||||
namespace Mouse
|
||||
{
|
||||
extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el cursor
|
||||
extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió
|
||||
extern bool cursor_visible; // Estado del cursor
|
||||
|
||||
void handleEvent(const SDL_Event &event);
|
||||
void updateCursorVisibility();
|
||||
}
|
||||
@@ -5,6 +5,24 @@
|
||||
#include <string> // Para string, basic_string
|
||||
#include "utils.h"
|
||||
|
||||
// Secciones del programa
|
||||
constexpr int SECTION_LOGO = 0;
|
||||
constexpr int SECTION_LOADING_SCREEN = 1;
|
||||
constexpr int SECTION_TITLE = 2;
|
||||
constexpr int SECTION_CREDITS = 3;
|
||||
constexpr int SECTION_GAME = 4;
|
||||
constexpr int SECTION_DEMO = 5;
|
||||
constexpr int SECTION_GAME_OVER = 6;
|
||||
constexpr int SECTION_ENDING = 7;
|
||||
constexpr int SECTION_ENDING2 = 8;
|
||||
constexpr int SECTION_QUIT = 9;
|
||||
|
||||
// Subsecciones
|
||||
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
|
||||
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
|
||||
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
|
||||
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
|
||||
|
||||
// Posiciones de las notificaciones
|
||||
enum not_pos_e
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "jail_shader.h" // Para init, render
|
||||
#include "notifier.h" // Para Notify
|
||||
#include "options.h"
|
||||
#include "mouse.h"
|
||||
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
@@ -489,4 +490,5 @@ void Screen::toggleShaders()
|
||||
void Screen::update()
|
||||
{
|
||||
Notifier::get()->update();
|
||||
Mouse::updateCursorVisibility();
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||
#include "options.h"
|
||||
#include "global_inputs.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
@@ -104,12 +106,7 @@ void Title::checkEvents()
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
globalEvents::check(event);
|
||||
|
||||
// Solo se comprueban estas teclas si no está activo el menu de logros
|
||||
if (event.type == SDL_KEYDOWN)
|
||||
@@ -148,62 +145,22 @@ void Title::checkInput()
|
||||
{
|
||||
moveCheevosList(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
if (show_cheevos_)
|
||||
else if (input_->checkInput(input_accept, REPEAT_FALSE))
|
||||
{
|
||||
hideCheevosList();
|
||||
counter_ = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleBorder();
|
||||
resource_->reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleVideoMode();
|
||||
resource_->reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
{
|
||||
screen_->toggleShaders();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen_->decWindowSize();
|
||||
resource_->reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen_->incWindowSize();
|
||||
resource_->reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_pause, REPEAT_FALSE))
|
||||
if (input_->checkInput(input_accept, REPEAT_FALSE))
|
||||
{
|
||||
if (state_ == show_loading_screen)
|
||||
{
|
||||
state_ = fade_loading_screen;
|
||||
}
|
||||
}
|
||||
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Actualiza la marquesina
|
||||
@@ -461,7 +418,7 @@ void Title::createCheevosTexture()
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Escribe la lista de logros en la textura
|
||||
const std::string cheevosOwner = "LOCAL ACHIEVEMENTS";
|
||||
const std::string cheevosOwner = "ACHIEVEMENTS";
|
||||
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")";
|
||||
int pos = 2;
|
||||
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green"));
|
||||
|
||||
Reference in New Issue
Block a user