summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-03 17:20:55 +0200
committerAki <nthirtyone@gmail.com>2017-04-03 17:20:55 +0200
commitbda0f791d64178904e655f74efce24a2f3fc2f96 (patch)
tree23657c3aff5d463bc8620e5aa73848e3af400ef8
parentfcc6dc19b495fbf21a803f10f7c4cec41d4f8a49 (diff)
downloadroflnauts-bda0f791d64178904e655f74efce24a2f3fc2f96.zip
roflnauts-bda0f791d64178904e655f74efce24a2f3fc2f96.tar.gz
roflnauts-bda0f791d64178904e655f74efce24a2f3fc2f96.tar.bz2
Position, Fixture, Body init moved from Hero to PhysicalBody
-rw-r--r--not/Hero.lua21
-rw-r--r--not/PhysicalBody.lua25
2 files changed, 32 insertions, 14 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index c9250e0..4654b33 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -55,19 +55,18 @@ function Hero:init (name, world, x, y)
local fileName = name or Hero.name -- INITIAL from metatable
local imagePath = string.format("assets/nauts/%s.png", fileName)
PhysicalBody.init(self, world, x, y, imagePath)
+ self:setBodyType("dynamic")
+ self:setBodyFixedRotation(true)
-- TODO: probably should be removed or heavily changed.
self.world = world
self.punchcd = 0
-- TODO: move following lines to PhysicalBody, cut if not needed, refectorize to subfunctions in target class.
local group = -1-#world.Nauts
- self.body = love.physics.newBody(world.world, x, y, "dynamic")
- self.shape = love.physics.newRectangleShape(10, 16)
- self.fixture = love.physics.newFixture(self.body, self.shape, 8)
- self.fixture:setUserData(self)
- self.fixture:setCategory(2)
- self.fixture:setMask(2)
- self.fixture:setGroupIndex(group)
- self.body:setFixedRotation(true)
+ local fixture = self:addFixture({-5,-8, 5,-8, 5,8, -5,8}, 8)
+ fixture:setUserData(self)
+ fixture:setCategory(2)
+ fixture:setMask(2)
+ fixture:setGroupIndex(group)
-- Actual `Hero` initialization.
self.name = name
self:setAnimationsList(require("animations"))
@@ -296,7 +295,6 @@ end
function Hero:draw (offset_x, offset_y, scale, debug)
if not self.alive then return end
PhysicalBody.draw(self, offset_x, offset_y, scale, debug)
-
-- debug draw
if debug then
for _,fixture in pairs(self.body:getFixtureList()) do
@@ -315,11 +313,6 @@ function Hero:draw (offset_x, offset_y, scale, debug)
end
end
--- getPosition
-function Hero:getPosition ()
- return self.body:getPosition()
-end
-
-- Draw HUD of `Hero`
-- elevation: 1 bottom, 0 top
function Hero:drawHUD (x,y,scale,elevation)
diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua
index bbea3ac..54d334f 100644
--- a/not/PhysicalBody.lua
+++ b/not/PhysicalBody.lua
@@ -20,6 +20,31 @@ end
-- Initializator of `PhysicalBody`.
function PhysicalBody:init (world, x, y, imagePath)
Sprite.init(self, imagePath)
+ self.body = love.physics.newBody(world.world, x, y)
+end
+
+-- Add new fixture to body.
+function PhysicalBody:addFixture (shape, density)
+ local shape = love.physics.newPolygonShape(shape)
+ local fixture = love.physics.newFixture(self.body, shape, density)
+ return fixture
+end
+
+-- Position-related methods.
+function PhysicalBody:getPosition ()
+ return self.body:getPosition()
+end
+function PhysicalBody:setPosition (x, y)
+ self.body:setPosition(x, y)
+end
+
+-- Various setters from Body.
+-- type: BodyType ("static", "dynamic", "kinematic")
+function PhysicalBody:setBodyType (type)
+ self.body:setType(type)
+end
+function PhysicalBody:setBodyFixedRotation (bool)
+ self.body:setFixedRotation(bool)
end
-- Update of `PhysicalBody`.