-- Metatable. local Prop = { x = 0, y = 0, width = 0, height = 0, frame = 1, animation = "closed", style = "door", } Prop.__index = Prop -- Constructor. local function newProp() return setmetatable({}, Prop) end -- Dimensions related functions. function Prop:getDimensions() return self.width, self.height end function Prop:setDimensions(width, height) self.width, self.height = width, height return self end -- Position related functions. function Prop:getPosition() return self.x, self.y end function Prop:setPosition(x, y) self.x, self.y = x, y return self end -- Don't mistake with seduce. function Prop:setUse(func) if type(func) == "function" then self.use = func end return self end -- Animation. function Prop:changeAnimation(name) if self.animation ~= name and name then self.animation = name self.frame = 1 end return self end -- Stylish. function Prop:setStyle(style) if self.style ~= style and style then self.style = style end return self end -- Returns true if given position is inside Prop's hitbox. function Prop:testPosition(x, y) local px, py = self:getPosition() local w, h = self:getDimensions() if x > px and x < px+w and y > py and y < py+h then return self end end -- Being used by player callback. function Prop:use() end -- LÖVE2D callbacks. function Prop:update() -- Animations local frames = #Game.quads[self.style][self.animation] self.frame = (self.frame%frames)+1 -- Automatic animation changes if self.animation == "opening" and self.frame == 7 then self:changeAnimation("open") end end function Prop:draw(scale) local x,y = self:getPosition() if Game.inRange(x, y) then local sprite = Game.sprites[self.style] local quad = Game.quads[self.style][self.animation][self.frame] love.graphics.setColor(255,255,255) love.graphics.draw(sprite, quad, (x)*scale, (y)*scale, 0, scale, scale) end end return newProp