feat(gui): add toolbar widget
This commit is contained in:
parent
afc063b2ab
commit
b42bf74472
51 changed files with 2191 additions and 1461 deletions
|
|
@ -18,10 +18,6 @@
|
|||
|
||||
(local SIM_FLAG_GROUNDED 4)
|
||||
|
||||
(local door-spawn-x 860)
|
||||
(local door-spawn-z 416)
|
||||
(local door-spawn-yaw 1.5708)
|
||||
|
||||
(local sim-cfg (pxl8.sim_config {:move_speed 150
|
||||
:gravity 600
|
||||
:jump_velocity 180
|
||||
|
|
@ -35,7 +31,6 @@
|
|||
|
||||
(var auto-run-cancel-key nil)
|
||||
(var auto-run? false)
|
||||
(var was-auto-running false)
|
||||
(var bob-time 0)
|
||||
(var cam-pitch 0)
|
||||
(var day-time 0)
|
||||
|
|
@ -44,27 +39,21 @@
|
|||
(var cam-yaw 0)
|
||||
(var cam-z 416)
|
||||
(var camera nil)
|
||||
(var ceiling-tex nil)
|
||||
(var current-bsp-id 1)
|
||||
(var floor-tex nil)
|
||||
(var land-squash 0)
|
||||
(var last-dt 0.016)
|
||||
(var light-time 0)
|
||||
(var glows nil)
|
||||
(var lights nil)
|
||||
(var materials-for-chunk 0)
|
||||
(var materials-set? false)
|
||||
(var network nil)
|
||||
(var portal-cooldown 0)
|
||||
(var real-time 0)
|
||||
(var smooth-cam-x 416)
|
||||
(var smooth-cam-z 416)
|
||||
(var was-grounded true)
|
||||
(var trim-tex nil)
|
||||
(var wall-tex nil)
|
||||
(var world nil)
|
||||
|
||||
(local MOSS_COLOR 200)
|
||||
(local PLASTER_COLOR 16)
|
||||
(local GRASS_COLOR 200)
|
||||
(local STONE_WALL_START 2)
|
||||
(local WOOD_COLOR 88)
|
||||
|
||||
|
|
@ -81,8 +70,7 @@
|
|||
(when (not world)
|
||||
(set world (pxl8.get_world))
|
||||
(when world
|
||||
(world:set_sim_config sim-cfg)
|
||||
(world:init_local_player cam-x cam-y cam-z))))
|
||||
(world:set_sim_config sim-cfg))))
|
||||
|
||||
(fn is-connected []
|
||||
(and network (network:connected)))
|
||||
|
|
@ -93,20 +81,6 @@
|
|||
(let [chunk (world:active_chunk)]
|
||||
(and chunk (chunk:ready)))))
|
||||
|
||||
(fn setup-textures [bsp-id]
|
||||
(if (= bsp-id 2)
|
||||
(do
|
||||
(set floor-tex (textures.rough-stone 44442 STONE_FLOOR_COLOR))
|
||||
(set wall-tex (textures.ashlar-wall 55552 ASHLAR_COLOR ASHLAR_MOSS))
|
||||
(set trim-tex (textures.rough-stone 77772 STONE_TRIM_COLOR))
|
||||
(set ceiling-tex (textures.plaster-wall 66662 PLASTER_COLOR)))
|
||||
(do
|
||||
(set floor-tex (textures.wood-planks 44444 WOOD_COLOR))
|
||||
(set wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR))
|
||||
(set trim-tex (textures.wood-trim 77777 WOOD_COLOR))
|
||||
(set ceiling-tex (textures.plaster-wall 66666 PLASTER_COLOR))))
|
||||
(set current-bsp-id bsp-id))
|
||||
|
||||
(fn init []
|
||||
(pxl8.set_relative_mouse_mode true)
|
||||
(pxl8.load_palette "res/palettes/palette.ase")
|
||||
|
|
@ -135,30 +109,38 @@
|
|||
(when world
|
||||
(world:init_local_player cam-x cam-y cam-z)
|
||||
(set smooth-cam-x cam-x)
|
||||
(set smooth-cam-z cam-z))
|
||||
|
||||
(setup-textures 1))
|
||||
(set smooth-cam-z cam-z)))
|
||||
|
||||
(fn setup-materials []
|
||||
(when (not world) (lua "return"))
|
||||
(when (not network) (lua "return"))
|
||||
(let [net-chunk (network:chunk_id)]
|
||||
(when (or (= net-chunk 0) (= materials-for-chunk net-chunk)) (lua "return"))
|
||||
(when (not= current-bsp-id net-chunk)
|
||||
(setup-textures net-chunk))
|
||||
(when (not floor-tex) (lua "return"))
|
||||
(when (not wall-tex) (lua "return"))
|
||||
(let [chunk (world:active_chunk)]
|
||||
(when (not chunk) (lua "return"))
|
||||
(when (not (chunk:ready)) (lua "return"))
|
||||
(let [floor-mat (pxl8.create_material {:texture floor-tex :lighting true :double_sided true})
|
||||
trim-mat (pxl8.create_material {:texture trim-tex :lighting true :double_sided true})
|
||||
wall-mat (pxl8.create_material {:texture wall-tex :lighting true :double_sided true})]
|
||||
(world:set_bsp_material 0 floor-mat)
|
||||
(world:set_bsp_material 1 wall-mat)
|
||||
(world:set_bsp_material 3 trim-mat)
|
||||
(entities.setup-lighting (chunk:bsp) 2)
|
||||
(set materials-for-chunk net-chunk)))))
|
||||
(when materials-set? (lua "return"))
|
||||
(when (not (network:has_chunk)) (lua "return"))
|
||||
(let [chunk (world:active_chunk)]
|
||||
(when (not chunk) (lua "return"))
|
||||
(when (not (chunk:ready)) (lua "return"))
|
||||
(let [dungeon-floor-tex (textures.wood-planks 44444 WOOD_COLOR)
|
||||
dungeon-wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR)
|
||||
dungeon-trim-tex (textures.wood-trim 77777 WOOD_COLOR)
|
||||
court-floor-tex (textures.rough-stone 44442 STONE_FLOOR_COLOR)
|
||||
court-wall-tex (textures.ashlar-wall 55552 ASHLAR_COLOR ASHLAR_MOSS)
|
||||
court-trim-tex (textures.rough-stone 77772 STONE_TRIM_COLOR)
|
||||
grass-tex (textures.grass-top 44447 GRASS_COLOR)
|
||||
dungeon-floor-mat (pxl8.create_material {:texture dungeon-floor-tex :lighting true :double_sided true})
|
||||
dungeon-wall-mat (pxl8.create_material {:texture dungeon-wall-tex :lighting true :double_sided true})
|
||||
dungeon-trim-mat (pxl8.create_material {:texture dungeon-trim-tex :lighting true :double_sided true})
|
||||
court-floor-mat (pxl8.create_material {:texture court-floor-tex :lighting true :double_sided true})
|
||||
court-wall-mat (pxl8.create_material {:texture court-wall-tex :lighting true :double_sided true})
|
||||
court-trim-mat (pxl8.create_material {:texture court-trim-tex :lighting true :double_sided true})
|
||||
grass-mat (pxl8.create_material {:texture grass-tex :lighting true :double_sided true})]
|
||||
(world:set_bsp_material 0 dungeon-floor-mat)
|
||||
(world:set_bsp_material 1 dungeon-wall-mat)
|
||||
(world:set_bsp_material 3 dungeon-trim-mat)
|
||||
(world:set_bsp_material 4 court-floor-mat)
|
||||
(world:set_bsp_material 5 court-wall-mat)
|
||||
(world:set_bsp_material 6 court-trim-mat)
|
||||
(world:set_bsp_material 7 grass-mat)
|
||||
(set materials-set? true))))
|
||||
|
||||
(fn sample-input []
|
||||
(when (pxl8.key_pressed "`")
|
||||
|
|
@ -172,8 +154,6 @@
|
|||
(when (and auto-run-cancel-key (not (pxl8.key_down auto-run-cancel-key)))
|
||||
(set auto-run-cancel-key nil))
|
||||
|
||||
(set was-auto-running auto-run?)
|
||||
|
||||
(pxl8.make_input_msg
|
||||
{:move_x (+ (if (pxl8.key_down "d") 1 0) (if (pxl8.key_down "a") -1 0))
|
||||
:move_y (+ (if (or (pxl8.key_down "w") auto-run?) 1 0)
|
||||
|
|
@ -186,47 +166,6 @@
|
|||
(set last-dt dt)
|
||||
(setup-materials)
|
||||
|
||||
(when (> portal-cooldown 0)
|
||||
(set portal-cooldown (- portal-cooldown dt)))
|
||||
|
||||
(when (and world network (<= portal-cooldown 0))
|
||||
(let [(door-x door-z) (entities.get-door-position)
|
||||
door-radius (entities.get-door-radius)
|
||||
dist-to-door (math.sqrt (+ (* (- cam-x door-x) (- cam-x door-x))
|
||||
(* (- cam-z door-z) (- cam-z door-z))))]
|
||||
(when (< dist-to-door door-radius)
|
||||
(let [current-id (network:chunk_id)]
|
||||
(if (= current-id 1)
|
||||
(do
|
||||
(pxl8.info "Door: BSP 1 -> BSP 2")
|
||||
(network:enter_scene 1 2 door-spawn-x 0 door-spawn-z)
|
||||
(world:init_local_player door-spawn-x 0 door-spawn-z)
|
||||
(world:set_look door-spawn-yaw 0)
|
||||
(set cam-x door-spawn-x)
|
||||
(set cam-y 0)
|
||||
(set cam-z door-spawn-z)
|
||||
(set cam-yaw door-spawn-yaw)
|
||||
(set cam-pitch 0)
|
||||
(set smooth-cam-x door-spawn-x)
|
||||
(set smooth-cam-z door-spawn-z)
|
||||
(setup-textures 2)
|
||||
(set portal-cooldown 2.0))
|
||||
(= current-id 2)
|
||||
(do
|
||||
(pxl8.info "Door: BSP 2 -> BSP 1")
|
||||
(network:enter_scene 1 1 door-spawn-x 0 door-spawn-z)
|
||||
(world:init_local_player door-spawn-x 0 door-spawn-z)
|
||||
(world:set_look door-spawn-yaw 0)
|
||||
(set cam-x door-spawn-x)
|
||||
(set cam-y 0)
|
||||
(set cam-z door-spawn-z)
|
||||
(set cam-yaw door-spawn-yaw)
|
||||
(set cam-pitch 0)
|
||||
(set smooth-cam-x door-spawn-x)
|
||||
(set smooth-cam-z door-spawn-z)
|
||||
(setup-textures 1)
|
||||
(set portal-cooldown 2.0)))))))
|
||||
|
||||
(when world
|
||||
(let [input-msg (sample-input)
|
||||
player (world:local_player)]
|
||||
|
|
@ -298,8 +237,7 @@
|
|||
r2 (* 0.04 (math.sin (+ (* real-time 3.2) phase)))
|
||||
light-radius (* 150 (+ 0.95 r1 r2))]
|
||||
(lights:clear)
|
||||
(when (= current-bsp-id 1)
|
||||
(lights:add light-x light-y light-z 2 light-intensity light-radius))
|
||||
(lights:add light-x light-y light-z 2 light-intensity light-radius)
|
||||
|
||||
(pxl8.push_target)
|
||||
(pxl8.begin_frame_3d camera lights {
|
||||
|
|
@ -317,10 +255,8 @@
|
|||
(pxl8.set_wireframe (menu.is-wireframe))
|
||||
(world:render [smooth-cam-x eye-y smooth-cam-z])
|
||||
|
||||
(when (and chunk (= current-bsp-id 1))
|
||||
(entities.render-fireball light-x light-y light-z (menu.is-wireframe)))
|
||||
|
||||
(entities.render-door (menu.is-wireframe) 0)
|
||||
(when chunk
|
||||
(entities.render-fireball light-x light-y light-z))
|
||||
|
||||
(pxl8.end_frame_3d)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue