edtris/game/helpers.fnl
2021-02-07 16:56:19 -05:00

13 lines
386 B
Fennel

(fn dir-from-key [keymap]
(var (dx dy) (values 0 0))
(when (love.keyboard.isDown keymap.up) (set dy -1))
(when (love.keyboard.isDown keymap.down) (set dy 1))
(when (love.keyboard.isDown keymap.left) (set dx -1))
(when (love.keyboard.isDown keymap.right) (set dx 1))
[dx dy])
(fn vec* [vec scalar]
(icollect [_ v (ipairs vec)] (* v scalar)))
{: dir-from-key : vec*}