aboutsummaryrefslogtreecommitdiff
path: root/src/phys/body.odin
diff options
context:
space:
mode:
authorXander Swan <no email>2025-12-05 21:31:14 -0500
committerXander Swan <no email>2025-12-05 21:31:14 -0500
commitcb11496752ede6dab15d7ae60e0005e78b77e5bb (patch)
tree5c731a250274bf570a604dfecb6b7ee0209d34cd /src/phys/body.odin
parent3375d712e40cce1d17198ba20839f58a2a77d202 (diff)
actual physics system
Diffstat (limited to 'src/phys/body.odin')
-rw-r--r--src/phys/body.odin65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/phys/body.odin b/src/phys/body.odin
new file mode 100644
index 0000000..fcae697
--- /dev/null
+++ b/src/phys/body.odin
@@ -0,0 +1,65 @@
+package phys
+
+Vec2 :: [2]f32
+
+Rect :: struct {
+ start: Vec2,
+ size: Vec2,
+}
+
+Layer :: enum(u16) {
+ DEFAULT,
+ HARD, // hard collisions; don't let bodies intersect at all
+ SOFT, // soft collisions; push away other bodies with a force
+ ENEMY, // enemy hitboxes
+ PLAYER, // player hitboxes
+}
+
+Collision_Type :: enum(u16) {
+ UP,
+ DOWN,
+ RIGHT,
+ LEFT,
+ HORIZONTAL,
+ VERTICAL,
+}
+
+Body :: struct {
+ handle: Body_Handle,
+ bin_idx: i32,
+ rect: Rect,
+ active: bool,
+ pos: Vec2,
+ vel: Vec2,
+ collisions: bit_set[Collision_Type; u16],
+ layers: bit_set[Layer; u16],
+ mask: bit_set[Layer; u16],
+}
+
+make_body :: proc(
+ w: ^World,
+ rect: Rect,
+ layers := bit_set[Layer; u16]{.DEFAULT},
+ mask := bit_set[Layer; u16]{.DEFAULT},
+) -> (Body_Handle, ^Body) {
+ b := Body {
+ rect = rect,
+ layers = layers,
+ mask = mask,
+ active = true,
+ }
+ return add_body(w, b)
+}
+
+aabb_hori :: proc(a: Rect, b: Rect) -> bool {
+ return a.start.x < b.start.x + b.size.x && b.start.x < a.start.x + a.size.x
+}
+
+aabb_vert :: proc(a: Rect, b: Rect) -> bool {
+ return a.start.y < b.start.y + b.size.y && b.start.y < a.start.y + a.size.y
+}
+
+aabb :: proc(a: Rect, b: Rect) -> bool {
+ return aabb_hori(a, b) && aabb_vert(a, b)
+}
+