83 lines
2.1 KiB
Scheme
83 lines
2.1 KiB
Scheme
(pub import pages)
|
|
(pub import utils)
|
|
|
|
(include raylib.h)
|
|
|
|
#-emscripten (define WIN-WIDTH 1440)
|
|
#-emscripten (define WIN-HEIGHT 900)
|
|
#+emscripten (define WIN-WIDTH 960)
|
|
#+emscripten (define WIN-HEIGHT 600)
|
|
|
|
(var error i32 0)
|
|
|
|
(defmacro (call-and-check test msg code fn . args)
|
|
`(do
|
|
(,fn ,@args)
|
|
(if (! (,test))
|
|
(do
|
|
(TraceLog LOG-ERROR ,msg)
|
|
(= error ,code)
|
|
(return)))))
|
|
|
|
(pub record app-state
|
|
((page page)))
|
|
|
|
(import menu)
|
|
(import game)
|
|
|
|
(ops app-state
|
|
;; TODO: add force arg to override changing to self protection
|
|
(pub fn change-page ((self (* app-state))
|
|
(target (tag-type page))) void
|
|
(if (= (. self page tag) target)
|
|
;; Don't change page to itself
|
|
(return))
|
|
(match (. self page)
|
|
((menu (state)) (rm-menu state))
|
|
((game (state)) (rm-game state)))
|
|
(if (== target (sum-type page menu))
|
|
(= (. self page) (mk-menu self)))
|
|
(if (== target (sum-type page game))
|
|
(= (. self page) (mk-game self)))))
|
|
|
|
(fn main-loop ((state (* app-state))) void
|
|
(match (. state page)
|
|
((menu (state))
|
|
(render-menu state)
|
|
(process-input-menu state))
|
|
((game (state))
|
|
(render-game state)
|
|
(process-input-game state))))
|
|
|
|
(fn init () void
|
|
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
|
(call-and-check IsWindowReady "failed to create window" 1
|
|
InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase")
|
|
(call-and-check IsAudioDeviceReady "failed to init audio" 2
|
|
InitAudioDevice)
|
|
(SetTargetFPS 60))
|
|
|
|
(fn deinit () void
|
|
(CloseAudioDevice)
|
|
(CloseWindow))
|
|
|
|
#-emscripten
|
|
(pub fn main ((argc int) (argv [* const char])) int
|
|
(init)
|
|
(if (!= error 0)
|
|
(return error))
|
|
(var state _ #(app-state : (mk-menu (& state))))
|
|
(while (! (WindowShouldClose))
|
|
(main-loop (& state)))
|
|
(return 0))
|
|
|
|
#+emscripten
|
|
(include emscripten.h)
|
|
|
|
#+emscripten
|
|
(pub fn main ((argc int) (argv [* const char])) int
|
|
(init)
|
|
(var state _ #(app-state : (mk-menu (& state))))
|
|
(emscripten-set-main-loop-arg (cast (* void) (& state)) main-loop 0 true)
|
|
(return 0))
|