2021-09-11 19:33:52 -07:00
|
|
|
(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
|
2021-09-11 19:33:52 -07:00
|
|
|
(var (mode mode-name) nil)
|
2018-10-17 18:32:39 -07:00
|
|
|
|
2021-09-11 19:33:52 -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
|
2021-09-11 19:33:52 -07:00
|
|
|
(match (pcall mode.activate ...)
|
|
|
|
(false msg) (print mode-name "activate error" msg))))
|
2018-10-17 18:32:39 -07:00
|
|
|
|
|
|
|
(fn love.load []
|
2021-09-11 19:33:52 -07:00
|
|
|
(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
|
|
|
|
2021-09-11 19:33:52 -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)
|
2021-09-11 19:33:52 -07:00
|
|
|
(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]
|
2021-09-11 19:33:52 -07:00
|
|
|
(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
|
2021-09-11 19:33:52 -07:00
|
|
|
(safely #(mode.keypressed key set-mode))))
|