refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG - asset/: ase loader, cart, save, embed - gfx/: graphics, animation, atlas, fonts, tilemap, transitions - sfx/: audio - script/: lua/fennel runtime, REPL - hal/: platform abstraction (SDL3) - world/: BSP, world, procedural gen - math/: math utilities - game/: GUI, replay - lua/: Lua API modules
This commit is contained in:
parent
272e0bc615
commit
39b604b333
106 changed files with 6078 additions and 3715 deletions
|
|
@ -6,9 +6,11 @@
|
|||
(var time 0)
|
||||
(var active-demo :logo)
|
||||
(var particles nil)
|
||||
(var particles2 nil)
|
||||
(var fire-init? false)
|
||||
(var rain-init? false)
|
||||
(var snow-init? false)
|
||||
(var snow-init2? false)
|
||||
(var use-famicube-palette? false)
|
||||
|
||||
(var logo-x 256)
|
||||
|
|
@ -22,14 +24,15 @@
|
|||
(fn switch-demo [new-demo]
|
||||
(when (and (not= active-demo new-demo) (not transition))
|
||||
(set transition-pending new-demo)
|
||||
(set transition (pxl8.transition_create :pixelate 0.5))
|
||||
(pxl8.transition_set_color transition 0xFF000000)
|
||||
(pxl8.transition_start transition)))
|
||||
(set transition (pxl8.create_transition :pixelate 0.5))
|
||||
(transition:set_color 0xFF000000)
|
||||
(transition:start)))
|
||||
|
||||
(global init (fn []
|
||||
(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))
|
||||
(set particles (pxl8.create_particles 1000))
|
||||
(set particles2 (pxl8.create_particles 500))
|
||||
(music.init)
|
||||
(music.start)
|
||||
(worldgen.init)))
|
||||
|
|
@ -44,8 +47,8 @@
|
|||
(set time (+ time dt))
|
||||
|
||||
(when transition
|
||||
(pxl8.transition_update transition dt)
|
||||
(when (pxl8.transition_is_complete transition)
|
||||
(transition:update dt)
|
||||
(when (transition:is_complete)
|
||||
(when transition-pending
|
||||
(when (and (= active-demo :worldgen) (not= transition-pending :worldgen))
|
||||
(pxl8.set_relative_mouse_mode false))
|
||||
|
|
@ -55,8 +58,8 @@
|
|||
(set transition-pending nil)
|
||||
(when (= active-demo :fire) (set fire-init? false))
|
||||
(when (= active-demo :rain) (set rain-init? false))
|
||||
(when (= active-demo :snow) (set snow-init? false)))
|
||||
(pxl8.transition_destroy transition)
|
||||
(when (= active-demo :snow) (set snow-init? false) (set snow-init2? false)))
|
||||
(transition:destroy)
|
||||
(set transition nil)))
|
||||
|
||||
(when (pxl8.key_pressed "1") (switch-demo :logo))
|
||||
|
|
@ -93,7 +96,9 @@
|
|||
(music.update dt)
|
||||
|
||||
(when particles
|
||||
(pxl8.particles_update particles dt)))
|
||||
(particles:update dt))
|
||||
(when particles2
|
||||
(particles2:update dt)))
|
||||
|
||||
(when (menu.is-paused)
|
||||
(menu.update))))
|
||||
|
|
@ -105,50 +110,75 @@
|
|||
(when logo-sprite
|
||||
(pxl8.sprite logo-sprite logo-x logo-y 128 64 (< logo-dx 0) (< logo-dy 0))))
|
||||
|
||||
:plasma (pxl8.vfx_plasma time 0.10 0.04 1)
|
||||
:plasma (do
|
||||
(pxl8.clear 0)
|
||||
(pxl8.text "Plasma (TODO: Fennel impl)" 200 170 1))
|
||||
|
||||
:tunnel (pxl8.vfx_tunnel time 2.0 0.25)
|
||||
:tunnel (do
|
||||
(pxl8.clear 0)
|
||||
(pxl8.text "Tunnel (TODO: Fennel impl)" 200 170 1))
|
||||
|
||||
:raster (do
|
||||
(pxl8.clear 0)
|
||||
(local bars [{:base_y 60 :amplitude 30 :height 16 :speed 2.0 :phase 0 :color 1 :fade_color 18}
|
||||
{:base_y 180 :amplitude 35 :height 16 :speed 1.8 :phase 2.0 :color 1 :fade_color 27}
|
||||
{:base_y 300 :amplitude 25 :height 16 :speed 2.2 :phase 4.0 :color 1 :fade_color 24}])
|
||||
(pxl8.vfx_raster_bars bars time))
|
||||
(pxl8.text "Raster Bars (TODO: Fennel impl)" 180 170 1))
|
||||
|
||||
:fire (do
|
||||
(pxl8.clear 0)
|
||||
(when particles
|
||||
(when (not fire-init?)
|
||||
(pxl8.particles_clear particles)
|
||||
(pxl8.vfx_fire particles 160 140 100 12)
|
||||
(particles:clear)
|
||||
(particles:set_position 320 360)
|
||||
(particles:set_spread 320 0)
|
||||
(particles:set_gravity 0 -80)
|
||||
(particles:set_drag 0.98)
|
||||
(particles:set_turbulence 60)
|
||||
(particles:set_spawn_rate 200)
|
||||
(particles:set_colors 1 9)
|
||||
(particles:set_life 2.0 5.0)
|
||||
(particles:set_velocity -30 30 -120 -60)
|
||||
(set fire-init? true))
|
||||
(pxl8.particles_render particles)))
|
||||
(particles:render)))
|
||||
|
||||
:rain (do
|
||||
(pxl8.clear 0)
|
||||
(when particles
|
||||
(when (not rain-init?)
|
||||
(pxl8.particles_clear particles)
|
||||
(pxl8.vfx_rain particles 320 10.0)
|
||||
(particles:clear)
|
||||
(particles:set_position 320 -10)
|
||||
(particles:set_spread 340 0)
|
||||
(particles:set_gravity 30 80)
|
||||
(particles:set_drag 1.0)
|
||||
(particles:set_turbulence 5)
|
||||
(particles:set_spawn_rate 500)
|
||||
(particles:set_colors 20 22)
|
||||
(particles:set_life 2.0 3.0)
|
||||
(particles:set_velocity -20 20 400 600)
|
||||
(set rain-init? true))
|
||||
(pxl8.particles_render particles)))
|
||||
(particles:render)))
|
||||
|
||||
:snow (do
|
||||
(pxl8.clear 0)
|
||||
(when particles
|
||||
(when (not snow-init?)
|
||||
(pxl8.particles_clear particles)
|
||||
(pxl8.vfx_snow particles 320 5.0)
|
||||
(particles:clear)
|
||||
(particles:set_position 320 -10)
|
||||
(particles:set_spread 340 0)
|
||||
(particles:set_gravity 0 25)
|
||||
(particles:set_drag 1.0)
|
||||
(particles:set_turbulence 100)
|
||||
(particles:set_spawn_rate 100)
|
||||
(particles:set_life 8.0 12.0)
|
||||
(particles:set_colors 10 15)
|
||||
(particles:set_velocity -50 50 30 50)
|
||||
(set snow-init? true))
|
||||
(pxl8.particles_render particles)))
|
||||
(particles:render)))
|
||||
|
||||
:worldgen (worldgen.frame)
|
||||
|
||||
_ (pxl8.clear 0))
|
||||
|
||||
(when transition
|
||||
(pxl8.transition_render transition))
|
||||
(transition:render))
|
||||
|
||||
(when (menu.is-paused)
|
||||
(menu.draw))))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var paused false)
|
||||
(var gui nil)
|
||||
|
||||
(fn init []
|
||||
(set gui (pxl8.create_gui)))
|
||||
|
||||
(fn show []
|
||||
(set paused true)
|
||||
|
|
@ -12,36 +16,39 @@
|
|||
(pxl8.set_relative_mouse_mode true))
|
||||
|
||||
(fn toggle []
|
||||
(when (not gui) (init))
|
||||
(if paused
|
||||
(hide)
|
||||
(show)))
|
||||
|
||||
(fn update []
|
||||
(let [(mx my) (pxl8.get_mouse_pos)]
|
||||
(pxl8.gui_cursor_move mx my))
|
||||
(when gui
|
||||
(let [(mx my) (pxl8.get_mouse_pos)]
|
||||
(gui:cursor_move mx my))
|
||||
|
||||
(when (pxl8.mouse_pressed 1)
|
||||
(pxl8.gui_cursor_down))
|
||||
(when (pxl8.mouse_pressed 1)
|
||||
(gui:cursor_down))
|
||||
|
||||
(when (pxl8.mouse_released 1)
|
||||
(pxl8.gui_cursor_up)))
|
||||
(when (pxl8.mouse_released 1)
|
||||
(gui:cursor_up))))
|
||||
|
||||
(fn draw []
|
||||
(pxl8.gui_begin_frame)
|
||||
(when gui
|
||||
(gui:begin_frame)
|
||||
|
||||
(pxl8.gui_window 200 100 240 140 "pxl8 demo")
|
||||
(pxl8.gui_window 200 100 240 140 "pxl8 demo")
|
||||
|
||||
(when (pxl8.gui_button 1 215 145 210 32 "Resume")
|
||||
(hide))
|
||||
(when (gui:button 1 215 145 210 32 "Resume")
|
||||
(hide))
|
||||
|
||||
(when (pxl8.gui_button 2 215 185 210 32 "Quit")
|
||||
(pxl8.quit))
|
||||
(when (gui:button 2 215 185 210 32 "Quit")
|
||||
(pxl8.quit))
|
||||
|
||||
(if (pxl8.gui_is_hovering)
|
||||
(pxl8.set_cursor :hand)
|
||||
(pxl8.set_cursor :arrow))
|
||||
(if (gui:is_hovering)
|
||||
(pxl8.set_cursor :hand)
|
||||
(pxl8.set_cursor :arrow))
|
||||
|
||||
(pxl8.gui_end_frame))
|
||||
(gui:end_frame)))
|
||||
|
||||
{:is-paused (fn [] paused)
|
||||
:toggle toggle
|
||||
|
|
|
|||
|
|
@ -64,16 +64,16 @@
|
|||
(local step-duration sixteenth)
|
||||
|
||||
(fn init []
|
||||
(set ctx (pxl8.sfx_context_create))
|
||||
(set ctx (pxl8.create_sfx_context))
|
||||
|
||||
(local reverb (pxl8.sfx_reverb_create
|
||||
(local reverb (pxl8.create_reverb
|
||||
{:room 0.5 :damping 0.4 :mix 0.35}))
|
||||
(local compressor (pxl8.sfx_compressor_create
|
||||
(local compressor (pxl8.create_compressor
|
||||
{:threshold -18 :ratio 6 :attack 3 :release 100}))
|
||||
(pxl8.sfx_context_append_node ctx reverb)
|
||||
(pxl8.sfx_context_append_node ctx compressor)
|
||||
(ctx:append_node reverb)
|
||||
(ctx:append_node compressor)
|
||||
|
||||
(pxl8.sfx_mixer_attach ctx)
|
||||
(ctx:attach)
|
||||
|
||||
(set melody-params (pxl8.sfx_voice_params
|
||||
{:waveform pxl8.SFX_WAVE_TRIANGLE
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
(fn stop []
|
||||
(set playing false)
|
||||
(pxl8.sfx_stop_all ctx))
|
||||
(ctx:stop_all))
|
||||
|
||||
(fn update [dt]
|
||||
(when playing
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
(local melody-note (. melody-entry 1))
|
||||
(local melody-dur (. melody-entry 2))
|
||||
(when (> melody-note 0)
|
||||
(pxl8.sfx_play_note ctx melody-note melody-params 0.45 melody-dur))
|
||||
(ctx:play_note melody-note melody-params 0.45 melody-dur))
|
||||
|
||||
(local bass-step (math.floor (/ step 2)))
|
||||
(local bass-idx (+ 1 (% bass-step (length bass))))
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
(local bass-note (. bass-entry 1))
|
||||
(local bass-dur (. bass-entry 2))
|
||||
(when (= (% step 2) 0)
|
||||
(pxl8.sfx_play_note ctx bass-note bass-params 0.55 bass-dur))
|
||||
(ctx:play_note bass-note bass-params 0.55 bass-dur))
|
||||
|
||||
(set step (+ step 1)))))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var world nil)
|
||||
(local bob-amount 4.0)
|
||||
(local bob-speed 8.0)
|
||||
(local cam-smoothing 0.25)
|
||||
(local cell-size 64)
|
||||
(local cursor-sensitivity 0.008)
|
||||
(local gravity -800)
|
||||
(local grid-size 64)
|
||||
(local ground-y 64)
|
||||
(local jump-force 175)
|
||||
(local land-recovery-speed 20)
|
||||
(local land-squash-amount -4)
|
||||
(local max-pitch 1.5)
|
||||
(local move-speed 200)
|
||||
(local turn-speed 2.0)
|
||||
|
||||
(var auto-run? false)
|
||||
(var auto-run-cancel-key nil)
|
||||
(var bob-time 0)
|
||||
(var cam-pitch 0)
|
||||
(var cam-x 1000)
|
||||
(var cam-y 64)
|
||||
(var cam-yaw 0)
|
||||
(var cam-z 1000)
|
||||
(var camera nil)
|
||||
(var cursor-look? true)
|
||||
|
||||
(var grounded? true)
|
||||
(var land-squash 0)
|
||||
(var smooth-cam-x 1000)
|
||||
(var smooth-cam-z 1000)
|
||||
(local cam-smoothing 0.25)
|
||||
|
||||
(local bob-amount 4.0)
|
||||
(local bob-speed 8.0)
|
||||
(var bob-time 0)
|
||||
(local cell-size 64)
|
||||
(local cursor-sensitivity 0.008)
|
||||
(local gravity -800)
|
||||
(local grid-size 64)
|
||||
(var grounded? true)
|
||||
(local ground-y 64)
|
||||
(local jump-force 175)
|
||||
(local land-recovery-speed 20)
|
||||
(local land-squash-amount -4)
|
||||
(var land-squash 0)
|
||||
(local max-pitch 1.5)
|
||||
(local move-speed 200)
|
||||
(local turn-speed 2.0)
|
||||
(var velocity-y 0)
|
||||
(var world nil)
|
||||
|
||||
(fn init []
|
||||
(set world (pxl8.world_new))
|
||||
(let [result (pxl8.world_generate world {
|
||||
(set camera (pxl8.create_camera_3d))
|
||||
(set world (pxl8.create_world))
|
||||
(let [result (world:generate {
|
||||
:type pxl8.PROCGEN_ROOMS
|
||||
:width 64
|
||||
:height 64
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
:height 64
|
||||
:base_color 4})]
|
||||
|
||||
(let [result (pxl8.world_apply_textures world [
|
||||
(let [result (world:apply_textures [
|
||||
{:name "floor"
|
||||
:texture_id floor-tex
|
||||
:rule (fn [normal] (> normal.y 0.7))}
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
(when (and auto-run-cancel-key (not (pxl8.key_down auto-run-cancel-key)))
|
||||
(set auto-run-cancel-key nil))
|
||||
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(when (world:is_loaded)
|
||||
(let [forward-x (- (math.sin cam-yaw))
|
||||
forward-z (- (math.cos cam-yaw))
|
||||
right-x (math.cos cam-yaw)
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
|
||||
(when (and (>= new-x 0) (<= new-x grid-max)
|
||||
(>= new-z 0) (<= new-z grid-max))
|
||||
(let [(resolved-x resolved-y resolved-z) (pxl8.world_resolve_collision world cam-x cam-y cam-z new-x cam-y new-z 5)]
|
||||
(let [(resolved-x resolved-y resolved-z) (world:resolve_collision cam-x cam-y cam-z new-x cam-y new-z 5)]
|
||||
(set cam-x resolved-x)
|
||||
(set cam-z resolved-z)))
|
||||
|
||||
|
|
@ -176,31 +176,36 @@
|
|||
(fn frame []
|
||||
(pxl8.clear 0)
|
||||
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(when (not camera)
|
||||
(pxl8.error "camera is nil!"))
|
||||
|
||||
(when (not world)
|
||||
(pxl8.error "world is nil!"))
|
||||
|
||||
(when (and world (not (world:is_loaded)))
|
||||
(pxl8.text "World not loaded yet..." 5 30 12))
|
||||
|
||||
(when (and camera world (world:is_loaded))
|
||||
(let [bob-offset (* (math.sin bob-time) bob-amount)
|
||||
eye-y (+ cam-y bob-offset land-squash)
|
||||
forward-x (- (math.sin cam-yaw))
|
||||
forward-z (- (math.cos cam-yaw))
|
||||
target-x (+ smooth-cam-x forward-x)
|
||||
target-y (+ eye-y (math.sin cam-pitch))
|
||||
target-z (+ smooth-cam-z forward-z)]
|
||||
target-z (+ smooth-cam-z forward-z)
|
||||
aspect (/ (pxl8.get_width) (pxl8.get_height))]
|
||||
|
||||
(pxl8.clear_zbuffer)
|
||||
(pxl8.set_backface_culling true)
|
||||
(pxl8.set_wireframe false)
|
||||
(camera:lookat [smooth-cam-x eye-y smooth-cam-z]
|
||||
[target-x target-y target-z]
|
||||
[0 1 0])
|
||||
(camera:set_perspective 1.047 aspect 1.0 4096.0)
|
||||
|
||||
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
|
||||
fov 1.047]
|
||||
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
|
||||
(pxl8.begin_frame_3d camera)
|
||||
(pxl8.clear_depth)
|
||||
|
||||
(pxl8.set_view (pxl8.mat4_lookat
|
||||
[smooth-cam-x eye-y smooth-cam-z]
|
||||
[target-x target-y target-z]
|
||||
[0 1 0]))
|
||||
(world:render [smooth-cam-x eye-y smooth-cam-z])
|
||||
|
||||
(pxl8.set_model (pxl8.mat4_identity))
|
||||
|
||||
(pxl8.world_render world [smooth-cam-x eye-y smooth-cam-z])
|
||||
(pxl8.end_frame_3d)
|
||||
|
||||
(let [cx (/ (pxl8.get_width) 2)
|
||||
cy (/ (pxl8.get_height) 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue