feat: multiple circles
This commit is contained in:
14
include/sims.hpp
Normal file
14
include/sims.hpp
Normal 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
|
||||||
16
src/main.cpp
16
src/main.cpp
@@ -4,7 +4,7 @@
|
|||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "../include/gfx.hpp"
|
#include "../include/sims.hpp"
|
||||||
|
|
||||||
bool key_event(SDL_Event e) {
|
bool key_event(SDL_Event e) {
|
||||||
if (e.type == SDL_EVENT_KEY_DOWN) {
|
if (e.type == SDL_EVENT_KEY_DOWN) {
|
||||||
@@ -27,6 +27,10 @@ bool event_handling(SDL_Event e) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sim(SDL_Renderer *r) {
|
||||||
|
sims::two_bodies(r);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)){
|
if (!SDL_Init(SDL_INIT_VIDEO)){
|
||||||
std::printf("SDL_INIT() failed");
|
std::printf("SDL_INIT() failed");
|
||||||
@@ -48,17 +52,13 @@ int main() {
|
|||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
|
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
struct {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
} circle_pos;
|
|
||||||
circle_pos = {10, 10};
|
|
||||||
while (!exit) {
|
while (!exit) {
|
||||||
exit = event_handling(e);
|
exit = event_handling(e);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
gfx::draw_circle(renderer, circle_pos.x, circle_pos.y, 10, true);
|
|
||||||
circle_pos.x++;
|
sim(renderer);
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
SDL_Delay(16);
|
SDL_Delay(16);
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/sims/two_bodies.cpp
Normal file
13
src/sims/two_bodies.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user