From 381153a6c9639a5afc35fee8f5c49984c1ae91b2 Mon Sep 17 00:00:00 2001 From: george Date: Sun, 14 Jun 2026 23:07:45 +0100 Subject: [PATCH] init --- .gitignore | 3 ++ build.jai | 20 ++++++++++ main.jai | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ring.jai | 31 +++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 build.jai create mode 100644 main.jai create mode 100644 ring.jai diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..489631b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +libs/ +.build/ +droplets diff --git a/build.jai b/build.jai new file mode 100644 index 0000000..4e980f8 --- /dev/null +++ b/build.jai @@ -0,0 +1,20 @@ +#run { + w := compiler_create_workspace(); + bo := get_build_options(w); + + bo.output_executable_name = "droplets"; + + import_paths: [..]string; + for bo.import_path array_add(*import_paths, it); + array_add(*import_paths, "libs"); + bo.import_path = import_paths; + + set_build_options(bo, w); + add_build_file("main.jai", w); + add_build_file("ring.jai", w); + + set_build_options_dc(.{do_output=false}); +} + +#import "Basic"; +#import "Compiler"; diff --git a/main.jai b/main.jai new file mode 100644 index 0000000..fb323ba --- /dev/null +++ b/main.jai @@ -0,0 +1,110 @@ +GRAVITY :: Vector2.{0, 3000}; +RECT_SIZE :: 10; +SPAWN_UPS :: 1.0 / 60; + +particle :: struct { + pos : Vector2; + vel : Vector2; +} + +main :: () { + InitWindow(800, 600, "Droplets"); + defer CloseWindow(); + SetTargetFPS(240); + high_fps := true; + + particles: [..]particle; + + mouse_drag := new_ring(); + defer array_free(mouse_drag.data); + + spawn_d := SPAWN_UPS; + + while !WindowShouldClose() { + dt := GetFrameTime(); + width := GetScreenWidth(); + height := GetScreenHeight(); + + if IsMouseButtonPressed(.MOUSE_BUTTON_MIDDLE) { + if !high_fps SetTargetFPS(240); + if high_fps SetTargetFPS(60); + high_fps = !high_fps; + } + if IsMouseButtonDown(.MOUSE_BUTTON_RIGHT) { + spawn_d -= dt; + if spawn_d < 0 { + pos := GetMousePosition(); + array_add(*particles, .{pos, .{0, 0}}); + spawn_d = SPAWN_UPS; + } + } + if IsMouseButtonReleased(.MOUSE_BUTTON_RIGHT) { + spawn_d = SPAWN_UPS; + } + if IsMouseButtonDown(.MOUSE_BUTTON_LEFT) { + del := GetMouseDelta() / dt; + ring_add(*mouse_drag, del); + } + if IsMouseButtonReleased(.MOUSE_BUTTON_LEFT) { + pos := GetMousePosition(); + + { + max_x := cast(float) GetScreenWidth(); + max_y := cast(float) GetScreenHeight(); + using pos; + if x > max_x x = max_x; + if x < 0 x = 0; + if y > max_y y = max_y; + if y < 0 y = 0; + } + + vel := ring_avg(*mouse_drag); + ring_reset(*mouse_drag); + + array_add(*particles, .{pos, vel}); + } + + for *p : particles { + using p; + + if pos.y + RECT_SIZE < xx height + vel += GRAVITY * dt; + + pos += vel * dt; + + if pos.x <= 0 { + vel.x = -(vel.x * 0.5); + pos.x = 0; + } + + if pos.x + RECT_SIZE >= xx width { + vel.x = -(vel.x * 0.5); + pos.x = xx (width - RECT_SIZE); + } + + if pos.y <= 0 { + vel.y = -(vel.y * 0.5); + vel.x *= 0.75; + pos.y = 0; + } + + if pos.y + RECT_SIZE > xx height { + vel.y = -(vel.y * 0.5); + vel.x *= 0.75; + if abs(vel.y) < abs((GRAVITY * dt).y) + vel = .{0, 0}; + pos.y = xx (height - RECT_SIZE); + } + } + + BeginDrawing(); + ClearBackground(RAYWHITE); + for p : particles { + DrawRectangleV(p.pos, .{RECT_SIZE, RECT_SIZE}, SKYBLUE); + } + EndDrawing(); + } +} + +#import "raylib"; +#import "Basic"; diff --git a/ring.jai b/ring.jai new file mode 100644 index 0000000..09eeba4 --- /dev/null +++ b/ring.jai @@ -0,0 +1,31 @@ +ring_add :: (using r : *ring, next: Vector2) { + data[start] = next; + start += 1; + start %= data.count; +} + +ring_avg :: (using r : *ring) -> Vector2 { + sum : Vector2; + for data { + sum += it; + } + return sum / cast(float) data.count; +} + +ring_reset :: (using r : *ring) { + memset(data.data, 0, data.count * size_of(Vector2)); +} + +new_ring :: (num_items: s64 = 5) -> ring { + r : ring; + r.data = NewArray(num_items, Vector2); + return r; +} + +ring :: struct { + start : s64; + data : []Vector2; +} + +#import "Math"; +#import "Basic";