commit de anar a dormir

This commit is contained in:
2024-10-09 23:01:44 +02:00
parent f2fa216b0d
commit 3fa5b227ae
17 changed files with 59 additions and 74 deletions

View File

@@ -7,8 +7,8 @@
#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
// Constructor
DefineButtons::DefineButtons(Text *text)
: text(text)
DefineButtons::DefineButtons(std::unique_ptr<Text> text)
: text(std::move(text))
{
// Copia punteros a los objetos
input = Input::get();
@@ -54,14 +54,6 @@ DefineButtons::DefineButtons(Text *text)
}
}
// Actualiza las variables del objeto
void DefineButtons::update()
{
if (enabled)
{
}
}
// Dibuja el objeto en pantalla
void DefineButtons::render()
{

View File

@@ -5,7 +5,8 @@
#include <string> // for string, basic_string
#include <vector> // for vector
#include "input.h" // for inputs_e
class Text;
#include "text.h"
#include <memory>
struct db_button_t
{
@@ -20,7 +21,7 @@ class DefineButtons
private:
// Objetos
Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para escribir texto
std::shared_ptr<Text> text; // Objeto para escribir texto
// Variables
bool enabled; // Indica si el objeto está habilitado
@@ -45,14 +46,11 @@ private:
public:
// Constructor
DefineButtons(Text *text);
DefineButtons(std::unique_ptr<Text> text);
// Destructor
~DefineButtons() = default;
// Actualiza las variables del objeto
void update();
// Dibuja el objeto en pantalla
void render();

View File

@@ -41,7 +41,7 @@ void Explosions::addTexture(int size, std::shared_ptr<Texture> texture, std::vec
{
explosion_texture_t temp;
temp.size = size;
temp.texture = texture.get();
temp.texture = texture;
temp.animation = animation;
textures.push_back(temp);
}

View File

@@ -8,7 +8,7 @@
struct explosion_texture_t
{
Texture *texture; // Textura para la explosión
std::shared_ptr<Texture>texture; // Textura para la explosión
std::vector<std::string> *animation; // Animación para la textura
int size; // Tamaño de la explosión
};

View File

@@ -16,18 +16,18 @@ GameLogo::GameLogo(int x, int y)
: x(x), y(y)
{
// Crea los objetos
dustTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
coffeeTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
crisisTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
arcadeEditionTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
dustTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
coffeeTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
crisisTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
arcadeEditionTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture.get());
crisisSprite = std::make_unique<SmartSprite>(crisisTexture.get());
coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture);
crisisSprite = std::make_unique<SmartSprite>(crisisTexture);
arcadeEditionSprite = std::make_unique<Sprite>((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture.get());
arcadeEditionSprite = std::make_unique<Sprite>((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture);
dustLSprite = std::make_unique<AnimatedSprite>(dustTexture.get(), Asset::get()->get("title_dust.ani"));
dustRSprite = std::make_unique<AnimatedSprite>(dustTexture.get(), Asset::get()->get("title_dust.ani"));
dustLSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
dustRSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
// Sonidos
crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str());

View File

@@ -15,10 +15,10 @@ class GameLogo
{
private:
// Objetos y punteros
std::unique_ptr<Texture> dustTexture; // Textura con los graficos del polvo
std::unique_ptr<Texture> coffeeTexture; // Textura con los graficos de la palabra "COFFEE"
std::unique_ptr<Texture> crisisTexture; // Textura con los graficos de la plabra "CRISIS"
std::unique_ptr<Texture> arcadeEditionTexture; // Textura con los graficos de "Arcade Edition"
std::shared_ptr<Texture> dustTexture; // Textura con los graficos del polvo
std::shared_ptr<Texture> coffeeTexture; // Textura con los graficos de la palabra "COFFEE"
std::shared_ptr<Texture> crisisTexture; // Textura con los graficos de la plabra "CRISIS"
std::shared_ptr<Texture> arcadeEditionTexture; // Textura con los graficos de "Arcade Edition"
std::unique_ptr<AnimatedSprite> dustLSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
std::unique_ptr<AnimatedSprite> dustRSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo

View File

@@ -80,25 +80,25 @@ Instructions::~Instructions()
void Instructions::iniSprites()
{
// Inicializa las texturas
auto item1 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points1_disk.png"));
itemTextures.push_back(std::move(item1));
auto item1 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points1_disk.png"));
itemTextures.push_back(item1);
auto item2 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points2_gavina.png"));
itemTextures.push_back(std::move(item2));
auto item2 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points2_gavina.png"));
itemTextures.push_back(item2);
auto item3 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points3_pacmar.png"));
itemTextures.push_back(std::move(item3));
auto item3 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points3_pacmar.png"));
itemTextures.push_back(item3);
auto item4 = std::make_unique<Texture>(renderer, Asset::get()->get("item_clock.png"));
itemTextures.push_back(std::move(item4));
auto item4 = std::make_shared<Texture>(renderer, Asset::get()->get("item_clock.png"));
itemTextures.push_back(item4);
auto item5 = std::make_unique<Texture>(renderer, Asset::get()->get("item_coffee.png"));
itemTextures.push_back(std::move(item5));
auto item5 = std::make_shared<Texture>(renderer, Asset::get()->get("item_coffee.png"));
itemTextures.push_back(item5);
// Inicializa los sprites
for (int i = 0; i < (int)itemTextures.size(); ++i)
{
auto sprite = std::make_unique<Sprite>(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i].get());
auto sprite = std::make_unique<Sprite>(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i]);
sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)});
sprites.push_back(std::move(sprite));
}

