summaryrefslogtreecommitdiffhomepage
path: root/not/Platform.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-03 18:16:23 +0200
committerAki <nthirtyone@gmail.com>2017-04-03 18:16:23 +0200
commit8fa7ec07a1a9b4307ed9b221770c91a242cd68d9 (patch)
tree437826f0c6566343ef6272c0fbee1930cded0c59 /not/Platform.lua
parent9af03e90acde019820021d0bc2fe546d10c25ed4 (diff)
downloadroflnauts-8fa7ec07a1a9b4307ed9b221770c91a242cd68d9.zip
roflnauts-8fa7ec07a1a9b4307ed9b221770c91a242cd68d9.tar.gz
roflnauts-8fa7ec07a1a9b4307ed9b221770c91a242cd68d9.tar.bz2
Platform is now child of PhysicalBody
Diffstat (limited to 'not/Platform.lua')
-rw-r--r--not/Platform.lua74
1 files changed, 22 insertions, 52 deletions
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