Converted particles to actors

This commit is contained in:
MaddoScientisto 2024-04-26 11:30:53 +02:00
commit c390096f4f
2 changed files with 39 additions and 30 deletions

View file

@ -69,6 +69,10 @@ function _update()
cirno.update() cirno.update()
weapons_manager.update() weapons_manager.update()
for b in all(actors) do
b:update()
end
end end
LAYERS = { LAYERS = {

View file

@ -1,12 +1,13 @@
--[[pod_format="raw",created="2024-04-24 07:17:14",modified="2024-04-24 20:33:05",revision=11]] --[[pod_format="raw",created="2024-04-24 07:17:14",modified="2024-04-24 20:33:05",revision=11]]
local map_manager = require(make_path("map")) local map_manager = require(make_path("map"))
local Actor = require(make_path("actor2"))
--local actor = require("actor2") --local actor = require("actor2")
M = {} M = {}
local weapons = {} local weapons = {}
local bullets = {} local bullets = {}
local particles = {} -- local particles = {}
weapon = { weapon = {
name = "Ice Blaster", name = "Ice Blaster",
@ -17,30 +18,34 @@ weapon = {
} }
particle = { Particle = Actor:new()
x=0, Particle.life=4
y=0, Particle.spriteIndex=81
life=4,
spriteIndex=81
}
particle.__index = particle
function particle:new(x,y)
local o = setmetatable({}, particle)
o.x=x
o.y=y
return o
end
function particle:update() -- particle = {
-- x=0,
-- y=0,
-- life=4,
-- spriteIndex=81
-- }
--particle.__index = particle
-- function Particle:new(x,y)
-- local o = setmetatable({}, particle)
-- o.x=x
-- o.y=y
-- return o
-- end
function Particle:update()
self.life-=1 self.life-=1
if self.life<0 then if self.life<=0 then
del(particles,self) del(actors,self)
end end
end end
function particle:draw() -- function Particle:draw()
spr(self.spriteIndex,self.x,self.y) -- spr(self.spriteIndex,self.x,self.y)
end -- end
bullet = { bullet = {
x=0, x=0,
@ -65,9 +70,9 @@ end
function bullet:destroy() function bullet:destroy()
-- Create particle -- Create particle
local p = particle:new(self.x, self.y) local p = Particle:new(self.x, self.y)
add(particles, p) add(actors, p)
del(bullets,self) del(bullets,self)
end end
@ -150,9 +155,9 @@ function M.draw()
b:draw() b:draw()
end end
for p in all(particles) do -- for p in all(particles) do
p:draw() -- p:draw()
end -- end
end end
function M.update() function M.update()
@ -160,13 +165,13 @@ function M.update()
b:update() b:update()
end end
for p in all(particles) do -- for p in all(particles) do
p:update() -- p:update()
end -- end
end end
function M.debug_draw() function M.debug_draw()
print(string.format("Bullets: %d Particles: %d", count(bullets), count(particles)), 0,32,1) print(string.format("Bullets: %d", count(bullets)), 0,32,1)
end end
return M return M