forked from jaildesigner-jailgames/jaildoctors_dilemma
Transició a surface: vaig per title.cpp
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for min
|
#include <algorithm> // for min
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
: shining_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani")))
|
: shining_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getSurface("shine.gif"), Resource::get()->getAnimations("shine.ani")))
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
options.section.section = Section::CREDITS;
|
options.section.section = Section::CREDITS;
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text, TEXT_STROKE
|
#include "text.h" // for Text, TEXT_STROKE
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
#include "utils.h" // for Color, stringToColor, Palette
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -240,19 +240,19 @@ void Ending::iniPics()
|
|||||||
|
|
||||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
if (options.video.palette == Palette::ZXSPECTRUM)
|
||||||
{
|
{
|
||||||
pics.push_back({"ending1.png", 48});
|
pics.push_back({"ending1.gif", 48});
|
||||||
pics.push_back({"ending2.png", 26});
|
pics.push_back({"ending2.gif", 26});
|
||||||
pics.push_back({"ending3.png", 29});
|
pics.push_back({"ending3.gif", 29});
|
||||||
pics.push_back({"ending4.png", 63});
|
pics.push_back({"ending4.gif", 63});
|
||||||
pics.push_back({"ending5.png", 53});
|
pics.push_back({"ending5.gif", 53});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pics.push_back({"ending1_zxarne.png", 48});
|
pics.push_back({"ending1_zxarne.gif", 48});
|
||||||
pics.push_back({"ending2_zxarne.png", 26});
|
pics.push_back({"ending2_zxarne.gif", 26});
|
||||||
pics.push_back({"ending3_zxarne.png", 29});
|
pics.push_back({"ending3_zxarne.gif", 29});
|
||||||
pics.push_back({"ending4_zxarne.png", 63});
|
pics.push_back({"ending4_zxarne.gif", 63});
|
||||||
pics.push_back({"ending5_zxarne.png", 53});
|
pics.push_back({"ending5_zxarne.gif", 53});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los sprites
|
// Crea los sprites
|
||||||
@@ -263,7 +263,7 @@ void Ending::iniPics()
|
|||||||
EndingTexture sp;
|
EndingTexture sp;
|
||||||
|
|
||||||
// Crea la texture
|
// Crea la texture
|
||||||
sp.image_texture = Resource::get()->getTexture(pic.caption);
|
sp.image_texture = Resource::get()->getSurface(pic.caption);
|
||||||
const int WIDTH = sp.image_texture->getWidth();
|
const int WIDTH = sp.image_texture->getWidth();
|
||||||
const int HEIGHT = sp.image_texture->getHeight();
|
const int HEIGHT = sp.image_texture->getHeight();
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,17 @@
|
|||||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawPoint, SDL_SetRenderDr...
|
#include <SDL2/SDL_render.h> // for SDL_RenderDrawPoint, SDL_SetRenderDr...
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for max, min, replace
|
#include <algorithm> // for max, min, replace
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X
|
#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||||
#include "moving_sprite.h" // for MovingSprite
|
#include "s_moving_sprite.h" // for MovingSprite
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor
|
#include "utils.h" // for Color, stringToColor
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ void Ending2::loadSprites()
|
|||||||
// Carga los sprites
|
// Carga los sprites
|
||||||
for (const auto &file : sprite_list_)
|
for (const auto &file : sprite_list_)
|
||||||
{
|
{
|
||||||
sprites_.emplace_back(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(file + ".png"), Resource::get()->getAnimations(file + ".ani")));
|
sprites_.emplace_back(std::make_shared<AnimatedSprite>(Resource::get()->getSurface(file + ".gif"), Resource::get()->getAnimations(file + ".ani")));
|
||||||
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
||||||
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "options.h" // for Options, OptionsVideo, options
|
#include "options.h" // for Options, OptionsVideo, options
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Enemy::Enemy(const EnemyData &enemy)
|
Enemy::Enemy(const EnemyData &enemy)
|
||||||
: sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))),
|
: sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getSurface(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))),
|
||||||
color_string_(enemy.color),
|
color_string_(enemy.color),
|
||||||
x1_(enemy.x1),
|
x1_(enemy.x1),
|
||||||
x2_(enemy.x2),
|
x2_(enemy.x2),
|
||||||
|
|||||||
@@ -653,7 +653,7 @@ void Game::checkEndGameCheevos()
|
|||||||
// Inicializa al jugador
|
// Inicializa al jugador
|
||||||
void Game::initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr<Room> room)
|
void Game::initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr<Room> room)
|
||||||
{
|
{
|
||||||
std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif";
|
||||||
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||||
const PlayerData player(spawn_point, player_texture, player_animations, room);
|
const PlayerData player(spawn_point, player_texture, player_animations, room);
|
||||||
player_ = std::make_shared<Player>(player);
|
player_ = std::make_shared<Player>(player);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for min, max
|
#include <algorithm> // for min, max
|
||||||
#include <string> // for basic_string, operator+, to_string, cha...
|
#include <string> // for basic_string, operator+, to_string, cha...
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED
|
#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
: player_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("player_game_over.png"), Resource::get()->getAnimations("player_game_over.ani"))),
|
: player_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getSurface("player_game_over.gif"), Resource::get()->getAnimations("player_game_over.ani"))),
|
||||||
tv_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("tv.png"), Resource::get()->getAnimations("tv.ani"))),
|
tv_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getSurface("tv.gif"), Resource::get()->getAnimations("tv.ani"))),
|
||||||
pre_counter_(0),
|
pre_counter_(0),
|
||||||
counter_(0),
|
counter_(0),
|
||||||
ticks_(0)
|
ticks_(0)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "sprite.h" // Para Sprite
|
#include "s_sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#include "surface.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(ItemData item)
|
Item::Item(ItemData item)
|
||||||
: sprite_(std::make_shared<Sprite>(Resource::get()->getTexture(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)),
|
: sprite_(std::make_shared<Sprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)),
|
||||||
change_color_speed(4)
|
change_color_speed(4)
|
||||||
{
|
{
|
||||||
// Inicia variables
|
// Inicia variables
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
|
|
||||||
struct ItemData
|
struct ItemData
|
||||||
|
|||||||
@@ -12,29 +12,25 @@
|
|||||||
#include "options.h" // for Options, options, OptionsVideo, Section...
|
#include "options.h" // for Options, options, OptionsVideo, Section...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for SSprite
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
#include "utils.h" // for Color, stringToColor, Palette
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen::LoadingScreen()
|
LoadingScreen::LoadingScreen()
|
||||||
|
: mono_loading_screen_surface_(Resource::get()->getSurface("loading_screen_bn.gif")),
|
||||||
|
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
||||||
|
mono_loading_screen_sprite_(std::make_shared<SSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
||||||
|
color_loading_screen_sprite_(std::make_shared<SSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
||||||
|
screen_surface_(std::make_shared<Surface>(Screen::get()->getSurface(), options.game.width, options.game.height))
|
||||||
{
|
{
|
||||||
// Reserva memoria para los punteros
|
// Cambia el destino de las surfaces
|
||||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
mono_loading_screen_surface_->setSurfaceDest(screen_surface_->getSurface());
|
||||||
{
|
color_loading_screen_surface_->setSurfaceDest(screen_surface_->getSurface());
|
||||||
mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn.png");
|
|
||||||
color_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_color.png");
|
|
||||||
}
|
|
||||||
else if (options.video.palette == Palette::ZXARNE)
|
|
||||||
{
|
|
||||||
mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn_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());
|
|
||||||
color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight());
|
|
||||||
|
|
||||||
texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
|
// Configura la superficie donde se van a pintar los sprites
|
||||||
clearTexture();
|
screen_surface_->setColor(0, 0xFF000000);
|
||||||
|
screen_surface_->clear(0);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
options.section.section = Section::LOADING_SCREEN;
|
options.section.section = Section::LOADING_SCREEN;
|
||||||
@@ -65,7 +61,6 @@ LoadingScreen::LoadingScreen()
|
|||||||
LoadingScreen::~LoadingScreen()
|
LoadingScreen::~LoadingScreen()
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
SDL_DestroyTexture(texture_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
@@ -190,7 +185,7 @@ void LoadingScreen::update()
|
|||||||
checkInput();
|
checkInput();
|
||||||
updateCounter();
|
updateCounter();
|
||||||
updateLoad();
|
updateLoad();
|
||||||
fillTexture();
|
renderLoad();
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,8 +205,8 @@ void LoadingScreen::render()
|
|||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
|
|
||||||
// Copila la textura a la pantalla
|
// Copia la surface a la surface de Screen
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, nullptr);
|
screen_surface_->render(0, 0);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
Screen::get()->render();
|
Screen::get()->render();
|
||||||
@@ -238,32 +233,3 @@ void LoadingScreen::run()
|
|||||||
|
|
||||||
JA_SetVolume(128);
|
JA_SetVolume(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja sobre la textura
|
|
||||||
void LoadingScreen::fillTexture()
|
|
||||||
{
|
|
||||||
// Empieza a dibujar en la textura
|
|
||||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
|
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
|
||||||
renderLoad();
|
|
||||||
|
|
||||||
// Deja el renderizador como estaba
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limpia la textura
|
|
||||||
void LoadingScreen::clearTexture()
|
|
||||||
{
|
|
||||||
// Empieza a dibujar en la textura
|
|
||||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_);
|
|
||||||
|
|
||||||
// Limpia
|
|
||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x00, 0x00, 0x00, 0xFF);
|
|
||||||
SDL_RenderClear(Screen::get()->getRenderer());
|
|
||||||
|
|
||||||
// Deja el renderizador como estaba
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
|
||||||
}
|
|
||||||
@@ -4,17 +4,18 @@
|
|||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
class Sprite; // lines 11-11
|
class SSprite; // lines 11-11
|
||||||
class Texture; // lines 12-12
|
class Surface; // lines 12-12
|
||||||
|
|
||||||
class LoadingScreen
|
class LoadingScreen
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<Texture> mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro
|
std::shared_ptr<Surface> mono_loading_screen_surface_; // Surface 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<Surface> color_loading_screen_surface_; // Surface con la pantalla de carga en color
|
||||||
std::shared_ptr<Sprite> mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1
|
std::shared_ptr<SSprite> mono_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture1
|
||||||
std::shared_ptr<Sprite> color_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture2
|
std::shared_ptr<SSprite> color_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture2
|
||||||
|
std::shared_ptr<Surface> screen_surface_; // Surface para dibujar la pantalla de carga
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
||||||
@@ -24,7 +25,6 @@ private:
|
|||||||
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
|
||||||
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
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -50,12 +50,6 @@ private:
|
|||||||
// Dibuja el efecto de carga en el borde
|
// Dibuja el efecto de carga en el borde
|
||||||
void renderBorder();
|
void renderBorder();
|
||||||
|
|
||||||
// Dibuja sobre la textura
|
|
||||||
void fillTexture();
|
|
||||||
|
|
||||||
// Limpia la textura
|
|
||||||
void clearTexture();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen();
|
LoadingScreen();
|
||||||
|
|||||||
@@ -9,24 +9,24 @@
|
|||||||
#include "options.h" // for Options, options, SectionState, Section
|
#include "options.h" // for Options, options, SectionState, Section
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for SSprite
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor
|
#include "utils.h" // for Color, stringToColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: jailgames_texture_(Resource::get()->getTexture("jailgames.png")),
|
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
|
||||||
since_1998_texture_(Resource::get()->getTexture("since_1998.png")),
|
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
|
||||||
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_(std::make_shared<SSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight()))
|
||||||
{
|
{
|
||||||
since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
|
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
|
||||||
since_1998_texture_->setColor(0, 0, 0);
|
//since_1998_surface_->setColor(0, 0, 0);
|
||||||
|
|
||||||
// Crea los sprites de cada linea
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < jailgames_texture_->getHeight(); ++i)
|
for (int i = 0; i < jailgames_surface_->getHeight(); ++i)
|
||||||
{
|
{
|
||||||
jailgames_sprite_.push_back(std::make_shared<Sprite>(jailgames_texture_, 0, i, jailgames_texture_->getWidth(), 1));
|
jailgames_sprite_.push_back(std::make_shared<SSprite>(jailgames_surface_, 0, i, jailgames_surface_->getWidth(), 1));
|
||||||
jailgames_sprite_.back()->setClip(0, i, jailgames_texture_->getWidth(), 1);
|
jailgames_sprite_.back()->setClip(0, i, jailgames_surface_->getWidth(), 1);
|
||||||
jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-181 - (i * 3)));
|
jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-181 - (i * 3)));
|
||||||
jailgames_sprite_.at(i)->setY(83 + i);
|
jailgames_sprite_.at(i)->setY(83 + i);
|
||||||
}
|
}
|
||||||
@@ -98,88 +98,89 @@ void Logo::updateTextureColors()
|
|||||||
{
|
{
|
||||||
constexpr int INI = 70;
|
constexpr int INI = 70;
|
||||||
constexpr int INC = 4;
|
constexpr int INC = 4;
|
||||||
|
/*
|
||||||
if (counter_ == INI + INC * 0)
|
if (counter_ == INI + INC * 0)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
since_1998_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 1)
|
else if (counter_ == INI + INC * 1)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
since_1998_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 2)
|
else if (counter_ == INI + INC * 2)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
since_1998_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 3)
|
else if (counter_ == INI + INC * 3)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
since_1998_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 4)
|
else if (counter_ == INI + INC * 4)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
since_1998_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 5)
|
else if (counter_ == INI + INC * 5)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
since_1998_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 6)
|
else if (counter_ == INI + INC * 6)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
since_1998_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 7)
|
else if (counter_ == INI + INC * 7)
|
||||||
{
|
{
|
||||||
since_1998_texture_->setColor(color_.at(7).r, color_.at(7).g, color_.at(7).b);
|
since_1998_surface_->setColor(color_.at(7).r, color_.at(7).g, color_.at(7).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 0)
|
else if (counter_ == INIT_FADE_ + INC * 0)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
jailgames_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
||||||
since_1998_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
since_1998_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 1)
|
else if (counter_ == INIT_FADE_ + INC * 1)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
jailgames_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
||||||
since_1998_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
since_1998_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 2)
|
else if (counter_ == INIT_FADE_ + INC * 2)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
jailgames_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
||||||
since_1998_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
since_1998_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 3)
|
else if (counter_ == INIT_FADE_ + INC * 3)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
jailgames_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
||||||
since_1998_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
since_1998_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 4)
|
else if (counter_ == INIT_FADE_ + INC * 4)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
jailgames_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
||||||
since_1998_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
since_1998_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 5)
|
else if (counter_ == INIT_FADE_ + INC * 5)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
jailgames_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
||||||
since_1998_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
since_1998_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 6)
|
else if (counter_ == INIT_FADE_ + INC * 6)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
jailgames_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
||||||
since_1998_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
since_1998_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class Sprite; // lines 12-12
|
class SSprite; // lines 12-12
|
||||||
class Texture; // lines 13-13
|
class Surface; // lines 13-13
|
||||||
|
|
||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
@@ -16,10 +16,10 @@ 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
|
||||||
std::shared_ptr<Texture> jailgames_texture_; // Textura con los graficos "JAILGAMES"
|
std::shared_ptr<Surface> jailgames_surface_; // Textura con los graficos "JAILGAMES"
|
||||||
std::shared_ptr<Texture> since_1998_texture_; // Textura con los graficos "Since 1998"
|
std::shared_ptr<Surface> since_1998_surface_; // 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<SSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
std::shared_ptr<Sprite> since_1998_sprite_; // Sprite para manejar la textura2
|
std::shared_ptr<SSprite> since_1998_sprite_; // SSprite para manejar la textura2
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Color> color_; // Vector con los colores para el fade
|
std::vector<Color> color_; // Vector con los colores para el fade
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
#include "options.h" // for Options, options, OptionsNotification
|
#include "options.h" // for Options, options, OptionsNotification
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Notifier *Notifier::notifier_ = nullptr;
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
@@ -36,7 +36,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)
|
||||||
: icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr),
|
: icon_texture_(!icon_file.empty() ? Resource::get()->getSurface(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),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include <algorithm> // for max, min
|
#include <algorithm> // for max, min
|
||||||
#include <cmath> // for ceil, abs
|
#include <cmath> // for ceil, abs
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "debug.h" // for Debug
|
#include "debug.h" // for Debug
|
||||||
#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
|
#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
|
||||||
#include "input.h" // for Input, InputAction
|
#include "input.h" // for Input, InputAction
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "room.h" // for Room, JA_Sound_t, TileType
|
#include "room.h" // for Room, JA_Sound_t, TileType
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(const PlayerData &player)
|
Player::Player(const PlayerData &player)
|
||||||
@@ -715,7 +715,7 @@ void Player::applySpawnValues(const PlayerSpawn &spawn)
|
|||||||
// Inicializa el sprite del jugador
|
// Inicializa el sprite del jugador
|
||||||
void Player::initSprite(const std::string &texture_path, const std::string &animations_path)
|
void Player::initSprite(const std::string &texture_path, const std::string &animations_path)
|
||||||
{
|
{
|
||||||
auto texture = Resource::get()->getTexture(texture_path);
|
auto texture = Resource::get()->getSurface(texture_path);
|
||||||
auto animations = Resource::get()->getAnimations(animations_path);
|
auto animations = Resource::get()->getAnimations(animations_path);
|
||||||
|
|
||||||
sprite_ = std::make_shared<AnimatedSprite>(texture, animations);
|
sprite_ = std::make_shared<AnimatedSprite>(texture, animations);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "defines.h" // for BORDER_TOP, BLOCK
|
#include "defines.h" // for BORDER_TOP, BLOCK
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class Room; // lines 16-16
|
class Room; // lines 16-16
|
||||||
struct JA_Sound_t; // lines 17-17
|
struct JA_Sound_t; // lines 17-17
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void Resource::clear()
|
|||||||
{
|
{
|
||||||
clearSounds();
|
clearSounds();
|
||||||
clearMusics();
|
clearMusics();
|
||||||
textures_.clear();
|
surfaces_.clear();
|
||||||
text_files_.clear();
|
text_files_.clear();
|
||||||
texts_.clear();
|
texts_.clear();
|
||||||
animations_.clear();
|
animations_.clear();
|
||||||
@@ -63,7 +63,7 @@ void Resource::load()
|
|||||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||||
loadSounds();
|
loadSounds();
|
||||||
loadMusics();
|
loadMusics();
|
||||||
loadTextures();
|
loadSurfaces();
|
||||||
loadTextFiles();
|
loadTextFiles();
|
||||||
loadAnimations();
|
loadAnimations();
|
||||||
loadTileMaps();
|
loadTileMaps();
|
||||||
@@ -110,14 +110,14 @@ JA_Music_t *Resource::getMusic(const std::string &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la textura a partir de un nombre
|
// Obtiene la textura a partir de un nombre
|
||||||
std::shared_ptr<Texture> Resource::getTexture(const std::string &name)
|
std::shared_ptr<Surface> Resource::getSurface(const std::string &name)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(textures_.begin(), textures_.end(), [&name](const auto &t)
|
auto it = std::find_if(surfaces_.begin(), surfaces_.end(), [&name](const auto &t)
|
||||||
{ return t.name == name; });
|
{ return t.name == name; });
|
||||||
|
|
||||||
if (it != textures_.end())
|
if (it != surfaces_.end())
|
||||||
{
|
{
|
||||||
return it->texture;
|
return it->surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||||
@@ -238,16 +238,16 @@ void Resource::loadMusics()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las texturas
|
// Carga las texturas
|
||||||
void Resource::loadTextures()
|
void Resource::loadSurfaces()
|
||||||
{
|
{
|
||||||
std::cout << "\n>> TEXTURES" << std::endl;
|
std::cout << "\n>> SURFACES" << std::endl;
|
||||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||||
textures_.clear();
|
surfaces_.clear();
|
||||||
|
|
||||||
for (const auto &l : list)
|
for (const auto &l : list)
|
||||||
{
|
{
|
||||||
auto name = getFileName(l);
|
auto name = getFileName(l);
|
||||||
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
|
surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(Screen::get()->getSurface(), l)));
|
||||||
updateLoadingProgress();
|
updateLoadingProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,16 +330,16 @@ void Resource::createText()
|
|||||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||||
|
|
||||||
std::vector<ResourceInfo> resources = {
|
std::vector<ResourceInfo> resources = {
|
||||||
{"debug", "debug.png", "debug.txt"},
|
{"debug", "debug.gif", "debug.txt"},
|
||||||
{"gauntlet", "gauntlet.png", "gauntlet.txt"},
|
{"gauntlet", "gauntlet.gif", "gauntlet.txt"},
|
||||||
{"smb2", "smb2.png", "smb2.txt"},
|
{"smb2", "smb2.gif", "smb2.txt"},
|
||||||
{"subatomic", "subatomic.png", "subatomic.txt"},
|
{"subatomic", "subatomic.gif", "subatomic.txt"},
|
||||||
{"8bithud", "8bithud.png", "8bithud.txt"}};
|
{"8bithud", "8bithud.gif", "8bithud.txt"}};
|
||||||
|
|
||||||
for (const auto &resource : resources)
|
for (const auto &resource : resources)
|
||||||
{
|
{
|
||||||
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(
|
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(
|
||||||
getTexture(resource.textureFile),
|
getSurface(resource.textureFile),
|
||||||
getTextFile(resource.textFile))));
|
getTextFile(resource.textFile))));
|
||||||
printWithDots("Text : ", resource.key, "[ DONE ]");
|
printWithDots("Text : ", resource.key, "[ DONE ]");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "animated_sprite.h" // for AnimationsFileBuffer
|
#include "s_animated_sprite.h" // for AnimationsFileBuffer
|
||||||
#include "room.h" // for room_t
|
#include "room.h" // for room_t
|
||||||
#include "text.h" // for Text, TextFile
|
#include "text.h" // for Text, TextFile
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Surface
|
||||||
struct JA_Music_t; // lines 11-11
|
struct JA_Music_t; // lines 11-11
|
||||||
struct JA_Sound_t; // lines 12-12
|
struct JA_Sound_t; // lines 12-12
|
||||||
|
|
||||||
@@ -32,15 +32,15 @@ struct ResourceMusic
|
|||||||
: name(name), music(music) {}
|
: name(name), music(music) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para almacenar objetos Texture y su nombre
|
// Estructura para almacenar objetos Surface y su nombre
|
||||||
struct ResourceTexture
|
struct ResourceSurface
|
||||||
{
|
{
|
||||||
std::string name; // Nombre de la textura
|
std::string name; // Nombre de la surface
|
||||||
std::shared_ptr<Texture> texture; // Objeto con la textura
|
std::shared_ptr<Surface> surface; // Objeto con la surface
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
|
ResourceSurface(const std::string &name, std::shared_ptr<Surface> surface)
|
||||||
: name(name), texture(texture) {}
|
: name(name), surface(surface) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para almacenar ficheros TextFile y su nombre
|
// Estructura para almacenar ficheros TextFile y su nombre
|
||||||
@@ -101,14 +101,6 @@ struct ResourceRoom
|
|||||||
// Estructura para llevar la cuenta de los recursos cargados
|
// Estructura para llevar la cuenta de los recursos cargados
|
||||||
struct ResourceCount
|
struct ResourceCount
|
||||||
{
|
{
|
||||||
// int sounds; // Número de sonidos cargados
|
|
||||||
// int musics; // Número de musicas cargadas
|
|
||||||
// int textures; // Número de texturas cargadas
|
|
||||||
// int text_files; // Número de ficheros de texto cargados
|
|
||||||
// int texts; // Número de objetos de texto cargados
|
|
||||||
// int animations; // Número de animaciones cargadas
|
|
||||||
// int tile_maps; // Número de mapas de tiles cargados
|
|
||||||
// int rooms; // Número de habitaciones cargadas
|
|
||||||
int total; // Número total de recursos
|
int total; // Número total de recursos
|
||||||
int loaded; // Número de recursos cargados
|
int loaded; // Número de recursos cargados
|
||||||
|
|
||||||
@@ -141,7 +133,7 @@ private:
|
|||||||
|
|
||||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||||
std::vector<ResourceTexture> textures_; // Vector con las musicas
|
std::vector<ResourceSurface> surfaces_; // Vector con las surfaces
|
||||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||||
@@ -156,8 +148,8 @@ private:
|
|||||||
// Carga las musicas
|
// Carga las musicas
|
||||||
void loadMusics();
|
void loadMusics();
|
||||||
|
|
||||||
// Carga las texturas
|
// Carga las surfaces
|
||||||
void loadTextures();
|
void loadSurfaces();
|
||||||
|
|
||||||
// Carga los ficheros de texto
|
// Carga los ficheros de texto
|
||||||
void loadTextFiles();
|
void loadTextFiles();
|
||||||
@@ -222,8 +214,8 @@ public:
|
|||||||
// Obtiene la música a partir de un nombre
|
// Obtiene la música a partir de un nombre
|
||||||
JA_Music_t *getMusic(const std::string &name);
|
JA_Music_t *getMusic(const std::string &name);
|
||||||
|
|
||||||
// Obtiene la textura a partir de un nombre
|
// Obtiene la surface a partir de un nombre
|
||||||
std::shared_ptr<Texture> getTexture(const std::string &name);
|
std::shared_ptr<Surface> getSurface(const std::string &name);
|
||||||
|
|
||||||
// Obtiene el fichero de texto a partir de un nombre
|
// Obtiene el fichero de texto a partir de un nombre
|
||||||
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
std::shared_ptr<TextFile> getTextFile(const std::string &name);
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "scoreboard.h" // for ScoreboardData
|
#include "scoreboard.h" // for ScoreboardData
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe...
|
#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe...
|
||||||
|
|
||||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||||
@@ -444,7 +444,7 @@ void Room::initializeRoom(const RoomData &room)
|
|||||||
tile_map_file_ = room.tile_map_file;
|
tile_map_file_ = room.tile_map_file;
|
||||||
auto_surface_direction_ = room.auto_surface_direction;
|
auto_surface_direction_ = room.auto_surface_direction;
|
||||||
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
||||||
texture_ = Resource::get()->getTexture(room.tile_set_file);
|
texture_ = Resource::get()->getSurface(room.tile_set_file);
|
||||||
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
|
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
|
||||||
is_paused_ = false;
|
is_paused_ = false;
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "s_animated_sprite.h" // for AnimatedSprite
|
||||||
#include "defines.h" // for BLOCK
|
#include "defines.h" // for BLOCK
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Cheat
|
#include "options.h" // for Options, options, OptionsVideo, Cheat
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||||
@@ -21,8 +21,8 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
|||||||
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::get()->getTexture("items.png");
|
item_texture_ = Resource::get()->getSurface("items.gif");
|
||||||
auto player_texture = Resource::get()->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png");
|
auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif");
|
||||||
auto player_animations = Resource::get()->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");
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture
|
|||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::render()
|
void Screen::render()
|
||||||
{
|
{
|
||||||
|
// Copia la surface a game_texture_
|
||||||
|
surface_->copyToTexture(renderer_, game_texture_);
|
||||||
|
|
||||||
// Renderiza sobre gameCanvas los overlays
|
// Renderiza sobre gameCanvas los overlays
|
||||||
renderNotifications();
|
renderNotifications();
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
|
#include "surface.h" // for Surface
|
||||||
|
#include <memory> // for shared_ptr
|
||||||
|
|
||||||
// Tipos de filtro
|
// Tipos de filtro
|
||||||
enum class ScreenFilter : Uint32
|
enum class ScreenFilter : Uint32
|
||||||
@@ -29,7 +31,7 @@ private:
|
|||||||
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
||||||
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
||||||
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
||||||
// std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int window_width_; // Ancho de la pantalla o ventana
|
int window_width_; // Ancho de la pantalla o ventana
|
||||||
@@ -132,7 +134,7 @@ public:
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
SDL_Renderer *getRenderer() { return renderer_; }
|
SDL_Renderer *getRenderer() { return renderer_; }
|
||||||
// std::shared_ptr<SurfaceData> getSurface() { return surface_->getSurface(); }
|
std::shared_ptr<SurfaceData> getSurface() { return surface_->getSurface(); }
|
||||||
SDL_Texture *getGameTexture() { return game_texture_; };
|
SDL_Texture *getGameTexture() { return game_texture_; };
|
||||||
SDL_Texture *getBorderTexture() { return border_texture_; }
|
SDL_Texture *getBorderTexture() { return border_texture_; }
|
||||||
};
|
};
|
||||||
@@ -98,11 +98,11 @@ void Surface::setColor(int index, Uint32 color)
|
|||||||
palette_.at(index) = color;
|
palette_.at(index) = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la superficie de destino con un color
|
// Rellena la superficie con un color
|
||||||
void Surface::clear(std::shared_ptr<SurfaceData> surface, Uint8 color)
|
void Surface::clear(Uint8 color)
|
||||||
{
|
{
|
||||||
const size_t total_pixels = surface->width * surface->height;
|
const size_t total_pixels = surface_->width * surface_->height;
|
||||||
std::fill(surface->data, surface->data + total_pixels, color);
|
std::fill(surface_->data, surface_->data + total_pixels, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone un pixel en la superficie de destino
|
// Pone un pixel en la superficie de destino
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ public:
|
|||||||
// Establece un color en la paleta
|
// Establece un color en la paleta
|
||||||
void setColor(int index, Uint32 color);
|
void setColor(int index, Uint32 color);
|
||||||
|
|
||||||
// Limpia la superficie de destino con un color
|
// Rellena la superficie con un color
|
||||||
void clear(std::shared_ptr<SurfaceData> surface, Uint8 color);
|
void clear(Uint8 color);
|
||||||
|
|
||||||
// Vuelca la superficie a una textura
|
// Vuelca la superficie a una textura
|
||||||
void copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture);
|
void copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture);
|
||||||
@@ -106,4 +106,10 @@ public:
|
|||||||
int getTransparentColor() const { return transparent_color_; }
|
int getTransparentColor() const { return transparent_color_; }
|
||||||
int getWidth() const { return surface_->width; }
|
int getWidth() const { return surface_->width; }
|
||||||
int getHeight() const { return surface_->height; }
|
int getHeight() const { return surface_->height; }
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
void setTransparentColor(int color) { transparent_color_ = color; }
|
||||||
|
void setSurfaceDest(std::shared_ptr<SurfaceData> surface_dest) { surface_dest_ = surface_dest; }
|
||||||
|
void setPalette(const std::array<Uint32, 256> &palette) { palette_ = palette; }
|
||||||
|
void setSurface(std::shared_ptr<SurfaceData> surface) { surface_ = surface; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#include <iostream> // Para cerr
|
#include <iostream> // Para cerr
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "sprite.h" // Para Sprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "texture.h" // Para Texture
|
#include "surface.h" // Para Surface
|
||||||
#include "utils.h" // Para Color, getFileName, printWithDots
|
#include "utils.h" // Para Color, getFileName, printWithDots
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
@@ -80,7 +80,7 @@ std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file)
|
Text::Text(std::shared_ptr<Surface> surface, const std::string &text_file)
|
||||||
{
|
{
|
||||||
// Carga los offsets desde el fichero
|
// Carga los offsets desde el fichero
|
||||||
auto tf = loadTextFile(text_file);
|
auto tf = loadTextFile(text_file);
|
||||||
@@ -96,14 +96,14 @@ Text::Text(std::shared_ptr<Texture> texture, const std::string &text_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
|
sprite_ = std::make_unique<SSprite>(surface, (SDL_Rect){0, 0, box_width_, box_height_});
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
fixed_width_ = false;
|
fixed_width_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file)
|
Text::Text(std::shared_ptr<Surface> surface, std::shared_ptr<TextFile> text_file)
|
||||||
{
|
{
|
||||||
// Inicializa variables desde la estructura
|
// Inicializa variables desde la estructura
|
||||||
box_height_ = text_file->box_height;
|
box_height_ = text_file->box_height;
|
||||||
@@ -116,7 +116,7 @@ Text::Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
|
sprite_ = std::make_unique<SSprite>(surface, (SDL_Rect){0, 0, box_width_, box_height_});
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
fixed_width_ = false;
|
fixed_width_ = false;
|
||||||
@@ -141,71 +141,58 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe texto en pantalla
|
// Escribe el texto en una surface
|
||||||
void Text::write2X(int x, int y, const std::string &text, int kerning)
|
std::shared_ptr<Surface> Text::writeToSurface(const std::string &text, int zoom, int kerning)
|
||||||
{
|
|
||||||
int shift = 0;
|
|
||||||
for (size_t i = 0; i < text.length(); ++i)
|
|
||||||
{
|
|
||||||
auto index = static_cast<size_t>(text[i]);
|
|
||||||
SDL_Rect rect = {offset_[index].x, offset_[index].y, box_width_, box_height_};
|
|
||||||
sprite_->getTexture()->render(x + shift, y, &rect, 2.0f, 2.0f);
|
|
||||||
shift += (offset_[index].w + kerning) * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto en una textura
|
|
||||||
std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int zoom, int kerning)
|
|
||||||
{
|
{
|
||||||
auto renderer = Screen::get()->getRenderer();
|
auto renderer = Screen::get()->getRenderer();
|
||||||
auto texture = std::make_shared<Texture>(renderer);
|
auto surface = std::make_shared<Surface>(renderer);
|
||||||
auto width = lenght(text, kerning) * zoom;
|
auto width = lenght(text, kerning) * zoom;
|
||||||
auto height = box_height_ * zoom;
|
auto height = box_height_ * zoom;
|
||||||
auto temp = SDL_GetRenderTarget(renderer);
|
auto temp = SDL_GetRenderTarget(renderer);
|
||||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
//surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
//surface->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
texture->setAsRenderTarget(renderer);
|
//surface->setAsRenderTarget(renderer);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
//zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
|
||||||
return texture;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto con extras en una textura
|
// Escribe el texto con extras en una surface
|
||||||
std::shared_ptr<Texture> Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
std::shared_ptr<Surface> Text::writeDXToSurface(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
|
||||||
{
|
{
|
||||||
auto renderer = Screen::get()->getRenderer();
|
auto renderer = Screen::get()->getRenderer();
|
||||||
auto texture = std::make_shared<Texture>(renderer);
|
auto surface = std::make_shared<Surface>(renderer);
|
||||||
auto width = Text::lenght(text, kerning) + shadow_distance;
|
auto width = Text::lenght(text, kerning) + shadow_distance;
|
||||||
auto height = box_height_ + shadow_distance;
|
auto height = box_height_ + shadow_distance;
|
||||||
auto temp = SDL_GetRenderTarget(renderer);
|
auto temp = SDL_GetRenderTarget(renderer);
|
||||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
//surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
//surface->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
texture->setAsRenderTarget(renderer);
|
//surface->setAsRenderTarget(renderer);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
|
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
|
||||||
return texture;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto con colores
|
// Escribe el texto con colores
|
||||||
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
//sprite_->getSurface()->setColor(color.r, color.g, color.b);
|
||||||
write(x, y, text, kerning, lenght);
|
write(x, y, text, kerning, lenght);
|
||||||
sprite_->getTexture()->setColor(255, 255, 255);
|
//sprite_->getSurface()->setColor(255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto con sombra
|
// Escribe el texto con sombra
|
||||||
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght)
|
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
//sprite_->getSurface()->setColor(color.r, color.g, color.b);
|
||||||
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
|
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
|
||||||
sprite_->getTexture()->setColor(255, 255, 255);
|
//sprite_->getSurface()->setColor(255, 255, 255);
|
||||||
write(x, y, text, kerning, lenght);
|
write(x, y, text, kerning, lenght);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,23 +262,8 @@ int Text::getCharacterSize() const
|
|||||||
return box_width_;
|
return box_width_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void Text::reLoadTexture()
|
|
||||||
{
|
|
||||||
sprite_->getTexture()->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void Text::setFixedWidth(bool value)
|
void Text::setFixedWidth(bool value)
|
||||||
{
|
{
|
||||||
fixed_width_ = value;
|
fixed_width_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece una paleta
|
|
||||||
void Text::setPalette(int number)
|
|
||||||
{
|
|
||||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
|
||||||
//sprite_->getTexture()->setPalette(number);
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
|
||||||
}
|
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <memory> // Para unique_ptr, shared_ptr
|
#include <memory> // Para unique_ptr, shared_ptr
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include "sprite.h" // Para Sprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "utils.h" // Para Color
|
#include "utils.h" // Para Color
|
||||||
class Texture; // lines 9-9
|
class Surface; // lines 9-9
|
||||||
|
|
||||||
constexpr int TEXT_COLOR = 1;
|
constexpr int TEXT_COLOR = 1;
|
||||||
constexpr int TEXT_SHADOW = 2;
|
constexpr int TEXT_SHADOW = 2;
|
||||||
@@ -32,7 +32,7 @@ class Text
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::unique_ptr<Sprite> sprite_ = nullptr; // Objeto con los graficos para el texto
|
std::unique_ptr<SSprite> sprite_ = nullptr; // Objeto con los graficos para el texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int box_width_ = 0; // Anchura de la caja de cada caracter en el png
|
int box_width_ = 0; // Anchura de la caja de cada caracter en el png
|
||||||
@@ -42,21 +42,20 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Text(std::shared_ptr<Texture> texture, const std::string &text_file);
|
Text(std::shared_ptr<Surface> surface, const std::string &text_file);
|
||||||
Text(std::shared_ptr<Texture> texture, std::shared_ptr<TextFile> text_file);
|
Text(std::shared_ptr<Surface> surface, std::shared_ptr<TextFile> text_file);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Text() = default;
|
~Text() = default;
|
||||||
|
|
||||||
// Escribe el texto en pantalla
|
// Escribe el texto en pantalla
|
||||||
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
|
||||||
void write2X(int x, int y, const std::string &text, int kerning = 1);
|
|
||||||
|
|
||||||
// Escribe el texto en una textura
|
// Escribe el texto en una textura
|
||||||
std::shared_ptr<Texture> writeToTexture(const std::string &text, int zoom = 1, int kerning = 1);
|
std::shared_ptr<Surface> writeToSurface(const std::string &text, int zoom = 1, int kerning = 1);
|
||||||
|
|
||||||
// Escribe el texto con extras en una textura
|
// Escribe el texto con extras en una textura
|
||||||
std::shared_ptr<Texture> writeDXToTexture(Uint8 flags, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1);
|
std::shared_ptr<Surface> writeDXToSurface(Uint8 flags, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1);
|
||||||
|
|
||||||
// Escribe el texto con colores
|
// Escribe el texto con colores
|
||||||
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1);
|
||||||
@@ -76,12 +75,6 @@ public:
|
|||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int getCharacterSize() const;
|
int getCharacterSize() const;
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void reLoadTexture();
|
|
||||||
|
|
||||||
// Establece si se usa un tamaño fijo de letra
|
// Establece si se usa un tamaño fijo de letra
|
||||||
void setFixedWidth(bool value);
|
void setFixedWidth(bool value);
|
||||||
|
|
||||||
// Establece una paleta
|
|
||||||
void setPalette(int number);
|
|
||||||
};
|
};
|
||||||
@@ -15,21 +15,18 @@
|
|||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "s_sprite.h" // for SSprite
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "texture.h" // for Texture
|
#include "surface.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
#include "utils.h" // for Color, stringToColor, Palette
|
||||||
#include "paleta.h"
|
#include "paleta.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
: texture_(Resource::get()->getTexture("title_logo.png")),
|
: surface_(Resource::get()->getSurface("title_logo.gif")),
|
||||||
sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()))
|
sprite_(std::make_shared<SSprite>(surface_, 0, 0, surface_->getWidth(), surface_->getHeight())),
|
||||||
|
bg_surface_(std::make_shared<Surface>(Screen::get()->getSurface(), options.game.width, options.game.height))
|
||||||
{
|
{
|
||||||
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
|
|
||||||
bg_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
|
|
||||||
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(Screen::get()->getRenderer(), 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());
|
||||||
@@ -49,7 +46,7 @@ Title::Title()
|
|||||||
Screen::get()->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();
|
fillSurface();
|
||||||
|
|
||||||
// Inicia la musica
|
// Inicia la musica
|
||||||
playMusic("title.ogg");
|
playMusic("title.ogg");
|
||||||
@@ -59,7 +56,7 @@ Title::Title()
|
|||||||
Title::~Title()
|
Title::~Title()
|
||||||
{
|
{
|
||||||
pDeleteSurface(loading_screen_);
|
pDeleteSurface(loading_screen_);
|
||||||
SDL_DestroyTexture(bg_texture_);
|
SDL_DestroyTexture(bg_surface_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa la marquesina
|
// Inicializa la marquesina
|
||||||
@@ -255,7 +252,7 @@ void Title::render()
|
|||||||
if (state_ == TitleState::SHOW_MENU)
|
if (state_ == TitleState::SHOW_MENU)
|
||||||
{
|
{
|
||||||
// Dibuja la textura de fondo
|
// Dibuja la textura de fondo
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr);
|
SDL_RenderCopy(Screen::get()->getRenderer(), bg_surface_, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja la marquesina
|
// Dibuja la marquesina
|
||||||
renderMarquee();
|
renderMarquee();
|
||||||
@@ -296,28 +293,28 @@ void Title::run()
|
|||||||
void Title::moveCheevosList(int direction)
|
void Title::moveCheevosList(int direction)
|
||||||
{
|
{
|
||||||
const int speed = 2;
|
const int speed = 2;
|
||||||
cheevos_texture_view_.y = direction == 0 ? cheevos_texture_view_.y - speed : cheevos_texture_view_.y + speed;
|
cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - speed : cheevos_surface_view_.y + speed;
|
||||||
|
|
||||||
const int bottom = cheevos_texture_->getHeight() - cheevos_texture_view_.h;
|
const int bottom = cheevos_surface_->getHeight() - cheevos_surface_view_.h;
|
||||||
if (cheevos_texture_view_.y < 0)
|
if (cheevos_surface_view_.y < 0)
|
||||||
{
|
{
|
||||||
cheevos_texture_view_.y = 0;
|
cheevos_surface_view_.y = 0;
|
||||||
}
|
}
|
||||||
else if (cheevos_texture_view_.y > bottom)
|
else if (cheevos_surface_view_.y > bottom)
|
||||||
{
|
{
|
||||||
cheevos_texture_view_.y = bottom;
|
cheevos_surface_view_.y = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
cheevos_sprite_->setClip(cheevos_texture_view_);
|
cheevos_sprite_->setClip(cheevos_surface_view_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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::fillSurface()
|
||||||
{
|
{
|
||||||
auto renderer = Screen::get()->getRenderer();
|
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_surface_);
|
||||||
|
|
||||||
// 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");
|
||||||
@@ -352,10 +349,10 @@ void Title::createCheevosTexture()
|
|||||||
constexpr int CHEEVOS_PADDING = 10;
|
constexpr int CHEEVOS_PADDING = 10;
|
||||||
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
|
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
|
||||||
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
|
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
|
||||||
cheevos_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer());
|
cheevos_surface_ = std::make_shared<Texture>(Screen::get()->getRenderer());
|
||||||
cheevos_texture_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
cheevos_surface_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
cheevos_texture_->setAsRenderTarget(Screen::get()->getRenderer());
|
cheevos_surface_->setAsRenderTarget(Screen::get()->getRenderer());
|
||||||
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
|
cheevos_surface_->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");
|
||||||
@@ -366,7 +363,7 @@ void Title::createCheevosTexture()
|
|||||||
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()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
|
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
|
||||||
int pos = 2;
|
int pos = 2;
|
||||||
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_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
|
||||||
pos += 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");
|
||||||
@@ -388,15 +385,15 @@ void Title::createCheevosTexture()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea el sprite para el listado de logros
|
// Crea el sprite para el listado de logros
|
||||||
cheevos_sprite_ = std::make_shared<Sprite>(cheevos_texture_, (GAMECANVAS_WIDTH - cheevos_texture_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_texture_->getWidth(), cheevos_texture_->getHeight());
|
cheevos_sprite_ = std::make_shared<SSprite>(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());
|
||||||
cheevos_texture_view_ = {0, 0, cheevos_texture_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
cheevos_surface_view_ = {0, 0, cheevos_surface_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
||||||
cheevos_sprite_->setClip(cheevos_texture_view_);
|
cheevos_sprite_->setClip(cheevos_surface_view_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Oculta la lista de logros
|
// Oculta la lista de logros
|
||||||
void Title::hideCheevosList()
|
void Title::hideCheevosList()
|
||||||
{
|
{
|
||||||
show_cheevos_ = false;
|
show_cheevos_ = false;
|
||||||
cheevos_texture_view_.y = 0;
|
cheevos_surface_view_.y = 0;
|
||||||
cheevos_sprite_->setClip(cheevos_texture_view_);
|
cheevos_sprite_->setClip(cheevos_surface_view_);
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "paleta.h" // for jSurface
|
#include "paleta.h" // for jSurface
|
||||||
class Sprite; // lines 13-13
|
class SSprite; // lines 13-13
|
||||||
class Texture; // lines 15-15
|
class Surface; // lines 15-15
|
||||||
|
|
||||||
class Title
|
class Title
|
||||||
{
|
{
|
||||||
@@ -28,11 +28,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<Texture> texture_; // Textura con los graficos
|
std::shared_ptr<Surface> surface_; // Textura con los graficos
|
||||||
std::shared_ptr<Sprite> sprite_; // Sprite para manejar la textura
|
std::shared_ptr<SSprite> sprite_; // SSprite para manejar la surface
|
||||||
SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla
|
std::shared_ptr<Surface> bg_surface_; // Textura para dibujar el fondo de la pantalla
|
||||||
std::shared_ptr<Texture> cheevos_texture_; // Textura con la lista de logros
|
std::shared_ptr<Surface> cheevos_surface_; // 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<SSprite> cheevos_sprite_; // SSprite para manejar la surface con la lista de logros
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter_ = 0; // Contador
|
int counter_ = 0; // Contador
|
||||||
@@ -41,7 +41,7 @@ private:
|
|||||||
std::vector<TitleLetter> letters_; // Vector con las letras de la marquesina
|
std::vector<TitleLetter> letters_; // Vector con las letras de la marquesina
|
||||||
int marquee_speed_ = 3; // Velocidad de desplazamiento de la marquesina
|
int marquee_speed_ = 3; // Velocidad de desplazamiento de la marquesina
|
||||||
bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros
|
bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros
|
||||||
SDL_Rect cheevos_texture_view_; // Zona visible de la textura con el listado de logros
|
SDL_Rect cheevos_surface_view_; // Zona visible de la surface con el listado de logros
|
||||||
TitleState state_; // Estado en el que se encuentra el bucle principal
|
TitleState state_; // Estado en el que se encuentra el bucle principal
|
||||||
jSurface loading_screen_; // Surface con los gráficos de la pantalla de carga
|
jSurface loading_screen_; // Surface con los gráficos de la pantalla de carga
|
||||||
|
|
||||||
@@ -69,10 +69,10 @@ private:
|
|||||||
// Desplaza la lista de logros
|
// Desplaza la lista de logros
|
||||||
void moveCheevosList(int direction);
|
void moveCheevosList(int direction);
|
||||||
|
|
||||||
// Rellena la textura de fondo con todos los gráficos
|
// Rellena la surface de fondo con todos los gráficos
|
||||||
void fillTexture();
|
void fillSurface();
|
||||||
|
|
||||||
// Crea y rellena la textura para mostrar los logros
|
// Crea y rellena la surface para mostrar los logros
|
||||||
void createCheevosTexture();
|
void createCheevosTexture();
|
||||||
|
|
||||||
// Oculta la lista de logros
|
// Oculta la lista de logros
|
||||||
|
|||||||
Reference in New Issue
Block a user