Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-01 22:36:22 +01:00
parent 360ebfd2e6
commit aca2be98af
27 changed files with 371 additions and 560 deletions

View File

@@ -20,15 +20,9 @@
// Constructor // Constructor
Credits::Credits() Credits::Credits()
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
resource_(Resource::get()),
asset_(Asset::get()),
input_(Input::get())
{ {
// Reserva memoria para los punteros // Reserva memoria para los punteros
text_ = resource_->getText("smb2"); sprite_ = std::make_shared<AnimatedSprite>(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani"));
sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("shine.png"), resource_->getAnimations("shine.ani"));
// Inicializa variables // Inicializa variables
options.section.section = Section::CREDITS; options.section.section = Section::CREDITS;
@@ -36,10 +30,10 @@ Credits::Credits()
sprite_->setPosition({194, 174, 8, 8}); sprite_->setPosition({194, 174, 8, 8});
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para el texto que se escribe en pantalla // Crea la textura para el texto que se escribe en pantalla
text_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); text_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (text_texture_ == nullptr) if (text_texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -50,7 +44,7 @@ Credits::Credits()
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el rexto
cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (cover_texture_ == nullptr) if (cover_texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -175,54 +169,56 @@ void Credits::fillTexture()
iniTexts(); iniTexts();
// Rellena la textura de texto // Rellena la textura de texto
SDL_SetRenderTarget(renderer_, text_texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
Color color = stringToColor(options.video.palette, "black"); Color color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
auto text = Resource::get()->getText("smb2");
// Escribe el texto en la textura // Escribe el texto en la textura
const int SIZE = text_->getCharacterSize(); const int SIZE = text->getCharacterSize();
int pos_y = 0; int pos_y = 0;
for (const auto &t : texts_) for (const auto &t : texts_)
{ {
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, pos_y * SIZE, t.label, 1, t.color); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, pos_y * SIZE, t.label, 1, t.color);
pos_y++; pos_y++;
} }
// Escribe el corazón // Escribe el corazón
const int TEXT_LENGHT = text_->lenght(texts_[22].label, 1) - text_->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio const int TEXT_LENGHT = text->lenght(texts_[22].label, 1) - text->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio
const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT; const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT;
text_->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red")); text->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red"));
// Recoloca el sprite del brillo // Recoloca el sprite del brillo
sprite_->setPosX(POS_X + 2); sprite_->setPosX(POS_X + 2);
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
// Rellena la textura que cubre el texto con color transparente // Rellena la textura que cubre el texto con color transparente
SDL_SetRenderTarget(renderer_, cover_texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_texture_);
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0x00); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0x00);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
for (int i = 0; i < 256; i += 2) for (int i = 0; i < 256; i += 2)
{ {
SDL_RenderDrawPoint(renderer_, i, 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0);
SDL_RenderDrawPoint(renderer_, i, 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2);
SDL_RenderDrawPoint(renderer_, i, 4); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4);
SDL_RenderDrawPoint(renderer_, i, 6); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6);
SDL_RenderDrawPoint(renderer_, i + 1, 5); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5);
SDL_RenderDrawPoint(renderer_, i + 1, 7); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7);
} }
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, 256, 192}; SDL_Rect rect = {0, 8, 256, 192};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
} }
// Actualiza el contador // Actualiza el contador
@@ -269,7 +265,7 @@ void Credits::update()
// Actualiza el contador // Actualiza el contador
updateCounter(); updateCounter();
screen_->update(); Screen::get()->update();
// Actualiza el sprite con el brillo // Actualiza el sprite con el brillo
if (counter_ > 770) if (counter_ > 770)
@@ -283,28 +279,28 @@ void Credits::update()
void Credits::render() void Credits::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
// Limpia la pantalla // Limpia la pantalla
screen_->clean(); Screen::get()->clean();
if (counter_ < 1150) if (counter_ < 1150)
{ {
// Dibuja la textura con el texto en pantalla // Dibuja la textura con el texto en pantalla
SDL_RenderCopy(renderer_, text_texture_, nullptr, nullptr); SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, nullptr, nullptr);
// Dibuja la textura que cubre el texto // Dibuja la textura que cubre el texto
const int offset = std::min(counter_ / 8, 192 / 2); const int offset = std::min(counter_ / 8, 192 / 2);
SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)}; SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)};
SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)}; SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)};
SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect); SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect);
// Dibuja el sprite con el brillo // Dibuja el sprite con el brillo
sprite_->render(); sprite_->render();
} }
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Bucle para el logo del juego // Bucle para el logo del juego

View File

@@ -23,12 +23,6 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
SDL_Texture *text_texture_; // Textura para dibujar el texto SDL_Texture *text_texture_; // Textura para dibujar el texto
SDL_Texture *cover_texture_; // Textura para cubrir el texto SDL_Texture *cover_texture_; // Textura para cubrir el texto
std::shared_ptr<AnimatedSprite> sprite_; // Sprite para el brillo del corazón std::shared_ptr<AnimatedSprite> sprite_; // Sprite para el brillo del corazón

View File

@@ -26,35 +26,30 @@ Debug *Debug::get()
return Debug::debug_; return Debug::debug_;
} }
// Constructor
Debug::Debug()
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
text_(Resource::get()->getText("debug")) {}
// Dibuja en pantalla // Dibuja en pantalla
void Debug::render() void Debug::render()
{ {
auto text = Resource::get()->getText("debug");
int y = y_; int y = y_;
int w = 0; int w = 0;
for (const auto &s : slot_) for (const auto &s : slot_)
{ {
text_->write(x_, y, s); text->write(x_, y, s);
w = (std::max(w, (int)s.length())); w = (std::max(w, (int)s.length()));
y += text_->getCharacterSize() + 1; y += text->getCharacterSize() + 1;
if (y > 192 - text_->getCharacterSize()) if (y > 192 - text->getCharacterSize())
{ {
y = y_; y = y_;
x_ += w * text_->getCharacterSize() + 2; x_ += w * text->getCharacterSize() + 2;
} }
} }
y = 0; y = 0;
for (const auto &l : log_) for (const auto &l : log_)
{ {
text_->writeColored(x_ + 10, y, l, Color(255, 255, 255)); text->writeColored(x_ + 10, y, l, Color(255, 255, 255));
y += text_->getCharacterSize() + 1; y += text->getCharacterSize() + 1;
} }
} }

View File

@@ -16,11 +16,6 @@ private:
// [SINGLETON] Objeto privado // [SINGLETON] Objeto privado
static Debug *debug_; static Debug *debug_;
// Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
std::shared_ptr<Text> text_; // Objeto encargado de escribir texto en pantalla
// Variables // Variables
std::vector<std::string> slot_; // Vector con los textos a escribir std::vector<std::string> slot_; // Vector con los textos a escribir
std::vector<std::string> log_; // Vector con los textos a escribir std::vector<std::string> log_; // Vector con los textos a escribir
@@ -29,7 +24,7 @@ private:
bool enabled_ = false; // Indica si esta activo el modo debug bool enabled_ = false; // Indica si esta activo el modo debug
// Constructor // Constructor
Debug(); Debug() = default;
// Destructor // Destructor
~Debug() = default; ~Debug() = default;
@@ -59,5 +54,5 @@ public:
void addToLog(std::string text) { log_.push_back(text); } void addToLog(std::string text) { log_.push_back(text); }
void clearLog() { log_.clear(); } void clearLog() { log_.clear(); }
void setEnabled(bool value) { enabled_ = value; } void setEnabled(bool value) { enabled_ = value; }
void switchEnabled() { enabled_ = !enabled_; } void toggleEnabled() { enabled_ = !enabled_; }
}; };

View File

