From a6d6f2854e0a7ea519281f853d1502fe2858d6a4 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 17 Aug 2022 08:55:05 +0200 Subject: [PATCH] =?UTF-8?q?Ta=20muestra=20informaci=C3=B3n=20de=20depuraci?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media/font/debug.png | Bin 0 -> 689 bytes media/font/debug.txt | 194 +++++++++++++++++++++++++++++++++++++++++++ source/game.cpp | 28 +++++++ source/game.h | 9 ++ source/player.h | 2 +- source/prog.cpp | 4 + source/text.cpp | 12 ++- source/text.h | 9 +- 8 files changed, 250 insertions(+), 8 deletions(-) create mode 100644 media/font/debug.png create mode 100644 media/font/debug.txt diff --git a/media/font/debug.png b/media/font/debug.png new file mode 100644 index 0000000000000000000000000000000000000000..afa42204d1342f4c94447eba89a892e41074c78b GIT binary patch literal 689 zcmV;i0#5yjP)001Kh1^@s6-0An-00001b5ch_0Itp) z=>Px%Ye_^wRA_^Elmn zPwB>WW*2Q-UKgL@J}LKZ0JV^}PZ_%T_bg7Y;zd7KKw8*iLK9Q~I`(C`DlFQ`LF~3< zl|;3nyPxGCdb)AP3$nwk)htqWB-hCW?`+boZjPBi+bf$rWHz}Rs?cg?IeZl?F-IHV ziUqU{cUqIi>*i23kZbPtKh>$kj=3%##nNd}?6X>I29Pp=>Z*BZJc1c9tFn`h9T{WX zLb^O(w&y8h}$4F60#0a^7SQp?HcjebvU+E7Ent%>Zr_0*Q4QPeYJ(*)(LKyqH zqa5jB@Fye|OdUH;FDPIqAzI%nBe4{3;^9StZUrIES^s00000NkvXXu0mjffiX%Y literal 0 HcmV?d00001 diff --git a/media/font/debug.txt b/media/font/debug.txt new file mode 100644 index 0000000..69e0630 --- /dev/null +++ b/media/font/debug.txt @@ -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 \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index 02ee37c..3af1ce3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -12,6 +12,7 @@ Game::Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input) eventHandler = new SDL_Event(); map = new Map(asset->get("01.map"), renderer, asset); player = new Player(renderer, asset, input, map); + debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer); } // Destructor @@ -20,6 +21,7 @@ Game::~Game() delete eventHandler; delete map; delete player; + delete debugText; } // Bucle para el juego @@ -48,6 +50,8 @@ void Game::init() section.name = SECTION_PROG_GAME; section.subsection = SUBSECTION_GAME_PLAY; + + debug = true; } // Actualiza el juego, las variables, comprueba la entrada, etc. @@ -71,6 +75,7 @@ void Game::update() } player->update(); + checkInput(); } } @@ -84,7 +89,30 @@ void Game::render() // Dibuja los objetos map->render(); player->render(); + renderDebugInfo(); // Actualiza la pantalla 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); } \ No newline at end of file diff --git a/source/game.h b/source/game.h index fdc5532..27a428d 100644 --- a/source/game.h +++ b/source/game.h @@ -6,6 +6,7 @@ #include "input.h" #include "map.h" #include "player.h" +#include "text.h" #ifndef GAME_H #define GAME_H @@ -18,11 +19,13 @@ private: Screen *screen; // Objeto encargado de dibujar en pantalla Input *input; // Objeto Input para gestionar las entradas 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 int ticks; // Contador de ticks para ajustar la velocidad del programa int ticksSpeed; // Velocidad a la que se repiten los bucles del programa Map *map; // Objeto encargado de gestionar el mapeado del juego 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. void update(); @@ -33,6 +36,12 @@ private: // Inicializa las variables necesarias para la sección 'Game' void init(); + // Comprueba la entrada + void checkInput(); + + // Muestra información de depuración + void renderDebugInfo(); + public: // Constructor Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input); diff --git a/source/player.h b/source/player.h index 0a4ffc6..52b000b 100644 --- a/source/player.h +++ b/source/player.h @@ -13,7 +13,7 @@ // The player class Player { -private: +public: Asset *asset; // Objeto con la ruta a todos los ficheros de recursos SDL_Renderer *renderer; // El renderizador de la ventana Input *input; // Objeto Input para gestionar las entradas diff --git a/source/prog.cpp b/source/prog.cpp index 4e7eac8..f244870 100644 --- a/source/prog.cpp +++ b/source/prog.cpp @@ -168,6 +168,10 @@ bool Prog::setFileList() asset->add("/media/music/music_surface.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(); } diff --git a/source/text.cpp b/source/text.cpp index 6de4715..3152d7d 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -4,13 +4,16 @@ #include // 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}; mSprite = new Sprite(rect, texture, renderer); mSprite->setTexture(texture); mSprite->setRenderer(renderer); - mFile = file; + mFile = textFile; init(); } @@ -18,6 +21,10 @@ Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer) // Destructor Text::~Text() { + texture->unload(); + delete texture; + texture = nullptr; + delete mSprite; mSprite = nullptr; } @@ -144,7 +151,6 @@ void Text::initOffsetFromFile() if (rfile.is_open() && rfile.good()) { std::string buffer; - //printf("Reading %s file\n", mFile.c_str()); // Lee los dos primeros valores del fichero std::getline(rfile, buffer); diff --git a/source/text.h b/source/text.h index e74b9db..94e9275 100644 --- a/source/text.h +++ b/source/text.h @@ -27,20 +27,21 @@ private: Uint8 mBoxWidth; // Anchura 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 + LTexture *texture; // Textura con los bitmaps del texto + + // Inicializador + void init(); // Inicializa el vector de offsets desde un fichero void initOffsetFromFile(); public: // Constructor - Text(std::string file, LTexture *texture, SDL_Renderer *renderer); + Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer); // Destructor ~Text(); - // Inicializador - void init(); - // Escribe el texto en pantalla void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);