1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
ENEMY_PROJECTILE,
PLAYER_PROJECTILE,
}
Collision_Type :: enum (u8) {
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;u8],
layers: bit_set[Layer;u16],
mask: bit_set[Layer;u16],
}
make_body :: proc(
rect: Rect,
layers := bit_set[Layer;u16]{.DEFAULT},
mask := bit_set[Layer;u16]{.DEFAULT},
) -> Body_Handle {
b := Body {
rect = rect,
layers = layers,
mask = mask,
active = true,
}
return add_body(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)
}
|