@@ -19,13 +19,7 @@
// Constructor // Constructor
Demo::Demo() Demo::Demo()
: screen_(Screen::get()), : board_(std::make_shared<ScoreboardData>())
renderer_(Screen::get()->getRenderer()),
resource_(Resource::get()),
asset_(Asset::get()),
input_(Input::get()),
debug_(Debug::get()),
board_(std::make_shared<ScoreboardData>())
{ {
// Inicia algunas variables // Inicia algunas variables
board_->ini_clock = SDL_GetTicks(); board_->ini_clock = SDL_GetTicks();
@@ -45,7 +39,6 @@ Demo::Demo()
ItemTracker::init(); ItemTracker::init();
scoreboard_ = std::make_shared<Scoreboard>(board_); scoreboard_ = std::make_shared<Scoreboard>(board_);
room_ = std::make_shared<Room>(current_room_, board_); room_ = std::make_shared<Room>(current_room_, board_);
text_ = resource_->getText("smb2");
// Inicializa el resto de variables // Inicializa el resto de variables
counter_ = 0; counter_ = 0;
@@ -112,7 +105,7 @@ void Demo::update()
scoreboard_->update(); scoreboard_->update();
checkRoomChange(); checkRoomChange();
screen_->update(); Screen::get()->update();
} }
} }
@@ -120,7 +113,7 @@ void Demo::update()
void Demo::render() void Demo::render()
{ {
// Prepara para dibujar el frame // Prepara para dibujar el frame
screen_->start(); Screen::get()->start();
// Dibuja los elementos del juego en orden // Dibuja los elementos del juego en orden
room_->renderMap(); room_->renderMap();
@@ -130,7 +123,7 @@ void Demo::render()
scoreboard_->render(); scoreboard_->render();
// Actualiza la pantalla // Actualiza la pantalla
screen_->render(); Screen::get()->render();
} }
// Escribe el nombre de la pantalla // Escribe el nombre de la pantalla
@@ -139,10 +132,10 @@ void Demo::renderRoomName()
// Texto en el centro de la pantalla // Texto en el centro de la pantalla
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2}; SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
Color color = stringToColor(options.video.palette, "white"); Color color = stringToColor(options.video.palette, "white");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor()); Resource::get()->getText("smb2")->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor());
} }
// Cambia de habitación // Cambia de habitación
@@ -152,7 +145,7 @@ bool Demo::changeRoom(const std::string &room_path)
if (room_path != "0") if (room_path != "0")
{ {
// Verifica que exista el fichero que se va a cargar // Verifica que exista el fichero que se va a cargar
if (asset_->get(room_path) != "") if (Asset::get()->get(room_path) != "")
{ {
// Crea un objeto habitación a partir del fichero // Crea un objeto habitación a partir del fichero
room_ = std::make_shared<Room>(room_path, board_); room_ = std::make_shared<Room>(room_path, board_);

View File

@@ -19,14 +19,7 @@ class Demo
{ {
private: private:
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de manejar el renderizador
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
Debug *debug_; // Objeto para gestionar la información de debug
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
std::shared_ptr<Text> text_; // Objeto para los textos del juego
std::shared_ptr<Scoreboard> scoreboard_; // Objeto encargado de gestionar el marcador std::shared_ptr<Scoreboard> scoreboard_; // Objeto encargado de gestionar el marcador
// Variables // Variables

View File

@@ -23,24 +23,14 @@
// Constructor // Constructor
Ending::Ending() Ending::Ending()
: screen_(Screen::get()), : counter_(-1),
renderer_(Screen::get()->getRenderer()), pre_counter_(0),
resource_(Resource::get()), cover_counter_(0),
asset_(Asset::get()), ticks_(0),
input_(Input::get()) current_scene_(0)
{ {
// Reserva memoria para los punteros a objetos
text_ = resource_->getText("smb2");
music = resource_->getMusic("ending1.ogg");
// Inicializa variables
counter_ = -1;
pre_counter_ = 0;
cover_counter_ = 0;
options.section.section = Section::ENDING; options.section.section = Section::ENDING;
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
ticks_ = 0;
current_scene_ = 0;
// Inicializa los textos // Inicializa los textos
iniTexts(); iniTexts();
@@ -52,10 +42,10 @@ Ending::Ending()
iniScenes(); iniScenes();
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el rexto
cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8); cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
if (cover_texture_ == nullptr) if (cover_texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -100,7 +90,7 @@ void Ending::update()
// Actualiza el volumen de la musica // Actualiza el volumen de la musica
updateMusicVolume(); updateMusicVolume();
screen_->update(); Screen::get()->update();
} }
} }
@@ -108,10 +98,10 @@ void Ending::update()
void Ending::render() void Ending::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
// Limpia la pantalla // Limpia la pantalla
screen_->clean(stringToColor(options.video.palette, "black")); Screen::get()->clean(stringToColor(options.video.palette, "black"));
// Dibuja las imagenes de la escena // Dibuja las imagenes de la escena
sprite_pics_[current_scene_].sprite->render(); sprite_pics_[current_scene_].sprite->render();
@@ -131,7 +121,7 @@ void Ending::render()
renderCoverTexture(); renderCoverTexture();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
@@ -190,51 +180,54 @@ void Ending::iniTexts()
for (const auto &t : texts) for (const auto &t : texts)
{ {
auto text = Resource::get()->getText("smb2");
const int WIDTH = text->lenght(t.caption, 1) + 2 + 2;
const int HEIGHT = text->getCharacterSize() + 2 + 2;
Color color = stringToColor(options.video.palette, "black");
EndingTexture st; EndingTexture st;
const int width = text_->lenght(t.caption, 1) + 2 + 2;
const int height = text_->getCharacterSize() + 2 + 2;
Color c = stringToColor(options.video.palette, "black");
// Crea la texture // Crea la texture
st.texture = std::make_shared<Texture>(renderer_); st.texture = std::make_shared<Texture>(Screen::get()->getRenderer());
st.texture->createBlank(width, height); st.texture->createBlank(WIDTH, HEIGHT);
st.texture->setAsRenderTarget(renderer_); st.texture->setAsRenderTarget(Screen::get()->getRenderer());
st.texture->setBlendMode(SDL_BLENDMODE_BLEND); st.texture->setBlendMode(SDL_BLENDMODE_BLEND);
text_->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, c, 2, c); text->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, color, 2, color);
// Crea el sprite // Crea el sprite
st.sprite = std::make_shared<Sprite>(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight()); st.sprite = std::make_shared<Sprite>(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight());
st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos); st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos);
// Crea la coverTexture // Crea la coverTexture
st.cover_texture = std::make_shared<Texture>(renderer_); st.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
st.cover_texture->createBlank(width, height + 8); st.cover_texture->createBlank(WIDTH, HEIGHT + 8);
st.cover_texture->setAsRenderTarget(renderer_); st.cover_texture->setAsRenderTarget(Screen::get()->getRenderer());
st.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND); st.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la coverTexture con color transparente // Rellena la coverTexture con color transparente
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
c = stringToColor(options.video.palette, "black"); color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
for (int i = 0; i < width; i += 2) for (int i = 0; i < WIDTH; i += 2)
{ {
SDL_RenderDrawPoint(renderer_, i, 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0);
SDL_RenderDrawPoint(renderer_, i, 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2);
SDL_RenderDrawPoint(renderer_, i, 4); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4);
SDL_RenderDrawPoint(renderer_, i, 6); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6);
SDL_RenderDrawPoint(renderer_, i + 1, 5); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5);
SDL_RenderDrawPoint(renderer_, i + 1, 7); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7);
} }
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, width, height}; SDL_Rect rect = {0, 8, WIDTH, HEIGHT};
c = stringToColor(options.video.palette, "black"); color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
// Crea el sprite // Crea el sprite
st.cover_sprite = std::make_shared<Sprite>(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8); st.cover_sprite = std::make_shared<Sprite>(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8);
@@ -243,7 +236,7 @@ void Ending::iniTexts()
// Inicializa variables // Inicializa variables
st.clip_desp = 8; st.clip_desp = 8;
st.clip_height = height; st.clip_height = HEIGHT;
sprite_texts_.push_back(st); sprite_texts_.push_back(st);
} }
@@ -280,7 +273,7 @@ void Ending::iniPics()
EndingTexture sp; EndingTexture sp;
// Crea la texture // Crea la texture
sp.texture = resource_->getTexture(p.caption); sp.texture = Resource::get()->getTexture(p.caption);
const int width = sp.texture->getWidth(); const int width = sp.texture->getWidth();
const int height = sp.texture->getHeight(); const int height = sp.texture->getHeight();
@@ -289,34 +282,34 @@ void Ending::iniPics()
sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos); sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos);
// Crea la coverTexture // Crea la coverTexture
sp.cover_texture = std::make_shared<Texture>(renderer_); sp.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
sp.cover_texture->createBlank(width, height + 8); sp.cover_texture->createBlank(width, height + 8);
sp.cover_texture->setAsRenderTarget(renderer_); sp.cover_texture->setAsRenderTarget(Screen::get()->getRenderer());
sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND); sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la coverTexture con color transparente // Rellena la coverTexture con color transparente
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
Color c = stringToColor(options.video.palette, "black"); Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF);
for (int i = 0; i < width; i += 2) for (int i = 0; i < width; i += 2)
{ {
SDL_RenderDrawPoint(renderer_, i, 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0);
SDL_RenderDrawPoint(renderer_, i, 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2);
SDL_RenderDrawPoint(renderer_, i, 4); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4);
SDL_RenderDrawPoint(renderer_, i, 6); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6);
SDL_RenderDrawPoint(renderer_, i + 1, 5); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5);
SDL_RenderDrawPoint(renderer_, i + 1, 7); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7);
} }
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, width, height}; SDL_Rect rect = {0, 8, width, height};
c = stringToColor(options.video.palette, "black"); c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF);
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
// Crea el sprite // Crea el sprite
sp.cover_sprite = std::make_shared<Sprite>(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8); sp.cover_sprite = std::make_shared<Sprite>(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8);
@@ -417,7 +410,7 @@ void Ending::iniScenes()
// Bucle principal // Bucle principal
void Ending::run() void Ending::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(Resource::get()->getMusic("ending1.ogg"));
while (options.section.section == Section::ENDING) while (options.section.section == Section::ENDING)
{ {
@@ -516,29 +509,29 @@ void Ending::checkChangeScene()
void Ending::fillCoverTexture() void Ending::fillCoverTexture()
{ {
// Rellena la textura que cubre el texto con color transparente // Rellena la textura que cubre el texto con color transparente
SDL_SetRenderTarget(renderer_, cover_texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_texture_);
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
const Color color = stringToColor(options.video.palette, "black"); const Color color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
for (int i = 0; i < 256; i += 2) for (int i = 0; i < 256; i += 2)
{ {
SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 0);
SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 1); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 1);
SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 2);
SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 3); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 3);
SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 4); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 4);
SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 6); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 6);
} }
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT}; SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
} }
// Dibuja la cortinilla de cambio de escena // Dibuja la cortinilla de cambio de escena
@@ -549,7 +542,7 @@ void Ending::renderCoverTexture()
const int offset = std::min(cover_counter_, 100); const int offset = std::min(cover_counter_, 100);
SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, offset * 2}; SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, offset * 2};
SDL_Rect dstRect = {0, 0, 256, offset * 2}; SDL_Rect dstRect = {0, 0, 256, offset * 2};
SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect); SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect);
} }
} }

View File

@@ -48,12 +48,6 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
SDL_Texture *cover_texture_; // Textura para cubrir el texto SDL_Texture *cover_texture_; // Textura para cubrir el texto
// Variables // Variables
@@ -65,7 +59,6 @@ private:
std::vector<EndingTexture> sprite_pics_; // Vector con los sprites de texto con su cortinilla std::vector<EndingTexture> sprite_pics_; // Vector con los sprites de texto con su cortinilla
int current_scene_; // Escena actual int current_scene_; // Escena actual
std::vector<SceneData> scenes_; // Vector con los textos e imagenes de cada escena std::vector<SceneData> scenes_; // Vector con los textos e imagenes de cada escena
JA_Music_t *music; // Musica que suena durante el final
// Actualiza el objeto // Actualiza el objeto
void update(); void update();

View File

@@ -227,7 +227,7 @@ void Game::checkDebugEvents(const SDL_Event &event)
switch (event.key.keysym.scancode) switch (event.key.keysym.scancode)
{ {
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
Debug::get()->switchEnabled(); Debug::get()->toggleEnabled();
options.cheats.invincible = static_cast<Cheat::CheatState>(Debug::get()->getEnabled()); options.cheats.invincible = static_cast<Cheat::CheatState>(Debug::get()->getEnabled());
board_->music = !Debug::get()->getEnabled(); board_->music = !Debug::get()->getEnabled();
board_->music ? JA_ResumeMusic() : JA_PauseMusic(); board_->music ? JA_ResumeMusic() : JA_PauseMusic();

View File

@@ -18,34 +18,25 @@
// Constructor // Constructor
GameOver::GameOver() GameOver::GameOver()
: screen_(Screen::get()), : player_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("player_game_over.png"), Resource::get()->getAnimations("player_game_over.ani"))),
renderer_(Screen::get()->getRenderer()), tv_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("tv.png"), Resource::get()->getAnimations("tv.ani"))),
resource_(Resource::get()), pre_counter_(0),
asset_(Asset::get()), counter_(0),
input_(Input::get()) ticks_(0)
{ {
// Reserva memoria para los punteros a objetos
text_ = resource_->getText("smb2");
player_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("player_game_over.png"), resource_->getAnimations("player_game_over.ani"));
tv_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("tv.png"), resource_->getAnimations("tv.ani"));
music_ = resource_->getMusic("game_over.ogg");
// Inicializa variables
pre_counter_ = 0;
counter_ = 0;
options.section.section = Section::GAME_OVER; options.section.section = Section::GAME_OVER;
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
ticks_ = 0;
player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10); player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10);
player_sprite_->setPosY(30); player_sprite_->setPosY(30);
tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10); tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10);
tv_sprite_->setPosY(30); tv_sprite_->setPosY(30);
// Inicializa el vector de colores // Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (const auto &cl : colorList) for (const auto &color : COLORS)
{ {
colors_.push_back(stringToColor(options.video.palette, cl)); colors_.push_back(stringToColor(options.video.palette, color));
} }
color_ = colors_.back(); color_ = colors_.back();
} }
@@ -72,7 +63,7 @@ void GameOver::update()
player_sprite_->update(); player_sprite_->update();
tv_sprite_->update(); tv_sprite_->update();
screen_->update(); Screen::get()->update();
} }
} }
@@ -81,11 +72,13 @@ void GameOver::render()
{ {
constexpr int Y = 32; constexpr int Y = 32;
screen_->start(); Screen::get()->start();
screen_->clean(); Screen::get()->clean();
auto text = Resource::get()->getText("smb2");
// Escribe el texto de GAME OVER // Escribe el texto de GAME OVER
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y, "G A M E O V E R", 1, color_); text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y, "G A M E O V E R", 1, color_);
// Dibuja los sprites // Dibuja los sprites
player_sprite_->setPosY(Y + 30); player_sprite_->setPosY(Y + 30);
@@ -95,15 +88,15 @@ void GameOver::render()
// Escribe el texto con las habitaciones y los items // Escribe el texto con las habitaciones y los items
const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10); const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10);
const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10); const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 80, "ITEMS: " + itemsTxt, 1, color_); text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 80, "ITEMS: " + itemsTxt, 1, color_);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 90, "ROOMS: " + roomsTxt, 1, color_); text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 90, "ROOMS: " + roomsTxt, 1, color_);
// Escribe el texto con "Tu peor pesadilla" // Escribe el texto con "Tu peor pesadilla"
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 110, "YOUR WORST NIGHTMARE IS", 1, color_); text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 110, "YOUR WORST NIGHTMARE IS", 1, color_);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 120, options.stats.worst_nightmare, 1, color_); text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 120, options.stats.worst_nightmare, 1, color_);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
@@ -178,7 +171,7 @@ void GameOver::updateCounters()
// Hace sonar la música // Hace sonar la música
if (counter_ == 1) if (counter_ == 1)
{ {
JA_PlayMusic(music_, 0); JA_PlayMusic(Resource::get()->getMusic("game_over.ogg"), 0);
} }
// Comprueba si ha terminado la sección // Comprueba si ha terminado la sección

View File

@@ -22,12 +22,6 @@ private:
static constexpr int COUNTER_FADE_LENGHT_ = 20; // Contador: duración del fade static constexpr int COUNTER_FADE_LENGHT_ = 20; // Contador: duración del fade
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite con el jugador std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite con el jugador
std::shared_ptr<AnimatedSprite> tv_sprite_; // Sprite con el televisor std::shared_ptr<AnimatedSprite> tv_sprite_; // Sprite con el televisor
@@ -37,7 +31,6 @@ private:
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
std::vector<Color> colors_; // Vector con los colores para el fade std::vector<Color> colors_; // Vector con los colores para el fade
Color color_; // Color usado para el texto y los sprites Color color_; // Color usado para el texto y los sprites
JA_Music_t *music_; // Musica que suena durante el juego
// Actualiza el objeto // Actualiza el objeto
void update(); void update();

View File

