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 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 self.move_x = -self.moveSpeed
elseif love.keyboard.isDown(keybind.moveRight) then elseif keybind:Check(keybind.moveRight) then
self.move_x = self.moveSpeed self.move_x = self.moveSpeed
else else
self.move_x = 0 self.move_x = 0
end end
self.vel.x = self.vel.x self.vel.x = self.vel.x
if love.keyboard.isDown(keybind.moveJump) then if keybind:Check(keybind.moveJump) then
if self.isOnGround then if self.isOnGround then
self.vel.y = -self.jumpImpulse self.vel.y = -self.jumpImpulse
end end
@ -90,18 +90,18 @@ function Player:Smart()
end end
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt) 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 if self.dashCooldownTimer == 0
and not self.isDashing and not self.isDashing
and self.dashCount > 0 then and self.dashCount > 0 then
self.dashCount = self.dashCount - 1 self.dashCount = self.dashCount - 1
self.isDashing = true self.isDashing = true
local vertical = 0 local vertical = 0
if love.keyboard.isDown(keybind.moveDown) then vertical = vertical + 1 end if keybind:Check(keybind.moveDown) then vertical = vertical + 1 end
if love.keyboard.isDown(keybind.moveUp) then vertical = vertical - 1 end if keybind:Check(keybind.moveUp) then vertical = vertical - 1 end
local horizontal = 0 local horizontal = 0
if love.keyboard.isDown(keybind.moveRight) then horizontal = horizontal + 1 end if keybind:Check(keybind.moveRight) then horizontal = horizontal + 1 end
if love.keyboard.isDown(keybind.moveLeft) then horizontal = horizontal - 1 end if keybind:Check(keybind.moveLeft) then horizontal = horizontal - 1 end
if horizontal == 0 and vertical == 0 then if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x horizontal = self.sprite_flip.x

View File

@ -1,9 +1,21 @@
keybind = {} keybind = {}
keybind.moveLeft = "left" function keybind:Check(key)
keybind.moveRight = "right" for _, keyname in pairs(key) do
keybind.moveUp = "up" if type(keyname) == "string" then
keybind.moveDown = "down" if love.keyboard.isDown(keyname) then return true end
keybind.moveJump = "z" else
keybind.moveAttack = "x" if love.mouse.isDown(keyname) then return true end
keybind.moveDash = "c" 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}