Compare commits

8 Commits

20 changed files with 318 additions and 297 deletions

View File

@@ -3,6 +3,9 @@
cmake_minimum_required(VERSION 3.10)
project(coffee_crisis_arcade_edition VERSION 0.01)
# Establece las políticas
cmake_policy(SET CMP0072 NEW)
# Configuración de compilador para MinGW en Windows, si es necesario
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_COMPILER "g++")

View File

@@ -11,7 +11,7 @@ Coffee Crisis Arcade Edition és una versió ampliada i millorada del aclamat Co
Defensa el teu cafè contra les bambolles gegants en aquest trepidant joc d'arcade! 🍵
<p align="center">
<img src="https://php.sustancia.synology.me/images/ccae_title.png" alt="Títol" width="60%" />
<img src="https://php.sustancia.synology.me/images/ccae/ccae_title.png" alt="Títol" width="60%" />
</p>
## Controls
@@ -25,8 +25,8 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
> Nota: El joc suporta nomes un jugador amb teclat.
<p align="center">
<img src="https://php.sustancia.synology.me/images/ccae1.png" alt="Joc" width="45%" />
<img src="https://php.sustancia.synology.me/images/ccae3.png" alt="Joc" width="45%" />
<img src="https://php.sustancia.synology.me/images/ccae/ccae1.png" alt="Joc" width="45%" />
<img src="https://php.sustancia.synology.me/images/ccae/ccae3.png" alt="Joc" width="45%" />
</p>
## Altres tecles
@@ -44,7 +44,7 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
| **F10** | Reset del joc |
<p align="center">
<img src="https://php.sustancia.synology.me/images/ccae2.png" alt="Joc" width="50%" />
<img src="https://php.sustancia.synology.me/images/ccae/ccae2.png" alt="Joc" width="50%" />
</p>
## Com instal·lar i jugar

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -56,13 +56,13 @@ private:
~Asset() = default;
public:
// [SINGLETON] Crearemos el objeto screen con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
static void init(const std::string &executable_path);
// [SINGLETON] Destruiremos el objeto screen con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Asset *get();
// Añade un elemento a la lista

View File

@@ -316,12 +316,10 @@ bool Director::initSDL()
std::cout << "Warning: texture filtering not enabled!\n";
}
#ifndef NO_SHADERS
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
{
std::cout << "Warning: opengl not enabled!\n";
}
#endif
// Crea la ventana
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
@@ -339,10 +337,8 @@ bool Director::initSDL()
flags = SDL_RENDERER_PRESENTVSYNC;
}
#ifndef NO_SHADERS
// La aceleración se activa según el define
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
#endif
renderer_ = SDL_CreateRenderer(window_, -1, flags);
@@ -484,6 +480,7 @@ void Director::setFileList()
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
Asset::get()->add(prefix + "/data/gfx/logo/logo_retroweekend.png", AssetType::BITMAP);
}
{ // Items

View File

@@ -9,22 +9,22 @@
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
#include <utility> // Para pair
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
// [SINGLETON]
Input *Input::input_ = nullptr;
// [SINGLETON] Crearemos el objeto input con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
void Input::init(const std::string &game_controller_db_path)
{
Input::input_ = new Input(game_controller_db_path);
}
// [SINGLETON] Destruiremos el objeto input con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
void Input::destroy()
{
delete Input::input_;
}
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Input *Input::get()
{
return Input::input_;

View File

@@ -64,7 +64,7 @@ enum class InputDeviceToUse : int
class Input
{
private:
// [SINGLETON] Objeto screen privado para Don Melitón
// [SINGLETON] Objeto privado
static Input *input_;
struct KeyBindings
@@ -109,13 +109,13 @@ private:
~Input() = default;
public:
// [SINGLETON] Crearemos el objeto screen con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
static void init(const std::string &game_controller_db_path);
// [SINGLETON] Destruiremos el objeto screen con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Input *get();
// Asigna inputs a teclas

View File

@@ -1,5 +1,3 @@
#ifndef NO_SHADERS
#include "jail_shader.h"
#include <SDL2/SDL_rect.h> // para SDL_Point
#include <stdlib.h> // para NULL, free, malloc, exit
@@ -248,4 +246,3 @@ namespace shader
}
}
}
#endif

View File

@@ -1,5 +1,3 @@
#ifndef NO_SHADERS
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Texture
@@ -45,4 +43,3 @@ namespace shader
void render();
}
#endif

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // Para move
#include <iostream>
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "jail_audio.h" // Para JA_StopMusic
@@ -19,8 +20,7 @@
Logo::Logo()
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
since_sprite_(std::make_unique<Sprite>(since_texture_)),
jail_texture_(Resource::get()->getTexture("logo_jailgames.png")),
ticks_(0)
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
{
// Inicializa variables
@@ -114,7 +114,7 @@ void Logo::checkInput()
globalInputs::check();
}
// Gestiona el logo de JAILGAME
// Gestiona el logo de JAILGAMES
void Logo::updateJAILGAMES()
{
if (counter_ == 30)
@@ -147,6 +147,22 @@ void Logo::updateJAILGAMES()
}
}
}
// Comprueba si ha terminado el logo
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
{
state_ = LogoState::RETROWEEKEND;
ticks_start_ = SDL_GetTicks();
}
}
// Gestiona el logo de RETROWEEKEND
void Logo::updateRETROWEEKEND()
{
if (SDL_GetTicks() >= ticks_start_ + 5000)
{
section::name = section::Name::INTRO;
}
}
// Gestiona el color de las texturas
@@ -190,21 +206,24 @@ void Logo::update()
// Comprueba las entradas
checkInput();
// Gestiona el logo de JAILGAME
updateJAILGAMES();
// Gestiona el color de las texturas
updateTextureColors();
// Gestiona el contador y sus eventos
counter_++;
// Comprueba si ha terminado el logo
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
switch (state_)
{
section::name = section::Name::INTRO;
case LogoState::JAILGAMES:
updateJAILGAMES();
updateTextureColors();
break;
case LogoState::RETROWEEKEND:
updateRETROWEEKEND();
break;
default:
break;
}
// Gestiona el contador
counter_++;
// Actualiza las variables de globalInputs
globalInputs::update();
}
@@ -213,24 +232,23 @@ void Logo::update()
// Dibuja en pantalla
void Logo::render()
{
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clean();
// Dibuja los sprites
for (auto &sprite : jail_sprite_)
switch (state_)
{
sprite->render();
case LogoState::JAILGAMES:
renderJAILGAMES();
break;
case LogoState::RETROWEEKEND:
renderRETROWEEKEND();
break;
default:
break;
}
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
{
since_sprite_->render();
}
// Vuelca el contenido del renderizador en pantalla
Screen::get()->render();
}
@@ -248,3 +266,132 @@ void Logo::run()
render();
}
}
// Renderiza el logo de JAILGAMES
void Logo::renderJAILGAMES()
{
// Dibuja los sprites
for (auto &sprite : jail_sprite_)
{
sprite->render();
}
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
{
since_sprite_->render();
}
}
// Renderiza el logo de RETROWEEKEND
void Logo::renderRETROWEEKEND()
{
// SDL_RenderCopy(Screen::get()->getRenderer(), mi_textura, nullptr, nullptr);
// SDL_RenderCopy(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture(), nullptr, nullptr);
// Dibujar y evaporar los píxeles
renderAndEvaporate(Screen::get()->getRenderer(), pixels_);
}
std::vector<Pixel> Logo::extractPixels(SDL_Texture *texture)
{
std::vector<Pixel> pixels;
// Obtener el formato y tamaño de la textura
Uint32 format;
int access, width, height;
SDL_QueryTexture(texture, &format, &access, &width, &height);
// Imprimir el nombre del formato de la textura
std::cout << "Texture format: " << SDL_GetPixelFormatName(format) << std::endl;
// Crear una superficie temporal para leer los píxeles
SDL_Surface *temp_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, format);
if (!temp_surface)
{
std::cout << "Error: SDL_CreateRGBSurfaceWithFormat failed - " << SDL_GetError() << std::endl;
return pixels;
}
SDL_Renderer *renderer = Screen::get()->getRenderer();
SDL_SetRenderTarget(renderer, nullptr); // Dibujar en pantalla principal
SDL_RenderClear(renderer); // Limpiar pantalla
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
SDL_RenderPresent(renderer); // Mostrar en pantalla
std::cout << "Se ha dibujado la textura en pantalla." << std::endl;
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
{
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
SDL_FreeSurface(temp_surface);
return pixels;
}
else
{
std::cout << "SDL_RenderReadPixels se ejecutó correctamente." << std::endl;
}
// Leer los píxeles de la textura
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
{
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
SDL_FreeSurface(temp_surface);
return pixels;
}
// Extraer los píxeles y almacenarlos en el vector
SDL_PixelFormat *pixel_format = SDL_AllocFormat(format);
Uint8 r, g, b, a;
/*for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
if (a > 0)
{
pixels.push_back({x, y, r, g, b, a});
}
}
}*/
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
// Imprimir algunos píxeles para depuración
if (x < 5 && y < 5)
{
std::cout << "Pixel (" << x << "," << y << ") - RGBA("
<< (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")" << std::endl;
}
// No filtrar por alfa por ahora
pixels.push_back({x, y, r, g, b, a});
}
}
std::cout << "Cantidad de píxeles a renderizar: " << pixels.size() << std::endl;
// Liberar recursos
SDL_FreeFormat(pixel_format);
SDL_FreeSurface(temp_surface);
return pixels;
}
void Logo::renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels)
{
for (auto &pixel : pixels)
{
// Establecer el color para el píxel actual
SDL_SetRenderDrawColor(renderer, pixel.r, pixel.g, pixel.b, pixel.a);
// Dibujar el píxel
SDL_RenderDrawPoint(renderer, pixel.x, pixel.y);
// Evaporar el píxel
// pixel.evaporate();
}
}

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL_rect.h> // Para SDL_Point
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <SDL2/SDL.h>
#include <memory> // Para shared_ptr, unique_ptr
#include <vector> // Para vector
class Sprite;
@@ -16,10 +17,31 @@ struct Color;
ZX Spectrum
*/
struct Pixel
{
int x, y; // Coordenadas del píxel
Uint8 r, g, b, a; // Color del píxel
// Método para ascender y desvanecerse
void evaporate()
{
y -= 1; // Asciende hacia arriba
a = (a > 5) ? a - 5 : 0; // Desvanece el alfa (transparencia)
// Añadir movimiento zig-zag aleatorio
x += (rand() % 3 - 1); // Movimiento horizontal aleatorio (-1, 0, 1)
}
};
// Clase Logo
class Logo
{
private:
enum class LogoState
{
JAILGAMES,
RETROWEEKEND,
};
// Constantes
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
@@ -36,8 +58,11 @@ private:
// Variables
std::vector<Color> color_; // Vector con los colores para el fade
int counter_; // Contador
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_Point dest_; // Posición X donde dibujar el logo
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando
Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL
std::vector<Pixel> pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND"
// Actualiza las variables
void update();
@@ -51,15 +76,28 @@ private:
// Comprueba las entradas
void checkInput();
// Gestiona el logo de JAILGAME
// Gestiona el logo de JAILGAMES
void updateJAILGAMES();
// Gestiona el logo de RETROWEEKEND
void updateRETROWEEKEND();
// Renderiza el logo de JAILGAMES
void renderJAILGAMES();
// Renderiza el logo de RETROWEEKEND
void renderRETROWEEKEND();
// Gestiona el color de las texturas
void updateTextureColors();
// Recarga todas las texturas
void reloadTextures();
std::vector<Pixel> extractPixels(SDL_Texture *texture);
void renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels);
public:
// Constructor
Logo();

View File

@@ -73,46 +73,7 @@ void MovingSprite::update()
}
// Muestra el sprite por pantalla
void MovingSprite::render()
{
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
}
// Establece el valor de la variable
void MovingSprite::setZoomW(float value)
{
zoom_w_ = value;
}
// Establece el valor de la variable
void MovingSprite::setZoomH(float value)
{
zoom_h_ = value;
}
// Establece el valor de la variable
void MovingSprite::setAngle(double value)
{
rotate_.angle = value;
}
// Establece el valor de la variable
void MovingSprite::setRotatingCenter(SDL_Point *point)
{
rotate_.center = point;
}
// Incrementa el valor del ángulo
void MovingSprite::updateAngle()
{
rotate_.angle += rotate_.amount;
}
// Obtiene el valor de la variable
bool MovingSprite::isRotating() const
{
return rotate_.enabled;
}
void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); }
// Establece la rotacion
void MovingSprite::rotate()
@@ -135,43 +96,6 @@ void MovingSprite::setRotate(bool enable)
rotate_.counter = 0;
}
// Establece el valor de la variable
void MovingSprite::setRotateSpeed(int value)
{
rotate_.speed = std::max(1, value);
}
// Establece el valor de la variable
void MovingSprite::setRotateAmount(double value)
{
rotate_.amount = value;
}
// Cambia el sentido de la rotación
void MovingSprite::switchRotate()
{
rotate_.amount *= -1;
}
// Establece el valor de la variable
void MovingSprite::setFlip(SDL_RendererFlip flip)
{
flip_ = flip;
}
// Gira el sprite horizontalmente
void MovingSprite::flip()
{
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
}
// Obtiene el valor de la variable
SDL_RendererFlip MovingSprite::getFlip()
{
return flip_;
}
// Establece la posición y_ el tamaño del objeto
void MovingSprite::setPos(SDL_Rect rect)
{
@@ -204,27 +128,3 @@ void MovingSprite::setPosY(float value)
y_ = value;
pos_.y = static_cast<int>(y_);
}
// Establece el valor de la variable
void MovingSprite::setVelX(float value)
{
vx_ = value;
}
// Establece el valor de la variable
void MovingSprite::setVelY(float value)
{
vy_ = value;
}
// Establece el valor de la variable
void MovingSprite::setAccelX(float value)
{
ax_ = value;
}
// Establece el valor de la variable
void MovingSprite::setAccelY(float value)
{
ay_ = value;
}

View File

@@ -38,7 +38,7 @@ protected:
SDL_RendererFlip flip_; // Indica como se voltea el sprite
// Incrementa el valor del ángulo
void updateAngle();
void updateAngle() { rotate_.angle += rotate_.amount; }
// Mueve el sprite
void move();
@@ -73,40 +73,40 @@ public:
float getAccelY() const { return ay_; }
// Establece la variable
void setVelX(float value);
void setVelY(float value);
void setAccelX(float value);
void setAccelY(float value);
void setVelX(float value) { vx_ = value; }
void setVelY(float value) { vy_ = value; }
void setAccelX(float value) { ax_ = value; }
void setAccelY(float value) { ay_ = value; }
// Obten el valor de la variable
bool isRotating() const;
bool isRotating() const { return rotate_.enabled; }
// Establece el valor de la variable
void setZoomW(float value);
void setZoomH(float value);
void setZoomW(float value) { zoom_w_ = value; }
void setZoomH(float value) { zoom_h_ = value; }
// Establece el valor de la variable
void setAngle(double vaue);
void setRotatingCenter(SDL_Point *point);
void setAngle(double value) { rotate_.angle = value; }
void setRotatingCenter(SDL_Point *point) { rotate_.center = point; }
// Activa o desactiva el efecto de rotación
void setRotate(bool enable);
// Establece el valor de la variable
void setRotateSpeed(int value);
void setRotateAmount(double value);
void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); }
void setRotateAmount(double value) { rotate_.amount = value; }
// Cambia el sentido de la rotación
void switchRotate();
void switchRotate() { rotate_.amount *= -1; }
// Establece el valor de la variable
void setFlip(SDL_RendererFlip flip);
void setFlip(SDL_RendererFlip flip) { flip_ = flip; }
// Gira el sprite horizontalmente
void flip();
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; }
// Obtiene el valor de la variable
SDL_RendererFlip getFlip();
SDL_RendererFlip getFlip() { return flip_; }
// Establece la posición y_ el tamaño del objeto
void setPos(SDL_Rect rect);

View File