@@ -18,30 +18,22 @@
// Constructor // Constructor
LoadingScreen::LoadingScreen() LoadingScreen::LoadingScreen()
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
resource_(Resource::get()),
asset_(Asset::get()),
input_(Input::get())
{ {
// Reserva memoria para los punteros // Reserva memoria para los punteros
if (options.video.palette == Palette::ZXSPECTRUM) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png"); mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn.png");
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color.png"); color_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_color.png");
} }
else if (options.video.palette == Palette::ZXARNE) else if (options.video.palette == Palette::ZXARNE)
{ {
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png"); mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn_zxarne.png");
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png"); color_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_color_zxarne.png");
} }
mono_loading_screen_sprite_ = std::make_shared<Sprite>(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight()); mono_loading_screen_sprite_ = std::make_shared<Sprite>(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight());
color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight()); color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight());
loading_sound1_ = resource_->getMusic("loading_sound1.ogg");
loading_sound2_ = resource_->getMusic("loading_sound2.ogg");
loading_sound3_ = resource_->getMusic("loading_sound3.ogg");
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
if (texture_ == nullptr) if (texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -73,7 +65,7 @@ LoadingScreen::LoadingScreen()
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
} }
// Destructor // Destructor
@@ -125,7 +117,7 @@ void LoadingScreen::updateLoad()
load_rect_ = {0, 0, 16, 8}; load_rect_ = {0, 0, 16, 8};
color_loading_screen_sprite_->setClip(load_rect_); color_loading_screen_sprite_->setClip(load_rect_);
color_loading_screen_sprite_->setPosition(load_rect_); color_loading_screen_sprite_->setPosition(load_rect_);
JA_PlayMusic(loading_sound3_); JA_PlayMusic(Resource::get()->getMusic("loading_sound3.ogg"));
} }
} }
// Segunda parte de la carga, la parte de los bloques en color // Segunda parte de la carga, la parte de los bloques en color
@@ -154,7 +146,7 @@ void LoadingScreen::updateCounter()
if (counter_ == 1) if (counter_ == 1)
{ {
JA_PlayMusic(loading_sound2_); JA_PlayMusic(Resource::get()->getMusic("loading_sound2.ogg"));
} }
} }
@@ -169,12 +161,12 @@ void LoadingScreen::renderBorder()
{ {
// Pinta el borde de colro azul // Pinta el borde de colro azul
Color color = stringToColor(options.video.palette, "blue"); Color color = stringToColor(options.video.palette, "blue");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Añade lineas amarillas // Añade lineas amarillas
color = stringToColor(options.video.palette, "yellow"); color = stringToColor(options.video.palette, "yellow");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); 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 WIDTH = options.game.width + (options.video.border.width * 2);
const int HEIGHT = options.game.height + (options.video.border.height * 2); const int HEIGHT = options.game.height + (options.video.border.height * 2);
bool drawEnabled = rand() % 2 == 0 ? true : false; bool drawEnabled = rand() % 2 == 0 ? true : false;
@@ -187,7 +179,7 @@ void LoadingScreen::renderBorder()
{ {
for (int i = row; i < row + ROW_HEIGHT; ++i) for (int i = row; i < row + ROW_HEIGHT; ++i)
{ {
SDL_RenderDrawLine(renderer_, 0, i, WIDTH, i); SDL_RenderDrawLine(Screen::get()->getRenderer(), 0, i, WIDTH, i);
} }
} }
row += ROW_HEIGHT; row += ROW_HEIGHT;
@@ -206,7 +198,7 @@ void LoadingScreen::update()
updateCounter(); updateCounter();
updateLoad(); updateLoad();
fillTexture(); fillTexture();
screen_->update(); Screen::get()->update();
} }
} }
@@ -216,20 +208,20 @@ void LoadingScreen::render()
if (options.video.border.enabled) if (options.video.border.enabled)
{ {
// Prepara para empezar a dibujar en la textura del borde // Prepara para empezar a dibujar en la textura del borde
screen_->startDrawOnBorder(); Screen::get()->startDrawOnBorder();
// Dibuja el efecto de carga en el borde // Dibuja el efecto de carga en el borde
renderBorder(); renderBorder();
} }
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
// Copila la textura a la pantalla // Copila la textura a la pantalla
SDL_RenderCopy(renderer_, texture_, nullptr, nullptr); SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Bucle para el logo del juego // Bucle para el logo del juego
@@ -237,12 +229,12 @@ void LoadingScreen::run()
{ {
// Inicia el sonido de carga // Inicia el sonido de carga
JA_SetVolume(64); JA_SetVolume(64);
JA_PlayMusic(loading_sound1_); JA_PlayMusic(Resource::get()->getMusic("loading_sound1.ogg"));
// Limpia la pantalla // Limpia la pantalla
screen_->start(); Screen::get()->start();
screen_->clean(); Screen::get()->clean();
screen_->render(); Screen::get()->render();
while (options.section.section == Section::LOADING_SCREEN) while (options.section.section == Section::LOADING_SCREEN)
{ {
@@ -258,27 +250,27 @@ void LoadingScreen::run()
void LoadingScreen::fillTexture() void LoadingScreen::fillTexture()
{ {
// Empieza a dibujar en la textura // Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(renderer_, texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
// Dibuja la pantalla de carga // Dibuja la pantalla de carga
renderLoad(); renderLoad();
// Deja el renderizador como estaba // Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
} }
// Limpia la textura // Limpia la textura
void LoadingScreen::clearTexture() void LoadingScreen::clearTexture()
{ {
// Empieza a dibujar en la textura // Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(renderer_, texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
// Limpia // Limpia
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Deja el renderizador como estaba // Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
} }

View File

@@ -16,11 +16,6 @@ class LoadingScreen
{ {
private: private:
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Texture> mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro std::shared_ptr<Texture> mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro
std::shared_ptr<Texture> color_loading_screen_texture_; // Textura con la pantalla de carga en color std::shared_ptr<Texture> color_loading_screen_texture_; // Textura con la pantalla de carga en color
std::shared_ptr<Sprite> mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1 std::shared_ptr<Sprite> mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1
@@ -32,9 +27,6 @@ private:
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
int load_counter_ = 0; // Contador para controlar las cargas int load_counter_ = 0; // Contador para controlar las cargas
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
JA_Music_t *loading_sound1_; // Sonidos para imitar la carga tipo spectrum
JA_Music_t *loading_sound2_; // Sonidos para imitar la carga tipo spectrum
JA_Music_t *loading_sound3_; // Sonidos para imitar la carga tipo spectrum
int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga
SDL_Texture *texture_; // Textura para dibujar la pantalla de carga SDL_Texture *texture_; // Textura para dibujar la pantalla de carga

View File

@@ -17,16 +17,10 @@
// Constructor // Constructor
Logo::Logo() Logo::Logo()
: screen_(Screen::get()), : jailgames_texture_(Resource::get()->getTexture("jailgames.png")),
renderer_(Screen::get()->getRenderer()), since_1998_texture_(Resource::get()->getTexture("since_1998.png")),
resource_(Resource::get()), since_1998_sprite_(std::make_shared<Sprite>(since_1998_texture_, (256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()))
asset_(Asset::get()),
input_(Input::get())
{ {
// Reserva memoria para los punteros
jailgames_texture_ = resource_->getTexture("jailgames.png");
since_1998_texture_ = resource_->getTexture("since_1998.png");
since_1998_sprite_ = std::make_shared<Sprite>(since_1998_texture_, (256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()); since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
since_1998_texture_->setColor(0, 0, 0); since_1998_texture_->setColor(0, 0, 0);
@@ -50,7 +44,7 @@ Logo::Logo()
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
} }
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
@@ -211,7 +205,7 @@ void Logo::update()
// Gestiona el color de las texturas // Gestiona el color de las texturas
updateTextureColors(); updateTextureColors();
screen_->update(); Screen::get()->update();
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
if (counter_ == END_LOGO_ + POST_LOGO_) if (counter_ == END_LOGO_ + POST_LOGO_)
@@ -225,10 +219,10 @@ void Logo::update()
void Logo::render() void Logo::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
// Limpia la pantalla // Limpia la pantalla
screen_->clean(); Screen::get()->clean();
// Dibuja los objetos // Dibuja los objetos
for (auto s : jailgames_sprite_) for (auto s : jailgames_sprite_)
@@ -238,7 +232,7 @@ void Logo::render()
since_1998_sprite_->render(); since_1998_sprite_->render();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Bucle para el logo del juego // Bucle para el logo del juego

View File

@@ -21,11 +21,6 @@ private:
static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con los ficheros de recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Texture> jailgames_texture_; // Textura con los graficos "JAILGAMES" std::shared_ptr<Texture> jailgames_texture_; // Textura con los graficos "JAILGAMES"
std::shared_ptr<Texture> since_1998_texture_; // Textura con los graficos "Since 1998" std::shared_ptr<Texture> since_1998_texture_; // Textura con los graficos "Since 1998"
std::vector<std::shared_ptr<Sprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES std::vector<std::shared_ptr<Sprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES

View File

@@ -35,8 +35,7 @@ Notifier *Notifier::get()
// Constructor // Constructor
Notifier::Notifier(const std::string &icon_file, const std::string &text) Notifier::Notifier(const std::string &icon_file, const std::string &text)
: renderer_(Screen::get()->getRenderer()), : icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr),
icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr),
text_(Resource::get()->getText(text)), text_(Resource::get()->getText(text)),
bg_color_(options.notifications.color), bg_color_(options.notifications.color),
wait_time_(150), wait_time_(150),
@@ -84,8 +83,8 @@ void Notifier::update()
// Comprueba los estados // Comprueba los estados
if (notifications_[i].state == NotificationStatus::RISING) if (notifications_[i].state == NotificationStatus::RISING)
{ {
//const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist); // const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist);
//const int alpha = 255 * step; // const int alpha = 255 * step;
constexpr int ALPHA = 255; constexpr int ALPHA = 255;
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP) if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
@@ -117,11 +116,10 @@ void Notifier::update()
else if (notifications_[i].state == NotificationStatus::VANISHING) else if (notifications_[i].state == NotificationStatus::VANISHING)
{ {
//const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist); // const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist);
//const int ALPHA = 255 * (1 - step); // const int ALPHA = 255 * (1 - step);
constexpr int ALPHA = 255; constexpr int ALPHA = 255;
if (options.notifications.getVerticalPosition() == NotificationPosition::TOP) if (options.notifications.getVerticalPosition() == NotificationPosition::TOP)
{ {
notifications_[i].rect.y--; notifications_[i].rect.y--;
@@ -235,34 +233,34 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
n.rect = {desp_h, y_pos, width, height}; n.rect = {desp_h, y_pos, width, height};
// Crea la textura // Crea la textura
n.texture = std::make_shared<Texture>(renderer_); n.texture = std::make_shared<Texture>(Screen::get()->getRenderer());
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
n.texture->setBlendMode(SDL_BLENDMODE_BLEND); n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Prepara para dibujar en la textura // Prepara para dibujar en la textura
n.texture->setAsRenderTarget(renderer_); n.texture->setAsRenderTarget(Screen::get()->getRenderer());
// Dibuja el fondo de la notificación // Dibuja el fondo de la notificación
SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, 255);
SDL_Rect rect; SDL_Rect rect;
if (shape == NotificationShape::ROUNDED) if (shape == NotificationShape::ROUNDED)
{ {
rect = {4, 0, width - (4 * 2), height}; rect = {4, 0, width - (4 * 2), height};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
rect = {4 / 2, 1, width - 4, height - 2}; rect = {4 / 2, 1, width - 4, height - 2};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
rect = {1, 4 / 2, width - 2, height - 4}; rect = {1, 4 / 2, width - 2, height - 4};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
rect = {0, 4, width, height - (4 * 2)}; rect = {0, 4, width, height - (4 * 2)};
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
} }
else if (shape == NotificationShape::SQUARED) else if (shape == NotificationShape::SQUARED)
{ {
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
} }
// Dibuja el icono de la notificación // Dibuja el icono de la notificación
@@ -291,7 +289,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
} }
// Deja de dibujar en la textura // Deja de dibujar en la textura
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
// Crea el sprite de la notificación // Crea el sprite de la notificación
n.sprite = std::make_shared<Sprite>(n.texture, n.rect); n.sprite = std::make_shared<Sprite>(n.texture, n.rect);

View File

@@ -62,9 +62,6 @@ private:
can_be_removed(true), height(0) {} can_be_removed(true), height(0) {}
}; };
// Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana
std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones std::shared_ptr<Texture> icon_texture_; // Textura para los iconos de las notificaciones
std::shared_ptr<Text> text_; // Objeto para dibujar texto std::shared_ptr<Text> text_; // Objeto para dibujar texto

View File

@@ -17,11 +17,7 @@
// Constructor // Constructor
Player::Player(const PlayerData &player) Player::Player(const PlayerData &player)
: renderer_(Screen::get()->getRenderer()), : room_(player.room)
input_(Input::get()),
asset_(Asset::get()),
debug_(Debug::get()),
room_(player.room)
{ {
// Inicializa algunas variables // Inicializa algunas variables
initSprite(player.texture_path, player.animations_path); initSprite(player.texture_path, player.animations_path);
@@ -82,13 +78,13 @@ void Player::checkInput()
if (!auto_movement_) if (!auto_movement_)
{ {
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
if (input_->checkInput(InputAction::LEFT)) if (Input::get()->checkInput(InputAction::LEFT))
{ {
vx_ = -0.6f; vx_ = -0.6f;
sprite_->setFlip(SDL_FLIP_HORIZONTAL); sprite_->setFlip(SDL_FLIP_HORIZONTAL);
} }
else if (input_->checkInput(InputAction::RIGHT)) else if (Input::get()->checkInput(InputAction::RIGHT))
{ {
vx_ = 0.6f; vx_ = 0.6f;
sprite_->setFlip(SDL_FLIP_NONE); sprite_->setFlip(SDL_FLIP_NONE);
@@ -119,7 +115,7 @@ void Player::checkInput()
} }
} }
if (input_->checkInput(InputAction::JUMP)) if (Input::get()->checkInput(InputAction::JUMP))
{ {
// Solo puede saltar si ademas de estar (state == s_standing) // Solo puede saltar si ademas de estar (state == s_standing)
// Esta sobre el suelo, rampa o suelo que se mueve // Esta sobre el suelo, rampa o suelo que se mueve
@@ -469,8 +465,8 @@ void Player::move()
collider_box_ = getRect(); // Actualiza el rectangulo de colisión collider_box_ = getRect(); // Actualiza el rectangulo de colisión
#ifdef DEBUG #ifdef DEBUG
debug_->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h)); Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
debug_->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h)); Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h));
#endif #endif
} }
@@ -510,7 +506,7 @@ void Player::playJumpSound()
} }
#ifdef DEBUG #ifdef DEBUG
debug_->add("JUMP: " + std::to_string(jumping_counter_ / 4)); Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4));
#endif #endif
} }
@@ -523,7 +519,7 @@ void Player::playFallSound()
} }
#ifdef DEBUG #ifdef DEBUG
debug_->add("FALL: " + std::to_string(falling_counter_ / 4)); Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4));
#endif #endif
} }
@@ -550,17 +546,17 @@ bool Player::isOnFloor()
#ifdef DEBUG #ifdef DEBUG
if (onFloor) if (onFloor)
{ {
debug_->add("ON_FLOOR"); Debug::get()->add("ON_FLOOR");
} }
if (onSlopeL) if (onSlopeL)
{ {
debug_->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y)); Debug::get()->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y));
} }
if (onSlopeR) if (onSlopeR)
{ {
debug_->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y)); Debug::get()->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y));
} }
#endif #endif
@@ -583,7 +579,7 @@ bool Player::isOnAutoSurface()
#ifdef DEBUG #ifdef DEBUG
if (onAutoSurface) if (onAutoSurface)
{ {
debug_->add("ON_AUTO_SURFACE"); Debug::get()->add("ON_AUTO_SURFACE");
} }
#endif #endif
@@ -609,7 +605,7 @@ bool Player::isOnDownSlope()
#ifdef DEBUG #ifdef DEBUG
if (onSlope) if (onSlope)
{ {
debug_->add("ON_DOWN_SLOPE"); Debug::get()->add("ON_DOWN_SLOPE");
} }
#endif #endif
@@ -744,34 +740,36 @@ void Player::initSprite(const std::string &texture_path, const std::string &anim
// Pinta la información de debug del jugador // Pinta la información de debug del jugador
void Player::renderDebugInfo() void Player::renderDebugInfo()
{ {
if (debug_->getEnabled()) if (Debug::get()->getEnabled())
{ {
auto renderer = Screen::get()->getRenderer();
// Pinta los underfeet // Pinta los underfeet
SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
SDL_RenderDrawPoint(renderer_, under_feet_[0].x, under_feet_[0].y); SDL_RenderDrawPoint(renderer, under_feet_[0].x, under_feet_[0].y);
SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y); SDL_RenderDrawPoint(renderer, under_feet_[1].x, under_feet_[1].y);
// Pinta rectangulo del jugador // Pinta rectangulo del jugador
SDL_SetRenderDrawColor(renderer_, debug_color_.r, debug_color_.g, debug_color_.b, 192); SDL_SetRenderDrawColor(renderer, debug_color_.r, debug_color_.g, debug_color_.b, 192);
SDL_Rect rect = getRect(); SDL_Rect rect = getRect();
SDL_RenderFillRect(renderer_, &rect); SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
SDL_RenderDrawRect(renderer_, &rect); SDL_RenderDrawRect(renderer, &rect);
// Pinta el rectangulo de movimiento // Pinta el rectangulo de movimiento
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
if (vx_ != 0.0f) if (vx_ != 0.0f)
{ {
SDL_RenderFillRect(renderer_, &debug_rect_x_); SDL_RenderFillRect(renderer, &debug_rect_x_);
} }
if (vy_ != 0.0f) if (vy_ != 0.0f)
{ {
SDL_RenderFillRect(renderer_, &debug_rect_y_); SDL_RenderFillRect(renderer, &debug_rect_y_);
} }
// Pinta el punto de debug // Pinta el punto de debug
SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255); SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
SDL_RenderDrawPoint(renderer_, debug_point_.x, debug_point_.y); SDL_RenderDrawPoint(renderer, debug_point_.x, debug_point_.y);
} }
} }
#endif #endif

