diff options
author | Aki <nthirtyone@gmail.com> | 2017-04-04 14:30:15 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-04-04 14:30:15 +0200 |
commit | 5c51b6e4d39bc55887f94dc65e58fd1765d86c1c (patch) | |
tree | 6695789c539f3ef748a6180e06211e6b01fab72a /not | |
parent | 10db7a170cf28db93740448bba76f7a9cd452664 (diff) | |
download | roflnauts-5c51b6e4d39bc55887f94dc65e58fd1765d86c1c.zip roflnauts-5c51b6e4d39bc55887f94dc65e58fd1765d86c1c.tar.gz roflnauts-5c51b6e4d39bc55887f94dc65e58fd1765d86c1c.tar.bz2 |
First steps to move player-input logics into Player from Hero
Diffstat (limited to 'not')
-rw-r--r-- | not/Hero.lua | 13 | ||||
-rw-r--r-- | not/Player.lua | 22 | ||||
-rw-r--r-- | not/World.lua | 6 |
3 files changed, 23 insertions, 18 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 7b968ab..a0758ee 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -1,5 +1,5 @@ --- `Hero` --- Hero (naut) entity that exists in a game world. +-- Hero (often referred to as: "naut") entity that exists in a game world. -- Collision category: [2] Hero = { -- General and physics @@ -22,8 +22,6 @@ Hero = { isJumping = false, jumpTimer = 0.16, jumpCounter = 2, - -- Keys - controlset = nil, -- Statics portrait_sprite = nil, portrait_frame = nil, @@ -73,15 +71,6 @@ function Hero:init (name, world, x, y) self:createEffect("respawn") end --- Control set managment --- TODO: move these two to `not.Player`. -function Hero:assignControlSet (set) - self.controlset = set -end -function Hero:getControlSet () - return self.controlset -end - -- Update callback of `Hero` -- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) diff --git a/not/Player.lua b/not/Player.lua index fd1613c..373505d 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -2,6 +2,7 @@ -- Special `not.Hero` controllable by a player. Player = { -- TODO: move functions and properties related to controls from `not.Hero`. + controlSet = --[[Controller.sets.*]]nil, } -- `Player` is a child of `Hero`. @@ -10,13 +11,28 @@ Player.__index = Player setmetatable(Player, Hero) -- Constructor of `Player`. -function Player:new (...) +-- TODO: I'm sure it is a duplicate, but `not.World.create*` methods need to pass proper parameters. +function Player:new (game, world, x, y, name) local o = setmetatable({}, self) - o:init(...) + 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, ...) -end
\ No newline at end of file +end + +-- Controller set manipulation. +function Player:assignControlSet (set) + self.controlset = set +end +function Player:getControlSet () + return self.controlset +end diff --git a/not/World.lua b/not/World.lua index b7bd48c..44923bb 100644 --- a/not/World.lua +++ b/not/World.lua @@ -5,7 +5,7 @@ -- WHOLE CODE HAS FLAG OF "need a cleanup" require "not.Platform" -require "not.Hero" +require "not.Player" require "not.Cloud" require "not.Effect" require "not.Decoration" @@ -136,9 +136,9 @@ end -- Add new naut to the world -- TODO: separate two methods for `not.Hero` and `not.Player`. --- TODO: follow new parameters in `not.Player.new` based on `not.Player.init`. +-- TODO: follow new parameters in `not.(Player/Hero).new` based on `not.(Player/Hero).init`. function World:createNaut(x, y, name) - local naut = Hero:new(self, self.world, x, y, name) + local naut = Player:new(self, self.world, x, y, name) table.insert(self.Nauts, naut) return naut end |