in-progress map things...
This commit is contained in:
parent
cfe7501fe2
commit
3c54e379d4
10 changed files with 753 additions and 14 deletions
|
|
@ -1,4 +1,5 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
(local bsp_world (require :mod.bsp_world))
|
||||
(local cube3d (require :mod.cube3d))
|
||||
|
||||
(var time 0)
|
||||
|
|
@ -16,11 +17,13 @@
|
|||
(var logo-sprite nil)
|
||||
|
||||
(global init (fn []
|
||||
(bsp_world.init)
|
||||
(pxl8.load_palette "res/sprites/pxl8_logo.ase")
|
||||
(set logo-sprite (pxl8.load_sprite "res/sprites/pxl8_logo.ase"))
|
||||
(set particles (pxl8.particles_new 1000))))
|
||||
|
||||
(global update (fn [dt]
|
||||
(bsp_world.update dt)
|
||||
(set time (+ time dt))
|
||||
|
||||
(when (pxl8.key_pressed "1")
|
||||
|
|
@ -46,6 +49,8 @@
|
|||
(set use-nes-palette (not use-nes-palette))
|
||||
(local palette-path (if use-nes-palette "res/palettes/nes.ase" "res/sprites/pxl8_logo.ase"))
|
||||
(pxl8.load_palette palette-path))
|
||||
(when (pxl8.key_pressed "0")
|
||||
(set current-effect 0))
|
||||
|
||||
(case current-effect
|
||||
1 (do
|
||||
|
|
@ -63,6 +68,8 @@
|
|||
|
||||
(global frame (fn []
|
||||
(case current-effect
|
||||
0 (bsp_world.frame)
|
||||
|
||||
1 (do
|
||||
(pxl8.clr 0)
|
||||
(when logo-sprite
|
||||
|
|
|
|||
53
demo/mod/bsp_world.fnl
Normal file
53
demo/mod/bsp_world.fnl
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var camera-angle 0)
|
||||
(local camera-height 0)
|
||||
(local camera-distance 300)
|
||||
(var fps 0)
|
||||
(var world nil)
|
||||
|
||||
(fn init []
|
||||
(set world (pxl8.world_new))
|
||||
(let [result (pxl8.world_load world "res/maps/test.bsp")]
|
||||
(if (< result 0)
|
||||
(pxl8.error (.. "Failed to load test.bsp - result: " result))
|
||||
(pxl8.info "Loaded world successfully!"))))
|
||||
|
||||
(fn update [dt]
|
||||
(when (> dt 0)
|
||||
(set fps (math.floor (/ 1.0 dt))))
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(set camera-angle (+ camera-angle (* dt 0.5)))))
|
||||
|
||||
(fn frame []
|
||||
(pxl8.clr 0)
|
||||
(pxl8.text (.. "FPS: " fps) 10 40 14)
|
||||
|
||||
(if (pxl8.world_is_loaded world)
|
||||
(let [cam-x (* camera-distance (math.cos camera-angle))
|
||||
cam-z (* camera-distance (math.sin camera-angle))]
|
||||
|
||||
(pxl8.text (.. "Camera: " (string.format "%.0f" cam-x) ","
|
||||
(string.format "%.0f" camera-height) ","
|
||||
(string.format "%.0f" cam-z)) 10 55 12)
|
||||
|
||||
(pxl8.clear_zbuffer)
|
||||
(pxl8.set_backface_culling true)
|
||||
(pxl8.set_wireframe true)
|
||||
|
||||
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
|
||||
fov 1.047]
|
||||
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
|
||||
|
||||
(pxl8.set_view (pxl8.mat4_lookat
|
||||
[cam-x camera-height cam-z]
|
||||
[0 0 0]
|
||||
[0 1 0]))
|
||||
|
||||
(pxl8.set_model (pxl8.mat4_identity))
|
||||
|
||||
(pxl8.world_render world [cam-x camera-height cam-z]))))
|
||||
|
||||
{:init init
|
||||
:update update
|
||||
:frame frame}
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
(var cam-pitch -0.2)
|
||||
(var show-debug-ui false)
|
||||
(var fps 0)
|
||||
(var fps-timer 0)
|
||||
(var fps-accumulator 0)
|
||||
(var fps-frame-count 0)
|
||||
|
||||
|
|
@ -174,7 +173,7 @@
|
|||
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 0.1 100.0))))
|
||||
|
||||
(let [target-x (* (math.sin cam-yaw) (math.cos cam-pitch))
|
||||
target-y (* (math.sin cam-pitch))
|
||||
target-y (math.sin cam-pitch)
|
||||
target-z (* (- (math.cos cam-yaw)) (math.cos cam-pitch))
|
||||
look-x (+ cam-x target-x)
|
||||
look-y (+ cam-y target-y)
|
||||
|
|
@ -213,13 +212,13 @@
|
|||
(pxl8.draw_triangle_3d v0 v1 v2 color))))))
|
||||
|
||||
(let [new-state (debug-ui.render {:show-debug-ui show-debug-ui
|
||||
:fps fps
|
||||
:wireframe wireframe
|
||||
:auto-rotate auto-rotate
|
||||
:orthographic orthographic
|
||||
:use-texture use-texture
|
||||
:affine affine
|
||||
:init-texture init-texture})]
|
||||
:fps fps
|
||||
:wireframe wireframe
|
||||
:auto-rotate auto-rotate
|
||||
:orthographic orthographic
|
||||
:use-texture use-texture
|
||||
:affine affine
|
||||
:init-texture init-texture})]
|
||||
(when (not= new-state.show-debug-ui nil) (set show-debug-ui new-state.show-debug-ui))
|
||||
(when (not= new-state.wireframe nil) (set wireframe new-state.wireframe))
|
||||
(when (not= new-state.auto-rotate nil) (set auto-rotate new-state.auto-rotate))
|
||||
|
|
@ -229,5 +228,5 @@
|
|||
(when use-texture (init-texture)))
|
||||
(when (not= new-state.affine nil) (set affine new-state.affine))))
|
||||
|
||||
{: update
|
||||
: frame}
|
||||
{:update update
|
||||
:frame frame}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue