forked from jaildesigner-jailgames/jaildoctors_dilemma
canvi de pc
This commit is contained in:
@@ -37,7 +37,7 @@ Game::Game()
|
||||
cheevos_(Cheevos::get())
|
||||
{
|
||||
// Inicia algunas variables
|
||||
std::make_shared<Surface>(Screen::get()->getGameSurface(), "test.gif");
|
||||
test_surface_ = std::make_shared<Surface>(Screen::get()->getSurface(), "test.gif");
|
||||
board_ = std::make_shared<ScoreboardData>();
|
||||
board_->ini_clock = SDL_GetTicks();
|
||||
#ifdef DEBUG
|
||||
@@ -260,7 +260,6 @@ void Game::update()
|
||||
// Pinta los objetos en pantalla
|
||||
void Game::render()
|
||||
{
|
||||
|
||||
// Prepara para dibujar el frame
|
||||
screen_->start();
|
||||
test_surface_->render(0, 0, 10, 10, 64, 64);
|
||||
|
||||
@@ -52,7 +52,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
// Crea la textura donde se vuelcan las surfaces
|
||||
surface_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
surface_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
if (surface_texture_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
@@ -60,6 +60,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
std::cout << "surface_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
//SDL_SetTextureBlendMode(surface_texture_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
game_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
|
||||
@@ -128,7 +129,9 @@ void Screen::render()
|
||||
// Renderiza sobre gameCanvas los overlays
|
||||
renderNotifications();
|
||||
|
||||
surface_->copyToTexture(renderer_, game_texture_);
|
||||
fillTextureWithColor(renderer_, surface_texture_, 0xFF, 0x00, 0xFF, 0xFF);
|
||||
surface_->copyToTexture(renderer_, surface_texture_);
|
||||
SDL_RenderCopy(renderer_, surface_texture_, nullptr, nullptr);
|
||||
|
||||
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||
if (options.video.border.enabled)
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window_; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
||||
std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
// Getters
|
||||
SDL_Renderer *getRenderer() { return renderer_; }
|
||||
std::shared_ptr<SurfaceData> getGameSurface() { return surface_->getSurface(); }
|
||||
std::shared_ptr<SurfaceData> getSurface() { return surface_->getSurface(); }
|
||||
SDL_Texture *getGameTexture() { return game_texture_; };
|
||||
SDL_Texture *getBorderTexture() { return border_texture_; }
|
||||
};
|
||||
@@ -18,7 +18,9 @@ Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h)
|
||||
Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, std::string file_path)
|
||||
: surface_dest_(surface_dest),
|
||||
surface_(std::make_shared<SurfaceData>(loadSurface(Asset::get()->get(file_path)))),
|
||||
transparent_color_(0) {}
|
||||
transparent_color_(0) {
|
||||
std::cout << "surface loaded: "<< surface_->width << "x" << surface_->height << std::endl;
|
||||
}
|
||||
|
||||
Surface::~Surface() {}
|
||||
|
||||
@@ -84,6 +86,12 @@ void Surface::loadPalette(const std::string &file_path)
|
||||
|
||||
// Copiar los datos de la paleta al std::array
|
||||
std::copy(pal.get(), pal.get() + palette_.size(), palette_.begin());
|
||||
|
||||
for (auto p : palette_)
|
||||
{
|
||||
std::cout << std::hex << p << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// Establece un color en la paleta
|
||||
@@ -125,6 +133,11 @@ Uint8 Surface::getPixel(int x, int y)
|
||||
// Copia una región de la superficie de origen a la de destino
|
||||
void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||
{
|
||||
if (!surface_ || !surface_dest_)
|
||||
{
|
||||
throw std::runtime_error("Surface source or destination is null.");
|
||||
}
|
||||
|
||||
// Limitar la región para evitar accesos fuera de rango
|
||||
w = std::min(w, surface_->width - sx);
|
||||
h = std::min(h, surface_->height - sy);
|
||||
|
||||
@@ -536,4 +536,23 @@ void playMusic(const std::string &music_path)
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic(music_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rellena una textura de un color
|
||||
void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
// Guardar el render target actual
|
||||
SDL_Texture* previous_target = SDL_GetRenderTarget(renderer);
|
||||
|
||||
// Establecer la textura como el render target
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
|
||||
// Establecer el color deseado
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
|
||||
// Pintar toda el área
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Restaurar el render target previo
|
||||
SDL_SetRenderTarget(renderer, previous_target);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <vector>
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL.h> // for SDL_Texture
|
||||
|
||||
|
||||
// Tipos de paleta
|
||||
enum class Palette : int
|
||||
@@ -129,4 +132,7 @@ void printWithDots(const std::string &text1, const std::string &text2, const std
|
||||
bool stringInVector(const std::vector<std::string> &vec, const std::string &str);
|
||||
|
||||
// Hace sonar la música
|
||||
void playMusic(const std::string &music_path);
|
||||
void playMusic(const std::string &music_path);
|
||||
|
||||
// Rellena una textura de un color
|
||||
void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
Reference in New Issue
Block a user