arreglos d'estil

This commit is contained in:
2025-03-23 20:45:03 +01:00
parent 9cddd6e03b
commit a49297527b
4 changed files with 30 additions and 27 deletions

View File

@@ -1,7 +1,5 @@
#pragma once #pragma once
#include <SDL3/SDL.h>
namespace namespace
{ {
SDL_Texture *dbg_tex = nullptr; SDL_Texture *dbg_tex = nullptr;

View File

@@ -1,8 +1,5 @@
#pragma once #pragma once
#include "SDL3/SDL.h"
#include <stdlib.h>
constexpr char WINDOW_CAPTION[] = "demo3_pixels_bouncing"; constexpr char WINDOW_CAPTION[] = "demo3_pixels_bouncing";
constexpr int WIDTH = 320; constexpr int WIDTH = 320;
constexpr int HEIGHT = 240; constexpr int HEIGHT = 240;

View File

@@ -1,7 +1,5 @@
#pragma once #pragma once
#include "defines.h"
namespace Dot namespace Dot
{ {
struct DotData struct DotData

View File

@@ -1,9 +1,19 @@
#include <SDL3/SDL.h> #include <SDL3/SDL_error.h> // Para SDL_GetError
#include "dot.h" #include <SDL3/SDL_events.h> // Para SDL_EventType, SDL_PollEvent, SDL_Event
#include "defines.h" #include <SDL3/SDL_init.h> // Para SDL_Init, SDL_Quit, SDL_INIT_VIDEO
#include "dbgtxt.h" #include <SDL3/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5
#include <iostream> #include <SDL3/SDL_rect.h> // Para SDL_FPoint
#include <vector> #include <SDL3/SDL_render.h> // Para SDL_SetRenderDrawColor, SDL_CreateRend...
#include <SDL3/SDL_stdinc.h> // Para Uint64
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <SDL3/SDL_video.h> // Para SDL_CreateWindow, SDL_DestroyWindow
#include <stdlib.h> // Para rand, srand
#include <time.h> // Para time
#include <iostream> // Para basic_ostream, char_traits, operator<<
#include <string> // 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 // Ventana y renderizador
SDL_Window *window = nullptr; SDL_Window *window = nullptr;
@@ -27,10 +37,10 @@ Uint64 ticks = 0;
// Actualiza el texto a mostrar en pantalla // Actualiza el texto a mostrar en pantalla
void setText() void setText()
{ {
const std::string text2 = test[scenario] == 1 ? " PIXEL" : " PIXELES"; const std::string TEXT2 = test[scenario] == 1 ? " PIXEL" : " PIXELES";
text = std::to_string(test[scenario]) + text2; text = std::to_string(test[scenario]) + TEXT2;
const int size = text.size() * 8; const int SIZE = text.size() * 8;
text_pos = WIDTH / 2 - size / 2; text_pos = WIDTH / 2 - SIZE / 2;
text_init_time = SDL_GetTicks(); text_init_time = SDL_GetTicks();
show_text = true; show_text = true;
} }
@@ -40,12 +50,12 @@ void initDots()
{ {
for (int i = 0; i < test[scenario]; ++i) for (int i = 0; i < test[scenario]; ++i)
{ {
const int sign = ((rand() % 2) * 2) - 1; const int SIGN = ((rand() % 2) * 2) - 1;
const float x = (rand() % (WIDTH / 2)) + (WIDTH / 4); const float X = (rand() % (WIDTH / 2)) + (WIDTH / 4);
const float vx = (((rand() % 20) + 10) * 0.1f) * sign; const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN;
const float vy = ((rand() % 60) - 30) * 0.1f; const float VY = ((rand() % 60) - 30) * 0.1f;
const Color color = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32}; const Color COLOR = {(rand() % 192) + 32, (rand() % 192) + 32, (rand() % 192) + 32};
dots[i] = Dot::ini(x, vx, vy, color); dots[i] = Dot::ini(X, VX, VY, COLOR);
} }
setText(); setText();
} }
@@ -55,10 +65,10 @@ void pushUpDots()
{ {
for (int i = 0; i < test[scenario]; ++i) for (int i = 0; i < test[scenario]; ++i)
{ {
const int sign = ((rand() % 2) * 2) - 1; const int SIGN = ((rand() % 2) * 2) - 1;
const float vx = (((rand() % 20) + 10) * 0.1f) * sign; const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN;
const float vy = ((rand() % 40) * 0.1f) + 5; const float VY = ((rand() % 40) * 0.1f) + 5;
Dot::modVel(dots[i], vx, -vy); Dot::modVel(dots[i], VX, -VY);
} }
} }