summaryrefslogtreecommitdiffhomepage
path: root/not/PhysicalBody.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
committerAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
commitb1cf14d64a2d3e28683db87190c4b2c7799c259d (patch)
treee45dac5cc6ce5265e3e3e2c914eb7cc92a820b8b /not/PhysicalBody.lua
parent0dd01913fe0eefc7ba4bc0797877f40fdedf9315 (diff)
parented62b573417bdc85bec616f6016846b02de4c906 (diff)
downloadroflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.zip
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.gz
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.bz2
Merge branch 'multi'maps
Diffstat (limited to 'not/PhysicalBody.lua')
-rw-r--r--not/PhysicalBody.lua34
1 files changed, 13 insertions, 21 deletions
diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua
index e9625fa..804c706 100644
--- a/not/PhysicalBody.lua
+++ b/not/PhysicalBody.lua
@@ -1,26 +1,17 @@
+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)
+ self.body:setUserData(self)
end
-- Add new fixture to body.
@@ -68,12 +59,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 +77,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