#include #include #include #include template using sdl_deleter_t = decltype([](auto* ptr) { sdl_destroyfunc(ptr); }); template using sdl_wrapper_t = std::unique_ptr>; using window_t = sdl_wrapper_t; using surface_t = sdl_wrapper_t; using renderer_t = sdl_wrapper_t; struct Point { int x; int y; }; auto operator+(Point a, Point b) { return Point{.x = a.x + b.x, .y = a.y + b.y}; } constexpr int width = 3440; constexpr int height = 1440; int main() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { std::println("fuck"); return EXIT_FAILURE; } { renderer_t renderer; window_t window; SDL_CreateWindowAndRenderer( width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN, std::out_ptr(window), std::out_ptr(renderer) ); SDL_SetRenderDrawColor(renderer.get(), 0, 0, 0, 0); SDL_RenderClear(renderer.get()); SDL_SetRenderDrawColor(renderer.get(), 255, 0, 0, 255); if (!window) { std::println( "Window could not be created! SDL_Error: {}", SDL_GetError() ); return EXIT_FAILURE; } auto surface = surface_t{SDL_GetWindowSurface(window.get())}; auto point = Point{.x = width / 2, .y = height / 2}; const Point directions[] = { {.x = -1, .y = 0}, {.x = 1, .y = 0}, {.x = 0, .y = -1}, {.x = 0, .y = 1} }; std::mt19937_64 rne(std::random_device{}()); std::uniform_int_distribution dist(0, 3); SDL_Event e; bool quit = false; while (!quit) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { quit = true; } } SDL_RenderDrawPoint(renderer.get(), point.x, point.y); Point newpoint; do { newpoint = point + directions[dist(rne)]; } while (newpoint.x < 0 or newpoint.x >= width or newpoint.y < 0 or newpoint.y >= height); point = newpoint; SDL_RenderPresent(renderer.get()); } } SDL_Quit(); // leaking memory, nothing I can do }