diff options
| author | iamcheeseman <[hidden email]> | 2026-01-13 00:01:44 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-01-13 00:01:44 -0500 |
| commit | afb58a61abd0e8114a090ab0ad664d59c10dd4b1 (patch) | |
| tree | 241788a343d7a206f1bb9394519d6f562eda8c21 | |
| parent | 58de3f9ddc72c5dbf433e45babb43a06c819cb4f (diff) | |
formatter
| -rw-r--r-- | odinfmt.json | 8 | ||||
| -rwxr-xr-x | run.sh | 1 | ||||
| -rw-r--r-- | src/assets.odin | 63 | ||||
| -rw-r--r-- | src/draw/animation.odin | 2 | ||||
| -rw-r--r-- | src/draw/draw.odin | 27 | ||||
| -rw-r--r-- | src/draw/sprite.odin | 1 | ||||
| -rw-r--r-- | src/entity_list.odin | 2 | ||||
| -rw-r--r-- | src/main.odin | 10 | ||||
| -rw-r--r-- | src/phys/body.odin | 30 | ||||
| -rw-r--r-- | src/phys/world.odin | 23 | ||||
| -rw-r--r-- | src/platform.odin | 15 | ||||
| -rw-r--r-- | src/player.odin | 58 | ||||
| -rw-r--r-- | src/resources.odin | 8 | ||||
| -rw-r--r-- | src/sprite.odin | 13 | ||||
| -rw-r--r-- | src/world.odin | 14 | ||||
| -rw-r--r-- | tools/compile_assets/main.odin | 5 |
16 files changed, 155 insertions, 125 deletions
diff --git a/odinfmt.json b/odinfmt.json new file mode 100644 index 0000000..29d711c --- /dev/null +++ b/odinfmt.json @@ -0,0 +1,8 @@ +{ + "spaces": 2, + "tabs": false, + "character_width": 80, + "sort_imports": true, + "align_struct_fields": false, + "align_struct_values": false +} @@ -1,2 +1,3 @@ odin run ./tools/compile_assets -- res src/assets.odin && +odinfmt src -w odin run src -disallow-do $1 diff --git a/src/assets.odin b/src/assets.odin index d1dd852..965fdc4 100644 --- a/src/assets.odin +++ b/src/assets.odin @@ -2,20 +2,20 @@ package demonchime // DO NOT EDIT -// +// // This file is autogenerated by tools/compile_assets // All resource types are defined in 'src/resources.odin'. import rl "vendor:raylib" Image_Id :: enum { - PLAYER, TILESETS, + PLAYER, } Animation_Id :: enum { - NONE, PLAYER, + NONE, } Room_Id :: enum { @@ -35,15 +35,56 @@ Resource_Id :: union { } images: [Image_Id]Image_Resource = { - .PLAYER = {data = #load("../.compiled-res/player-sheet.qoi"), anim = .PLAYER}, .TILESETS = {data = #load("../.compiled-res/tilesets.qoi"), anim = .NONE}, + .PLAYER = { + data = #load("../.compiled-res/player-sheet.qoi"), + anim = .PLAYER, + }, } 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 = {"run"={from = 6, to = 13}, "jump_down"={from = 17, to = 18}, "jump_up"={from = 14, to = 15}, "sleep"={from = 19, to = 22}, "idle"={from = 0, to = 5}, "jump_trans"={from = 16, to = 16}}}, + .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}, + "sleep" = {from = 19, to = 22}, + "run" = {from = 6, to = 13}, + "idle" = {from = 0, to = 5}, + "jump_up" = {from = 14, to = 15}, + "jump_down" = {from = 17, to = 18}, + }, + }, + .NONE = {frame_count = 1, frame_durations = {100}, tags = {}}, } + +//odinfmt: disable + rooms: [Room_Id]Room_Resource = { .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, 16, 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, 0, 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, 41, 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, 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={}, 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, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 21, 19, 19, 19, 19, 31, 31, 28, 40, 40, 40, 40, 40, 40, 40, 27, 31, 19, 31, 31, 31, 19, 19, 31, 31, 31, 31, 19, 19, 19, 17, 0, 0, 0, 0, 0, 0, 10, 28, 40, 40, 21, 19, 31, 31, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 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, 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, 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, 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, 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, 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, 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, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 9, 20, 20, 20, 18, 18, 18, 20, 8, 0, 0, 0, 0, 0, 0, 5, 18, 9, 9, 20, 20, 20, 18, 9, 18, 9, 18, 18, 9, 39, 40, 40, 40, 40, 40, 40, 40, 40, 43, 20, 20, 9, 20, 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}}, objects={}, background_image=nil}, @@ -100,15 +141,17 @@ tiles: []Tile_Resource = { {tileset=.TILESET, rect=Rect{start = {160, 48}, size = {16, 16}}, id=44, collisions={Rect{start = {0, 8}, size = {16, 8}}, Rect{start = {8, 0}, size = {8, 8}}}}, } +//odinfmt: enable + world: []Room_Position_Resource = { - {id=.ROOM_BEGIN_1, x=-528, y=-64, width=480, height=320}, - {id=.ROOM_BEGIN, x=-48, y=-64, width=480, height=320}, + {id = .ROOM_BEGIN_1, x = -528, y = -64, width = 480, height = 320}, + {id = .ROOM_BEGIN, x = -48, y = -64, width = 480, height = 320}, } path_to_id: map[string]Resource_Id = { - "res/img/player.ase" = Image_Id.PLAYER, + "res/img/player.ase" = Image_Id.PLAYER, "res/img/tilesets.png" = Image_Id.TILESETS, - "res/room_begin.tmj" = Room_Id.ROOM_BEGIN, + "res/room_begin.tmj" = Room_Id.ROOM_BEGIN, "res/room_begin_1.tmj" = Room_Id.ROOM_BEGIN_1, } diff --git a/src/draw/animation.odin b/src/draw/animation.odin index e6b50d1..a59fe5f 100644 --- a/src/draw/animation.odin +++ b/src/draw/animation.odin @@ -1,7 +1,7 @@ package draw -import "core:log" import "core:encoding/json" +import "core:log" import "core:os" import "core:path/filepath" import "core:strings" diff --git a/src/draw/draw.odin b/src/draw/draw.odin index 122e6fa..c4dae9f 100644 --- a/src/draw/draw.odin +++ b/src/draw/draw.odin @@ -1,7 +1,7 @@ package draw -import "core:math" import "core:c" +import "core:math" import rl "vendor:raylib" @@ -27,7 +27,7 @@ renderer: struct { @(private) color_to_rl :: proc(col: Color) -> rl.Color { - return rl.Color{ + return rl.Color { u8(col.r * 255), u8(col.g * 255), u8(col.b * 255), @@ -59,7 +59,7 @@ end_frame :: proc() { f32(rl.GetScreenWidth()) / f32(SCREEN_WIDTH), f32(rl.GetScreenHeight()) / f32(SCREEN_HEIGHT), ) - screen_start := Vec2{ + screen_start := Vec2 { (f32(rl.GetScreenWidth()) - (SCREEN_WIDTH * scale)) / 2, (f32(rl.GetScreenHeight()) - (SCREEN_HEIGHT * scale)) / 2, } @@ -77,13 +77,15 @@ rect :: proc(rect: Rect) { assert(rect.size.x > 0 && rect.size.y > 0) rl.DrawRectangle( - c.int(rect.start.x), c.int(rect.start.y), - c.int(rect.size.x), c.int(rect.size.y), + c.int(rect.start.x), + c.int(rect.start.y), + c.int(rect.size.x), + c.int(rect.size.y), color_to_rl(renderer.tint), ) } -texture :: proc{ +texture :: proc { texture_full, texture_quad, } @@ -107,9 +109,11 @@ texture_quad :: proc( rl.DrawTexturePro( img, transmute(rl.Rectangle)quad, - rl.Rectangle{ - position.x, position.y, - quad.size.x * scale.x, quad.size.y * scale.y, + rl.Rectangle { + position.x, + position.y, + quad.size.x * scale.x, + quad.size.y * scale.y, }, offset, rotation, @@ -124,10 +128,7 @@ texture_full :: proc( rotation: f32 = 0, scale := Vec2{1, 1}, ) { - size := Vec2{ - f32(img.width), - -f32(img.height), - } + size := Vec2{f32(img.width), -f32(img.height)} texture_quad(img, Rect{Vec2{0, 0}, size}, position, offset, rotation, scale) } diff --git a/src/draw/sprite.odin b/src/draw/sprite.odin index 3a90dfe..f7cd87b 100644 --- a/src/draw/sprite.odin +++ b/src/draw/sprite.odin @@ -3,4 +3,3 @@ package draw import "core:log" import rl "vendor:raylib" - diff --git a/src/entity_list.odin b/src/entity_list.odin index 1f07ef9..633a553 100644 --- a/src/entity_list.odin +++ b/src/entity_list.odin @@ -65,7 +65,7 @@ Entity_List_Iter :: struct($T: typeid) { } iter_entity_list :: proc(list: Entity_List($T)) -> Entity_List_Iter(T) { - return Entity_List_Iter(T) { list = list } + return Entity_List_Iter(T){list = list} } entity_list_iter :: proc(it: ^Entity_List_Iter($T)) -> (^T, bool) { diff --git a/src/main.odin b/src/main.odin index bed9861..88e4173 100644 --- a/src/main.odin +++ b/src/main.odin @@ -6,8 +6,8 @@ package demonchime import "base:runtime" -import "core:log" import "core:fmt" +import "core:log" import "core:mem" import os "core:os/os2" @@ -86,7 +86,7 @@ frame :: proc() { update_player(rl.GetFrameTime()) draw.new_frame() - + rl.BeginMode2D(state.camera) draw_player() @@ -96,7 +96,8 @@ frame :: proc() { rl.EndMode2D() fps_text := fmt.caprintf( - "FPS: %v", rl.GetFPS(), + "FPS: %v", + rl.GetFPS(), allocator = context.temp_allocator, ) rl.DrawText(fps_text, 5, 5, 8, rl.GREEN) @@ -138,7 +139,7 @@ main :: proc() { } mem.tracking_allocator_destroy(&track) } - } + } logger = log.create_console_logger() context.logger = logger @@ -163,4 +164,3 @@ main :: proc() { cleanup() } - diff --git a/src/phys/body.odin b/src/phys/body.odin index 0fe6c51..d568186 100644 --- a/src/phys/body.odin +++ b/src/phys/body.odin @@ -7,15 +7,15 @@ Rect :: struct { size: Vec2, } -Layer :: enum(u16) { +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 + 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(u8) { +Collision_Type :: enum (u8) { UP, DOWN, RIGHT, @@ -31,20 +31,23 @@ Body :: struct { active: bool, pos: Vec2, vel: Vec2, - collisions: bit_set[Collision_Type; u8], - layers: bit_set[Layer; u16], - mask: bit_set[Layer; u16], + 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, ^Body) { + layers := bit_set[Layer;u16]{.DEFAULT}, + mask := bit_set[Layer;u16]{.DEFAULT}, +) -> ( + Body_Handle, + ^Body, +) { b := Body { - rect = rect, + rect = rect, layers = layers, - mask = mask, + mask = mask, active = true, } return add_body(b) @@ -61,4 +64,3 @@ aabb_vert :: proc(a: Rect, b: Rect) -> bool { aabb :: proc(a: Rect, b: Rect) -> bool { return aabb_hori(a, b) && aabb_vert(a, b) } - diff --git a/src/phys/world.odin b/src/phys/world.odin index 51a85a5..c263459 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -26,19 +26,19 @@ destroy_world :: proc() { delete(world.bodies) } -@(private="file") +@(private = "file") hash_bin :: proc(x: i32, y: i32) -> u32 { return transmute(u32)((x * 73856093) ~ (y * 19349663)) } -@(private="file") +@(private = "file") world_to_bin :: proc(point: Vec2) -> (i32, i32) { - return \ - i32(math.floor(point.x / BIN_SIZE)), - i32(math.floor(point.y / BIN_SIZE)) + return i32( + math.floor(point.x / BIN_SIZE), + ), i32(math.floor(point.y / BIN_SIZE)) } -@(private="file") +@(private = "file") get_surrounding_bins :: proc( pos: Vec2, allocator := context.temp_allocator, @@ -49,8 +49,8 @@ get_surrounding_bins :: proc( idx := 0 - for offset_x in -1..=1 { - for offset_y in -1..=1 { + 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 := &world.bins[bin_idx % BIN_COUNT] neighbors[idx] = bin @@ -61,13 +61,13 @@ get_surrounding_bins :: proc( return neighbors } -@(private="file") +@(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] } -@(private="file") +@(private = "file") add_to_bins :: proc(b: ^Body) { bin := find_bin(b^) idx := i32(len(bin)) @@ -75,7 +75,7 @@ add_to_bins :: proc(b: ^Body) { b.bin_idx = idx } -@(private="file") +@(private = "file") remove_from_bins :: proc(b: Body) { bin := find_bin(b) @@ -214,4 +214,3 @@ set_body_position :: proc(h: Body_Handle, new_pos: Vec2) { b.pos = new_pos } } - diff --git a/src/platform.odin b/src/platform.odin index a071468..0e4d93b 100644 --- a/src/platform.odin +++ b/src/platform.odin @@ -10,9 +10,7 @@ Platform :: struct { make_platform :: proc(rect: Rect) -> (Entity_Handle, ^Platform) { handle, body := phys.make_body(transmute(phys.Rect)rect) - return make_entity(&state.platform_list, Platform { - body = handle, - }) + return make_entity(&state.platform_list, Platform{body = handle}) } draw_platforms :: proc() { @@ -36,18 +34,11 @@ clear_platforms :: proc() { setup_map_collisions :: proc() { clear_platforms() - make_map_collisions :: proc( - x: i32, - y: i32, - tile_id: u32, - ) { + make_map_collisions :: proc(x: i32, y: i32, tile_id: u32) { tile := tiles[tile_id] for coll in tile.collisions { - make_platform({ - coll.start + {f32(x), f32(y)}, - coll.size, - }) + make_platform({coll.start + {f32(x), f32(y)}, coll.size}) } } diff --git a/src/player.odin b/src/player.odin index e7fd214..71b015b 100644 --- a/src/player.odin +++ b/src/player.odin @@ -28,32 +28,26 @@ Player_State :: enum { player: struct { body_handle: phys.Body_Handle, sprite: Sprite, - jump_buffer: f32, coyote_time: f32, - dash_cooldown: f32, dash_timer: f32, - state: Player_State, - outside_room: bool, has_double_jumped: bool, } init_player :: proc() { - handle, body := phys.make_body( - phys.Rect{{-4, 17}, {8, 16}}, - ) + handle, body := phys.make_body(phys.Rect{{-4, 17}, {8, 16}}) player.body_handle = handle phys.set_body_position(handle, Vec2{50, 100}) init_sprite(&player.sprite, .PLAYER) - player.sprite.offset = Vec2{ + player.sprite.offset = Vec2 { math.floor(f32(player.sprite.width / 2)), - -f32(player.sprite.height) + -f32(player.sprite.height), } } @@ -63,7 +57,7 @@ delete_player :: proc() { destroy_sprite(player.sprite) } -@(private="file") +@(private = "file") get_input_dir :: proc() -> f32 { input: f32 @@ -77,7 +71,7 @@ get_input_dir :: proc() -> f32 { return input } -@(private="file") +@(private = "file") default_state :: proc(dt: f32) { input := get_input_dir() @@ -104,12 +98,12 @@ default_state :: proc(dt: f32) { player.has_double_jumped = false } else { switch body.vel.y { - case -math.INF_F32..<-50: - set_sprite_active_tag(&player.sprite, "jump_up") - case 50..<math.INF_F32: - set_sprite_active_tag(&player.sprite, "jump_down") - case: - set_sprite_active_tag(&player.sprite, "jump_trans") + case -math.INF_F32 ..< -50: + set_sprite_active_tag(&player.sprite, "jump_up") + case 50 ..< math.INF_F32: + set_sprite_active_tag(&player.sprite, "jump_down") + case: + set_sprite_active_tag(&player.sprite, "jump_trans") } } @@ -127,9 +121,9 @@ default_state :: proc(dt: f32) { } } - if .DOWN not_in body.collisions \ - && !is_keybind_down(actions.jump) \ - && body.vel.y < PLAYER_JUMP_RELEASE_CUT { + if .DOWN not_in body.collisions && + !is_keybind_down(actions.jump) && + body.vel.y < PLAYER_JUMP_RELEASE_CUT { body.vel.y = PLAYER_JUMP_RELEASE_CUT } @@ -143,7 +137,7 @@ default_state :: proc(dt: f32) { phys.update_body(player.body_handle) } -@(private="file") +@(private = "file") enter_dash :: proc() { body := phys.get_body(player.body_handle) // the sprite x scale is the direction the player is facing :) @@ -153,7 +147,7 @@ enter_dash :: proc() { player.state = .DASH } -@(private="file") +@(private = "file") dash_state :: proc(dt: f32) { phys.update_body(player.body_handle) @@ -165,7 +159,7 @@ dash_state :: proc(dt: f32) { } } -@(private="file") +@(private = "file") exit_dash :: proc() { player.state = .DEFAULT @@ -175,26 +169,22 @@ exit_dash :: proc() { body.vel /= 2 } -@(private="file") +@(private = "file") change_rooms :: proc() { body := phys.get_body(player.body_handle) width := f32(current_room.width) height := f32(current_room.height) - if body.pos.x < 0 || body.pos.x > width \ - || body.pos.y < 0 || body.pos.y > height { - prev_room_pos := Vec2{ - f32(current_room.x), - f32(current_room.y), - } + if body.pos.x < 0 || + body.pos.x > width || + body.pos.y < 0 || + body.pos.y > height { + prev_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} changed := open_room_at({i32(body.pos.x), i32(body.pos.y)}) if changed { - new_room_pos := Vec2{ - f32(current_room.x), - f32(current_room.y), - } + new_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} diff := prev_room_pos - new_room_pos new_pos := body.pos + diff - {0, 0} diff --git a/src/resources.odin b/src/resources.odin index 799ba75..49e9603 100644 --- a/src/resources.odin +++ b/src/resources.odin @@ -28,23 +28,17 @@ Object_Resource :: struct { Room_Resource :: struct { width: i32, height: i32, - tile_width: i32, tile_height: i32, - layers: [][]u32, - objects: []Object_Resource, - background_image: Maybe(Image_Id), } Tile_Resource :: struct { tileset: Tileset_Id, rect: Rect, - id: u32, - collisions: []Rect, } @@ -74,7 +68,7 @@ get_image :: proc(id: Image_Id) -> rl.Texture2D { die("Could not load asset %v", id) } - img_res.texture = rl.LoadTextureFromImage(rl_img); + img_res.texture = rl.LoadTextureFromImage(rl_img) rl.UnloadImage(rl_img) } diff --git a/src/sprite.odin b/src/sprite.odin index af2fdf9..803dd85 100644 --- a/src/sprite.odin +++ b/src/sprite.odin @@ -12,20 +12,17 @@ Sprite :: struct { current_tag: Tag_Resource, frame_time: f32, current_frame: i32, - width: i32, height: i32, - pos: Vec2, offset: Vec2, rotation: f32, scale: Vec2, - just_finished_loop: bool, } init_sprite :: proc( - sprite: ^Sprite, + sprite: ^Sprite, image_id: Image_Id, anim_id: Maybe(Animation_Id) = nil, ) -> bool { @@ -85,14 +82,12 @@ update_sprite :: proc(sprite: ^Sprite, dt: f32) { } } -draw_sprite :: proc( - sprite: Sprite, -) { - rect := draw.Rect{ +draw_sprite :: proc(sprite: Sprite) { + rect := draw.Rect { {f32(sprite.width * sprite.current_frame), 0}, {f32(sprite.width), f32(sprite.height)}, } - + draw.texture_quad( sprite.image, rect, diff --git a/src/world.odin b/src/world.odin index d0e6c74..3248d65 100644 --- a/src/world.odin +++ b/src/world.odin @@ -16,8 +16,10 @@ open_room_at :: proc(pos: [2]i32) -> bool { continue } - if pos.x >= room_pos.x && pos.x <= room_pos.x + room_pos.width \ - && pos.y >= room_pos.y && pos.y <= room_pos.y + room_pos.height { + if pos.x >= room_pos.x && + pos.x <= room_pos.x + room_pos.width && + pos.y >= room_pos.y && + pos.y <= room_pos.y + room_pos.height { current_room = room_pos return true } @@ -42,13 +44,13 @@ draw_room :: proc(id: Room_Id) { tileset := tilesets[tile.tileset] rl.DrawTexturePro( get_image(tileset.image), - rl.Rectangle{ + rl.Rectangle { x = f32(tile.rect.start.x), y = f32(tile.rect.start.y), width = f32(tile.rect.size.x), height = f32(tile.rect.size.y), }, - rl.Rectangle{ + rl.Rectangle { x = f32(x), y = f32(y), width = f32(tile.rect.size.x), @@ -59,11 +61,11 @@ draw_room :: proc(id: Room_Id) { rl.WHITE, ) } - + iterate_room_tiles(id, draw_tile) } -Map_Iterate_Callback :: proc(i32, i32, u32) +Map_Iterate_Callback :: proc(_: i32, _: i32, _: u32) iterate_room_tiles :: proc(id: Room_Id, callback: Map_Iterate_Callback) { room := get_room(id) diff --git a/tools/compile_assets/main.odin b/tools/compile_assets/main.odin index 68c5625..e33dc37 100644 --- a/tools/compile_assets/main.odin +++ b/tools/compile_assets/main.odin @@ -46,6 +46,8 @@ images: [Image_Id]Image_Resource = { animations: [Animation_Id]Animation_Resource = { <anim-load>} +//odinfmt: disable + rooms: [Room_Id]Room_Resource = { <room-load>} @@ -55,6 +57,8 @@ tilesets: [Tileset_Id]Tileset_Resource = { tiles: []Tile_Resource = { <tiles-load>} +//odinfmt: enable + world: []Room_Position_Resource = { <room-positions>} @@ -63,6 +67,7 @@ path_to_id: map[string]Resource_Id = { load_resources :: proc() { } + ` images: map[string]string |
