diff --git a/assets/cats.png b/assets/cats.png new file mode 100644 index 0000000..7190b42 Binary files /dev/null and b/assets/cats.png differ diff --git a/main.lua b/main.lua index 7b76f2d..967c6f8 100644 --- a/main.lua +++ b/main.lua @@ -36,9 +36,25 @@ function love.update(dt) Tree.controls:cache() end -function love.draw() - Tree.level.camera:attach() +local function coverTransform(img, containerW, containerH) + local iw, ih = img:getWidth(), img:getHeight() + local scale = math.max(containerW / iw, containerH / ih) + local sw, sh = iw * scale, ih * scale + local offsetX = (containerW - sw) * 0.5 + local offsetY = (containerH - sh) * 0.5 + return scale, offsetX, offsetY, sw, sh +end +function love.draw() + local scale, ox, oy = coverTransform(Tree.assets.files.cats, love.graphics.getWidth(), love.graphics.getHeight()) + + love.graphics.push() + love.graphics.translate(ox, oy) + love.graphics.scale(scale, scale) + love.graphics.draw(Tree.assets.files.cats, 0, 0) + love.graphics.pop() + + Tree.level.camera:attach() for y = 0, height - 1 do for x = 0, width - 1 do love.graphics.draw(Grass, Tilemap[x][y], x, y,