diff options
Diffstat (limited to 'src/phys')
| -rw-r--r-- | src/phys/body.odin | 4 | ||||
| -rw-r--r-- | src/phys/world.odin | 12 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/phys/body.odin b/src/phys/body.odin index 0256dee..0fe6c51 100644 --- a/src/phys/body.odin +++ b/src/phys/body.odin @@ -15,7 +15,7 @@ Layer :: enum(u16) { PLAYER, // player hitboxes } -Collision_Type :: enum(u16) { +Collision_Type :: enum(u8) { UP, DOWN, RIGHT, @@ -31,7 +31,7 @@ Body :: struct { active: bool, pos: Vec2, vel: Vec2, - collisions: bit_set[Collision_Type; u16], + collisions: bit_set[Collision_Type; u8], layers: bit_set[Layer; u16], mask: bit_set[Layer; u16], } diff --git a/src/phys/world.odin b/src/phys/world.odin index 0f03de7..8470872 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -195,15 +195,21 @@ update_body :: proc(h: Body_Handle) { b.vel.y = 0 } + set_body_position(h, res_pos) +} + +set_body_position :: proc(h: Body_Handle, new_pos: Vec2) { + b := get_body(h) + prev_bin := hash_bin(world_to_bin(b.pos + b.rect.start)) - res_bin := hash_bin(world_to_bin(res_pos + b.rect.start)) + res_bin := hash_bin(world_to_bin(new_pos + b.rect.start)) if prev_bin != res_bin { remove_from_bins(b^) - b.pos = res_pos + b.pos = new_pos add_to_bins(b^) } else { - b.pos = res_pos + b.pos = new_pos } } |
