forked from jaildesigner-jailgames/jaildoctors_dilemma
El nombre de la habitación se pinta a partir de una textura
This commit is contained in:
@@ -42,6 +42,25 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
|
||||
stats = new Stats(asset->get("stats.csv"), asset->get("stats_buffer.csv"), options);
|
||||
|
||||
// Crea la textura para poner el nombre de la habitación
|
||||
roomNameTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text->getCharacterSize() * 2);
|
||||
if (roomNameTexture == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el blend mode de la textura
|
||||
SDL_SetTextureBlendMode(roomNameTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Establece el destino de la textura
|
||||
roomNameRect = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text->getCharacterSize() * 2};
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
fillRoomNameTexture();
|
||||
|
||||
// Inicializa el resto de variables
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
@@ -78,6 +97,8 @@ Game::~Game()
|
||||
delete text;
|
||||
delete stats;
|
||||
|
||||
SDL_DestroyTexture(roomNameTexture);
|
||||
|
||||
JA_DeleteMusic(music);
|
||||
JA_DeleteSound(deathSound);
|
||||
}
|
||||
@@ -317,13 +338,8 @@ void Game::renderDebugInfo()
|
||||
// Escribe el nombre de la pantalla
|
||||
void Game::renderRoomName()
|
||||
{
|
||||
// Texto en el centro de la pantalla
|
||||
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
|
||||
color_t color = stringToColor(options->palette, "white");
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room->getName(), 1, room->getBGColor());
|
||||
// Dibuja la textura con el nombre de la habitación
|
||||
SDL_RenderCopy(renderer, roomNameTexture, nullptr, &roomNameRect);
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
@@ -345,6 +361,9 @@ bool Game::changeRoom(std::string file)
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, board.jailEnabled, debug);
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
fillRoomNameTexture();
|
||||
|
||||
// Pone el color del marcador en función del color del borde de la habitación
|
||||
setScoreBoardColor();
|
||||
|
||||
@@ -637,3 +656,21 @@ void Game::initStats()
|
||||
|
||||
stats->init();
|
||||
}
|
||||
|
||||
// Crea la textura con el nombre de la habitación
|
||||
void Game::fillRoomNameTexture()
|
||||
{
|
||||
// Pone la textura como destino de renderizado
|
||||
SDL_SetRenderTarget(renderer, roomNameTexture);
|
||||
|
||||
// Rellena la textura de color
|
||||
const color_t color = stringToColor(options->palette, "white");
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto en la textura
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room->getName(), 1, room->getBGColor());
|
||||
|
||||
// Deja el renderizador por defecto
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
@@ -41,20 +41,22 @@ private:
|
||||
Debug *debug; // Objeto para gestionar la información de debug
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
Stats *stats; // Objeto encargado de gestionar las estadísticas
|
||||
SDL_Texture *roomNameTexture; // Textura para escribir el nombre de la habitación
|
||||
|
||||
// Variables
|
||||
JA_Music_t* music; // Musica que suena durante el juego
|
||||
JA_Music_t *music; // Musica que suena durante el juego
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
section_t section; // Seccion actual dentro del juego
|
||||
std::string currentRoom; // Fichero de la habitación actual
|
||||
playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
||||
JA_Sound_t* deathSound; // Sonido a reproducir cuando muere el jugador
|
||||
JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador
|
||||
board_t board; // Estructura con los datos del marcador
|
||||
bool paused; // Indica si el juego se encuentra en pausa
|
||||
bool blackScreen; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||
int blackScreenCounter; // Contador para temporizar la pantalla en negro
|
||||
int totalItems; // Cantidad total de items que hay en el mapeado del juego
|
||||
SDL_Rect roomNameRect; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void update();
|
||||
@@ -133,6 +135,9 @@ private:
|
||||
// Inicializa el diccionario de las estadísticas
|
||||
void initStats();
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
void fillRoomNameTexture();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);
|
||||
|
||||
Reference in New Issue
Block a user