Make_unique en title.cpp
This commit is contained in:
@@ -5,9 +5,6 @@
|
|||||||
#include <string> // for allocator, basic_string, char_traits
|
#include <string> // for allocator, basic_string, char_traits
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "define_buttons.h" // for DefineButtons
|
|
||||||
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE
|
|
||||||
#include "game_logo.h" // for GameLogo
|
|
||||||
#include "global_inputs.h" // for globalInputs::check
|
#include "global_inputs.h" // for globalInputs::check
|
||||||
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_RE...
|
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_RE...
|
||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_P...
|
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_P...
|
||||||
@@ -16,63 +13,41 @@
|
|||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "section.h" // for options_e, options, name_e, name
|
#include "section.h" // for options_e, options, name_e, name
|
||||||
#include "sprite.h" // for Sprite
|
|
||||||
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW
|
|
||||||
#include "texture.h" // for Texture
|
|
||||||
#include "tiled_bg.h" // for Tiledbg, TILED_MODE_RANDOM
|
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(JA_Music_t *music)
|
Title::Title(JA_Music_t *music) : music(music)
|
||||||
{
|
{
|
||||||
// Copia las direcciones de los punteros y objetos
|
// Copia las direcciones de los punteros y objetos
|
||||||
this->music = music;
|
|
||||||
input = Input::get();
|
input = Input::get();
|
||||||
asset = Asset::get();
|
asset = Asset::get();
|
||||||
screen = Screen::get();
|
screen = Screen::get();
|
||||||
SDL_Renderer *renderer = screen->getRenderer();
|
SDL_Renderer *renderer = screen->getRenderer();
|
||||||
|
|
||||||
// Reserva memoria y crea los objetos
|
// Reserva memoria y crea los objetos
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = std::make_unique<SDL_Event>();
|
||||||
fade = new Fade(renderer);
|
fade = std::make_unique<Fade>(renderer);
|
||||||
|
|
||||||
text1 = new Text(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer);
|
text1 = std::make_unique<Text>(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer);
|
||||||
text1->addPalette(asset->get("smb2_pal1.gif"));
|
text1->addPalette(asset->get("smb2_pal1.gif"));
|
||||||
text1->setPalette(1);
|
text1->setPalette(1);
|
||||||
text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
text2 = std::make_unique<Text>(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||||
|
|
||||||
miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png"));
|
miniLogoTexture = std::make_unique<Texture>(renderer, asset->get("logo_jailgames_mini.png"));
|
||||||
miniLogoSprite = new Sprite(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture);
|
miniLogoSprite = std::make_unique<Sprite>(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture.get());
|
||||||
|
|
||||||
tiledbg = new Tiledbg(asset->get("title_bg_tile.png"), {0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
|
tiledbg = std::make_unique<Tiledbg>(asset->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
|
||||||
|
|
||||||
gameLogo = new GameLogo(param.game.gameArea.centerX, param.title.titleCCPosition);
|
gameLogo = std::make_unique<GameLogo>(param.game.gameArea.centerX, param.title.titleCCPosition);
|
||||||
gameLogo->enable();
|
gameLogo->enable();
|
||||||
|
|
||||||
defineButtons = new DefineButtons(text2);
|
defineButtons = std::make_unique<DefineButtons>(text2.get());
|
||||||
|
|
||||||
// Inicializa los valores
|
// Inicializa los valores
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Title::~Title()
|
|
||||||
{
|
|
||||||
// Destruye los objetos y libera la memoria
|
|
||||||
delete eventHandler;
|
|
||||||
delete fade;
|
|
||||||
|
|
||||||
delete text1;
|
|
||||||
delete text2;
|
|
||||||
|
|
||||||
delete miniLogoTexture;
|
|
||||||
delete miniLogoSprite;
|
|
||||||
|
|
||||||
delete tiledbg;
|
|
||||||
delete gameLogo;
|
|
||||||
delete defineButtons;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los valores de las variables
|
// Inicializa los valores de las variables
|
||||||
void Title::init()
|
void Title::init()
|
||||||
{
|
{
|
||||||
@@ -135,14 +110,7 @@ void Title::update()
|
|||||||
else if (section::options == section::OPTIONS_TITLE_2)
|
else if (section::options == section::OPTIONS_TITLE_2)
|
||||||
{
|
{
|
||||||
// El contador solo sube si no estamos definiendo botones
|
// El contador solo sube si no estamos definiendo botones
|
||||||
if (!defineButtons->isEnabled())
|
counter = defineButtons->isEnabled() ? 0 : counter + 1;
|
||||||
{
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
counter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reproduce la música
|
// Reproduce la música
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
@@ -182,8 +150,9 @@ void Title::render()
|
|||||||
|
|
||||||
if (section::options == section::OPTIONS_TITLE_2)
|
if (section::options == section::OPTIONS_TITLE_2)
|
||||||
{
|
{
|
||||||
const color_t shadow = {0x14, 0x87, 0xc4};
|
constexpr color_t shadow = {0x14, 0x87, 0xc4};
|
||||||
// 'PULSA 1P o 2P PARA JUGAR'
|
|
||||||
|
// 'PRESS TO PLAY'
|
||||||
if (counter % 50 > 14 && !defineButtons->isEnabled())
|
if (counter % 50 > 14 && !defineButtons->isEnabled())
|
||||||
{
|
{
|
||||||
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, param.title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow);
|
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, param.title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow);
|
||||||
@@ -216,7 +185,7 @@ void Title::checkEvents()
|
|||||||
if (!defineButtons->isEnabled())
|
if (!defineButtons->isEnabled())
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
// Comprueba los eventos que hay en la cola
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(eventHandler.get()) != 0)
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (eventHandler->type == SDL_QUIT)
|
||||||
@@ -236,18 +205,24 @@ void Title::checkEvents()
|
|||||||
switch (eventHandler->key.keysym.sym)
|
switch (eventHandler->key.keysym.sym)
|
||||||
{
|
{
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
|
{
|
||||||
if (defineButtons->enable(0))
|
if (defineButtons->enable(0))
|
||||||
resetCounter();
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SDLK_2:
|
case SDLK_2:
|
||||||
|
{
|
||||||
if (defineButtons->enable(1))
|
if (defineButtons->enable(1))
|
||||||
resetCounter();
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SDLK_3:
|
case SDLK_3:
|
||||||
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -263,10 +238,6 @@ void Title::checkInput()
|
|||||||
// Comprueba los controladores solo si no se estan definiendo los botones
|
// Comprueba los controladores solo si no se estan definiendo los botones
|
||||||
if (!defineButtons->isEnabled())
|
if (!defineButtons->isEnabled())
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////
|
|
||||||
// TECLADO //
|
|
||||||
//////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Comprueba el teclado para empezar a jugar
|
// Comprueba el teclado para empezar a jugar
|
||||||
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||||
{
|
{
|
||||||
@@ -277,10 +248,7 @@ void Title::checkInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////
|
// Comprueba los mandos
|
||||||
// MANDOS //
|
|
||||||
//////////////////////////////////////////////////
|
|
||||||
|
|
||||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||||
@@ -299,7 +267,8 @@ void Title::checkInput()
|
|||||||
|
|
||||||
// Comprueba el botón de START de los mandos
|
// Comprueba el botón de START de los mandos
|
||||||
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{ // Si no está el botón de servicio activo
|
{
|
||||||
|
// Si no está el botón de servicio activo
|
||||||
if (!input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (!input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
@@ -359,7 +328,7 @@ void Title::swapControllers()
|
|||||||
defineButtons->swapControllers();
|
defineButtons->swapControllers();
|
||||||
|
|
||||||
// Crea cadenas de texto vacias para un numero máximo de mandos
|
// Crea cadenas de texto vacias para un numero máximo de mandos
|
||||||
const int MAX_CONTROLLERS = 2;
|
constexpr int MAX_CONTROLLERS = 2;
|
||||||
std::string text[MAX_CONTROLLERS];
|
std::string text[MAX_CONTROLLERS];
|
||||||
int playerControllerIndex[MAX_CONTROLLERS];
|
int playerControllerIndex[MAX_CONTROLLERS];
|
||||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||||
@@ -380,7 +349,7 @@ void Title::swapControllers()
|
|||||||
const int index = playerControllerIndex[i];
|
const int index = playerControllerIndex[i];
|
||||||
if (options.controller[index].plugged)
|
if (options.controller[index].plugged)
|
||||||
{
|
{
|
||||||
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name;
|
text[i] = lang::getText(101) + std::to_string(i + 1) + ": " + options.controller[index].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,24 +2,28 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
|
#include <memory>
|
||||||
|
#include "define_buttons.h"
|
||||||
|
#include "fade.h"
|
||||||
|
#include "game_logo.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "tiled_bg.h"
|
||||||
#include "utils.h" // for section_t
|
#include "utils.h" // for section_t
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "texture.h"
|
||||||
|
|
||||||
class Asset;
|
class Asset;
|
||||||
class DefineButtons;
|
|
||||||
class Fade;
|
|
||||||
class GameLogo;
|
|
||||||
class Input;
|
class Input;
|
||||||
class Screen;
|
class Screen;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
|
||||||
class Texture;
|
class Texture;
|
||||||
class Tiledbg;
|
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
#define TEXT_COPYRIGHT "@2020,2024 JailDesigner"
|
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||||
|
|
||||||
// Parámetros
|
// Parámetros
|
||||||
#define ALLOW_TITLE_ANIMATION_SKIP true
|
constexpr bool ALLOW_TITLE_ANIMATION_SKIP = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu
|
Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu
|
||||||
@@ -44,16 +48,16 @@ private:
|
|||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||||
Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
std::unique_ptr<Tiledbg> tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
||||||
GameLogo *gameLogo; // Objeto para dibujar el logo con el título del juego
|
std::unique_ptr<GameLogo> gameLogo; // Objeto para dibujar el logo con el título del juego
|
||||||
DefineButtons *defineButtons; // Objeto para definir los botones del joystic
|
std::unique_ptr<DefineButtons> defineButtons; // Objeto para definir los botones del joystic
|
||||||
Texture *miniLogoTexture; // Textura con el logo de JailGames mini
|
std::unique_ptr<Texture> miniLogoTexture; // Textura con el logo de JailGames mini
|
||||||
Sprite *miniLogoSprite; // Sprite con el logo de JailGames mini
|
std::unique_ptr<Sprite> miniLogoSprite; // Sprite con el logo de JailGames mini
|
||||||
|
|
||||||
Text *text1; // Objeto de texto para poder escribir textos en pantalla
|
std::unique_ptr<Text> text1; // Objeto de texto para poder escribir textos en pantalla
|
||||||
Text *text2; // Objeto de texto para poder escribir textos en pantalla
|
std::unique_ptr<Text> text2; // Objeto de texto para poder escribir textos en pantalla
|
||||||
Fade *fade; // Objeto para realizar fundidos en pantalla
|
std::unique_ptr<Fade> fade; // Objeto para realizar fundidos en pantalla
|
||||||
|
|
||||||
JA_Music_t *music; // Musica para el titulo
|
JA_Music_t *music; // Musica para el titulo
|
||||||
|
|
||||||
@@ -95,7 +99,7 @@ public:
|
|||||||
Title(JA_Music_t *music);
|
Title(JA_Music_t *music);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Title();
|
~Title() = default;
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
Reference in New Issue
Block a user