summaryrefslogtreecommitdiffhomepage
path: root/not/Hero.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-03-19 01:35:43 +0100
committerAki <nthirtyone@gmail.com>2017-03-19 01:35:43 +0100
commitb262cb3eec1a797832d168f9e6d144468fb48c1d (patch)
tree3bdc06329029d44f14515830afacee7410b69956 /not/Hero.lua
parent340a3a4b92de5495b47e8e1e102178edfd97514f (diff)
downloadroflnauts-b262cb3eec1a797832d168f9e6d144468fb48c1d.zip
roflnauts-b262cb3eec1a797832d168f9e6d144468fb48c1d.tar.gz
roflnauts-b262cb3eec1a797832d168f9e6d144468fb48c1d.tar.bz2
Initializers in PhysicalBody, Hero and Sprite
Diffstat (limited to 'not/Hero.lua')
-rw-r--r--not/Hero.lua52
1 files changed, 29 insertions, 23 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index 8d226ac..eee7a83 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -36,7 +36,7 @@ Hero = {
-- Sounds
sfx = require "sounds",
-- Animations table
- animations = require "animations"
+ animations = nil
}
-- `Hero` is a child of `PhysicalBody`.
@@ -46,28 +46,9 @@ setmetatable(Hero, PhysicalBody)
-- Constructor of `Hero`.
function Hero:new (game, world, x, y, name)
- -- Meta
- local o = {}
- setmetatable(o, self)
- -- Physics
- local group = -1-#game.Nauts
- o.body = love.physics.newBody(world, x, y, "dynamic")
- o.shape = love.physics.newRectangleShape(10, 16)
- o.fixture = love.physics.newFixture(o.body, o.shape, 8)
- o.fixture:setUserData(o)
- o.fixture:setCategory(2)
- o.fixture:setMask(2)
- o.fixture:setGroupIndex(group)
- o.body:setFixedRotation(true)
- -- Misc
- o.name = name or "empty"
- o:setImage(Sprite.newImage("assets/nauts/"..o.name..".png"))
- o.world = game
- o.punchcd = 0
- -- Animation
- o.current = o.animations.default
- o:createEffect("respawn")
- -- Portrait load for first object created
+ local o = setmetatable({}, self)
+ o:init(name, game, x, y)
+ -- Load portraits statically.
if self.portrait_sprite == nil then
self.portrait_sprite = love.graphics.newImage("assets/portraits.png")
self.portrait_frame = love.graphics.newImage("assets/menu.png")
@@ -75,6 +56,31 @@ function Hero:new (game, world, x, y, name)
return o
end
+-- Initializator of `Hero`.
+function Hero:init (name, world, x, y)
+ -- Find imagePath basing on hero name and call super initializator.
+ 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)
+ -- To be removed or heavily changed.
+ self.world = world
+ self.punchcd = 0
+ -- To be moved to PhysicalBody abstract.
+ 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)
+ -- Actual `Hero` initialization.
+ self.name = name
+ self:setAnimationsList(require("animations"))
+ self:createEffect("respawn")
+end
+
-- Control set managment
function Hero:assignControlSet(set)
self.controlset = set