From 58b4e162519118f328a0655f7413a656b27d232e Mon Sep 17 00:00:00 2001 From: bizcochito Date: Tue, 18 Jan 2022 16:49:49 +0100 Subject: [PATCH] redone controls you can have any ammount of keys assigned to an acction, only mouse and keyboard supported for now --- data/scripts/entities/player.lua | 16 ++++++++-------- data/scripts/keybind.lua | 26 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/data/scripts/entities/player.lua b/data/scripts/entities/player.lua index 4077548..4ea1e5f 100644 --- a/data/scripts/entities/player.lua +++ b/data/scripts/entities/player.lua @@ -73,16 +73,16 @@ function Player:Smart() if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end - if love.keyboard.isDown(keybind.moveLeft) then + if keybind:Check(keybind.moveLeft) then self.move_x = -self.moveSpeed - elseif love.keyboard.isDown(keybind.moveRight) then + elseif keybind:Check(keybind.moveRight) then self.move_x = self.moveSpeed else self.move_x = 0 end self.vel.x = self.vel.x - if love.keyboard.isDown(keybind.moveJump) then + if keybind:Check(keybind.moveJump) then if self.isOnGround then self.vel.y = -self.jumpImpulse end @@ -90,18 +90,18 @@ function Player:Smart() end self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt) - if love.keyboard.isDown(keybind.moveDash) then + if keybind:Check(keybind.moveDash) then if self.dashCooldownTimer == 0 and not self.isDashing and self.dashCount > 0 then self.dashCount = self.dashCount - 1 self.isDashing = true local vertical = 0 - if love.keyboard.isDown(keybind.moveDown) then vertical = vertical + 1 end - if love.keyboard.isDown(keybind.moveUp) then vertical = vertical - 1 end + if keybind:Check(keybind.moveDown) then vertical = vertical + 1 end + if keybind:Check(keybind.moveUp) then vertical = vertical - 1 end local horizontal = 0 - if love.keyboard.isDown(keybind.moveRight) then horizontal = horizontal + 1 end - if love.keyboard.isDown(keybind.moveLeft) then horizontal = horizontal - 1 end + if keybind:Check(keybind.moveRight) then horizontal = horizontal + 1 end + if keybind:Check(keybind.moveLeft) then horizontal = horizontal - 1 end if horizontal == 0 and vertical == 0 then horizontal = self.sprite_flip.x diff --git a/data/scripts/keybind.lua b/data/scripts/keybind.lua index e1acf4c..6d42b06 100644 --- a/data/scripts/keybind.lua +++ b/data/scripts/keybind.lua @@ -1,9 +1,21 @@ keybind = {} -keybind.moveLeft = "left" -keybind.moveRight = "right" -keybind.moveUp = "up" -keybind.moveDown = "down" -keybind.moveJump = "z" -keybind.moveAttack = "x" -keybind.moveDash = "c" +function keybind:Check(key) + for _, keyname in pairs(key) do + if type(keyname) == "string" then + if love.keyboard.isDown(keyname) then return true end + else + if love.mouse.isDown(keyname) then return true end + end + end + return false +end + + +keybind.moveLeft = {"left", "a"} +keybind.moveRight = {"right", "d"} +keybind.moveUp = {"up", "w"} +keybind.moveDown = {"down", "s"} +keybind.moveJump = {"z", "space"} +keybind.moveAttack = {"x", 1} +keybind.moveDash = {"c", 2} -- 2.39.2