diff --git a/source/dbgtxt.h b/source/dbgtxt.h index 1643949..ca421e1 100644 --- a/source/dbgtxt.h +++ b/source/dbgtxt.h @@ -1,7 +1,5 @@ #pragma once -#include - namespace { SDL_Texture *dbg_tex = nullptr; diff --git a/source/defines.h b/source/defines.h index 96afd03..846b674 100644 --- a/source/defines.h +++ b/source/defines.h @@ -1,8 +1,5 @@ #pragma once -#include "SDL3/SDL.h" -#include - constexpr char WINDOW_CAPTION[] = "demo3_pixels_bouncing"; constexpr int WIDTH = 320; constexpr int HEIGHT = 240; diff --git a/source/dot.h b/source/dot.h index cf5929f..3e8525d 100644 --- a/source/dot.h +++ b/source/dot.h @@ -1,7 +1,5 @@ #pragma once -#include "defines.h" - namespace Dot { struct DotData diff --git a/source/main.cpp b/source/main.cpp index 1e2d788..97d4e45 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,9 +1,19 @@ -#include -#include "dot.h" -#include "defines.h" -#include "dbgtxt.h" -#include -#include +#include // Para SDL_GetError +#include // Para SDL_EventType, SDL_PollEvent, SDL_Event +#include // Para SDL_Init, SDL_Quit, SDL_INIT_VIDEO +#include // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5 +#include // Para SDL_FPoint +#include // Para SDL_SetRenderDrawColor, SDL_CreateRend... +#include // Para Uint64 +#include // Para SDL_GetTicks +#include // Para SDL_CreateWindow, SDL_DestroyWindow +#include // Para rand, srand +#include // Para time +#include // Para basic_ostream, char_traits, operator<< +#include // Para operator+, string, to_string +#include "dbgtxt.h" // Para dbg_init, dbg_print +#include "defines.h" // Para WIDTH, MAX_DOTS, Color, HEIGHT, ZOOM +#include "dot.h" // Para DotData, ini, modVel, update // Ventana y renderizador SDL_Window *window = nullptr; @@ -27,10 +37,10 @@ Uint64 ticks = 0; // Actualiza el texto a mostrar en pantalla void setText() { - const std::string text2 = test[scenario] == 1 ? " PIXEL" : " PIXELES"; - text = std::to_string(test[scenario]) + text2; - const int size = text.size() * 8; - text_pos = WIDTH / 2 - size / 2; + const std::string TEXT2 = test[scenario] == 1 ? " PIXEL" : " PIXELES"; + text = std::to_string(test[scenario]) + TEXT2; + const int SIZE = text.size() * 8; + text_pos = WIDTH / 2 - SIZE / 2; text_init_time = SDL_GetTicks(); show_text = true; } @@ -40,12 +50,12 @@ void initDots() { for (int i = 0; i < test[scenario]; ++i) { - const int sign = ((rand() % 2) * 2) - 1; - const float x = (rand() % (WIDTH / 2)) + (WIDTH / 4); - const float vx = (((rand() % 20) + 10) * 0.1f) * sign; - const float vy = ((rand() % 60) - 30) * 0.1f; - const Color color = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32}; - dots[i] = Dot::ini(x, vx, vy, color); + const int SIGN = ((rand() % 2) * 2) - 1; + const float X = (rand() % (WIDTH / 2)) + (WIDTH / 4); + const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN; + const float VY = ((rand() % 60) - 30) * 0.1f; + const Color COLOR = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32}; + dots[i] = Dot::ini(X, VX, VY, COLOR); } setText(); } @@ -55,10 +65,10 @@ void pushUpDots() { for (int i = 0; i < test[scenario]; ++i) { - const int sign = ((rand() % 2) * 2) - 1; - const float vx = (((rand() % 20) + 10) * 0.1f) * sign; - const float vy = ((rand() % 40) * 0.1f) + 5; - Dot::modVel(dots[i], vx, -vy); + const int SIGN = ((rand() % 2) * 2) - 1; + const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN; + const float VY = ((rand() % 40) * 0.1f) + 5; + Dot::modVel(dots[i], VX, -VY); } }