add menu bg and buttons
This commit is contained in:
70
game.sex
70
game.sex
@@ -99,44 +99,44 @@
|
|||||||
(draw-tmx-layer (. state map) "FIH" (& (. state cam)))
|
(draw-tmx-layer (. state map) "FIH" (& (. state cam)))
|
||||||
(EndMode2D)
|
(EndMode2D)
|
||||||
|
|
||||||
(DrawText "WASD/arrows: move wheel: zoom click: back to menu"
|
(DrawText "WASD/arrows: move wheel: zoom ESC: back to menu"
|
||||||
10 10 20 RAYWHITE)
|
10 10 20 RAYWHITE)
|
||||||
(DrawText (TextFormat "FIH objects: %d"
|
|
||||||
(tmx-object-count (. state map) "FIH"))
|
|
||||||
10 30 20 RAYWHITE)
|
|
||||||
|
|
||||||
(EndDrawing))
|
(EndDrawing))
|
||||||
|
|
||||||
(pub fn process-input-game ((state (* game-state))) void
|
(pub fn process-input-game ((state (* game-state))) void
|
||||||
(if (!= (. state map) NULL)
|
(if (== (. state map) NULL)
|
||||||
|
(return))
|
||||||
|
|
||||||
|
(var speed float (* 300.0 (GetFrameTime)))
|
||||||
|
|
||||||
|
(if (|| (IsKeyPressed KEY-LEFT) (IsKeyPressed KEY-A))
|
||||||
|
(-= (. state fih x) TILE-SIZE))
|
||||||
|
(if (|| (IsKeyPressed KEY-RIGHT) (IsKeyPressed KEY-D))
|
||||||
|
(+= (. state fih x) TILE-SIZE))
|
||||||
|
(if (|| (IsKeyPressed KEY-UP) (IsKeyPressed KEY-W))
|
||||||
|
(-= (. state fih y) TILE-SIZE))
|
||||||
|
(if (|| (IsKeyPressed KEY-DOWN) (IsKeyPressed KEY-S))
|
||||||
|
(+= (. state fih y) TILE-SIZE))
|
||||||
|
|
||||||
|
(var map-width float (cast (tmx-pixel-width (. state map)) float))
|
||||||
|
(var map-height float (cast (tmx-pixel-height (. state map)) float))
|
||||||
|
(if (< (. state cam target x) 0.0)
|
||||||
|
(= (. state cam target x) 0.0))
|
||||||
|
(if (> (. state cam target x) map-width)
|
||||||
|
(= (. state cam target x) map-width))
|
||||||
|
(if (< (. state cam target y) 0.0)
|
||||||
|
(= (. state cam target y) 0.0))
|
||||||
|
(if (> (. state cam target y) map-height)
|
||||||
|
(= (. state cam target y) map-height))
|
||||||
|
|
||||||
|
(var wheel float (GetMouseWheelMove))
|
||||||
|
(if (!= wheel 0.0)
|
||||||
(do
|
(do
|
||||||
(var speed float (* 300.0 (GetFrameTime)))
|
(+= (. state cam zoom) (* wheel 0.5))
|
||||||
|
(if (< (. state cam zoom) 0.5)
|
||||||
|
(= (. state cam zoom) 0.5))
|
||||||
|
(if (> (. state cam zoom) 8.0)
|
||||||
|
(= (. state cam zoom) 8.0))))
|
||||||
|
|
||||||
(if (|| (IsKeyPressed KEY-LEFT) (IsKeyPressed KEY-A))
|
(if (IsKeyReleased KEY-ESCAPE)
|
||||||
(-= (. state fih x) TILE-SIZE))
|
(.change-page (. state app-state) (sum-type page menu))))
|
||||||
(if (|| (IsKeyPressed KEY-RIGHT) (IsKeyPressed KEY-D))
|
|
||||||
(+= (. state fih x) TILE-SIZE))
|
|
||||||
(if (|| (IsKeyPressed KEY-UP) (IsKeyPressed KEY-W))
|
|
||||||
(-= (. state fih y) TILE-SIZE))
|
|
||||||
(if (|| (IsKeyPressed KEY-DOWN) (IsKeyPressed KEY-S))
|
|
||||||
(+= (. state fih y) TILE-SIZE))
|
|
||||||
|
|
||||||
(var map-width float (cast (tmx-pixel-width (. state map)) float))
|
|
||||||
(var map-height float (cast (tmx-pixel-height (. state map)) float))
|
|
||||||
(if (< (. state cam target x) 0.0)
|
|
||||||
(= (. state cam target x) 0.0))
|
|
||||||
(if (> (. state cam target x) map-width)
|
|
||||||
(= (. state cam target x) map-width))
|
|
||||||
(if (< (. state cam target y) 0.0)
|
|
||||||
(= (. state cam target y) 0.0))
|
|
||||||
(if (> (. state cam target y) map-height)
|
|
||||||
(= (. state cam target y) map-height))
|
|
||||||
|
|
||||||
(var wheel float (GetMouseWheelMove))
|
|
||||||
(if (!= wheel 0.0)
|
|
||||||
(do
|
|
||||||
(+= (. state cam zoom) (* wheel 0.5))
|
|
||||||
(if (< (. state cam zoom) 0.5)
|
|
||||||
(= (. state cam zoom) 0.5))
|
|
||||||
(if (> (. state cam zoom) 8.0)
|
|
||||||
(= (. state cam zoom) 8.0)))))))
|
|
||||||
|
|||||||
18
main.sex
18
main.sex
@@ -26,7 +26,8 @@
|
|||||||
((page page)
|
((page page)
|
||||||
;; TODO: fix macro expansion in fields!!!
|
;; TODO: fix macro expansion in fields!!!
|
||||||
;; Should've been (tag-type page). Fuck!!!!
|
;; Should've been (tag-type page). Fuck!!!!
|
||||||
(target-page (enum pageǂ))))
|
(target-page (enum pageǂ))
|
||||||
|
(running bool)))
|
||||||
|
|
||||||
(import menu)
|
(import menu)
|
||||||
(import game)
|
(import game)
|
||||||
@@ -37,6 +38,9 @@
|
|||||||
(target (tag-type page))) void
|
(target (tag-type page))) void
|
||||||
(= (. self target-page) target))
|
(= (. self target-page) target))
|
||||||
|
|
||||||
|
(pub fn quit ((self (* app-state))) void
|
||||||
|
(= (. self running) false))
|
||||||
|
|
||||||
(fn change-page- ((self (* app-state))) void
|
(fn change-page- ((self (* app-state))) void
|
||||||
(if (== (. self page tag) (. self target-page))
|
(if (== (. self page tag) (. self target-page))
|
||||||
;; Don't change page to itself
|
;; Don't change page to itself
|
||||||
@@ -66,6 +70,7 @@
|
|||||||
InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase")
|
InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase")
|
||||||
(call-and-check IsAudioDeviceReady "failed to init audio" 2
|
(call-and-check IsAudioDeviceReady "failed to init audio" 2
|
||||||
InitAudioDevice)
|
InitAudioDevice)
|
||||||
|
(SetExitKey -1)
|
||||||
(SetTargetFPS 60))
|
(SetTargetFPS 60))
|
||||||
|
|
||||||
(fn deinit () void
|
(fn deinit () void
|
||||||
@@ -77,8 +82,11 @@
|
|||||||
(init)
|
(init)
|
||||||
(if (!= error 0)
|
(if (!= error 0)
|
||||||
(return error))
|
(return error))
|
||||||
(var state _ #(app-state : (mk-menu (& state)) (sum-type page menu)))
|
(var state _ #(app-state : (mk-menu (& state))
|
||||||
(while (! (WindowShouldClose))
|
(sum-type page menu)
|
||||||
|
true))
|
||||||
|
(while (&& (! (WindowShouldClose))
|
||||||
|
(. state running))
|
||||||
(main-loop (cast (& state) (* void))))
|
(main-loop (cast (& state) (* void))))
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|
||||||
@@ -88,6 +96,8 @@
|
|||||||
#+emscripten
|
#+emscripten
|
||||||
(pub fn main ((argc int) (argv [* const char])) int
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
(init)
|
(init)
|
||||||
(var state _ #(app-state : (mk-menu (& state)) (sum-type page menu)))
|
(var state _ #(app-state : (mk-menu (& state))
|
||||||
|
(sum-type page menu)
|
||||||
|
true))
|
||||||
(emscripten-set-main-loop-arg main-loop (cast (& state) (* void)) 0 true)
|
(emscripten-set-main-loop-arg main-loop (cast (& state) (* void)) 0 true)
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
64
menu.sex
64
menu.sex
@@ -1,37 +1,63 @@
|
|||||||
(include raylib.h)
|
(include raylib.h)
|
||||||
|
(include raygui.h)
|
||||||
(pub import pages)
|
(pub import pages)
|
||||||
(import main)
|
(import main)
|
||||||
(import utils)
|
(import utils)
|
||||||
|
|
||||||
(pub record menu-state
|
(pub record menu-state
|
||||||
((app-state (* app-state))))
|
((app-state (* app-state))
|
||||||
|
(bg Texture2D)
|
||||||
(pub fn mk-menu ((app-state (* app-state))) page
|
(btn-to-game int)
|
||||||
(var state _ (mem-alloc menu-state))
|
(btn-exit int)))
|
||||||
(= (. 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-WIDTH 1440)
|
||||||
#-emscripten (define WIN-HEIGHT 900)
|
#-emscripten (define WIN-HEIGHT 900)
|
||||||
#+emscripten (define WIN-WIDTH 960)
|
#+emscripten (define WIN-WIDTH 960)
|
||||||
#+emscripten (define WIN-HEIGHT 600)
|
#+emscripten (define WIN-HEIGHT 600)
|
||||||
|
|
||||||
|
(define BTN-WIDTH 320.0)
|
||||||
|
(define BTN-HEIGHT 72.0)
|
||||||
|
|
||||||
|
(pub fn mk-menu ((app-state (* app-state))) page
|
||||||
|
(var state _ (mem-alloc menu-state))
|
||||||
|
(= (. state app-state) app-state)
|
||||||
|
(= (. state btn-to-game) 0)
|
||||||
|
(= (. state btn-exit) 0)
|
||||||
|
(var img Image (LoadImage "res/img/menu.png"))
|
||||||
|
(ImageResize (& img) WIN-WIDTH WIN-HEIGHT)
|
||||||
|
(= (. state bg) (LoadTextureFromImage img))
|
||||||
|
(return (page/menu state)))
|
||||||
|
|
||||||
|
(pub fn rm-menu ((state (* menu-state))) void
|
||||||
|
(free state)
|
||||||
|
(return))
|
||||||
|
|
||||||
(pub fn render-menu ((state (* menu-state))) void
|
(pub fn render-menu ((state (* menu-state))) void
|
||||||
(BeginDrawing)
|
(BeginDrawing)
|
||||||
(ClearBackground BLACK)
|
(ClearBackground BLACK)
|
||||||
(DrawTriangleGradient
|
(DrawTexture (. state bg) 0 0 WHITE)
|
||||||
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
|
||||||
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
(= (. state btn-to-game)
|
||||||
#(Vector2 : (/ WIN-WIDTH 2) (- (/ WIN-HEIGHT 2) 100))
|
(GuiButton #(Rectangle : 80.0
|
||||||
RED
|
(- WIN-HEIGHT 350.0)
|
||||||
GREEN
|
BTN-WIDTH
|
||||||
BLUE)
|
BTN-HEIGHT) "To game"))
|
||||||
|
|
||||||
|
(= (. state btn-exit)
|
||||||
|
(GuiButton #(Rectangle : 80.0
|
||||||
|
(- WIN-HEIGHT 240.0)
|
||||||
|
BTN-WIDTH
|
||||||
|
BTN-HEIGHT) "Quit"))
|
||||||
|
|
||||||
(EndDrawing))
|
(EndDrawing))
|
||||||
|
|
||||||
(pub fn process-input-menu ((state (* menu-state))) void
|
(pub fn process-input-menu ((state (* menu-state))) void
|
||||||
(if (IsMouseButtonReleased MOUSE-LEFT-BUTTON)
|
(if (== (. state btn-to-game) 1)
|
||||||
(.change-page (. state app-state) (sum-type page game))))
|
(do
|
||||||
|
(= (. state btn-to-game) 0)
|
||||||
|
(.change-page (. state app-state) (sum-type page game))))
|
||||||
|
|
||||||
|
(if (== (. state btn-exit) 1)
|
||||||
|
(do
|
||||||
|
(= (. state btn-exit) 0)
|
||||||
|
(.quit (. state app-state)))))
|
||||||
|
|||||||
BIN
res/img/menu.png
Normal file
BIN
res/img/menu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 332 KiB |
Reference in New Issue
Block a user