singletons
This commit is contained in:
@@ -6,27 +6,22 @@
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||
#include <string> // for basic_string
|
||||
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/locale/lang.h" // for Lang
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/locale/lang.h" // for Lang
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/resource.h"
|
||||
#include "game/defaults.hpp" // for shdwTxtColor, GAMECANVAS_CENTER_X, GAME...
|
||||
#include "utils/utils.h" // for color_t, section_t
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) {
|
||||
Instructions::Instructions(SDL_Renderer *renderer, section_t *section) {
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->lang = lang;
|
||||
this->section = section;
|
||||
|
||||
// Texturas (handles compartidos de Resource)
|
||||
@@ -122,21 +117,21 @@ void Instructions::render() {
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 8, lang->getText(11), 1, orangeColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 24, lang->getText(12), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 34, lang->getText(13), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 48, lang->getText(14), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 58, lang->getText(15), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 75, lang->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 8, Lang::get()->getText(11), 1, orangeColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 24, Lang::get()->getText(12), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 34, Lang::get()->getText(13), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 48, Lang::get()->getText(14), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 58, Lang::get()->getText(15), 1, noColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, 75, Lang::get()->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
||||
|
||||
text->writeShadowed(84, 92, lang->getText(17), shdwTxtColor);
|
||||
text->writeShadowed(84, 108, lang->getText(18), shdwTxtColor);
|
||||
text->writeShadowed(84, 124, lang->getText(19), shdwTxtColor);
|
||||
text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor);
|
||||
text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor);
|
||||
text->writeShadowed(84, 92, Lang::get()->getText(17), shdwTxtColor);
|
||||
text->writeShadowed(84, 108, Lang::get()->getText(18), shdwTxtColor);
|
||||
text->writeShadowed(84, 124, Lang::get()->getText(19), shdwTxtColor);
|
||||
text->writeShadowed(84, 140, Lang::get()->getText(20), shdwTxtColor);
|
||||
text->writeShadowed(84, 156, Lang::get()->getText(21), shdwTxtColor);
|
||||
|
||||
if ((mode == m_manual) && (counter % 50 > 14)) {
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - 12, Lang::get()->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Disquito
|
||||
@@ -178,10 +173,10 @@ void Instructions::render() {
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
Screen::get()->clean(bgColor);
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
if (mode == m_auto) {
|
||||
@@ -195,7 +190,7 @@ void Instructions::render() {
|
||||
SDL_RenderTexture(renderer, backbuffer, nullptr, &fWindow);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -216,15 +211,15 @@ void Instructions::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Instructions::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
quitRequested = true;
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (GlobalInputs::handle(screen, input)) { return; }
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
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)) {
|
||||
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
|
||||
if (mode == m_auto) {
|
||||
finished = true;
|
||||
} else {
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <vector> // for vector
|
||||
class Asset;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Screen;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
@@ -22,14 +18,10 @@ class Instructions {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
std::vector<Texture *> itemTextures; // Vector con las texturas de los items
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||
Sprite *sprite; // Sprite con la textura de las instrucciones
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Text *text; // Objeto para escribir texto
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
@@ -48,7 +40,7 @@ class Instructions {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
|
||||
Instructions(SDL_Renderer *renderer, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Instructions();
|
||||
|
||||
@@ -4,28 +4,23 @@
|
||||
|
||||
#include <string> // for basic_string
|
||||
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/locale/lang.h" // for Lang
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/smartsprite.h" // for SmartSprite
|
||||
#include "core/rendering/text.h" // for Text
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/rendering/writer.h" // for Writer
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
#include "core/resources/resource.h"
|
||||
#include "game/defaults.hpp" // for GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QU...
|
||||
#include "utils/utils.h" // for section_t, color_t
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) {
|
||||
Intro::Intro(SDL_Renderer *renderer, section_t *section) {
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->lang = lang;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
@@ -115,39 +110,39 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
|
||||
}
|
||||
|
||||
// Un dia qualsevol de l'any 2000
|
||||
texts[0]->setCaption(lang->getText(27));
|
||||
texts[0]->setCaption(Lang::get()->getText(27));
|
||||
texts[0]->setSpeed(8);
|
||||
|
||||
// Tot esta tranquil a la UPV
|
||||
texts[1]->setCaption(lang->getText(28));
|
||||
texts[1]->setCaption(Lang::get()->getText(28));
|
||||
texts[1]->setSpeed(8);
|
||||
|
||||
// Fins que un desaprensiu...
|
||||
texts[2]->setCaption(lang->getText(29));
|
||||
texts[2]->setCaption(Lang::get()->getText(29));
|
||||
texts[2]->setSpeed(12);
|
||||
|
||||
// HEY! ME ANE A FERME UN CORTAET...
|
||||
texts[3]->setCaption(lang->getText(30));
|
||||
texts[3]->setCaption(Lang::get()->getText(30));
|
||||
texts[3]->setSpeed(8);
|
||||
|
||||
// UAAAAAAAAAAAAA!!!
|
||||
texts[4]->setCaption(lang->getText(31));
|
||||
texts[4]->setCaption(Lang::get()->getText(31));
|
||||
texts[4]->setSpeed(1);
|
||||
|
||||
// Espera un moment...
|
||||
texts[5]->setCaption(lang->getText(32));
|
||||
texts[5]->setCaption(Lang::get()->getText(32));
|
||||
texts[5]->setSpeed(16);
|
||||
|
||||
// Si resulta que no tinc solt!
|
||||
texts[6]->setCaption(lang->getText(33));
|
||||
texts[6]->setCaption(Lang::get()->getText(33));
|
||||
texts[6]->setSpeed(2);
|
||||
|
||||
// MERDA DE MAQUINA!
|
||||
texts[7]->setCaption(lang->getText(34));
|
||||
texts[7]->setCaption(Lang::get()->getText(34));
|
||||
texts[7]->setSpeed(3);
|
||||
|
||||
// Blop... blop... blop...
|
||||
texts[8]->setCaption(lang->getText(35));
|
||||
texts[8]->setCaption(Lang::get()->getText(35));
|
||||
texts[8]->setSpeed(16);
|
||||
|
||||
for (auto text : texts) {
|
||||
@@ -193,14 +188,14 @@ void Intro::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Intro::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (GlobalInputs::handle(screen, input)) { return; }
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
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)) {
|
||||
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
|
||||
JA_StopMusic();
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
@@ -369,10 +364,10 @@ void Intro::update() {
|
||||
// Dibuja el objeto en pantalla
|
||||
void Intro::render() {
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
Screen::get()->clean(bgColor);
|
||||
|
||||
// Dibuja los objetos
|
||||
for (auto bitmap : bitmaps) {
|
||||
@@ -384,7 +379,7 @@ void Intro::render() {
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <vector> // for vector
|
||||
class Asset;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
@@ -19,12 +15,8 @@ class Intro {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Texture *texture; // Textura con los graficos
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||
std::vector<Writer *> texts; // Textos de la intro
|
||||
Text *text; // Textos de la intro
|
||||
@@ -56,7 +48,7 @@ class Intro {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
|
||||
Intro(SDL_Renderer *renderer, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Intro();
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include <algorithm> // for min
|
||||
#include <string> // for basic_string
|
||||
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
#include "core/resources/resource.h"
|
||||
#include "game/defaults.hpp" // for bgColor, SECTION_PROG_LOGO, SECTION_PROG...
|
||||
#include "utils/utils.h" // for section_t, color_t
|
||||
@@ -21,12 +21,9 @@ constexpr int INIT_FADE = 100;
|
||||
constexpr int END_LOGO = 200;
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section) {
|
||||
Logo::Logo(SDL_Renderer *renderer, section_t *section) {
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
@@ -76,14 +73,14 @@ void Logo::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (GlobalInputs::handle(screen, input)) { return; }
|
||||
if (GlobalInputs::handle()) { return; }
|
||||
|
||||
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)) {
|
||||
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
@@ -120,10 +117,10 @@ void Logo::update() {
|
||||
// Dibuja el objeto en pantalla
|
||||
void Logo::render() {
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean({238, 238, 238});
|
||||
Screen::get()->clean({238, 238, 238});
|
||||
|
||||
// Dibuja los objetos
|
||||
sprite->render();
|
||||
@@ -132,7 +129,7 @@ void Logo::render() {
|
||||
renderFade();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
class Asset;
|
||||
class Input;
|
||||
class Screen;
|
||||
class Sprite;
|
||||
class Texture;
|
||||
struct section_t;
|
||||
@@ -13,9 +10,6 @@ class Logo {
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Texture *texture; // Textura con los graficos
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Sprite *sprite; // Sprite con la textura del logo
|
||||
@@ -46,7 +40,7 @@ class Logo {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section);
|
||||
Logo(SDL_Renderer *renderer, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Logo();
|
||||
|
||||
@@ -25,13 +25,9 @@
|
||||
#include "game/ui/menu.h" // for Menu
|
||||
|
||||
// Constructor
|
||||
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, Lang *lang, section_t *section) {
|
||||
Title::Title(SDL_Renderer *renderer, section_t *section) {
|
||||
// Copia las direcciones de los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
this->asset = asset;
|
||||
this->lang = lang;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
@@ -136,7 +132,7 @@ void Title::init() {
|
||||
deviceIndex.push_back(0); // El primer mando encontrado. Si no ha encontrado ninguno es el teclado
|
||||
|
||||
// Si ha encontrado un mando se lo asigna al segundo jugador
|
||||
if (input->gameControllerFound()) {
|
||||
if (Input::get()->gameControllerFound()) {
|
||||
Options::inputs[1].id = availableInputDevices[deviceIndex[1]].id;
|
||||
Options::inputs[1].name = availableInputDevices[deviceIndex[1]].name;
|
||||
Options::inputs[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
||||
@@ -241,10 +237,10 @@ void Title::update() {
|
||||
// que Screen::blit() presente por la ruta activa (GPU o
|
||||
// SDL_Renderer). Un `SDL_RenderPresent(renderer)` directe
|
||||
// crasheja quan el SDL3 GPU ha reclamat la ventana.
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(crashSound);
|
||||
@@ -513,10 +509,10 @@ void Title::render() {
|
||||
// Sección 1 - Titulo desplazandose
|
||||
case SUBSECTION_TITLE_1: {
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
Screen::get()->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
{
|
||||
@@ -532,16 +528,16 @@ void Title::render() {
|
||||
crisisBitmap->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
} break;
|
||||
|
||||
// Sección 2 - Titulo vibrando
|
||||
case SUBSECTION_TITLE_2: {
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
Screen::get()->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
{
|
||||
@@ -560,15 +556,15 @@ void Title::render() {
|
||||
dustBitmapL->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
} break;
|
||||
|
||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
||||
case SUBSECTION_TITLE_3: { // Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
Screen::get()->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
{
|
||||
@@ -598,14 +594,14 @@ void Title::render() {
|
||||
|
||||
// PRESS ANY KEY!
|
||||
if ((counter % 50 > 14) && (menuVisible == false)) {
|
||||
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor);
|
||||
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, Lang::get()->getText(23), 1, noColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Fade
|
||||
fade->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
Screen::get()->blit();
|
||||
} break;
|
||||
|
||||
default:
|
||||
@@ -642,12 +638,12 @@ void Title::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Title::checkInput() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
GlobalInputs::handle(screen, input);
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Actualiza el tileado de fondo
|
||||
@@ -673,37 +669,37 @@ void Title::updateMenuLabels() {
|
||||
// DIFFICULTY
|
||||
switch (Options::settings.difficulty) {
|
||||
case DIFFICULTY_EASY:
|
||||
menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(66)); // EASY
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(59) + ": " + Lang::get()->getText(66)); // EASY
|
||||
break;
|
||||
|
||||
case DIFFICULTY_NORMAL:
|
||||
menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(67)); // NORMAL
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(59) + ": " + Lang::get()->getText(67)); // NORMAL
|
||||
break;
|
||||
|
||||
case DIFFICULTY_HARD:
|
||||
menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(68)); // HARD
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(59) + ": " + Lang::get()->getText(68)); // HARD
|
||||
break;
|
||||
|
||||
default:
|
||||
menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(67)); // NORMAL
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(59) + ": " + Lang::get()->getText(67)); // NORMAL
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
// PLAYER 1 CONTROLS
|
||||
menu.options->setItemCaption(i, lang->getText(62));
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(62));
|
||||
|
||||
i++;
|
||||
// PLAYER 1 CONTROLS - OPTIONS
|
||||
switch (Options::inputs[0].deviceType) {
|
||||
case INPUT_USE_KEYBOARD:
|
||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||
menu.options->setGreyed(i, false);
|
||||
break;
|
||||
|
||||
case INPUT_USE_GAMECONTROLLER:
|
||||
menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER
|
||||
if (!input->gameControllerFound())
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||
if (!Input::get()->gameControllerFound())
|
||||
menu.options->setGreyed(i, true);
|
||||
else {
|
||||
menu.options->setGreyed(i, false);
|
||||
@@ -712,25 +708,25 @@ void Title::updateMenuLabels() {
|
||||
break;
|
||||
|
||||
default:
|
||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
// PLAYER 2 CONTROLS
|
||||
menu.options->setItemCaption(i, lang->getText(63));
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(63));
|
||||
|
||||
i++;
|
||||
// PLAYER 2 CONTROLS - OPTIONS
|
||||
switch (Options::inputs[1].deviceType) {
|
||||
case INPUT_USE_KEYBOARD:
|
||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||
menu.options->setGreyed(i, false);
|
||||
break;
|
||||
|
||||
case INPUT_USE_GAMECONTROLLER:
|
||||
menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER
|
||||
if (!input->gameControllerFound())
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||
if (!Input::get()->gameControllerFound())
|
||||
menu.options->setGreyed(i, true);
|
||||
else {
|
||||
menu.options->setGreyed(i, false);
|
||||
@@ -739,7 +735,7 @@ void Title::updateMenuLabels() {
|
||||
break;
|
||||
|
||||
default:
|
||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -747,59 +743,59 @@ void Title::updateMenuLabels() {
|
||||
// LANGUAGE
|
||||
switch (Options::settings.language) {
|
||||
case es_ES:
|
||||
menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(24)); // SPANISH
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(24)); // SPANISH
|
||||
break;
|
||||
|
||||
case ba_BA:
|
||||
menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(25)); // VALENCIAN
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(25)); // VALENCIAN
|
||||
break;
|
||||
|
||||
case en_UK:
|
||||
menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(26)); // ENGLISH
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(26)); // ENGLISH
|
||||
break;
|
||||
|
||||
default:
|
||||
menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(26)); // ENGLISH
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(26)); // ENGLISH
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
// DISPLAY MODE
|
||||
menu.options->setItemCaption(i, lang->getText(58));
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(58));
|
||||
|
||||
i++;
|
||||
// DISPLAY MODE - OPTIONS
|
||||
menu.options->setItemCaption(i, Options::video.fullscreen ? lang->getText(5) : lang->getText(4));
|
||||
menu.options->setItemCaption(i, Options::video.fullscreen ? Lang::get()->getText(5) : Lang::get()->getText(4));
|
||||
|
||||
i++;
|
||||
// WINDOW SIZE
|
||||
menu.options->setItemCaption(i, lang->getText(7) + " x" + std::to_string(Options::window.zoom)); // WINDOW SIZE
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(7) + " x" + std::to_string(Options::window.zoom)); // WINDOW SIZE
|
||||
|
||||
i++;
|
||||
// SCALE MODE
|
||||
if (Options::video.scale_mode == SDL_SCALEMODE_LINEAR)
|
||||
menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(71)); // BILINEAL
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(60) + ": " + Lang::get()->getText(71)); // BILINEAL
|
||||
else
|
||||
menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(72)); // LINEAL
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(60) + ": " + Lang::get()->getText(72)); // LINEAL
|
||||
|
||||
i++;
|
||||
// VSYNC
|
||||
if (Options::video.vsync)
|
||||
menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(73)); // ON
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(61) + ": " + Lang::get()->getText(73)); // ON
|
||||
else
|
||||
menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(74)); // OFF
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(61) + ": " + Lang::get()->getText(74)); // OFF
|
||||
|
||||
i++;
|
||||
// HOW TO PLAY
|
||||
menu.options->setItemCaption(i, lang->getText(2));
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(2));
|
||||
|
||||
i++;
|
||||
// ACCEPT
|
||||
menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(9)); // ACCEPT
|
||||
|
||||
i++;
|
||||
// CANCEL
|
||||
menu.options->setItemCaption(i, lang->getText(10)); // CANCEL
|
||||
menu.options->setItemCaption(i, Lang::get()->getText(10)); // CANCEL
|
||||
|
||||
// Recoloca el menu de opciones
|
||||
menu.options->centerMenuOnX(GAMECANVAS_CENTER_X);
|
||||
@@ -808,13 +804,13 @@ void Title::updateMenuLabels() {
|
||||
|
||||
// Establece las etiquetas del menu de titulo
|
||||
#ifdef GAME_CONSOLE
|
||||
menu.title->setItemCaption(0, lang->getText(0)); // PLAY
|
||||
menu.title->setItemCaption(0, Lang::get()->getText(0)); // PLAY
|
||||
#else
|
||||
menu.title->setItemCaption(0, lang->getText(51)); // 1 PLAYER
|
||||
menu.title->setItemCaption(0, Lang::get()->getText(51)); // 1 PLAYER
|
||||
#endif
|
||||
menu.title->setItemCaption(1, lang->getText(52)); // 2 PLAYERS
|
||||
menu.title->setItemCaption(2, lang->getText(1)); // OPTIONS
|
||||
menu.title->setItemCaption(3, lang->getText(3)); // QUIT
|
||||
menu.title->setItemCaption(1, Lang::get()->getText(52)); // 2 PLAYERS
|
||||
menu.title->setItemCaption(2, Lang::get()->getText(1)); // OPTIONS
|
||||
menu.title->setItemCaption(3, Lang::get()->getText(3)); // QUIT
|
||||
#ifdef __EMSCRIPTEN__
|
||||
menu.title->setVisible(3, false);
|
||||
menu.title->setSelectable(3, false);
|
||||
@@ -825,8 +821,8 @@ void Title::updateMenuLabels() {
|
||||
menu.title->centerMenuElementsOnX();
|
||||
|
||||
// Establece las etiquetas del menu de seleccion de jugador
|
||||
menu.playerSelect->setItemCaption(0, lang->getText(39)); // SELECT PLAYER
|
||||
menu.playerSelect->setItemCaption(3, lang->getText(40)); // BACK
|
||||
menu.playerSelect->setItemCaption(0, Lang::get()->getText(39)); // SELECT PLAYER
|
||||
menu.playerSelect->setItemCaption(3, Lang::get()->getText(40)); // BACK
|
||||
|
||||
// Recoloca el menu de selección de jugador
|
||||
menu.playerSelect->centerMenuOnX(GAMECANVAS_CENTER_X);
|
||||
@@ -846,11 +842,11 @@ void Title::updateMenuLabels() {
|
||||
|
||||
// Aplica las opciones de menu seleccionadas
|
||||
void Title::applyOptions() {
|
||||
screen->setVideoMode(Options::video.fullscreen);
|
||||
screen->setWindowZoom(Options::window.zoom);
|
||||
screen->setVSync(Options::video.vsync);
|
||||
Screen::get()->setVideoMode(Options::video.fullscreen);
|
||||
Screen::get()->setWindowZoom(Options::window.zoom);
|
||||
Screen::get()->setVSync(Options::video.vsync);
|
||||
|
||||
lang->setLang(Options::settings.language);
|
||||
Lang::get()->setLang(Options::settings.language);
|
||||
|
||||
updateMenuLabels();
|
||||
createTiledBackground();
|
||||
@@ -954,7 +950,7 @@ void Title::run() {
|
||||
|
||||
// Inicia la parte donde se muestran las instrucciones
|
||||
void Title::runInstructions(mode_e mode) {
|
||||
instructions = new Instructions(renderer, screen, asset, input, lang, section);
|
||||
instructions = new Instructions(renderer, section);
|
||||
instructions->start(mode);
|
||||
instructionsActive = true;
|
||||
instructionsMode = mode;
|
||||
@@ -965,7 +961,7 @@ void Title::runDemoGame() {
|
||||
// Temporalmente ponemos section para que el constructor de Game funcione
|
||||
section->name = SECTION_PROG_GAME;
|
||||
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
||||
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, section);
|
||||
demoGame = new Game(1, 0, renderer, true, section);
|
||||
demoGameActive = true;
|
||||
// Restauramos section para que Director no transicione fuera de Title
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
@@ -975,7 +971,7 @@ void Title::runDemoGame() {
|
||||
bool Title::updatePlayerInputs(int numPlayer) {
|
||||
const int numDevices = availableInputDevices.size();
|
||||
|
||||
if (!input->gameControllerFound()) { // Si no hay mandos se deja todo de manera prefijada
|
||||
if (!Input::get()->gameControllerFound()) { // Si no hay mandos se deja todo de manera prefijada
|
||||
deviceIndex[0] = 0;
|
||||
deviceIndex[1] = 0;
|
||||
|
||||
@@ -1035,7 +1031,7 @@ void Title::createTiledBackground() {
|
||||
}
|
||||
|
||||
// Crea los objetos para pintar en la textura de fondo
|
||||
Texture *bgTileTexture = new Texture(renderer, asset->get("title_bg_tile.png"));
|
||||
Texture *bgTileTexture = new Texture(renderer, Asset::get()->get("title_bg_tile.png"));
|
||||
Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer);
|
||||
|
||||
// Prepara para dibujar sobre la textura
|
||||
@@ -1069,7 +1065,7 @@ void Title::checkInputDevices() {
|
||||
if (Options::settings.console) {
|
||||
std::cout << "Filling devices for options menu..." << std::endl;
|
||||
}
|
||||
const int numControllers = input->getNumControllers();
|
||||
const int numControllers = Input::get()->getNumControllers();
|
||||
availableInputDevices.clear();
|
||||
input_t temp;
|
||||
|
||||
@@ -1077,7 +1073,7 @@ void Title::checkInputDevices() {
|
||||
if (numControllers > 0)
|
||||
for (int i = 0; i < numControllers; ++i) {
|
||||
temp.id = i;
|
||||
temp.name = input->getControllerName(i);
|
||||
temp.name = Input::get()->getControllerName(i);
|
||||
temp.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
availableInputDevices.push_back(temp);
|
||||
if (Options::settings.console) {
|
||||
|
||||
@@ -8,13 +8,9 @@
|
||||
#include "game/scenes/instructions.h" // for mode_e
|
||||
#include "utils/utils.h" // for input_t, section_t
|
||||
class AnimatedSprite;
|
||||
class Asset;
|
||||
class Fade;
|
||||
class Game;
|
||||
class Input;
|
||||
class Lang;
|
||||
class Menu;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Sprite;
|
||||
class Text;
|
||||
@@ -43,10 +39,6 @@ class Title {
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Instructions *instructions; // Objeto para la sección de las instrucciones
|
||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
@@ -73,19 +65,19 @@ class Title {
|
||||
Fade *fade; // Objeto para realizar fundidos en pantalla
|
||||
|
||||
// Variable
|
||||
JA_Music_t *titleMusic; // Musica para el titulo
|
||||
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
||||
int backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
|
||||
int counter; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo
|
||||
float sin[360]; // Vector con los valores del seno precalculados
|
||||
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
|
||||
bool demo; // Indica si el modo demo estará activo
|
||||
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
Uint8 postFade; // Opción a realizar cuando termina el fundido
|
||||
menu_t menu; // Variable con todos los objetos menus y sus variables
|
||||
JA_Music_t *titleMusic; // Musica para el titulo
|
||||
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
||||
int backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
|
||||
int counter; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo
|
||||
float sin[360]; // Vector con los valores del seno precalculados
|
||||
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
|
||||
bool demo; // Indica si el modo demo estará activo
|
||||
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
Uint8 postFade; // Opción a realizar cuando termina el fundido
|
||||
menu_t menu; // Variable con todos los objetos menus y sus variables
|
||||
// Snapshot per a permetre CANCEL al menú d'opcions.
|
||||
Options::Video prevVideo;
|
||||
Options::Window prevWindow;
|
||||
@@ -153,7 +145,7 @@ class Title {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, Lang *lang, section_t *section);
|
||||
Title(SDL_Renderer *renderer, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Title();
|
||||
|
||||
Reference in New Issue
Block a user