summaryrefslogtreecommitdiffhomepage
path: root/not/Player.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
committerAki <nthirtyone@gmail.com>2017-08-13 02:26:55 +0200
commitb1cf14d64a2d3e28683db87190c4b2c7799c259d (patch)
treee45dac5cc6ce5265e3e3e2c914eb7cc92a820b8b /not/Player.lua
parent0dd01913fe0eefc7ba4bc0797877f40fdedf9315 (diff)
parented62b573417bdc85bec616f6016846b02de4c906 (diff)
downloadroflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.zip
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.gz
roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.bz2
Merge branch 'multi'maps
Diffstat (limited to 'not/Player.lua')
-rw-r--r--not/Player.lua49
1 files changed, 18 insertions, 31 deletions
diff --git a/not/Player.lua b/not/Player.lua
index 2a4b2e6..b0dac75 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.
@@ -57,7 +41,7 @@ function Player:update (dt)
self.facing = -1
self:applyForce(-250, 0)
-- Controlled speed limit
- if x < -self.max_velocity then
+ if x < -self.MAX_VELOCITY then
self:applyForce(250, 0)
end
end
@@ -65,7 +49,7 @@ function Player:update (dt)
self.facing = 1
self:applyForce(250, 0)
-- Controlled speed limit
- if x > self.max_velocity then
+ if x > self.MAX_VELOCITY then
self:applyForce(-250, 0)
end
end
@@ -74,6 +58,7 @@ end
-- Controller callbacks.
function Player:controlpressed (set, action, key)
if set ~= self:getControllerSet() then return end
+ self.smoke = false -- TODO: temporary
-- Jumping
if action == "jump" then
if self.jumpCounter > 0 then
@@ -137,7 +122,6 @@ function Player:controlpressed (set, action, key)
else
self:punch("left")
end
- self.punchdir = 1
end
end
end
@@ -150,10 +134,13 @@ function Player:controlreleased (set, action, key)
end
-- Walking
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")
+ if not (self:isControlDown("left") or self:isControlDown("right")) then
+ self.isWalking = false
+ if self.current == self.animations.walk then
+ self:setAnimation("default")
+ end
end
end
end
+
+return Player