New helper function converting grid space to flat index.
This commit is contained in:
+5
-1
@@ -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.
|
// 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_x := f32(col * TILE_SIZE)
|
||||||
world_y := f32(row * TILE_SIZE)
|
world_y := f32(row * TILE_SIZE)
|
||||||
return rl.Vector2{world_x, world_y}
|
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
|
// 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 {
|
get_world_tile_rect :: proc(gx, gy, offset_x, offset_y, w, h: f32) -> rl.Rectangle {
|
||||||
return rl.Rectangle {
|
return rl.Rectangle {
|
||||||
|
|||||||
Reference in New Issue
Block a user