forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida la clase debug
This commit is contained in:
59
source/debug.cpp
Normal file
59
source/debug.cpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Debug::~Debug()
|
||||||
|
{
|
||||||
|
delete text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void Debug::update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void Debug::render()
|
||||||
|
{
|
||||||
|
int y = this->y;
|
||||||
|
|
||||||
|
for (auto s : slot)
|
||||||
|
{
|
||||||
|
text->write(x, y, s);
|
||||||
|
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();
|
||||||
|
}
|
||||||
50
source/debug.h
Normal file
50
source/debug.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#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
|
||||||
|
int x; // Posicion donde escribir el texto de debug
|
||||||
|
int y; // Posición donde escribir el texto de 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();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -43,6 +43,7 @@ Director::Director(std::string path)
|
|||||||
initInput();
|
initInput();
|
||||||
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
screen->setBorderColor(borderColor);
|
screen->setBorderColor(borderColor);
|
||||||
|
debug = new Debug(renderer, screen, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director()
|
Director::~Director()
|
||||||
@@ -51,6 +52,7 @@ Director::~Director()
|
|||||||
delete asset;
|
delete asset;
|
||||||
delete input;
|
delete input;
|
||||||
delete screen;
|
delete screen;
|
||||||
|
delete debug;
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
@@ -251,7 +253,7 @@ void Director::runTitle()
|
|||||||
// Ejecuta la seccion de juego donde se juega
|
// Ejecuta la seccion de juego donde se juega
|
||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
game = new Game(renderer, screen, asset, input);
|
game = new Game(renderer, screen, asset, input, debug);
|
||||||
setSection(game->run());
|
setSection(game->run());
|
||||||
delete game;
|
delete game;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
#ifndef DIRECTOR_H
|
||||||
@@ -29,6 +30,7 @@ private:
|
|||||||
Title *title; // Objeto para gestionar la pantalla de título
|
Title *title; // Objeto para gestionar la pantalla de título
|
||||||
Intro *intro; // Onjeto para gestionar la introducción del juego
|
Intro *intro; // Onjeto para gestionar la introducción del juego
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
Debug *debug; // Objeto para getsionar la información de debug
|
||||||
|
|
||||||
struct options_t *options; // Variable con todas las opciones del programa
|
struct options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Inicia algunas variables
|
||||||
clock = SDL_GetTicks();
|
clock = SDL_GetTicks();
|
||||||
@@ -16,6 +16,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
this->screen = screen;
|
this->screen = screen;
|
||||||
this->input = input;
|
this->input = input;
|
||||||
|
this->debug = debug;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
scoreboard = new ScoreBoard(renderer, asset, &playerLives, &itemsPicked, &clock);
|
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;
|
playerLives = 9;
|
||||||
itemsPicked = 0;
|
itemsPicked = 0;
|
||||||
|
|
||||||
debug = true;
|
debugEnabled = true;
|
||||||
player->setInvincible(debug);
|
player->setInvincible(debugEnabled);
|
||||||
musicEnabled = !debug;
|
musicEnabled = !debugEnabled;
|
||||||
|
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
section.subsection = SUBSECTION_GAME_PLAY;
|
section.subsection = SUBSECTION_GAME_PLAY;
|
||||||
@@ -93,9 +94,9 @@ void Game::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_D:
|
case SDL_SCANCODE_D:
|
||||||
debug = !debug;
|
debugEnabled = !debugEnabled;
|
||||||
player->setInvincible(debug);
|
player->setInvincible(debugEnabled);
|
||||||
musicEnabled = !debug;
|
musicEnabled = !debugEnabled;
|
||||||
musicEnabled ? JA_PlayMusic(music) : JA_StopMusic();
|
musicEnabled ? JA_PlayMusic(music) : JA_StopMusic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -171,16 +172,14 @@ void Game::update()
|
|||||||
checkEventHandler();
|
checkEventHandler();
|
||||||
|
|
||||||
// Actualiza los objetos
|
// Actualiza los objetos
|
||||||
|
debug->clear();
|
||||||
room->update();
|
room->update();
|
||||||
{
|
player->update();
|
||||||
player->update();
|
|
||||||
// checkPlayerAndWalls(); // Debe ir detras del player update, por si se ha metido en algun muro
|
|
||||||
}
|
|
||||||
checkPlayerOnBorder();
|
checkPlayerOnBorder();
|
||||||
// checkPlayerOnFloor();
|
|
||||||
checkPlayerAndItems();
|
checkPlayerAndItems();
|
||||||
checkPlayerAndEnemies();
|
checkPlayerAndEnemies();
|
||||||
scoreboard->update();
|
scoreboard->update();
|
||||||
|
updateDebugInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,10 +204,18 @@ void Game::render()
|
|||||||
screen->blit();
|
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
|
// Pone la información de debug en pantalla
|
||||||
void Game::renderDebugInfo()
|
void Game::renderDebugInfo()
|
||||||
{
|
{
|
||||||
if (!debug)
|
if (!debugEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -230,18 +237,8 @@ void Game::renderDebugInfo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el texto
|
// Pinta el texto
|
||||||
std::string text;
|
debug->setPos({1, 152});
|
||||||
const int inc = debugText->getCharacterWidth() + 1;
|
debug->render();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
@@ -33,13 +34,14 @@ private:
|
|||||||
Text *debugText; // Objeto para los textos de debug del juego
|
Text *debugText; // Objeto para los textos de debug del juego
|
||||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
||||||
JA_Music music; // Musica que suena durante el juego
|
JA_Music music; // Musica que suena durante el juego
|
||||||
|
Debug *debug;
|
||||||
bool musicEnabled; // Indica si ha de sonar la musica durante el juego
|
bool musicEnabled; // Indica si ha de sonar la musica durante el juego
|
||||||
int ticks; // Contador de ticks para ajustar la velocidad 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
|
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
section_t section; // Seccion actual dentro del juego
|
section_t section; // Seccion actual dentro del juego
|
||||||
std::string currentRoom; // Fichero de la habitación actual
|
std::string currentRoom; // Fichero de la habitación actual
|
||||||
player_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
player_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
||||||
bool debug; // Indica si el modo debug está activo
|
bool debugEnabled; // Indica si el modo debug está activo
|
||||||
int playerLives; // Lleva la cuenta de ls vidas restantes del jugador
|
int playerLives; // Lleva la cuenta de ls vidas restantes del jugador
|
||||||
int itemsPicked; // Lleva la cuenta de los objetos recogidos
|
int itemsPicked; // Lleva la cuenta de los objetos recogidos
|
||||||
Uint32 clock; // Cuenta el tiempo que dura la partida
|
Uint32 clock; // Cuenta el tiempo que dura la partida
|
||||||
@@ -53,6 +55,9 @@ private:
|
|||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void checkEventHandler();
|
void checkEventHandler();
|
||||||
|
|
||||||
|
// Pone la información de debug en pantalla
|
||||||
|
void updateDebugInfo();
|
||||||
|
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
void renderDebugInfo();
|
void renderDebugInfo();
|
||||||
|
|
||||||
@@ -79,7 +84,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input);
|
Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Debug *debug);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ void Text::initOffsetFromFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int Text::getCharacterWidth()
|
int Text::getCharacterSize()
|
||||||
{
|
{
|
||||||
return boxWidth;
|
return boxWidth;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
int lenght(std::string text, int kerning = 1);
|
int lenght(std::string text, int kerning = 1);
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve el valor de la variable
|
||||||
int getCharacterWidth();
|
int getCharacterSize();
|
||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture();
|
||||||
|
|||||||
Reference in New Issue
Block a user