diff options
| author | iamcheeseman <[hidden email]> | 2026-01-16 13:43:18 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-01-16 13:43:18 -0500 |
| commit | f5a8333aaf0104d3aba4f096c9180cd8287ac1ff (patch) | |
| tree | 5dd0643d7c4d0896aed32d5c3cf881af319a1ad0 /src | |
| parent | 9180c51c40084aa30448bc4ffc06385489e7bf45 (diff) | |
Do collision checks in steps of the body's size
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets.odin | 4 | ||||
| -rw-r--r-- | src/phys/world.odin | 90 |
2 files changed, 53 insertions, 41 deletions
diff --git a/src/assets.odin b/src/assets.odin index 838bc5d..dc2c9a4 100644 --- a/src/assets.odin +++ b/src/assets.odin @@ -49,7 +49,7 @@ images: [Image_Id]Image_Resource = { animations: [Animation_Id]Animation_Resource = { .NONE = {frame_count=1, frame_durations={100}, tags={}}, - .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"idle"={from = 0, to = 5}, "jump_trans"={from = 16, to = 16}, "run"={from = 6, to = 13}, "jump_down"={from = 17, to = 18}, "jump_up"={from = 14, to = 15}, "sleep"={from = 19, to = 22}}}, + .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"jump_up"={from = 14, to = 15}, "run"={from = 6, to = 13}, "jump_trans"={from = 16, to = 16}, "jump_down"={from = 17, to = 18}, "idle"={from = 0, to = 5}, "sleep"={from = 19, to = 22}}}, } rooms: [Room_Id]Room_Resource = { @@ -57,7 +57,7 @@ rooms: [Room_Id]Room_Resource = { .CARRABASSETT1 = {width=20, height=20, tile_width=16, tile_height=16, layers={{40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 31, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 31, 31, 17, 0, 0, 0, 16, 19, 28, 40, 40, 40, 40, 40, 40, 40, 27, 31, 31, 17, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 40, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 40, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 38, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 28, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 40, 43, 9, 9, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 18, 20, 20, 40, 40, 40, 40, 40, 43, 9, 9, 9, 9, 9, 9, 18, 9, 18, 18, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={{type = .UPGRADE, pos = {160, 240}, size = {0, 0}, parallax = {0, 0}, properties = {"image"="res/img/dash_pickup.qoi", "type"=0}}, }, background_image=nil}, .CARRABASSETT2 = {width=20, height=20, tile_width=16, tile_height=16, layers={{40, 40, 40, 8, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 8, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 8, 0, 0, 10, 31, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 20, 42, 0, 0, 0, 10, 19, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 27, 31, 19, 28, 38, 18, 6, 0, 0, 0, 0, 10, 19, 28, 40, 40, 40, 40, 40, 27, 17, 0, 0, 10, 28, 40, 38, 20, 42, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 17, 0, 0, 0, 0, 16, 19, 31, 19, 17, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 39, 40, 40, 40, 40, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 18, 9, 9, 39, 40, 40, 40, 40, 40, 40, 20, 9, 18, 9, 9, 9, 20, 20, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={}, background_image=nil}, .CARRABASSETT3 = {width=20, height=40, tile_width=16, tile_height=16, layers={{40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 19, 31, 19, 19, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 19, 31, 17, 0, 0, 0, 0, 0, 16, 19, 28, 40, 40, 40, 40, 40, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 19, 28, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 28, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 20, 9, 39, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 18, 9, 18, 39, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 41, 20, 20, 18, 18, 39, 40, 40, 40, 40, 40, 21, 28, 40, 40, 32, 0, 0, 0, 0, 10, 31, 31, 19, 19, 28, 40, 40, 40, 40, 27, 17, 7, 40, 40, 43, 42, 0, 0, 0, 0, 0, 0, 0, 0, 10, 19, 19, 19, 31, 17, 0, 7, 40, 40, 40, 38, 18, 18, 20, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 38, 20, 20, 18, 6, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 6, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 43, 6, 0, 0, 0, 0, 0, 7, 40, 40, 21, 28, 40, 21, 31, 28, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 7, 40, 40, 32, 16, 19, 17, 0, 16, 19, 19, 31, 28, 40, 38, 9, 20, 6, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 16, 19, 31, 19, 19, 17, 0, 0, 7, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 20, 18, 9, 9, 18, 20, 39, 40, 40, 43, 6, 0, 0, 0, 0, 0, 41, 20, 20, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 42, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 20, 20, 42, 0, 10, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 19, 19, 28, 40, 8, 0, 0, 0, 10, 31, 19, 31, 28, 40, 40, 40, 40, 40, 40, 32, 0, 0, 10, 19, 17, 0, 0, 0, 0, 0, 0, 0, 16, 31, 31, 31, 19, 31, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 38, 9, 9, 9, 20, 20, 18, 18, 9, 9, 42, 0, 0, 0, 0, 0, 0, 0, 0, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 8, 0, 0, 5, 20, 20, 9, 9, 18, 40, 40, 40, 21, 31, 31, 19, 31, 31, 19, 19, 17, 0, 5, 39, 40, 40, 40, 40, 40, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 28, 40, 40, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 41, 20, 18, 20, 39, 40, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 6, 0, 0, 0, 0, 41, 9, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 43, 6, 0, 0, 41, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={}, background_image=nil}, - .CARRABASSETT4 = {width=20, height=20, tile_width=16, tile_height=16, layers={{40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 19, 19, 17, 0, 10, 31, 19, 31, 28, 40, 40, 40, 40, 40, 40, 40, 21, 31, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 19, 31, 19, 28, 40, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 5, 18, 9, 20, 9, 20, 20, 9, 9, 39, 40, 40, 18, 9, 20, 18, 20, 9, 9, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={{type = .UPGRADE, pos = {160, 241}, size = {0, 0}, parallax = {0, 0}, properties = {"image"="res/img/double_jump_pickup.qoi", "type"=1}}, }, background_image=nil}, + .CARRABASSETT4 = {width=20, height=20, tile_width=16, tile_height=16, layers={{40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 19, 19, 17, 0, 10, 31, 19, 31, 28, 40, 40, 40, 40, 40, 40, 40, 21, 31, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 19, 31, 19, 28, 40, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 5, 18, 9, 20, 9, 20, 20, 9, 9, 39, 40, 40, 18, 9, 20, 18, 20, 9, 9, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={{type = .UPGRADE, pos = {160, 241}, size = {0, 0}, parallax = {0, 0}, properties = {"type"=1, "image"="res/img/double_jump_pickup.qoi"}}, }, background_image=nil}, } tilesets: [Tileset_Id]Tileset_Resource = { diff --git a/src/phys/world.odin b/src/phys/world.odin index 15e7826..6ab12d5 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -2,6 +2,7 @@ package phys import "core:log" import "core:math" +import "core:math/linalg" import rl "vendor:raylib" @@ -203,57 +204,68 @@ update_body :: proc(h: Body_Handle) { rect := b.rect rect.start += b.pos - res_rect := b.rect - res_rect.start += res_pos - - bin_list := _get_surrounding_bins(res_rect.start) + small_side := min(rect.size.x, rect.size.y) + steps := i32(math.ceil(linalg.length(b.vel * dt) / small_side)) b.collisions = {} - for bin in bin_list { - for c_h in bin { - if c_h == h { - continue - } + for i in 0..<steps { + p := f32(i + 1) / f32(steps) - c := _get_body(c_h) + res_rect := b.rect + res_rect.start += b.pos + b.vel * dt * p - if b.mask & c.layers == {} { - continue - } + bin_list := _get_surrounding_bins(res_rect.start) - c_rect := c.rect - c_rect.start += c.pos + for bin in bin_list { + for c_h in bin { + if c_h == h { + continue + } - if aabb(res_rect, c_rect) { - if aabb_hori(rect, c_rect) { - if b.vel.y > 0 { - res_pos.y = c_rect.start.y - b.rect.size.y - b.rect.start.y - b.collisions += {.DOWN} - } else { - res_pos.y = c_rect.start.y + c_rect.size.y - b.rect.start.y - b.collisions += {.UP} - } - b.collisions += {.VERTICAL} - } else if aabb_vert(rect, c.rect) { - if b.vel.x > 0 { - res_pos.x = c_rect.start.x - b.rect.size.x - b.rect.start.x - b.collisions += {.LEFT} - } else { - res_pos.x = c_rect.start.x + c_rect.size.x - b.rect.start.x - b.collisions += {.RIGHT} + c := _get_body(c_h) + + if b.mask & c.layers == {} { + continue + } + + c_rect := c.rect + c_rect.start += c.pos + + if aabb(res_rect, c_rect) { + if aabb_hori(rect, c_rect) { + if b.vel.y > 0 { + res_pos.y = c_rect.start.y - b.rect.size.y - b.rect.start.y + b.collisions += {.DOWN} + } else { + res_pos.y = c_rect.start.y + c_rect.size.y - b.rect.start.y + b.collisions += {.UP} + } + b.collisions += {.VERTICAL} + } else if aabb_vert(rect, c.rect) { + if b.vel.x > 0 { + res_pos.x = c_rect.start.x - b.rect.size.x - b.rect.start.x + b.collisions += {.LEFT} + } else { + res_pos.x = c_rect.start.x + c_rect.size.x - b.rect.start.x + b.collisions += {.RIGHT} + } + b.collisions += {.HORIZONTAL} } - b.collisions += {.HORIZONTAL} } } } - } - if .HORIZONTAL in b.collisions { - b.vel.x = 0 - } - if .VERTICAL in b.collisions { - b.vel.y = 0 + if .HORIZONTAL in b.collisions { + b.vel.x = 0 + } + if .VERTICAL in b.collisions { + b.vel.y = 0 + } + + if b.collisions != nil { + break + } } set_position(h, res_pos) |
