Ta muestra información de depuración
This commit is contained in:
BIN
media/font/debug.png
Normal file
BIN
media/font/debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 689 B |
194
media/font/debug.txt
Normal file
194
media/font/debug.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
5
|
||||||
|
# box height
|
||||||
|
5
|
||||||
|
# 32 espacio ( )
|
||||||
|
5
|
||||||
|
# 33 !
|
||||||
|
5
|
||||||
|
# 34 "
|
||||||
|
5
|
||||||
|
# 35 #
|
||||||
|
5
|
||||||
|
# 36 $
|
||||||
|
5
|
||||||
|
# 37 %
|
||||||
|
5
|
||||||
|
# 38 &
|
||||||
|
5
|
||||||
|
# 39 '
|
||||||
|
5
|
||||||
|
# 40 (
|
||||||
|
5
|
||||||
|
# 41 )
|
||||||
|
5
|
||||||
|
# 42 *
|
||||||
|
5
|
||||||
|
# 43 +
|
||||||
|
5
|
||||||
|
# 44 ,
|
||||||
|
5
|
||||||
|
# 45 -
|
||||||
|
5
|
||||||
|
# 46 .
|
||||||
|
5
|
||||||
|
# 47 /
|
||||||
|
5
|
||||||
|
# 48 0
|
||||||
|
5
|
||||||
|
# 49 1
|
||||||
|
5
|
||||||
|
# 50 2
|
||||||
|
5
|
||||||
|
# 51 3
|
||||||
|
5
|
||||||
|
# 52 4
|
||||||
|
5
|
||||||
|
# 53 5
|
||||||
|
5
|
||||||
|
# 54 6
|
||||||
|
5
|
||||||
|
# 55 7
|
||||||
|
5
|
||||||
|
# 56 8
|
||||||
|
5
|
||||||
|
# 57 9
|
||||||
|
5
|
||||||
|
# 58 :
|
||||||
|
5
|
||||||
|
# 59 ;
|
||||||
|
5
|
||||||
|
# 60 <
|
||||||
|
5
|
||||||
|
# 61 =
|
||||||
|
5
|
||||||
|
# 62 >
|
||||||
|
5
|
||||||
|
# 63 ?
|
||||||
|
5
|
||||||
|
# 64 @
|
||||||
|
5
|
||||||
|
# 65 A
|
||||||
|
5
|
||||||
|
# 66 B
|
||||||
|
5
|
||||||
|
# 67 C
|
||||||
|
5
|
||||||
|
# 68 D
|
||||||
|
5
|
||||||
|
# 69 E
|
||||||
|
5
|
||||||
|
# 70 F
|
||||||
|
5
|
||||||
|
# 71 G
|
||||||
|
5
|
||||||
|
# 72 H
|
||||||
|
5
|
||||||
|
# 73 I
|
||||||
|
5
|
||||||
|
# 74 J
|
||||||
|
5
|
||||||
|
# 75 K
|
||||||
|
5
|
||||||
|
# 76 L
|
||||||
|
5
|
||||||
|
# 77 M
|
||||||
|
5
|
||||||
|
# 78 N
|
||||||
|
5
|
||||||
|
# 79 O
|
||||||
|
5
|
||||||
|
# 80 P
|
||||||
|
5
|
||||||
|
# 81 Q
|
||||||
|
5
|
||||||
|
# 82 R
|
||||||
|
5
|
||||||
|
# 83 S
|
||||||
|
5
|
||||||
|
# 84 T
|
||||||
|
5
|
||||||
|
# 85 U
|
||||||
|
5
|
||||||
|
# 86 V
|
||||||
|
5
|
||||||
|
# 87 W
|
||||||
|
5
|
||||||
|
# 88 X
|
||||||
|
5
|
||||||
|
# 89 Y
|
||||||
|
5
|
||||||
|
# 90 Z
|
||||||
|
5
|
||||||
|
# 91 [
|
||||||
|
5
|
||||||
|
# 92 \
|
||||||
|
5
|
||||||
|
# 93 ]
|
||||||
|
5
|
||||||
|
# 94 ^
|
||||||
|
5
|
||||||
|
# 95 _
|
||||||
|
5
|
||||||
|
# 96 `
|
||||||
|
5
|
||||||
|
# 97 a
|
||||||
|
5
|
||||||
|
# 98 b
|
||||||
|
5
|
||||||
|
# 99 c
|
||||||
|
5
|
||||||
|
# 100 d
|
||||||
|
5
|
||||||
|
# 101 e
|
||||||
|
5
|
||||||
|
# 102 f
|
||||||
|
5
|
||||||
|
# 103 g
|
||||||
|
5
|
||||||
|
# 104 h
|
||||||
|
5
|
||||||
|
# 105 i
|
||||||
|
5
|
||||||
|
# 106 j
|
||||||
|
5
|
||||||
|
# 107 k
|
||||||
|
5
|
||||||
|
# 108 l
|
||||||
|
5
|
||||||
|
# 109 m
|
||||||
|
5
|
||||||
|
# 110 n
|
||||||
|
5
|
||||||
|
# 111 o
|
||||||
|
5
|
||||||
|
# 112 p
|
||||||
|
5
|
||||||
|
# 113 q
|
||||||
|
5
|
||||||
|
# 114 r
|
||||||
|
5
|
||||||
|
# 115 s
|
||||||
|
5
|
||||||
|
# 116 t
|
||||||
|
5
|
||||||
|
# 117 u
|
||||||
|
5
|
||||||
|
# 118 v
|
||||||
|
5
|
||||||
|
# 119 w
|
||||||
|
5
|
||||||
|
# 120 x
|
||||||
|
5
|
||||||
|
# 121 y
|
||||||
|
5
|
||||||
|
# 122 z
|
||||||
|
5
|
||||||
|
# 123 {
|
||||||
|
5
|
||||||
|
# 124 |
|
||||||
|
5
|
||||||
|
# 125 }
|
||||||
|
5
|
||||||
|
# 126 ~
|
||||||
|
5
|
||||||
@@ -12,6 +12,7 @@ Game::Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input)
|
|||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
map = new Map(asset->get("01.map"), renderer, asset);
|
map = new Map(asset->get("01.map"), renderer, asset);
|
||||||
player = new Player(renderer, asset, input, map);
|
player = new Player(renderer, asset, input, map);
|
||||||
|
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -20,6 +21,7 @@ Game::~Game()
|
|||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
delete map;
|
delete map;
|
||||||
delete player;
|
delete player;
|
||||||
|
delete debugText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
@@ -48,6 +50,8 @@ void Game::init()
|
|||||||
|
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
section.subsection = SUBSECTION_GAME_PLAY;
|
section.subsection = SUBSECTION_GAME_PLAY;
|
||||||
|
|
||||||
|
debug = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
@@ -71,6 +75,7 @@ void Game::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
player->update();
|
player->update();
|
||||||
|
checkInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +89,30 @@ void Game::render()
|
|||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
map->render();
|
map->render();
|
||||||
player->render();
|
player->render();
|
||||||
|
renderDebugInfo();
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba la entrada
|
||||||
|
void Game::checkInput()
|
||||||
|
{
|
||||||
|
if (input->checkInput(INPUT_BUTTON_2, REPEAT_FALSE))
|
||||||
|
debug = !debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra información de depuración
|
||||||
|
void Game::renderDebugInfo()
|
||||||
|
{
|
||||||
|
if (!debug)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int line = 0;
|
||||||
|
std::string text = "";
|
||||||
|
|
||||||
|
text = std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY());
|
||||||
|
debugText->write(0, line, text, -1);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
@@ -18,11 +19,13 @@ private:
|
|||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
|
Text *debugText; // Objeto para escribir texto con información de debug
|
||||||
section_t section; // Seccion actual dentro del programa
|
section_t section; // Seccion actual dentro del programa
|
||||||
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
|
||||||
Map *map; // Objeto encargado de gestionar el mapeado del juego
|
Map *map; // Objeto encargado de gestionar el mapeado del juego
|
||||||
Player *player; // Objeto para gestionar el jugador
|
Player *player; // Objeto para gestionar el jugador
|
||||||
|
bool debug; // Indica si esta activo el modo de depuración
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
@@ -33,6 +36,12 @@ private:
|
|||||||
// Inicializa las variables necesarias para la sección 'Game'
|
// Inicializa las variables necesarias para la sección 'Game'
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
// Comprueba la entrada
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
|
// Muestra información de depuración
|
||||||
|
void renderDebugInfo();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input);
|
Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// The player
|
// The player
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
|
|||||||
@@ -168,6 +168,10 @@ bool Prog::setFileList()
|
|||||||
asset->add("/media/music/music_surface.ogg", music);
|
asset->add("/media/music/music_surface.ogg", music);
|
||||||
asset->add("/media/music/music_volcano.ogg", music);
|
asset->add("/media/music/music_volcano.ogg", music);
|
||||||
|
|
||||||
|
// Texto
|
||||||
|
asset->add("/media/font/debug.png", font);
|
||||||
|
asset->add("/media/font/debug.txt", font);
|
||||||
|
|
||||||
return asset->check();
|
return asset->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,16 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer)
|
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
texture = new LTexture();
|
||||||
|
loadTextureFromFile(texture, bitmapFile, renderer);
|
||||||
|
|
||||||
SDL_Rect rect = {0,0,0,0};
|
SDL_Rect rect = {0,0,0,0};
|
||||||
mSprite = new Sprite(rect, texture, renderer);
|
mSprite = new Sprite(rect, texture, renderer);
|
||||||
mSprite->setTexture(texture);
|
mSprite->setTexture(texture);
|
||||||
mSprite->setRenderer(renderer);
|
mSprite->setRenderer(renderer);
|
||||||
mFile = file;
|
mFile = textFile;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@@ -18,6 +21,10 @@ Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Text::~Text()
|
Text::~Text()
|
||||||
{
|
{
|
||||||
|
texture->unload();
|
||||||
|
delete texture;
|
||||||
|
texture = nullptr;
|
||||||
|
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
mSprite = nullptr;
|
||||||
}
|
}
|
||||||
@@ -144,7 +151,6 @@ void Text::initOffsetFromFile()
|
|||||||
if (rfile.is_open() && rfile.good())
|
if (rfile.is_open() && rfile.good())
|
||||||
{
|
{
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
//printf("Reading %s file\n", mFile.c_str());
|
|
||||||
|
|
||||||
// Lee los dos primeros valores del fichero
|
// Lee los dos primeros valores del fichero
|
||||||
std::getline(rfile, buffer);
|
std::getline(rfile, buffer);
|
||||||
|
|||||||
@@ -27,20 +27,21 @@ private:
|
|||||||
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
|
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
|
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||||
std::string mFile; // Fichero con los descriptores de la fuente
|
std::string mFile; // Fichero con los descriptores de la fuente
|
||||||
|
LTexture *texture; // Textura con los bitmaps del texto
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init();
|
||||||
|
|
||||||
// Inicializa el vector de offsets desde un fichero
|
// Inicializa el vector de offsets desde un fichero
|
||||||
void initOffsetFromFile();
|
void initOffsetFromFile();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Text(std::string file, LTexture *texture, SDL_Renderer *renderer);
|
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Text();
|
~Text();
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Escribe el texto en pantalla
|
// Escribe el texto en pantalla
|
||||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user