Map parsing
This commit is contained in:
@@ -51,7 +51,8 @@ load_atlas :: proc() -> Atlas {
|
||||
|
||||
|
||||
draw_tile :: proc(tile: Tile) {
|
||||
offset := get_offset(tile.atlas, tile.frame)
|
||||
offset, empty := get_offset(tile.atlas, tile.frame)
|
||||
if empty do return
|
||||
rl.DrawTexturePro(
|
||||
tile.atlas^.tex,
|
||||
rl.Rectangle {
|
||||
@@ -73,13 +74,24 @@ draw_tile :: proc(tile: Tile) {
|
||||
)
|
||||
}
|
||||
|
||||
get_offset :: proc(atlas: ^Atlas, f: i32) -> rl.Vector2 {
|
||||
get_offset :: proc(
|
||||
atlas: ^Atlas,
|
||||
f: i32,
|
||||
) -> (
|
||||
offset: rl.Vector2,
|
||||
empty: bool,
|
||||
) {
|
||||
|
||||
col := f % atlas.cols
|
||||
row := f / atlas.cols
|
||||
if f == 0 do return {}, true
|
||||
|
||||
return rl.Vector2 {
|
||||
col := (f - 1) % atlas.cols
|
||||
row := (f - 1) / atlas.cols
|
||||
|
||||
|
||||
offset = rl.Vector2 {
|
||||
f32(col) * atlas.tile_size.x,
|
||||
f32(row) * atlas.tile_size.y,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user