Mejorada la información de debug

This commit is contained in:
2022-08-30 20:35:53 +02:00
parent 8616c3e165
commit 38c41193ec
3 changed files with 142 additions and 112 deletions

View File

@@ -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)
{