simple-object.lua
· 724 B · Lua
Raw
Playground
return function(animation, x, y)
local object = {
x = x
, y = y
, frame = 0
, animation = animation
, grabbed = false
}
function object:draw()
if mouseIsPressed and not taken and self:contains(mouseX, mouseY) and not self.grabbed then
self.grabbed = true
taken = true
elseif not mouseIsPressed then
self.grabbed = false
taken = false
print(animation, self.x, self.y)
end
self:animate()
if self.grabbed then
self.x = mouseX
self.y = mouseY
end
end
require "is.animated" (object)
require "is.sized" (object)
return object
end
| 1 | return function(animation, x, y) |
| 2 | local object = { |
| 3 | x = x |
| 4 | , y = y |
| 5 | , frame = 0 |
| 6 | , animation = animation |
| 7 | , grabbed = false |
| 8 | } |
| 9 | function object:draw() |
| 10 | if mouseIsPressed and not taken and self:contains(mouseX, mouseY) and not self.grabbed then |
| 11 | self.grabbed = true |
| 12 | taken = true |
| 13 | elseif not mouseIsPressed then |
| 14 | self.grabbed = false |
| 15 | taken = false |
| 16 | print(animation, self.x, self.y) |
| 17 | end |
| 18 | self:animate() |
| 19 | if self.grabbed then |
| 20 | self.x = mouseX |
| 21 | self.y = mouseY |
| 22 | end |
| 23 | end |
| 24 | require "is.animated" (object) |
| 25 | require "is.sized" (object) |
| 26 | return object |
| 27 | end |