View File

@@ -63,10 +63,6 @@ public:
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana
Input *input_; // Objeto para gestionar la entrada
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
Debug *debug_; // Objeto para gestionar la información de debug
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
std::shared_ptr<AnimatedSprite> sprite_; // Sprite del jugador std::shared_ptr<AnimatedSprite> sprite_; // Sprite del jugador

View File

@@ -399,11 +399,7 @@ bool setItem(ItemData *item, const std::string &key, const std::string &value)
// Constructor // Constructor
Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data) Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
: screen_(Screen::get()), : data_(data)
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
debug_(Debug::get()),
data_(data)
{ {
auto room = Resource::get()->getRoom(room_path); auto room = Resource::get()->getRoom(room_path);
number_ = room->number; number_ = room->number;
@@ -468,7 +464,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
setAnimatedTiles(); setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación // Crea la textura para el mapa de tiles de la habitación
map_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); map_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
if (map_texture_ == nullptr) if (map_texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -482,7 +478,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
fillMapTexture(); fillMapTexture();
// Establece el color del borde // Establece el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, room->border_color)); Screen::get()->setBorderColor(stringToColor(options.video.palette, room->border_color));
} }
// Destructor // Destructor
@@ -514,9 +510,9 @@ Color Room::getBorderColor()
void Room::fillMapTexture() void Room::fillMapTexture()
{ {
const Color color = stringToColor(options.video.palette, bg_color_); const Color color = stringToColor(options.video.palette, bg_color_);
SDL_SetRenderTarget(renderer_, map_texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), map_texture_);
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo // Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
@@ -538,14 +534,14 @@ void Room::fillMapTexture()
texture_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip); texture_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
#ifdef DEBUG #ifdef DEBUG
if (debug_->getEnabled()) if (Debug::get()->getEnabled())
{ {
if (clip.x != -TILE_SIZE_) if (clip.x != -TILE_SIZE_)
{ {
clip.x = x * TILE_SIZE_; clip.x = x * TILE_SIZE_;
clip.y = y * TILE_SIZE_; clip.y = y * TILE_SIZE_;
SDL_SetRenderDrawColor(renderer_, 64, 64, 64, 224); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 64, 64, 64, 224);
SDL_RenderFillRect(renderer_, &clip); SDL_RenderFillRect(Screen::get()->getRenderer(), &clip);
} }
} }
#endif #endif
@@ -553,16 +549,16 @@ void Room::fillMapTexture()
} }
#ifdef DEBUG #ifdef DEBUG
if (debug_->getEnabled()) if (Debug::get()->getEnabled())
{ {
// BottomSurfaces // BottomSurfaces
if (true) if (true)
{ {
for (auto l : bottom_surfaces_) for (auto l : bottom_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
} }
} }
@@ -571,9 +567,9 @@ void Room::fillMapTexture()
{ {
for (auto l : top_surfaces_) for (auto l : top_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 0, 255, 0, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
} }
} }
@@ -582,9 +578,9 @@ void Room::fillMapTexture()
{ {
for (auto l : left_surfaces_) for (auto l : left_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 128, 128, 255, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 128, 128, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2);
} }
} }
@@ -593,9 +589,9 @@ void Room::fillMapTexture()
{ {
for (auto l : right_surfaces_) for (auto l : right_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 255, 0, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2);
} }
} }
@@ -604,9 +600,9 @@ void Room::fillMapTexture()
{ {
for (auto l : left_slopes_) for (auto l : left_slopes_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2);
} }
} }
@@ -615,9 +611,9 @@ void Room::fillMapTexture()
{ {
for (auto l : right_slopes_) for (auto l : right_slopes_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2);
} }
} }
@@ -626,14 +622,14 @@ void Room::fillMapTexture()
{ {
for (auto l : auto_surfaces_) for (auto l : auto_surfaces_)
{ {
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
} }
} }
} }
#endif #endif
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
} }
// Dibuja el mapa en pantalla // Dibuja el mapa en pantalla
@@ -641,11 +637,11 @@ void Room::renderMap()
{ {
// Dibuja la textura con el mapa en pantalla // Dibuja la textura con el mapa en pantalla
SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
SDL_RenderCopy(renderer_, map_texture_, nullptr, &dest); SDL_RenderCopy(Screen::get()->getRenderer(), map_texture_, nullptr, &dest);
// Dibuja los tiles animados // Dibuja los tiles animados
#ifdef DEBUG #ifdef DEBUG
if (!debug_->getEnabled()) if (!Debug::get()->getEnabled())
{ {
renderAnimatedTiles(); renderAnimatedTiles();
} }
@@ -811,73 +807,19 @@ bool Room::itemCollision(SDL_Rect &rect)
return false; return false;
} }
// Recarga la textura
void Room::reLoadTexture()
{
texture_->reLoad();
fillMapTexture();
for (auto enemy : enemies_)
{
enemy->reLoadTexture();
}
for (auto item : items_)
{
item->reLoadTexture();
}
}
// Recarga la paleta
void Room::reLoadPalette()
{
// Cambia el color de los items
for (auto item : items_)
{
item->setColors(stringToColor(options.video.palette, item_color1_), stringToColor(options.video.palette, item_color2_));
}
// Cambia el color de los enemigos
for (auto enemy : enemies_)
{
enemy->setPalette(options.video.palette);
}
// Establece el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, border_color_));
// Cambia la textura
// texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
// Pone la nueva textura a los tiles animados
for (auto tile : animated_tiles_)
{
tile.sprite->setTexture(texture_);
}
// Recarga las texturas
reLoadTexture();
}
// Obten el tamaño del tile
int Room::getTileSize()
{
return TILE_SIZE_;
}
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
int Room::getSlopeHeight(SDL_Point p, tile_e slope) int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{ {
// Calcula la base del tile // Calcula la base del tile
int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
#ifdef DEBUG #ifdef DEBUG
debug_->add("BASE = " + std::to_string(base)); Debug::get()->add("BASE = " + std::to_string(base));
#endif #endif
// Calcula cuanto se ha entrado en el tile horizontalmente // Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (p.x % TILE_SIZE_); // Esto da un valor entre 0 y 7 const int pos = (p.x % TILE_SIZE_); // Esto da un valor entre 0 y 7
#ifdef DEBUG #ifdef DEBUG
debug_->add("POS = " + std::to_string(pos)); Debug::get()->add("POS = " + std::to_string(pos));
#endif #endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa // Se resta a la base la cantidad de pixeles pos en funcion de la rampa
@@ -885,14 +827,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{ {
base -= pos + 1; base -= pos + 1;
#ifdef DEBUG #ifdef DEBUG
debug_->add("BASE_R = " + std::to_string(base)); Debug::get()->add("BASE_R = " + std::to_string(base));
#endif #endif
} }
else else
{ {
base -= (TILE_SIZE_ - pos); base -= (TILE_SIZE_ - pos);
#ifdef DEBUG #ifdef DEBUG
debug_->add("BASE_L = " + std::to_string(base)); Debug::get()->add("BASE_L = " + std::to_string(base));
#endif #endif
} }

View File

@@ -78,10 +78,6 @@ private:
static constexpr int MAP_HEIGHT_ = 16; // Alto del mapa en tiles static constexpr int MAP_HEIGHT_ = 16; // Alto del mapa en tiles
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
Debug *debug_; // Objeto para gestionar la información de debug
std::vector<std::shared_ptr<Enemy>> enemies_; // Listado con los enemigos de la habitación 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::vector<std::shared_ptr<Item>> items_; // Listado con los items que hay en la habitación
std::shared_ptr<Texture> texture_; // Textura con los graficos de la habitación std::shared_ptr<Texture> texture_; // Textura con los graficos de la habitación
@@ -195,14 +191,8 @@ public:
// Indica si hay colision con un objeto a partir de un rectangulo // Indica si hay colision con un objeto a partir de un rectangulo
bool itemCollision(SDL_Rect &rect); bool itemCollision(SDL_Rect &rect);
// Recarga la textura
void reLoadTexture();
// Recarga la paleta
void reLoadPalette();
// Obten el tamaño del tile // Obten el tamaño del tile
int getTileSize(); int getTileSize() const { return TILE_SIZE_; }
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
int getSlopeHeight(SDL_Point p, tile_e slope); int getSlopeHeight(SDL_Point p, tile_e slope);

View File

@@ -13,24 +13,20 @@
// Constructor // Constructor
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data) Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
: renderer_(Screen::get()->getRenderer()), : data_(data),
resource_(Resource::get()),
asset_(Asset::get()),
data_(data),
clock_(ClockData()) clock_(ClockData())
{ {
const int TEXTURE_WIDTH_ = options.game.width; const int TEXTURE_WIDTH_ = options.game.width;
constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK; constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK;
// Reserva memoria para los objetos // Reserva memoria para los objetos
item_texture_ = resource_->getTexture("items.png"); item_texture_ = Resource::get()->getTexture("items.png");
auto player_texture = resource_->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"); auto player_texture = Resource::get()->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png");
auto player_animations = resource_->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"); auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations); player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations);
player_sprite_->setCurrentAnimation("walk_menu"); player_sprite_->setCurrentAnimation("walk_menu");
text_ = resource_->getText("smb2");
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, TEXTURE_WIDTH_, TEXTURE_HEIGHT_); texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, TEXTURE_WIDTH_, TEXTURE_HEIGHT_);
if (texture_ == nullptr) if (texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -65,7 +61,7 @@ Scoreboard::~Scoreboard()
// Pinta el objeto en pantalla // Pinta el objeto en pantalla
void Scoreboard::render() void Scoreboard::render()
{ {
SDL_RenderCopy(renderer_, texture_, nullptr, &texture_dest_); SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, &texture_dest_);
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
@@ -152,12 +148,12 @@ int Scoreboard::getMinutes()
void Scoreboard::fillTexture() void Scoreboard::fillTexture()
{ {
// Empieza a dibujar en la textura // Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(renderer_, texture_); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
// Limpia la textura // Limpia la textura
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
SDL_RenderFillRect(renderer_, nullptr); SDL_RenderFillRect(Screen::get()->getRenderer(), nullptr);
// Anclas // Anclas
constexpr int LINE1 = BLOCK; constexpr int LINE1 = BLOCK;
@@ -186,17 +182,18 @@ void Scoreboard::fillTexture()
} }
// Escribe los textos // Escribe los textos
const std::string timeTxt = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10); auto text = Resource::get()->getText("smb2");
const std::string itemsTxt = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10); const std::string TIME_TEXT = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10);
text_->writeColored(BLOCK, LINE1, "Items collected ", data_->color); const std::string ITEMS_TEXT = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10);
text_->writeColored(17 * BLOCK, LINE1, itemsTxt, items_color_); text->writeColored(BLOCK, LINE1, "Items collected ", data_->color);
text_->writeColored(20 * BLOCK, LINE1, " Time ", data_->color); text->writeColored(17 * BLOCK, LINE1, ITEMS_TEXT, items_color_);
text_->writeColored(26 * BLOCK, LINE1, timeTxt, stringToColor(options.video.palette, "white")); text->writeColored(20 * BLOCK, LINE1, " Time ", data_->color);
text->writeColored(26 * BLOCK, LINE1, TIME_TEXT, stringToColor(options.video.palette, "white"));
const std::string roomsTxt = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10); const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10);
text_->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor(options.video.palette, "white")); text->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor(options.video.palette, "white"));
text_->writeColored(28 * BLOCK, LINE2, roomsTxt, stringToColor(options.video.palette, "white")); text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor(options.video.palette, "white"));
// Deja el renderizador como estaba // Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
} }

