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

@ -1,12 +1,13 @@
--[[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 Actor = require(make_path("actor2"))
--local actor = require("actor2")
M = {}
local weapons = {}
local bullets = {}
local particles = {}
-- local particles = {}
weapon = {
name = "Ice Blaster",
@ -17,30 +18,34 @@ weapon = {
}
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
Particle = Actor:new()
Particle.life=4
Particle.spriteIndex=81
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
if self.life<0 then
del(particles,self)
if self.life<=0 then
del(actors,self)
end
end
function particle:draw()
spr(self.spriteIndex,self.x,self.y)
end
-- function Particle:draw()
-- spr(self.spriteIndex,self.x,self.y)
-- end
bullet = {
x=0,
@ -65,9 +70,9 @@ end
function bullet:destroy()
-- 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)
end
@ -150,9 +155,9 @@ function M.draw()
b:draw()
end
for p in all(particles) do
p:draw()
end
-- for p in all(particles) do
-- p:draw()
-- end
end
function M.update()
@ -160,13 +165,13 @@ function M.update()
b:update()
end
for p in all(particles) do
p:update()
end
-- for p in all(particles) do
-- p:update()
-- end
end
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
return M