60 lines
1.3 KiB
Lua
60 lines
1.3 KiB
Lua
local window = require("window")
|
|
local button = require("button")
|
|
|
|
function love.load()
|
|
timer = 0
|
|
bx, by = 0, 0
|
|
cx, cy = 0, 0
|
|
|
|
main = {
|
|
x = 50,
|
|
y = 50,
|
|
rx = 50, ry = 50, width = 300, height = 200
|
|
}
|
|
|
|
function main:moverect()
|
|
self.rx = self.rx + 50
|
|
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)
|
|
|
|
main.mousepressed = window.mousepressed(function(self, x, y, button)
|
|
btn:mousepressed(x, y, button)
|
|
end)
|
|
end
|
|
|
|
function love.mousepressed(x, y, button)
|
|
local x, y = x / MULTIPLIER, y / MULTIPLIER
|
|
bx, by = x, y
|
|
main:mousepressed(x, y, button)
|
|
end
|
|
|
|
function love.update(dt)
|
|
timer = timer + dt
|
|
end
|
|
|
|
function love.draw()
|
|
love.graphics.push()
|
|
love.graphics.scale(MULTIPLIER)
|
|
|
|
love.graphics.print(string.format("t: %d", timer), 0, 0)
|
|
love.graphics.print(string.format("%d %d", bx, by), 0, 20)
|
|
love.graphics.print(string.format("%d %d", cx, cy), 0, 40)
|
|
|
|
main:draw()
|
|
|
|
love.graphics.pop()
|
|
end
|