View File

@@ -51,10 +51,6 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
std::shared_ptr<Text> text_; // Objeto para escribir texto
std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite para mostrar las vidas en el marcador
std::shared_ptr<Texture> item_texture_; // Textura con los graficos para las vidas std::shared_ptr<Texture> item_texture_; // Textura con los graficos para las vidas
std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador std::shared_ptr<ScoreboardData> data_; // Contiene las variables a mostrar en el marcador

View File

@@ -50,7 +50,7 @@ void Stats::addDeath(const std::string &name)
// En caso contrario crea la entrada // En caso contrario crea la entrada
else else
{ {
stats_t item; StatsData item;
item.name = name; item.name = name;
item.visited = 0; item.visited = 0;
item.died = 1; item.died = 1;
@@ -71,7 +71,7 @@ void Stats::addVisit(const std::string &name)
// En caso contrario crea la entrada // En caso contrario crea la entrada
else else
{ {
stats_t item; StatsData item;
item.name = name; item.name = name;
item.visited = 1; item.visited = 1;
item.died = 0; item.died = 0;
@@ -80,7 +80,7 @@ void Stats::addVisit(const std::string &name)
} }
// Busca una entrada en la lista por nombre // Busca una entrada en la lista por nombre
int Stats::findByName(const std::string &name, const std::vector<stats_t> &list) int Stats::findByName(const std::string &name, const std::vector<StatsData> &list)
{ {
int i = 0; int i = 0;
@@ -97,7 +97,7 @@ int Stats::findByName(const std::string &name, const std::vector<stats_t> &list)
} }
// Carga las estadisticas desde un fichero // Carga las estadisticas desde un fichero
bool Stats::loadFromFile(const std::string &file_path, std::vector<stats_t> &list) bool Stats::loadFromFile(const std::string &file_path, std::vector<StatsData> &list)
{ {
list.clear(); list.clear();
@@ -117,7 +117,7 @@ bool Stats::loadFromFile(const std::string &file_path, std::vector<stats_t> &lis
// Comprueba que la linea no sea un comentario // Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#") if (line.substr(0, 1) != "#")
{ {
stats_t stat; StatsData stat;
std::stringstream ss(line); std::stringstream ss(line);
std::string tmp; std::string tmp;
@@ -152,7 +152,7 @@ bool Stats::loadFromFile(const std::string &file_path, std::vector<stats_t> &lis
} }
// Guarda las estadisticas en un fichero // Guarda las estadisticas en un fichero
void Stats::saveToFile(const std::string &file_path, const std::vector<stats_t> &list) void Stats::saveToFile(const std::string &file_path, const std::vector<StatsData> &list)
{ {
// Crea y abre el fichero de texto // Crea y abre el fichero de texto
std::ofstream file(file_path); std::ofstream file(file_path);
@@ -203,7 +203,7 @@ void Stats::updateListFromBuffer()
} }
else else
{ // En caso contrario crea la entrada { // En caso contrario crea la entrada
stats_t item; StatsData item;
item.name = buffer.name; item.name = buffer.name;
item.visited = buffer.visited; item.visited = buffer.visited;
item.died = buffer.died; item.died = buffer.died;

View File

@@ -6,34 +6,34 @@
class Stats class Stats
{ {
private: private:
struct stats_t struct StatsData
{ {
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
int visited; // Cuenta las veces que se ha visitado una habitación int visited; // Cuenta las veces que se ha visitado una habitación
int died; // Cuenta las veces que se ha muerto en una habitación int died; // Cuenta las veces que se ha muerto en una habitación
}; };
struct stats_dictionary_t struct StatsDictionary
{ {
std::string number; // Numero de la habitación std::string number; // Numero de la habitación
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
}; };
// Variables // Variables
std::vector<stats_dictionary_t> dictionary; // Lista con la equivalencia nombre-numero de habitacion std::vector<StatsDictionary> dictionary; // Lista con la equivalencia nombre-numero de habitacion
std::vector<stats_t> bufferList; // Lista con las estadisticas temporales por habitación std::vector<StatsData> bufferList; // Lista con las estadisticas temporales por habitación
std::vector<stats_t> list; // Lista con las estadisticas completas por habitación std::vector<StatsData> list; // Lista con las estadisticas completas por habitación
std::string bufferPath; // Fichero con las estadísticas temporales std::string bufferPath; // Fichero con las estadísticas temporales
std::string filePath; // Fichero con las estadísticas completas std::string filePath; // Fichero con las estadísticas completas
// Busca una entrada en la lista por nombre // Busca una entrada en la lista por nombre
int findByName(const std::string &name, const std::vector<stats_t> &list); int findByName(const std::string &name, const std::vector<StatsData> &list);
// Carga las estadisticas desde un fichero // Carga las estadisticas desde un fichero
bool loadFromFile(const std::string &filePath, std::vector<stats_t> &list); bool loadFromFile(const std::string &filePath, std::vector<StatsData> &list);
// Guarda las estadisticas en un fichero // Guarda las estadisticas en un fichero
void saveToFile(const std::string &filePath, const std::vector<stats_t> &list); void saveToFile(const std::string &filePath, const std::vector<StatsData> &list);
// Calcula cual es la habitación con más muertes // Calcula cual es la habitación con más muertes
void checkWorstNightmare(); void checkWorstNightmare();

View File

@@ -23,26 +23,11 @@
// Constructor // Constructor
Title::Title() Title::Title()
: screen_(Screen::get()), : texture_(Resource::get()->getTexture("title_logo.png")),
renderer_(Screen::get()->getRenderer()), sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()))
resource_(Resource::get()),
input_(Input::get())
{ {
// Reserva memoria para los punteros
if (options.video.palette == Palette::ZXSPECTRUM)
{
texture_ = resource_->getTexture("title_logo.png");
}
else if (options.video.palette == Palette::ZXARNE)
{
texture_ = resource_->getTexture("title_logo.png");
}
sprite_ = std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight());
text_ = resource_->getText("smb2");
info_text_ = resource_->getText("subatomic");
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo // Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
bg_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); bg_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (bg_texture_ == nullptr) if (bg_texture_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -53,7 +38,7 @@ Title::Title()
SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND);
// Carga la surface con los gráficos de la pantalla de carga // Carga la surface con los gráficos de la pantalla de carga
pInit(renderer_, 256, 128); pInit(Screen::get()->getRenderer(), 256, 128);
loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str()); loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str());
pLoadPal(Asset::get()->get("loading_screen_color.gif").c_str()); pLoadPal(Asset::get()->get("loading_screen_color.gif").c_str());
pSetSource(loading_screen_); pSetSource(loading_screen_);
@@ -68,7 +53,7 @@ Title::Title()
createCheevosTexture(); createCheevosTexture();
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Rellena la textura de fondo con todos los gráficos // Rellena la textura de fondo con todos los gráficos
fillTexture(); fillTexture();
@@ -137,22 +122,22 @@ void Title::checkInput()
{ {
if (show_cheevos_) if (show_cheevos_)
{ {
if (input_->checkInput(InputAction::DOWN, REPEAT_TRUE)) if (Input::get()->checkInput(InputAction::DOWN, REPEAT_TRUE))
{ {
moveCheevosList(1); moveCheevosList(1);
} }
else if (input_->checkInput(InputAction::UP, REPEAT_TRUE)) else if (Input::get()->checkInput(InputAction::UP, REPEAT_TRUE))
{ {
moveCheevosList(0); moveCheevosList(0);
} }
else if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) else if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
{ {
hideCheevosList(); hideCheevosList();
counter_ = 0; counter_ = 0;
} }
} }
if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
{ {
if (state_ == TitleState::SHOW_LOADING_SCREEN) if (state_ == TitleState::SHOW_LOADING_SCREEN)
{ {
@@ -166,6 +151,8 @@ void Title::checkInput()
// Actualiza la marquesina // Actualiza la marquesina
void Title::updateMarquee() void Title::updateMarquee()
{ {
const auto TEXT = Resource::get()->getText("smb2");
for (int i = 0; i < (int)letters_.size(); ++i) for (int i = 0; i < (int)letters_.size(); ++i)
{ {
if (letters_[i].enabled) if (letters_[i].enabled)
@@ -181,7 +168,7 @@ void Title::updateMarquee()
if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled) if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled)
{ {
letters_[i].enabled = true; letters_[i].enabled = true;
letters_[i].x = letters_[i - 1].x + text_->lenght(letters_[i - 1].letter) + 1; letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1;
} }
} }
} }
@@ -196,11 +183,12 @@ void Title::updateMarquee()
// Dibuja la marquesina // Dibuja la marquesina
void Title::renderMarquee() void Title::renderMarquee()
{ {
const auto TEXT = Resource::get()->getText("smb2");
for (const auto &l : letters_) for (const auto &l : letters_)
{ {
if (l.enabled) if (l.enabled)
{ {
text_->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white")); TEXT->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white"));
} }
} }
} }
@@ -217,7 +205,7 @@ void Title::update()
// Comprueba las entradas // Comprueba las entradas
checkInput(); checkInput();
screen_->update(); Screen::get()->update();
// Incrementa el contador // Incrementa el contador
counter_++; counter_++;
@@ -268,13 +256,13 @@ void Title::update()
void Title::render() void Title::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
screen_->clean(stringToColor(options.video.palette, "black")); Screen::get()->clean(stringToColor(options.video.palette, "black"));
if (state_ == TitleState::SHOW_MENU) if (state_ == TitleState::SHOW_MENU)
{ {
// Dibuja la textura de fondo // Dibuja la textura de fondo
SDL_RenderCopy(renderer_, bg_texture_, nullptr, nullptr); SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr);
// Dibuja la marquesina // Dibuja la marquesina
renderMarquee(); renderMarquee();
@@ -290,14 +278,14 @@ void Title::render()
// Dibuja la pantalla de carga // Dibuja la pantalla de carga
pCls(4); pCls(4);
pBlit(0, 0, 0, 0, 256, 128); pBlit(0, 0, 0, 0, 256, 128);
pFlip(renderer_); pFlip(Screen::get()->getRenderer());
// Dibuja el logo del título // Dibuja el logo del título
sprite_->render(); sprite_->render();
} }
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Bucle para el logo del juego // Bucle para el logo del juego
@@ -333,73 +321,77 @@ void Title::moveCheevosList(int direction)
// Rellena la textura de fondo con todos los gráficos // Rellena la textura de fondo con todos los gráficos
void Title::fillTexture() void Title::fillTexture()
{ {
auto renderer = Screen::get()->getRenderer();
// Coloca el puntero del renderizador sobre la textura // Coloca el puntero del renderizador sobre la textura
SDL_SetRenderTarget(renderer_, bg_texture_); SDL_SetRenderTarget(renderer, bg_texture_);
// Rellena la textura de color // Rellena la textura de color
const Color c = stringToColor(options.video.palette, "black"); const Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer);
// Pinta el gráfico del titulo a partir del sprite // Pinta el gráfico del titulo a partir del sprite
sprite_->render(); sprite_->render();
// Escribe el texto en la textura // Escribe el texto en la textura
const Color textColor = stringToColor(options.video.palette, "green"); auto text = Resource::get()->getText("smb2");
const int textSize = text_->getCharacterSize(); const Color COLOR = stringToColor(options.video.palette, "green");
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor); const int TEXT_SIZE = text->getCharacterSize();
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * TEXT_SIZE, "1.PLAY", 1, COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * textSize, "3.REDEFINE KEYS", 1, textColor); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE, "2.ACHIEVEMENTS", 1, COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * textSize, "ESC.EXIT GAME", 1, textColor); text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * TEXT_SIZE, "3.REDEFINE KEYS", 1, COLOR);
text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * TEXT_SIZE, "ESC.EXIT GAME", 1, COLOR);
// Devuelve el puntero del renderizador a su sitio // Devuelve el puntero del renderizador a su sitio
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(renderer, nullptr);
} }
// Crea y rellena la textura para mostrar los logros // Crea y rellena la textura para mostrar los logros
void Title::createCheevosTexture() void Title::createCheevosTexture()
{ {
// Crea la textura con el listado de logros // Crea la textura con el listado de logros
const auto cheevosList = Cheevos::get()->list(); const auto CHEEVOS_LIST = Cheevos::get()->list();
const auto TEXT = Resource::get()->getText("subatomic");
constexpr int CHEEVOS_TEXTURE_WIDTH = 200; constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = 110; constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = 110;
constexpr int CHEEVOS_TEXTURE_POS_Y = 73; constexpr int CHEEVOS_TEXTURE_POS_Y = 73;
constexpr int CHEEVOS_PADDING = 10; constexpr int CHEEVOS_PADDING = 10;
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (info_text_->getCharacterSize() * 2) + 1; const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * cheevosList.size()) + 2 + info_text_->getCharacterSize() + 8; const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
cheevos_texture_ = std::make_shared<Texture>(renderer_); cheevos_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer());
cheevos_texture_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); cheevos_texture_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
cheevos_texture_->setAsRenderTarget(renderer_); cheevos_texture_->setAsRenderTarget(Screen::get()->getRenderer());
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND); cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la textura con color sólido // Rellena la textura con color sólido
const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black"); const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(Screen::get()->getRenderer());
// Escribe la lista de logros en la textura // Escribe la lista de logros en la textura
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; const std::string CHEEVOS_OWNER = "ACHIEVEMENTS";
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->size()) + ")"; const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
int pos = 2; int pos = 2;
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
pos += info_text_->getCharacterSize(); pos += TEXT->getCharacterSize();
const Color CHEEVO_LOCKED_COLOR = stringToColor(options.video.palette, "white"); const Color CHEEVO_LOCKED_COLOR = stringToColor(options.video.palette, "white");
const Color CHEEVO_UNLOCKED_COLOR = stringToColor(options.video.palette, "bright_green"); const Color CHEEVO_UNLOCKED_COLOR = stringToColor(options.video.palette, "bright_green");
Color cheevoColor; Color cheevoColor;
SDL_SetRenderDrawColor(renderer_, CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF); 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_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1); constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
for (const auto &cheevo : cheevosList) for (const auto &cheevo : CHEEVOS_LIST)
{ {
cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR; cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR;
pos += CHEEVOS_PADDING; pos += CHEEVOS_PADDING;
constexpr int HALF = CHEEVOS_PADDING / 2; constexpr int HALF = CHEEVOS_PADDING / 2;
SDL_RenderDrawLine(renderer_, LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1); SDL_RenderDrawLine(Screen::get()->getRenderer(), LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1);
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor); TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor);
pos += info_text_->getCharacterSize() + 1; pos += TEXT->getCharacterSize() + 1;
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor); TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor);
pos += info_text_->getCharacterSize(); pos += TEXT->getCharacterSize();
} }
// Crea el sprite para el listado de logros // Crea el sprite para el listado de logros

View File

@@ -32,15 +32,9 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos
Input *input_; // Objeto pata gestionar la entrada
std::shared_ptr<Texture> texture_; // Textura con los graficos std::shared_ptr<Texture> texture_; // Textura con los graficos
std::shared_ptr<Sprite> sprite_; // Sprite para manejar la textura std::shared_ptr<Sprite> sprite_; // Sprite para manejar la textura
SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
std::shared_ptr<Text> info_text_; // Objeto para escribir texto en pantalla
std::shared_ptr<Texture> cheevos_texture_; // Textura con la lista de logros std::shared_ptr<Texture> cheevos_texture_; // Textura con la lista de logros
std::shared_ptr<Sprite> cheevos_sprite_; // Sprite para manejar la textura con la lista de logros std::shared_ptr<Sprite> cheevos_sprite_; // Sprite para manejar la textura con la lista de logros