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();
|
||||
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
screen->setBorderColor(borderColor);
|
||||
debug = new Debug(renderer, screen, asset);
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
@@ -51,6 +52,7 @@ Director::~Director()
|
||||
delete asset;
|
||||
delete input;
|
||||
delete screen;
|
||||
delete debug;
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
@@ -251,7 +253,7 @@ void Director::runTitle()
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void Director::runGame()
|
||||
{
|
||||
game = new Game(renderer, screen, asset, input);
|
||||
game = new Game(renderer, screen, asset, input, debug);
|
||||
setSection(game->run());
|
||||
delete game;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "title.h"
|
||||
#include "intro.h"
|
||||
#include "asset.h"
|
||||
#include "debug.h"
|
||||
#include "const.h"
|
||||
|
||||
#ifndef DIRECTOR_H
|
||||
@@ -29,6 +30,7 @@ private:
|
||||
Title *title; // Objeto para gestionar la pantalla de título
|
||||
Intro *intro; // Onjeto para gestionar la introducción del juego
|
||||
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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
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
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "player.h"
|
||||
#include "jail_audio.h"
|
||||
#include "scoreboard.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
@@ -33,13 +34,14 @@ private:
|
||||
Text *debugText; // Objeto para los textos de debug del juego
|
||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
||||
JA_Music music; // Musica que suena durante el juego
|
||||
Debug *debug;
|
||||
bool musicEnabled; // Indica si ha de sonar la musica durante el 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
|
||||
std::string currentRoom; // Fichero de la habitación actual
|
||||
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 itemsPicked; // Lleva la cuenta de los objetos recogidos
|
||||
Uint32 clock; // Cuenta el tiempo que dura la partida
|
||||
@@ -53,6 +55,9 @@ private:
|
||||
// Comprueba los eventos de la cola
|
||||
void checkEventHandler();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void updateDebugInfo();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void renderDebugInfo();
|
||||
|
||||
@@ -79,7 +84,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();
|
||||
|
||||
@@ -172,7 +172,7 @@ void Text::initOffsetFromFile()
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int Text::getCharacterWidth()
|
||||
int Text::getCharacterSize()
|
||||
{
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterWidth();
|
||||
int getCharacterSize();
|
||||
|
||||
// Recarga la textura
|
||||
void reLoadTexture();
|
||||
|
||||
Reference in New Issue
Block a user