diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cba2e6..d5f87b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,50 @@ { "files.associations": { - "iostream": "cpp" + "iostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/source/dbgtxt.h b/source/dbgtxt.h new file mode 100644 index 0000000..dead131 --- /dev/null +++ b/source/dbgtxt.h @@ -0,0 +1,37 @@ +#pragma once +#include + + +namespace { + SDL_Texture *dbg_tex = NULL; + SDL_Renderer *dbg_ren = NULL; +} + +void dbg_init(SDL_Renderer *renderer) { + dbg_ren = renderer; + Uint8 font[448] = {0x42, 0x4D, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x01, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x18, 0xF3, 0x83, 0x83, 0xCF, 0x83, 0x87, 0x00, 0x00, 0xF3, 0x39, 0x39, 0xCF, 0x79, 0xF3, 0x00, 0x00, 0x01, 0xF9, 0x39, 0xCF, 0x61, 0xF9, 0x00, 0x00, 0x33, 0xF9, 0x03, 0xE7, 0x87, 0x81, 0x00, 0x00, 0x93, 0x03, 0x3F, 0xF3, 0x1B, 0x39, 0x00, 0x00, 0xC3, 0x3F, 0x9F, 0x39, 0x3B, 0x39, 0x00, 0x41, 0xE3, 0x03, 0xC3, 0x01, 0x87, 0x83, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xE7, 0x01, 0xC7, 0x81, 0x01, 0x83, 0x00, 0x00, 0xE7, 0x1F, 0x9B, 0xE7, 0x1F, 0x39, 0x00, 0x00, 0xE7, 0x8F, 0x39, 0xE7, 0x87, 0xF9, 0x00, 0x00, 0xC3, 0xC7, 0x39, 0xE7, 0xC3, 0xC3, 0x00, 0x00, 0x99, 0xE3, 0x39, 0xE7, 0xF1, 0xE7, 0x00, 0x00, 0x99, 0xF1, 0xB3, 0xC7, 0x39, 0xF3, 0x00, 0x00, 0x99, 0x01, 0xC7, 0xE7, 0x83, 0x81, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x83, 0xE7, 0x83, 0xEF, 0x39, 0x39, 0x00, 0x00, 0x39, 0xE7, 0x39, 0xC7, 0x11, 0x11, 0x00, 0x00, 0xF9, 0xE7, 0x39, 0x83, 0x01, 0x83, 0x00, 0x00, 0x83, 0xE7, 0x39, 0x11, 0x01, 0xC7, 0x00, 0x00, 0x3F, 0xE7, 0x39, 0x39, 0x29, 0x83, 0x00, 0x00, 0x33, 0xE7, 0x39, 0x39, 0x39, 0x11, 0x00, 0x00, 0x87, 0x81, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x39, 0x83, 0x3F, 0x85, 0x31, 0x00, 0x00, 0x39, 0x31, 0x39, 0x3F, 0x33, 0x23, 0x00, 0x00, 0x29, 0x21, 0x39, 0x03, 0x21, 0x07, 0x00, 0x00, 0x01, 0x01, 0x39, 0x39, 0x39, 0x31, 0x00, 0x00, 0x01, 0x09, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x11, 0x19, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x39, 0x39, 0x83, 0x03, 0x83, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xC1, 0x39, 0x81, 0x83, 0x31, 0x01, 0x00, 0x00, 0x99, 0x39, 0xE7, 0x39, 0x23, 0x3F, 0x00, 0x00, 0x39, 0x39, 0xE7, 0xF9, 0x07, 0x3F, 0x00, 0x00, 0x31, 0x01, 0xE7, 0xF9, 0x0F, 0x3F, 0x00, 0x00, 0x3F, 0x39, 0xE7, 0xF9, 0x27, 0x3F, 0x00, 0x00, 0x9F, 0x39, 0xE7, 0xF9, 0x33, 0x3F, 0x00, 0x00, 0xC1, 0x39, 0x81, 0xF9, 0x39, 0x3F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x03, 0xC3, 0x07, 0x01, 0x3F, 0x00, 0x00, 0x39, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0x01, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x39, 0x03, 0x3F, 0x39, 0x03, 0x03, 0x00, 0x00, 0x39, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x93, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0xC7, 0x03, 0xC3, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}; + dbg_tex = SDL_CreateTextureFromSurface(dbg_ren, SDL_LoadBMP_RW(SDL_RWFromMem(font, 448), 1)); +} + +void dbg_print(int x, int y, const char* text, Uint8 r, Uint8 g, Uint8 b) { + int cc = 0; + SDL_SetTextureColorMod(dbg_tex, r, g, b); + SDL_Rect src = {0, 0, 8, 8}; + SDL_Rect dst = {x, y, 8, 8}; + while (text[cc] != 0) { + if (text[cc] != 32) + { + if (text[cc] >= 65) + { + src.x = ((text[cc]-65)%6)*8; src.y = ((text[cc]-65)/6)*8; + } + else + { + src.x = ((text[cc]-22)%6)*8; src.y = ((text[cc]-22)/6)*8; + } + + SDL_RenderCopy(dbg_ren, dbg_tex, &src, &dst); + } + cc++; dst.x+=8; + } +} diff --git a/source/defines.h b/source/defines.h index 078622e..876a7bb 100644 --- a/source/defines.h +++ b/source/defines.h @@ -5,6 +5,7 @@ #define SCREEN_HEIGHT 240 #define BALL_SIZE 8 #define GRAVITY 0.2f +#define TEXT_TIME 100 struct color_t { diff --git a/source/main.cpp b/source/main.cpp index 5ff7ea0..8e0c0a6 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,6 +2,7 @@ #include "texture.h" #include "ball.h" #include "defines.h" +#include "dbgtxt.h" #include #include @@ -14,9 +15,24 @@ int test[8] = {1, 10, 100, 500, 1000, 10000, 50000, 100000}; bool shouldExit = false; Uint32 ticks = 0; +int index = 0; +std::string text = ""; +int textPos = 0; +bool showText = true; +int counter = 0; void deleteBalls(); +void setText() +{ + const std::string text2 = test[index] == 1 ? " PELOTA" : " PELOTAS"; + text = std::to_string(test[index]) + text2; + const int size = text.size() * 8; + textPos = SCREEN_WIDTH / 2 - size / 2; + counter = TEXT_TIME; + showText = true; +} + void initBalls(int value) { deleteBalls(); @@ -102,7 +118,9 @@ bool init() texture = new Texture(renderer, "resources/pelota.png"); ticks = SDL_GetTicks(); srand(time(NULL)); - initBalls(2); + dbg_init(renderer); + initBalls(index); + setText(); return success; } @@ -154,43 +172,53 @@ void checkEvents() if (event->key.keysym.sym == SDLK_1) { - initBalls(0); + index = 0; + initBalls(index); } if (event->key.keysym.sym == SDLK_2) { - initBalls(1); + index = 1; + initBalls(index); } if (event->key.keysym.sym == SDLK_3) { - initBalls(2); + index = 2; + initBalls(index); } if (event->key.keysym.sym == SDLK_4) { - initBalls(3); + index = 3; + initBalls(index); } if (event->key.keysym.sym == SDLK_5) { - initBalls(4); + index = 4; + initBalls(index); } if (event->key.keysym.sym == SDLK_6) { - initBalls(5); + index = 5; + initBalls(index); } if (event->key.keysym.sym == SDLK_7) { - initBalls(6); + index = 6; + initBalls(index); } if (event->key.keysym.sym == SDLK_8) { - initBalls(7); + index = 7; + initBalls(index); } + + setText(); } } } @@ -205,6 +233,11 @@ void update() { ball->update(); } + + if (counter > 0) + counter--; + else + showText = false; } } @@ -218,6 +251,9 @@ void render() ball->render(); } + if (showText) + dbg_print(textPos, 8, text.c_str(), 255, 255, 255); + SDL_RenderPresent(renderer); }