Add layout

This commit is contained in:
백현웅 2024-12-30 19:46:44 +09:00
parent 40fdba2588
commit 0cbc05c30f

View file

@ -1,45 +1,45 @@
-- Imports
local window = require("window") local window = require("window")
local button = require("button") local button = require("button")
function love.load() local inventory = {
timer = 0 x = 0, y = 0,
bx, by = 0, 0 width = WIDTH*0.7,
cx, cy = 0, 0 height = HEIGHT*0.2,
main = {
x = 50,
y = 50,
rx = 50, ry = 50, width = 300, height = 200
} }
function main:moverect() inventory.draw = window.draw(function(self)
self.rx = self.rx + 50 window.draw_border(self.width, self.height)
self.ry = self.ry + 50
end
local m = main
cback = function (x, y)
cx, cy = x, y
m:moverect()
end
btn = button.new('Move', cback, 10, 10, 50, 50)
main.draw = window.draw(function(self)
love.graphics.rectangle('fill', self.rx, self.ry, 50, 50)
love.graphics.print(string.format("x %d", self.rx), 50, 100)
btn:draw()
end) end)
main.mousepressed = window.mousepressed(function(self, x, y, button) local screen = {
btn:mousepressed(x, y, button) x = 0, y = inventory.height,
width = inventory.width,
height = HEIGHT - inventory.height,
}
screen.draw = window.draw(function(self)
window.draw_border(self.width, self.height)
end) end)
local log = {
x = inventory.width , y = 0,
width = WIDTH*0.3,
height = HEIGHT,
}
log.draw = window.draw(function(self)
window.draw_border(self.width, self.height)
end)
function love.load()
timer = 0
end end
function love.mousepressed(x, y, button) function love.mousepressed(x, y, button)
local x, y = x / MULTIPLIER, y / MULTIPLIER local x, y = x / MULTIPLIER, y / MULTIPLIER
bx, by = x, y
main:mousepressed(x, y, button)
end end
function love.update(dt) function love.update(dt)
@ -50,11 +50,9 @@ function love.draw()
love.graphics.push() love.graphics.push()
love.graphics.scale(MULTIPLIER) love.graphics.scale(MULTIPLIER)
love.graphics.print(string.format("t: %d", timer), 0, 0) screen:draw()
love.graphics.print(string.format("%d %d", bx, by), 0, 20) inventory:draw()
love.graphics.print(string.format("%d %d", cx, cy), 0, 40) log:draw()
main:draw()
love.graphics.pop() love.graphics.pop()
end end