From a8551f5da9549453381a0f2daa0ff4aefd06272f Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 02:50:40 +0100 Subject: Added tempalte for not.Player --- not/Player.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 not/Player.lua (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua new file mode 100644 index 0000000..bcd72bc --- /dev/null +++ b/not/Player.lua @@ -0,0 +1,22 @@ +--- `Player` +-- Special `not.Hero` controllable by a player. +Player = { + -- TODO: move functions and properties related to controls from `not.Hero`. +} + +-- `Player` is a child of `Hero`. +require "not.Hero" +Player.__index = Player +setmetatable(Player, Hero) + +-- Constructor of `Player`. +function Player:new (...) + local o = setmetatable({}, self) + o:init(...) + return o +end + +-- Initializator of `Player`. +function Player:init (...) + Hero.init(self, ...) +end \ No newline at end of file -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/Player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index bcd72bc..fd1613c 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -16,7 +16,7 @@ function Player:new (...) return o end --- Initializator of `Player`. +-- Initializer of `Player`. function Player:init (...) Hero.init(self, ...) end \ No newline at end of file -- cgit v1.1 From 5c51b6e4d39bc55887f94dc65e58fd1765d86c1c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 14:30:15 +0200 Subject: First steps to move player-input logics into Player from Hero --- not/Player.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'not/Player.lua') 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 -- cgit v1.1 From 8e11bf89f1abe547c30f7d5ac39bf0d7ed555f7e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 18:43:14 +0200 Subject: Some of World's create methods are now following new parameter orders of entities constructors --- not/Player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 373505d..5fc2adc 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -12,7 +12,7 @@ setmetatable(Player, Hero) -- Constructor of `Player`. -- 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) +function Player:new (name, game, x, y) local o = setmetatable({}, self) o:init(name, game, x, y) -- Load portraits statically to `not.Hero`. -- cgit v1.1 From 527901f599c79047ab9a12fbc065a93faa8f872e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 19:32:26 +0200 Subject: Moved most player-input-related methods from Hero to Player --- not/Player.lua | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 1 deletion(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 5fc2adc..2bee903 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -11,7 +11,6 @@ Player.__index = Player setmetatable(Player, Hero) -- Constructor of `Player`. --- TODO: I'm sure it is a duplicate, but `not.World.create*` methods need to pass proper parameters. function Player:new (name, game, x, y) local o = setmetatable({}, self) o:init(name, game, x, y) @@ -36,3 +35,144 @@ end function Player:getControlSet () return self.controlset end + +-- Check if control of assigned controller is pressed. +function Player:isControlDown (control) + return Controller.isDown(self:getControlSet(), control) +end + +-- Update of `Player`. +function Player:update (dt) + local x, y = self:getLinearVelocity() + 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. + + -- Jumping. + if self.isJumping and self.jumpTimer > 0 then + self:setLinearVelocity(x,-160) + self.jumpTimer = self.jumpTimer - dt + end + + -- Walking. + if self:isControlDown("left") then + self.facing = -1 + self:applyForce(-250, 0) + -- Controlled speed limit + if x < -self.max_velocity then + self:applyForce(250, 0) + end + end + if self:isControlDown("right") then + self.facing = 1 + self:applyForce(250, 0) + -- Controlled speed limit + if x > self.max_velocity then + self:applyForce(-250, 0) + end + end + + -- Limiting walking speed. + if not self:isControlDown("left") and + not self:isControlDown("right") + then + local face = nil + if x < -12 then + face = 1 + elseif x > 12 then + face = -1 + else + face = 0 + end + self:applyForce(40*face,0) + if not self.inAir then + self:applyForce(80*face,0) + end + end +end + +-- Controller callbacks. +function Player:controlpressed (set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + if self.jumpCounter > 0 then + -- General jump logics + self.isJumping = true + --self:playSound(6) + -- Spawn proper effect + if not self.inAir then + self:createEffect("jump") + else + self:createEffect("doublejump") + end + -- Start salto if last jump + if self.jumpCounter == 1 then + self.salto = true + end + -- Animation clear + if (self.current == self.animations.attack) or + (self.current == self.animations.attack_up) or + (self.current == self.animations.attack_down) then + self:setAnimation("default") + end + -- Remove jump + self.jumpCounter = self.jumpCounter - 1 + end + end + + -- Walking + if (action == "left" or action == "right") and + (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end + + -- Punching + if action == "attack" and self.punchCooldown <= 0 then + local f = self.facing + self.salto = false + if isDown(controlset, "up") then + -- Punch up + if self.current ~= self.animations.damage then + self:setAnimation("attack_up") + end + self:punch("up") + elseif isDown(controlset, "down") then + -- Punch down + if self.current ~= self.animations.damage then + self:setAnimation("attack_down") + end + self:punch("down") + else + -- Punch horizontal + if self.current ~= self.animations.damage then + self:setAnimation("attack") + end + if f == 1 then + self:punch("right") + else + self:punch("left") + end + self.punchdir = 1 + end + end +end +function Player:controlreleased (set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + self.isJumping = false + self.jumpTimer = Hero.jumpTimer -- take initial from metatable + end + -- Walking + if (action == "left" or action == "right") and not + (isDown(controlset, "left") or isDown(controlset, "right")) and + self.current == self.animations.walk + then + self:setAnimation("default") + end +end -- cgit v1.1 From a46bdb0673461a69fe4467f794f0ddaab9449f85 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 19:45:59 +0200 Subject: Hero no longer uses controler-related functions/methods --- not/Player.lua | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 2bee903..515684f 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -92,8 +92,6 @@ end -- Controller callbacks. function Player:controlpressed (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then if self.jumpCounter > 0 then @@ -122,24 +120,26 @@ function Player:controlpressed (set, action, key) end -- Walking - if (action == "left" or action == "right") and - (self.current ~= self.animations.attack) and - (self.current ~= self.animations.attack_up) and - (self.current ~= self.animations.attack_down) then - self:setAnimation("walk") + if (action == "left" or action == "right") then + self.isWalking = true + if (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end end -- Punching if action == "attack" and self.punchCooldown <= 0 then local f = self.facing self.salto = false - if isDown(controlset, "up") then + if self:isControlDown("up") then -- Punch up if self.current ~= self.animations.damage then self:setAnimation("attack_up") end self:punch("up") - elseif isDown(controlset, "down") then + elseif self:isControlDown("down") then -- Punch down if self.current ~= self.animations.damage then self:setAnimation("attack_down") @@ -161,18 +161,17 @@ function Player:controlpressed (set, action, key) end function Player:controlreleased (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then self.isJumping = false self.jumpTimer = Hero.jumpTimer -- take initial from metatable end -- Walking - if (action == "left" or action == "right") and not - (isDown(controlset, "left") or isDown(controlset, "right")) and - self.current == self.animations.walk - then - self:setAnimation("default") + if (action == "left" or action == "right") then + self.isWalking = false + if not (self:isControlDown("left") or self:isControlDown("right")) and + self.current == self.animations.walk then + self:setAnimation("default") + end end end -- cgit v1.1 From 5ed018c810a5433851fefc2c45792de1da7e7ca8 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 01:01:07 +0200 Subject: Controller-related methods and variables in Player renamed --- not/Player.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 515684f..719b77e 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -2,7 +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, + controllerSet = --[[Controller.sets.*]]nil, } -- `Player` is a child of `Hero`. @@ -29,16 +29,16 @@ function Player:init (...) end -- Controller set manipulation. -function Player:assignControlSet (set) - self.controlset = set +function Player:assignControllerSet (set) + self.controllerSet = set end -function Player:getControlSet () - return self.controlset +function Player:getControllerSet () + return self.controllerSet end -- Check if control of assigned controller is pressed. function Player:isControlDown (control) - return Controller.isDown(self:getControlSet(), control) + return Controller.isDown(self:getControllerSet(), control) end -- Update of `Player`. @@ -91,7 +91,7 @@ end -- Controller callbacks. function Player:controlpressed (set, action, key) - if set ~= self:getControlSet() then return end + if set ~= self:getControllerSet() then return end -- Jumping if action == "jump" then if self.jumpCounter > 0 then @@ -160,7 +160,7 @@ function Player:controlpressed (set, action, key) end end function Player:controlreleased (set, action, key) - if set ~= self:getControlSet() then return end + if set ~= self:getControllerSet() then return end -- Jumping if action == "jump" then self.isJumping = false -- cgit v1.1 From 970655737ce7f497f0725d28605fc296c9923a64 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:16:05 +0200 Subject: Hotfix for destroyed body crash --- not/Player.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 719b77e..30057bb 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -43,9 +43,9 @@ end -- Update of `Player`. function Player:update (dt) - local x, y = self:getLinearVelocity() 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. - + if self.body:isDestroyed() then return end + local x, y = self:getLinearVelocity() -- Jumping. if self.isJumping and self.jumpTimer > 0 then self:setLinearVelocity(x,-160) -- cgit v1.1 From eff39f1f49d5223cb27b5874f8ac29ce8a2ef85f Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:28:21 +0200 Subject: Moved damping back to Hero from Player --- not/Player.lua | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'not/Player.lua') diff --git a/not/Player.lua b/not/Player.lua index 30057bb..2a4b2e6 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -69,24 +69,6 @@ function Player:update (dt) self:applyForce(-250, 0) end end - - -- Limiting walking speed. - if not self:isControlDown("left") and - not self:isControlDown("right") - then - local face = nil - if x < -12 then - face = 1 - elseif x > 12 then - face = -1 - else - face = 0 - end - self:applyForce(40*face,0) - if not self.inAir then - self:applyForce(80*face,0) - end - end end -- Controller callbacks. -- cgit v1.1