Map Render

This commit is contained in:
2026-08-06 15:25:34 +03:00
parent c2eb4a7b24
commit dee1d4cc0f
8 changed files with 172 additions and 58 deletions
+85
View File
@@ -0,0 +1,85 @@
package main
import "core:fmt"
import rl "vendor:raylib"
Atlas :: struct {
tex: rl.Texture2D,
tile_size: rl.Vector2,
cols: i32,
rows: i32,
frames: i32,
}
TILE_MULT :: 4
Tile :: struct {
atlas: ^Atlas,
pos: rl.Vector2,
frame: i32,
}
load_atlas :: proc() -> Atlas {
at: Atlas
at.tex = rl.LoadTexture("./assets/3rdparty/tileset/Tiles/Tileset.png")
at.tile_size = rl.Vector2{16, 16}
at.rows = at.tex.height / (i32(at.tile_size.y))
at.cols = at.tex.width / i32(at.tile_size.x)
at.frames = at.cols * at.rows
fmt.printf(
"Atlas rows: %v, Atlas cols: %v, Frames: %v\n",
at.rows,
at.cols,
at.frames,
)
return at
}
//
// draw_atlas :: proc(at: ^Atlas) {
// rl.DrawTexturePro(
// at^.tex,
// rl.Rectangle{0, 0, at.tile_size.x, at.tile_size.y},
// rl.Rectangle{0, 0, 64, 64},
// rl.Vector2{0, 0},
// 0,
// rl.WHITE,
// )
// }
draw_tile :: proc(tile: Tile) {
offset := get_offset(tile.atlas, tile.frame)
rl.DrawTexturePro(
tile.atlas^.tex,
rl.Rectangle {
offset.x,
offset.y,
tile.atlas.tile_size.x,
tile.atlas.tile_size.y,
},
rl.Rectangle {
tile.pos.x * TILE_MULT,
tile.pos.y * TILE_MULT,
tile.atlas.tile_size.x * TILE_MULT,
tile.atlas.tile_size.y * TILE_MULT,
},
rl.Vector2{0, 0},
// rl.Vector2{tile.pos.x, tile.pos.y},
0,
rl.WHITE,
)
}
get_offset :: proc(atlas: ^Atlas, f: i32) -> rl.Vector2 {
col := f % atlas.cols
row := f / atlas.cols
return rl.Vector2 {
f32(col) * atlas.tile_size.x,
f32(row) * atlas.tile_size.y,
}
}