pxl8/demo/main.fnl

111 lines
3.1 KiB
Text
Raw Normal View History

2025-08-13 15:04:49 -05:00
(local pxl8 (require :pxl8))
(local menu (require :mod.menu))
2026-01-07 17:45:46 -06:00
(local music (require :mod.music))
(local first_person3d (require :mod.first_person3d))
2025-08-13 15:04:49 -05:00
(var time 0)
2026-01-31 09:31:17 -06:00
(var in-world false)
2026-01-21 23:19:50 -06:00
(var first_person3d-init? false)
2025-08-13 15:04:49 -05:00
2025-09-28 13:10:29 -05:00
(var logo-x 256)
(var logo-y 148)
(var logo-dx 100)
(var logo-dy 80)
(var logo-sprite nil)
(var transition nil)
2026-01-31 09:31:17 -06:00
(var transition-to-world false)
2026-01-31 09:31:17 -06:00
(fn start-transition []
(when (not transition)
(set transition-to-world true)
(set transition (pxl8.create_transition :pixelate 0.5))
(transition:set_color 0xFF000000)
(transition:start)))
2025-09-28 13:10:29 -05:00
2026-01-31 09:31:17 -06:00
(fn enter-world []
(when (first_person3d.is-ready)
(start-transition)))
2025-08-13 15:04:49 -05:00
(global init (fn []
2025-10-06 19:00:03 -05:00
(pxl8.load_palette "res/sprites/pxl8_logo.ase")
(set logo-sprite (pxl8.load_sprite "res/sprites/pxl8_logo.ase"))
2026-01-31 09:31:17 -06:00
(music.init)
(menu.init)
(first_person3d.preload)))
2025-08-13 15:04:49 -05:00
(global update (fn [dt]
(when (pxl8.key_pressed "escape")
2026-01-31 09:31:17 -06:00
(if (menu.is-paused)
(do
(menu.hide)
(when in-world
(pxl8.set_relative_mouse_mode true)))
(if in-world
(do
(menu.show)
(pxl8.set_relative_mouse_mode false))
(menu.toggle))))
(when (not (menu.is-paused))
(set time (+ time dt))
2026-01-31 09:31:17 -06:00
(music.update dt)
(when transition
(transition:update dt)
(when (transition:is_complete)
2026-01-31 09:31:17 -06:00
(when transition-to-world
(set in-world true)
(set transition-to-world false)
(pxl8.set_relative_mouse_mode true))
(transition:destroy)
(set transition nil)))
2026-01-31 09:31:17 -06:00
(if in-world
(do
(when (not first_person3d-init?)
(first_person3d.init)
(set first_person3d-init? true))
(first_person3d.update dt))
(do
(when (and (not (menu.is-paused))
(first_person3d.is-ready)
(or (pxl8.key_pressed "return") (pxl8.key_pressed "space")))
(enter-world))
(set logo-x (+ logo-x (* logo-dx dt)))
(set logo-y (+ logo-y (* logo-dy dt)))
(when (< logo-x 0)
(set logo-x 0)
(set logo-dx (math.abs logo-dx)))
(when (> logo-x 512)
(set logo-x 512)
(set logo-dx (- (math.abs logo-dx))))
(when (< logo-y 0)
(set logo-y 0)
(set logo-dy (math.abs logo-dy)))
(when (> logo-y 296)
(set logo-y 296)
(set logo-dy (- (math.abs logo-dy)))))))
(when (menu.is-paused)
(menu.update))))
2025-08-13 15:04:49 -05:00
2025-10-04 04:13:48 -05:00
(global frame (fn []
2026-01-31 09:31:17 -06:00
(if in-world
(first_person3d.frame)
(do
(pxl8.clear 0)
(when logo-sprite
(pxl8.sprite logo-sprite logo-x logo-y 128 64 (< logo-dx 0) (< logo-dy 0)))
(when (not (menu.is-paused))
(if (first_person3d.is-ready)
(pxl8.text "Press ENTER to start" 240 320 1)
(if (first_person3d.is-connected)
(pxl8.text "Loading world..." 260 320 1)
(pxl8.text "Connecting..." 275 320 1))))))
(when transition
(transition:render))
(when (menu.is-paused)
(menu.draw))))