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 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
|
self.move_x = -self.moveSpeed
|
||||||
elseif Keybind:Check(Keybind.move.right) then
|
elseif Keybind:CheckDown(Keybind.move.right) 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 Keybind:Check(Keybind.move.jump) then
|
if Keybind:CheckDown(Keybind.move.jump) 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 Keybind:Check(Keybind.move.dash) then
|
if Keybind:CheckDown(Keybind.move.dash) 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 Keybind:Check(Keybind.move.down) then vertical = vertical + 1 end
|
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
|
||||||
if Keybind:Check(Keybind.move.up) then vertical = vertical - 1 end
|
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
|
||||||
local horizontal = 0
|
local horizontal = 0
|
||||||
if Keybind:Check(Keybind.move.right) then horizontal = horizontal + 1 end
|
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
|
||||||
if Keybind:Check(Keybind.move.left) then horizontal = horizontal - 1 end
|
if Keybind:CheckDown(Keybind.move.left) 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
|
||||||
|
|
|
@ -3,8 +3,8 @@ Keybind.move = {}
|
||||||
Keybind.menu = {}
|
Keybind.menu = {}
|
||||||
Keybind.debug = {}
|
Keybind.debug = {}
|
||||||
|
|
||||||
function Keybind:Check(action)
|
function Keybind:CheckDown(action)
|
||||||
for _, keyname in pairs(action) do
|
for _, keyname in pairs(action.keys) do
|
||||||
if type(keyname) == "string" then
|
if type(keyname) == "string" then
|
||||||
if love.keyboard.isDown(keyname) then return true end
|
if love.keyboard.isDown(keyname) then return true end
|
||||||
else
|
else
|
||||||
|
@ -14,43 +14,55 @@ function Keybind:Check(action)
|
||||||
return false
|
return false
|
||||||
end
|
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 _, 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
|
if key == keyname then return true end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Keybind:Add(action, key)
|
function Keybind:AddKey(action, key)
|
||||||
table.insert(action, key)
|
table.insert(action.keys, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Keybind:Change(action, position, key)
|
function Keybind:ChangeKey(action, position, key)
|
||||||
action[position] = key
|
action.keys[position] = key
|
||||||
end
|
end
|
||||||
|
|
||||||
function Keybind:Remove(action)
|
function Keybind:RemoveKeys(action)
|
||||||
action = {}
|
action.keys = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Keybind:Default()
|
function Keybind:Default()
|
||||||
--Menu
|
--Menu
|
||||||
Keybind.menu.pause = {"escape"}
|
Keybind.menu.pause= { keys = {"escape"}}
|
||||||
--Move
|
--Move
|
||||||
Keybind.move.left = {"left", "a"}
|
Keybind.move.left = { keys = {"left", "a"}}
|
||||||
Keybind.move.right = {"right", "d"}
|
Keybind.move.right = { keys = {"right", "d"}}
|
||||||
Keybind.move.up = {"up", "w"}
|
Keybind.move.up = { keys = {"up", "w"}}
|
||||||
Keybind.move.down = {"down", "s"}
|
Keybind.move.down = { keys = {"down", "s"}}
|
||||||
Keybind.move.jump = {"z", "space"}
|
Keybind.move.jump = { keys = {"z", "space"}}
|
||||||
Keybind.move.attack = {"x", 1}
|
Keybind.move.attack = { keys = {"x", 1}}
|
||||||
Keybind.move.dash = {"c", 2}
|
Keybind.move.dash = { keys = {"c", 2}}
|
||||||
--Debug
|
--Debug
|
||||||
Keybind.debug.debug = {"f1"}
|
Keybind.debug.debug = { keys = {"f1"}}
|
||||||
Keybind.debug.reposition = {"f2"}
|
Keybind.debug.reposition = { keys = {"f2"}}
|
||||||
Keybind.debug.reload = {"f3"}
|
Keybind.debug.reload = { keys = {"f3"}}
|
||||||
Keybind.debug.editor = {"f4"}
|
Keybind.debug.editor = { keys = {"f4"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set default values at start
|
-- Set default values at start
|
||||||
|
|
10
main.lua
10
main.lua
|
@ -66,7 +66,7 @@ function love.update(dt)
|
||||||
|
|
||||||
|
|
||||||
--keypressed
|
--keypressed
|
||||||
if Keybind:Check(Keybind.menu.pause) then
|
if Keybind:HasPressed(Keybind.menu.pause) then
|
||||||
if do_pause then
|
if do_pause then
|
||||||
do_pause = false
|
do_pause = false
|
||||||
else
|
else
|
||||||
|
@ -75,7 +75,7 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:Check(Keybind.debug.debug) then
|
if Keybind:HasPressed(Keybind.debug.debug) then
|
||||||
if debug then
|
if debug then
|
||||||
debug = false
|
debug = false
|
||||||
debug_collision = true
|
debug_collision = true
|
||||||
|
@ -86,17 +86,17 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:Check(Keybind.debug.reposition) then
|
if Keybind:HasPressed(Keybind.debug.reposition) then
|
||||||
if not editor_mode then
|
if not editor_mode then
|
||||||
main_Player.pos.x, main_Player.pos.y = 16,-10
|
main_Player.pos.x, main_Player.pos.y = 16,-10
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:Check(Keybind.debug.reload) then
|
if Keybind:HasPressed(Keybind.debug.reload) then
|
||||||
LoadLevel()
|
LoadLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:Check(Keybind.debug.editor) then
|
if Keybind:HasPressed(Keybind.debug.editor) then
|
||||||
if editor_mode then
|
if editor_mode then
|
||||||
editor_mode = false
|
editor_mode = false
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue