melee-roguelite/wrap.fnl

45 lines
1.3 KiB
Plaintext
Raw Normal View History

(local fennel (require :lib.fennel))
(local repl (require :lib.stdio))
2018-11-30 17:40:07 -08:00
(local canvas (let [(w h) (love.window.getMode)]
(love.graphics.newCanvas w h)))
2018-10-17 18:32:39 -07:00
(var scale 1)
;; set the first mode
(var (mode mode-name) nil)
2018-10-17 18:32:39 -07:00
(fn set-mode [new-mode-name ...]
(set (mode mode-name) (values (require new-mode-name) new-mode-name))
2018-10-17 18:32:39 -07:00
(when mode.activate
(match (pcall mode.activate ...)
(false msg) (print mode-name "activate error" msg))))
2018-10-17 18:32:39 -07:00
(fn love.load []
(set-mode :mode-intro)
2019-09-22 15:38:01 -07:00
(canvas:setFilter "nearest" "nearest")
(repl.start))
2018-10-17 18:32:39 -07:00
(fn safely [f]
(xpcall f #(set-mode :error-mode mode-name $ (fennel.traceback))))
2018-10-17 18:32:39 -07:00
(fn love.draw []
2019-09-22 15:38:01 -07:00
;; the canvas allows you to get sharp pixel-art style scaling; if you
;; don't want that, just skip that and call mode.draw directly.
(love.graphics.setCanvas canvas)
(love.graphics.clear)
(love.graphics.setColor 1 1 1)
(safely mode.draw)
2019-09-22 15:38:01 -07:00
(love.graphics.setCanvas)
(love.graphics.setColor 1 1 1)
(love.graphics.draw canvas 0 0 0 scale scale))
2018-10-17 18:32:39 -07:00
2019-09-22 15:38:01 -07:00
(fn love.update [dt]
(when mode.update
(safely #(mode.update dt set-mode))))
2018-10-17 18:32:39 -07:00
(fn love.keypressed [key]
2019-09-22 15:38:01 -07:00
(if (and (love.keyboard.isDown "lctrl" "rctrl" "capslock") (= key "q"))
(love.event.quit)
;; add what each keypress should do in each mode
(safely #(mode.keypressed key set-mode))))