Posant make_uniques, s'ha quedat tot enmerdat per culpa d'un struct
This commit is contained in:
@@ -21,16 +21,13 @@
|
|||||||
HiScoreTable::HiScoreTable(JA_Music_t *music) : music(music)
|
HiScoreTable::HiScoreTable(JA_Music_t *music) : music(music)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
asset = Asset::get();
|
renderer = Screen::get()->getRenderer();
|
||||||
input = Input::get();
|
|
||||||
screen = Screen::get();
|
|
||||||
renderer = screen->getRenderer();
|
|
||||||
|
|
||||||
// Objetos
|
// Objetos
|
||||||
eventHandler = std::make_unique<SDL_Event>();
|
eventHandler = std::make_unique<SDL_Event>();
|
||||||
fade = std::make_unique<Fade>(renderer);
|
fade = std::make_unique<Fade>(renderer);
|
||||||
background = std::make_unique<Background>(renderer);
|
background = std::make_unique<Background>(renderer);
|
||||||
text = std::make_unique<Text>(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer);
|
text = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||||
@@ -80,7 +77,7 @@ void HiScoreTable::update()
|
|||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music);
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
background->update();
|
background->update();
|
||||||
@@ -147,10 +144,10 @@ void HiScoreTable::fillTexture()
|
|||||||
void HiScoreTable::render()
|
void HiScoreTable::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);
|
||||||
|
|
||||||
// Pinta el fondo
|
// Pinta el fondo
|
||||||
background->render();
|
background->render();
|
||||||
@@ -164,7 +161,7 @@ void HiScoreTable::render()
|
|||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
@@ -202,7 +199,7 @@ void HiScoreTable::checkEvents()
|
|||||||
void HiScoreTable::checkInput()
|
void HiScoreTable::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (input->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section::name = section::NAME_TITLE;
|
section::name = section::NAME_TITLE;
|
||||||
@@ -211,7 +208,7 @@ void HiScoreTable::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen->checkInput();
|
Screen::get()->checkInput();
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
|
|||||||
@@ -10,10 +10,6 @@
|
|||||||
#include "section.h" // for options_e
|
#include "section.h" // for options_e
|
||||||
#include "background.h"
|
#include "background.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
class Asset;
|
|
||||||
|
|
||||||
class Input;
|
|
||||||
class Screen;
|
|
||||||
|
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
@@ -33,10 +29,7 @@ class HiScoreTable
|
|||||||
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
|
|
||||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
|
||||||
JA_Music_t *music; // Musica de fondo
|
JA_Music_t *music; // Musica de fondo
|
||||||
|
|
||||||
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
||||||
|
|||||||
@@ -22,20 +22,16 @@
|
|||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions(JA_Music_t *music)
|
Instructions::Instructions(JA_Music_t *music) : music(music)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
this->music = music;
|
renderer = Screen::get()->getRenderer();
|
||||||
input = Input::get();
|
|
||||||
screen = Screen::get();
|
|
||||||
asset = Asset::get();
|
|
||||||
renderer = screen->getRenderer();
|
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = std::make_unique<SDL_Event>();
|
||||||
text = new Text(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer);
|
text = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
||||||
tiledbg = new Tiledbg(asset->get("title_bg_tile.png"), {0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC);
|
tiledbg = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC);
|
||||||
fade = new Fade(renderer);
|
fade = std::make_unique<Fade>(renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||||
@@ -72,24 +68,9 @@ Instructions::Instructions(JA_Music_t *music)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Instructions::~Instructions()
|
Instructions::~Instructions()
|
||||||
{
|
{
|
||||||
for (auto texture : itemTextures)
|
|
||||||
{
|
|
||||||
texture->unload();
|
|
||||||
delete texture;
|
|
||||||
}
|
|
||||||
itemTextures.clear();
|
itemTextures.clear();
|
||||||
|
|
||||||
for (auto sprite : sprites)
|
|
||||||
{
|
|
||||||
delete sprite;
|
|
||||||
}
|
|
||||||
sprites.clear();
|
sprites.clear();
|
||||||
|
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
|
||||||
delete tiledbg;
|
|
||||||
delete fade;
|
|
||||||
|
|
||||||
SDL_DestroyTexture(backbuffer);
|
SDL_DestroyTexture(backbuffer);
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
}
|
}
|
||||||
@@ -98,27 +79,27 @@ Instructions::~Instructions()
|
|||||||
void Instructions::iniSprites()
|
void Instructions::iniSprites()
|
||||||
{
|
{
|
||||||
// Inicializa las texturas
|
// Inicializa las texturas
|
||||||
Texture *item1 = new Texture(renderer, asset->get("item_points1_disk.png"));
|
auto item1 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points1_disk.png"));
|
||||||
itemTextures.push_back(item1);
|
itemTextures.push_back(std::move(item1));
|
||||||
|
|
||||||
Texture *item2 = new Texture(renderer, asset->get("item_points2_gavina.png"));
|
auto item2 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points2_gavina.png"));
|
||||||
itemTextures.push_back(item2);
|
itemTextures.push_back(std::move(item2));
|
||||||
|
|
||||||
Texture *item3 = new Texture(renderer, asset->get("item_points3_pacmar.png"));
|
auto item3 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points3_pacmar.png"));
|
||||||
itemTextures.push_back(item3);
|
itemTextures.push_back(std::move(item3));
|
||||||
|
|
||||||
Texture *item4 = new Texture(renderer, asset->get("item_clock.png"));
|
auto item4 = std::make_unique<Texture>(renderer, Asset::get()->get("item_clock.png"));
|
||||||
itemTextures.push_back(item4);
|
itemTextures.push_back(std::move(item4));
|
||||||
|
|
||||||
Texture *item5 = new Texture(renderer, asset->get("item_coffee.png"));
|
auto item5 = std::make_unique<Texture>(renderer, Asset::get()->get("item_coffee.png"));
|
||||||
itemTextures.push_back(item5);
|
itemTextures.push_back(std::move(item5));
|
||||||
|
|
||||||
// Inicializa los sprites
|
// Inicializa los sprites
|
||||||
for (int i = 0; i < (int)itemTextures.size(); ++i)
|
for (int i = 0; i < (int)itemTextures.size(); ++i)
|
||||||
{
|
{
|
||||||
Sprite *sprite = new Sprite(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i]);
|
auto sprite = std::make_unique<Sprite>(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i].get());
|
||||||
sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)});
|
sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)});
|
||||||
sprites.push_back(sprite);
|
sprites.push_back(std::move(sprite));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +210,7 @@ void Instructions::fillBackbuffer()
|
|||||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
for (auto sprite : sprites)
|
for (auto &sprite : sprites)
|
||||||
{
|
{
|
||||||
sprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
@@ -252,7 +233,7 @@ void Instructions::update()
|
|||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music);
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter++;
|
counter++;
|
||||||
@@ -282,10 +263,10 @@ void Instructions::render()
|
|||||||
fillBackbuffer();
|
fillBackbuffer();
|
||||||
|
|
||||||
// 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 mosacico de fondo
|
// Dibuja el mosacico de fondo
|
||||||
tiledbg->render();
|
tiledbg->render();
|
||||||
@@ -299,13 +280,13 @@ void Instructions::render()
|
|||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
Screen::get()->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void Instructions::reloadTextures()
|
void Instructions::reloadTextures()
|
||||||
{
|
{
|
||||||
for (auto tex : itemTextures)
|
for (auto &tex : itemTextures)
|
||||||
{
|
{
|
||||||
tex->reLoad();
|
tex->reLoad();
|
||||||
}
|
}
|
||||||
@@ -317,7 +298,7 @@ void Instructions::reloadTextures()
|
|||||||
void Instructions::checkEvents()
|
void Instructions::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
// Comprueba los eventos que hay en la cola
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(eventHandler.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)
|
||||||
@@ -341,7 +322,7 @@ void Instructions::checkEvents()
|
|||||||
void Instructions::checkInput()
|
void Instructions::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (input->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section::name = section::NAME_TITLE;
|
section::name = section::NAME_TITLE;
|
||||||
@@ -350,7 +331,7 @@ void Instructions::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen->checkInput();
|
Screen::get()->checkInput();
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
class Asset;
|
#include <memory>
|
||||||
class Fade;
|
#include "fade.h"
|
||||||
class Input;
|
#include "sprite.h"
|
||||||
class Screen;
|
#include "text.h"
|
||||||
class Sprite;
|
#include "texture.h"
|
||||||
class Text;
|
#include "tiled_bg.h"
|
||||||
class Texture;
|
|
||||||
class Tiledbg;
|
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -33,19 +31,17 @@ class Instructions
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
std::vector<std::unique_ptr<Texture>> itemTextures; // Vector con las texturas de los items
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
std::vector<std::unique_ptr<Sprite>> sprites; // Vector con los sprites de los items
|
||||||
std::vector<Texture *> itemTextures; // Vector con las texturas de los items
|
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||||
std::vector<Sprite *> sprites; // Vector con los sprites de los items
|
std::unique_ptr<Text> text; // Objeto para escribir texto
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
std::unique_ptr<Tiledbg> tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
||||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
||||||
SDL_Texture *texture; // Textura fija con el texto
|
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
JA_Music_t *music; // Musica de fondo
|
||||||
Text *text; // Objeto para escribir texto
|
SDL_Texture *texture; // Textura fija con el texto
|
||||||
Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
Fade *fade; // Objeto para renderizar fades
|
|
||||||
JA_Music_t *music; // Musica de fondo
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
|
|||||||
145
source/logo.cpp
145
source/logo.cpp
@@ -17,16 +17,13 @@
|
|||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
{
|
{
|
||||||
// Copia la dirección de los objetos
|
// Copia la dirección de los objetos
|
||||||
input = Input::get();
|
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||||
screen = Screen::get();
|
|
||||||
asset = Asset::get();
|
|
||||||
SDL_Renderer *renderer = screen->getRenderer();
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = std::make_unique<SDL_Event>();
|
||||||
jailTexture = new Texture(renderer, asset->get("logo_jailgames.png"));
|
jailTexture = std::make_unique<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
|
||||||
sinceTexture = new Texture(renderer, asset->get("logo_since_1998.png"));
|
sinceTexture = std::make_unique<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
|
||||||
sinceSprite = new Sprite((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture);
|
sinceSprite = std::make_unique<Sprite>((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture.get());
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter = 0;
|
counter = 0;
|
||||||
@@ -48,12 +45,12 @@ Logo::Logo()
|
|||||||
// Crea los sprites de cada linea
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < jailTexture->getHeight(); ++i)
|
for (int i = 0; i < jailTexture->getHeight(); ++i)
|
||||||
{
|
{
|
||||||
Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture);
|
auto temp = std::make_unique<Sprite>(0, i, jailTexture->getWidth(), 1, jailTexture.get());
|
||||||
temp->setSpriteClip(0, i, jailTexture->getWidth(), 1);
|
temp->setSpriteClip(0, i, jailTexture->getWidth(), 1);
|
||||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jailTexture->getWidth() - (i * 3);
|
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jailTexture->getWidth() - (i * 3);
|
||||||
temp->setPosX(posX);
|
temp->setPosX(posX);
|
||||||
temp->setPosY(dest.y + i);
|
temp->setPosY(dest.y + i);
|
||||||
jailSprite.push_back(temp);
|
jailSprite.push_back(std::move(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
@@ -67,18 +64,6 @@ Logo::Logo()
|
|||||||
color.push_back({0xFF, 0xFF, 0xFF}); // Bright white
|
color.push_back({0xFF, 0xFF, 0xFF}); // Bright white
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Logo::~Logo()
|
|
||||||
{
|
|
||||||
for (auto sprite : jailSprite)
|
|
||||||
{
|
|
||||||
delete sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete sinceSprite;
|
|
||||||
delete eventHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void Logo::reloadTextures()
|
void Logo::reloadTextures()
|
||||||
{
|
{
|
||||||
@@ -90,7 +75,7 @@ void Logo::reloadTextures()
|
|||||||
void Logo::checkEvents()
|
void Logo::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
// Comprueba los eventos que hay en la cola
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(eventHandler.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)
|
||||||
@@ -114,7 +99,7 @@ void Logo::checkEvents()
|
|||||||
void Logo::checkInput()
|
void Logo::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (input->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section::name = section::NAME_TITLE;
|
section::name = section::NAME_TITLE;
|
||||||
@@ -123,7 +108,7 @@ void Logo::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen->checkInput();
|
Screen::get()->checkInput();
|
||||||
|
|
||||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
@@ -162,91 +147,29 @@ void Logo::updateJAILGAMES()
|
|||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
void Logo::updateTextureColors()
|
void Logo::updateTextureColors()
|
||||||
{
|
{
|
||||||
const int inc = 4;
|
constexpr int inc = 4;
|
||||||
|
|
||||||
if (counter <= showSinceSprite_cm + inc * 0)
|
// Manejo de 'sinceTexture'
|
||||||
{
|
for (int i = 0; i <= 7; ++i)
|
||||||
sinceTexture->setColor(color[0].r, color[0].g, color[0].b);
|
{
|
||||||
}
|
if (counter == showSinceSprite_cm + inc * i)
|
||||||
|
{
|
||||||
|
sinceTexture->setColor(color[i].r, color[i].g, color[i].b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 1)
|
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
|
||||||
{
|
for (int i = 0; i <= 6; ++i)
|
||||||
sinceTexture->setColor(color[1].r, color[1].g, color[1].b);
|
{
|
||||||
}
|
if (counter == initFade_cm + inc * i)
|
||||||
|
{
|
||||||
else if (counter == showSinceSprite_cm + inc * 2)
|
jailTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b);
|
||||||
{
|
sinceTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b);
|
||||||
sinceTexture->setColor(color[2].r, color[2].g, color[2].b);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 3)
|
|
||||||
{
|
|
||||||
sinceTexture->setColor(color[3].r, color[3].g, color[3].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 4)
|
|
||||||
{
|
|
||||||
sinceTexture->setColor(color[4].r, color[4].g, color[4].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 5)
|
|
||||||
{
|
|
||||||
sinceTexture->setColor(color[5].r, color[5].g, color[5].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 6)
|
|
||||||
{
|
|
||||||
sinceTexture->setColor(color[6].r, color[6].g, color[6].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == showSinceSprite_cm + inc * 7)
|
|
||||||
{
|
|
||||||
sinceTexture->setColor(color[7].r, color[7].g, color[7].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 0)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[6].r, color[6].g, color[6].b);
|
|
||||||
sinceTexture->setColor(color[6].r, color[6].g, color[6].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 1)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[5].r, color[5].g, color[5].b);
|
|
||||||
sinceTexture->setColor(color[5].r, color[5].g, color[5].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 2)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[4].r, color[4].g, color[4].b);
|
|
||||||
sinceTexture->setColor(color[4].r, color[4].g, color[4].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 3)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[3].r, color[3].g, color[3].b);
|
|
||||||
sinceTexture->setColor(color[3].r, color[3].g, color[3].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 4)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[2].r, color[2].g, color[2].b);
|
|
||||||
sinceTexture->setColor(color[2].r, color[2].g, color[2].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 5)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[1].r, color[1].g, color[1].b);
|
|
||||||
sinceTexture->setColor(color[1].r, color[1].g, color[1].b);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter == initFade_cm + inc * 6)
|
|
||||||
{
|
|
||||||
jailTexture->setColor(color[0].r, color[0].g, color[0].b);
|
|
||||||
sinceTexture->setColor(color[0].r, color[0].g, color[0].b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void Logo::update()
|
void Logo::update()
|
||||||
{
|
{
|
||||||
@@ -257,7 +180,7 @@ void Logo::update()
|
|||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
screen->update();
|
Screen::get()->update();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -289,20 +212,20 @@ void Logo::update()
|
|||||||
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();
|
Screen::get()->clean();
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
for (auto sprite : jailSprite)
|
for (auto &sprite : jailSprite)
|
||||||
{
|
{
|
||||||
sprite->render();
|
sprite->render();
|
||||||
}
|
}
|
||||||
sinceSprite->render();
|
sinceSprite->render();
|
||||||
|
|
||||||
// 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,15 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
#include <SDL2/SDL_rect.h> // for SDL_Point
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for color_t
|
#include <memory>
|
||||||
class Asset;
|
#include "utils.h" // for color_t
|
||||||
class Input;
|
#include "sprite.h"
|
||||||
class Screen;
|
#include "texture.h"
|
||||||
class Sprite;
|
|
||||||
class Texture;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
||||||
@@ -24,14 +22,11 @@ class Logo
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
std::unique_ptr<Texture> sinceTexture; // Textura con los graficos "Since 1998"
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
std::unique_ptr<Sprite> sinceSprite; // Sprite para manejar la sinceTexture
|
||||||
Texture *jailTexture; // Textura con los graficos "JAILGAMES"
|
std::unique_ptr<Texture> jailTexture; // Textura con los graficos "JAILGAMES"
|
||||||
Texture *sinceTexture; // Textura con los graficos "Since 1998"
|
std::vector<std::unique_ptr<Sprite>> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
std::vector<Sprite *> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
|
||||||
Sprite *sinceSprite; // Sprite para manejar la sinceTexture
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<color_t> color; // Vector con los colores para el fade
|
std::vector<color_t> color; // Vector con los colores para el fade
|
||||||
@@ -71,7 +66,7 @@ public:
|
|||||||
Logo();
|
Logo();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Logo();
|
~Logo() = default;
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
@@ -1,34 +1,30 @@
|
|||||||
#include "notify.h"
|
#include "notify.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <string> // for basic_string, char_traits, string
|
#include <string> // for basic_string, char_traits, string
|
||||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile) : renderer(renderer)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->renderer = renderer;
|
|
||||||
bgColor = options.notification.color;
|
bgColor = options.notification.color;
|
||||||
waitTime = 150;
|
waitTime = 150;
|
||||||
stack = false;
|
stack = false;
|
||||||
hasIcons = iconFile == "" ? false : true;
|
hasIcons = iconFile == "" ? false : true;
|
||||||
iconTexture = nullptr;
|
|
||||||
textTexture = nullptr;
|
|
||||||
text = nullptr;
|
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
if (hasIcons)
|
if (hasIcons)
|
||||||
{
|
{
|
||||||
iconTexture = new Texture(renderer, iconFile);
|
iconTexture = std::make_unique<Texture>(renderer, iconFile);
|
||||||
}
|
}
|
||||||
textTexture = new Texture(renderer, bitmapFile);
|
textTexture = std::make_unique<Texture>(renderer, bitmapFile);
|
||||||
text = new Text(textFile, textTexture, renderer);
|
text = std::make_unique<Text>(textFile, textTexture.get());
|
||||||
sound = JA_LoadSound(soundFile.c_str());
|
sound = JA_LoadSound(soundFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,22 +32,9 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
|
|||||||
Notify::~Notify()
|
Notify::~Notify()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
if (textTexture)
|
|
||||||
delete textTexture;
|
|
||||||
|
|
||||||
if (iconTexture)
|
|
||||||
delete iconTexture;
|
|
||||||
|
|
||||||
if (text)
|
|
||||||
delete text;
|
|
||||||
|
|
||||||
JA_DeleteSound(sound);
|
JA_DeleteSound(sound);
|
||||||
|
|
||||||
for (auto notification : notifications)
|
notifications.clear();
|
||||||
{
|
|
||||||
delete notification.sprite;
|
|
||||||
delete notification.texture;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja las notificaciones por pantalla
|
// Dibuja las notificaciones por pantalla
|
||||||
@@ -158,8 +141,6 @@ void Notify::clearFinishedNotifications()
|
|||||||
{
|
{
|
||||||
if (notifications[i].state == ns_finished)
|
if (notifications[i].state == ns_finished)
|
||||||
{
|
{
|
||||||
delete notifications[i].sprite;
|
|
||||||
delete notifications[i].texture;
|
|
||||||
notifications.erase(notifications.begin() + i);
|
notifications.erase(notifications.begin() + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,9 +152,13 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
// Cuenta el número de textos a mostrar
|
// Cuenta el número de textos a mostrar
|
||||||
int numTexts = 0;
|
int numTexts = 0;
|
||||||
if (text1 != "")
|
if (text1 != "")
|
||||||
|
{
|
||||||
numTexts++;
|
numTexts++;
|
||||||
|
}
|
||||||
if (text2 != "")
|
if (text2 != "")
|
||||||
|
{
|
||||||
numTexts++;
|
numTexts++;
|
||||||
|
}
|
||||||
|
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (numTexts == 0)
|
if (numTexts == 0)
|
||||||
@@ -194,8 +179,8 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
const int iconSize = 16;
|
constexpr int iconSize = 16;
|
||||||
const int paddingOut = 1;
|
constexpr int paddingOut = 1;
|
||||||
const int paddingIn = text->getCharacterSize() / 2;
|
const int paddingIn = text->getCharacterSize() / 2;
|
||||||
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
||||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||||
@@ -263,7 +248,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
n.texture = new Texture(renderer);
|
n.texture = std::make_unique<Texture>(renderer);
|
||||||
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
@@ -296,11 +281,10 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
// Dibuja el icono de la notificación
|
// Dibuja el icono de la notificación
|
||||||
if (hasIcons && icon >= 0 && numTexts == 2)
|
if (hasIcons && icon >= 0 && numTexts == 2)
|
||||||
{
|
{
|
||||||
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture);
|
auto sp = std::make_unique<Sprite>((SDL_Rect){0, 0, iconSize, iconSize}, iconTexture.get());
|
||||||
sp->setPos({paddingIn, paddingIn, iconSize, iconSize});
|
sp->setPos({paddingIn, paddingIn, iconSize, iconSize});
|
||||||
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||||
sp->render();
|
sp->render();
|
||||||
delete sp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto de la notificación
|
// Escribe el texto de la notificación
|
||||||
@@ -319,7 +303,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Crea el sprite de la notificación
|
// Crea el sprite de la notificación
|
||||||
n.sprite = new Sprite(n.rect, n.texture);
|
n.sprite = std::make_unique<Sprite>(n.rect, n.texture);
|
||||||
|
|
||||||
// Deja la notificación invisible
|
// Deja la notificación invisible
|
||||||
n.texture->setAlpha(0);
|
n.texture->setAlpha(0);
|
||||||
|
|||||||
@@ -4,15 +4,13 @@
|
|||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <string> // for basic_string, string
|
#include <string> // for basic_string, string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
#include <memory>
|
||||||
#include "utils.h" // for color_t
|
#include "utils.h" // for color_t
|
||||||
class Sprite;
|
#include "text.h"
|
||||||
class Text;
|
#include "texture.h"
|
||||||
class Texture;
|
#include "sprite.h"
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
#ifndef NOTIFY_H
|
|
||||||
#define NOTIFY_H
|
|
||||||
|
|
||||||
class Notify
|
class Notify
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -49,8 +47,8 @@ private:
|
|||||||
int counter;
|
int counter;
|
||||||
notification_state_e state;
|
notification_state_e state;
|
||||||
notification_position_e position;
|
notification_position_e position;
|
||||||
Texture *texture;
|
std::unique_ptr<Texture> texture;
|
||||||
Sprite *sprite;
|
std::unique_ptr<Sprite> sprite;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
int y;
|
int y;
|
||||||
int travelDist;
|
int travelDist;
|
||||||
@@ -59,9 +57,10 @@ private:
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Texture *textTexture; // Textura para la fuente de las notificaciones
|
|
||||||
Texture *iconTexture; // Textura para los iconos de las notificaciones
|
std::unique_ptr<Texture> textTexture; // Textura para la fuente de las notificaciones
|
||||||
Text *text; // Objeto para dibujar texto
|
std::unique_ptr<Texture> iconTexture; // Textura para los iconos de las notificaciones
|
||||||
|
std::unique_ptr<Text> text; // Objeto para dibujar texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
color_t bgColor; // Color de fondo de las notificaciones
|
color_t bgColor; // Color de fondo de las notificaciones
|
||||||
@@ -96,5 +95,3 @@ public:
|
|||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool active();
|
bool active();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||||
{
|
{
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
playerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[0], "", animations[0]));
|
playerSprite = std::make_unique<AnimatedSprite>(texture[0], "", animations[0]);
|
||||||
powerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[1], "", animations[1]));
|
powerSprite = std::make_unique<AnimatedSprite>(texture[1], "", animations[1]);
|
||||||
powerSprite->getTexture()->setAlpha(224);
|
powerSprite->getTexture()->setAlpha(224);
|
||||||
enterName = std::unique_ptr<EnterName>(new EnterName());
|
enterName = std::make_unique<EnterName>();
|
||||||
|
|
||||||
// Rectangulo con la zona de juego
|
// Rectangulo con la zona de juego
|
||||||
this->playArea = playArea;
|
this->playArea = playArea;
|
||||||
|
|||||||
@@ -95,15 +95,15 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
texture = new Texture(renderer, bitmapFile);
|
texture = std::make_unique<Texture>(renderer, bitmapFile);
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
|
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture.get());
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
fixedWidth = false;
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
|
Text::Text(std::string textFile, Texture *texture)
|
||||||
{
|
{
|
||||||
// Carga los offsets desde el fichero
|
// Carga los offsets desde el fichero
|
||||||
textFile_t tf = LoadTextFile(textFile);
|
textFile_t tf = LoadTextFile(textFile);
|
||||||
@@ -119,15 +119,14 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
this->texture = nullptr;
|
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight});
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
fixedWidth = false;
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
Text::Text(textFile_t *textFile, Texture *texture)
|
||||||
{
|
{
|
||||||
// Inicializa variables desde la estructura
|
// Inicializa variables desde la estructura
|
||||||
boxHeight = textFile->boxHeight;
|
boxHeight = textFile->boxHeight;
|
||||||
@@ -140,23 +139,12 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
this->texture = nullptr;
|
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight});
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture);
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
fixedWidth = false;
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Text::~Text()
|
|
||||||
{
|
|
||||||
delete sprite;
|
|
||||||
if (texture != nullptr)
|
|
||||||
{
|
|
||||||
delete texture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe texto en pantalla
|
// Escribe texto en pantalla
|
||||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
@@ -259,7 +247,7 @@ int Text::lenght(std::string text, int kerning)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int Text::getCharacterSize()
|
int Text::getCharacterSize() const
|
||||||
{
|
{
|
||||||
return boxWidth;
|
return boxWidth;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
|
#include <memory>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
class Sprite; // lines 6-6
|
#include "sprite.h"
|
||||||
class Texture; // lines 7-7
|
#include "texture.h"
|
||||||
|
|
||||||
#define TXT_COLOR 1
|
#define TXT_COLOR 1
|
||||||
#define TXT_SHADOW 2
|
#define TXT_SHADOW 2
|
||||||
@@ -14,9 +15,7 @@ class Texture; // lines 7-7
|
|||||||
|
|
||||||
struct offset_t
|
struct offset_t
|
||||||
{
|
{
|
||||||
int x;
|
int x, y, w;
|
||||||
int y;
|
|
||||||
int w;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct textFile_t
|
struct textFile_t
|
||||||
@@ -34,8 +33,8 @@ class Text
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Sprite *sprite; // Objeto con los graficos para el texto
|
std::unique_ptr<Sprite> sprite; // Objeto con los graficos para el texto
|
||||||
Texture *texture; // Textura con los bitmaps del texto
|
std::unique_ptr<Texture> texture; // Textura con los bitmaps del texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
@@ -46,11 +45,11 @@ private:
|
|||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||||
Text(std::string textFile, Texture *texture, SDL_Renderer *renderer);
|
Text(std::string textFile, Texture *texture);
|
||||||
Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer);
|
Text(textFile_t *textFile, Texture *texture);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Text();
|
~Text() = default;
|
||||||
|
|
||||||
// Escribe el texto en pantalla
|
// Escribe el texto en pantalla
|
||||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||||
@@ -71,7 +70,7 @@ public:
|
|||||||
int lenght(std::string text, int kerning = 1);
|
int lenght(std::string text, int kerning = 1);
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int getCharacterSize();
|
int getCharacterSize() const;
|
||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture();
|
||||||
|
|||||||
Reference in New Issue
Block a user