summaryrefslogtreecommitdiffhomepage
path: root/player.lua
diff options
context:
space:
mode:
Diffstat (limited to 'player.lua')
-rw-r--r--player.lua66
1 files changed, 28 insertions, 38 deletions
diff --git a/player.lua b/player.lua
index 077780c..fe11dbe 100644
--- a/player.lua
+++ b/player.lua
@@ -38,8 +38,7 @@ Player = {
jumptimer = 0.16,
jumpnumber = 2,
-- Keys
- controller = nil,
- controller_empty = {isDown = function () return false end},
+ controlset = nil,
-- HUD
portrait_sprite = nil,
portrait_sheet = require "portraits",
@@ -81,22 +80,16 @@ function Player:delete()
self.sprite = nil
end
--- Controller
-function Player:assignController(controller)
- self.controller = controller or nil
- controller:setParent(self)
+-- Control set managment
+function Player:assignControlSet(set)
+ self.controlset = set or nil
end
-
-function Player:getController()
- if self.controller ~= nil then
- return self.controller
- else
- return self.controller_empty
- end
+function Player:getControlSet()
+ return self.controlset
end
-- Update callback of `Player`
-function Player:update (dt)
+function Player:update(dt)
-- hotfix? for destroyed bodies
if self.body:isDestroyed() then return end
-- # LOCALS
@@ -120,8 +113,7 @@ function Player:update (dt)
-- # HORIZONTAL MOVEMENT
-- Walking
- local controller = self:getController()
- if controller:isDown("left") then
+ if Controller.isDown(self:getControlSet(), "left") then
self.facing = -1
self.body:applyForce(-250, 0)
-- Controlled speed limit
@@ -129,7 +121,7 @@ function Player:update (dt)
self.body:applyForce(250, 0)
end
end
- if controller:isDown("right") then
+ if Controller.isDown(self:getControlSet(), "right") then
self.facing = 1
self.body:applyForce(250, 0)
-- Controlled speed limit
@@ -139,8 +131,8 @@ function Player:update (dt)
end
-- Custom linear damping
- if not controller:isDown("left") and
- not controller:isDown("right")
+ if not Controller.isDown(self:getControlSet(), "left") and
+ not Controller.isDown(self:getControlSet(), "right")
then
local face = nil
if x < -12 then
@@ -164,7 +156,7 @@ function Player:update (dt)
-- Thank you De Morgan!
if self.current.repeated or not (self.frame == self.current.frames) then
self.frame = (self.frame % self.current.frames) + 1
- elseif controller:isDown("right") or controller:isDown("left") then
+ elseif Controller.isDown(self:getControlSet(), "right") or Controller.isDown(self:getControlSet(), "left") then
-- If nonrepeatable animation is finished and player is walking
self:changeAnimation("walk")
elseif self.current == self.animations.damage then
@@ -209,11 +201,11 @@ function Player:update (dt)
end
end
--- Keypressed callback (I think?) of `Player`
-function Player:controllerPressed (key)
- local controller = self:getController()
+-- Controller callbacks
+function Player:controlpressed(set, action, key)
+ if set ~= self:getControlSet() then return end
-- Jumping
- if key == "jump" then
+ if action == "jump" then
if self.jumpnumber > 0 then
-- General jump logics
self.jumpactive = true
@@ -239,7 +231,7 @@ function Player:controllerPressed (key)
end
-- Walking
- if (key == "left" or key == "right") and
+ 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
@@ -247,16 +239,16 @@ function Player:controllerPressed (key)
end
-- Punching
- if key == "attack" and self.punchcd <= 0 then
+ if action == "attack" and self.punchcd <= 0 then
local f = self.facing
self.salto = false
- if controller:isDown("up") then
+ if Controller.isDown(self:getControlSet(), "up") then
-- Punch up
if self.current ~= self.animations.damage then
self:changeAnimation("attack_up")
end
self:hit(-f,-18,4*f,10, 0, -1)
- elseif controller:isDown("down") then
+ elseif Controller.isDown(self:getControlSet(), "down") then
-- Punch down
if self.current ~= self.animations.damage then
self:changeAnimation("attack_down")
@@ -272,19 +264,16 @@ function Player:controllerPressed (key)
end
end
end
-
--- Keyreleased callback (I think?) of `Player`
-function Player:controllerReleased (key)
- local controller = self:getController()
+function Player:controlreleased(set, action, key)
+ if set ~= self:getControlSet() then return end
-- Jumping
- if key == "jump" then
+ if action == "jump" then
self.jumpactive = false
self.jumptimer = Player.jumptimer -- take initial from metatable
end
-
-- Walking
- if (key == "left" or key == "right") and not
- (controller:isDown("left") or controller:isDown("right")) and
+ if (action == "left" or action == "right") and not
+ (Controller.isDown(self:getControlSet(), "left") or Controller.isDown(self:getControlSet(), "right")) and
self.current == self.animations.walk
then
self:changeAnimation("idle")
@@ -292,7 +281,7 @@ function Player:controllerReleased (key)
end
-- Draw of `Player`
-function Player:draw (offset_x, offset_y, scale, debug)
+function Player:draw(offset_x, offset_y, scale, debug)
-- locals
local offset_x = offset_x or 0
local offset_y = offset_y or 0
@@ -320,12 +309,13 @@ end
-- Draw HUD of `Player`
-- elevation: 1 bottom, 0 top
-function Player:drawHUD (x,y,scale,elevation)
+function Player:drawHUD(x,y,scale,elevation)
-- hud displays only if player is alive
if self.alive then
love.graphics.setColor(255,255,255,255)
love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name].normal, x*scale, y*scale, 0, scale, scale)
local dy = 30 * elevation
+ love.graphics.setFont(Font)
love.graphics.print((self.combo*10).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale)
love.graphics.print(math.max(0, self.lives),(x+24)*scale,(y-3+dy)*scale,0,scale,scale)
end