From 93e91c1821087b05f235ae356b7af4d8cfc3cae7 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:32:59 +0200 Subject: Decoration properly inherits from Sprite --- not/Decoration.lua | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'not') diff --git a/not/Decoration.lua b/not/Decoration.lua index a57c143..80f6653 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -1,27 +1,33 @@ --- TODO: follow new code template --- TODO: add comments -require "not.Sprite" +--- `Decoration` +-- Positioned sprite used to decorate maps with additional graphics. Decoration = { - world = nil, - sprite = nil, + world = --[[not.World]]nil, x = 0, y = 0 } + +-- `Decoration` is a child of `Sprite`. +require "not.Sprite" Decoration.__index = Decoration setmetatable(Decoration, Sprite) -function Decoration:new(x, y, sprite) - local o = {} - setmetatable(o, self) - o:setImage(love.graphics.newImage(sprite)) - o:setPosition(x,y) + +-- Constructor of `Decoration`. +function Decoration:new (x, y, imagePath) + local o = setmetatable({}, self) + o:init(x, y, imagePath) return o end -function Decoration:setPosition(x, y) - self.x, self.y = x, y + +-- Initializator of `Decoration`. +function Decoration:init (x, y, imagePath) + Sprite.init(self, imagePath) + self:setPosition(x, y) end -function Decoration:getPosition() + +-- Position-related methods. +function Decoration:getPosition () return self.x, self.y end -function Decoration:draw(offset_x, offset_y, scale) - Sprite.draw(self, offset_x, offset_y, scale) +function Decoration:setPosition (x, y) + self.x, self.y = x, y end \ No newline at end of file -- cgit v1.1