feature/simple_ui #18

Merged
PeaAshMeter merged 25 commits from feature/simple_ui into main 2025-11-08 01:32:47 +03:00
2 changed files with 15 additions and 2 deletions
Showing only changes of commit a8c188b24e - Show all commits

View File

@ -8,8 +8,7 @@ local function new(template, size)
local tileMap = require("lib.utils.sprite_atlas").load(Tree.assets.files.tiles.grass) local tileMap = require("lib.utils.sprite_atlas").load(Tree.assets.files.tiles.grass)
for y = 0, size.y - 1 do for y = 0, size.y - 1 do
for x = 0, size.x - 1 do for x = 0, size.x - 1 do
local type = tileMap.map["flower_grass"] local tile = require('lib.level.tile').new { quad = tileMap:pickQuad("flower_grass"), atlas = tileMap.atlas }
local tile = require('lib.level.tile').new { quad = type[math.random(1, #type)], atlas = tileMap.atlas }
:copyWith({ position = Vec3 { x, y } }) :copyWith({ position = Vec3 { x, y } })
map[tostring(tile.position)] = tile map[tostring(tile.position)] = tile
end end

View File

@ -52,4 +52,18 @@ local function load(path)
return setmetatable(_spriteAtlas, spriteAtlas) return setmetatable(_spriteAtlas, spriteAtlas)
end end
--- Returns a random quad of the group
---
--- @param tag string
--- @return love.Quad
function spriteAtlas:pickQuad(tag)
local group = self.map[tag]
if group then
return group[math.random(1, #group)]
end
print("[SpriteAtlas]: no tile with a tag '" .. tag .. "'")
return love.graphics.newQuad(0, 0, self.tileSize, self.tileSize, self.atlas) --fallback
end
return { load = load } return { load = load }