add initial pages support
This commit is contained in:
4
Makefile
4
Makefile
@@ -25,14 +25,14 @@ else
|
|||||||
RAYLIB_LIBS := -lGL -lm -lpthread -ldl -lrt -lX11
|
RAYLIB_LIBS := -lGL -lm -lpthread -ldl -lrt -lX11
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJECTS := main.o
|
OBJECTS := main.o menu.o game.o
|
||||||
|
|
||||||
all: catch-phase
|
all: catch-phase
|
||||||
|
|
||||||
catch-phase: $(OBJECTS) $(RAYLIB_LIB)
|
catch-phase: $(OBJECTS) $(RAYLIB_LIB)
|
||||||
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(RAYLIB_LIB) $(RAYLIB_LIBS)
|
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(RAYLIB_LIB) $(RAYLIB_LIBS)
|
||||||
|
|
||||||
main.o: main.sex | $(OBJ_DIR)
|
%.o: %.sex
|
||||||
$(SEXC) $< -c -o $@ -- $(CFLAGS) $(INCLUDES)
|
$(SEXC) $< -c -o $@ -- $(CFLAGS) $(INCLUDES)
|
||||||
|
|
||||||
# raylib ------------------------------------------------------------
|
# raylib ------------------------------------------------------------
|
||||||
|
|||||||
37
game.sex
Normal file
37
game.sex
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
(include raylib.h)
|
||||||
|
(pub import pages)
|
||||||
|
(import main)
|
||||||
|
(import utils)
|
||||||
|
|
||||||
|
(pub record game-state
|
||||||
|
((app-state (* app-state))))
|
||||||
|
|
||||||
|
(pub fn mk-game ((app-state (* app-state))) page
|
||||||
|
(var state _ (mem-alloc game-state))
|
||||||
|
(= (. state app-state) app-state)
|
||||||
|
(return (page/game state)))
|
||||||
|
|
||||||
|
(pub fn rm-game ((state (* game-state))) void
|
||||||
|
(free state)
|
||||||
|
(return))
|
||||||
|
|
||||||
|
#-emscripten (define WIN-WIDTH 1440)
|
||||||
|
#-emscripten (define WIN-HEIGHT 900)
|
||||||
|
#+emscripten (define WIN-WIDTH 960)
|
||||||
|
#+emscripten (define WIN-HEIGHT 600)
|
||||||
|
|
||||||
|
(pub fn render-game ((state (* game-state))) void
|
||||||
|
(BeginDrawing)
|
||||||
|
(ClearBackground BLACK)
|
||||||
|
(DrawTriangleGradient
|
||||||
|
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (- (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (- (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (/ WIN-WIDTH 2) (+ (/ WIN-HEIGHT 2) 100))
|
||||||
|
#(Color : 255 255 0 255)
|
||||||
|
#(Color : 255 0 255 255)
|
||||||
|
#(Color : 0 255 255 255))
|
||||||
|
(EndDrawing))
|
||||||
|
|
||||||
|
(pub fn process-input-game ((state (* game-state))) void
|
||||||
|
(if (IsMouseButtonReleased MOUSE-LEFT-BUTTON)
|
||||||
|
(.change-page (. state app-state) (sum-type page menu))))
|
||||||
49
main.sex
49
main.sex
@@ -1,3 +1,6 @@
|
|||||||
|
(pub import pages)
|
||||||
|
(pub import utils)
|
||||||
|
|
||||||
(include raylib.h)
|
(include raylib.h)
|
||||||
|
|
||||||
#-emscripten (define WIN-WIDTH 1440)
|
#-emscripten (define WIN-WIDTH 1440)
|
||||||
@@ -16,17 +19,35 @@
|
|||||||
(= error ,code)
|
(= error ,code)
|
||||||
(return)))))
|
(return)))))
|
||||||
|
|
||||||
(fn update () void
|
(pub record app-state
|
||||||
(BeginDrawing)
|
((page page)))
|
||||||
(ClearBackground BLACK)
|
|
||||||
(DrawTriangleGradient
|
(import menu)
|
||||||
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
(import game)
|
||||||
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
|
||||||
#(Vector2 : (/ WIN-WIDTH 2) (- (/ WIN-HEIGHT 2) 100))
|
(ops app-state
|
||||||
RED
|
;; TODO: add force arg to override changing to self protection
|
||||||
GREEN
|
(pub fn change-page ((self (* app-state))
|
||||||
BLUE)
|
(target (tag-type page))) void
|
||||||
(EndDrawing))
|
(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
|
(fn init () void
|
||||||
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
||||||
@@ -45,8 +66,9 @@
|
|||||||
(init)
|
(init)
|
||||||
(if (!= error 0)
|
(if (!= error 0)
|
||||||
(return error))
|
(return error))
|
||||||
|
(var state _ #(app-state : (mk-menu (& state))))
|
||||||
(while (! (WindowShouldClose))
|
(while (! (WindowShouldClose))
|
||||||
(update))
|
(main-loop (& state)))
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|
||||||
#+emscripten
|
#+emscripten
|
||||||
@@ -55,5 +77,6 @@
|
|||||||
#+emscripten
|
#+emscripten
|
||||||
(pub fn main ((argc int) (argv [* const char])) int
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
(init)
|
(init)
|
||||||
(emscripten-set-main-loop update 0 true)
|
(var state _ #(app-state : (mk-menu (& state))))
|
||||||
|
(emscripten-set-main-loop-arg (cast (* void) (& state)) main-loop 0 true)
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
37
menu.sex
Normal file
37
menu.sex
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
(include raylib.h)
|
||||||
|
(pub import pages)
|
||||||
|
(import main)
|
||||||
|
(import utils)
|
||||||
|
|
||||||
|
(pub record menu-state
|
||||||
|
((app-state (* app-state))))
|
||||||
|
|
||||||
|
(pub fn mk-menu ((app-state (* app-state))) page
|
||||||
|
(var state _ (mem-alloc menu-state))
|
||||||
|
(= (. state app-state) app-state)
|
||||||
|
(return (page/menu state)))
|
||||||
|
|
||||||
|
(pub fn rm-menu ((state (* menu-state))) void
|
||||||
|
(free state)
|
||||||
|
(return))
|
||||||
|
|
||||||
|
#-emscripten (define WIN-WIDTH 1440)
|
||||||
|
#-emscripten (define WIN-HEIGHT 900)
|
||||||
|
#+emscripten (define WIN-WIDTH 960)
|
||||||
|
#+emscripten (define WIN-HEIGHT 600)
|
||||||
|
|
||||||
|
(pub fn render-menu ((state (* menu-state))) void
|
||||||
|
(BeginDrawing)
|
||||||
|
(ClearBackground BLACK)
|
||||||
|
(DrawTriangleGradient
|
||||||
|
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (/ WIN-WIDTH 2) (- (/ WIN-HEIGHT 2) 100))
|
||||||
|
RED
|
||||||
|
GREEN
|
||||||
|
BLUE)
|
||||||
|
(EndDrawing))
|
||||||
|
|
||||||
|
(pub fn process-input-menu ((state (* menu-state))) void
|
||||||
|
(if (IsMouseButtonReleased MOUSE-LEFT-BUTTON)
|
||||||
|
(.change-page (. state app-state) (sum-type page game))))
|
||||||
6
pages.sex
Normal file
6
pages.sex
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
(record menu-state)
|
||||||
|
(record game-state)
|
||||||
|
|
||||||
|
(pub sum page
|
||||||
|
((menu ((state (* menu-state))))
|
||||||
|
(game ((state (* game-state))))))
|
||||||
Reference in New Issue
Block a user