Merge pull request 'Made HasPressed function and implemented it' (#6) from bizcochito/Mothback:master into master
Reviewed-on: https://git.fai.su/lustlion/Mothback/pulls/6
This commit is contained in:
commit
0706d76b57
|
@ -73,16 +73,16 @@ function Player:Smart()
|
|||
|
||||
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
|
||||
|
||||
if Keybind:Check(Keybind.move.left) then
|
||||
if Keybind:CheckDown(Keybind.move.left) then
|
||||
self.move_x = -self.moveSpeed
|
||||
elseif Keybind:Check(Keybind.move.right) then
|
||||
elseif Keybind:CheckDown(Keybind.move.right) then
|
||||
self.move_x = self.moveSpeed
|
||||
else
|
||||
self.move_x = 0
|
||||
end
|
||||
self.vel.x = self.vel.x
|
||||
|
||||
if Keybind:Check(Keybind.move.jump) then
|
||||
if Keybind:CheckDown(Keybind.move.jump) 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 Keybind:Check(Keybind.move.dash) then
|
||||
if Keybind:CheckDown(Keybind.move.dash) 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 Keybind:Check(Keybind.move.down) then vertical = vertical + 1 end
|
||||
if Keybind:Check(Keybind.move.up) then vertical = vertical - 1 end
|
||||
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
|
||||
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
|
||||
local horizontal = 0
|
||||
if Keybind:Check(Keybind.move.right) then horizontal = horizontal + 1 end
|
||||
if Keybind:Check(Keybind.move.left) then horizontal = horizontal - 1 end
|
||||
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
|
||||
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
|
||||
|
||||
if horizontal == 0 and vertical == 0 then
|
||||
horizontal = self.sprite_flip.x
|
||||
|
|
|
@ -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 = nil
|
||||
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
|
||||
|
|
10
main.lua
10
main.lua
|
@ -66,7 +66,7 @@ function love.update(dt)
|
|||
|
||||
|
||||
--keypressed
|
||||
if Keybind:Check(Keybind.menu.pause) then
|
||||
if Keybind:HasPressed(Keybind.menu.pause) then
|
||||
if do_pause then
|
||||
do_pause = false
|
||||
else
|
||||
|
@ -75,7 +75,7 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
if Keybind:Check(Keybind.debug.debug) then
|
||||
if Keybind:HasPressed(Keybind.debug.debug) then
|
||||
if debug then
|
||||
debug = false
|
||||
debug_collision = true
|
||||
|
@ -86,17 +86,17 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
if Keybind:Check(Keybind.debug.reposition) then
|
||||
if Keybind:HasPressed(Keybind.debug.reposition) then
|
||||
if not editor_mode then
|
||||
main_Player.pos.x, main_Player.pos.y = 16,-10
|
||||
end
|
||||
end
|
||||
|
||||
if Keybind:Check(Keybind.debug.reload) then
|
||||
if Keybind:HasPressed(Keybind.debug.reload) then
|
||||
LoadLevel()
|
||||
end
|
||||
|
||||
if Keybind:Check(Keybind.debug.editor) then
|
||||
if Keybind:HasPressed(Keybind.debug.editor) then
|
||||
if editor_mode then
|
||||
editor_mode = false
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue