diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-10 21:08:09 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-10 21:08:09 +0800 |
| commit | 843ace158173805c6273a2d09bd3d61088492f80 (patch) | |
| tree | a1186150c0b61ad41167a9f29ef5f0c1539aa9a4 /logic/controller.lua | |
| parent | 42cb7b6fd46f0b7010dbd93289f5c76c08790c38 (diff) | |
chore: allow direction keys to move
Diffstat (limited to 'logic/controller.lua')
| -rw-r--r-- | logic/controller.lua | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/logic/controller.lua b/logic/controller.lua index 00149b5..8ce8cec 100644 --- a/logic/controller.lua +++ b/logic/controller.lua @@ -16,25 +16,29 @@ end local function playerPressKeysToMoves(dt) local moveDirections = { - { key = "d", axis = "x", dir = Direction.RIGHT, delta = 1 }, - { key = "a", axis = "x", dir = Direction.LEFT, delta = -1 }, - { key = "w", axis = "y", dir = Direction.TOP, delta = -1 }, - { key = "s", axis = "y", dir = Direction.BOTTOM, delta = 1 } + { keys = {"d","right"}, axis = "x", dir = Direction.RIGHT, delta = 1 }, + { keys = {"a","left"}, axis = "x", dir = Direction.LEFT, delta = -1 }, + { keys = {"w","up"}, axis = "y", dir = Direction.TOP, delta = -1 }, + { keys = {"s","down"}, axis = "y", dir = Direction.BOTTOM, delta = 1 } } local keydown = love.keyboard.isDown for _, move in ipairs(moveDirections) do local dv = G.player.speed * dt * move.delta - if keydown(move.key) then - G.player.facing = move.dir - G.player.moving = true - - local delta = G.player.speed * dt * move.delta - if utils.isBlocked(G.player.body, G.player.x, G.player.y, move.dir, move.axis, dv) then - delta = 0 + for _, key in ipairs(move.keys) do + if keydown(key) then + G.player.facing = move.dir + G.player.moving = true + + local delta = G.player.speed * dt * move.delta + if utils.isBlocked(G.player.body, G.player.x, G.player.y, move.dir, move.axis, dv) then + delta = 0 + end + G.player[move.axis] = G.player[move.axis] + delta + + break end - G.player[move.axis] = G.player[move.axis] + delta end end |
