forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida la clase debug
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#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)
|
||||
{
|
||||
// Inicia algunas variables
|
||||
clock = SDL_GetTicks();
|
||||
@@ -16,6 +16,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
this->asset = asset;
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
this->debug = debug;
|
||||
|
||||
// Crea los objetos
|
||||
scoreboard = new ScoreBoard(renderer, asset, &playerLives, &itemsPicked, &clock);
|
||||
@@ -33,9 +34,9 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
playerLives = 9;
|
||||
itemsPicked = 0;
|
||||
|
||||
debug = true;
|
||||
player->setInvincible(debug);
|
||||
musicEnabled = !debug;
|
||||
debugEnabled = true;
|
||||
player->setInvincible(debugEnabled);
|
||||
musicEnabled = !debugEnabled;
|
||||
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.subsection = SUBSECTION_GAME_PLAY;
|
||||
@@ -93,9 +94,9 @@ void Game::checkEventHandler()
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_D:
|
||||
debug = !debug;
|
||||
player->setInvincible(debug);
|
||||
musicEnabled = !debug;
|
||||
debugEnabled = !debugEnabled;
|
||||
player->setInvincible(debugEnabled);
|
||||
musicEnabled = !debugEnabled;
|
||||
musicEnabled ? JA_PlayMusic(music) : JA_StopMusic();
|
||||
break;
|
||||
|
||||
@@ -171,16 +172,14 @@ void Game::update()
|
||||
checkEventHandler();
|
||||
|
||||
// Actualiza los objetos
|
||||
debug->clear();
|
||||
room->update();
|
||||
{
|
||||
player->update();
|
||||
// checkPlayerAndWalls(); // Debe ir detras del player update, por si se ha metido en algun muro
|
||||
}
|
||||
player->update();
|
||||
checkPlayerOnBorder();
|
||||
// checkPlayerOnFloor();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
scoreboard->update();
|
||||
updateDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,10 +204,18 @@ void Game::render()
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo()
|
||||
{
|
||||
debug->add("X = " + std::to_string((int)player->x) + ", Y = " + std::to_string((int)player->y));
|
||||
debug->add("VX = " + std::to_string(player->vx) + ", VY = " + std::to_string(player->vy));
|
||||
debug->add("STATE = " + std::to_string(player->state));
|
||||
}
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void Game::renderDebugInfo()
|
||||
{
|
||||
if (!debug)
|
||||
if (!debugEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -230,18 +237,8 @@ void Game::renderDebugInfo()
|
||||
}
|
||||
|
||||
// Pinta el texto
|
||||
std::string text;
|
||||
const int inc = debugText->getCharacterWidth() + 1;
|
||||
int line = 131;
|
||||
|
||||
text = "X = " + std::to_string((int)player->x) + ", Y = " + std::to_string((int)player->y);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "VX = " + std::to_string(player->vx) + ", VY = " + std::to_string(player->vy);
|
||||
debugText->write(0, line += inc, text);
|
||||
|
||||
text = "STATE = " + std::to_string(player->state);
|
||||
debugText->write(0, line += inc, text);
|
||||
debug->setPos({1, 152});
|
||||
debug->render();
|
||||
}
|
||||
|
||||
// Escribe el nombre de la pantalla
|
||||
|
||||
Reference in New Issue
Block a user