forked from jaildesigner-jailgames/jaildoctors_dilemma
Mejorada la información de debug
This commit is contained in:
@@ -20,6 +20,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
player = new Player(spawnPoint, asset->get("player01.png"), asset->get("player01.ani"), renderer, asset, input, room);
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||
|
||||
// Inicializa variables
|
||||
ticks = 0;
|
||||
@@ -51,6 +52,9 @@ Game::~Game()
|
||||
|
||||
delete text;
|
||||
text = nullptr;
|
||||
|
||||
delete debugText;
|
||||
debugText = nullptr;
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
@@ -151,29 +155,51 @@ void Game::render()
|
||||
text->writeCentered(GAMECANVAS_CENTER_X, 16 * 8, room->getName());
|
||||
|
||||
// Debug info
|
||||
if (debug)
|
||||
{
|
||||
std::string text;
|
||||
text = "status: " + std::to_string(player->status);
|
||||
this->text->write(0, 17 * 8, text);
|
||||
|
||||
text = "foot: " + std::to_string((int)player->getLeftFoot().y);
|
||||
this->text->write(0, 18 * 8, text);
|
||||
|
||||
const int a = (player->lastPosition.y + 16) / 8;
|
||||
const int b = player->getLeftFoot().y / 8;
|
||||
text = "tile: " + std::to_string(a) + " - " + std::to_string(b);
|
||||
this->text->write(0, 19 * 8, text);
|
||||
|
||||
const bool collision = checkPlayerAndEnemies();
|
||||
text = "collision: " + std::to_string(collision);
|
||||
this->text->write(0, 20 * 8, text);
|
||||
}
|
||||
renderDebugInfo();
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void Game::renderDebugInfo()
|
||||
{
|
||||
if (!debug)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Pinta la rejilla
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 64);
|
||||
for (int i = 0; i < PLAY_AREA_BOTTOM; i += 8)
|
||||
{ // Lineas horizontales
|
||||
SDL_RenderDrawLine(renderer, 0, i, PLAY_AREA_RIGHT, i);
|
||||
}
|
||||
for (int i = 0; i < PLAY_AREA_RIGHT; i += 8)
|
||||
{ // Lineas verticales
|
||||
SDL_RenderDrawLine(renderer, i, 0, i, PLAY_AREA_BOTTOM - 1);
|
||||
}
|
||||
|
||||
// Pinta el texto
|
||||
std::string text;
|
||||
int line = (16 * 8) + 3;
|
||||
|
||||
text = "status: " + std::to_string(player->status);
|
||||
debugText->write(0, line += 6, text);
|
||||
|
||||
text = "foot: " + std::to_string((int)player->getLeftFoot().y);
|
||||
debugText->write(0, line += 6, text);
|
||||
|
||||
const int a = (player->lastPosition.y + 16) / 8;
|
||||
const int b = player->getLeftFoot().y / 8;
|
||||
text = "tile: " + std::to_string(a) + " - " + std::to_string(b);
|
||||
debugText->write(0, line += 6, text);
|
||||
|
||||
const bool collision = checkPlayerAndEnemies();
|
||||
text = "collision: " + std::to_string(collision);
|
||||
debugText->write(0, line += 6, text);
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
bool Game::changeRoom(std::string file)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Text *text; // Objeto para los textos del juego
|
||||
Text *debugText; // Objeto para los textos de debug del juego
|
||||
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
section_t section; // Seccion actual dentro del juego
|
||||
@@ -43,6 +44,9 @@ private:
|
||||
// Pinta los objetos en pantalla
|
||||
void render();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void renderDebugInfo();
|
||||
|
||||
// Cambia de habitación
|
||||
bool changeRoom(std::string file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user