From 62b67be7882dffebd6de0c8241d253d806a6905c Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 26 May 2017 19:14:27 +0200 Subject: Halfway through with moving to new OOP module --- not/PhysicalBody.lua | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'not/PhysicalBody.lua') 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 -- cgit v1.1 From 657eb912abc89a71d16ea60516458ad6c72f6a4e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 19 Jul 2017 14:50:25 +0200 Subject: Initial clash No additional effect, rusty mechanics for now --- not/PhysicalBody.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not/PhysicalBody.lua') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index fd92f89..804c706 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -11,6 +11,7 @@ PhysicalBody.body =--[[love.physics.newBody]]nil function PhysicalBody:new (x, y, world, imagePath) PhysicalBody.__super.new(self, world, imagePath) self.body = love.physics.newBody(world.world, x, y) + self.body:setUserData(self) end -- Add new fixture to body. -- cgit v1.1