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/Platform.lua | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 not/Platform.lua (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua new file mode 100644 index 0000000..9b7b03c --- /dev/null +++ b/not/Platform.lua @@ -0,0 +1,73 @@ +-- `Platform` +-- Static platform physical object with a sprite. `Players` can walk on it. +-- Collision category: [1] + +-- WHOLE CODE HAS FLAG OF "need a cleanup" +require "not.Sprite" + +-- Metatable of `Platform` +-- nils initialized in constructor +Platform = { + body = nil, + shape = nil, + fixture = nil, + world = nil, +} +Platform.__index = Platform +setmetatable(Platform, Sprite) + +-- Constructor of `Platform` +function Platform:new (game, world, x, y, shape, sprite, animations) + local o = {} + setmetatable(o, self) + o.body = love.physics.newBody(world, x, y) + -- MULTIPLE SHAPES NEED TO BE REWRITED! + o.shape = {} + if type(shape[1]) == "number" then + local poly = love.physics.newPolygonShape(shape) + table.insert(o.shape, poly) + o.fixture = love.physics.newFixture(o.body, poly) + o.fixture:setCategory(1) + o.fixture:setFriction(0.2) + else + for i,v in pairs(shape) do + local poly = love.physics.newPolygonShape(v) + table.insert(o.shape, poly) + local fixture = love.physics.newFixture(o.body, poly) + fixture:setCategory(1) + fixture:setFriction(0.2) + end + end + -- END HERE + o:setImage(love.graphics.newImage(sprite)) + o:setAnimationsList(animations) + o.world = game + return o +end + +-- Position +function Platform:getPosition() + return self.body:getPosition() +end + +-- Draw of `Platform` +function Platform:draw (offset_x, offset_y, scale, debug) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + local debug = debug or false + 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 + -- sprite draw + Sprite.draw(self, draw_x, draw_y, 0, scale, scale) + -- debug draw + if debug then + love.graphics.setColor(255, 69, 0, 140) + for i,v in pairs(self.shape) do + love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(v:getPoints()))) + end + end +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/Platform.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua index 9b7b03c..ecf0377 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -1,6 +1,8 @@ -- `Platform` -- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] +-- TODO: reformat code to follow new code patterns +-- TODO: comment uncovered code parts -- WHOLE CODE HAS FLAG OF "need a cleanup" require "not.Sprite" @@ -51,6 +53,7 @@ function Platform:getPosition() end -- Draw of `Platform` +-- TODO: see todos in `not.Sprite.draw`. function Platform:draw (offset_x, offset_y, scale, debug) -- locals local offset_x = offset_x or 0 -- 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/Platform.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua index ecf0377..7dcea6c 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -55,17 +55,8 @@ end -- Draw of `Platform` -- TODO: see todos in `not.Sprite.draw`. function Platform:draw (offset_x, offset_y, scale, debug) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - local debug = debug or false - 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 - -- sprite draw - Sprite.draw(self, draw_x, draw_y, 0, scale, scale) + Sprite.draw(self, offset_x, offset_y, scale) + -- debug draw if debug then love.graphics.setColor(255, 69, 0, 140) -- cgit v1.1 From 8fa7ec07a1a9b4307ed9b221770c91a242cd68d9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:16:23 +0200 Subject: Platform is now child of PhysicalBody --- not/Platform.lua | 74 +++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua index 7dcea6c..0c03e73 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -1,67 +1,37 @@ --- `Platform` +--- `Platform` -- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] -- TODO: reformat code to follow new code patterns -- TODO: comment uncovered code parts - --- WHOLE CODE HAS FLAG OF "need a cleanup" -require "not.Sprite" - --- Metatable of `Platform` --- nils initialized in constructor Platform = { - body = nil, - shape = nil, - fixture = nil, - world = nil, + world = --[[not.World]]nil, } + +-- `Platform` is a child of `PhysicalBody`. +require "not.PhysicalBody" Platform.__index = Platform -setmetatable(Platform, Sprite) +setmetatable(Platform, PhysicalBody) -- Constructor of `Platform` function Platform:new (game, world, x, y, shape, sprite, animations) - local o = {} - setmetatable(o, self) - o.body = love.physics.newBody(world, x, y) - -- MULTIPLE SHAPES NEED TO BE REWRITED! - o.shape = {} - if type(shape[1]) == "number" then - local poly = love.physics.newPolygonShape(shape) - table.insert(o.shape, poly) - o.fixture = love.physics.newFixture(o.body, poly) - o.fixture:setCategory(1) - o.fixture:setFriction(0.2) - else - for i,v in pairs(shape) do - local poly = love.physics.newPolygonShape(v) - table.insert(o.shape, poly) - local fixture = love.physics.newFixture(o.body, poly) - fixture:setCategory(1) - fixture:setFriction(0.2) - end - end - -- END HERE - o:setImage(love.graphics.newImage(sprite)) - o:setAnimationsList(animations) - o.world = game + local o = setmetatable({}, self) + o:init(animations, shape, game, x, y, sprite) return o end --- Position -function Platform:getPosition() - return self.body:getPosition() -end - --- Draw of `Platform` --- TODO: see todos in `not.Sprite.draw`. -function Platform:draw (offset_x, offset_y, scale, debug) - Sprite.draw(self, offset_x, offset_y, scale) - - -- debug draw - if debug then - love.graphics.setColor(255, 69, 0, 140) - for i,v in pairs(self.shape) do - love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(v:getPoints()))) - end +-- Initializator of `Platform`. +function Platform:init (animations, shape, world, x, y, imagePath) + PhysicalBody.init(self, world, x, y, imagePath) + self:setAnimationsList(animations) + self.world = world + -- Create table of shapes if single shape is passed. + if type(shape[1]) == "number" then + shape = {shape} + end + -- Add all shapes from as fixtures to body. + for _,single in pairs(shape) do + local fixture = self:addFixture(single) + fixture:setCategory(1) + fixture:setFriction(0.2) end 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/Platform.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua index 0c03e73..5ee2dd7 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -19,7 +19,7 @@ function Platform:new (game, world, x, y, shape, sprite, animations) return o end --- Initializator of `Platform`. +-- Initializer of `Platform`. function Platform:init (animations, shape, world, x, y, imagePath) PhysicalBody.init(self, world, x, y, imagePath) self:setAnimationsList(animations) -- cgit v1.1 From 8e11bf89f1abe547c30f7d5ac39bf0d7ed555f7e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 18:43:14 +0200 Subject: Some of World's create methods are now following new parameter orders of entities constructors --- not/Platform.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Platform.lua') diff --git a/not/Platform.lua b/not/Platform.lua index 5ee2dd7..3748c47 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -13,7 +13,7 @@ Platform.__index = Platform setmetatable(Platform, PhysicalBody) -- Constructor of `Platform` -function Platform:new (game, world, x, y, shape, sprite, animations) +function Platform:new (animations, shape, game, x, y, sprite) local o = setmetatable({}, self) o:init(animations, shape, game, x, y, sprite) return o -- cgit v1.1