aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorne_mene <[email protected]>2026-03-27 00:25:03 +0100
committerne_mene <[email protected]>2026-03-27 00:25:03 +0100
commit1bccbcf63fa304af2240a55e5fe51056a245d7d7 (patch)
treece3ed5d703e4f73651e259449a9947ce97d6a10e
parente020b7c2041ed7e04194c02dc19eb9a95af2edce (diff)
parent34535e47d69c3dabf0c3ec4c6434ae9bc99c618d (diff)
Merge remote-tracking branch 'refs/remotes/origin/main'
merj
-rw-r--r--src/objs/player.lua37
-rw-r--r--src/objs/specks.lua92
-rw-r--r--src/utils.lua4
-rw-r--r--test.speck.lua1
4 files changed, 96 insertions, 38 deletions
diff --git a/src/objs/player.lua b/src/objs/player.lua
index 0ce14e2..4a51eae 100644
--- a/src/objs/player.lua
+++ b/src/objs/player.lua
@@ -89,6 +89,9 @@ function player_update_sys(player, dt)
if player.box:touching_down() then
player.grounded_timer = COYOTE
end
+ if love.keyboard.isDown("k") then
+ export_speck_sys(player.speck_sys, "test.speck.lua")
+ end
end
function new_player(x, y)
@@ -96,23 +99,25 @@ function new_player(x, y)
add_comp(ent, "Player")
add_comp(ent, "Speck_System")
- ent.speck_sys.interval = 0.05
-
- ent.speck_sys.spawn_amount_max = 10
-
- ent.speck_sys.lifetime_max = 0.6
- ent.speck_sys.lifetime_min = 0.3
-
- ent.speck_sys.initial_velx = 100
- ent.speck_sys.initial_vely = 0
- ent.speck_sys.spread = 360
-
- ent.speck_sys.forcey = 1000
- ent.speck_sys.bounce = true
+ -- ent.speck_sys.interval = 0.05
+ --
+ -- ent.speck_sys.spawn_amount_max = 10
+ --
+ -- ent.speck_sys.lifetime_max = 0.6
+ -- ent.speck_sys.lifetime_min = 0.3
+ --
+ -- ent.speck_sys.initial_velx = 100
+ -- ent.speck_sys.initial_vely = 0
+ -- ent.speck_sys.spread = 360
+ --
+ -- ent.speck_sys.forcey = 1000
+ -- ent.speck_sys.bounce = true
+ --
+ -- ent.speck_sys.spawn_shape = "Rectangle"
+ -- ent.speck_sys.spawn_width = 100
+ -- ent.speck_sys.spawn_height = 100
- ent.speck_sys.spawn_shape = speck_shape_rectangle
- ent.speck_sys.spawn_width = 100
- ent.speck_sys.spawn_height = 100
+ ent.speck_sys = load_speck_sys("test.speck.lua")
add_comp(ent, "Body", x, y, 8, 14, {
offsetx = -4,
diff --git a/src/objs/specks.lua b/src/objs/specks.lua
index 5044c9c..75e3a77 100644
--- a/src/objs/specks.lua
+++ b/src/objs/specks.lua
@@ -1,23 +1,28 @@
Speck_Sys = {}
Speck_Sys.__index = Speck_Sys
-function speck_shape_rectangle(speck_sys)
- local w = (speck_sys.spawn_width or 0) / 2
- local h = (speck_sys.spawn_height or 0) / 2
- return randf_range(-w, w), randf_range(-h, h)
-end
-function speck_shape_point(speck_sys)
- return 0, 0
-end
-function speck_shape_circle(speck_sys)
- local angle = randf_range(0, math.pi * 2)
- local r = speck_sys.spawn_radius or 0
- r = r * lmath.random()
- return r*math.cos(angle), r*math.sin(angle)
-end
+local SPAWN_FUNCTIONS = {
+ Rectangle = function (speck_sys)
+ local w = (speck_sys.spawn_width or 0) / 2
+ local h = (speck_sys.spawn_height or 0) / 2
+
+ return randf_range(-w, w), randf_range(-h, h)
+ end,
+
+ Circle = function (speck_sys)
+ local angle = randf_range(0, math.pi * 2)
+ local r = speck_sys.spawn_radius or 0
+ r = r * lmath.random()
+ return r*math.cos(angle), r*math.sin(angle)
+ end,
+
+ Point = function (speck_sys)
+ return 0, 0
+ end
+}
function Speck_Sys.new()
local self = setmetatable({}, Speck_Sys)
@@ -38,12 +43,12 @@ function Speck_Sys.new()
self.free_ids = {}
self.free_ids_size = 0
- self.spawn_shape = speck_shape_point
+ self.spawn_shape = "Point"
self.spawn_amount_min = 1
self.spawn_amount_max = 1
- self.scale_curve = lerp
+ self.scale_curve = "Lerp"
self.scale_start_min = 0.8
self.scale_start_max = 1.25
@@ -61,12 +66,12 @@ function Speck_Sys.new()
self.lifetime_max = 5
self.interval = 0.1
- self.spawn_timer = self.interval
- self.texture = get_tex("res/img/speck.png")
+ self.texture_path = "res/img/speck.png"
self.x = 0
self.y = 0
+ self.spawn_timer = self.interval
return self
end
@@ -83,10 +88,12 @@ function Speck_Sys:check_bounce(i)
to_tile_coords(self.data.pos[i].x, self.data.pos[i].y))
end
+
function Speck_Sys:spawn_particles()
local data = self.data
local amt = lmath.random(self.spawn_amount_min, self.spawn_amount_max)
+ local shape_func = SPAWN_FUNCTIONS[self.spawn_shape]
for i = 1, amt do
local id
if self.free_ids_size > 0 then
@@ -99,7 +106,7 @@ function Speck_Sys:spawn_particles()
data.alive[id] = true
- local offx, offy = self.spawn_shape(self)
+ local offx, offy = shape_func(self)
data.pos[id] = { x = self.x + offx, y = self.y + offy }
data.vel[id] = { x = self.initial_velx, y = self.initial_vely }
@@ -173,8 +180,9 @@ function Speck_Sys:update(dt)
end
function Speck_Sys:draw()
- local scale_curve = self.scale_curve
+ local scale_curve = EASING_FUNCTIONS[self.scale_curve]
local data = self.data
+ local tex = get_tex(self.texture_path)
for i = 1, data.size do
if not data.alive[i] then
@@ -184,10 +192,10 @@ function Speck_Sys:draw()
local anim = 1 - data.lifetime[i] / data.lifetime_max[i]
local scale = scale_curve(data.scale_start[i], data.scale_end[i], anim)
- local w, h = self.texture:getDimensions()
+ local w, h = tex:getDimensions()
lg.draw(
- self.texture, data.pos[i].x, data.pos[i].y, 0, scale, scale, w / 2, h / 2
+ tex, data.pos[i].x, data.pos[i].y, 0, scale, scale, w / 2, h / 2
)
::next_speck_draw::
end
@@ -207,3 +215,43 @@ end
function speck_draw_sys(ent)
ent.speck_sys:draw()
end
+
+function export_speck_sys(sys, filename)
+ local EXPORTED_ARGS = {
+ "spawn_shape",
+ "spawn_amount_min",
+ "spawn_amount_max",
+ "spawn_width",
+ "spawn_height",
+ "spawn_radius",
+ "scale_curve",
+ "scale_start_min",
+ "scale_start_max",
+ "scale_end_min",
+ "scale_end_max",
+ "forcex",
+ "forcey",
+ "initial_velx",
+ "initial_vely",
+ "spread",
+ "lifetime_min",
+ "lifetime_max",
+ "interval",
+ "texture_path"
+ }
+ local exp = {}
+
+ for i, arg in ipairs(EXPORTED_ARGS) do
+ exp[arg] = sys[arg]
+ end
+ export_to_source(exp, filename)
+end
+
+function load_speck_sys(filename)
+ local sys = Speck_Sys.new()
+ local loaded = lf.load(filename)()
+ for key, data in pairs(loaded) do
+ sys[key] = data
+ end
+ return sys
+end
diff --git a/src/utils.lua b/src/utils.lua
index 56479b8..1f388cc 100644
--- a/src/utils.lua
+++ b/src/utils.lua
@@ -105,3 +105,7 @@ function table.shallow_copy(t)
end
return t2
end
+
+EASING_FUNCTIONS = {
+ Lerp = lerp
+}
diff --git a/test.speck.lua b/test.speck.lua
new file mode 100644
index 0000000..6021d0f
--- /dev/null
+++ b/test.speck.lua
@@ -0,0 +1 @@
+return {["forcey"]=1000,["spawn_shape"]="Rectangle",["spawn_width"]=100,["spawn_height"]=100,["texture_path"]="res/img/speck.png",["interval"]=0.05,["lifetime_max"]=0.6,["spawn_amount_max"]=10,["forcex"]=0,["scale_end_max"]=0,["scale_end_min"]=0,["spawn_amount_min"]=1,["scale_curve"]="Lerp",["scale_start_min"]=0.8,["scale_start_max"]=1.25,["lifetime_min"]=0.3,["initial_velx"]=100,["initial_vely"]=0,["spread"]=360,} \ No newline at end of file