From 84278ed41f61c586dbb38dd99c45ee33e2f58c77 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 16 Mar 2017 19:05:50 +0100 Subject: Moved ? -> not.?; Renamed Player -> Hero --- not/Decoration.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 not/Decoration.lua (limited to 'not/Decoration.lua') diff --git a/not/Decoration.lua b/not/Decoration.lua new file mode 100644 index 0000000..7f020e1 --- /dev/null +++ b/not/Decoration.lua @@ -0,0 +1,34 @@ +require "not.Sprite" +Decoration = { + world = nil, + sprite = nil, + x = 0, + y = 0 +} +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) + return o +end +function Decoration:setPosition(x, y) + self.x, self.y = x, y +end +function Decoration:getPosition() + return self.x, self.y +end +function Decoration:draw(offset_x, offset_y, scale) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + local x, y = self:getPosition() + -- pixel grid + local draw_x = (math.floor(x) + offset_x) * scale + local draw_y = (math.floor(y) + offset_y) * scale + -- draw + Sprite.draw(self, draw_x, draw_y, 0, scale, scale) +end \ No newline at end of file -- cgit v1.1 From 2e352657813b37d17c2215b85189f18a50c099f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:29:32 +0100 Subject: Comments, todos, pretty useless --- not/Decoration.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'not/Decoration.lua') diff --git a/not/Decoration.lua b/not/Decoration.lua index 7f020e1..5bfc328 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -1,3 +1,5 @@ +-- TODO: follow new code template +-- TODO: add comments require "not.Sprite" Decoration = { world = nil, -- cgit v1.1 From cca4d9c1bf4033c79e4bd61a257c6ea02557524c Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 04:19:59 +0100 Subject: Moving draw away to abstract classes --- not/Decoration.lua | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'not/Decoration.lua') diff --git a/not/Decoration.lua b/not/Decoration.lua index 5bfc328..a57c143 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -23,14 +23,5 @@ function Decoration:getPosition() return self.x, self.y end function Decoration:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - local x, y = self:getPosition() - -- pixel grid - local draw_x = (math.floor(x) + offset_x) * scale - local draw_y = (math.floor(y) + offset_y) * scale - -- draw - Sprite.draw(self, draw_x, draw_y, 0, scale, scale) + Sprite.draw(self, offset_x, offset_y, scale) end \ No newline at end of file -- cgit v1.1 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/Decoration.lua') 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 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/Decoration.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Decoration.lua') diff --git a/not/Decoration.lua b/not/Decoration.lua index 80f6653..9dc2bdd 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -18,7 +18,7 @@ function Decoration:new (x, y, imagePath) return o end --- Initializator of `Decoration`. +-- Initializer of `Decoration`. function Decoration:init (x, y, imagePath) Sprite.init(self, imagePath) self:setPosition(x, y) -- cgit v1.1