diff options
author | Aki <nthirtyone@gmail.com> | 2017-05-26 19:14:27 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-05-26 19:14:27 +0200 |
commit | 62b67be7882dffebd6de0c8241d253d806a6905c (patch) | |
tree | 4b4bc483d4a95f5cb02cc33e41a5600c28cfb49b /not/PhysicalBody.lua | |
parent | afac3fdc7ce03e03304eec448149f346099cab94 (diff) | |
download | roflnauts-62b67be7882dffebd6de0c8241d253d806a6905c.zip roflnauts-62b67be7882dffebd6de0c8241d253d806a6905c.tar.gz roflnauts-62b67be7882dffebd6de0c8241d253d806a6905c.tar.bz2 |
Halfway through with moving to new OOP module
Diffstat (limited to 'not/PhysicalBody.lua')
-rw-r--r-- | not/PhysicalBody.lua | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index e9625fa..fd92f89 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -1,25 +1,15 @@ +require "not.Entity" + --- `PhysicalBody` -- Abstract class for drawable entity existing in `not.World`. -PhysicalBody = { - body =--[[love.physics.newBody]]nil, -} - --- `PhysicalBody` is a child of `Sprite`. -require "not.Sprite" -PhysicalBody.__index = PhysicalBody -setmetatable(PhysicalBody, Sprite) +PhysicalBody = Entity:extends() ---[[ Constructor of `PhysicalBody`. -function PhysicalBody:new (world, x, y, imagePath) - local o = setmetatable({}, self) - o:init(world, x, y, imagePath) - return o -end -]] +PhysicalBody.body =--[[love.physics.newBody]]nil --- Initializer of `PhysicalBody`. -function PhysicalBody:init (world, x, y, imagePath) - Sprite.init(self, imagePath) +-- Constructor of `PhysicalBody`. +-- `world` and `imagePath` are passed to parent's constructor (`Entity`). +function PhysicalBody:new (x, y, world, imagePath) + PhysicalBody.__super.new(self, world, imagePath) self.body = love.physics.newBody(world.world, x, y) end @@ -68,12 +58,12 @@ end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) - Sprite.update(self, dt) + PhysicalBody.__super.update(self, dt) end -- Draw of `PhysicalBody`. function PhysicalBody:draw (offset_x, offset_y, scale, debug) - Sprite.draw(self, offset_x, offset_y, scale) + PhysicalBody.__super.draw(self, offset_x, offset_y, scale) if debug then for _,fixture in pairs(self.body:getFixtureList()) do local category = fixture:getCategory() @@ -86,8 +76,9 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) if category == 3 then love.graphics.setColor(137, 0, 255, 40) end - -- TODO: `world` is not a member of `PhysicalBody` or its instance normally. love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) end end end + +return PhysicalBody |