Añadida la clase debug
This commit is contained in:
104
source/debug.cpp
Normal file
104
source/debug.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "debug.h"
|
||||
|
||||
// Constructor
|
||||
Debug::Debug(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
text = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||
|
||||
// Inicializa variables
|
||||
x = 0;
|
||||
y = 0;
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Debug::~Debug()
|
||||
{
|
||||
delete text;
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Debug::update()
|
||||
{
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
void Debug::render()
|
||||
{
|
||||
int y = this->y;
|
||||
int w = 0;
|
||||
|
||||
for (auto s : slot)
|
||||
{
|
||||
text->write(x, y, s);
|
||||
w = (std::max(w, (int)s.length()));
|
||||
y += text->getCharacterSize() + 1;
|
||||
if (y > 192 - text->getCharacterSize())
|
||||
{
|
||||
y = this->y;
|
||||
x += w * text->getCharacterSize() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
y = 0;
|
||||
for (auto l : log)
|
||||
{
|
||||
text->writeColored(x + 10, y, l, {255, 255, 255});
|
||||
y += text->getCharacterSize() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la posición donde se colocará la información de debug
|
||||
void Debug::setPos(SDL_Point p)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
}
|
||||
|
||||
// Añade un texto para mostrar
|
||||
void Debug::add(std::string text)
|
||||
{
|
||||
slot.push_back(text);
|
||||
}
|
||||
|
||||
// Borra la información de debug
|
||||
void Debug::clear()
|
||||
{
|
||||
slot.clear();
|
||||
}
|
||||
|
||||
// Añade un texto para mostrar en el apartado log
|
||||
void Debug::addToLog(std::string text)
|
||||
{
|
||||
log.push_back(text);
|
||||
}
|
||||
|
||||
// Borra la información de debug del apartado log
|
||||
void Debug::clearLog()
|
||||
{
|
||||
log.clear();
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Debug::setEnabled(bool value)
|
||||
{
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Debug::getEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Cambia el valor de la variable
|
||||
void Debug::switchEnabled()
|
||||
{
|
||||
enabled = !enabled;
|
||||
}
|
||||
67
source/debug.h
Normal file
67
source/debug.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
#include "asset.h"
|
||||
#include "text.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
// Clase Debug
|
||||
class Debug
|
||||
{
|
||||
private:
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Text *text; // Objeto encargado de escribir texto en pantalla
|
||||
std::vector<std::string> slot; // Vector con los textos a escribir
|
||||
std::vector<std::string> log; // Vector con los textos a escribir
|
||||
int x; // Posicion donde escribir el texto de debug
|
||||
int y; // Posición donde escribir el texto de debug
|
||||
bool enabled; // Indica si esta activo el modo debug
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Debug(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
||||
|
||||
// Destructor
|
||||
~Debug();
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Dibuja en pantalla
|
||||
void render();
|
||||
|
||||
// Establece la posición donde se colocará la información de debug
|
||||
void setPos(SDL_Point p);
|
||||
|
||||
// Añade un texto para mostrar
|
||||
void add(std::string text);
|
||||
|
||||
// Borra la información de debug
|
||||
void clear();
|
||||
|
||||
// Añade un texto para mostrar en el apartado log
|
||||
void addToLog(std::string text);
|
||||
|
||||
// Borra la información de debug del apartado log
|
||||
void clearLog();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getEnabled();
|
||||
|
||||
// Cambia el valor de la variable
|
||||
void switchEnabled();
|
||||
};
|
||||
|
||||
#endif
|
||||
140
source/game.cpp
140
source/game.cpp
@@ -1,13 +1,15 @@
|
||||
#include "game.h"
|
||||
|
||||
// Constructor
|
||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Debug *debug)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
this->debug = debug;
|
||||
this->debug->setEnabled(true);
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
eventHandler = new SDL_Event();
|
||||
@@ -15,7 +17,6 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
||||
player = new Player(renderer, asset, input, map);
|
||||
enemyEngine = new EnemyEngine(renderer, asset, player, map, asset->get(map->getEnemyFile()));
|
||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
||||
|
||||
// Inicializa variables
|
||||
@@ -25,8 +26,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.subsection = SUBSECTION_GAME_PLAY;
|
||||
|
||||
debug = true;
|
||||
musicEnabled = !debug;
|
||||
musicEnabled = !debug->getEnabled();
|
||||
;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -37,7 +38,6 @@ Game::~Game()
|
||||
delete map;
|
||||
delete player;
|
||||
delete enemyEngine;
|
||||
delete debugText;
|
||||
JA_DeleteMusic(music);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,40 @@ void Game::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Comprueba los eventos de la cola
|
||||
checkEventHandler();
|
||||
|
||||
// Actualiza los objetos
|
||||
debug->clear();
|
||||
map->update();
|
||||
enemyEngine->update();
|
||||
player->update();
|
||||
checkScreenBorders();
|
||||
|
||||
updateDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
void Game::render()
|
||||
{
|
||||
// Prepara para dibujar el frame
|
||||
screen->start();
|
||||
screen->clean();
|
||||
|
||||
// Dibuja los objetos
|
||||
map->render();
|
||||
enemyEngine->render();
|
||||
player->render();
|
||||
renderDebugInfo();
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Comprueba los eventos de la cola
|
||||
void Game::checkEventHandler()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
@@ -92,8 +126,8 @@ void Game::update()
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_D:
|
||||
debug = !debug;
|
||||
musicEnabled = !debug;
|
||||
debug->switchEnabled();
|
||||
musicEnabled = !debug->getEnabled();
|
||||
musicEnabled ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
break;
|
||||
|
||||
@@ -134,41 +168,29 @@ void Game::update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map->update();
|
||||
enemyEngine->update();
|
||||
player->update();
|
||||
checkScreenBorders();
|
||||
checkInput();
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
void Game::render()
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo()
|
||||
{
|
||||
// Prepara para dibujar el frame
|
||||
screen->start();
|
||||
screen->clean();
|
||||
|
||||
// Dibuja los objetos
|
||||
map->render();
|
||||
enemyEngine->render();
|
||||
player->render();
|
||||
renderDebugInfo();
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen->blit();
|
||||
debug->add("R - Reload player and map");
|
||||
debug->add("D - Toggle debug mode");
|
||||
debug->add(std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY()) + "," + std::to_string((int)player->sprite->getWidth()) + "," + std::to_string((int)player->sprite->getHeight()));
|
||||
debug->add("VY " + std::to_string(player->vy) + " " + std::to_string(player->jumpStrenght));
|
||||
debug->add("VX " + std::to_string(player->vx));
|
||||
debug->add("jump_pressed " + std::to_string(player->jumpPressed));
|
||||
debug->add("isOnFloor " + std::to_string(player->isOnFloor()));
|
||||
debug->add("getTile(" + std::to_string(player->underFeet[0].x) + "," + std::to_string(player->underFeet[0].y) + ") = " + std::to_string(player->map->getTile(player->underFeet[0])));
|
||||
debug->add("state " + std::to_string(player->state));
|
||||
debug->add(map->getName() + " (" + map->getRoomFileName(b_top) + ", " + map->getRoomFileName(b_right) + ", " + map->getRoomFileName(b_bottom) + ", " + map->getRoomFileName(b_left) + ")");
|
||||
debug->add("hookedOn = " + std::to_string(player->hookedOnMovingPlatform));
|
||||
debug->add("DIAMONDS = " + std::to_string(player->diamonds));
|
||||
}
|
||||
|
||||
// Comprueba la entrada
|
||||
void Game::checkInput()
|
||||
{
|
||||
}
|
||||
|
||||
// Muestra información de depuración
|
||||
// Pone la información de debug en pantalla
|
||||
void Game::renderDebugInfo()
|
||||
{
|
||||
if (!debug)
|
||||
if (!debug->getEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -184,54 +206,14 @@ void Game::renderDebugInfo()
|
||||
SDL_RenderDrawLine(renderer, i, 0, i, 240);
|
||||
}
|
||||
|
||||
// Pinta el texto
|
||||
const int inc = debugText->getCharacterWidth() + 1;
|
||||
int line = 0;
|
||||
std::string text = "";
|
||||
|
||||
text = "R - Reload player and map";
|
||||
debugText->write(1, 210, text);
|
||||
|
||||
text = "D - Toggle debug mode";
|
||||
debugText->write(1, 216, text);
|
||||
|
||||
text = std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY()) + "," + std::to_string((int)player->sprite->getWidth()) + "," + std::to_string((int)player->sprite->getHeight());
|
||||
debugText->write(0, line, text);
|
||||
|
||||
text = "VY " + std::to_string(player->vy) + " " + std::to_string(player->jumpStrenght);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "VX " + std::to_string(player->vx);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "jump_pressed " + std::to_string(player->jumpPressed);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "isOnFloor " + std::to_string(player->isOnFloor());
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
const std::string foot_x = std::to_string(player->underFeet[0].x);
|
||||
const std::string foot_y = std::to_string(player->underFeet[0].y);
|
||||
const std::string gettile = std::to_string(player->map->getTile(player->underFeet[0]));
|
||||
text = "getTile(" + foot_x + "," + foot_y + ") = " + gettile;
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "state " + std::to_string(player->state);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = map->getName() + " (" + map->getRoomFileName(b_top) + ", " + map->getRoomFileName(b_right) + ", " + map->getRoomFileName(b_bottom) + ", " + map->getRoomFileName(b_left) + ")";
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "hookedOn = " + std::to_string(player->hookedOnMovingPlatform);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "DIAMONDS = " + std::to_string(player->diamonds);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
// Pinta mascaras
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 128);
|
||||
SDL_Rect rect = player->sprite->getRect();
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Pinta el texto
|
||||
debug->setPos({1, 1});
|
||||
debug->render();
|
||||
}
|
||||
|
||||
// Cambia el mapa
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "item_tracker.h"
|
||||
#include "enemy_engine.h"
|
||||
#include "text.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
@@ -23,15 +24,14 @@ private:
|
||||
Input *input; // Objeto Input para gestionar las entradas
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
JA_Music music; // Contiene la musica que se reproduce durante el juego
|
||||
Text *debugText; // Objeto para escribir texto con información de debug
|
||||
Map *map; // Objeto encargado de gestionar el mapeado del juego
|
||||
Player *player; // Objeto para gestionar el jugador
|
||||
ItemTracker *itemTracker; // Objeto para gestionar los items recogidos
|
||||
EnemyEngine *enemyEngine; // Objeto encargado de gestionar los enemigos
|
||||
Debug *debug; // Objeto para gestionar la información de debug
|
||||
section_t section; // Seccion actual dentro del programa
|
||||
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
bool debug; // Indica si esta activo el modo de depuración
|
||||
bool musicEnabled; // Indica si la musica puede sonar o no
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
@@ -40,8 +40,11 @@ private:
|
||||
// Pinta los objetos en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba la entrada
|
||||
void checkInput();
|
||||
// Comprueba los eventos de la cola
|
||||
void checkEventHandler();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void updateDebugInfo();
|
||||
|
||||
// Muestra información de depuración
|
||||
void renderDebugInfo();
|
||||
@@ -54,7 +57,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input);
|
||||
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Debug *debug);
|
||||
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
@@ -650,14 +650,14 @@ void Menu::render()
|
||||
// Establece el rectangulo de fondo del menu y el selector
|
||||
void Menu::setRectSize()
|
||||
{
|
||||
rectBG.rect.w = findWidth() + text->getCharacterWidth();
|
||||
rectBG.rect.h = findHeight() + text->getCharacterWidth();
|
||||
rectBG.rect.w = findWidth() + text->getCharacterSize();
|
||||
rectBG.rect.h = findHeight() + text->getCharacterSize();
|
||||
|
||||
// La posición X es la del menú menos medio caracter
|
||||
rectBG.rect.x = x - (text->getCharacterWidth() / 2);
|
||||
rectBG.rect.x = x - (text->getCharacterSize() / 2);
|
||||
|
||||
// La posición Y es la del menu menos la altura de medio caracter
|
||||
rectBG.rect.y = y - (text->getCharacterWidth() / 2);
|
||||
rectBG.rect.y = y - (text->getCharacterSize() / 2);
|
||||
|
||||
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
|
||||
setSelectorPos(selector.index);
|
||||
@@ -770,7 +770,7 @@ void Menu::setItemCaption(int index, std::string text)
|
||||
{
|
||||
item[index].label = text;
|
||||
item[index].rect.w = this->text->lenght(item[index].label);
|
||||
item[index].rect.h = this->text->getCharacterWidth();
|
||||
item[index].rect.h = this->text->getCharacterSize();
|
||||
reorganize();
|
||||
|
||||
const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w);
|
||||
|
||||
@@ -32,6 +32,7 @@ Prog::Prog(std::string path)
|
||||
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
screen->setBorderColor(borderColor);
|
||||
screen->setVideoMode(options->fullScreenMode);
|
||||
debug = new Debug(renderer, screen, asset);
|
||||
}
|
||||
|
||||
Prog::~Prog()
|
||||
@@ -43,6 +44,7 @@ Prog::~Prog()
|
||||
delete asset;
|
||||
delete input;
|
||||
delete screen;
|
||||
delete debug;
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
@@ -472,7 +474,7 @@ void Prog::runTitle()
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void Prog::runGame()
|
||||
{
|
||||
game = new Game(renderer, screen, asset, input);
|
||||
game = new Game(renderer, screen, asset, input, debug);
|
||||
setSection(game->run());
|
||||
delete game;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "intro.h"
|
||||
#include "title.h"
|
||||
#include "prog.h"
|
||||
#include "debug.h"
|
||||
#include "const.h"
|
||||
|
||||
#ifndef PROG_H
|
||||
@@ -29,6 +30,7 @@ private:
|
||||
Intro *intro; // Objeto encargado de gestionar la intro del juego
|
||||
Logo *logo; // Objeto encargado de gestionar el logo del juego
|
||||
Title *title; // Objeto encargado de gestionar el titulo del juego, con el menu principal
|
||||
Debug *debug; // Objeto para getsionar la información de debug
|
||||
section_t section; // Sección y subsección actual del programa;
|
||||
struct options_t *options; // Contiene las opciones del programa
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "const.h"
|
||||
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -7,9 +7,9 @@
|
||||
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
{
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
mSprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
mSprite->setTexture(texture);
|
||||
mSprite->setRenderer(renderer);
|
||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
sprite->setTexture(texture);
|
||||
sprite->setRenderer(renderer);
|
||||
file = textFile;
|
||||
|
||||
init();
|
||||
@@ -18,12 +18,8 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Text::~Text()
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
@@ -41,11 +37,11 @@ void Text::init()
|
||||
initOffsetFromFile();
|
||||
|
||||
// Inicia los valores del sprite que dibuja las letras
|
||||
mSprite->setWidth(boxWidth);
|
||||
mSprite->setHeight(boxHeight);
|
||||
mSprite->setPosX(0);
|
||||
mSprite->setPosY(0);
|
||||
mSprite->setSpriteClip(0, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
sprite->setWidth(boxWidth);
|
||||
sprite->setHeight(boxHeight);
|
||||
sprite->setPosX(0);
|
||||
sprite->setPosY(0);
|
||||
sprite->setSpriteClip(0, 0, sprite->getWidth(), sprite->getHeight());
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; i++)
|
||||
@@ -53,10 +49,6 @@ void Text::init()
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
|
||||
// printf("Cargando %s\n", file.c_str());
|
||||
// const std::string texto = "w = "+ std::to_string(boxWidth) + ", h = " + std::to_string(boxHeight);
|
||||
// printf("%s\n",texto.c_str());
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
@@ -69,10 +61,10 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
mSprite->setSpriteClip(offset[int(text[i])].x, offset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||
mSprite->setPosX(x + shift);
|
||||
mSprite->setPosY(y);
|
||||
mSprite->render();
|
||||
sprite->setSpriteClip(offset[int(text[i])].x, offset[int(text[i])].y, sprite->getWidth(), sprite->getHeight());
|
||||
sprite->setPosX(x + shift);
|
||||
sprite->setPosY(y);
|
||||
sprite->render();
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
}
|
||||
}
|
||||
@@ -80,17 +72,17 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght)
|
||||
{
|
||||
mSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x, y, text, kerning, lenght);
|
||||
mSprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
}
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght)
|
||||
{
|
||||
mSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
|
||||
mSprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
|
||||
@@ -150,6 +142,8 @@ int Text::lenght(std::string text, int kerning)
|
||||
void Text::initOffsetFromFile()
|
||||
{
|
||||
std::ifstream rfile(file);
|
||||
printf("Reading file %s\n", file.c_str());
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
std::string buffer;
|
||||
@@ -176,11 +170,27 @@ void Text::initOffsetFromFile()
|
||||
buffer.clear();
|
||||
line_read++;
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", file.c_str());
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int Text::getCharacterWidth()
|
||||
int Text::getCharacterSize()
|
||||
{
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
void Text::reLoadTexture()
|
||||
{
|
||||
texture->reLoad();
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
Sprite *mSprite; // Objeto con los graficos para el texto
|
||||
Sprite *sprite; // Objeto con los graficos para el texto
|
||||
|
||||
struct Offset
|
||||
{
|
||||
@@ -62,7 +62,10 @@ public:
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterWidth();
|
||||
int getCharacterSize();
|
||||
|
||||
// Recarga la textura
|
||||
void reLoadTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user