From 90ee367dc694fcdc1dd88be3a42da7e187e9235a Mon Sep 17 00:00:00 2001 From: Alejandro Laguna Date: Fri, 7 Nov 2025 10:14:06 +0100 Subject: [PATCH] feat: multiple circles --- include/sims.hpp | 14 ++++++++++++++ src/main.cpp | 16 ++++++++-------- src/sims/two_bodies.cpp | 13 +++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 include/sims.hpp create mode 100644 src/sims/two_bodies.cpp diff --git a/include/sims.hpp b/include/sims.hpp new file mode 100644 index 0000000..53c8cd9 --- /dev/null +++ b/include/sims.hpp @@ -0,0 +1,14 @@ +#ifndef SIMS_HPP + #define SIMS_HPP + #include + +namespace sims { + typedef struct { + int x; + int y; + int r; + } body; + void two_bodies(SDL_Renderer *r); +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 339cabc..41fbbbf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "../include/gfx.hpp" +#include "../include/sims.hpp" bool key_event(SDL_Event e) { if (e.type == SDL_EVENT_KEY_DOWN) { @@ -27,6 +27,10 @@ bool event_handling(SDL_Event e) { return false; } +void sim(SDL_Renderer *r) { + sims::two_bodies(r); +} + int main() { if (!SDL_Init(SDL_INIT_VIDEO)){ std::printf("SDL_INIT() failed"); @@ -48,17 +52,13 @@ int main() { SDL_Event e; bool exit = false; - struct { - int x; - int y; - } circle_pos; - circle_pos = {10, 10}; while (!exit) { exit = event_handling(e); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); - gfx::draw_circle(renderer, circle_pos.x, circle_pos.y, 10, true); - circle_pos.x++; + + sim(renderer); + SDL_RenderPresent(renderer); SDL_Delay(16); } diff --git a/src/sims/two_bodies.cpp b/src/sims/two_bodies.cpp new file mode 100644 index 0000000..36fc926 --- /dev/null +++ b/src/sims/two_bodies.cpp @@ -0,0 +1,13 @@ +#include +#include "../../include/gfx.hpp" +#include "../../include/sims.hpp" + +namespace sims { + void two_bodies(SDL_Renderer *r) { + body body1 = {10, 10, 10}; + body body2 = {250, 250, 10}; + + gfx::draw_circle(r, body1.x, body1.y, body1.r, true); + gfx::draw_circle(r, body2.x, body2.y, body2.r, true); + } +}