redone controls #1

Merged
lustlion merged 1 commits from :master into master 2022-01-18 16:34:16 +00:00
2 changed files with 27 additions and 15 deletions
Showing only changes of commit 58b4e16251 - Show all commits

View File

@ -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

View File

@ -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}