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
248
src/lua/pxl8.lua
248
src/lua/pxl8.lua
|
|
@ -1,248 +0,0 @@
|
|||
local core = require("pxl8.core")
|
||||
local gfx2d = require("pxl8.gfx2d")
|
||||
local input = require("pxl8.input")
|
||||
local vfx = require("pxl8.vfx")
|
||||
local particles = require("pxl8.particles")
|
||||
local tilemap = require("pxl8.tilemap")
|
||||
local gfx3d = require("pxl8.gfx3d")
|
||||
local math3d = require("pxl8.math")
|
||||
local gui = require("pxl8.gui")
|
||||
local world = require("pxl8.world")
|
||||
local transition = require("pxl8.transition")
|
||||
local anim = require("pxl8.anim")
|
||||
local sfx = require("pxl8.sfx")
|
||||
local pxl8 = {}
|
||||
|
||||
core.init(pxl8_gfx, pxl8_input, pxl8_rng, pxl8_sfx, pxl8_sys)
|
||||
|
||||
pxl8.get_fps = core.get_fps
|
||||
pxl8.get_height = core.get_height
|
||||
pxl8.get_title = core.get_title
|
||||
pxl8.get_width = core.get_width
|
||||
pxl8.info = core.info
|
||||
pxl8.warn = core.warn
|
||||
pxl8.error = core.error
|
||||
pxl8.debug = core.debug
|
||||
pxl8.trace = core.trace
|
||||
pxl8.quit = core.quit
|
||||
|
||||
pxl8.rng_seed = core.rng_seed
|
||||
pxl8.rng_next = core.rng_next
|
||||
pxl8.rng_f32 = core.rng_f32
|
||||
pxl8.rng_range = core.rng_range
|
||||
|
||||
pxl8.clear = gfx2d.clear
|
||||
pxl8.pixel = gfx2d.pixel
|
||||
pxl8.line = gfx2d.line
|
||||
pxl8.rect = gfx2d.rect
|
||||
pxl8.rect_fill = gfx2d.rect_fill
|
||||
pxl8.circle = gfx2d.circle
|
||||
pxl8.circle_fill = gfx2d.circle_fill
|
||||
pxl8.text = gfx2d.text
|
||||
pxl8.sprite = gfx2d.sprite
|
||||
pxl8.load_palette = gfx2d.load_palette
|
||||
pxl8.load_sprite = gfx2d.load_sprite
|
||||
pxl8.create_texture = gfx2d.create_texture
|
||||
pxl8.gfx_color_ramp = gfx2d.color_ramp
|
||||
pxl8.gfx_fade_palette = gfx2d.fade_palette
|
||||
pxl8.gfx_cycle_palette = gfx2d.cycle_palette
|
||||
pxl8.add_palette_cycle = gfx2d.add_palette_cycle
|
||||
pxl8.remove_palette_cycle = gfx2d.remove_palette_cycle
|
||||
pxl8.set_palette_cycle_speed = gfx2d.set_palette_cycle_speed
|
||||
pxl8.clear_palette_cycles = gfx2d.clear_palette_cycles
|
||||
|
||||
pxl8.key_down = input.key_down
|
||||
pxl8.key_pressed = input.key_pressed
|
||||
pxl8.key_released = input.key_released
|
||||
pxl8.mouse_dx = input.mouse_dx
|
||||
pxl8.mouse_dy = input.mouse_dy
|
||||
pxl8.mouse_wheel_x = input.mouse_wheel_x
|
||||
pxl8.mouse_wheel_y = input.mouse_wheel_y
|
||||
pxl8.mouse_x = input.mouse_x
|
||||
pxl8.mouse_y = input.mouse_y
|
||||
pxl8.get_mouse_pos = input.get_mouse_pos
|
||||
pxl8.mouse_pressed = input.mouse_pressed
|
||||
pxl8.mouse_released = input.mouse_released
|
||||
pxl8.center_cursor = input.center_cursor
|
||||
pxl8.set_cursor = input.set_cursor
|
||||
pxl8.set_relative_mouse_mode = input.set_relative_mouse_mode
|
||||
|
||||
pxl8.vfx_raster_bars = vfx.raster_bars
|
||||
pxl8.vfx_plasma = vfx.plasma
|
||||
pxl8.vfx_rotozoom = vfx.rotozoom
|
||||
pxl8.vfx_tunnel = vfx.tunnel
|
||||
pxl8.vfx_explosion = vfx.explosion
|
||||
pxl8.vfx_fire = vfx.fire
|
||||
pxl8.vfx_rain = vfx.rain
|
||||
pxl8.vfx_smoke = vfx.smoke
|
||||
pxl8.vfx_snow = vfx.snow
|
||||
pxl8.vfx_sparks = vfx.sparks
|
||||
pxl8.vfx_starfield = vfx.starfield
|
||||
|
||||
pxl8.particles_new = particles.new
|
||||
pxl8.particles_destroy = particles.destroy
|
||||
pxl8.particles_clear = particles.clear
|
||||
pxl8.particles_emit = particles.emit
|
||||
pxl8.particles_update = particles.update
|
||||
pxl8.particles_render = particles.render
|
||||
|
||||
pxl8.tilesheet_new = tilemap.tilesheet_new
|
||||
pxl8.tilesheet_destroy = tilemap.tilesheet_destroy
|
||||
pxl8.tilesheet_load = tilemap.tilesheet_load
|
||||
pxl8.tilemap_new = tilemap.new
|
||||
pxl8.tilemap_destroy = tilemap.destroy
|
||||
pxl8.tilemap_set_tilesheet = tilemap.set_tilesheet
|
||||
pxl8.tilemap_set_tile = tilemap.set_tile
|
||||
pxl8.tilemap_get_tile_id = tilemap.get_tile_id
|
||||
pxl8.tilemap_set_camera = tilemap.set_camera
|
||||
pxl8.tilemap_render = tilemap.render
|
||||
pxl8.tilemap_render_layer = tilemap.render_layer
|
||||
pxl8.tilemap_is_solid = tilemap.is_solid
|
||||
pxl8.tilemap_check_collision = tilemap.check_collision
|
||||
pxl8.tilemap_get_tile_data = tilemap.get_tile_data
|
||||
pxl8.tilemap_load_ase = tilemap.load_ase
|
||||
pxl8.tilemap_set_tile_data = tilemap.set_tile_data
|
||||
pxl8.TILE_FLIP_X = tilemap.TILE_FLIP_X
|
||||
pxl8.TILE_FLIP_Y = tilemap.TILE_FLIP_Y
|
||||
pxl8.TILE_SOLID = tilemap.TILE_SOLID
|
||||
pxl8.TILE_TRIGGER = tilemap.TILE_TRIGGER
|
||||
|
||||
pxl8.clear_zbuffer = gfx3d.clear_zbuffer
|
||||
pxl8.set_model = gfx3d.set_model
|
||||
pxl8.set_view = gfx3d.set_view
|
||||
pxl8.set_projection = gfx3d.set_projection
|
||||
pxl8.set_wireframe = gfx3d.set_wireframe
|
||||
pxl8.set_affine_textures = gfx3d.set_affine_textures
|
||||
pxl8.set_backface_culling = gfx3d.set_backface_culling
|
||||
pxl8.draw_triangle_3d = gfx3d.draw_triangle
|
||||
pxl8.draw_triangle_3d_textured = gfx3d.draw_triangle_textured
|
||||
pxl8.draw_line_3d = gfx3d.draw_line
|
||||
|
||||
pxl8.mat4_identity = math3d.mat4_identity
|
||||
pxl8.mat4_multiply = math3d.mat4_multiply
|
||||
pxl8.mat4_translate = math3d.mat4_translate
|
||||
pxl8.mat4_rotate_x = math3d.mat4_rotate_x
|
||||
pxl8.mat4_rotate_y = math3d.mat4_rotate_y
|
||||
pxl8.mat4_rotate_z = math3d.mat4_rotate_z
|
||||
pxl8.mat4_scale = math3d.mat4_scale
|
||||
pxl8.mat4_ortho = math3d.mat4_ortho
|
||||
pxl8.mat4_perspective = math3d.mat4_perspective
|
||||
pxl8.mat4_lookat = math3d.mat4_lookat
|
||||
pxl8.bounds = math3d.bounds
|
||||
|
||||
pxl8.gui_state_create = gui.state_create
|
||||
pxl8.gui_state_destroy = gui.state_destroy
|
||||
pxl8.gui_begin_frame = gui.begin_frame
|
||||
pxl8.gui_end_frame = gui.end_frame
|
||||
pxl8.gui_cursor_move = gui.cursor_move
|
||||
pxl8.gui_cursor_down = gui.cursor_down
|
||||
pxl8.gui_cursor_up = gui.cursor_up
|
||||
pxl8.gui_button = gui.button
|
||||
pxl8.gui_window = gui.window
|
||||
pxl8.gui_label = gui.label
|
||||
pxl8.gui_is_hovering = gui.is_hovering
|
||||
pxl8.gui_get_cursor_pos = gui.get_cursor_pos
|
||||
|
||||
pxl8.world_new = world.new
|
||||
pxl8.world_destroy = world.destroy
|
||||
pxl8.world_load = world.load
|
||||
pxl8.world_render = world.render
|
||||
pxl8.world_unload = world.unload
|
||||
pxl8.world_is_loaded = world.is_loaded
|
||||
pxl8.world_generate = world.generate
|
||||
pxl8.world_apply_textures = world.apply_textures
|
||||
pxl8.world_check_collision = world.check_collision
|
||||
pxl8.world_resolve_collision = world.resolve_collision
|
||||
pxl8.procgen_tex = world.procgen_tex
|
||||
pxl8.PROCGEN_ROOMS = world.PROCGEN_ROOMS
|
||||
pxl8.PROCGEN_TERRAIN = world.PROCGEN_TERRAIN
|
||||
|
||||
pxl8.transition_create = transition.create
|
||||
pxl8.transition_destroy = transition.destroy
|
||||
pxl8.transition_get_progress = transition.get_progress
|
||||
pxl8.transition_is_active = transition.is_active
|
||||
pxl8.transition_is_complete = transition.is_complete
|
||||
pxl8.transition_render = transition.render
|
||||
pxl8.transition_reset = transition.reset
|
||||
pxl8.transition_set_color = transition.set_color
|
||||
pxl8.transition_set_reverse = transition.set_reverse
|
||||
pxl8.transition_start = transition.start
|
||||
pxl8.transition_stop = transition.stop
|
||||
pxl8.transition_update = transition.update
|
||||
|
||||
pxl8.anim_create = anim.create
|
||||
pxl8.anim_create_from_ase = anim.create_from_ase
|
||||
pxl8.anim_destroy = anim.destroy
|
||||
pxl8.anim_add_state = anim.add_state
|
||||
pxl8.anim_get_current_frame = anim.get_current_frame
|
||||
pxl8.anim_get_current_frame_id = anim.get_current_frame_id
|
||||
pxl8.anim_get_state = anim.get_state
|
||||
pxl8.anim_has_state_machine = anim.has_state_machine
|
||||
pxl8.anim_is_complete = anim.is_complete
|
||||
pxl8.anim_is_playing = anim.is_playing
|
||||
pxl8.anim_pause = anim.pause
|
||||
pxl8.anim_play = anim.play
|
||||
pxl8.anim_render_sprite = anim.render_sprite
|
||||
pxl8.anim_reset = anim.reset
|
||||
pxl8.anim_set_frame = anim.set_frame
|
||||
pxl8.anim_set_loop = anim.set_loop
|
||||
pxl8.anim_set_reverse = anim.set_reverse
|
||||
pxl8.anim_set_speed = anim.set_speed
|
||||
pxl8.anim_set_state = anim.set_state
|
||||
pxl8.anim_stop = anim.stop
|
||||
pxl8.anim_update = anim.update
|
||||
|
||||
pxl8.sfx_compressor_create = sfx.compressor_create
|
||||
pxl8.sfx_compressor_set_attack = sfx.compressor_set_attack
|
||||
pxl8.sfx_compressor_set_ratio = sfx.compressor_set_ratio
|
||||
pxl8.sfx_compressor_set_release = sfx.compressor_set_release
|
||||
pxl8.sfx_compressor_set_threshold = sfx.compressor_set_threshold
|
||||
pxl8.sfx_context_append_node = sfx.context_append_node
|
||||
pxl8.sfx_context_create = sfx.context_create
|
||||
pxl8.sfx_context_destroy = sfx.context_destroy
|
||||
pxl8.sfx_context_get_head = sfx.context_get_head
|
||||
pxl8.sfx_context_get_volume = sfx.context_get_volume
|
||||
pxl8.sfx_context_insert_node = sfx.context_insert_node
|
||||
pxl8.sfx_context_remove_node = sfx.context_remove_node
|
||||
pxl8.sfx_context_set_volume = sfx.context_set_volume
|
||||
pxl8.sfx_delay_create = sfx.delay_create
|
||||
pxl8.sfx_delay_set_feedback = sfx.delay_set_feedback
|
||||
pxl8.sfx_delay_set_mix = sfx.delay_set_mix
|
||||
pxl8.sfx_delay_set_time = sfx.delay_set_time
|
||||
pxl8.sfx_get_master_volume = sfx.get_master_volume
|
||||
pxl8.sfx_mixer_attach = sfx.mixer_attach
|
||||
pxl8.sfx_mixer_detach = sfx.mixer_detach
|
||||
pxl8.sfx_node_destroy = sfx.node_destroy
|
||||
pxl8.sfx_note_to_freq = sfx.note_to_freq
|
||||
pxl8.sfx_play_note = sfx.play_note
|
||||
pxl8.sfx_release_voice = sfx.release_voice
|
||||
pxl8.sfx_reverb_create = sfx.reverb_create
|
||||
pxl8.sfx_reverb_set_damping = sfx.reverb_set_damping
|
||||
pxl8.sfx_reverb_set_mix = sfx.reverb_set_mix
|
||||
pxl8.sfx_reverb_set_room = sfx.reverb_set_room
|
||||
pxl8.sfx_set_master_volume = sfx.set_master_volume
|
||||
pxl8.sfx_stop_all = sfx.stop_all
|
||||
pxl8.sfx_stop_voice = sfx.stop_voice
|
||||
pxl8.sfx_voice_params = sfx.voice_params
|
||||
|
||||
pxl8.SFX_FILTER_BANDPASS = sfx.FILTER_BANDPASS
|
||||
pxl8.SFX_FILTER_HIGHPASS = sfx.FILTER_HIGHPASS
|
||||
pxl8.SFX_FILTER_LOWPASS = sfx.FILTER_LOWPASS
|
||||
pxl8.SFX_FILTER_NONE = sfx.FILTER_NONE
|
||||
|
||||
pxl8.SFX_LFO_AMPLITUDE = sfx.LFO_AMPLITUDE
|
||||
pxl8.SFX_LFO_FILTER = sfx.LFO_FILTER
|
||||
pxl8.SFX_LFO_PITCH = sfx.LFO_PITCH
|
||||
|
||||
pxl8.SFX_NODE_COMPRESSOR = sfx.NODE_COMPRESSOR
|
||||
pxl8.SFX_NODE_DELAY = sfx.NODE_DELAY
|
||||
pxl8.SFX_NODE_REVERB = sfx.NODE_REVERB
|
||||
|
||||
pxl8.SFX_WAVE_NOISE = sfx.WAVE_NOISE
|
||||
pxl8.SFX_WAVE_PULSE = sfx.WAVE_PULSE
|
||||
pxl8.SFX_WAVE_SAW = sfx.WAVE_SAW
|
||||
pxl8.SFX_WAVE_SINE = sfx.WAVE_SINE
|
||||
pxl8.SFX_WAVE_SQUARE = sfx.WAVE_SQUARE
|
||||
pxl8.SFX_WAVE_TRIANGLE = sfx.WAVE_TRIANGLE
|
||||
|
||||
return pxl8
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local anim = {}
|
||||
|
||||
function anim.create(frame_ids, frame_durations)
|
||||
local frame_count = #frame_ids
|
||||
local c_frame_ids = ffi.new("u32[?]", frame_count)
|
||||
local c_frame_durations = nil
|
||||
|
||||
for i = 1, frame_count do
|
||||
c_frame_ids[i-1] = frame_ids[i]
|
||||
end
|
||||
|
||||
if frame_durations then
|
||||
c_frame_durations = ffi.new("u16[?]", frame_count)
|
||||
for i = 1, frame_count do
|
||||
c_frame_durations[i-1] = frame_durations[i]
|
||||
end
|
||||
end
|
||||
|
||||
return C.pxl8_anim_create(c_frame_ids, c_frame_durations, frame_count)
|
||||
end
|
||||
|
||||
function anim.create_from_ase(filepath)
|
||||
return C.pxl8_anim_create_from_ase(core.gfx, filepath)
|
||||
end
|
||||
|
||||
function anim.destroy(a)
|
||||
C.pxl8_anim_destroy(a)
|
||||
end
|
||||
|
||||
function anim.add_state(a, name, state_anim)
|
||||
return C.pxl8_anim_add_state(a, name, state_anim)
|
||||
end
|
||||
|
||||
function anim.get_current_frame(a)
|
||||
return C.pxl8_anim_get_current_frame(a)
|
||||
end
|
||||
|
||||
function anim.get_current_frame_id(a)
|
||||
return C.pxl8_anim_get_current_frame_id(a)
|
||||
end
|
||||
|
||||
function anim.get_state(a)
|
||||
local state_name = C.pxl8_anim_get_state(a)
|
||||
if state_name ~= nil then
|
||||
return ffi.string(state_name)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function anim.has_state_machine(a)
|
||||
return C.pxl8_anim_has_state_machine(a)
|
||||
end
|
||||
|
||||
function anim.is_complete(a)
|
||||
return C.pxl8_anim_is_complete(a)
|
||||
end
|
||||
|
||||
function anim.is_playing(a)
|
||||
return C.pxl8_anim_is_playing(a)
|
||||
end
|
||||
|
||||
function anim.pause(a)
|
||||
C.pxl8_anim_pause(a)
|
||||
end
|
||||
|
||||
function anim.play(a)
|
||||
C.pxl8_anim_play(a)
|
||||
end
|
||||
|
||||
function anim.render_sprite(a, x, y, w, h, flip_x, flip_y)
|
||||
C.pxl8_anim_render_sprite(a, core.gfx, x, y, w, h, flip_x or false, flip_y or false)
|
||||
end
|
||||
|
||||
function anim.reset(a)
|
||||
C.pxl8_anim_reset(a)
|
||||
end
|
||||
|
||||
function anim.set_frame(a, frame)
|
||||
C.pxl8_anim_set_frame(a, frame)
|
||||
end
|
||||
|
||||
function anim.set_loop(a, loop)
|
||||
C.pxl8_anim_set_loop(a, loop)
|
||||
end
|
||||
|
||||
function anim.set_reverse(a, reverse)
|
||||
C.pxl8_anim_set_reverse(a, reverse)
|
||||
end
|
||||
|
||||
function anim.set_speed(a, speed)
|
||||
C.pxl8_anim_set_speed(a, speed)
|
||||
end
|
||||
|
||||
function anim.set_state(a, name)
|
||||
return C.pxl8_anim_set_state(a, name)
|
||||
end
|
||||
|
||||
function anim.stop(a)
|
||||
C.pxl8_anim_stop(a)
|
||||
end
|
||||
|
||||
function anim.update(a, dt)
|
||||
C.pxl8_anim_update(a, dt)
|
||||
end
|
||||
|
||||
return anim
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
|
||||
local core = {}
|
||||
|
||||
function core.init(gfx, input, rng, sfx, sys)
|
||||
core.gfx = gfx
|
||||
core.input = input
|
||||
core.rng = rng
|
||||
core.sfx = sfx
|
||||
core.sys = sys
|
||||
end
|
||||
|
||||
function core.get_fps()
|
||||
return C.pxl8_get_fps(core.sys)
|
||||
end
|
||||
|
||||
function core.get_width()
|
||||
return C.pxl8_gfx_get_width(core.gfx)
|
||||
end
|
||||
|
||||
function core.get_height()
|
||||
return C.pxl8_gfx_get_height(core.gfx)
|
||||
end
|
||||
|
||||
function core.get_title()
|
||||
local cart = C.pxl8_get_cart()
|
||||
if cart ~= nil then
|
||||
local title = C.pxl8_cart_get_title(cart)
|
||||
if title ~= nil then
|
||||
return ffi.string(title)
|
||||
end
|
||||
end
|
||||
return "pxl8"
|
||||
end
|
||||
|
||||
local function is_user_script(info)
|
||||
local src = info and info.short_src
|
||||
return src and (src:match("%.fnl$") or src:match("%.lua$"))
|
||||
end
|
||||
|
||||
local function get_caller_info()
|
||||
for level = 2, 10 do
|
||||
local info = debug.getinfo(level, "Sl")
|
||||
if not info then break end
|
||||
if is_user_script(info) then
|
||||
return info.short_src, info.currentline or 0
|
||||
end
|
||||
end
|
||||
return "?", 0
|
||||
end
|
||||
|
||||
core.LOG_TRACE = 0
|
||||
core.LOG_DEBUG = 1
|
||||
core.LOG_INFO = 2
|
||||
core.LOG_WARN = 3
|
||||
core.LOG_ERROR = 4
|
||||
|
||||
local function make_logger(level)
|
||||
return function(msg)
|
||||
local src, line = get_caller_info()
|
||||
C.pxl8_lua_log(level, src, line, msg)
|
||||
end
|
||||
end
|
||||
|
||||
core.trace = make_logger(core.LOG_TRACE)
|
||||
core.debug = make_logger(core.LOG_DEBUG)
|
||||
core.info = make_logger(core.LOG_INFO)
|
||||
core.warn = make_logger(core.LOG_WARN)
|
||||
core.error = make_logger(core.LOG_ERROR)
|
||||
|
||||
function core.quit()
|
||||
C.pxl8_set_running(core.sys, false)
|
||||
end
|
||||
|
||||
function core.rng_seed(seed)
|
||||
C.pxl8_rng_seed(core.rng, seed)
|
||||
end
|
||||
|
||||
function core.rng_next()
|
||||
return C.pxl8_rng_next(core.rng)
|
||||
end
|
||||
|
||||
function core.rng_f32()
|
||||
return C.pxl8_rng_f32(core.rng)
|
||||
end
|
||||
|
||||
function core.rng_range(min, max)
|
||||
return C.pxl8_rng_range(core.rng, min, max)
|
||||
end
|
||||
|
||||
return core
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local graphics = {}
|
||||
|
||||
function graphics.clear(color)
|
||||
C.pxl8_clear(core.gfx, color or 0)
|
||||
end
|
||||
|
||||
function graphics.pixel(x, y, color)
|
||||
if color then
|
||||
C.pxl8_pixel(core.gfx, x, y, color)
|
||||
else
|
||||
return C.pxl8_get_pixel(core.gfx, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
function graphics.line(x0, y0, x1, y1, color)
|
||||
C.pxl8_line(core.gfx, x0, y0, x1, y1, color)
|
||||
end
|
||||
|
||||
function graphics.rect(x, y, w, h, color)
|
||||
C.pxl8_rect(core.gfx, x, y, w, h, color)
|
||||
end
|
||||
|
||||
function graphics.rect_fill(x, y, w, h, color)
|
||||
C.pxl8_rect_fill(core.gfx, x, y, w, h, color)
|
||||
end
|
||||
|
||||
function graphics.circle(x, y, r, color)
|
||||
C.pxl8_circle(core.gfx, x, y, r, color)
|
||||
end
|
||||
|
||||
function graphics.circle_fill(x, y, r, color)
|
||||
C.pxl8_circle_fill(core.gfx, x, y, r, color)
|
||||
end
|
||||
|
||||
function graphics.text(str, x, y, color)
|
||||
C.pxl8_text(core.gfx, str, x or 0, y or 0, color or 15)
|
||||
end
|
||||
|
||||
function graphics.sprite(id, x, y, w, h, flip_x, flip_y)
|
||||
C.pxl8_sprite(core.gfx, id or 0, x or 0, y or 0, w or 16, h or 16, flip_x or false, flip_y or false)
|
||||
end
|
||||
|
||||
function graphics.load_palette(filepath)
|
||||
return C.pxl8_gfx_load_palette(core.gfx, filepath)
|
||||
end
|
||||
|
||||
function graphics.load_sprite(filepath)
|
||||
local sprite_id = ffi.new("unsigned int[1]")
|
||||
local result = C.pxl8_gfx_load_sprite(core.gfx, filepath, sprite_id)
|
||||
if result == 0 then
|
||||
return sprite_id[0]
|
||||
else
|
||||
return nil, result
|
||||
end
|
||||
end
|
||||
|
||||
function graphics.create_texture(pixels, width, height)
|
||||
local pixel_data = ffi.new("u8[?]", width * height)
|
||||
for i = 0, width * height - 1 do
|
||||
pixel_data[i] = pixels[i + 1] or 0
|
||||
end
|
||||
local result = C.pxl8_gfx_create_texture(core.gfx, pixel_data, width, height)
|
||||
if result < 0 then
|
||||
return nil
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function graphics.color_ramp(start, count, from_color, to_color)
|
||||
C.pxl8_gfx_color_ramp(core.gfx, start, count, from_color, to_color)
|
||||
end
|
||||
|
||||
function graphics.fade_palette(start, count, amount, target_color)
|
||||
C.pxl8_gfx_fade_palette(core.gfx, start, count, amount, target_color)
|
||||
end
|
||||
|
||||
function graphics.cycle_palette(start, count, step)
|
||||
C.pxl8_gfx_cycle_palette(core.gfx, start, count, step or 1)
|
||||
end
|
||||
|
||||
function graphics.add_palette_cycle(start_index, end_index, speed)
|
||||
return C.pxl8_gfx_add_palette_cycle(core.gfx, start_index, end_index, speed or 1.0)
|
||||
end
|
||||
|
||||
function graphics.remove_palette_cycle(cycle_id)
|
||||
C.pxl8_gfx_remove_palette_cycle(core.gfx, cycle_id)
|
||||
end
|
||||
|
||||
function graphics.set_palette_cycle_speed(cycle_id, speed)
|
||||
C.pxl8_gfx_set_palette_cycle_speed(core.gfx, cycle_id, speed)
|
||||
end
|
||||
|
||||
function graphics.clear_palette_cycles()
|
||||
C.pxl8_gfx_clear_palette_cycles(core.gfx)
|
||||
end
|
||||
|
||||
return graphics
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local gfx3d = {}
|
||||
|
||||
function gfx3d.clear_zbuffer()
|
||||
C.pxl8_3d_clear_zbuffer(core.gfx)
|
||||
end
|
||||
|
||||
function gfx3d.set_model(mat)
|
||||
C.pxl8_3d_set_model(core.gfx, mat)
|
||||
end
|
||||
|
||||
function gfx3d.set_view(mat)
|
||||
C.pxl8_3d_set_view(core.gfx, mat)
|
||||
end
|
||||
|
||||
function gfx3d.set_projection(mat)
|
||||
C.pxl8_3d_set_projection(core.gfx, mat)
|
||||
end
|
||||
|
||||
function gfx3d.set_wireframe(wireframe)
|
||||
C.pxl8_3d_set_wireframe(core.gfx, wireframe)
|
||||
end
|
||||
|
||||
function gfx3d.set_affine_textures(affine)
|
||||
C.pxl8_3d_set_affine_textures(core.gfx, affine)
|
||||
end
|
||||
|
||||
function gfx3d.set_backface_culling(culling)
|
||||
C.pxl8_3d_set_backface_culling(core.gfx, culling)
|
||||
end
|
||||
|
||||
function gfx3d.draw_triangle(v0, v1, v2, color)
|
||||
local vec0 = ffi.new("pxl8_vec3", {x = v0[1], y = v0[2], z = v0[3]})
|
||||
local vec1 = ffi.new("pxl8_vec3", {x = v1[1], y = v1[2], z = v1[3]})
|
||||
local vec2 = ffi.new("pxl8_vec3", {x = v2[1], y = v2[2], z = v2[3]})
|
||||
C.pxl8_3d_draw_triangle_raw(core.gfx, vec0, vec1, vec2, color)
|
||||
end
|
||||
|
||||
function gfx3d.draw_triangle_textured(v0, v1, v2, uv0, uv1, uv2, texture_id)
|
||||
local vec0 = ffi.new("pxl8_vec3", {x = v0[1], y = v0[2], z = v0[3]})
|
||||
local vec1 = ffi.new("pxl8_vec3", {x = v1[1], y = v1[2], z = v1[3]})
|
||||
local vec2 = ffi.new("pxl8_vec3", {x = v2[1], y = v2[2], z = v2[3]})
|
||||
C.pxl8_3d_draw_triangle_textured(core.gfx, vec0, vec1, vec2,
|
||||
uv0[1], uv0[2], uv1[1], uv1[2], uv2[1], uv2[2], texture_id)
|
||||
end
|
||||
|
||||
function gfx3d.draw_line(p0, p1, color)
|
||||
local vec0 = ffi.new("pxl8_vec3", {x = p0[1], y = p0[2], z = p0[3]})
|
||||
local vec1 = ffi.new("pxl8_vec3", {x = p1[1], y = p1[2], z = p1[3]})
|
||||
C.pxl8_3d_draw_line_3d(core.gfx, vec0, vec1, color)
|
||||
end
|
||||
|
||||
return gfx3d
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local gui = {}
|
||||
|
||||
local state = nil
|
||||
|
||||
local function gui_state()
|
||||
if not state then
|
||||
state = ffi.gc(C.pxl8_gui_state_create(), C.pxl8_gui_state_destroy)
|
||||
end
|
||||
return state
|
||||
end
|
||||
|
||||
function gui.begin_frame()
|
||||
C.pxl8_gui_begin_frame(gui_state())
|
||||
end
|
||||
|
||||
function gui.end_frame()
|
||||
C.pxl8_gui_end_frame(gui_state())
|
||||
end
|
||||
|
||||
function gui.cursor_move(x, y)
|
||||
C.pxl8_gui_cursor_move(gui_state(), x, y)
|
||||
end
|
||||
|
||||
function gui.cursor_down()
|
||||
C.pxl8_gui_cursor_down(gui_state())
|
||||
end
|
||||
|
||||
function gui.cursor_up()
|
||||
C.pxl8_gui_cursor_up(gui_state())
|
||||
end
|
||||
|
||||
function gui.button(id, x, y, w, h, label)
|
||||
return C.pxl8_gui_button(gui_state(), core.gfx, id, x, y, w, h, label)
|
||||
end
|
||||
|
||||
function gui.window(x, y, w, h, title)
|
||||
C.pxl8_gui_window(core.gfx, x, y, w, h, title)
|
||||
end
|
||||
|
||||
function gui.label(x, y, text, color)
|
||||
C.pxl8_gui_label(core.gfx, x, y, text, color)
|
||||
end
|
||||
|
||||
function gui.is_hovering()
|
||||
return C.pxl8_gui_is_hovering(gui_state())
|
||||
end
|
||||
|
||||
function gui.get_cursor_pos()
|
||||
local x = ffi.new("i32[1]")
|
||||
local y = ffi.new("i32[1]")
|
||||
C.pxl8_gui_get_cursor_pos(gui_state(), x, y)
|
||||
return x[0], y[0]
|
||||
end
|
||||
|
||||
return gui
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local input = {}
|
||||
|
||||
function input.key_down(key)
|
||||
return C.pxl8_key_down(core.input, key)
|
||||
end
|
||||
|
||||
function input.key_pressed(key)
|
||||
return C.pxl8_key_pressed(core.input, key)
|
||||
end
|
||||
|
||||
function input.key_released(key)
|
||||
return C.pxl8_key_released(core.input, key)
|
||||
end
|
||||
|
||||
function input.mouse_wheel_x()
|
||||
return C.pxl8_mouse_wheel_x(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_wheel_y()
|
||||
return C.pxl8_mouse_wheel_y(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_x()
|
||||
return C.pxl8_mouse_x(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_y()
|
||||
return C.pxl8_mouse_y(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_dx()
|
||||
return C.pxl8_mouse_dx(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_dy()
|
||||
return C.pxl8_mouse_dy(core.input)
|
||||
end
|
||||
|
||||
function input.get_mouse_pos()
|
||||
return C.pxl8_mouse_x(core.input), C.pxl8_mouse_y(core.input)
|
||||
end
|
||||
|
||||
function input.mouse_pressed(button)
|
||||
return C.pxl8_mouse_pressed(core.input, button)
|
||||
end
|
||||
|
||||
function input.mouse_released(button)
|
||||
return C.pxl8_mouse_released(core.input, button)
|
||||
end
|
||||
|
||||
function input.set_relative_mouse_mode(enabled)
|
||||
C.pxl8_set_relative_mouse_mode(core.sys, enabled)
|
||||
end
|
||||
|
||||
function input.center_cursor()
|
||||
C.pxl8_center_cursor(core.sys)
|
||||
end
|
||||
|
||||
function input.set_cursor(cursor_type)
|
||||
local cursor_enum
|
||||
if cursor_type == "arrow" then
|
||||
cursor_enum = C.PXL8_CURSOR_ARROW
|
||||
elseif cursor_type == "hand" then
|
||||
cursor_enum = C.PXL8_CURSOR_HAND
|
||||
else
|
||||
cursor_enum = C.PXL8_CURSOR_ARROW
|
||||
end
|
||||
C.pxl8_set_cursor(core.sys, cursor_enum)
|
||||
end
|
||||
|
||||
return input
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
|
||||
local math3d = {}
|
||||
|
||||
function math3d.mat4_identity()
|
||||
return C.pxl8_mat4_identity()
|
||||
end
|
||||
|
||||
function math3d.mat4_multiply(a, b)
|
||||
return C.pxl8_mat4_multiply(a, b)
|
||||
end
|
||||
|
||||
function math3d.mat4_translate(x, y, z)
|
||||
return C.pxl8_mat4_translate(x, y, z)
|
||||
end
|
||||
|
||||
function math3d.mat4_rotate_x(angle)
|
||||
return C.pxl8_mat4_rotate_x(angle)
|
||||
end
|
||||
|
||||
function math3d.mat4_rotate_y(angle)
|
||||
return C.pxl8_mat4_rotate_y(angle)
|
||||
end
|
||||
|
||||
function math3d.mat4_rotate_z(angle)
|
||||
return C.pxl8_mat4_rotate_z(angle)
|
||||
end
|
||||
|
||||
function math3d.mat4_scale(x, y, z)
|
||||
return C.pxl8_mat4_scale(x, y, z)
|
||||
end
|
||||
|
||||
function math3d.mat4_ortho(left, right, bottom, top, near, far)
|
||||
return C.pxl8_mat4_ortho(left, right, bottom, top, near, far)
|
||||
end
|
||||
|
||||
function math3d.mat4_perspective(fov, aspect, near, far)
|
||||
return C.pxl8_mat4_perspective(fov, aspect, near, far)
|
||||
end
|
||||
|
||||
function math3d.mat4_lookat(eye, center, up)
|
||||
local eye_vec = ffi.new("pxl8_vec3", {x = eye[1], y = eye[2], z = eye[3]})
|
||||
local center_vec = ffi.new("pxl8_vec3", {x = center[1], y = center[2], z = center[3]})
|
||||
local up_vec = ffi.new("pxl8_vec3", {x = up[1], y = up[2], z = up[3]})
|
||||
return C.pxl8_mat4_lookat(eye_vec, center_vec, up_vec)
|
||||
end
|
||||
|
||||
function math3d.bounds(x, y, w, h)
|
||||
return ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
||||
end
|
||||
|
||||
return math3d
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local particles = {}
|
||||
|
||||
function particles.new(max_count)
|
||||
return C.pxl8_particles_create(max_count or 1000, core.rng)
|
||||
end
|
||||
|
||||
function particles.destroy(ps)
|
||||
C.pxl8_particles_destroy(ps)
|
||||
end
|
||||
|
||||
function particles.clear(ps)
|
||||
C.pxl8_particles_clear(ps)
|
||||
end
|
||||
|
||||
function particles.emit(ps, count)
|
||||
C.pxl8_particles_emit(ps, count or 1)
|
||||
end
|
||||
|
||||
function particles.update(ps, dt)
|
||||
C.pxl8_particles_update(ps, dt)
|
||||
end
|
||||
|
||||
function particles.render(ps)
|
||||
C.pxl8_particles_render(ps, core.gfx)
|
||||
end
|
||||
|
||||
return particles
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local sfx = {}
|
||||
|
||||
sfx.FILTER_BANDPASS = C.PXL8_SFX_FILTER_BANDPASS
|
||||
sfx.FILTER_HIGHPASS = C.PXL8_SFX_FILTER_HIGHPASS
|
||||
sfx.FILTER_LOWPASS = C.PXL8_SFX_FILTER_LOWPASS
|
||||
sfx.FILTER_NONE = C.PXL8_SFX_FILTER_NONE
|
||||
|
||||
sfx.LFO_AMPLITUDE = C.PXL8_SFX_LFO_AMPLITUDE
|
||||
sfx.LFO_FILTER = C.PXL8_SFX_LFO_FILTER
|
||||
sfx.LFO_PITCH = C.PXL8_SFX_LFO_PITCH
|
||||
|
||||
sfx.NODE_COMPRESSOR = C.PXL8_SFX_NODE_COMPRESSOR
|
||||
sfx.NODE_DELAY = C.PXL8_SFX_NODE_DELAY
|
||||
sfx.NODE_REVERB = C.PXL8_SFX_NODE_REVERB
|
||||
|
||||
sfx.WAVE_NOISE = C.PXL8_SFX_WAVE_NOISE
|
||||
sfx.WAVE_PULSE = C.PXL8_SFX_WAVE_PULSE
|
||||
sfx.WAVE_SAW = C.PXL8_SFX_WAVE_SAW
|
||||
sfx.WAVE_SINE = C.PXL8_SFX_WAVE_SINE
|
||||
sfx.WAVE_SQUARE = C.PXL8_SFX_WAVE_SQUARE
|
||||
sfx.WAVE_TRIANGLE = C.PXL8_SFX_WAVE_TRIANGLE
|
||||
|
||||
function sfx.compressor_create(opts)
|
||||
opts = opts or {}
|
||||
local cfg = ffi.new("pxl8_sfx_compressor_config")
|
||||
cfg.attack = opts.attack or 10
|
||||
cfg.ratio = opts.ratio or 4
|
||||
cfg.release = opts.release or 100
|
||||
cfg.threshold = opts.threshold or -12
|
||||
return C.pxl8_sfx_compressor_create(cfg)
|
||||
end
|
||||
|
||||
function sfx.compressor_set_attack(node, attack)
|
||||
C.pxl8_sfx_compressor_set_attack(node, attack)
|
||||
end
|
||||
|
||||
function sfx.compressor_set_ratio(node, ratio)
|
||||
C.pxl8_sfx_compressor_set_ratio(node, ratio)
|
||||
end
|
||||
|
||||
function sfx.compressor_set_release(node, release)
|
||||
C.pxl8_sfx_compressor_set_release(node, release)
|
||||
end
|
||||
|
||||
function sfx.compressor_set_threshold(node, threshold)
|
||||
C.pxl8_sfx_compressor_set_threshold(node, threshold)
|
||||
end
|
||||
|
||||
function sfx.context_append_node(ctx, node)
|
||||
C.pxl8_sfx_context_append_node(ctx, node)
|
||||
end
|
||||
|
||||
function sfx.context_create()
|
||||
return C.pxl8_sfx_context_create()
|
||||
end
|
||||
|
||||
function sfx.context_destroy(ctx)
|
||||
C.pxl8_sfx_context_destroy(ctx)
|
||||
end
|
||||
|
||||
function sfx.context_get_head(ctx)
|
||||
return C.pxl8_sfx_context_get_head(ctx)
|
||||
end
|
||||
|
||||
function sfx.context_get_volume(ctx)
|
||||
return C.pxl8_sfx_context_get_volume(ctx)
|
||||
end
|
||||
|
||||
function sfx.context_insert_node(ctx, after, node)
|
||||
C.pxl8_sfx_context_insert_node(ctx, after, node)
|
||||
end
|
||||
|
||||
function sfx.context_remove_node(ctx, node)
|
||||
C.pxl8_sfx_context_remove_node(ctx, node)
|
||||
end
|
||||
|
||||
function sfx.context_set_volume(ctx, volume)
|
||||
C.pxl8_sfx_context_set_volume(ctx, volume)
|
||||
end
|
||||
|
||||
function sfx.delay_create(opts)
|
||||
opts = opts or {}
|
||||
local cfg = ffi.new("pxl8_sfx_delay_config")
|
||||
cfg.feedback = opts.feedback or 0.4
|
||||
cfg.mix = opts.mix or 0.25
|
||||
cfg.time_l = opts.time_l or 350
|
||||
cfg.time_r = opts.time_r or 500
|
||||
return C.pxl8_sfx_delay_create(cfg)
|
||||
end
|
||||
|
||||
function sfx.delay_set_feedback(node, feedback)
|
||||
C.pxl8_sfx_delay_set_feedback(node, feedback)
|
||||
end
|
||||
|
||||
function sfx.delay_set_mix(node, mix)
|
||||
C.pxl8_sfx_delay_set_mix(node, mix)
|
||||
end
|
||||
|
||||
function sfx.delay_set_time(node, time_l, time_r)
|
||||
C.pxl8_sfx_delay_set_time(node, time_l, time_r)
|
||||
end
|
||||
|
||||
function sfx.get_master_volume()
|
||||
return C.pxl8_sfx_mixer_get_master_volume(core.sfx)
|
||||
end
|
||||
|
||||
function sfx.mixer_attach(ctx)
|
||||
C.pxl8_sfx_mixer_attach(core.sfx, ctx)
|
||||
end
|
||||
|
||||
function sfx.mixer_detach(ctx)
|
||||
C.pxl8_sfx_mixer_detach(core.sfx, ctx)
|
||||
end
|
||||
|
||||
function sfx.node_destroy(node)
|
||||
C.pxl8_sfx_node_destroy(node)
|
||||
end
|
||||
|
||||
function sfx.note_to_freq(note)
|
||||
return C.pxl8_sfx_note_to_freq(note)
|
||||
end
|
||||
|
||||
function sfx.play_note(ctx, note, params, volume, duration)
|
||||
return C.pxl8_sfx_play_note(ctx, note, params, volume or 0.8, duration or 0)
|
||||
end
|
||||
|
||||
function sfx.release_voice(ctx, voice_id)
|
||||
C.pxl8_sfx_release_voice(ctx, voice_id)
|
||||
end
|
||||
|
||||
function sfx.reverb_create(opts)
|
||||
opts = opts or {}
|
||||
local cfg = ffi.new("pxl8_sfx_reverb_config")
|
||||
cfg.damping = opts.damping or 0.5
|
||||
cfg.mix = opts.mix or 0.3
|
||||
cfg.room = opts.room or 0.5
|
||||
return C.pxl8_sfx_reverb_create(cfg)
|
||||
end
|
||||
|
||||
function sfx.reverb_set_damping(node, damping)
|
||||
C.pxl8_sfx_reverb_set_damping(node, damping)
|
||||
end
|
||||
|
||||
function sfx.reverb_set_mix(node, mix)
|
||||
C.pxl8_sfx_reverb_set_mix(node, mix)
|
||||
end
|
||||
|
||||
function sfx.reverb_set_room(node, room)
|
||||
C.pxl8_sfx_reverb_set_room(node, room)
|
||||
end
|
||||
|
||||
function sfx.set_master_volume(volume)
|
||||
C.pxl8_sfx_mixer_set_master_volume(core.sfx, volume)
|
||||
end
|
||||
|
||||
function sfx.stop_all(ctx)
|
||||
C.pxl8_sfx_stop_all(ctx)
|
||||
end
|
||||
|
||||
function sfx.stop_voice(ctx, voice_id)
|
||||
C.pxl8_sfx_stop_voice(ctx, voice_id)
|
||||
end
|
||||
|
||||
function sfx.voice_params(opts)
|
||||
opts = opts or {}
|
||||
local params = ffi.new("pxl8_sfx_voice_params")
|
||||
|
||||
params.amp_env.attack = opts.attack or 0.01
|
||||
params.amp_env.decay = opts.decay or 0.1
|
||||
params.amp_env.sustain = opts.sustain or 0.5
|
||||
params.amp_env.release = opts.release or 0.2
|
||||
|
||||
params.filter_env.attack = opts.filter_attack or 0.01
|
||||
params.filter_env.decay = opts.filter_decay or 0.1
|
||||
params.filter_env.sustain = opts.filter_sustain or 0.3
|
||||
params.filter_env.release = opts.filter_release or 0.1
|
||||
|
||||
params.filter_type = opts.filter_type or C.PXL8_SFX_FILTER_NONE
|
||||
params.lfo_target = opts.lfo_target or C.PXL8_SFX_LFO_PITCH
|
||||
params.lfo_waveform = opts.lfo_waveform or C.PXL8_SFX_WAVE_SINE
|
||||
params.waveform = opts.waveform or C.PXL8_SFX_WAVE_SINE
|
||||
|
||||
params.filter_cutoff = opts.filter_cutoff or 4000
|
||||
params.filter_env_depth = opts.filter_env_depth or 0
|
||||
params.filter_resonance = opts.filter_resonance or 0
|
||||
params.fx_send = opts.fx_send or 0
|
||||
params.lfo_depth = opts.lfo_depth or 0
|
||||
params.lfo_rate = opts.lfo_rate or 0
|
||||
params.pulse_width = opts.pulse_width or 0.5
|
||||
|
||||
return params
|
||||
end
|
||||
|
||||
return sfx
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local tilemap = {}
|
||||
|
||||
tilemap.TILE_FLIP_X = 1
|
||||
tilemap.TILE_FLIP_Y = 2
|
||||
tilemap.TILE_SOLID = 4
|
||||
tilemap.TILE_TRIGGER = 8
|
||||
|
||||
local tile_data = setmetatable({}, {__mode = "k"})
|
||||
|
||||
function tilemap.tilesheet_new(tile_size)
|
||||
return C.pxl8_tilesheet_create(tile_size or 16)
|
||||
end
|
||||
|
||||
function tilemap.tilesheet_destroy(tilesheet)
|
||||
C.pxl8_tilesheet_destroy(tilesheet)
|
||||
end
|
||||
|
||||
function tilemap.tilesheet_load(tilesheet, filepath)
|
||||
return C.pxl8_tilesheet_load(tilesheet, filepath, core.gfx)
|
||||
end
|
||||
|
||||
function tilemap.new(width, height, tile_size)
|
||||
return C.pxl8_tilemap_create(width, height, tile_size or 16)
|
||||
end
|
||||
|
||||
function tilemap.destroy(tm)
|
||||
C.pxl8_tilemap_destroy(tm)
|
||||
end
|
||||
|
||||
function tilemap.set_tilesheet(tm, tilesheet)
|
||||
return C.pxl8_tilemap_set_tilesheet(tm, tilesheet)
|
||||
end
|
||||
|
||||
function tilemap.set_tile(tm, layer, x, y, tile_id, flags)
|
||||
C.pxl8_tilemap_set_tile(tm, layer or 0, x, y, tile_id or 0, flags or 0)
|
||||
end
|
||||
|
||||
function tilemap.get_tile_id(tm, layer, x, y)
|
||||
return C.pxl8_tilemap_get_tile_id(tm, layer or 0, x, y)
|
||||
end
|
||||
|
||||
function tilemap.set_camera(tm, x, y)
|
||||
C.pxl8_tilemap_set_camera(tm, x, y)
|
||||
end
|
||||
|
||||
function tilemap.render(tm)
|
||||
C.pxl8_tilemap_render(tm, core.gfx)
|
||||
end
|
||||
|
||||
function tilemap.render_layer(tm, layer)
|
||||
C.pxl8_tilemap_render_layer(tm, core.gfx, layer)
|
||||
end
|
||||
|
||||
function tilemap.is_solid(tm, x, y)
|
||||
return C.pxl8_tilemap_is_solid(tm, x, y)
|
||||
end
|
||||
|
||||
function tilemap.check_collision(tm, x, y, w, h)
|
||||
return C.pxl8_tilemap_check_collision(tm, x, y, w, h)
|
||||
end
|
||||
|
||||
function tilemap.get_tile_data(tm, tile_id)
|
||||
if not tm or tile_id == 0 then return nil end
|
||||
if not tile_data[tm] then return nil end
|
||||
return tile_data[tm][tile_id]
|
||||
end
|
||||
|
||||
function tilemap.load_ase(tm, filepath, layer)
|
||||
return C.pxl8_tilemap_load_ase(tm, filepath, layer or 0)
|
||||
end
|
||||
|
||||
function tilemap.set_tile_data(tm, tile_id, data)
|
||||
if not tm or tile_id == 0 then return end
|
||||
if not tile_data[tm] then tile_data[tm] = {} end
|
||||
tile_data[tm][tile_id] = data
|
||||
end
|
||||
|
||||
return tilemap
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local transition = {}
|
||||
|
||||
local transition_types = {
|
||||
fade = 0,
|
||||
wipe_left = 1,
|
||||
wipe_right = 2,
|
||||
wipe_up = 3,
|
||||
wipe_down = 4,
|
||||
circle_open = 5,
|
||||
circle_close = 6,
|
||||
dissolve = 7,
|
||||
pixelate = 8
|
||||
}
|
||||
|
||||
function transition.create(type_name, duration)
|
||||
local type_id = transition_types[type_name] or 0
|
||||
return C.pxl8_transition_create(type_id, duration or 1.0)
|
||||
end
|
||||
|
||||
function transition.destroy(t)
|
||||
C.pxl8_transition_destroy(t)
|
||||
end
|
||||
|
||||
function transition.get_progress(t)
|
||||
return C.pxl8_transition_get_progress(t)
|
||||
end
|
||||
|
||||
function transition.is_active(t)
|
||||
return C.pxl8_transition_is_active(t)
|
||||
end
|
||||
|
||||
function transition.is_complete(t)
|
||||
return C.pxl8_transition_is_complete(t)
|
||||
end
|
||||
|
||||
function transition.render(t)
|
||||
C.pxl8_transition_render(t, core.gfx)
|
||||
end
|
||||
|
||||
function transition.reset(t)
|
||||
C.pxl8_transition_reset(t)
|
||||
end
|
||||
|
||||
function transition.set_color(t, color)
|
||||
C.pxl8_transition_set_color(t, color)
|
||||
end
|
||||
|
||||
function transition.set_reverse(t, reverse)
|
||||
C.pxl8_transition_set_reverse(t, reverse)
|
||||
end
|
||||
|
||||
function transition.start(t)
|
||||
C.pxl8_transition_start(t)
|
||||
end
|
||||
|
||||
function transition.stop(t)
|
||||
C.pxl8_transition_stop(t)
|
||||
end
|
||||
|
||||
function transition.update(t, dt)
|
||||
C.pxl8_transition_update(t, dt)
|
||||
end
|
||||
|
||||
return transition
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local vfx = {}
|
||||
|
||||
function vfx.raster_bars(bars, time)
|
||||
local c_bars = ffi.new("pxl8_raster_bar[?]", #bars)
|
||||
for i, bar in ipairs(bars) do
|
||||
c_bars[i-1].base_y = bar.base_y or 0
|
||||
c_bars[i-1].amplitude = bar.amplitude or 10
|
||||
c_bars[i-1].height = bar.height or 5
|
||||
c_bars[i-1].speed = bar.speed or 1.0
|
||||
c_bars[i-1].phase = bar.phase or 0
|
||||
c_bars[i-1].color = bar.color or 15
|
||||
c_bars[i-1].fade_color = bar.fade_color or bar.color or 15
|
||||
end
|
||||
C.pxl8_vfx_raster_bars(core.gfx, c_bars, #bars, time)
|
||||
end
|
||||
|
||||
function vfx.plasma(time, scale1, scale2, palette_offset)
|
||||
C.pxl8_vfx_plasma(core.gfx, time, scale1 or 0.05, scale2 or 0.03, palette_offset or 0)
|
||||
end
|
||||
|
||||
function vfx.rotozoom(angle, zoom, cx, cy)
|
||||
local width = C.pxl8_gfx_get_width(core.gfx)
|
||||
local height = C.pxl8_gfx_get_height(core.gfx)
|
||||
C.pxl8_vfx_rotozoom(core.gfx, angle, zoom, cx or width/2, cy or height/2)
|
||||
end
|
||||
|
||||
function vfx.tunnel(time, speed, twist)
|
||||
C.pxl8_vfx_tunnel(core.gfx, time, speed or 2.0, twist or 0.5)
|
||||
end
|
||||
|
||||
function vfx.explosion(ps, x, y, color, force)
|
||||
C.pxl8_vfx_explosion(ps, x, y, color or 15, force or 200.0)
|
||||
end
|
||||
|
||||
function vfx.fire(ps, x, y, width, palette_start)
|
||||
C.pxl8_vfx_fire(ps, x, y, width or 50, palette_start or 64)
|
||||
end
|
||||
|
||||
function vfx.rain(ps, width, wind)
|
||||
local w = width or C.pxl8_gfx_get_width(core.gfx)
|
||||
C.pxl8_vfx_rain(ps, w, wind or 0.0)
|
||||
end
|
||||
|
||||
function vfx.smoke(ps, x, y, color)
|
||||
C.pxl8_vfx_smoke(ps, x, y, color or 8)
|
||||
end
|
||||
|
||||
function vfx.snow(ps, width, wind)
|
||||
local w = width or C.pxl8_gfx_get_width(core.gfx)
|
||||
C.pxl8_vfx_snow(ps, w, wind or 10.0)
|
||||
end
|
||||
|
||||
function vfx.sparks(ps, x, y, color)
|
||||
C.pxl8_vfx_sparks(ps, x, y, color or 15)
|
||||
end
|
||||
|
||||
function vfx.starfield(ps, speed, spread)
|
||||
C.pxl8_vfx_starfield(ps, speed or 5.0, spread or 500.0)
|
||||
end
|
||||
|
||||
return vfx
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local core = require("pxl8.core")
|
||||
|
||||
local world = {}
|
||||
|
||||
world.PROCGEN_ROOMS = C.PXL8_PROCGEN_ROOMS
|
||||
world.PROCGEN_TERRAIN = C.PXL8_PROCGEN_TERRAIN
|
||||
|
||||
function world.new()
|
||||
return C.pxl8_world_create()
|
||||
end
|
||||
|
||||
function world.destroy(w)
|
||||
C.pxl8_world_destroy(w)
|
||||
end
|
||||
|
||||
function world.load(w, filepath)
|
||||
return C.pxl8_world_load(w, filepath)
|
||||
end
|
||||
|
||||
function world.render(w, camera_pos)
|
||||
local vec = ffi.new("pxl8_vec3", {x = camera_pos[1], y = camera_pos[2], z = camera_pos[3]})
|
||||
C.pxl8_world_render(w, core.gfx, vec)
|
||||
end
|
||||
|
||||
function world.unload(w)
|
||||
C.pxl8_world_unload(w)
|
||||
end
|
||||
|
||||
function world.is_loaded(w)
|
||||
return C.pxl8_world_is_loaded(w)
|
||||
end
|
||||
|
||||
function world.generate(w, params)
|
||||
local c_params = ffi.new("pxl8_procgen_params")
|
||||
c_params.type = params.type or C.PXL8_PROCGEN_ROOMS
|
||||
c_params.width = params.width or 32
|
||||
c_params.height = params.height or 32
|
||||
c_params.depth = params.depth or 0
|
||||
c_params.seed = params.seed or 0
|
||||
c_params.min_room_size = params.min_room_size or 5
|
||||
c_params.max_room_size = params.max_room_size or 10
|
||||
c_params.num_rooms = params.num_rooms or 8
|
||||
return C.pxl8_world_generate(w, core.gfx, c_params)
|
||||
end
|
||||
|
||||
function world.procgen_tex(params)
|
||||
local width = params.width or 64
|
||||
local height = params.height or 64
|
||||
local buffer = ffi.new("u8[?]", width * height)
|
||||
local tex_params = ffi.new("pxl8_procgen_tex_params")
|
||||
|
||||
local name = params.name or ""
|
||||
ffi.copy(tex_params.name, name, math.min(#name, 15))
|
||||
|
||||
tex_params.seed = params.seed or 0
|
||||
tex_params.width = width
|
||||
tex_params.height = height
|
||||
tex_params.scale = params.scale or 1.0
|
||||
tex_params.roughness = params.roughness or 0.0
|
||||
tex_params.base_color = params.base_color or 0
|
||||
tex_params.variation = params.variation or 0
|
||||
|
||||
C.pxl8_procgen_tex(buffer, tex_params)
|
||||
|
||||
local tex_id = C.pxl8_gfx_create_texture(core.gfx, buffer, width, height)
|
||||
if tex_id < 0 then
|
||||
return nil
|
||||
end
|
||||
return tex_id
|
||||
end
|
||||
|
||||
function world.apply_textures(w, texture_defs)
|
||||
local count = #texture_defs
|
||||
local textures = ffi.new("pxl8_world_texture[?]", count)
|
||||
|
||||
for i, def in ipairs(texture_defs) do
|
||||
local idx = i - 1
|
||||
ffi.copy(textures[idx].name, def.name or "", math.min(#(def.name or ""), 15))
|
||||
textures[idx].texture_id = def.texture_id or 0
|
||||
|
||||
if def.rule then
|
||||
textures[idx].rule = ffi.cast("bool (*)(const pxl8_vec3*, const pxl8_bsp_face*, const pxl8_bsp*)",
|
||||
function(normal, face, bsp)
|
||||
return def.rule(normal[0], face, bsp)
|
||||
end)
|
||||
else
|
||||
textures[idx].rule = nil
|
||||
end
|
||||
end
|
||||
|
||||
local result = C.pxl8_world_apply_textures(w, textures, count)
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function world.check_collision(w, x, y, z, radius)
|
||||
local pos = ffi.new("pxl8_vec3", {x = x, y = y, z = z})
|
||||
return C.pxl8_world_check_collision(w, pos, radius)
|
||||
end
|
||||
|
||||
function world.resolve_collision(w, from_x, from_y, from_z, to_x, to_y, to_z, radius)
|
||||
local from = ffi.new("pxl8_vec3", {x = from_x, y = from_y, z = from_z})
|
||||
local to = ffi.new("pxl8_vec3", {x = to_x, y = to_y, z = to_z})
|
||||
local result = C.pxl8_world_resolve_collision(w, from, to, radius)
|
||||
return result.x, result.y, result.z
|
||||
end
|
||||
|
||||
return world
|
||||
Loading…
Add table
Add a link
Reference in a new issue