refactor some things...
This commit is contained in:
parent
3550fad638
commit
1744e689b5
25 changed files with 2396 additions and 1307 deletions
117
src/lua/pxl8.lua
117
src/lua/pxl8.lua
|
|
@ -1,7 +1,7 @@
|
|||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local gfx = _pxl8_gfx_ctx
|
||||
local input = _pxl8_input_ctx
|
||||
local gfx = _pxl8_gfx
|
||||
local input = _pxl8_input
|
||||
|
||||
-- pxl8 lua api
|
||||
--
|
||||
|
|
@ -47,8 +47,12 @@ function pxl8.sprite(id, x, y, w, h, flip_x, flip_y)
|
|||
C.pxl8_sprite(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 pxl8.get_screen()
|
||||
return C.pxl8_get_screen(gfx)
|
||||
function pxl8.get_width()
|
||||
return C.pxl8_gfx_get_width(gfx)
|
||||
end
|
||||
|
||||
function pxl8.get_height()
|
||||
return C.pxl8_gfx_get_height(gfx)
|
||||
end
|
||||
|
||||
function pxl8.load_palette(filepath)
|
||||
|
|
@ -119,8 +123,7 @@ function pxl8.vfx_plasma(time, scale1, scale2, palette_offset)
|
|||
end
|
||||
|
||||
function pxl8.vfx_rotozoom(angle, zoom, cx, cy)
|
||||
local screen = pxl8.get_screen()
|
||||
C.pxl8_vfx_rotozoom(gfx, angle, zoom, cx or screen.width/2, cy or screen.height/2)
|
||||
C.pxl8_vfx_rotozoom(gfx, angle, zoom, cx or pxl8.get_width()/2, cy or pxl8.get_height()/2)
|
||||
end
|
||||
|
||||
function pxl8.vfx_tunnel(time, speed, twist)
|
||||
|
|
@ -128,29 +131,27 @@ function pxl8.vfx_tunnel(time, speed, twist)
|
|||
end
|
||||
|
||||
function pxl8.particles_new(max_count)
|
||||
local ps = ffi.new("pxl8_particle_system")
|
||||
C.pxl8_vfx_particles_init(ps, max_count or 1000)
|
||||
return ps
|
||||
return C.pxl8_particles_create(max_count or 1000)
|
||||
end
|
||||
|
||||
function pxl8.particles_destroy(ps)
|
||||
C.pxl8_vfx_particles_destroy(ps)
|
||||
C.pxl8_particles_destroy(ps)
|
||||
end
|
||||
|
||||
function pxl8.particles_clear(ps)
|
||||
C.pxl8_vfx_particles_clear(ps)
|
||||
C.pxl8_particles_clear(ps)
|
||||
end
|
||||
|
||||
function pxl8.particles_emit(ps, count)
|
||||
C.pxl8_vfx_particles_emit(ps, count or 1)
|
||||
C.pxl8_particles_emit(ps, count or 1)
|
||||
end
|
||||
|
||||
function pxl8.particles_update(ps, dt)
|
||||
C.pxl8_vfx_particles_update(ps, dt)
|
||||
C.pxl8_particles_update(ps, dt)
|
||||
end
|
||||
|
||||
function pxl8.particles_render(ps)
|
||||
C.pxl8_vfx_particles_render(ps, gfx)
|
||||
C.pxl8_particles_render(ps, gfx)
|
||||
end
|
||||
|
||||
function pxl8.vfx_explosion(ps, x, y, color, force)
|
||||
|
|
@ -162,7 +163,7 @@ function pxl8.vfx_fire(ps, x, y, width, palette_start)
|
|||
end
|
||||
|
||||
function pxl8.vfx_rain(ps, width, wind)
|
||||
C.pxl8_vfx_rain(ps, width or pxl8.get_screen().width, wind or 0.0)
|
||||
C.pxl8_vfx_rain(ps, width or pxl8.get_width(), wind or 0.0)
|
||||
end
|
||||
|
||||
function pxl8.vfx_smoke(ps, x, y, color)
|
||||
|
|
@ -170,7 +171,7 @@ function pxl8.vfx_smoke(ps, x, y, color)
|
|||
end
|
||||
|
||||
function pxl8.vfx_snow(ps, width, wind)
|
||||
C.pxl8_vfx_snow(ps, width or pxl8.get_screen().width, wind or 10.0)
|
||||
C.pxl8_vfx_snow(ps, width or pxl8.get_width(), wind or 10.0)
|
||||
end
|
||||
|
||||
function pxl8.vfx_sparks(ps, x, y, color)
|
||||
|
|
@ -190,7 +191,7 @@ function pxl8.gfx_fade_palette(start, count, amount, target_color)
|
|||
end
|
||||
|
||||
function pxl8.tilesheet_new(tile_size)
|
||||
return C.pxl8_tilesheet_new(tile_size or 16)
|
||||
return C.pxl8_tilesheet_create(tile_size or 16)
|
||||
end
|
||||
|
||||
function pxl8.tilesheet_destroy(tilesheet)
|
||||
|
|
@ -202,7 +203,7 @@ function pxl8.tilesheet_load(tilesheet, filepath)
|
|||
end
|
||||
|
||||
function pxl8.tilemap_new(width, height, tile_size)
|
||||
return C.pxl8_tilemap_new(width, height, tile_size or 16)
|
||||
return C.pxl8_tilemap_create(width, height, tile_size or 16)
|
||||
end
|
||||
|
||||
function pxl8.tilemap_destroy(tilemap)
|
||||
|
|
@ -246,6 +247,86 @@ pxl8.TILE_FLIP_Y = 2
|
|||
pxl8.TILE_SOLID = 4
|
||||
pxl8.TILE_TRIGGER = 8
|
||||
|
||||
function pxl8.clear_zbuffer()
|
||||
C.pxl8_3d_clear_zbuffer(gfx)
|
||||
end
|
||||
|
||||
function pxl8.set_model(mat)
|
||||
C.pxl8_3d_set_model(gfx, mat)
|
||||
end
|
||||
|
||||
function pxl8.set_view(mat)
|
||||
C.pxl8_3d_set_view(gfx, mat)
|
||||
end
|
||||
|
||||
function pxl8.set_projection(mat)
|
||||
C.pxl8_3d_set_projection(gfx, mat)
|
||||
end
|
||||
|
||||
function pxl8.set_wireframe(wireframe)
|
||||
C.pxl8_3d_set_wireframe(gfx, wireframe)
|
||||
end
|
||||
|
||||
function pxl8.set_backface_culling(culling)
|
||||
C.pxl8_3d_set_backface_culling(gfx, culling)
|
||||
end
|
||||
|
||||
function pxl8.draw_triangle_3d(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(gfx, vec0, vec1, vec2, color)
|
||||
end
|
||||
|
||||
function pxl8.draw_line_3d(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(gfx, vec0, vec1, color)
|
||||
end
|
||||
|
||||
function pxl8.mat4_identity()
|
||||
return C.pxl8_mat4_identity()
|
||||
end
|
||||
|
||||
function pxl8.mat4_multiply(a, b)
|
||||
return C.pxl8_mat4_multiply(a, b)
|
||||
end
|
||||
|
||||
function pxl8.mat4_translate(x, y, z)
|
||||
return C.pxl8_mat4_translate(x, y, z)
|
||||
end
|
||||
|
||||
function pxl8.mat4_rotate_x(angle)
|
||||
return C.pxl8_mat4_rotate_x(angle)
|
||||
end
|
||||
|
||||
function pxl8.mat4_rotate_y(angle)
|
||||
return C.pxl8_mat4_rotate_y(angle)
|
||||
end
|
||||
|
||||
function pxl8.mat4_rotate_z(angle)
|
||||
return C.pxl8_mat4_rotate_z(angle)
|
||||
end
|
||||
|
||||
function pxl8.mat4_scale(x, y, z)
|
||||
return C.pxl8_mat4_scale(x, y, z)
|
||||
end
|
||||
|
||||
function pxl8.mat4_ortho(left, right, bottom, top, near, far)
|
||||
return C.pxl8_mat4_ortho(left, right, bottom, top, near, far)
|
||||
end
|
||||
|
||||
function pxl8.mat4_perspective(fov, aspect, near, far)
|
||||
return C.pxl8_mat4_perspective(fov, aspect, near, far)
|
||||
end
|
||||
|
||||
function pxl8.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
|
||||
|
||||
pxl8.gfx = gfx
|
||||
pxl8.input = input
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue