Transició a surface acabada. Ja compila
This commit is contained in:
@@ -1,269 +0,0 @@
|
||||
#include "animated_sprite.h"
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para printWithDots
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
Animations loadAnimationsFromFile(const std::string &file_path)
|
||||
{
|
||||
std::ifstream file(file_path);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
|
||||
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
|
||||
std::vector<std::string> buffer;
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (!line.empty())
|
||||
buffer.push_back(line);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
||||
: MovingSprite(texture)
|
||||
{
|
||||
// Carga las animaciones
|
||||
if (!file_path.empty())
|
||||
{
|
||||
Animations v = loadAnimationsFromFile(file_path);
|
||||
setAnimations(v);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations)
|
||||
: MovingSprite(texture)
|
||||
{
|
||||
if (!animations.empty())
|
||||
{
|
||||
setAnimations(animations);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(const std::string &name)
|
||||
{
|
||||
auto index = -1;
|
||||
|
||||
for (const auto &a : animations_)
|
||||
{
|
||||
index++;
|
||||
if (a.name == name)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (animations_[current_animation_].speed == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcula el frame actual a partir del contador
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animations_[current_animation_].current_frame >= static_cast<int>(animations_[current_animation_].frames.size()))
|
||||
{
|
||||
if (animations_[current_animation_].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
||||
animations_[current_animation_].completed = true;
|
||||
}
|
||||
else
|
||||
{ // Si hay loop, vuelve al frame indicado
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
{
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
animations_[current_animation_].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool AnimatedSprite::animationIsCompleted()
|
||||
{
|
||||
return animations_[current_animation_].completed;
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||
{
|
||||
const auto new_animation = getIndex(name);
|
||||
if (current_animation_ != new_animation)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(int index)
|
||||
{
|
||||
const auto new_animation = index;
|
||||
if (current_animation_ != new_animation)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void AnimatedSprite::update()
|
||||
{
|
||||
animate();
|
||||
MovingSprite::update();
|
||||
}
|
||||
|
||||
// Reinicia la animación
|
||||
void AnimatedSprite::resetAnimation()
|
||||
{
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void AnimatedSprite::setAnimations(const Animations &animations)
|
||||
{
|
||||
int frame_width = 1;
|
||||
int frame_height = 1;
|
||||
int frames_per_row = 1;
|
||||
int max_tiles = 1;
|
||||
|
||||
size_t index = 0;
|
||||
while (index < animations.size())
|
||||
{
|
||||
std::string line = animations.at(index);
|
||||
|
||||
// Parsea el fichero para buscar variables y valores
|
||||
if (line != "[animation]")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
size_t pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string key = line.substr(0, pos);
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
if (key == "frame_width")
|
||||
frame_width = value;
|
||||
else if (key == "frame_height")
|
||||
frame_height = value;
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
const int w = texture_->getWidth() / frame_width;
|
||||
const int h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
AnimationData animation;
|
||||
do
|
||||
{
|
||||
index++;
|
||||
line = animations.at(index);
|
||||
size_t pos = line.find("=");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1);
|
||||
|
||||
if (key == "name")
|
||||
animation.name = value;
|
||||
else if (key == "speed")
|
||||
animation.speed = std::stoi(value);
|
||||
else if (key == "loop")
|
||||
animation.loop = std::stoi(value);
|
||||
else if (key == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(value);
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
const int num_tile = std::stoi(tmp);
|
||||
if (num_tile <= max_tiles)
|
||||
{
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
animation.frames.emplace_back(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations_.emplace_back(animation);
|
||||
}
|
||||
|
||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||
index++;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setWidth(frame_width);
|
||||
setHeight(frame_height);
|
||||
}
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void AnimatedSprite::setCurrentAnimationFrame(int num)
|
||||
{
|
||||
// Descarta valores fuera de rango
|
||||
if (num < 0 || num >= static_cast<int>(animations_[current_animation_].frames.size()))
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
|
||||
// Cambia el valor de la variable
|
||||
animations_[current_animation_].current_frame = num;
|
||||
animations_[current_animation_].counter = 0;
|
||||
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
class Texture; // lines 9-9
|
||||
|
||||
struct AnimationData
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||
int speed; // Velocidad de la animación
|
||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int current_frame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
|
||||
AnimationData() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||
};
|
||||
|
||||
using Animations = std::vector<std::string>;
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
Animations loadAnimationsFromFile(const std::string &file_path);
|
||||
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
protected:
|
||||
// Variables
|
||||
std::vector<AnimationData> animations_; // Vector con las diferentes animaciones
|
||||
int current_animation_ = 0; // Animacion activa
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void setAnimations(const Animations &animations);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations);
|
||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture)
|
||||
: MovingSprite(texture) {}
|
||||
|
||||
// Destructor
|
||||
virtual ~AnimatedSprite() = default;
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(const std::string &name);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(const std::string &name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentAnimationFrame(int num);
|
||||
|
||||
// Obtiene el numero de frames de la animación actual
|
||||
int getCurrentAnimationSize() { return static_cast<int>(animations_[current_animation_].frames.size()); }
|
||||
};
|
||||
@@ -143,7 +143,7 @@ void Credits::fillTexture()
|
||||
|
||||
// Rellena la textura de texto
|
||||
Screen::get()->setRenderSurfaceData(text_surface_);
|
||||
Screen::get()->clean(stringToColor("black"));
|
||||
Screen::get()->clear(stringToColor("black"));
|
||||
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
|
||||
@@ -164,12 +164,11 @@ void Credits::fillTexture()
|
||||
|
||||
// Recoloca el sprite del brillo
|
||||
shining_sprite_->setPosX(POS_X + 2);
|
||||
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
Screen::get()->setRenderSurfaceData(text_surface_);
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
@@ -253,7 +252,7 @@ void Credits::render()
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(1);
|
||||
Screen::get()->clear(1);
|
||||
|
||||
if (counter_ < 1150)
|
||||
{
|
||||
|
||||
@@ -48,5 +48,7 @@ constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
|
||||
// Colores
|
||||
const Color borderColor = {0x27, 0x27, 0x36};
|
||||
const Color black = {0xFF, 0xFF, 0xFF};
|
||||
// const Color borderColor = {0x27, 0x27, 0x36};
|
||||
const Uint8 border_color = 1;
|
||||
// const Color black = {0xFF, 0xFF, 0xFF};
|
||||
const Uint8 black_color = 1;
|
||||
|
||||
@@ -76,7 +76,7 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
// Crea los objetos
|
||||
Screen::init(window_, renderer_);
|
||||
Screen::get()->setBorderColor(borderColor);
|
||||
Screen::get()->setBorderColor(border_color);
|
||||
Resource::init();
|
||||
Notifier::init("notify.gif", "8bithud");
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
@@ -139,7 +139,6 @@ std::string Director::checkProgramArguments(int argc, const char *argv[])
|
||||
return argv[0];
|
||||
}
|
||||
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void Director::createSystemFolder(const std::string &folder)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#include "defines.h" // for GAMECANVAS_HEIGHT, options.game.width
|
||||
#include "defines.h" // for options.game.height, options.game.width
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||
@@ -43,19 +43,12 @@ Ending::Ending()
|
||||
Screen::get()->setBorderColor(stringToColor("black"));
|
||||
|
||||
// Crea la textura para cubrir el texto
|
||||
cover_surface_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height + 8);
|
||||
SDL_SetTextureBlendMode(cover_surface_, SDL_BLENDMODE_BLEND);
|
||||
cover_surface_ = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), options.game.width, options.game.height + 8);
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
fillCoverTexture();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Ending::~Ending()
|
||||
{
|
||||
SDL_DestroyTexture(cover_surface_);
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Ending::update()
|
||||
{
|
||||
@@ -91,7 +84,7 @@ void Ending::render()
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(stringToColor("yellow"));
|
||||
Screen::get()->clear(stringToColor("yellow"));
|
||||
|
||||
// Dibuja las imagenes de la escena
|
||||
sprite_pics_.at(current_scene_).image_sprite->render();
|
||||
@@ -176,7 +169,7 @@ void Ending::iniTexts()
|
||||
const int HEIGHT = text->getCharacterSize() + 2 + 2;
|
||||
Uint8 color = stringToColor("black");
|
||||
|
||||
EndingTexture st;
|
||||
EndingSurface st;
|
||||
|
||||
// Crea la textura
|
||||
st.image_surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), WIDTH, HEIGHT);
|
||||
@@ -192,7 +185,7 @@ void Ending::iniTexts()
|
||||
Screen::get()->setRenderSurfaceData(st.cover_surface);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Crea una malla de 8 pixels de alto
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
@@ -243,7 +236,7 @@ void Ending::iniPics()
|
||||
|
||||
for (const auto &pic : pics)
|
||||
{
|
||||
EndingTexture sp;
|
||||
EndingSurface sp;
|
||||
|
||||
// Crea la texture
|
||||
sp.image_surface = Resource::get()->getSurface(pic.caption);
|
||||
@@ -259,7 +252,7 @@ void Ending::iniPics()
|
||||
Screen::get()->setRenderSurfaceData(sp.cover_surface);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Crea una malla en los primeros 8 pixels
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
@@ -479,29 +472,29 @@ void Ending::checkChangeScene()
|
||||
void Ending::fillCoverTexture()
|
||||
{
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_surface_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->setRenderSurfaceData(cover_surface_);
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
const Uint8 color = stringToColor("black");
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
for (int i = 0; i < 256; i += 2)
|
||||
{
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 0);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 1);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 2);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 3);
|
||||
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 4);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 6);
|
||||
cover_surface_->putPixel(surface, i + 0, options.game.height + 0, color);
|
||||
cover_surface_->putPixel(surface, i + 1, options.game.height + 1, color);
|
||||
cover_surface_->putPixel(surface, i + 0, options.game.height + 2, color);
|
||||
cover_surface_->putPixel(surface, i + 1, options.game.height + 3, color);
|
||||
|
||||
cover_surface_->putPixel(surface, i, options.game.height + 4, color);
|
||||
cover_surface_->putPixel(surface, i, options.game.height + 6, color);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
SDL_Rect rect = {0, 0, 256, options.game.height};
|
||||
cover_surface_->fillRect(surface, &rect, color);
|
||||
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
@@ -513,7 +506,7 @@ void Ending::renderCoverTexture()
|
||||
const int OFFSET = std::min(cover_counter_, 100);
|
||||
SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, OFFSET * 2};
|
||||
SDL_Rect dstRect = {0, 0, 256, OFFSET * 2};
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), cover_surface_, &srcRect, &dstRect);
|
||||
cover_surface_->render(&srcRect, &dstRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Ending
|
||||
{
|
||||
private:
|
||||
// Estructuras
|
||||
struct EndingTexture // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
||||
struct EndingSurface // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
||||
{
|
||||
std::shared_ptr<Surface> image_surface; // Surface a mostrar
|
||||
std::shared_ptr<SSprite> image_sprite; // SSprite para mostrar la textura
|
||||
@@ -42,15 +42,15 @@ private:
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Texture *cover_surface_; // Surface para cubrir el texto
|
||||
std::shared_ptr<Surface> cover_surface_; // Surface para cubrir el texto
|
||||
|
||||
// Variables
|
||||
int counter_; // Contador
|
||||
int pre_counter_; // Contador previo
|
||||
int cover_counter_; // Contador para la cortinilla
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
std::vector<EndingTexture> sprite_texts_; // Vector con los sprites de texto con su cortinilla
|
||||
std::vector<EndingTexture> sprite_pics_; // Vector con los sprites de texto con su cortinilla
|
||||
std::vector<EndingSurface> sprite_texts_; // Vector con los sprites de texto con su cortinilla
|
||||
std::vector<EndingSurface> sprite_pics_; // Vector con los sprites de texto con su cortinilla
|
||||
int current_scene_; // Escena actual
|
||||
std::vector<SceneData> scenes_; // Vector con los textos e imagenes de cada escena
|
||||
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
Ending();
|
||||
|
||||
// Destructor
|
||||
~Ending();
|
||||
~Ending() = default;
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
|
||||
@@ -101,7 +101,7 @@ void Ending2::render()
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(stringToColor("black"));
|
||||
Screen::get()->clear(stringToColor("black"));
|
||||
|
||||
// Dibuja los sprites
|
||||
renderSprites();
|
||||
@@ -113,24 +113,26 @@ void Ending2::render()
|
||||
renderTexts();
|
||||
|
||||
// Dibuja una trama arriba y abajo
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0xFF);
|
||||
Uint8 color = stringToColor("black");
|
||||
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), 1, 1);
|
||||
auto surfaceData = Screen::get()->getRenderSurfaceData();
|
||||
for (int i = 0; i < 256; i += 2)
|
||||
{
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 0);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 1);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 2);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 3);
|
||||
surface->putPixel(surfaceData, i + 0, 0, color);
|
||||
surface->putPixel(surfaceData, i + 1, 1, color);
|
||||
surface->putPixel(surfaceData, i + 0, 2, color);
|
||||
surface->putPixel(surfaceData, i + 1, 3, color);
|
||||
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6);
|
||||
surface->putPixel(surfaceData, i, 4, color);
|
||||
surface->putPixel(surfaceData, i, 6, color);
|
||||
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 191);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 190);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 189);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 188);
|
||||
surface->putPixel(surfaceData, i + 0, 191, color);
|
||||
surface->putPixel(surfaceData, i + 1, 190, color);
|
||||
surface->putPixel(surfaceData, i + 0, 189, color);
|
||||
surface->putPixel(surfaceData, i + 1, 188, color);
|
||||
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 187);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 185);
|
||||
surface->putPixel(surfaceData, i, 187, color);
|
||||
surface->putPixel(surfaceData, i, 185, color);
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
|
||||
@@ -201,6 +201,7 @@ void Game::updateDebugInfo()
|
||||
// Pone la información de debug en pantalla
|
||||
void Game::renderDebugInfo()
|
||||
{
|
||||
/*
|
||||
if (!Debug::get()->getEnabled())
|
||||
{
|
||||
return;
|
||||
@@ -225,6 +226,7 @@ void Game::renderDebugInfo()
|
||||
// Pinta el texto
|
||||
Debug::get()->setPos({1, 18 * 8});
|
||||
Debug::get()->render();
|
||||
*/
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -446,7 +448,7 @@ void Game::renderBlackScreen()
|
||||
{
|
||||
if (black_screen_)
|
||||
{
|
||||
Screen::get()->clean();
|
||||
Screen::get()->clear();
|
||||
Screen::get()->setBorderColor(stringToColor("black"));
|
||||
}
|
||||
}
|
||||
@@ -457,8 +459,8 @@ void Game::setScoreBoardColor()
|
||||
// Obtiene el color del borde
|
||||
const Uint8 colorBorder = room_->getBorderColor();
|
||||
|
||||
const bool isBlack = colorBorder, stringToColor("black");
|
||||
const bool isBrightBlack = colorBorder, stringToColor("bright_black");
|
||||
const bool isBlack = colorBorder == stringToColor("black");
|
||||
const bool isBrightBlack = colorBorder == stringToColor("bright_black");
|
||||
|
||||
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
|
||||
board_->color = isBlack || isBrightBlack ? stringToColor("white") : colorBorder;
|
||||
@@ -563,7 +565,7 @@ void Game::fillRoomNameTexture()
|
||||
Screen::get()->setRenderSurfaceData(room_name_surface_);
|
||||
|
||||
// Rellena la textura de color
|
||||
Screen::get()->clean(stringToColor("white"));
|
||||
Screen::get()->clear(stringToColor("white"));
|
||||
|
||||
// Escribe el texto en la textura
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
|
||||
@@ -71,7 +71,7 @@ void GameOver::render()
|
||||
constexpr int Y = 32;
|
||||
|
||||
Screen::get()->start();
|
||||
Screen::get()->clean(1);
|
||||
Screen::get()->clear(1);
|
||||
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
|
||||
|
||||
@@ -149,15 +149,14 @@ void LoadingScreen::renderBorder()
|
||||
{
|
||||
// Pinta el borde de colro azul
|
||||
Uint8 color = stringToColor("blue");
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->clear(color);
|
||||
|
||||
// Añade lineas amarillas
|
||||
color = stringToColor("yellow");
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
const int WIDTH = options.game.width + (options.video.border.width * 2);
|
||||
const int HEIGHT = options.game.height + (options.video.border.height * 2);
|
||||
bool drawEnabled = rand() % 2 == 0 ? true : false;
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
|
||||
int row = 0;
|
||||
while (row < HEIGHT)
|
||||
@@ -167,7 +166,7 @@ void LoadingScreen::renderBorder()
|
||||
{
|
||||
for (int i = row; i < row + ROW_HEIGHT; ++i)
|
||||
{
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), 0, i, WIDTH, i);
|
||||
screen_surface_->drawLine(surface, 0, i, WIDTH, i, color);
|
||||
}
|
||||
}
|
||||
row += ROW_HEIGHT;
|
||||
@@ -221,7 +220,7 @@ void LoadingScreen::run()
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->start();
|
||||
Screen::get()->clean();
|
||||
Screen::get()->clear();
|
||||
Screen::get()->render();
|
||||
|
||||
while (options.section.section == Section::LOADING_SCREEN)
|
||||
|
||||
@@ -96,9 +96,9 @@ void Logo::updateJAILGAMES()
|
||||
// Gestiona el color de las texturas
|
||||
void Logo::updateTextureColors()
|
||||
{
|
||||
constexpr int INI = 70;
|
||||
/*constexpr int INI = 70;
|
||||
constexpr int INC = 4;
|
||||
/*
|
||||
|
||||
if (counter_ == INI + INC * 0)
|
||||
{
|
||||
since_1998_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
||||
@@ -221,7 +221,7 @@ void Logo::render()
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean();
|
||||
Screen::get()->clear();
|
||||
|
||||
// Dibuja los objetos
|
||||
for (const auto &s : jailgames_sprite_)
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
#include "moving_sprite.h"
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
|
||||
: Sprite(texture, pos),
|
||||
x_(pos.x),
|
||||
y_(pos.y),
|
||||
rotate_(rotate),
|
||||
zoom_w_(zoom_w),
|
||||
zoom_h_(zoom_h),
|
||||
flip_(flip) { Sprite::pos_ = pos; }
|
||||
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
|
||||
: Sprite(texture, pos),
|
||||
x_(pos.x),
|
||||
y_(pos.y),
|
||||
rotate_(Rotate()),
|
||||
zoom_w_(1.0f),
|
||||
zoom_h_(1.0f),
|
||||
flip_(SDL_FLIP_NONE) { Sprite::pos_ = pos; }
|
||||
|
||||
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
|
||||
: Sprite(texture),
|
||||
x_(0.0f),
|
||||
y_(0.0f),
|
||||
rotate_(Rotate()),
|
||||
zoom_w_(1.0f),
|
||||
zoom_h_(1.0f),
|
||||
flip_(SDL_FLIP_NONE) { Sprite::clear(); }
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
{
|
||||
x_ = 0.0f; // Posición en el eje X
|
||||
y_ = 0.0f; // Posición en el eje Y
|
||||
|
||||
vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
rotate_ = Rotate(); // Inicializa la estructura
|
||||
|
||||
zoom_w_ = 1.0f; // Zoom aplicado a la anchura
|
||||
zoom_h_ = 1.0f; // Zoom aplicado a la altura
|
||||
|
||||
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
|
||||
Sprite::clear();
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
void MovingSprite::move()
|
||||
{
|
||||
x_ += vx_;
|
||||
y_ += vy_;
|
||||
|
||||
vx_ += ax_;
|
||||
vy_ += ay_;
|
||||
|
||||
pos_.x = static_cast<int>(x_);
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void MovingSprite::update()
|
||||
{
|
||||
move();
|
||||
rotate();
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
texture_->render(pos_.x, pos_.y, &clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
{
|
||||
if (rotate_.enabled)
|
||||
{
|
||||
++rotate_.counter;
|
||||
if (rotate_.counter % rotate_.speed == 0)
|
||||
{
|
||||
updateAngle();
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Activa o desactiva el efecto de rotación
|
||||
void MovingSprite::setRotate(bool enable)
|
||||
{
|
||||
rotate_.enabled = enable;
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
x_ = static_cast<float>(rect.x);
|
||||
y_ = static_cast<float>(rect.y);
|
||||
|
||||
pos_ = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de las variables
|
||||
void MovingSprite::setPos(float x, float y)
|
||||
{
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
|
||||
pos_.x = static_cast<int>(x_);
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float value)
|
||||
{
|
||||
x_ = value;
|
||||
pos_.x = static_cast<int>(x_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float value)
|
||||
{
|
||||
y_ = value;
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_HORIZONTAL
|
||||
#include <algorithm> // for max
|
||||
#include <memory> // for shared_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture; // lines 9-9
|
||||
|
||||
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
public:
|
||||
struct Rotate
|
||||
{
|
||||
bool enabled; // Indica si ha de rotar
|
||||
int counter; // Contador
|
||||
int speed; // Velocidad de giro
|
||||
double angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
SDL_Point *center; // Centro de rotación
|
||||
|
||||
Rotate() : enabled(false), counter(0), speed(1), angle(0.0), amount(0.0f), center(nullptr) {}
|
||||
};
|
||||
|
||||
protected:
|
||||
float x_; // Posición en el eje X
|
||||
float y_; // Posición en el eje Y
|
||||
|
||||
float vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
float ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
Rotate rotate_; // Variables usada para controlar la rotación del sprite
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // Zoom aplicado a la altura
|
||||
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
||||
|
||||
// Incrementa el valor del ángulo
|
||||
void updateAngle() { rotate_.angle += rotate_.amount; }
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
// Rota el sprite
|
||||
void rotate();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos);
|
||||
explicit MovingSprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
virtual ~MovingSprite() = default;
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
virtual void update();
|
||||
|
||||
// Reinicia todas las variables a cero
|
||||
void clear() override;
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render() override;
|
||||
|
||||
// Obtiene la variable
|
||||
float getPosX() const { return x_; }
|
||||
float getPosY() const { return y_; }
|
||||
float getVelX() const { return vx_; }
|
||||
float getVelY() const { return vy_; }
|
||||
float getAccelX() const { return ax_; }
|
||||
float getAccelY() const { return ay_; }
|
||||
|
||||
// Establece la variable
|
||||
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 { return rotate_.enabled; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value) { zoom_w_ = value; }
|
||||
void setZoomH(float value) { zoom_h_ = value; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
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) { rotate_.speed = std::max(1, value); }
|
||||
void setRotateAmount(double value) { rotate_.amount = value; }
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate() { rotate_.amount *= -1; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip) { flip_ = flip; }
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; }
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip() { return flip_; }
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de las variables
|
||||
void setPos(float x, float y);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float value);
|
||||
};
|
||||
@@ -9,9 +9,9 @@
|
||||
#include "options.h" // for Options, options, OptionsNotification
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "s_sprite.h" // for Sprite
|
||||
#include "s_sprite.h" // for SSprite
|
||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
||||
#include "surface.h" // for Texture
|
||||
#include "surface.h" // for Surface
|
||||
|
||||
// [SINGLETON]
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
@@ -234,47 +234,45 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
n.rect = {desp_h, y_pos, width, height};
|
||||
|
||||
// Crea la textura
|
||||
n.surface = std::make_shared<Texture>(Screen::get()->getRenderer());
|
||||
n.surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
n.surface->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
n.surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
|
||||
|
||||
// Prepara para dibujar en la textura
|
||||
n.surface->setAsRenderTarget(Screen::get()->getRenderer());
|
||||
Screen::get()->setRenderSurfaceData(n.surface);
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, 255);
|
||||
SDL_Rect rect;
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
if (shape == NotificationShape::ROUNDED)
|
||||
{
|
||||
rect = {4, 0, width - (4 * 2), height};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {4 / 2, 1, width - 4, height - 2};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {1, 4 / 2, width - 2, height - 4};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
|
||||
rect = {0, 4, width, height - (4 * 2)};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
n.surface->fillRect(surface, &rect, bg_color_);
|
||||
}
|
||||
|
||||
else if (shape == NotificationShape::SQUARED)
|
||||
{
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->clear(bg_color_);
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
if (has_icons_ && icon >= 0 && texts.size() >= 2)
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(icon_surface_, (SDL_Rect){0, 0, ICON_SIZE_, ICON_SIZE_});
|
||||
auto sp = std::make_unique<SSprite>(icon_surface_, (SDL_Rect){0, 0, ICON_SIZE_, ICON_SIZE_});
|
||||
sp->setPosition({padding_in_h, padding_in_v, ICON_SIZE_, ICON_SIZE_});
|
||||
sp->setClip({ICON_SIZE_ * (icon % 10), ICON_SIZE_ * (icon / 10), ICON_SIZE_, ICON_SIZE_});
|
||||
sp->render();
|
||||
}
|
||||
|
||||
// Escribe el texto de la notificación
|
||||
const Color color{255, 255, 255};
|
||||
const Uint8 color = stringToColor("white");
|
||||
int iterator = 0;
|
||||
for (const auto &text : texts)
|
||||
{
|
||||
@@ -290,13 +288,13 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
|
||||
// Crea el sprite de la notificación
|
||||
n.sprite = std::make_shared<Sprite>(n.surface, n.rect);
|
||||
n.sprite = std::make_shared<SSprite>(n.surface, n.rect);
|
||||
|
||||
// Deja la notificación invisible
|
||||
n.surface->setAlpha(0);
|
||||
//n.surface->setAlpha(0);
|
||||
|
||||
// Añade la notificación a la lista
|
||||
notifications_.emplace_back(n);
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
||||
|
||||
// Variables
|
||||
Color bg_color_; // Color de fondo de las notificaciones
|
||||
Uint8 bg_color_; // Color de fondo de las notificaciones
|
||||
int wait_time_; // Tiempo que se ve la notificación
|
||||
std::vector<Notification> notifications_; // La lista de notificaciones activas
|
||||
bool stack_; // Indica si las notificaciones se apilan
|
||||
|
||||
@@ -81,7 +81,7 @@ constexpr Subsection DEFAULT_SUBSECTION = Subsection::LOGO_TO_INTRO;
|
||||
constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto
|
||||
constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosition::UPPER_LEFT; // Posición de las notificaciones por defecto
|
||||
constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
|
||||
const Color DEFAULT_NOTIFICATION_COLOR = Color(48, 48, 48); // Color de las notificaciones por defecto
|
||||
const Uint8 DEFAULT_NOTIFICATION_COLOR = 1; // Color de las notificaciones por defecto
|
||||
constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto
|
||||
constexpr const char *DEFAULT_VERSION = "1.10"; // Versión por defecto
|
||||
|
||||
@@ -90,7 +90,7 @@ struct OptionsNotification
|
||||
{
|
||||
NotificationPosition pos; // Ubicación de las notificaciones en pantalla
|
||||
bool sound; // Indica si las notificaciones suenan
|
||||
Color color; // Color de las notificaciones
|
||||
Uint8 color; // Color de las notificaciones
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsNotification()
|
||||
@@ -99,7 +99,7 @@ struct OptionsNotification
|
||||
color(DEFAULT_NOTIFICATION_COLOR) {}
|
||||
|
||||
// Constructor
|
||||
OptionsNotification(NotificationPosition p, bool s, Color c)
|
||||
OptionsNotification(NotificationPosition p, bool s, Uint8 c)
|
||||
: pos(p),
|
||||
sound(s),
|
||||
color(c) {}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include <cmath> // for ceil, abs
|
||||
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
||||
#include "debug.h" // for Debug
|
||||
#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
|
||||
#include "input.h" // for Input, InputAction
|
||||
@@ -43,8 +43,7 @@ Player::Player(const PlayerData &player)
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render()
|
||||
{
|
||||
sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||
sprite_->render();
|
||||
sprite_->render(1, color_);
|
||||
|
||||
#ifdef DEBUG
|
||||
renderDebugInfo();
|
||||
@@ -718,7 +717,7 @@ void Player::initSprite(const std::string &texture_path, const std::string &anim
|
||||
auto texture = Resource::get()->getSurface(texture_path);
|
||||
auto animations = Resource::get()->getAnimations(animations_path);
|
||||
|
||||
sprite_ = std::make_shared<AnimatedSprite>(texture, animations);
|
||||
sprite_ = std::make_shared<SAnimatedSprite>(texture, animations);
|
||||
sprite_->setWidth(WIDTH_);
|
||||
sprite_->setHeight(HEIGHT_);
|
||||
sprite_->setCurrentAnimation("walk");
|
||||
@@ -728,6 +727,7 @@ void Player::initSprite(const std::string &texture_path, const std::string &anim
|
||||
// Pinta la información de debug del jugador
|
||||
void Player::renderDebugInfo()
|
||||
{
|
||||
/*
|
||||
if (Debug::get()->getEnabled())
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
@@ -759,5 +759,6 @@ void Player::renderDebugInfo()
|
||||
SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
|
||||
SDL_RenderDrawPoint(renderer, debug_point_.x, debug_point_.y);
|
||||
}
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
@@ -59,7 +59,7 @@ void Resource::load()
|
||||
{
|
||||
calculateTotal();
|
||||
Screen::get()->show();
|
||||
Screen::get()->setBorderColor(Color(0, 0, 0));
|
||||
Screen::get()->setBorderColor(1);
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
loadMusics();
|
||||
@@ -405,7 +405,7 @@ void Resource::renderProgress()
|
||||
constexpr int BAR_HEIGHT = 10;
|
||||
const int bar_position = options.game.height - BAR_HEIGHT - Y_PADDING;
|
||||
Screen::get()->start();
|
||||
Screen::get()->clean();
|
||||
Screen::get()->clear();
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 255, 255);
|
||||
|
||||
const int wired_bar_width = options.game.width - (X_PADDING * 2);
|
||||
|
||||
@@ -415,7 +415,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
|
||||
setAnimatedTiles();
|
||||
|
||||
// Crea la textura para el mapa de tiles de la habitación
|
||||
map_surface_ = createTexture(Screen::get()->getRenderer(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
map_surface_ = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
|
||||
// Pinta el mapa de la habitación en la textura
|
||||
fillMapTexture();
|
||||
@@ -424,9 +424,6 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
|
||||
Screen::get()->setBorderColor(stringToColor(border_color_));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Room::~Room() { SDL_DestroyTexture(map_surface_); }
|
||||
|
||||
void Room::initializeRoom(const RoomData &room)
|
||||
{
|
||||
// Asignar valores a las variables miembro
|
||||
@@ -477,9 +474,8 @@ void Room::initializeRoom(const RoomData &room)
|
||||
void Room::fillMapTexture()
|
||||
{
|
||||
const Uint8 color = stringToColor(bg_color_);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), map_surface_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->setRenderSurfaceData(map_surface_);
|
||||
Screen::get()->clear(color);
|
||||
|
||||
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
|
||||
|
||||
@@ -501,7 +497,7 @@ void Room::fillMapTexture()
|
||||
surface_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (Debug::get()->getEnabled())
|
||||
/*if (Debug::get()->getEnabled())
|
||||
{
|
||||
if (clip.x != -TILE_SIZE_)
|
||||
{
|
||||
@@ -510,14 +506,14 @@ void Room::fillMapTexture()
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 64, 64, 64, 224);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &clip);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (Debug::get()->getEnabled())
|
||||
{
|
||||
{ /*
|
||||
// BottomSurfaces
|
||||
if (true)
|
||||
{
|
||||
@@ -593,10 +589,11 @@ void Room::fillMapTexture()
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
#endif
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
}
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
@@ -604,7 +601,7 @@ void Room::renderMap()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), map_surface_, nullptr, &dest);
|
||||
map_surface_->render(nullptr, &dest);
|
||||
|
||||
// Dibuja los tiles animados
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -78,7 +78,7 @@ private:
|
||||
std::vector<std::shared_ptr<Enemy>> enemies_; // Listado con los enemigos de la habitación
|
||||
std::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación
|
||||
std::shared_ptr<Surface> surface_; // Textura con los graficos de la habitación
|
||||
SDL_Texture *map_surface_; // Textura para dibujar el mapa de la habitación
|
||||
std::shared_ptr<Surface> map_surface_; // Textura para dibujar el mapa de la habitación
|
||||
std::shared_ptr<ScoreboardData> data_; // Puntero a los datos del marcador
|
||||
|
||||
// Variables
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data);
|
||||
|
||||
// Destructor
|
||||
~Room();
|
||||
~Room() = default;
|
||||
|
||||
// Devuelve el nombre de la habitación
|
||||
std::string getName() const { return name_; }
|
||||
|
||||
@@ -17,8 +17,8 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
: data_(data),
|
||||
clock_(ClockData())
|
||||
{
|
||||
const int TEXTURE_WIDTH_ = options.game.width;
|
||||
constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK;
|
||||
const int SURFACE_WIDTH_ = options.game.width;
|
||||
constexpr int SURFACE_HEIGHT_ = 6 * BLOCK;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
item_surface_ = Resource::get()->getSurface("items.gif");
|
||||
@@ -27,8 +27,8 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations);
|
||||
player_sprite_->setCurrentAnimation("walk_menu");
|
||||
|
||||
surface_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_);
|
||||
surface_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_};
|
||||
surface_ = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), SURFACE_WIDTH_, SURFACE_HEIGHT_);
|
||||
surface_dest_ = {0, options.game.height - SURFACE_HEIGHT_, SURFACE_WIDTH_, SURFACE_HEIGHT_};
|
||||
|
||||
// Inicializa las variables
|
||||
counter_ = 0;
|
||||
@@ -46,16 +46,10 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Scoreboard::~Scoreboard()
|
||||
{
|
||||
SDL_DestroyTexture(surface_);
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void Scoreboard::render()
|
||||
{
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), surface_, nullptr, &surface_dest_);
|
||||
surface_->render(nullptr, &surface_dest_);
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -142,12 +136,10 @@ int Scoreboard::getMinutes()
|
||||
void Scoreboard::fillTexture()
|
||||
{
|
||||
// Empieza a dibujar en la textura
|
||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), surface_);
|
||||
Screen::get()->setRenderSurfaceData(surface_);
|
||||
|
||||
// Limpia la textura
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->clear(stringToColor("black"));
|
||||
|
||||
// Anclas
|
||||
constexpr int LINE1 = BLOCK;
|
||||
@@ -187,5 +179,5 @@ void Scoreboard::fillTexture()
|
||||
text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor("white"));
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
std::shared_ptr<SAnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador
|
||||
std::shared_ptr<Surface> item_surface_; // Surface con los graficos para los elementos del marcador
|
||||
std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador
|
||||
SDL_Texture *surface_; // Surface donde dibujar el marcador;
|
||||
std::shared_ptr<Surface> surface_; // Surface donde dibujar el marcador;
|
||||
|
||||
// Variables
|
||||
std::vector<Uint8> color_; // Vector con los colores del objeto
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
explicit Scoreboard(std::shared_ptr<ScoreboardData> data);
|
||||
|
||||
// Destructor
|
||||
~Scoreboard();
|
||||
~Scoreboard() = default;
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
|
||||
@@ -46,24 +46,24 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
adjustWindowSize();
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
border_color_ = {0x00, 0x00, 0x00};
|
||||
border_color_ = 1;
|
||||
|
||||
// Establece el modo de escalado
|
||||
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
// Crea la textura donde se vuelcan las surfaces
|
||||
surface_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
game_texture_ = createTexture(renderer, options.game.width, options.game.height);
|
||||
game_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
|
||||
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||
border_texture_ = createTexture(renderer, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
setBorderColor(border_color_);
|
||||
border_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
|
||||
// Crea la surface donde se vuelcan los datos
|
||||
surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height);
|
||||
surface_->loadPalette(Asset::get()->get("zx-spectrum-8x.gif"));
|
||||
// Crea la surface donde se dibujan los graficos del juego
|
||||
game_surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height);
|
||||
game_surface_->loadPalette(Asset::get()->get("zx-spectrum-8x.gif"));
|
||||
|
||||
// Crea la surface donde se dibujan los graficos del juego
|
||||
border_surface_ = std::make_shared<Surface>(nullptr, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||
border_surface_->loadPalette(Asset::get()->get("zx-spectrum-8x.gif"));
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options.video.mode);
|
||||
@@ -76,22 +76,21 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
SDL_DestroyTexture(surface_texture_);
|
||||
SDL_DestroyTexture(game_texture_);
|
||||
SDL_DestroyTexture(border_texture_);
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
void Screen::clean(Color color)
|
||||
void Screen::clear(Color color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
void Screen::clean(Uint8 index)
|
||||
void Screen::clear(Uint8 index)
|
||||
{
|
||||
surface_->clear(index);
|
||||
game_surface_->clear(index);
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
@@ -101,14 +100,11 @@ void Screen::start()
|
||||
setRenderSurfaceData(nullptr);
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura del borde
|
||||
void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture_); }
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::render()
|
||||
{
|
||||
// Copia la surface a game_texture_
|
||||
surface_->copyToTexture(renderer_, game_texture_);
|
||||
game_surface_->copyToTexture(renderer_, game_texture_);
|
||||
|
||||
// Renderiza sobre gameCanvas los overlays
|
||||
renderNotifications();
|
||||
@@ -206,7 +202,7 @@ void Screen::setBorderColor(Uint8 color)
|
||||
border_color_ = color;
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, border_texture_);
|
||||
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||
SDL_SetRenderDrawColor(renderer_, color, color, color, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
@@ -238,7 +234,7 @@ void Screen::gameCanvasToBorderCanvas()
|
||||
{
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, border_texture_);
|
||||
SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_texture_rect_);
|
||||
SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_rect_);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
@@ -262,7 +258,7 @@ void Screen::renderPresent()
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_texture_rect_);
|
||||
SDL_RenderCopy(renderer_, game_texture_, nullptr, &game_rect_);
|
||||
}
|
||||
SDL_RenderPresent(renderer_);
|
||||
}
|
||||
@@ -316,7 +312,7 @@ void Screen::adjustWindowSize()
|
||||
// Ajusta game_canvas_rect_
|
||||
void Screen::adjustGameCanvasRect()
|
||||
{
|
||||
game_texture_rect_ = {
|
||||
game_rect_ = {
|
||||
options.video.border.enabled ? options.video.border.width : 0,
|
||||
options.video.border.enabled ? options.video.border.height : 0,
|
||||
options.game.width,
|
||||
@@ -358,5 +354,5 @@ void Screen::resetShaders()
|
||||
// Establece el renderizador para las surfaces
|
||||
void Screen::setRenderSurfaceData(std::shared_ptr<Surface> surface)
|
||||
{
|
||||
(surface) ? surface_->redirectSurfaceDataTo(surface) : surface_->restoreOriginalSurfaceData();
|
||||
(surface) ? game_surface_->redirectSurfaceDataTo(surface) : game_surface_->restoreOriginalSurfaceData();
|
||||
}
|
||||
@@ -28,15 +28,15 @@ private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window_; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
||||
std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
||||
std::shared_ptr<Surface> game_surface_; // Objeto para trabajar con surfaces
|
||||
std::shared_ptr<Surface> border_surface_; // Objeto para trabajar con surfaces
|
||||
|
||||
// Variables
|
||||
int window_width_; // Ancho de la pantalla o ventana
|
||||
int window_height_; // Alto de la pantalla o ventana
|
||||
SDL_Rect game_texture_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
SDL_Rect game_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
Uint8 border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
|
||||
// Dibuja las notificaciones
|
||||
@@ -77,15 +77,12 @@ public:
|
||||
static Screen *get();
|
||||
|
||||
// Limpia la pantalla
|
||||
void clean(Color color = {0x00, 0x00, 0x00});
|
||||
void clean(Uint8 index);
|
||||
void clear(Color color = {0x00, 0x00, 0x00});
|
||||
void clear(Uint8 index);
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
void start();
|
||||
|
||||
// Prepara para empezar a dibujar en la textura del borde
|
||||
void startDrawOnBorder();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void render();
|
||||
void renderWithoutNotifier();
|
||||
@@ -136,11 +133,10 @@ public:
|
||||
// Establece el renderizador para las surfaces
|
||||
void setRenderSurfaceData(std::shared_ptr<Surface> surface = nullptr);
|
||||
|
||||
// Limpia
|
||||
|
||||
// Getters
|
||||
SDL_Renderer *getRenderer() { return renderer_; }
|
||||
std::shared_ptr<SurfaceData> getRenderSurfaceData() { return surface_->getSurfaceData(); }
|
||||
SDL_Texture *getGameTexture() { return game_texture_; };
|
||||
SDL_Texture *getBorderTexture() { return border_texture_; }
|
||||
std::shared_ptr<SurfaceData> getRenderSurfaceData() { return game_surface_->getSurfaceData(); }
|
||||
|
||||
// Prepara para empezar a dibujar en la textura del borde
|
||||
void startDrawOnBorder() { setRenderSurfaceData(border_surface_); }
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "sprite.h"
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, int x, int y, int w, int h)
|
||||
: texture_(texture),
|
||||
pos_((SDL_Rect){x, y, w, h}),
|
||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, SDL_Rect rect)
|
||||
: texture_(texture),
|
||||
pos_(rect),
|
||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
: texture_(texture),
|
||||
pos_({0, 0, texture_->getWidth(), texture_->getHeight()}),
|
||||
clip_(pos_) {}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
texture_->render(pos_.x, pos_.y, &clip_, zoom_, zoom_);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPosition(int x, int y)
|
||||
{
|
||||
pos_.x = x;
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPosition(SDL_Point p)
|
||||
{
|
||||
pos_.x = p.x;
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Reinicia las variables a cero
|
||||
void Sprite::clear()
|
||||
{
|
||||
pos_ = {0, 0, 0, 0};
|
||||
clip_ = {0, 0, 0, 0};
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <memory> // Para shared_ptr
|
||||
class Texture;
|
||||
|
||||
// Clase sprite
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
// Variables
|
||||
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
|
||||
SDL_Rect clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
double zoom_ = 1.0f; // Zoom aplicado a la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(std::shared_ptr<Texture>, int x, int y, int w, int h);
|
||||
Sprite(std::shared_ptr<Texture>, SDL_Rect rect);
|
||||
explicit Sprite(std::shared_ptr<Texture>);
|
||||
|
||||
// Destructor
|
||||
virtual ~Sprite() = default;
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
virtual void render();
|
||||
|
||||
// Reinicia las variables a cero
|
||||
virtual void clear();
|
||||
|
||||
// Obtiene la posición y el tamaño
|
||||
int getX() const { return pos_.x; }
|
||||
int getY() const { return pos_.y; }
|
||||
int getWidth() const { return pos_.w; }
|
||||
int getHeight() const { return pos_.h; }
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getPosition() const { return pos_; }
|
||||
SDL_Rect &getRect() { return pos_; }
|
||||
|
||||
// Establece la posición y el tamaño
|
||||
void setX(int x) { pos_.x = x; }
|
||||
void setY(int y) { pos_.y = y; }
|
||||
void setWidth(int w) { pos_.w = w; }
|
||||
void setHeight(int h) { pos_.h = h; }
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(SDL_Point p);
|
||||
void setPosition(SDL_Rect r) { pos_ = r; }
|
||||
|
||||
// Establece el nivel de zoom
|
||||
void setZoom(float zoom) { zoom_ = zoom; }
|
||||
|
||||
// Aumenta o disminuye la posición
|
||||
void incX(int value) { pos_.x += value; }
|
||||
void incY(int value) { pos_.y += value; }
|
||||
|
||||
// Obtiene el rectangulo que se dibuja de la textura
|
||||
SDL_Rect getClip() const { return clip_; }
|
||||
|
||||
// Establece el rectangulo que se dibuja de la textura
|
||||
void setClip(SDL_Rect rect) { clip_ = rect; }
|
||||
void setClip(int x, int y, int w, int h) { clip_ = (SDL_Rect){x, y, w, h}; }
|
||||
|
||||
// Obtiene un puntero a la textura
|
||||
std::shared_ptr<Texture> getTexture() const { return texture_; }
|
||||
|
||||
// Establece la textura a utilizar
|
||||
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
|
||||
};
|
||||
@@ -147,6 +147,44 @@ void Surface::fillRect(std::shared_ptr<SurfaceData> surface_data, SDL_Rect *rect
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja una linea
|
||||
void Surface::drawLine(std::shared_ptr<SurfaceData> surface_data, int x1, int y1, int x2, int y2, Uint8 color)
|
||||
{
|
||||
// Calcula las diferencias
|
||||
int dx = std::abs(x2 - x1);
|
||||
int dy = std::abs(y2 - y1);
|
||||
|
||||
// Determina la dirección del incremento
|
||||
int sx = (x1 < x2) ? 1 : -1;
|
||||
int sy = (y1 < y2) ? 1 : -1;
|
||||
|
||||
int err = dx - dy;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Asegúrate de no dibujar fuera de los límites de la superficie
|
||||
if (x1 >= 0 && x1 < surface_data->width && y1 >= 0 && y1 < surface_data->height)
|
||||
{
|
||||
surface_data->data[x1 + y1 * surface_data->width] = color;
|
||||
}
|
||||
|
||||
// Si alcanzamos el punto final, salimos
|
||||
if (x1 == x2 && y1 == y2)
|
||||
break;
|
||||
|
||||
int e2 = 2 * err;
|
||||
if (e2 > -dy)
|
||||
{
|
||||
err -= dy;
|
||||
x1 += sx;
|
||||
}
|
||||
if (e2 < dx)
|
||||
{
|
||||
err += dx;
|
||||
y1 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copia una región de la superficie de origen a la de destino
|
||||
void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||
|
||||
@@ -109,6 +109,9 @@ public:
|
||||
// Dibuja un rectangulo
|
||||
void fillRect(std::shared_ptr<SurfaceData> surface_data, SDL_Rect *rect, Uint8 color);
|
||||
|
||||
// Dibuja una linea
|
||||
void drawLine(std::shared_ptr<SurfaceData> surface_data, int x1, int y1, int x2, int y2, Uint8 color);
|
||||
|
||||
// Getters
|
||||
std::shared_ptr<SurfaceData> getSurfaceData() const { return surface_data_; }
|
||||
int getTransparentColor() const { return transparent_color_; }
|
||||
|
||||
@@ -144,13 +144,11 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
// Escribe el texto en una surface
|
||||
std::shared_ptr<Surface> Text::writeToSurface(const std::string &text, int zoom, int kerning)
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
auto width = lenght(text, kerning) * zoom;
|
||||
auto height = box_height_ * zoom;
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
|
||||
Screen::get()->setRenderSurfaceData(surface);
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
write(0, 0, text, kerning);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
|
||||
@@ -160,13 +158,11 @@ std::shared_ptr<Surface> Text::writeToSurface(const std::string &text, int zoom,
|
||||
// Escribe el texto con extras en una surface
|
||||
std::shared_ptr<Surface> Text::writeDXToSurface(Uint8 flags, const std::string &text, int kerning, Uint8 textColor, Uint8 shadow_distance, Uint8 shadow_color, int lenght)
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
auto width = Text::lenght(text, kerning) + shadow_distance;
|
||||
auto height = box_height_ + shadow_distance;
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
|
||||
Screen::get()->setRenderSurfaceData(surface);
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ void Title::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
Screen::get()->clean(stringToColor("black"));
|
||||
Screen::get()->clear(stringToColor("black"));
|
||||
|
||||
if (state_ == TitleState::SHOW_MENU)
|
||||
{
|
||||
@@ -352,19 +352,17 @@ void Title::createCheevosTexture()
|
||||
|
||||
// Rellena la textura con color sólido
|
||||
const Uint8 CHEEVOS_BG_COLOR = stringToColor("black");
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->clear(CHEEVOS_BG_COLOR);
|
||||
|
||||
// Escribe la lista de logros en la textura
|
||||
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS";
|
||||
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
|
||||
int pos = 2;
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor("bright_green"));
|
||||
pos += TEXT->getCharacterSize();
|
||||
const Uint8 CHEEVO_LOCKED_COLOR = stringToColor("white");
|
||||
const Uint8 CHEEVO_UNLOCKED_COLOR = stringToColor("bright_green");
|
||||
Uint8 cheevoColor;
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF);
|
||||
constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
|
||||
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
|
||||
|
||||
@@ -373,7 +371,7 @@ void Title::createCheevosTexture()
|
||||
cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR;
|
||||
pos += CHEEVOS_PADDING;
|
||||
constexpr int HALF = CHEEVOS_PADDING / 2;
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1);
|
||||
cheevos_surface_->drawLine(Screen::get()->getRenderSurfaceData(), LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1, cheevoColor);
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor);
|
||||
pos += TEXT->getCharacterSize() + 1;
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor);
|
||||
|
||||
Reference in New Issue
Block a user