blooblib/draw_tilemap.go

25 lines
707 B
Go

package bloob
func (image *Image) DrawTilemap(tilemap *Tilemap, pos Vec2i) {
tilesize := tilemap.Tileset[0].Size
for y := 0; y < tilemap.Size.Y; y += 1 {
for x := 0; x < tilemap.Size.X; x += 1 {
tpos := Vec2i{X: x, Y: y}
image.Draw(tilemap.Tileset[tilemap.Get(tpos)], Add(Mul(tpos, tilesize), pos))
}
}
}
func (image *Image) MakeTileset(tileSize Vec2i) []*Image {
tileCount := Div(image.Size, tileSize)
var tiles []*Image
for y := 0; y < tileCount.Y; y += 1 {
for x := 0; x < tileCount.X; x += 1 {
tile := NewImage(tileSize)
tile.DrawSub(image, Vec2i{}, Recti{Pos: Vec2i{X: x * tileSize.X, Y: y * tileSize.Y}, Size: tileSize})
tiles = append(tiles, tile)
}
}
return tiles
}