From 7c41e69dda3234f66a137c303fecd7bfe114ff69 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Fri, 31 Jul 2026 07:12:59 +0200 Subject: [PATCH] New helper function converting grid space to flat index. --- src/map.odin | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/map.odin b/src/map.odin index fdffe17..94a865b 100644 --- a/src/map.odin +++ b/src/map.odin @@ -122,12 +122,16 @@ world_to_grid :: proc(world_pos: rl.Vector2) -> Grid_Pos { } // returns world-space position grid pos top-left corner opposite of world_to_grid. -grid_to_world :: proc(col: int, row: int) -> rl.Vector2 { +grid_to_world :: proc(col, row: int) -> rl.Vector2 { world_x := f32(col * TILE_SIZE) world_y := f32(row * TILE_SIZE) return rl.Vector2{world_x, world_y} } +grid_to_index :: proc(col, row, width: int) -> int { + return (row * width) + col +} + // requires world x/y and then gives the rectangle in pixels that matches that get_world_tile_rect :: proc(gx, gy, offset_x, offset_y, w, h: f32) -> rl.Rectangle { return rl.Rectangle {