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