Made HasPressed function and implemented it

This commit is contained in:
bizcochito
2022-01-19 14:55:15 +01:00
parent 0305dd4fc2
commit 03793e1fb8
3 changed files with 47 additions and 35 deletions

View File

@@ -3,8 +3,8 @@ Keybind.move = {}
Keybind.menu = {}
Keybind.debug = {}
function Keybind:Check(action)
for _, keyname in pairs(action) do
function Keybind:CheckDown(action)
for _, keyname in pairs(action.keys) do
if type(keyname) == "string" then
if love.keyboard.isDown(keyname) then return true end
else
@@ -14,43 +14,55 @@ function Keybind:Check(action)
return false
end
function Keybind:Colision(cat, key)
function Keybind:HasPressed(action)
if Keybind:CheckDown(action) then
if not action.pressed then
action.pressed = true
return true
end
else
action.pressed = false
end
return false
end
function Keybind:CheckCollision(cat, key)
for _, action in pairs(cat) do
for _, keyname in pairs(action) do
for _, keyname in pairs(action.keys) do
if key == keyname then return true end
end
end
return false
end
function Keybind:Add(action, key)
table.insert(action, key)
function Keybind:AddKey(action, key)
table.insert(action.keys, key)
end
function Keybind:Change(action, position, key)
action[position] = key
function Keybind:ChangeKey(action, position, key)
action.keys[position] = key
end
function Keybind:Remove(action)
action = {}
function Keybind:RemoveKeys(action)
action.keys = {}
end
function Keybind:Default()
--Menu
Keybind.menu.pause = {"escape"}
Keybind.menu.pause= { keys = {"escape"}}
--Move
Keybind.move.left = {"left", "a"}
Keybind.move.right = {"right", "d"}
Keybind.move.up = {"up", "w"}
Keybind.move.down = {"down", "s"}
Keybind.move.jump = {"z", "space"}
Keybind.move.attack = {"x", 1}
Keybind.move.dash = {"c", 2}
Keybind.move.left = { keys = {"left", "a"}}
Keybind.move.right = { keys = {"right", "d"}}
Keybind.move.up = { keys = {"up", "w"}}
Keybind.move.down = { keys = {"down", "s"}}
Keybind.move.jump = { keys = {"z", "space"}}
Keybind.move.attack = { keys = {"x", 1}}
Keybind.move.dash = { keys = {"c", 2}}
--Debug
Keybind.debug.debug = {"f1"}
Keybind.debug.reposition = {"f2"}
Keybind.debug.reload = {"f3"}
Keybind.debug.editor = {"f4"}
Keybind.debug.debug = { keys = {"f1"}}
Keybind.debug.reposition = { keys = {"f2"}}
Keybind.debug.reload = { keys = {"f3"}}
Keybind.debug.editor = { keys = {"f4"}}
end
-- Set default values at start