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 #include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
// Constructor // Constructor
DefineButtons::DefineButtons(Text *text) DefineButtons::DefineButtons(std::unique_ptr<Text> text)
: text(text) : text(std::move(text))
{ {
// Copia punteros a los objetos // Copia punteros a los objetos
input = Input::get(); 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 // Dibuja el objeto en pantalla
void DefineButtons::render() void DefineButtons::render()
{ {

View File

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

View File

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

View File

@@ -8,7 +8,7 @@
struct explosion_texture_t 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 std::vector<std::string> *animation; // Animación para la textura
int size; // Tamaño de la explosión int size; // Tamaño de la explosión
}; };

View File

@@ -16,18 +16,18 @@ GameLogo::GameLogo(int x, int y)
: x(x), y(y) : x(x), y(y)
{ {
// Crea los objetos // Crea los objetos
dustTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png")); dustTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
coffeeTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png")); coffeeTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
crisisTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png")); crisisTexture = std::make_shared<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")); arcadeEditionTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture.get()); coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture);
crisisSprite = std::make_unique<SmartSprite>(crisisTexture.get()); 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")); dustLSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
dustRSprite = std::make_unique<AnimatedSprite>(dustTexture.get(), Asset::get()->get("title_dust.ani")); dustRSprite = std::make_unique<AnimatedSprite>(dustTexture, Asset::get()->get("title_dust.ani"));
// Sonidos // Sonidos
crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str()); crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str());

View File

@@ -15,10 +15,10 @@ class GameLogo
{ {
private: private:
// Objetos y punteros // Objetos y punteros
std::unique_ptr<Texture> dustTexture; // Textura con los graficos del polvo std::shared_ptr<Texture> dustTexture; // Textura con los graficos del polvo
std::unique_ptr<Texture> coffeeTexture; // Textura con los graficos de la palabra "COFFEE" std::shared_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::shared_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> 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> 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 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() void Instructions::iniSprites()
{ {
// Inicializa las texturas // Inicializa las texturas
auto item1 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points1_disk.png")); auto item1 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points1_disk.png"));
itemTextures.push_back(std::move(item1)); itemTextures.push_back(item1);
auto item2 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points2_gavina.png")); auto item2 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points2_gavina.png"));
itemTextures.push_back(std::move(item2)); itemTextures.push_back(item2);
auto item3 = std::make_unique<Texture>(renderer, Asset::get()->get("item_points3_pacmar.png")); auto item3 = std::make_shared<Texture>(renderer, Asset::get()->get("item_points3_pacmar.png"));
itemTextures.push_back(std::move(item3)); itemTextures.push_back(item3);
auto item4 = std::make_unique<Texture>(renderer, Asset::get()->get("item_clock.png")); auto item4 = std::make_shared<Texture>(renderer, Asset::get()->get("item_clock.png"));
itemTextures.push_back(std::move(item4)); itemTextures.push_back(item4);
auto item5 = std::make_unique<Texture>(renderer, Asset::get()->get("item_coffee.png")); auto item5 = std::make_shared<Texture>(renderer, Asset::get()->get("item_coffee.png"));
itemTextures.push_back(std::move(item5)); itemTextures.push_back(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)
{ {
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)}); sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)});
sprites.push_back(std::move(sprite)); sprites.push_back(std::move(sprite));
} }

View File

@@ -31,7 +31,7 @@ class Instructions
{ {
private: private:
// Objetos y punteros // 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::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<SDL_Event> eventHandler; // Manejador de eventos
std::unique_ptr<Text> text; // Objeto para escribir texto std::unique_ptr<Text> text; // Objeto para escribir texto

View File

@@ -20,10 +20,9 @@ Logo::Logo()
SDL_Renderer *renderer = Screen::get()->getRenderer(); SDL_Renderer *renderer = Screen::get()->getRenderer();
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = std::make_unique<SDL_Event>(); jailTexture = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
jailTexture = std::make_unique<Texture>(renderer, Asset::get()->get("logo_jailgames.png")); sinceTexture = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.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);
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;
@@ -45,7 +44,7 @@ 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)
{ {
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); 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);
@@ -74,20 +73,21 @@ void Logo::reloadTextures()
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void Logo::checkEvents() void Logo::checkEvents()
{ {
SDL_Event event;
// Comprueba los eventos que hay en la cola // 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 // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::NAME_QUIT;
break; break;
} }
// Comprueba si se ha cambiado el tamaño de la ventana // 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(); reloadTextures();
} }

View File

@@ -22,10 +22,9 @@ class Logo
{ {
private: private:
// Objetos y punteros // Objetos y punteros
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos std::shared_ptr<Texture> sinceTexture; // Textura con los graficos "Since 1998"
std::unique_ptr<Texture> sinceTexture; // Textura con los graficos "Since 1998"
std::unique_ptr<Sprite> sinceSprite; // Sprite para manejar la sinceTexture 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 std::vector<std::unique_ptr<Sprite>> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
// Variables // Variables

View File

@@ -92,17 +92,17 @@ void OnScreenHelp::render()
void OnScreenHelp::fillTexture() void OnScreenHelp::fillTexture()
{ {
// Cambia el renderizador a la textura // 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); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
// Crea el objeto para el texto // 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()); 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 // 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 // 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 // Borra la textura
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); 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_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture
#include <vector> // for vector #include <vector> // for vector
class Sprite; // lines 10-10 #include <memory>
class Text; #include "sprite.h" // lines 10-10
#include "text.h"
enum class OnScreenHelpStatus enum class OnScreenHelpStatus
{ {

View File

@@ -232,15 +232,13 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
// Reinicia los shaders // Reinicia los shaders
if (options.video.shaders) if (options.video.shaders)
{ {
#ifdef SHADERS
std::ifstream f(asset->get("crtpi.glsl").c_str()); std::ifstream f(asset->get("crtpi.glsl").c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
shader::init(window, shaderCanvas, source.c_str()); shader::init(window, shaderCanvas, source.c_str());
#endif
} }
// Actualiza variables
// shakeEffect.originalPos = srcrect.x;
// shakeEffect.originalWidth = srcrect.w;
} }
// Camibia entre pantalla completa y ventana // 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 // Crea los objetos
texture = std::make_unique<Texture>(renderer, bitmapFile); texture = std::make_shared<Texture>(renderer, bitmapFile);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture.get()); sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture);
// Inicializa variables // Inicializa variables
fixedWidth = false; fixedWidth = false;

View File

@@ -34,7 +34,7 @@ class Text
private: private:
// Objetos y punteros // Objetos y punteros
std::unique_ptr<Sprite> sprite; // Objeto con los graficos para el texto 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 // 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

View File

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