feat: multiple circles

This commit is contained in:
2025-11-07 10:14:06 +01:00
parent 42183469ab
commit 90ee367dc6
3 changed files with 35 additions and 8 deletions

14
include/sims.hpp Normal file
View File

@@ -0,0 +1,14 @@
#ifndef SIMS_HPP
#define SIMS_HPP
#include <SDL3/SDL_render.h>
namespace sims {
typedef struct {
int x;
int y;
int r;
} body;
void two_bodies(SDL_Renderer *r);
}
#endif

View File

@@ -4,7 +4,7 @@
#include <SDL3/SDL_timer.h>
#include <cstdio>
#include <cstdlib>
#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);
}

13
src/sims/two_bodies.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include <SDL3/SDL.h>
#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);
}
}