@@ -12,22 +12,22 @@
#include "texture.h" // Para Texture
#include "resource.h"
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
// [SINGLETON]
Notifier *Notifier::notifier_ = nullptr;
// [SINGLETON] Crearemos el objeto screen con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
{
Notifier::notifier_ = new Notifier(icon_file, text);
}
// [SINGLETON] Destruiremos el objeto screen con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
void Notifier::destroy()
{
delete Notifier::notifier_;
}
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Notifier *Notifier::get()
{
return Notifier::notifier_;

View File

@@ -13,7 +13,7 @@ class Texture; // lines 11-11
class Notifier
{
private:
// [SINGLETON] Objeto notifier privado para Don Melitón
// [SINGLETON] Objeto notifier
static Notifier *notifier_;
enum class NotificationStatus
@@ -77,13 +77,13 @@ private:
~Notifier() = default;
public:
// [SINGLETON] Crearemos el objeto notifier con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto notifier y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Notifier *get();
// Dibuja las notificaciones por pantalla

View File

@@ -15,27 +15,24 @@
#include "on_screen_help.h" // Para OnScreenHelp
#include "options.h" // Para Options, OptionsVideo, options, Options...
#include "mouse.h"
#ifndef NO_SHADERS
#include "jail_shader.h" // para init, render
#endif
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
// [SINGLETON]
Screen *Screen::screen_ = nullptr;
// [SINGLETON] Crearemos el objeto screen con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
{
Screen::screen_ = new Screen(window, renderer);
}
// [SINGLETON] Destruiremos el objeto screen con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
void Screen::destroy()
{
delete Screen::screen_;
}
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Screen *Screen::get()
{
return Screen::screen_;
@@ -105,11 +102,6 @@ void Screen::renderScreen()
SDL_SetRenderTarget(renderer_, nullptr);
clean();
#ifdef NO_SHADERS
// Actualiza la pantalla con el contenido del buffer de renderizado
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
SDL_RenderPresent(renderer_);
#else
if (options.video.shaders)
{
// Aplica shaders y renderiza el contenido
@@ -121,7 +113,6 @@ void Screen::renderScreen()
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
SDL_RenderPresent(renderer_);
}
#endif
}
// Establece el modo de video
@@ -174,13 +165,11 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
// Reinicia los shaders
if (options.video.shaders)
{
#ifndef NO_SHADERS
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
std::ifstream f(Asset::get()->get(glsl_file).c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
shader::init(window_, game_canvas_, source.c_str());
#endif
}
}
@@ -363,12 +352,6 @@ void Screen::attenuate(bool value)
attenuate_effect_ = value;
}
// Obtiene el puntero al renderizador
SDL_Renderer *Screen::getRenderer()
{
return renderer_;
}
// Calcula los frames por segundo
void Screen::updateFPS()
{

View File

@@ -24,7 +24,7 @@ enum class ScreenVideoMode : int
class Screen
{
private:
// [SINGLETON] Objeto screen privado para Don Melitón
// [SINGLETON] Objeto privado
static Screen *screen_;
// Objetos y punteros
@@ -110,14 +110,9 @@ private:
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
SDL_Point getNewPosition();
// Actualiza la pantalla con el contenido del game_canvas_
void presentGameCanvas();
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
void renderScreen();
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
// Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer);
@@ -125,13 +120,13 @@ private:
~Screen();
public:
// [SINGLETON] Crearemos el objeto screen con esta función estática
// [SINGLETON] Crearemos el objeto con esta función estática
static void init(SDL_Window *window, SDL_Renderer *renderer);
// [SINGLETON] Destruiremos el objeto screen con esta función estática
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Screen *get();
// Actualiza la lógica de la clase
@@ -182,6 +177,6 @@ public:
// Atenua la pantalla
void attenuate(bool value);
// Obtiene el puntero al renderizador
SDL_Renderer *getRenderer();
// Getters
SDL_Renderer *getRenderer() { return renderer_; }
};

View File

@@ -17,22 +17,13 @@ void SmartSprite::update()
}
}
// Establece el valor de la variable
void SmartSprite::setFinishedCounter(int value)
// Dibuja el sprite
void SmartSprite::render()
{
finished_counter_ = value;
if (enabled_)
{
MovingSprite::render();
}
// Establece el valor de la variable
void SmartSprite::setDestX(int x)
{
dest_x_ = x;
}
// Establece el valor de la variable
void SmartSprite::setDestY(int y)
{
dest_y_ = y;
}
// Comprueba el movimiento
@@ -115,21 +106,3 @@ void SmartSprite::checkFinished()
}
}
}
// Obtiene el valor de la variable
bool SmartSprite::isOnDestination() const
{
return on_destination_;
}
// Obtiene el valor de la variable
bool SmartSprite::hasFinished() const
{
return finished_;
}
// Habilita el objeto
void SmartSprite::setEnabled(bool value)
{
enabled_ = value;
}

View File

@@ -32,27 +32,18 @@ public:
// Actualiza la posición y comprueba si ha llegado a su destino
void update() override;
// Establece el valor de la variable
void setFinishedCounter(int value);
// Dibuja el sprite
void render();
// Establece el valor de la variable
void setDestX(int x);
// Getters
int getDestX() const { return dest_x_; }
int getDestY() const { return dest_y_; }
bool isOnDestination() const { return on_destination_; }
bool hasFinished() const { return finished_; }
// Establece el valor de la variable
void setDestY(int y);
// Obtiene el valor de la variable
int getDestX() const;
// Obtiene el valor de la variable
int getDestY() const;
// Obtiene el valor de la variable
bool isOnDestination() const;
// Obtiene el valor de la variable
bool hasFinished() const;
// Habilita el objeto
void setEnabled(bool value);
// Setters
void setFinishedCounter(int value) { finished_counter_ = value; }
void setDestX(int x) { dest_x_ = x; }
void setDestY(int y) { dest_y_ = y; }
void setEnabled(bool value) { enabled_ = value; }
};