diff --git a/.gitignore b/.gitignore index 4c2ce86..c88df49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.idea/ /sprites.o /dod +/boids diff --git a/Makefile b/Makefile index 73ed6cc..7429197 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ sprites.o: sprites.c sprites.h lib.h dod: dod.c ./lib/libraylib.a $(CC) $(CFLAGS) -Iinclude/ -lm dod.c -o dod ./lib/libraylib.a +boids: boids.c lib.h ./lib/libraylib.a + $(CC) $(CFLAGS) -Iinclude/ -lm boids.c -o boids ./lib/libraylib.a + run: all ./main diff --git a/base.c b/base.c new file mode 100644 index 0000000..6304ccc --- /dev/null +++ b/base.c @@ -0,0 +1,29 @@ +#include "include/raylib.h" +#include "include/raymath.h" +#include +#include "lib.h" + +#define SCREEN_WIDTH 1300 +#define SCREEN_HEIGHT 1000 +#define TARGET_FPS 60 + + +int main(void) { + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Boids"); + + SetTargetFPS(TARGET_FPS); + + while (!WindowShouldClose()) { + float dt = GetFrameTime(); + + // Update + + BeginDrawing(); + { + ClearBackground(RAYWHITE); + } + EndDrawing(); + } + + CloseWindow(); +} diff --git a/boids.c b/boids.c new file mode 100644 index 0000000..05c8ec9 --- /dev/null +++ b/boids.c @@ -0,0 +1,78 @@ +#include "include/raylib.h" +#include "include/raymath.h" +#include +#include +#include "lib.h" + +#define SCREEN_WIDTH 1300 +#define SCREEN_HEIGHT 1000 +#define TARGET_FPS 60 +#define NUM_BOIDS 16 + +const float max_speed = 200.0f; +const float max_force = 0.1; + +typedef struct Boid { + Point position; + Vector2 acceleration; + Vector2 velocity; +} Boid; + +int main(void) { + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Boids"); + + SetTargetFPS(TARGET_FPS); + + Boid *boids = calloc(NUM_BOIDS, sizeof(Boid)); + for (int i = 0; i < NUM_BOIDS; i++) { + Boid *boid = &boids[i]; + int rand_x = GetRandomValue(0, SCREEN_WIDTH); + int rand_y = GetRandomValue(0, SCREEN_HEIGHT); + boid->position = (Vector2){rand_x, rand_y}; + int rand_vx = GetRandomValue(0, 100); + int rand_vy = GetRandomValue(0, 100); + boid->velocity = (Vector2){rand_vx * 0.01f, rand_vy * 0.01f}; + int rand_ax = GetRandomValue(0, 100); + int rand_ay = GetRandomValue(0, 100); + boid->velocity = (Vector2){rand_ax * 0.01f - 0.5f, rand_ay * 0.01f - 0.5f}; + } + + PointOption target_pos = {0}; + + while (!WindowShouldClose()) { + float dt = GetFrameTime(); + + // Update + if (IsMouseButtonPressed(0)) { + Vector2 mouse_pos = GetMousePosition(); + target_pos = (PointOption){.tag = SOME, .some.point = mouse_pos}; + } + + + for (int i = 0; i < NUM_BOIDS; i++) { + Boid *boid = &boids[i]; + boid->velocity = Vector2Add(boid->velocity, boid->acceleration); + boid->velocity = Vector2ClampValue(boid->velocity, 0.0f, max_speed); + boid->position = Vector2Add(boid->position, boid->velocity); + } + + + BeginDrawing(); + { + ClearBackground(RAYWHITE); + // You can draw a triangle but you'd need to rotate all 3 vectors, and I don't + // want to get distracted with that + // DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, GREEN); + // DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, GREEN); + for (int i = 0; i < NUM_BOIDS; i++) { + Boid *boid = &boids[i]; + DrawCircle(boid->position.x, boid->position.y, 35, BLACK); + DrawCircle(boid->position.x, boid->position.y, 25, GREEN); + } + } + EndDrawing(); + } + + free(boids); + CloseWindow(); +} diff --git a/hours.org b/hours.org new file mode 100644 index 0000000..9c194a6 --- /dev/null +++ b/hours.org @@ -0,0 +1,12 @@ +* Bexorg Hours +#+BEGIN: clocktable :scope subtree :maxlevel 2 +#+CAPTION: Clock summary at [2024-01-06 Sat 12:28] +| Headline | Time | +|------------+------| +| *Total time* | *0:00* | +#+END: + +** <2024-01-06 Sat> +:LOGBOOK: +CLOCK: [2024-01-06 Sat 11:00] +:END: diff --git a/main.c b/main.c index 8c6ba49..334363c 100644 --- a/main.c +++ b/main.c @@ -12,7 +12,7 @@ #define DEBUG_MODE_ENABLED -bool global_debug_mode; +bool global_debug_mode = false; #define ENNIX_LIB_IMPLEMENTATION #include "lib.h" @@ -349,7 +349,7 @@ int main(void) { printf("Direction Size: %ld \n", sizeof(Direction)); printf("KnightState Size: %ld \n", sizeof(KnightState)); - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - basic window"); + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Tiny Knights"); int monitor = GetCurrentMonitor(); int monitor_width = GetMonitorWidth(monitor);