View File

@@ -31,7 +31,7 @@ class Instructions
{
private:
// Objetos y punteros
std::vector<std::unique_ptr<Texture>> itemTextures; // Vector con las texturas de los items
std::vector<std::shared_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

View File

@@ -20,10 +20,9 @@ Logo::Logo()
SDL_Renderer *renderer = Screen::get()->getRenderer();
// Reserva memoria para los punteros
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());
jailTexture = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
sinceTexture = std::make_shared<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);
// Inicializa variables
counter = 0;
@@ -45,7 +44,7 @@ Logo::Logo()
// Crea los sprites de cada linea
for (int i = 0; i < jailTexture->getHeight(); ++i)
{
auto temp = std::make_unique<Sprite>(0, i, jailTexture->getWidth(), 1, jailTexture.get());
auto temp = std::make_unique<Sprite>(0, i, jailTexture->getWidth(), 1, jailTexture);
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);
@@ -74,20 +73,21 @@ void Logo::reloadTextures()
// Comprueba el manejador de eventos
void Logo::checkEvents()
{
SDL_Event event;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler.get()) != 0)
while (SDL_PollEvent(&event))
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
if (event.type == SDL_QUIT)
{
section::name = section::NAME_QUIT;
break;
}
// Comprueba si se ha cambiado el tamaño de la ventana
else if (eventHandler->type == SDL_WINDOWEVENT)
else if (event.type == SDL_WINDOWEVENT)
{
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
reloadTextures();
}

View File

@@ -22,10 +22,9 @@ class Logo
{
private:
// Objetos y punteros
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
std::unique_ptr<Texture> sinceTexture; // Textura con los graficos "Since 1998"
std::shared_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::shared_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

View File

@@ -92,17 +92,17 @@ void OnScreenHelp::render()
void OnScreenHelp::fillTexture()
{
// Cambia el renderizador a la textura
SDL_Texture *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
// Crea el objeto para el texto
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
// Crea la textura con los gráficos
auto controllersTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
auto controllersTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
// Crea el sprite para dibujar los gráficos
auto sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, 16, 16}, controllersTexture.get());
auto sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, 16, 16}, controllersTexture);
// Borra la textura
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);

View File

@@ -3,8 +3,9 @@
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Texture
#include <vector> // for vector
class Sprite; // lines 10-10
class Text;
#include <memory>
#include "sprite.h" // lines 10-10
#include "text.h"
enum class OnScreenHelpStatus
{

View File

@@ -232,15 +232,13 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
// Reinicia los shaders
if (options.video.shaders)
{
#ifdef SHADERS
std::ifstream f(asset->get("crtpi.glsl").c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
shader::init(window, shaderCanvas, source.c_str());
#endif
}
// Actualiza variables
// shakeEffect.originalPos = srcrect.x;
// shakeEffect.originalWidth = srcrect.w;
}
// Camibia entre pantalla completa y ventana

View File

@@ -95,8 +95,8 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
}
// Crea los objetos
texture = std::make_unique<Texture>(renderer, bitmapFile);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture.get());
texture = std::make_shared<Texture>(renderer, bitmapFile);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture);
// Inicializa variables
fixedWidth = false;

View File

@@ -34,7 +34,7 @@ class Text
private:
// Objetos y punteros
std::unique_ptr<Sprite> sprite; // Objeto con los graficos para el texto
std::unique_ptr<Texture> texture; // Textura con los bitmaps del texto
std::shared_ptr<Texture> texture; // Textura con los bitmaps del texto
// Variables
int boxWidth; // Anchura de la caja de cada caracter en el png

View File

@@ -35,15 +35,15 @@ Title::Title(JA_Music_t *music)
text1->setPalette(1);
text2 = std::make_unique<Text>(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
miniLogoTexture = std::make_unique<Texture>(renderer, asset->get("logo_jailgames_mini.png"));
miniLogoSprite = std::make_unique<Sprite>(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture.get());
miniLogoTexture = std::make_shared<Texture>(renderer, asset->get("logo_jailgames_mini.png"));
miniLogoSprite = std::make_unique<Sprite>(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture);
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 = std::make_unique<GameLogo>(param.game.gameArea.centerX, param.title.titleCCPosition);
gameLogo->enable();
defineButtons = std::make_unique<DefineButtons>(text2.get());
defineButtons = std::make_unique<DefineButtons>(std::move(text2));
// Inicializa los valores
init();
@@ -78,9 +78,6 @@ void Title::update()
// Actualiza el objeto screen
screen->update();
// Actualiza el objeto 'defineButtons'
defineButtons->update();
// Comprueba el fade y si se ha acabado
fade->update();
if (fade->hasEnded())

View File

@@ -52,7 +52,7 @@ private:
std::unique_ptr<Tiledbg> tiledbg; // Objeto para dibujar el mosaico animado de fondo
std::unique_ptr<GameLogo> gameLogo; // Objeto para dibujar el logo con el título del juego
std::unique_ptr<DefineButtons> defineButtons; // Objeto para definir los botones del joystic
std::unique_ptr<Texture> miniLogoTexture; // Textura con el logo de JailGames mini
std::shared_ptr<Texture> miniLogoTexture; // Textura con el logo de JailGames mini
std::unique_ptr<Sprite> miniLogoSprite; // Sprite con el logo de JailGames mini
std::unique_ptr<Text> text1; // Objeto de texto para poder escribir textos en pantalla