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/Player.lua | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 2a4b2e6..5d108ce 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -1,31 +1,15 @@ +require "not.Hero" + --- `Player` -- Special `not.Hero` controllable by a player. -Player = { - -- TODO: move functions and properties related to controls from `not.Hero`. - controllerSet = --[[Controller.sets.*]]nil, -} +-- TODO: move functions and properties related to controls from `not.Hero`. +Player = Hero:extends() --- `Player` is a child of `Hero`. -require "not.Hero" -Player.__index = Player -setmetatable(Player, Hero) +Player.controllerSet =--[[Controller.sets.*]]nil -- Constructor of `Player`. -function Player:new (name, game, x, y) - local o = setmetatable({}, self) - o:init(name, game, x, y) - -- Load portraits statically to `not.Hero`. - -- TODO: this is heresy, put it into `load` method or something similar. - if Hero.portrait_sprite == nil then - Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") - Hero.portrait_frame = love.graphics.newImage("assets/menu.png") - end - return o -end - --- Initializer of `Player`. -function Player:init (...) - Hero.init(self, ...) +function Player:new (name, x, y, world) + Player.__super.new(self, name, x, y, world) end -- Controller set manipulation. @@ -43,7 +27,7 @@ end -- Update of `Player`. function Player:update (dt) - Hero.update(self, dt) -- TODO: It would be probably a good idea to add return to update functions to terminate if something goes badly in parent's update. + Player.__super.update(self, dt) -- TODO: It would be probably a good idea to add return to update functions to terminate if something goes badly in parent's update. if self.body:isDestroyed() then return end local x, y = self:getLinearVelocity() -- Jumping. @@ -157,3 +141,5 @@ function Player:controlreleased (set, action, key) end end end + +return Player -- cgit v1.1