diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets.odin | 11 | ||||
| -rw-r--r-- | src/draw/draw.odin | 10 | ||||
| -rw-r--r-- | src/main.odin | 2 | ||||
| -rw-r--r-- | src/phys/world.odin | 75 | ||||
| -rw-r--r-- | src/player.odin | 26 | ||||
| -rw-r--r-- | src/world.odin | 6 |
6 files changed, 79 insertions, 51 deletions
diff --git a/src/assets.odin b/src/assets.odin index c8943bb..841c740 100644 --- a/src/assets.odin +++ b/src/assets.odin @@ -9,13 +9,13 @@ package demonchime import rl "vendor:raylib" Image_Id :: enum { - TILESETS, PLAYER, + TILESETS, } Animation_Id :: enum { - PLAYER, NONE, + PLAYER, } Room_Id :: enum { @@ -29,6 +29,7 @@ Tileset_Id :: enum { } Object_Type :: enum { + COLLISION, PLAYER_SPAWN, } @@ -40,18 +41,18 @@ Resource_Id :: union { } images: [Image_Id]Image_Resource = { - .TILESETS = {data = #load("../.compiled-res/tilesets.qoi"), anim = .NONE}, .PLAYER = {data = #load("../.compiled-res/player-sheet.qoi"), anim = .PLAYER}, + .TILESETS = {data = #load("../.compiled-res/tilesets.qoi"), anim = .NONE}, } animations: [Animation_Id]Animation_Resource = { - .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_trans"={from = 16, to = 16}, "jump_down"={from = 17, to = 18}, "idle"={from = 0, to = 5}, "sleep"={from = 19, to = 22}, "jump_up"={from = 14, to = 15}, "run"={from = 6, to = 13}}}, .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 = {"jump_trans"={from = 16, to = 16}, "jump_down"={from = 17, to = 18}, "idle"={from = 0, to = 5}, "sleep"={from = 19, to = 22}, "jump_up"={from = 14, to = 15}, "run"={from = 6, to = 13}}}, } rooms: [Room_Id]Room_Resource = { .ROOM_BEGIN_SECRET_1 = {width=30, 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, 27, 31, 31, 19, 31, 31, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 17, 0, 0, 0, 0, 0, 10, 19, 19, 31, 19, 31, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 9, 18, 9, 18, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 20, 9, 18, 9, 9, 9, 20, 20, 9, 18, 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, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 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}, - .ROOM_BEGIN = {width=30, 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, 27, 31, 31, 19, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 31, 31, 11, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 27, 31, 19, 31, 19, 19, 19, 31, 19, 31, 19, 19, 17, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 21, 31, 31, 31, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 21, 19, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 5, 9, 20, 9, 20, 20, 20, 18, 20, 20, 18, 18, 9, 18, 9, 18, 6, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 8, 0, 0, 0, 0, 0, 7, 11, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 9, 9, 18, 18, 9, 39, 0, 0, 0, 5, 9, 20, 9, 44, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 20, 9, 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, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 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 = .PLAYER_SPAWN, pos = {240, 195}, size = {0, 0}, parallax = {0, 0}, properties = {}}, }, background_image=nil}, + .ROOM_BEGIN = {width=30, 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, 27, 31, 31, 19, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 31, 31, 31, 11, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 27, 31, 19, 31, 19, 19, 19, 31, 19, 31, 19, 19, 17, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 21, 31, 31, 31, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 40, 21, 19, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 5, 9, 20, 9, 20, 20, 20, 18, 20, 20, 18, 18, 9, 18, 9, 18, 6, 0, 0, 0, 0, 0, 7, 32, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 8, 0, 0, 0, 0, 0, 7, 11, 0, 0, 0, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 38, 9, 9, 18, 18, 9, 39, 0, 0, 0, 5, 9, 20, 9, 44, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 0, 0, 0, 7, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 20, 9, 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, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 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 = .PLAYER_SPAWN, pos = {304, 128}, size = {0, 0}, parallax = {0, 0}, properties = {}}, {type = .COLLISION, pos = {288, 128}, size = {48, 48}, parallax = {0, 0}, properties = {}}, }, background_image=nil}, .ROOM_BEGIN_1 = {width=30, 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, 27, 19, 31, 31, 19, 19, 31, 19, 19, 19, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 19, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 19, 28, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 27, 19, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 31, 28, 40, 40, 40, 40, 40, 40, 27, 31, 31, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 28, 40, 40, 40, 40, 27, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 40, 40, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 40, 21, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 40, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 18, 20, 20, 20, 20, 18, 9, 18, 9, 40, 38, 9, 18, 42, 0, 0, 0, 0, 0, 0, 0, 41, 9, 18, 18, 9, 18, 18, 20, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 43, 20, 9, 18, 9, 18, 20, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40}}, objects={}, background_image=nil}, } diff --git a/src/draw/draw.odin b/src/draw/draw.odin index c4dae9f..75071f3 100644 --- a/src/draw/draw.odin +++ b/src/draw/draw.odin @@ -26,7 +26,7 @@ renderer: struct { } @(private) -color_to_rl :: proc(col: Color) -> rl.Color { +_color_to_rl :: proc(col: Color) -> rl.Color { return rl.Color { u8(col.r * 255), u8(col.g * 255), @@ -46,7 +46,7 @@ deinit :: proc() { new_frame :: proc() { rl.BeginTextureMode(renderer.screen) - rl.ClearBackground(color_to_rl(Color{0.2, 0.2, 0.2, 1})) + rl.ClearBackground(_color_to_rl(Color{0.2, 0.2, 0.2, 1})) } end_frame :: proc() { @@ -54,7 +54,7 @@ end_frame :: proc() { rl.BeginDrawing() { - rl.ClearBackground(color_to_rl(Color{0, 0, 0, 1})) + rl.ClearBackground(_color_to_rl(Color{0, 0, 0, 1})) scale := math.min( f32(rl.GetScreenWidth()) / f32(SCREEN_WIDTH), f32(rl.GetScreenHeight()) / f32(SCREEN_HEIGHT), @@ -81,7 +81,7 @@ rect :: proc(rect: Rect) { c.int(rect.start.y), c.int(rect.size.x), c.int(rect.size.y), - color_to_rl(renderer.tint), + _color_to_rl(renderer.tint), ) } @@ -117,7 +117,7 @@ texture_quad :: proc( }, offset, rotation, - color_to_rl(renderer.tint), + _color_to_rl(renderer.tint), ) } diff --git a/src/main.odin b/src/main.odin index 05a4438..8a528eb 100644 --- a/src/main.odin +++ b/src/main.odin @@ -73,7 +73,7 @@ frame :: proc() { draw_player() draw_room(current_room.id) - // draw_platforms() + draw_platforms() rl.EndMode2D() diff --git a/src/phys/world.odin b/src/phys/world.odin index cf66229..5bbfcbd 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -27,31 +27,31 @@ destroy_world :: proc() { } @(private = "file") -hash_bin :: proc(x: i32, y: i32) -> u32 { +_hash_bin :: proc(x: i32, y: i32) -> u32 { return transmute(u32)((x * 73856093) ~ (y * 19349663)) } @(private = "file") -world_to_bin :: proc(point: Vec2) -> (i32, i32) { +_world_to_bin :: proc(point: Vec2) -> (i32, i32) { return i32( math.floor(point.x / BIN_SIZE), ), i32(math.floor(point.y / BIN_SIZE)) } @(private = "file") -get_surrounding_bins :: proc( +_get_surrounding_bins :: proc( pos: Vec2, allocator := context.temp_allocator, ) -> []^[dynamic]Body_Handle { neighbors := make([]^[dynamic]Body_Handle, 9, allocator) - center_x, center_y := world_to_bin(pos) + center_x, center_y := _world_to_bin(pos) idx := 0 for offset_x in -1..=1 { for offset_y in -1..=1 { - bin_idx := hash_bin(center_x + i32(offset_x), center_y + i32(offset_y)) + bin_idx := _hash_bin(center_x + i32(offset_x), center_y + i32(offset_y)) bin := &world.bins[bin_idx % BIN_COUNT] neighbors[idx] = bin idx += 1 @@ -62,22 +62,22 @@ get_surrounding_bins :: proc( } @(private = "file") -find_bin :: proc(b: Body) -> ^[dynamic]Body_Handle { - bin_x, bin_y := world_to_bin(b.pos + b.rect.start) - return &world.bins[hash_bin(bin_x, bin_y) % BIN_COUNT] +_find_bin :: proc(b: Body) -> ^[dynamic]Body_Handle { + bin_x, bin_y := _world_to_bin(b.pos + b.rect.start) + return &world.bins[_hash_bin(bin_x, bin_y) % BIN_COUNT] } @(private = "file") -add_to_bins :: proc(b: ^Body) { - bin := find_bin(b^) +_add_to_bins :: proc(b: ^Body) { + bin := _find_bin(b^) idx := i32(len(bin)) append(bin, b.handle) b.bin_idx = idx } @(private = "file") -remove_from_bins :: proc(b: Body) { - bin := find_bin(b) +_remove_from_bins :: proc(b: Body) { + bin := _find_bin(b) assert(len(bin) > 0) assert(bin[b.bin_idx] == b.handle) @@ -115,7 +115,7 @@ add_body :: proc(b: Body) -> (Body_Handle, ^Body) { body := &world.bodies[world.handles[handle]] body.handle = handle - add_to_bins(body) + _add_to_bins(body) return handle, body } @@ -123,7 +123,7 @@ add_body :: proc(b: Body) -> (Body_Handle, ^Body) { remove_body :: proc(h: Body_Handle) { b := get_body(h) - remove_from_bins(b^) + _remove_from_bins(b^) last := pop(&world.bodies) if last.handle != h { @@ -134,6 +134,39 @@ remove_body :: proc(h: Body_Handle) { append(&world.unused_handles, h) } +get_collisions :: proc( + h: Body_Handle, + allocator := context.allocator +) -> []Body_Handle { + bodies := make([dynamic]Body_Handle, allocator) + + b := get_body(h) + + rect := b.rect + rect.start += b.pos + + bin_list := _get_surrounding_bins(rect.start) + + for bin in bin_list { + for c_h in bin { + if c_h == h { + continue + } + + c := get_body(c_h) + + c_rect := c.rect + c_rect.start += c.pos + + if aabb(rect, c_rect) { + append(&bodies, c_h) + } + } + } + + return bodies[:] +} + update_body :: proc(h: Body_Handle) { dt := rl.GetFrameTime() @@ -147,15 +180,11 @@ update_body :: proc(h: Body_Handle) { res_rect := b.rect res_rect.start += res_pos - bin_list := get_surrounding_bins(res_rect.start) + bin_list := _get_surrounding_bins(res_rect.start) b.collisions = {} - total_len := 0 - for bin in bin_list { - total_len += len(bin) - for c_h in bin { if c_h == h { continue @@ -203,13 +232,13 @@ update_body :: proc(h: Body_Handle) { 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(new_pos + b.rect.start)) + prev_bin := _hash_bin(_world_to_bin(b.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^) + _remove_from_bins(b^) b.pos = new_pos - add_to_bins(b) + _add_to_bins(b) } else { b.pos = new_pos } diff --git a/src/player.odin b/src/player.odin index 07b6473..7233278 100644 --- a/src/player.odin +++ b/src/player.odin @@ -55,7 +55,7 @@ delete_player :: proc() { } @(private = "file") -get_input_dir :: proc() -> f32 { +_get_input_dir :: proc() -> f32 { input: f32 if is_keybind_down(actions.move_left) { @@ -69,8 +69,8 @@ get_input_dir :: proc() -> f32 { } @(private = "file") -default_state :: proc(dt: f32) { - input := get_input_dir() +_default_state :: proc(dt: f32) { + input := _get_input_dir() if input != 0 { set_sprite_active_tag(&player.sprite, "run") @@ -84,7 +84,7 @@ default_state :: proc(dt: f32) { } if is_keybind_just_down(actions.dash) && player.dash_cooldown <= 0 { - enter_dash() + _enter_dash() return } @@ -135,7 +135,7 @@ default_state :: proc(dt: f32) { } @(private = "file") -enter_dash :: proc() { +_enter_dash :: proc() { body := phys.get_body(player.body_handle) // the sprite x scale is the direction the player is facing :) body.vel = {math.sign(player.sprite.scale.x) * PLAYER_DASH_SPEED, 0} @@ -145,19 +145,19 @@ enter_dash :: proc() { } @(private = "file") -dash_state :: proc(dt: f32) { +_dash_state :: proc(dt: f32) { phys.update_body(player.body_handle) player.dash_timer -= dt body := phys.get_body(player.body_handle) if player.dash_timer <= 0 || body.collisions != {} { - exit_dash() + _exit_dash() } } @(private = "file") -exit_dash :: proc() { +_exit_dash :: proc() { player.state = .DEFAULT player.dash_cooldown = PLAYER_DASH_COOLDOWN @@ -167,7 +167,7 @@ exit_dash :: proc() { } @(private = "file") -change_rooms :: proc() { +_change_rooms :: proc() { body := phys.get_body(player.body_handle) width := f32(current_room.width) @@ -192,10 +192,8 @@ change_rooms :: proc() { update_player :: proc(dt: f32) { switch player.state { - case .DEFAULT: - default_state(dt) - case .DASH: - dash_state(dt) + case .DEFAULT: _default_state(dt) + case .DASH: _dash_state(dt) } body := phys.get_body(player.body_handle) @@ -207,7 +205,7 @@ update_player :: proc(dt: f32) { player.jump_buffer -= dt player.coyote_time -= dt - change_rooms() + _change_rooms() } draw_player :: proc() { diff --git a/src/world.odin b/src/world.odin index d2e8601..f16852a 100644 --- a/src/world.odin +++ b/src/world.odin @@ -9,7 +9,7 @@ current_room: Room_Position_Resource object_spawners := [Object_Type]Object_Spawner{ .PLAYER_SPAWN = object_spawner_player_spawn, - // .COLLISION = object_spawner_collision, + .COLLISION = object_spawner_collision, } room_open_cb := []Room_Change_Callback{ @@ -20,7 +20,7 @@ room_close_cb := []Room_Change_Callback{ } @(private = "file") -spawn_objects :: proc(room_id: Room_Id) { +_spawn_objects :: proc(room_id: Room_Id) { room := get_room(room_id) for obj in room.objects { @@ -43,7 +43,7 @@ _open_room :: proc(room_pos: Room_Position_Resource) { cb(current_room.id) } - spawn_objects(current_room.id) + _spawn_objects(current_room.id) } open_room_at :: proc(pos: [2]i32) -> bool { |
