singletons
This commit is contained in:
@@ -5,35 +5,35 @@
|
|||||||
|
|
||||||
namespace GlobalInputs {
|
namespace GlobalInputs {
|
||||||
|
|
||||||
auto handle(Screen *screen, Input *input) -> bool {
|
auto handle() -> bool {
|
||||||
if (screen == nullptr || input == nullptr) { return false; }
|
if (Screen::get() == nullptr || Input::get() == nullptr) { return false; }
|
||||||
|
|
||||||
if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_window_fullscreen, REPEAT_FALSE)) {
|
||||||
screen->toggleVideoMode();
|
Screen::get()->toggleVideoMode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE)) {
|
||||||
screen->decWindowZoom();
|
Screen::get()->decWindowZoom();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE)) {
|
||||||
screen->incWindowZoom();
|
Screen::get()->incWindowZoom();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_prev_preset, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_prev_preset, REPEAT_FALSE)) {
|
||||||
screen->prevPreset();
|
Screen::get()->prevPreset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_next_preset, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_next_preset, REPEAT_FALSE)) {
|
||||||
screen->nextPreset();
|
Screen::get()->nextPreset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_toggle_shader, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_toggle_shader, REPEAT_FALSE)) {
|
||||||
screen->toggleShaderEnabled();
|
Screen::get()->toggleShaderEnabled();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_toggle_shader_type, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_toggle_shader_type, REPEAT_FALSE)) {
|
||||||
screen->toggleActiveShader();
|
Screen::get()->toggleActiveShader();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class Input;
|
|
||||||
class Screen;
|
|
||||||
|
|
||||||
namespace GlobalInputs {
|
namespace GlobalInputs {
|
||||||
// Gestiona els atalls globals disponibles en qualsevol escena: zoom de
|
// Gestiona els atalls globals disponibles en qualsevol escena: zoom de
|
||||||
// finestra (F1/F2), fullscreen (F3), presets de shader (F8/F9), toggle
|
// finestra (F1/F2), fullscreen (F3), presets de shader (F8/F9), toggle
|
||||||
// shader (F10) i tipus de shader POSTFX↔CRTPI (F11). Retorna true si ha
|
// shader (F10) i tipus de shader POSTFX↔CRTPI (F11). Retorna true si ha
|
||||||
// consumit alguna tecla (per si la capa cridant vol suprimir-la del
|
// consumit alguna tecla (per si la capa cridant vol suprimir-la del
|
||||||
// processament específic de l'escena).
|
// processament específic de l'escena).
|
||||||
auto handle(Screen *screen, Input *input) -> bool;
|
auto handle() -> bool;
|
||||||
} // namespace GlobalInputs
|
} // namespace GlobalInputs
|
||||||
|
|||||||
@@ -39,6 +39,23 @@ static void installWebStandardMapping(SDL_JoystickID jid) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
Input *Input::instance = nullptr;
|
||||||
|
|
||||||
|
// Singleton API
|
||||||
|
void Input::init(const std::string &gameControllerDbPath) {
|
||||||
|
Input::instance = new Input(gameControllerDbPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Input::destroy() {
|
||||||
|
delete Input::instance;
|
||||||
|
Input::instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Input::get() -> Input * {
|
||||||
|
return Input::instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file) {
|
Input::Input(std::string file) {
|
||||||
// Fichero gamecontrollerdb.txt
|
// Fichero gamecontrollerdb.txt
|
||||||
|
|||||||
@@ -79,10 +79,18 @@ class Input {
|
|||||||
// Construye el nombre visible de un mando (name truncado + sufijo #N)
|
// Construye el nombre visible de un mando (name truncado + sufijo #N)
|
||||||
std::string buildControllerName(SDL_Gamepad *pad, int padIndex);
|
std::string buildControllerName(SDL_Gamepad *pad, int padIndex);
|
||||||
|
|
||||||
public:
|
// Constructor privado (usar Input::init)
|
||||||
// Constructor
|
|
||||||
Input(std::string file);
|
Input(std::string file);
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
static Input *instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Singleton API
|
||||||
|
static void init(const std::string &gameControllerDbPath); // Crea la instancia
|
||||||
|
static void destroy(); // Libera la instancia
|
||||||
|
static auto get() -> Input *; // Obtiene el puntero a la instancia
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Input();
|
~Input();
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,25 @@
|
|||||||
#include "core/resources/asset.h" // for Asset
|
#include "core/resources/asset.h" // for Asset
|
||||||
#include "core/resources/resource_helper.h"
|
#include "core/resources/resource_helper.h"
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
Lang *Lang::instance = nullptr;
|
||||||
|
|
||||||
|
// Singleton API
|
||||||
|
void Lang::init() {
|
||||||
|
Lang::instance = new Lang();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lang::destroy() {
|
||||||
|
delete Lang::instance;
|
||||||
|
Lang::instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Lang::get() -> Lang * {
|
||||||
|
return Lang::instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Lang::Lang(Asset *mAsset) {
|
Lang::Lang() {
|
||||||
this->mAsset = mAsset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -21,19 +37,19 @@ bool Lang::setLang(Uint8 lang) {
|
|||||||
|
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case es_ES:
|
case es_ES:
|
||||||
file = mAsset->get("es_ES.txt");
|
file = Asset::get()->get("es_ES.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case en_UK:
|
case en_UK:
|
||||||
file = mAsset->get("en_UK.txt");
|
file = Asset::get()->get("en_UK.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ba_BA:
|
case ba_BA:
|
||||||
file = mAsset->get("ba_BA.txt");
|
file = Asset::get()->get("ba_BA.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
file = mAsset->get("en_UK.txt");
|
file = Asset::get()->get("en_UK.txt");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
class Asset;
|
|
||||||
|
|
||||||
// Códigos de idioma
|
// Códigos de idioma
|
||||||
constexpr int es_ES = 0;
|
constexpr int es_ES = 0;
|
||||||
@@ -17,12 +16,19 @@ constexpr int MAX_TEXT_STRINGS = 100;
|
|||||||
// Clase Lang
|
// Clase Lang
|
||||||
class Lang {
|
class Lang {
|
||||||
private:
|
private:
|
||||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
std::string mTextStrings[MAX_TEXT_STRINGS]; // Vector con los textos
|
std::string mTextStrings[MAX_TEXT_STRINGS]; // Vector con los textos
|
||||||
|
|
||||||
|
// Constructor privado (usar Lang::init)
|
||||||
|
Lang();
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
static Lang *instance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Singleton API
|
||||||
Lang(Asset *mAsset);
|
static void init(); // Crea la instancia
|
||||||
|
static void destroy(); // Libera la instancia
|
||||||
|
static auto get() -> Lang *; // Obtiene el puntero a la instancia
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Lang();
|
~Lang();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "core/input/mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
#include "core/input/mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
||||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
|
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
|
||||||
#include "core/resources/asset.h" // for Asset
|
|
||||||
#include "core/resources/resource.h"
|
#include "core/resources/resource.h"
|
||||||
#include "game/defaults.hpp" // for GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT
|
#include "game/defaults.hpp" // for GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT
|
||||||
#include "game/options.hpp" // for Options::video, Options::settings
|
#include "game/options.hpp" // for Options::video, Options::settings
|
||||||
@@ -60,12 +59,28 @@ namespace {
|
|||||||
} // namespace
|
} // namespace
|
||||||
#endif // __EMSCRIPTEN__
|
#endif // __EMSCRIPTEN__
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
Screen *Screen::instance = nullptr;
|
||||||
|
|
||||||
|
// Singleton API
|
||||||
|
void Screen::init(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
|
Screen::instance = new Screen(window, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Screen::destroy() {
|
||||||
|
delete Screen::instance;
|
||||||
|
Screen::instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Screen::get() -> Screen * {
|
||||||
|
return Screen::instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset) {
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->asset = asset;
|
|
||||||
|
|
||||||
gameCanvasWidth = GAMECANVAS_WIDTH;
|
gameCanvasWidth = GAMECANVAS_WIDTH;
|
||||||
gameCanvasHeight = GAMECANVAS_HEIGHT;
|
gameCanvasHeight = GAMECANVAS_HEIGHT;
|
||||||
@@ -586,8 +601,7 @@ void Screen::applyCurrentPostFXPreset() {
|
|||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
||||||
if (Options::postfx_presets.empty()) { return; }
|
if (Options::postfx_presets.empty()) { return; }
|
||||||
if (Options::current_postfx_preset < 0
|
if (Options::current_postfx_preset < 0 || Options::current_postfx_preset >= static_cast<int>(Options::postfx_presets.size())) {
|
||||||
|| Options::current_postfx_preset >= static_cast<int>(Options::postfx_presets.size())) {
|
|
||||||
Options::current_postfx_preset = 0;
|
Options::current_postfx_preset = 0;
|
||||||
}
|
}
|
||||||
const auto &PRESET = Options::postfx_presets[Options::current_postfx_preset];
|
const auto &PRESET = Options::postfx_presets[Options::current_postfx_preset];
|
||||||
@@ -608,8 +622,7 @@ void Screen::applyCurrentCrtPiPreset() {
|
|||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
||||||
if (Options::crtpi_presets.empty()) { return; }
|
if (Options::crtpi_presets.empty()) { return; }
|
||||||
if (Options::current_crtpi_preset < 0
|
if (Options::current_crtpi_preset < 0 || Options::current_crtpi_preset >= static_cast<int>(Options::crtpi_presets.size())) {
|
||||||
|| Options::current_crtpi_preset >= static_cast<int>(Options::crtpi_presets.size())) {
|
|
||||||
Options::current_crtpi_preset = 0;
|
Options::current_crtpi_preset = 0;
|
||||||
}
|
}
|
||||||
const auto &PRESET = Options::crtpi_presets[Options::current_crtpi_preset];
|
const auto &PRESET = Options::crtpi_presets[Options::current_crtpi_preset];
|
||||||
@@ -636,13 +649,11 @@ auto Screen::getCurrentPresetName() const -> const char* {
|
|||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return "---"; }
|
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return "---"; }
|
||||||
if (Options::video.shader.current_shader == Rendering::ShaderType::POSTFX) {
|
if (Options::video.shader.current_shader == Rendering::ShaderType::POSTFX) {
|
||||||
if (Options::current_postfx_preset >= 0
|
if (Options::current_postfx_preset >= 0 && Options::current_postfx_preset < static_cast<int>(Options::postfx_presets.size())) {
|
||||||
&& Options::current_postfx_preset < static_cast<int>(Options::postfx_presets.size())) {
|
|
||||||
return Options::postfx_presets[Options::current_postfx_preset].name.c_str();
|
return Options::postfx_presets[Options::current_postfx_preset].name.c_str();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Options::current_crtpi_preset >= 0
|
if (Options::current_crtpi_preset >= 0 && Options::current_crtpi_preset < static_cast<int>(Options::crtpi_presets.size())) {
|
||||||
&& Options::current_crtpi_preset < static_cast<int>(Options::crtpi_presets.size())) {
|
|
||||||
return Options::crtpi_presets[Options::current_crtpi_preset].name.c_str();
|
return Options::crtpi_presets[Options::current_crtpi_preset].name.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace Rendering {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Asset;
|
|
||||||
class Text;
|
class Text;
|
||||||
|
|
||||||
class Screen {
|
class Screen {
|
||||||
@@ -30,8 +29,12 @@ class Screen {
|
|||||||
static constexpr int WASM_RENDER_SCALE = 3;
|
static constexpr int WASM_RENDER_SCALE = 3;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor y destructor
|
// Singleton API
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset);
|
static void init(SDL_Window *window, SDL_Renderer *renderer); // Crea la instancia
|
||||||
|
static void destroy(); // Libera la instancia
|
||||||
|
static auto get() -> Screen *; // Obtiene el puntero a la instancia
|
||||||
|
|
||||||
|
// Destructor (público por requisitos de `delete` desde destroy())
|
||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
// Render loop
|
// Render loop
|
||||||
@@ -82,6 +85,12 @@ class Screen {
|
|||||||
void applyCurrentCrtPiPreset(); // Escriu el preset CrtPi actiu al backend
|
void applyCurrentCrtPiPreset(); // Escriu el preset CrtPi actiu al backend
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Constructor privado (usar Screen::init)
|
||||||
|
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
static Screen *instance;
|
||||||
|
|
||||||
// Helpers internos de setVideoMode
|
// Helpers internos de setVideoMode
|
||||||
void applyFullscreen(bool fullscreen); // SDL_SetWindowFullscreen + visibilidad del cursor
|
void applyFullscreen(bool fullscreen); // SDL_SetWindowFullscreen + visibilidad del cursor
|
||||||
void applyWindowedLayout(); // Calcula windowWidth/Height/dest + SDL_SetWindowSize + SDL_SetWindowPosition
|
void applyWindowedLayout(); // Calcula windowWidth/Height/dest + SDL_SetWindowSize + SDL_SetWindowPosition
|
||||||
@@ -104,7 +113,6 @@ class Screen {
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
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
|
|
||||||
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
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|||||||
@@ -7,6 +7,23 @@
|
|||||||
|
|
||||||
#include "core/resources/resource_helper.h"
|
#include "core/resources/resource_helper.h"
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
Asset *Asset::instance = nullptr;
|
||||||
|
|
||||||
|
// Singleton API
|
||||||
|
void Asset::init(const std::string &executablePath) {
|
||||||
|
Asset::instance = new Asset(executablePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Asset::destroy() {
|
||||||
|
delete Asset::instance;
|
||||||
|
Asset::instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Asset::get() -> Asset * {
|
||||||
|
return Asset::instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Asset::Asset(std::string executablePath) {
|
Asset::Asset(std::string executablePath) {
|
||||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
||||||
|
|||||||
@@ -39,10 +39,18 @@ class Asset {
|
|||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
std::string getTypeName(int type);
|
std::string getTypeName(int type);
|
||||||
|
|
||||||
public:
|
// Constructor privado (usar Asset::init)
|
||||||
// Constructor
|
|
||||||
Asset(std::string path);
|
Asset(std::string path);
|
||||||
|
|
||||||
|
// Instancia única
|
||||||
|
static Asset *instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Singleton API
|
||||||
|
static void init(const std::string &executablePath); // Crea la instancia
|
||||||
|
static void destroy(); // Libera la instancia
|
||||||
|
static auto get() -> Asset *; // Obtiene el puntero a la instancia
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
#include "core/resources/resource_helper.h"
|
#include "core/resources/resource_helper.h"
|
||||||
#include "game/ui/menu.h"
|
#include "game/ui/menu.h"
|
||||||
|
|
||||||
|
// Nota: Asset::get() e Input::get() se consultan en preloadAll y al construir
|
||||||
|
// los menús; no se guardan punteros en el objeto Resource.
|
||||||
|
|
||||||
Resource *Resource::instance_ = nullptr;
|
Resource *Resource::instance_ = nullptr;
|
||||||
|
|
||||||
static std::string basename(const std::string &path) {
|
static std::string basename(const std::string &path) {
|
||||||
@@ -25,9 +28,9 @@ static std::string stem(const std::string &path) {
|
|||||||
return b.substr(0, dot);
|
return b.substr(0, dot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::init(SDL_Renderer *renderer, Asset *asset, Input *input) {
|
void Resource::init(SDL_Renderer *renderer) {
|
||||||
if (instance_ == nullptr) {
|
if (instance_ == nullptr) {
|
||||||
instance_ = new Resource(renderer, asset, input);
|
instance_ = new Resource(renderer);
|
||||||
instance_->preloadAll();
|
instance_->preloadAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,10 +44,8 @@ Resource *Resource::get() {
|
|||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource::Resource(SDL_Renderer *renderer, Asset *asset, Input *input)
|
Resource::Resource(SDL_Renderer *renderer)
|
||||||
: renderer_(renderer),
|
: renderer_(renderer) {}
|
||||||
asset_(asset),
|
|
||||||
input_(input) {}
|
|
||||||
|
|
||||||
Resource::~Resource() {
|
Resource::~Resource() {
|
||||||
for (auto &[name, m] : menus_) delete m;
|
for (auto &[name, m] : menus_) delete m;
|
||||||
@@ -64,7 +65,7 @@ Resource::~Resource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Resource::preloadAll() {
|
void Resource::preloadAll() {
|
||||||
const auto &items = asset_->getAll();
|
const auto &items = Asset::get()->getAll();
|
||||||
|
|
||||||
// Pass 1: texturas, sonidos, músicas, animaciones (raw lines), demo, lenguajes
|
// Pass 1: texturas, sonidos, músicas, animaciones (raw lines), demo, lenguajes
|
||||||
for (const auto &it : items) {
|
for (const auto &it : items) {
|
||||||
@@ -155,7 +156,7 @@ void Resource::preloadAll() {
|
|||||||
if (bname.size() < 4 || bname.substr(bname.size() - 4) != ".men") continue;
|
if (bname.size() < 4 || bname.substr(bname.size() - 4) != ".men") continue;
|
||||||
auto bytes = ResourceHelper::loadFile(it.file);
|
auto bytes = ResourceHelper::loadFile(it.file);
|
||||||
if (bytes.empty()) continue;
|
if (bytes.empty()) continue;
|
||||||
Menu *m = new Menu(renderer_, asset_, input_, "");
|
Menu *m = new Menu(renderer_, "");
|
||||||
m->loadFromBytes(bytes, bname);
|
m->loadFromBytes(bytes, bname);
|
||||||
const std::string s = stem(it.file);
|
const std::string s = stem(it.file);
|
||||||
menus_[s] = m;
|
menus_[s] = m;
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Menu;
|
class Menu;
|
||||||
class Text;
|
class Text;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -19,7 +17,7 @@ struct JA_Sound_t;
|
|||||||
// Singleton inicializado desde Director; las escenas consultan handles via get*().
|
// Singleton inicializado desde Director; las escenas consultan handles via get*().
|
||||||
class Resource {
|
class Resource {
|
||||||
public:
|
public:
|
||||||
static void init(SDL_Renderer *renderer, Asset *asset, Input *input);
|
static void init(SDL_Renderer *renderer);
|
||||||
static void destroy();
|
static void destroy();
|
||||||
static Resource *get();
|
static Resource *get();
|
||||||
|
|
||||||
@@ -32,14 +30,12 @@ class Resource {
|
|||||||
const std::vector<uint8_t> &getDemoBytes() const { return demoBytes_; }
|
const std::vector<uint8_t> &getDemoBytes() const { return demoBytes_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Resource(SDL_Renderer *renderer, Asset *asset, Input *input);
|
Resource(SDL_Renderer *renderer);
|
||||||
~Resource();
|
~Resource();
|
||||||
|
|
||||||
void preloadAll();
|
void preloadAll();
|
||||||
|
|
||||||
SDL_Renderer *renderer_;
|
SDL_Renderer *renderer_;
|
||||||
Asset *asset_;
|
|
||||||
Input *input_;
|
|
||||||
|
|
||||||
std::unordered_map<std::string, Texture *> textures_;
|
std::unordered_map<std::string, Texture *> textures_;
|
||||||
std::unordered_map<std::string, JA_Sound_t *> sounds_;
|
std::unordered_map<std::string, JA_Sound_t *> sounds_;
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ Director::Director(int argc, const char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea el objeto que controla los ficheros de recursos
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
asset = new Asset(executablePath);
|
Asset::init(executablePath);
|
||||||
asset->setVerbose(Options::settings.console);
|
Asset::get()->setVerbose(Options::settings.console);
|
||||||
|
|
||||||
// Si falta algún fichero no inicia el programa
|
// Si falta algún fichero no inicia el programa
|
||||||
if (!setFileList()) {
|
if (!setFileList()) {
|
||||||
@@ -106,18 +106,18 @@ Director::Director(int argc, const char *argv[]) {
|
|||||||
Texture::setGlobalScaleMode(Options::video.scale_mode);
|
Texture::setGlobalScaleMode(Options::video.scale_mode);
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
lang = new Lang(asset);
|
Lang::init();
|
||||||
lang->setLang(Options::settings.language);
|
Lang::get()->setLang(Options::settings.language);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
input = new Input("/gamecontrollerdb.txt");
|
Input::init("/gamecontrollerdb.txt");
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
const std::string binDir = std::filesystem::path(executablePath).parent_path().string();
|
const std::string binDir = std::filesystem::path(executablePath).parent_path().string();
|
||||||
#ifdef MACOS_BUNDLE
|
#ifdef MACOS_BUNDLE
|
||||||
input = new Input(binDir + "/../Resources/gamecontrollerdb.txt");
|
Input::init(binDir + "/../Resources/gamecontrollerdb.txt");
|
||||||
#else
|
#else
|
||||||
input = new Input(binDir + "/gamecontrollerdb.txt");
|
Input::init(binDir + "/gamecontrollerdb.txt");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -130,22 +130,22 @@ Director::Director(int argc, const char *argv[]) {
|
|||||||
// intenta reclamar la ventana para el dispositivo SDL3 GPU.
|
// intenta reclamar la ventana para el dispositivo SDL3 GPU.
|
||||||
//
|
//
|
||||||
// Por eso el constructor de Screen NO carga notificationText desde
|
// Por eso el constructor de Screen NO carga notificationText desde
|
||||||
// Resource; se enlaza después vía `screen->initNotifications()`.
|
// Resource; se enlaza después vía `Screen::get()->initNotifications()`.
|
||||||
screen = new Screen(window, renderer, asset);
|
Screen::init(window, renderer);
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (Options::video.gpu.acceleration) {
|
if (Options::video.gpu.acceleration) {
|
||||||
screen->initShaders();
|
Screen::get()->initShaders();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ahora sí, precarga todos los recursos en memoria (texturas, sonidos,
|
// Ahora sí, precarga todos los recursos en memoria (texturas, sonidos,
|
||||||
// música, ...). Vivirán durante toda la vida de la app.
|
// música, ...). Vivirán durante toda la vida de la app.
|
||||||
Resource::init(renderer, asset, input);
|
Resource::init(renderer);
|
||||||
|
|
||||||
// Completa el enlazado de Screen con recursos que necesitan Resource
|
// Completa el enlazado de Screen con recursos que necesitan Resource
|
||||||
// inicializado (actualmente sólo el Text de las notificaciones).
|
// inicializado (actualmente sólo el Text de las notificaciones).
|
||||||
screen->initNotifications();
|
Screen::get()->initNotifications();
|
||||||
|
|
||||||
activeSection = ActiveSection::None;
|
activeSection = ActiveSection::None;
|
||||||
}
|
}
|
||||||
@@ -163,14 +163,14 @@ Director::~Director() {
|
|||||||
|
|
||||||
// Screen puede tener referencias a Text propiedad de Resource: destruir
|
// Screen puede tener referencias a Text propiedad de Resource: destruir
|
||||||
// Screen antes que Resource.
|
// Screen antes que Resource.
|
||||||
delete screen;
|
Screen::destroy();
|
||||||
|
|
||||||
// Libera todos los recursos precargados antes de cerrar SDL.
|
// Libera todos los recursos precargados antes de cerrar SDL.
|
||||||
Resource::destroy();
|
Resource::destroy();
|
||||||
|
|
||||||
delete asset;
|
Asset::destroy();
|
||||||
delete input;
|
Input::destroy();
|
||||||
delete lang;
|
Lang::destroy();
|
||||||
delete section;
|
delete section;
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
@@ -186,51 +186,51 @@ Director::~Director() {
|
|||||||
// Inicializa el objeto input
|
// Inicializa el objeto input
|
||||||
void Director::initInput() {
|
void Director::initInput() {
|
||||||
// Establece si ha de mostrar mensajes
|
// Establece si ha de mostrar mensajes
|
||||||
input->setVerbose(Options::settings.console);
|
Input::get()->setVerbose(Options::settings.console);
|
||||||
|
|
||||||
// Busca si hay un mando conectado
|
// Busca si hay un mando conectado
|
||||||
input->discoverGameController();
|
Input::get()->discoverGameController();
|
||||||
|
|
||||||
// Teclado - Movimiento del jugador
|
// Teclado - Movimiento del jugador
|
||||||
input->bindKey(input_up, SDL_SCANCODE_UP);
|
Input::get()->bindKey(input_up, SDL_SCANCODE_UP);
|
||||||
input->bindKey(input_down, SDL_SCANCODE_DOWN);
|
Input::get()->bindKey(input_down, SDL_SCANCODE_DOWN);
|
||||||
input->bindKey(input_left, SDL_SCANCODE_LEFT);
|
Input::get()->bindKey(input_left, SDL_SCANCODE_LEFT);
|
||||||
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
|
Input::get()->bindKey(input_right, SDL_SCANCODE_RIGHT);
|
||||||
input->bindKey(input_fire_left, SDL_SCANCODE_Q);
|
Input::get()->bindKey(input_fire_left, SDL_SCANCODE_Q);
|
||||||
input->bindKey(input_fire_center, SDL_SCANCODE_W);
|
Input::get()->bindKey(input_fire_center, SDL_SCANCODE_W);
|
||||||
input->bindKey(input_fire_right, SDL_SCANCODE_E);
|
Input::get()->bindKey(input_fire_right, SDL_SCANCODE_E);
|
||||||
|
|
||||||
// Teclado - Otros
|
// Teclado - Otros
|
||||||
input->bindKey(input_accept, SDL_SCANCODE_RETURN);
|
Input::get()->bindKey(input_accept, SDL_SCANCODE_RETURN);
|
||||||
input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
|
Input::get()->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
|
||||||
input->bindKey(input_pause, SDL_SCANCODE_ESCAPE);
|
Input::get()->bindKey(input_pause, SDL_SCANCODE_ESCAPE);
|
||||||
input->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
|
Input::get()->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
|
||||||
input->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
|
Input::get()->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
|
||||||
input->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
|
Input::get()->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
|
||||||
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
|
Input::get()->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
|
||||||
input->bindKey(input_prev_preset, SDL_SCANCODE_F8);
|
Input::get()->bindKey(input_prev_preset, SDL_SCANCODE_F8);
|
||||||
input->bindKey(input_next_preset, SDL_SCANCODE_F9);
|
Input::get()->bindKey(input_next_preset, SDL_SCANCODE_F9);
|
||||||
input->bindKey(input_toggle_shader, SDL_SCANCODE_F10);
|
Input::get()->bindKey(input_toggle_shader, SDL_SCANCODE_F10);
|
||||||
input->bindKey(input_toggle_shader_type, SDL_SCANCODE_F11);
|
Input::get()->bindKey(input_toggle_shader_type, SDL_SCANCODE_F11);
|
||||||
|
|
||||||
// Mando - Movimiento del jugador
|
// Mando - Movimiento del jugador
|
||||||
input->bindGameControllerButton(input_up, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
Input::get()->bindGameControllerButton(input_up, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||||
input->bindGameControllerButton(input_down, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
Input::get()->bindGameControllerButton(input_down, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||||
input->bindGameControllerButton(input_left, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
Input::get()->bindGameControllerButton(input_left, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||||
input->bindGameControllerButton(input_right, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
Input::get()->bindGameControllerButton(input_right, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||||
input->bindGameControllerButton(input_fire_left, SDL_GAMEPAD_BUTTON_WEST);
|
Input::get()->bindGameControllerButton(input_fire_left, SDL_GAMEPAD_BUTTON_WEST);
|
||||||
input->bindGameControllerButton(input_fire_center, SDL_GAMEPAD_BUTTON_NORTH);
|
Input::get()->bindGameControllerButton(input_fire_center, SDL_GAMEPAD_BUTTON_NORTH);
|
||||||
input->bindGameControllerButton(input_fire_right, SDL_GAMEPAD_BUTTON_EAST);
|
Input::get()->bindGameControllerButton(input_fire_right, SDL_GAMEPAD_BUTTON_EAST);
|
||||||
|
|
||||||
// Mando - Otros
|
// Mando - Otros
|
||||||
// SOUTH queda sin asignar para evitar salidas accidentales: pausa/cancel se hace con START/BACK.
|
// SOUTH queda sin asignar para evitar salidas accidentales: pausa/cancel se hace con START/BACK.
|
||||||
input->bindGameControllerButton(input_accept, SDL_GAMEPAD_BUTTON_EAST);
|
Input::get()->bindGameControllerButton(input_accept, SDL_GAMEPAD_BUTTON_EAST);
|
||||||
#ifdef GAME_CONSOLE
|
#ifdef GAME_CONSOLE
|
||||||
input->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_BACK);
|
Input::get()->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_BACK);
|
||||||
input->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_START);
|
Input::get()->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_START);
|
||||||
#else
|
#else
|
||||||
input->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_START);
|
Input::get()->bindGameControllerButton(input_pause, SDL_GAMEPAD_BUTTON_START);
|
||||||
input->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_BACK);
|
Input::get()->bindGameControllerButton(input_exit, SDL_GAMEPAD_BUTTON_BACK);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,123 +313,123 @@ bool Director::setFileList() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ficheros de configuración
|
// Ficheros de configuración
|
||||||
asset->add(systemFolder + "/score.bin", t_data, false, true);
|
Asset::get()->add(systemFolder + "/score.bin", t_data, false, true);
|
||||||
asset->add(prefix + "/data/demo/demo.bin", t_data);
|
Asset::get()->add(prefix + "/data/demo/demo.bin", t_data);
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
asset->add(prefix + "/data/music/intro.ogg", t_music);
|
Asset::get()->add(prefix + "/data/music/intro.ogg", t_music);
|
||||||
asset->add(prefix + "/data/music/playing.ogg", t_music);
|
Asset::get()->add(prefix + "/data/music/playing.ogg", t_music);
|
||||||
asset->add(prefix + "/data/music/title.ogg", t_music);
|
Asset::get()->add(prefix + "/data/music/title.ogg", t_music);
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
asset->add(prefix + "/data/sound/balloon.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/balloon.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/bubble1.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/bubble1.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/bubble2.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/bubble2.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/bubble3.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/bubble3.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/bubble4.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/bubble4.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/bullet.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/bullet.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/coffeeout.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/coffeeout.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/hiscore.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/hiscore.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/itemdrop.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/itemdrop.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/itempickup.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/itempickup.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/menu_move.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/menu_move.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/menu_select.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/menu_select.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/player_collision.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/player_collision.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/stage_change.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/stage_change.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/title.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/title.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/clock.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/clock.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/powerball.wav", t_sound);
|
Asset::get()->add(prefix + "/data/sound/powerball.wav", t_sound);
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
asset->add(prefix + "/data/gfx/balloon1.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/balloon1.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/balloon1.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/balloon1.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/balloon2.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/balloon2.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/balloon2.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/balloon2.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/balloon3.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/balloon3.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/balloon3.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/balloon3.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/balloon4.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/balloon4.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/balloon4.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/balloon4.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/bullet.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/bullet.png", t_bitmap);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/game_buildings.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_buildings.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/game_clouds.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_clouds.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/game_grass.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_grass.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/game_power_meter.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_power_meter.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/game_sky_colors.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_sky_colors.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/game_text.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/game_text.png", t_bitmap);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/intro.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/intro.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/logo.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/logo.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/menu_game_over.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/menu_game_over.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/menu_game_over_end.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/menu_game_over_end.png", t_bitmap);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/item_points1_disk.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_points1_disk.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_points1_disk.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_points1_disk.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/item_points2_gavina.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_points2_gavina.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_points2_gavina.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_points2_gavina.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/item_points3_pacmar.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_points3_pacmar.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_points3_pacmar.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_points3_pacmar.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/item_clock.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_clock.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_clock.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_clock.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/item_coffee.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_coffee.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_coffee.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_coffee.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/item_coffee_machine.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/item_coffee_machine.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/item_coffee_machine.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/item_coffee_machine.ani", t_data);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/title_bg_tile.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/title_bg_tile.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_coffee.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/title_coffee.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_crisis.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/title_crisis.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_dust.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/title_dust.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_dust.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/title_dust.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/title_gradient.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/title_gradient.png", t_bitmap);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/player_head.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/player_head.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/player_body.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/player_body.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/player_legs.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/player_legs.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/player_death.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/player_death.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/player_fire.ani", t_data);
|
Asset::get()->add(prefix + "/data/gfx/player_fire.ani", t_data);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/player_bal1_head.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_bal1_head.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_bal1_body.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_bal1_body.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_bal1_legs.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_bal1_legs.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_bal1_death.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_bal1_death.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_bal1_fire.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_bal1_fire.png", t_bitmap);
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/player_arounder_head.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_arounder_head.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_arounder_body.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_arounder_body.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_arounder_legs.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_arounder_legs.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_arounder_death.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_arounder_death.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/player_arounder_fire.png", t_bitmap);
|
Asset::get()->add(prefix + "/data/gfx/player_arounder_fire.png", t_bitmap);
|
||||||
|
|
||||||
// Fuentes
|
// Fuentes
|
||||||
asset->add(prefix + "/data/font/8bithud.png", t_font);
|
Asset::get()->add(prefix + "/data/font/8bithud.png", t_font);
|
||||||
asset->add(prefix + "/data/font/8bithud.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/8bithud.txt", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia.png", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia.png", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia_big2.png", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia_big2.png", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia.txt", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia2.png", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia2.png", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia2.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia2.txt", t_font);
|
||||||
asset->add(prefix + "/data/font/nokia_big2.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/nokia_big2.txt", t_font);
|
||||||
asset->add(prefix + "/data/font/smb2_big.png", t_font);
|
Asset::get()->add(prefix + "/data/font/smb2_big.png", t_font);
|
||||||
asset->add(prefix + "/data/font/smb2_big.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/smb2_big.txt", t_font);
|
||||||
asset->add(prefix + "/data/font/smb2.png", t_font);
|
Asset::get()->add(prefix + "/data/font/smb2.png", t_font);
|
||||||
asset->add(prefix + "/data/font/smb2.txt", t_font);
|
Asset::get()->add(prefix + "/data/font/smb2.txt", t_font);
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
asset->add(prefix + "/data/lang/es_ES.txt", t_lang);
|
Asset::get()->add(prefix + "/data/lang/es_ES.txt", t_lang);
|
||||||
asset->add(prefix + "/data/lang/en_UK.txt", t_lang);
|
Asset::get()->add(prefix + "/data/lang/en_UK.txt", t_lang);
|
||||||
asset->add(prefix + "/data/lang/ba_BA.txt", t_lang);
|
Asset::get()->add(prefix + "/data/lang/ba_BA.txt", t_lang);
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
asset->add(prefix + "/data/menu/title.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/title.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/title_gc.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/title_gc.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/options.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/options.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/options_gc.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/options_gc.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/pause.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/pause.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/gameover.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/gameover.men", t_data);
|
||||||
asset->add(prefix + "/data/menu/player_select.men", t_data);
|
Asset::get()->add(prefix + "/data/menu/player_select.men", t_data);
|
||||||
|
|
||||||
return asset->check();
|
return Asset::get()->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
@@ -540,17 +540,17 @@ void Director::handleSectionTransition() {
|
|||||||
activeSection = targetSection;
|
activeSection = targetSection;
|
||||||
switch (activeSection) {
|
switch (activeSection) {
|
||||||
case ActiveSection::Logo:
|
case ActiveSection::Logo:
|
||||||
logo = std::make_unique<Logo>(renderer, screen, asset, input, section);
|
logo = std::make_unique<Logo>(renderer, section);
|
||||||
break;
|
break;
|
||||||
case ActiveSection::Intro:
|
case ActiveSection::Intro:
|
||||||
intro = std::make_unique<Intro>(renderer, screen, asset, input, lang, section);
|
intro = std::make_unique<Intro>(renderer, section);
|
||||||
break;
|
break;
|
||||||
case ActiveSection::Title:
|
case ActiveSection::Title:
|
||||||
title = std::make_unique<Title>(renderer, screen, input, asset, lang, section);
|
title = std::make_unique<Title>(renderer, section);
|
||||||
break;
|
break;
|
||||||
case ActiveSection::Game: {
|
case ActiveSection::Game: {
|
||||||
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
||||||
game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, section);
|
game = std::make_unique<Game>(numPlayers, 0, renderer, false, section);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ActiveSection::None:
|
case ActiveSection::None:
|
||||||
@@ -611,16 +611,16 @@ SDL_AppResult Director::handleEvent(SDL_Event *event) {
|
|||||||
// Hot-plug de mandos
|
// Hot-plug de mandos
|
||||||
if (event->type == SDL_EVENT_GAMEPAD_ADDED) {
|
if (event->type == SDL_EVENT_GAMEPAD_ADDED) {
|
||||||
std::string name;
|
std::string name;
|
||||||
if (input->handleGamepadAdded(event->gdevice.which, name)) {
|
if (Input::get()->handleGamepadAdded(event->gdevice.which, name)) {
|
||||||
screen->notify(name + " " + lang->getText(94),
|
Screen::get()->notify(name + " " + Lang::get()->getText(94),
|
||||||
color_t{0x40, 0xFF, 0x40},
|
color_t{0x40, 0xFF, 0x40},
|
||||||
color_t{0, 0, 0},
|
color_t{0, 0, 0},
|
||||||
2500);
|
2500);
|
||||||
}
|
}
|
||||||
} else if (event->type == SDL_EVENT_GAMEPAD_REMOVED) {
|
} else if (event->type == SDL_EVENT_GAMEPAD_REMOVED) {
|
||||||
std::string name;
|
std::string name;
|
||||||
if (input->handleGamepadRemoved(event->gdevice.which, name)) {
|
if (Input::get()->handleGamepadRemoved(event->gdevice.which, name)) {
|
||||||
screen->notify(name + " " + lang->getText(95),
|
Screen::get()->notify(name + " " + Lang::get()->getText(95),
|
||||||
color_t{0xFF, 0x50, 0x50},
|
color_t{0xFF, 0x50, 0x50},
|
||||||
color_t{0, 0, 0},
|
color_t{0, 0, 0},
|
||||||
2500);
|
2500);
|
||||||
@@ -650,4 +650,3 @@ SDL_AppResult Director::handleEvent(SDL_Event *event) {
|
|||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
class Asset;
|
|
||||||
class Game;
|
class Game;
|
||||||
class Input;
|
|
||||||
class Intro;
|
class Intro;
|
||||||
class Lang;
|
|
||||||
class Logo;
|
class Logo;
|
||||||
class Screen;
|
|
||||||
class Title;
|
class Title;
|
||||||
struct section_t;
|
struct section_t;
|
||||||
|
|
||||||
@@ -26,10 +22,6 @@ class Director {
|
|||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window; // La ventana donde dibujamos
|
SDL_Window *window; // La ventana donde dibujamos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
section_t *section; // Sección y subsección actual del programa;
|
section_t *section; // Sección y subsección actual del programa;
|
||||||
|
|
||||||
// Secciones del juego
|
// Secciones del juego
|
||||||
|
|||||||
@@ -30,13 +30,9 @@
|
|||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, section_t *section) {
|
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, bool demo, section_t *section) {
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->lang = lang;
|
|
||||||
this->input = input;
|
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
@@ -404,15 +400,15 @@ void Game::loadMedia() {
|
|||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
gameOverMenu = R->getMenu("gameover");
|
gameOverMenu = R->getMenu("gameover");
|
||||||
gameOverMenu->setItemCaption(0, lang->getText(48));
|
gameOverMenu->setItemCaption(0, Lang::get()->getText(48));
|
||||||
gameOverMenu->setItemCaption(1, lang->getText(49));
|
gameOverMenu->setItemCaption(1, Lang::get()->getText(49));
|
||||||
const int w = text->getCharacterSize() * lang->getText(45).length();
|
const int w = text->getCharacterSize() * Lang::get()->getText(45).length();
|
||||||
gameOverMenu->setRectSize(w, 0);
|
gameOverMenu->setRectSize(w, 0);
|
||||||
gameOverMenu->centerMenuOnX(199);
|
gameOverMenu->centerMenuOnX(199);
|
||||||
pauseMenu = R->getMenu("pause");
|
pauseMenu = R->getMenu("pause");
|
||||||
pauseMenu->setItemCaption(0, lang->getText(41));
|
pauseMenu->setItemCaption(0, Lang::get()->getText(41));
|
||||||
pauseMenu->setItemCaption(1, lang->getText(46));
|
pauseMenu->setItemCaption(1, Lang::get()->getText(46));
|
||||||
pauseMenu->setItemCaption(2, lang->getText(47));
|
pauseMenu->setItemCaption(2, Lang::get()->getText(47));
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
balloonSound = R->getSound("balloon.wav");
|
balloonSound = R->getSound("balloon.wav");
|
||||||
@@ -444,7 +440,7 @@ void Game::loadMedia() {
|
|||||||
bool Game::loadScoreFile() {
|
bool Game::loadScoreFile() {
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
const std::string p = asset->get("score.bin");
|
const std::string p = Asset::get()->get("score.bin");
|
||||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "r+b");
|
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "r+b");
|
||||||
|
|
||||||
@@ -536,7 +532,7 @@ bool Game::loadDemoFile() {
|
|||||||
// Guarda el fichero de puntos
|
// Guarda el fichero de puntos
|
||||||
bool Game::saveScoreFile() {
|
bool Game::saveScoreFile() {
|
||||||
bool success = true;
|
bool success = true;
|
||||||
const std::string p = asset->get("score.bin");
|
const std::string p = Asset::get()->get("score.bin");
|
||||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||||
if (file != nullptr) {
|
if (file != nullptr) {
|
||||||
@@ -562,7 +558,7 @@ bool Game::saveScoreFile() {
|
|||||||
// Guarda el fichero de datos para la demo
|
// Guarda el fichero de datos para la demo
|
||||||
bool Game::saveDemoFile() {
|
bool Game::saveDemoFile() {
|
||||||
bool success = true;
|
bool success = true;
|
||||||
const std::string p = asset->get("demo.bin");
|
const std::string p = Asset::get()->get("demo.bin");
|
||||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
if (demo.recording) {
|
if (demo.recording) {
|
||||||
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
SDL_IOStream *file = SDL_IOFromFile(p.c_str(), "w+b");
|
||||||
@@ -1375,33 +1371,33 @@ void Game::renderScoreBoard() {
|
|||||||
const int offsetRight = PLAY_AREA_RIGHT - 45;
|
const int offsetRight = PLAY_AREA_RIGHT - 45;
|
||||||
|
|
||||||
// PLAYER1 - SCORE
|
// PLAYER1 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetLeft, offset1, lang->getText(53));
|
textScoreBoard->writeCentered(offsetLeft, offset1, Lang::get()->getText(53));
|
||||||
textScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players[0]->getScore()));
|
textScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players[0]->getScore()));
|
||||||
|
|
||||||
// PLAYER1 - MULT
|
// PLAYER1 - MULT
|
||||||
textScoreBoard->writeCentered(offsetLeft, offset3, lang->getText(55));
|
textScoreBoard->writeCentered(offsetLeft, offset3, Lang::get()->getText(55));
|
||||||
textScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players[0]->getScoreMultiplier()).substr(0, 3));
|
textScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players[0]->getScoreMultiplier()).substr(0, 3));
|
||||||
|
|
||||||
if (numPlayers == 2) {
|
if (numPlayers == 2) {
|
||||||
// PLAYER2 - SCORE
|
// PLAYER2 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetRight, offset1, lang->getText(54));
|
textScoreBoard->writeCentered(offsetRight, offset1, Lang::get()->getText(54));
|
||||||
textScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players[1]->getScore()));
|
textScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players[1]->getScore()));
|
||||||
|
|
||||||
// PLAYER2 - MULT
|
// PLAYER2 - MULT
|
||||||
textScoreBoard->writeCentered(offsetRight, offset3, lang->getText(55));
|
textScoreBoard->writeCentered(offsetRight, offset3, Lang::get()->getText(55));
|
||||||
textScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players[1]->getScoreMultiplier()).substr(0, 3));
|
textScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players[1]->getScoreMultiplier()).substr(0, 3));
|
||||||
} else {
|
} else {
|
||||||
// PLAYER2 - SCORE
|
// PLAYER2 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetRight, offset1, lang->getText(54));
|
textScoreBoard->writeCentered(offsetRight, offset1, Lang::get()->getText(54));
|
||||||
textScoreBoard->writeCentered(offsetRight, offset2, "0000000");
|
textScoreBoard->writeCentered(offsetRight, offset2, "0000000");
|
||||||
|
|
||||||
// PLAYER2 - MULT
|
// PLAYER2 - MULT
|
||||||
textScoreBoard->writeCentered(offsetRight, offset3, lang->getText(55));
|
textScoreBoard->writeCentered(offsetRight, offset3, Lang::get()->getText(55));
|
||||||
textScoreBoard->writeCentered(offsetRight, offset4, "1.0");
|
textScoreBoard->writeCentered(offsetRight, offset4, "1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
// STAGE
|
// STAGE
|
||||||
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset1, lang->getText(57) + std::to_string(stage[currentStage].number));
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset1, Lang::get()->getText(57) + std::to_string(stage[currentStage].number));
|
||||||
|
|
||||||
// POWERMETER
|
// POWERMETER
|
||||||
powerMeterSprite->setPosY(offset2);
|
powerMeterSprite->setPosY(offset2);
|
||||||
@@ -1412,7 +1408,7 @@ void Game::renderScoreBoard() {
|
|||||||
powerMeterSprite->render();
|
powerMeterSprite->render();
|
||||||
|
|
||||||
// HI-SCORE
|
// HI-SCORE
|
||||||
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56));
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, Lang::get()->getText(56));
|
||||||
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, hiScoreName + updateScoreText(hiScore));
|
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, hiScoreName + updateScoreText(hiScore));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2458,10 +2454,10 @@ void Game::renderBackground() {
|
|||||||
// Dibuja el juego
|
// Dibuja el juego
|
||||||
void Game::render() {
|
void Game::render() {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
renderBackground();
|
renderBackground();
|
||||||
@@ -2484,7 +2480,7 @@ void Game::render() {
|
|||||||
renderFlashEffect();
|
renderFlashEffect();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el nivel de amenaza
|
// Gestiona el nivel de amenaza
|
||||||
@@ -2519,7 +2515,7 @@ void Game::checkGameInput() {
|
|||||||
demo.keys.fireRight = 0;
|
demo.keys.fireRight = 0;
|
||||||
|
|
||||||
// Atalls globals (zoom finestra, fullscreen, shaders, presets, ...)
|
// Atalls globals (zoom finestra, fullscreen, shaders, presets, ...)
|
||||||
GlobalInputs::handle(screen, input);
|
GlobalInputs::handle();
|
||||||
|
|
||||||
// Modo Demo activo
|
// Modo Demo activo
|
||||||
if (demo.enabled) {
|
if (demo.enabled) {
|
||||||
@@ -2561,7 +2557,7 @@ void Game::checkGameInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si se pulsa cualquier tecla, se sale del modo demo
|
// Si se pulsa cualquier tecla, se sale del modo demo
|
||||||
if (input->checkAnyInput()) {
|
if (Input::get()->checkAnyInput()) {
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2579,12 +2575,12 @@ void Game::checkGameInput() {
|
|||||||
for (auto player : players) {
|
for (auto player : players) {
|
||||||
if (player->isAlive()) {
|
if (player->isAlive()) {
|
||||||
// Input a la izquierda
|
// Input a la izquierda
|
||||||
if (input->checkInput(input_left, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_left, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
player->setInput(input_left);
|
player->setInput(input_left);
|
||||||
demo.keys.left = 1;
|
demo.keys.left = 1;
|
||||||
} else {
|
} else {
|
||||||
// Input a la derecha
|
// Input a la derecha
|
||||||
if (input->checkInput(input_right, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_right, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
player->setInput(input_right);
|
player->setInput(input_right);
|
||||||
demo.keys.right = 1;
|
demo.keys.right = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -2594,7 +2590,7 @@ void Game::checkGameInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comprueba el input de disparar al centro
|
// Comprueba el input de disparar al centro
|
||||||
if (input->checkInput(input_fire_center, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_fire_center, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
if (player->canFire()) {
|
if (player->canFire()) {
|
||||||
player->setInput(input_fire_center);
|
player->setInput(input_fire_center);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), i);
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), i);
|
||||||
@@ -2608,7 +2604,7 @@ void Game::checkGameInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la izquierda
|
// Comprueba el input de disparar a la izquierda
|
||||||
if (input->checkInput(input_fire_left, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_fire_left, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
if (player->canFire()) {
|
if (player->canFire()) {
|
||||||
player->setInput(input_fire_left);
|
player->setInput(input_fire_left);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), i);
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), i);
|
||||||
@@ -2622,7 +2618,7 @@ void Game::checkGameInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la derecha
|
// Comprueba el input de disparar a la derecha
|
||||||
if (input->checkInput(input_fire_right, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_fire_right, REPEAT_TRUE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
if (player->canFire()) {
|
if (player->canFire()) {
|
||||||
player->setInput(input_fire_right);
|
player->setInput(input_fire_right);
|
||||||
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), i);
|
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), i);
|
||||||
@@ -2636,7 +2632,7 @@ void Game::checkGameInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de pausa
|
// Comprueba el input de pausa
|
||||||
if (input->checkInput(input_pause, REPEAT_FALSE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
if (Input::get()->checkInput(input_pause, REPEAT_FALSE, Options::inputs[i].deviceType, Options::inputs[i].id)) {
|
||||||
section->subsection = SUBSECTION_GAME_PAUSE;
|
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2659,13 +2655,13 @@ void Game::checkGameInput() {
|
|||||||
void Game::renderMessages() {
|
void Game::renderMessages() {
|
||||||
// GetReady
|
// GetReady
|
||||||
if ((counter < STAGE_COUNTER) && (!demo.enabled)) {
|
if ((counter < STAGE_COUNTER) && (!demo.enabled)) {
|
||||||
textNokiaBig2->write((int)getReadyBitmapPath[counter], PLAY_AREA_CENTER_Y - 8, lang->getText(75), -2);
|
textNokiaBig2->write((int)getReadyBitmapPath[counter], PLAY_AREA_CENTER_Y - 8, Lang::get()->getText(75), -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time Stopped
|
// Time Stopped
|
||||||
if (timeStopped) {
|
if (timeStopped) {
|
||||||
if ((timeStoppedCounter > 100) || (timeStoppedCounter % 10 > 4)) {
|
if ((timeStoppedCounter > 100) || (timeStoppedCounter % 10 > 4)) {
|
||||||
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, lang->getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
|
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, Lang::get()->getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeStoppedCounter > 100) {
|
if (timeStoppedCounter > 100) {
|
||||||
@@ -2682,7 +2678,7 @@ void Game::renderMessages() {
|
|||||||
// D E M O
|
// D E M O
|
||||||
if (demo.enabled) {
|
if (demo.enabled) {
|
||||||
if (demo.counter % 30 > 14) {
|
if (demo.counter % 30 > 14) {
|
||||||
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, lang->getText(37), 0, noColor, 2, shdwTxtColor);
|
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, Lang::get()->getText(37), 0, noColor, 2, shdwTxtColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2692,17 +2688,17 @@ void Game::renderMessages() {
|
|||||||
std::string text;
|
std::string text;
|
||||||
|
|
||||||
if (stageNum == 10) { // Ultima fase
|
if (stageNum == 10) { // Ultima fase
|
||||||
text = lang->getText(79);
|
text = Lang::get()->getText(79);
|
||||||
} else { // X fases restantes
|
} else { // X fases restantes
|
||||||
text = std::to_string(11 - stage[currentStage].number) + lang->getText(38);
|
text = std::to_string(11 - stage[currentStage].number) + Lang::get()->getText(38);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gameCompleted) { // Escribe el numero de fases restantes
|
if (!gameCompleted) { // Escribe el numero de fases restantes
|
||||||
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
|
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
|
||||||
} else { // Escribe el texto de juego completado
|
} else { // Escribe el texto de juego completado
|
||||||
text = lang->getText(50);
|
text = Lang::get()->getText(50);
|
||||||
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
|
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
|
||||||
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang->getText(76), -1, noColor, 1, shdwTxtColor);
|
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, Lang::get()->getText(76), -1, noColor, 1, shdwTxtColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2861,6 +2857,9 @@ void Game::updatePausedGame() {
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Atalls globals (zoom finestra, fullscreen, shaders, presets, ...)
|
||||||
|
GlobalInputs::handle();
|
||||||
|
|
||||||
if (leavingPauseMenu) {
|
if (leavingPauseMenu) {
|
||||||
if (pauseCounter > 0) { // El contador está descendiendo
|
if (pauseCounter > 0) { // El contador está descendiendo
|
||||||
const bool a = pauseCounter == 90;
|
const bool a = pauseCounter == 90;
|
||||||
@@ -2913,10 +2912,10 @@ void Game::updatePausedGame() {
|
|||||||
// Dibuja el menu de pausa del juego
|
// Dibuja el menu de pausa del juego
|
||||||
void Game::renderPausedGame() {
|
void Game::renderPausedGame() {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Pinta el escenario
|
// Pinta el escenario
|
||||||
{
|
{
|
||||||
@@ -2948,7 +2947,7 @@ void Game::renderPausedGame() {
|
|||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el estado de pausa del juego
|
// Inicializa el estado de pausa del juego
|
||||||
@@ -2974,6 +2973,9 @@ void Game::updateGameOverScreen() {
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Atalls globals (zoom finestra, fullscreen, shaders, presets, ...)
|
||||||
|
GlobalInputs::handle();
|
||||||
|
|
||||||
// Actualiza la lógica del menu
|
// Actualiza la lógica del menu
|
||||||
gameOverMenu->update();
|
gameOverMenu->update();
|
||||||
|
|
||||||
@@ -3043,10 +3045,10 @@ void Game::checkGameOverEvents() {
|
|||||||
// Dibuja los elementos de la pantalla de game over
|
// Dibuja los elementos de la pantalla de game over
|
||||||
void Game::renderGameOverScreen() {
|
void Game::renderGameOverScreen() {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibujo
|
// Dibujo
|
||||||
if (!gameCompleted) { // Dibujo de haber perdido la partida
|
if (!gameCompleted) { // Dibujo de haber perdido la partida
|
||||||
@@ -3059,33 +3061,33 @@ void Game::renderGameOverScreen() {
|
|||||||
if (numPlayers == 1) {
|
if (numPlayers == 1) {
|
||||||
// Congratulations!!
|
// Congratulations!!
|
||||||
if (gameCompleted) {
|
if (gameCompleted) {
|
||||||
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 8), lang->getText(50));
|
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 8), Lang::get()->getText(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game Over
|
// Game Over
|
||||||
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), lang->getText(43));
|
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), Lang::get()->getText(43));
|
||||||
|
|
||||||
// Your Score
|
// Your Score
|
||||||
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players[0]->getScore()));
|
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), Lang::get()->getText(44) + std::to_string(players[0]->getScore()));
|
||||||
} else {
|
} else {
|
||||||
// Congratulations!!
|
// Congratulations!!
|
||||||
if (gameCompleted) {
|
if (gameCompleted) {
|
||||||
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 9), lang->getText(50));
|
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 9), Lang::get()->getText(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game Over
|
// Game Over
|
||||||
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), lang->getText(43));
|
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), Lang::get()->getText(43));
|
||||||
|
|
||||||
// Player1 Score
|
// Player1 Score
|
||||||
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players[0]->getScore()));
|
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), Lang::get()->getText(77) + std::to_string(players[0]->getScore()));
|
||||||
|
|
||||||
// Player2 Score
|
// Player2 Score
|
||||||
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players[1]->getScore()));
|
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), Lang::get()->getText(78) + std::to_string(players[1]->getScore()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue?
|
// Continue?
|
||||||
if (!gameCompleted) { // Solo dibuja el menu de continuar en el caso de no haber completado la partida
|
if (!gameCompleted) { // Solo dibuja el menu de continuar en el caso de no haber completado la partida
|
||||||
text->writeCentered(199, PLAY_AREA_CENTER_Y + BLOCK * 3, lang->getText(45));
|
text->writeCentered(199, PLAY_AREA_CENTER_Y + BLOCK * 3, Lang::get()->getText(45));
|
||||||
gameOverMenu->render();
|
gameOverMenu->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3093,7 +3095,7 @@ void Game::renderGameOverScreen() {
|
|||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el estado de game over
|
// Inicializa el estado de game over
|
||||||
@@ -3158,7 +3160,7 @@ void Game::initPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Letrero de GetReady
|
// Letrero de GetReady
|
||||||
const int size = textNokiaBig2->lenght(lang->getText(75), -2);
|
const int size = textNokiaBig2->lenght(Lang::get()->getText(75), -2);
|
||||||
|
|
||||||
const float start1 = PLAY_AREA_LEFT - size;
|
const float start1 = PLAY_AREA_LEFT - size;
|
||||||
const float finish1 = PLAY_AREA_CENTER_X - (size / 2);
|
const float finish1 = PLAY_AREA_CENTER_X - (size / 2);
|
||||||
|
|||||||
@@ -6,17 +6,13 @@
|
|||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "utils/utils.h" // for demoKeys_t, color_t
|
#include "utils/utils.h" // for demoKeys_t, color_t
|
||||||
class Asset;
|
|
||||||
class Balloon;
|
class Balloon;
|
||||||
class Bullet;
|
class Bullet;
|
||||||
class Fade;
|
class Fade;
|
||||||
class Input;
|
|
||||||
class Item;
|
class Item;
|
||||||
class Lang;
|
|
||||||
class Menu;
|
class Menu;
|
||||||
class MovingSprite;
|
class MovingSprite;
|
||||||
class Player;
|
class Player;
|
||||||
class Screen;
|
|
||||||
class SmartSprite;
|
class SmartSprite;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
class Text;
|
||||||
@@ -131,10 +127,6 @@ class Game {
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
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
|
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
|
||||||
Input *input; // Manejador de entrada
|
|
||||||
section_t *section; // Seccion actual dentro del juego
|
section_t *section; // Seccion actual dentro del juego
|
||||||
|
|
||||||
std::vector<Player *> players; // Vector con los jugadores
|
std::vector<Player *> players; // Vector con los jugadores
|
||||||
@@ -545,7 +537,7 @@ class Game {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, section_t *section);
|
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, bool demo, section_t *section);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -456,7 +456,9 @@ namespace Options {
|
|||||||
for (const auto &p : yaml["presets"]) {
|
for (const auto &p : yaml["presets"]) {
|
||||||
PostFXPreset preset;
|
PostFXPreset preset;
|
||||||
if (p.contains("name")) {
|
if (p.contains("name")) {
|
||||||
try { preset.name = p["name"].get_value<std::string>(); } catch (...) {}
|
try {
|
||||||
|
preset.name = p["name"].get_value<std::string>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
parseFloatField(p, "vignette", preset.vignette);
|
parseFloatField(p, "vignette", preset.vignette);
|
||||||
parseFloatField(p, "scanlines", preset.scanlines);
|
parseFloatField(p, "scanlines", preset.scanlines);
|
||||||
@@ -511,7 +513,9 @@ namespace Options {
|
|||||||
for (const auto &p : yaml["presets"]) {
|
for (const auto &p : yaml["presets"]) {
|
||||||
CrtPiPreset preset;
|
CrtPiPreset preset;
|
||||||
if (p.contains("name")) {
|
if (p.contains("name")) {
|
||||||
try { preset.name = p["name"].get_value<std::string>(); } catch (...) {}
|
try {
|
||||||
|
preset.name = p["name"].get_value<std::string>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
||||||
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
||||||
@@ -522,22 +526,34 @@ namespace Options {
|
|||||||
parseFloatField(p, "curvature_x", preset.curvature_x);
|
parseFloatField(p, "curvature_x", preset.curvature_x);
|
||||||
parseFloatField(p, "curvature_y", preset.curvature_y);
|
parseFloatField(p, "curvature_y", preset.curvature_y);
|
||||||
if (p.contains("mask_type")) {
|
if (p.contains("mask_type")) {
|
||||||
try { preset.mask_type = p["mask_type"].get_value<int>(); } catch (...) {}
|
try {
|
||||||
|
preset.mask_type = p["mask_type"].get_value<int>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (p.contains("enable_scanlines")) {
|
if (p.contains("enable_scanlines")) {
|
||||||
try { preset.enable_scanlines = p["enable_scanlines"].get_value<bool>(); } catch (...) {}
|
try {
|
||||||
|
preset.enable_scanlines = p["enable_scanlines"].get_value<bool>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (p.contains("enable_multisample")) {
|
if (p.contains("enable_multisample")) {
|
||||||
try { preset.enable_multisample = p["enable_multisample"].get_value<bool>(); } catch (...) {}
|
try {
|
||||||
|
preset.enable_multisample = p["enable_multisample"].get_value<bool>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (p.contains("enable_gamma")) {
|
if (p.contains("enable_gamma")) {
|
||||||
try { preset.enable_gamma = p["enable_gamma"].get_value<bool>(); } catch (...) {}
|
try {
|
||||||
|
preset.enable_gamma = p["enable_gamma"].get_value<bool>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (p.contains("enable_curvature")) {
|
if (p.contains("enable_curvature")) {
|
||||||
try { preset.enable_curvature = p["enable_curvature"].get_value<bool>(); } catch (...) {}
|
try {
|
||||||
|
preset.enable_curvature = p["enable_curvature"].get_value<bool>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (p.contains("enable_sharper")) {
|
if (p.contains("enable_sharper")) {
|
||||||
try { preset.enable_sharper = p["enable_sharper"].get_value<bool>(); } catch (...) {}
|
try {
|
||||||
|
preset.enable_sharper = p["enable_sharper"].get_value<bool>();
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
crtpi_presets.push_back(preset);
|
crtpi_presets.push_back(preset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,19 +14,14 @@
|
|||||||
#include "core/rendering/sprite.h" // for Sprite
|
#include "core/rendering/sprite.h" // for Sprite
|
||||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW
|
||||||
#include "core/rendering/texture.h" // for Texture
|
#include "core/rendering/texture.h" // for Texture
|
||||||
#include "core/resources/asset.h" // for Asset
|
|
||||||
#include "core/resources/resource.h"
|
#include "core/resources/resource.h"
|
||||||
#include "game/defaults.hpp" // for shdwTxtColor, GAMECANVAS_CENTER_X, GAME...
|
#include "game/defaults.hpp" // for shdwTxtColor, GAMECANVAS_CENTER_X, GAME...
|
||||||
#include "utils/utils.h" // for color_t, section_t
|
#include "utils/utils.h" // for color_t, section_t
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Copia los punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
this->lang = lang;
|
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Texturas (handles compartidos de Resource)
|
// Texturas (handles compartidos de Resource)
|
||||||
@@ -122,21 +117,21 @@ void Instructions::render() {
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Escribe el texto
|
// 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, 8, Lang::get()->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, 24, Lang::get()->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, 34, Lang::get()->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, 48, Lang::get()->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, 58, Lang::get()->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, 75, Lang::get()->getText(16), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
|
||||||
text->writeShadowed(84, 92, lang->getText(17), shdwTxtColor);
|
text->writeShadowed(84, 92, Lang::get()->getText(17), shdwTxtColor);
|
||||||
text->writeShadowed(84, 108, lang->getText(18), shdwTxtColor);
|
text->writeShadowed(84, 108, Lang::get()->getText(18), shdwTxtColor);
|
||||||
text->writeShadowed(84, 124, lang->getText(19), shdwTxtColor);
|
text->writeShadowed(84, 124, Lang::get()->getText(19), shdwTxtColor);
|
||||||
text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor);
|
text->writeShadowed(84, 140, Lang::get()->getText(20), shdwTxtColor);
|
||||||
text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor);
|
text->writeShadowed(84, 156, Lang::get()->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
if ((mode == m_manual) && (counter % 50 > 14)) {
|
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
|
// Disquito
|
||||||
@@ -178,10 +173,10 @@ void Instructions::render() {
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Establece la ventana del backbuffer
|
// Establece la ventana del backbuffer
|
||||||
if (mode == m_auto) {
|
if (mode == m_auto) {
|
||||||
@@ -195,7 +190,7 @@ void Instructions::render() {
|
|||||||
SDL_RenderTexture(renderer, backbuffer, nullptr, &fWindow);
|
SDL_RenderTexture(renderer, backbuffer, nullptr, &fWindow);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
@@ -216,15 +211,15 @@ void Instructions::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Instructions::checkInput() {
|
void Instructions::checkInput() {
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||||
quitRequested = true;
|
quitRequested = true;
|
||||||
finished = true;
|
finished = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
if (mode == m_auto) {
|
||||||
finished = true;
|
finished = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Lang;
|
|
||||||
class Screen;
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
class Text;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -22,14 +18,10 @@ class Instructions {
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
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
|
std::vector<Texture *> itemTextures; // Vector con las texturas de los items
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
Sprite *sprite; // Sprite con la textura de las instrucciones
|
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
|
Text *text; // Objeto para escribir texto
|
||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
|
||||||
@@ -48,7 +40,7 @@ class Instructions {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
|
Instructions(SDL_Renderer *renderer, section_t *section);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Instructions();
|
~Instructions();
|
||||||
|
|||||||
@@ -13,19 +13,14 @@
|
|||||||
#include "core/rendering/text.h" // for Text
|
#include "core/rendering/text.h" // for Text
|
||||||
#include "core/rendering/texture.h" // for Texture
|
#include "core/rendering/texture.h" // for Texture
|
||||||
#include "core/rendering/writer.h" // for Writer
|
#include "core/rendering/writer.h" // for Writer
|
||||||
#include "core/resources/asset.h" // for Asset
|
|
||||||
#include "core/resources/resource.h"
|
#include "core/resources/resource.h"
|
||||||
#include "game/defaults.hpp" // for GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QU...
|
#include "game/defaults.hpp" // for GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QU...
|
||||||
#include "utils/utils.h" // for section_t, color_t
|
#include "utils/utils.h" // for section_t, color_t
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Copia los punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
|
||||||
this->lang = lang;
|
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// 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
|
// Un dia qualsevol de l'any 2000
|
||||||
texts[0]->setCaption(lang->getText(27));
|
texts[0]->setCaption(Lang::get()->getText(27));
|
||||||
texts[0]->setSpeed(8);
|
texts[0]->setSpeed(8);
|
||||||
|
|
||||||
// Tot esta tranquil a la UPV
|
// Tot esta tranquil a la UPV
|
||||||
texts[1]->setCaption(lang->getText(28));
|
texts[1]->setCaption(Lang::get()->getText(28));
|
||||||
texts[1]->setSpeed(8);
|
texts[1]->setSpeed(8);
|
||||||
|
|
||||||
// Fins que un desaprensiu...
|
// Fins que un desaprensiu...
|
||||||
texts[2]->setCaption(lang->getText(29));
|
texts[2]->setCaption(Lang::get()->getText(29));
|
||||||
texts[2]->setSpeed(12);
|
texts[2]->setSpeed(12);
|
||||||
|
|
||||||
// HEY! ME ANE A FERME UN CORTAET...
|
// HEY! ME ANE A FERME UN CORTAET...
|
||||||
texts[3]->setCaption(lang->getText(30));
|
texts[3]->setCaption(Lang::get()->getText(30));
|
||||||
texts[3]->setSpeed(8);
|
texts[3]->setSpeed(8);
|
||||||
|
|
||||||
// UAAAAAAAAAAAAA!!!
|
// UAAAAAAAAAAAAA!!!
|
||||||
texts[4]->setCaption(lang->getText(31));
|
texts[4]->setCaption(Lang::get()->getText(31));
|
||||||
texts[4]->setSpeed(1);
|
texts[4]->setSpeed(1);
|
||||||
|
|
||||||
// Espera un moment...
|
// Espera un moment...
|
||||||
texts[5]->setCaption(lang->getText(32));
|
texts[5]->setCaption(Lang::get()->getText(32));
|
||||||
texts[5]->setSpeed(16);
|
texts[5]->setSpeed(16);
|
||||||
|
|
||||||
// Si resulta que no tinc solt!
|
// Si resulta que no tinc solt!
|
||||||
texts[6]->setCaption(lang->getText(33));
|
texts[6]->setCaption(Lang::get()->getText(33));
|
||||||
texts[6]->setSpeed(2);
|
texts[6]->setSpeed(2);
|
||||||
|
|
||||||
// MERDA DE MAQUINA!
|
// MERDA DE MAQUINA!
|
||||||
texts[7]->setCaption(lang->getText(34));
|
texts[7]->setCaption(Lang::get()->getText(34));
|
||||||
texts[7]->setSpeed(3);
|
texts[7]->setSpeed(3);
|
||||||
|
|
||||||
// Blop... blop... blop...
|
// Blop... blop... blop...
|
||||||
texts[8]->setCaption(lang->getText(35));
|
texts[8]->setCaption(Lang::get()->getText(35));
|
||||||
texts[8]->setSpeed(16);
|
texts[8]->setSpeed(16);
|
||||||
|
|
||||||
for (auto text : texts) {
|
for (auto text : texts) {
|
||||||
@@ -193,14 +188,14 @@ void Intro::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Intro::checkInput() {
|
void Intro::checkInput() {
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#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();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
@@ -369,10 +364,10 @@ void Intro::update() {
|
|||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void Intro::render() {
|
void Intro::render() {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
for (auto bitmap : bitmaps) {
|
for (auto bitmap : bitmaps) {
|
||||||
@@ -384,7 +379,7 @@ void Intro::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Lang;
|
|
||||||
class Screen;
|
|
||||||
class SmartSprite;
|
class SmartSprite;
|
||||||
class Text;
|
class Text;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -19,12 +15,8 @@ class Intro {
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Texture *texture; // Textura con los graficos
|
Texture *texture; // Textura con los graficos
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
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<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||||
std::vector<Writer *> texts; // Textos de la intro
|
std::vector<Writer *> texts; // Textos de la intro
|
||||||
Text *text; // Textos de la intro
|
Text *text; // Textos de la intro
|
||||||
@@ -56,7 +48,7 @@ class Intro {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
|
Intro(SDL_Renderer *renderer, section_t *section);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Intro();
|
~Intro();
|
||||||
|
|||||||
@@ -21,12 +21,9 @@ constexpr int INIT_FADE = 100;
|
|||||||
constexpr int END_LOGO = 200;
|
constexpr int END_LOGO = 200;
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Copia la dirección de los objetos
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
@@ -76,14 +73,14 @@ void Logo::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Logo::checkInput() {
|
void Logo::checkInput() {
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#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->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
@@ -120,10 +117,10 @@ void Logo::update() {
|
|||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void Logo::render() {
|
void Logo::render() {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean({238, 238, 238});
|
Screen::get()->clean({238, 238, 238});
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
sprite->render();
|
sprite->render();
|
||||||
@@ -132,7 +129,7 @@ void Logo::render() {
|
|||||||
renderFade();
|
renderFade();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Screen;
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
struct section_t;
|
struct section_t;
|
||||||
@@ -13,9 +10,6 @@ class Logo {
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
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
|
Texture *texture; // Textura con los graficos
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
Sprite *sprite; // Sprite con la textura del logo
|
Sprite *sprite; // Sprite con la textura del logo
|
||||||
@@ -46,7 +40,7 @@ class Logo {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section);
|
Logo(SDL_Renderer *renderer, section_t *section);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Logo();
|
~Logo();
|
||||||
|
|||||||
@@ -25,13 +25,9 @@
|
|||||||
#include "game/ui/menu.h" // for Menu
|
#include "game/ui/menu.h" // for Menu
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Copia las direcciones de los punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
|
||||||
this->input = input;
|
|
||||||
this->asset = asset;
|
|
||||||
this->lang = lang;
|
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// 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
|
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
|
// 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].id = availableInputDevices[deviceIndex[1]].id;
|
||||||
Options::inputs[1].name = availableInputDevices[deviceIndex[1]].name;
|
Options::inputs[1].name = availableInputDevices[deviceIndex[1]].name;
|
||||||
Options::inputs[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
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
|
// que Screen::blit() presente por la ruta activa (GPU o
|
||||||
// SDL_Renderer). Un `SDL_RenderPresent(renderer)` directe
|
// SDL_Renderer). Un `SDL_RenderPresent(renderer)` directe
|
||||||
// crasheja quan el SDL3 GPU ha reclamat la ventana.
|
// crasheja quan el SDL3 GPU ha reclamat la ventana.
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(crashSound);
|
JA_PlaySound(crashSound);
|
||||||
@@ -513,10 +509,10 @@ void Title::render() {
|
|||||||
// Sección 1 - Titulo desplazandose
|
// Sección 1 - Titulo desplazandose
|
||||||
case SUBSECTION_TITLE_1: {
|
case SUBSECTION_TITLE_1: {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
// Dibuja el tileado de fondo
|
||||||
{
|
{
|
||||||
@@ -532,16 +528,16 @@ void Title::render() {
|
|||||||
crisisBitmap->render();
|
crisisBitmap->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// Sección 2 - Titulo vibrando
|
// Sección 2 - Titulo vibrando
|
||||||
case SUBSECTION_TITLE_2: {
|
case SUBSECTION_TITLE_2: {
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
// Dibuja el tileado de fondo
|
||||||
{
|
{
|
||||||
@@ -560,15 +556,15 @@ void Title::render() {
|
|||||||
dustBitmapL->render();
|
dustBitmapL->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
// 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
|
case SUBSECTION_TITLE_3: { // Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
Screen::get()->clean(bgColor);
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
// Dibuja el tileado de fondo
|
||||||
{
|
{
|
||||||
@@ -598,14 +594,14 @@ void Title::render() {
|
|||||||
|
|
||||||
// PRESS ANY KEY!
|
// PRESS ANY KEY!
|
||||||
if ((counter % 50 > 14) && (menuVisible == false)) {
|
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
|
||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -642,12 +638,12 @@ void Title::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Title::checkInput() {
|
void Title::checkInput() {
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
GlobalInputs::handle(screen, input);
|
GlobalInputs::handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el tileado de fondo
|
// Actualiza el tileado de fondo
|
||||||
@@ -673,37 +669,37 @@ void Title::updateMenuLabels() {
|
|||||||
// DIFFICULTY
|
// DIFFICULTY
|
||||||
switch (Options::settings.difficulty) {
|
switch (Options::settings.difficulty) {
|
||||||
case DIFFICULTY_EASY:
|
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;
|
break;
|
||||||
|
|
||||||
case DIFFICULTY_NORMAL:
|
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;
|
break;
|
||||||
|
|
||||||
case DIFFICULTY_HARD:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 1 CONTROLS
|
// PLAYER 1 CONTROLS
|
||||||
menu.options->setItemCaption(i, lang->getText(62));
|
menu.options->setItemCaption(i, Lang::get()->getText(62));
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 1 CONTROLS - OPTIONS
|
// PLAYER 1 CONTROLS - OPTIONS
|
||||||
switch (Options::inputs[0].deviceType) {
|
switch (Options::inputs[0].deviceType) {
|
||||||
case INPUT_USE_KEYBOARD:
|
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);
|
menu.options->setGreyed(i, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_USE_GAMECONTROLLER:
|
case INPUT_USE_GAMECONTROLLER:
|
||||||
menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER
|
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||||
if (!input->gameControllerFound())
|
if (!Input::get()->gameControllerFound())
|
||||||
menu.options->setGreyed(i, true);
|
menu.options->setGreyed(i, true);
|
||||||
else {
|
else {
|
||||||
menu.options->setGreyed(i, false);
|
menu.options->setGreyed(i, false);
|
||||||
@@ -712,25 +708,25 @@ void Title::updateMenuLabels() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 2 CONTROLS
|
// PLAYER 2 CONTROLS
|
||||||
menu.options->setItemCaption(i, lang->getText(63));
|
menu.options->setItemCaption(i, Lang::get()->getText(63));
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 2 CONTROLS - OPTIONS
|
// PLAYER 2 CONTROLS - OPTIONS
|
||||||
switch (Options::inputs[1].deviceType) {
|
switch (Options::inputs[1].deviceType) {
|
||||||
case INPUT_USE_KEYBOARD:
|
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);
|
menu.options->setGreyed(i, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_USE_GAMECONTROLLER:
|
case INPUT_USE_GAMECONTROLLER:
|
||||||
menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER
|
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
|
||||||
if (!input->gameControllerFound())
|
if (!Input::get()->gameControllerFound())
|
||||||
menu.options->setGreyed(i, true);
|
menu.options->setGreyed(i, true);
|
||||||
else {
|
else {
|
||||||
menu.options->setGreyed(i, false);
|
menu.options->setGreyed(i, false);
|
||||||
@@ -739,7 +735,7 @@ void Title::updateMenuLabels() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
|
menu.options->setItemCaption(i, Lang::get()->getText(69)); // KEYBOARD
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,59 +743,59 @@ void Title::updateMenuLabels() {
|
|||||||
// LANGUAGE
|
// LANGUAGE
|
||||||
switch (Options::settings.language) {
|
switch (Options::settings.language) {
|
||||||
case es_ES:
|
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;
|
break;
|
||||||
|
|
||||||
case ba_BA:
|
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;
|
break;
|
||||||
|
|
||||||
case en_UK:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// DISPLAY MODE
|
// DISPLAY MODE
|
||||||
menu.options->setItemCaption(i, lang->getText(58));
|
menu.options->setItemCaption(i, Lang::get()->getText(58));
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// DISPLAY MODE - OPTIONS
|
// 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++;
|
i++;
|
||||||
// WINDOW SIZE
|
// 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++;
|
i++;
|
||||||
// SCALE MODE
|
// SCALE MODE
|
||||||
if (Options::video.scale_mode == SDL_SCALEMODE_LINEAR)
|
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
|
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++;
|
i++;
|
||||||
// VSYNC
|
// VSYNC
|
||||||
if (Options::video.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
|
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++;
|
i++;
|
||||||
// HOW TO PLAY
|
// HOW TO PLAY
|
||||||
menu.options->setItemCaption(i, lang->getText(2));
|
menu.options->setItemCaption(i, Lang::get()->getText(2));
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// ACCEPT
|
// ACCEPT
|
||||||
menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT
|
menu.options->setItemCaption(i, Lang::get()->getText(9)); // ACCEPT
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
// CANCEL
|
// CANCEL
|
||||||
menu.options->setItemCaption(i, lang->getText(10)); // CANCEL
|
menu.options->setItemCaption(i, Lang::get()->getText(10)); // CANCEL
|
||||||
|
|
||||||
// Recoloca el menu de opciones
|
// Recoloca el menu de opciones
|
||||||
menu.options->centerMenuOnX(GAMECANVAS_CENTER_X);
|
menu.options->centerMenuOnX(GAMECANVAS_CENTER_X);
|
||||||
@@ -808,13 +804,13 @@ void Title::updateMenuLabels() {
|
|||||||
|
|
||||||
// Establece las etiquetas del menu de titulo
|
// Establece las etiquetas del menu de titulo
|
||||||
#ifdef GAME_CONSOLE
|
#ifdef GAME_CONSOLE
|
||||||
menu.title->setItemCaption(0, lang->getText(0)); // PLAY
|
menu.title->setItemCaption(0, Lang::get()->getText(0)); // PLAY
|
||||||
#else
|
#else
|
||||||
menu.title->setItemCaption(0, lang->getText(51)); // 1 PLAYER
|
menu.title->setItemCaption(0, Lang::get()->getText(51)); // 1 PLAYER
|
||||||
#endif
|
#endif
|
||||||
menu.title->setItemCaption(1, lang->getText(52)); // 2 PLAYERS
|
menu.title->setItemCaption(1, Lang::get()->getText(52)); // 2 PLAYERS
|
||||||
menu.title->setItemCaption(2, lang->getText(1)); // OPTIONS
|
menu.title->setItemCaption(2, Lang::get()->getText(1)); // OPTIONS
|
||||||
menu.title->setItemCaption(3, lang->getText(3)); // QUIT
|
menu.title->setItemCaption(3, Lang::get()->getText(3)); // QUIT
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
menu.title->setVisible(3, false);
|
menu.title->setVisible(3, false);
|
||||||
menu.title->setSelectable(3, false);
|
menu.title->setSelectable(3, false);
|
||||||
@@ -825,8 +821,8 @@ void Title::updateMenuLabels() {
|
|||||||
menu.title->centerMenuElementsOnX();
|
menu.title->centerMenuElementsOnX();
|
||||||
|
|
||||||
// Establece las etiquetas del menu de seleccion de jugador
|
// Establece las etiquetas del menu de seleccion de jugador
|
||||||
menu.playerSelect->setItemCaption(0, lang->getText(39)); // SELECT PLAYER
|
menu.playerSelect->setItemCaption(0, Lang::get()->getText(39)); // SELECT PLAYER
|
||||||
menu.playerSelect->setItemCaption(3, lang->getText(40)); // BACK
|
menu.playerSelect->setItemCaption(3, Lang::get()->getText(40)); // BACK
|
||||||
|
|
||||||
// Recoloca el menu de selección de jugador
|
// Recoloca el menu de selección de jugador
|
||||||
menu.playerSelect->centerMenuOnX(GAMECANVAS_CENTER_X);
|
menu.playerSelect->centerMenuOnX(GAMECANVAS_CENTER_X);
|
||||||
@@ -846,11 +842,11 @@ void Title::updateMenuLabels() {
|
|||||||
|
|
||||||
// Aplica las opciones de menu seleccionadas
|
// Aplica las opciones de menu seleccionadas
|
||||||
void Title::applyOptions() {
|
void Title::applyOptions() {
|
||||||
screen->setVideoMode(Options::video.fullscreen);
|
Screen::get()->setVideoMode(Options::video.fullscreen);
|
||||||
screen->setWindowZoom(Options::window.zoom);
|
Screen::get()->setWindowZoom(Options::window.zoom);
|
||||||
screen->setVSync(Options::video.vsync);
|
Screen::get()->setVSync(Options::video.vsync);
|
||||||
|
|
||||||
lang->setLang(Options::settings.language);
|
Lang::get()->setLang(Options::settings.language);
|
||||||
|
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
createTiledBackground();
|
createTiledBackground();
|
||||||
@@ -954,7 +950,7 @@ void Title::run() {
|
|||||||
|
|
||||||
// Inicia la parte donde se muestran las instrucciones
|
// Inicia la parte donde se muestran las instrucciones
|
||||||
void Title::runInstructions(mode_e mode) {
|
void Title::runInstructions(mode_e mode) {
|
||||||
instructions = new Instructions(renderer, screen, asset, input, lang, section);
|
instructions = new Instructions(renderer, section);
|
||||||
instructions->start(mode);
|
instructions->start(mode);
|
||||||
instructionsActive = true;
|
instructionsActive = true;
|
||||||
instructionsMode = mode;
|
instructionsMode = mode;
|
||||||
@@ -965,7 +961,7 @@ void Title::runDemoGame() {
|
|||||||
// Temporalmente ponemos section para que el constructor de Game funcione
|
// Temporalmente ponemos section para que el constructor de Game funcione
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
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;
|
demoGameActive = true;
|
||||||
// Restauramos section para que Director no transicione fuera de Title
|
// Restauramos section para que Director no transicione fuera de Title
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
@@ -975,7 +971,7 @@ void Title::runDemoGame() {
|
|||||||
bool Title::updatePlayerInputs(int numPlayer) {
|
bool Title::updatePlayerInputs(int numPlayer) {
|
||||||
const int numDevices = availableInputDevices.size();
|
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[0] = 0;
|
||||||
deviceIndex[1] = 0;
|
deviceIndex[1] = 0;
|
||||||
|
|
||||||
@@ -1035,7 +1031,7 @@ void Title::createTiledBackground() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos para pintar en la textura de fondo
|
// 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);
|
Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer);
|
||||||
|
|
||||||
// Prepara para dibujar sobre la textura
|
// Prepara para dibujar sobre la textura
|
||||||
@@ -1069,7 +1065,7 @@ void Title::checkInputDevices() {
|
|||||||
if (Options::settings.console) {
|
if (Options::settings.console) {
|
||||||
std::cout << "Filling devices for options menu..." << std::endl;
|
std::cout << "Filling devices for options menu..." << std::endl;
|
||||||
}
|
}
|
||||||
const int numControllers = input->getNumControllers();
|
const int numControllers = Input::get()->getNumControllers();
|
||||||
availableInputDevices.clear();
|
availableInputDevices.clear();
|
||||||
input_t temp;
|
input_t temp;
|
||||||
|
|
||||||
@@ -1077,7 +1073,7 @@ void Title::checkInputDevices() {
|
|||||||
if (numControllers > 0)
|
if (numControllers > 0)
|
||||||
for (int i = 0; i < numControllers; ++i) {
|
for (int i = 0; i < numControllers; ++i) {
|
||||||
temp.id = i;
|
temp.id = i;
|
||||||
temp.name = input->getControllerName(i);
|
temp.name = Input::get()->getControllerName(i);
|
||||||
temp.deviceType = INPUT_USE_GAMECONTROLLER;
|
temp.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
availableInputDevices.push_back(temp);
|
availableInputDevices.push_back(temp);
|
||||||
if (Options::settings.console) {
|
if (Options::settings.console) {
|
||||||
|
|||||||
@@ -8,13 +8,9 @@
|
|||||||
#include "game/scenes/instructions.h" // for mode_e
|
#include "game/scenes/instructions.h" // for mode_e
|
||||||
#include "utils/utils.h" // for input_t, section_t
|
#include "utils/utils.h" // for input_t, section_t
|
||||||
class AnimatedSprite;
|
class AnimatedSprite;
|
||||||
class Asset;
|
|
||||||
class Fade;
|
class Fade;
|
||||||
class Game;
|
class Game;
|
||||||
class Input;
|
|
||||||
class Lang;
|
|
||||||
class Menu;
|
class Menu;
|
||||||
class Screen;
|
|
||||||
class SmartSprite;
|
class SmartSprite;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
class Text;
|
||||||
@@ -43,10 +39,6 @@ class Title {
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
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
|
Instructions *instructions; // Objeto para la sección de las instrucciones
|
||||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
Game *demoGame; // Objeto para lanzar la demo del juego
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
@@ -153,7 +145,7 @@ class Title {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, Lang *lang, section_t *section);
|
Title(SDL_Renderer *renderer, section_t *section);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Title();
|
~Title();
|
||||||
|
|||||||
@@ -11,11 +11,9 @@
|
|||||||
#include "core/resources/resource_helper.h"
|
#include "core/resources/resource_helper.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file) {
|
Menu::Menu(SDL_Renderer *renderer, std::string file) {
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
|
|
||||||
// Inicializa punteros
|
// Inicializa punteros
|
||||||
soundMove = nullptr;
|
soundMove = nullptr;
|
||||||
@@ -74,8 +72,6 @@ Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
|||||||
|
|
||||||
Menu::~Menu() {
|
Menu::~Menu() {
|
||||||
renderer = nullptr;
|
renderer = nullptr;
|
||||||
asset = nullptr;
|
|
||||||
input = nullptr;
|
|
||||||
|
|
||||||
if (soundMove) {
|
if (soundMove) {
|
||||||
JA_DeleteSound(soundMove);
|
JA_DeleteSound(soundMove);
|
||||||
@@ -130,8 +126,8 @@ bool Menu::parseFromStream(std::istream &file, const std::string &filename) {
|
|||||||
// Crea el objeto text tan pronto como se pueda. Necesario para añadir items.
|
// Crea el objeto text tan pronto como se pueda. Necesario para añadir items.
|
||||||
// Carga via ResourceHelper para que funcione tanto con pack como con filesystem.
|
// Carga via ResourceHelper para que funcione tanto con pack como con filesystem.
|
||||||
if (font_png != "" && font_txt != "" && !textAllocated) {
|
if (font_png != "" && font_txt != "" && !textAllocated) {
|
||||||
auto pngBytes = ResourceHelper::loadFile(asset->get(font_png));
|
auto pngBytes = ResourceHelper::loadFile(Asset::get()->get(font_png));
|
||||||
auto txtBytes = ResourceHelper::loadFile(asset->get(font_txt));
|
auto txtBytes = ResourceHelper::loadFile(Asset::get()->get(font_txt));
|
||||||
text = new Text(pngBytes, txtBytes, renderer);
|
text = new Text(pngBytes, txtBytes, renderer);
|
||||||
textAllocated = true;
|
textAllocated = true;
|
||||||
}
|
}
|
||||||
@@ -218,17 +214,17 @@ bool Menu::setVars(std::string var, std::string value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "sound_cancel") {
|
else if (var == "sound_cancel") {
|
||||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||||
if (!bytes.empty()) soundCancel = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
if (!bytes.empty()) soundCancel = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "sound_accept") {
|
else if (var == "sound_accept") {
|
||||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||||
if (!bytes.empty()) soundAccept = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
if (!bytes.empty()) soundAccept = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "sound_move") {
|
else if (var == "sound_move") {
|
||||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||||
if (!bytes.empty()) soundMove = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
if (!bytes.empty()) soundMove = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,7 +766,7 @@ void Menu::setDefaultActionWhenCancel(int item) {
|
|||||||
|
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
// Gestiona la entrada de teclado y mando durante el menu
|
||||||
void Menu::checkInput() {
|
void Menu::checkInput() {
|
||||||
if (input->checkInput(input_up, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_up, REPEAT_FALSE)) {
|
||||||
if (decreaseSelectorIndex()) {
|
if (decreaseSelectorIndex()) {
|
||||||
if (soundMove) {
|
if (soundMove) {
|
||||||
JA_PlaySound(soundMove);
|
JA_PlaySound(soundMove);
|
||||||
@@ -778,7 +774,7 @@ void Menu::checkInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->checkInput(input_down, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_down, REPEAT_FALSE)) {
|
||||||
if (increaseSelectorIndex()) {
|
if (increaseSelectorIndex()) {
|
||||||
if (soundMove) {
|
if (soundMove) {
|
||||||
JA_PlaySound(soundMove);
|
JA_PlaySound(soundMove);
|
||||||
@@ -786,14 +782,14 @@ void Menu::checkInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->checkInput(input_accept, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) {
|
||||||
itemSelected = selector.index;
|
itemSelected = selector.index;
|
||||||
if (soundAccept) {
|
if (soundAccept) {
|
||||||
JA_PlaySound(soundAccept);
|
JA_PlaySound(soundAccept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->checkInput(input_cancel, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_cancel, REPEAT_FALSE)) {
|
||||||
itemSelected = defaultActionWhenCancel;
|
itemSelected = defaultActionWhenCancel;
|
||||||
if (soundCancel) {
|
if (soundCancel) {
|
||||||
JA_PlaySound(soundCancel);
|
JA_PlaySound(soundCancel);
|
||||||
@@ -875,7 +871,7 @@ void Menu::setBackgroundType(int value) {
|
|||||||
// Establece la fuente de texto que se utilizará
|
// Establece la fuente de texto que se utilizará
|
||||||
void Menu::setText(std::string font_png, std::string font_txt) {
|
void Menu::setText(std::string font_png, std::string font_txt) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
text = new Text(asset->get(font_png), asset->get(font_txt), renderer);
|
text = new Text(Asset::get()->get(font_png), Asset::get()->get(font_txt), renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "utils/utils.h" // for color_t
|
#include "utils/utils.h" // for color_t
|
||||||
class Asset;
|
|
||||||
class Input;
|
|
||||||
class Text;
|
class Text;
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
@@ -70,9 +68,7 @@ class Menu {
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||||
Asset *asset; // Objeto para gestionar los ficheros de recursos
|
|
||||||
Text *text; // Texto para poder escribir los items del menu
|
Text *text; // Texto para poder escribir los items del menu
|
||||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string name; // Nombre del menu
|
std::string name; // Nombre del menu
|
||||||
@@ -146,7 +142,7 @@ class Menu {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = "");
|
Menu(SDL_Renderer *renderer, std::string file = "");
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Menu();
|
~Menu();
|
||||||
|
|||||||
Reference in New Issue
Block a user