Bullet particles

This commit is contained in:
MaddoScientisto 2024-04-24 22:53:04 +02:00
commit cd9ec6cc01
4 changed files with 113 additions and 80 deletions

View file

@ -1,8 +1,11 @@
--[[pod_format="raw",created="2024-04-24 07:17:14",modified="2024-04-24 08:16:10",revision=9]]
--[[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"))
M = {}
local weapons = {}
local bullets = {}
local particles = {}
weapon = {
name = "Ice Blaster",
@ -13,6 +16,31 @@ 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
function particle:update()
self.life-=1
if self.life<0 then
del(particles,self)
end
end
function particle:draw()
spr(self.spriteIndex,self.x,self.y)
end
bullet = {
x=0,
y=0,
@ -22,26 +50,6 @@ bullet = {
destroy_sprite_index=66,
life=100,
damage=1,
-- draw=function(self)
-- --pset(self.x,self.y,8)
-- spr(self.spriteIndex,self.x,self.y)
-- end,
-- update=function(self)
-- self.x+=self.dx
-- self.y+=self.dy
-- self.life-=1
-- if self.life<0 then
-- del(bullets,self)
-- -- TODO: Create particle
-- end
-- self.check_collision(self)
-- end,
-- check_collision=function(self)
-- -- If Collide with wall destroy self and create particle
-- end
}
bullet.__index = bullet
function bullet:new(x, y, dx, dy)
@ -50,15 +58,25 @@ function bullet:new(x, y, dx, dy)
o.y = y
o.dx = dx
o.dy = dy
--o.life = 100
--o.spriteIndex = 80
--o.destroy_sprite_index = 66
--o.damage = 1
return o
end
function bullet:destroy()
-- Create particle
local p = particle:new(self.x, self.y)
add(particles, p)
del(bullets,self)
end
function bullet:check_collision()
--
if (map_manager.is_tile_shoot_solid(self.x,self.y)) then
self:destroy()
end
end
function bullet:update()
@ -67,11 +85,10 @@ function bullet:update()
self.life-=1
if self.life<0 then
del(bullets,self)
-- TODO: Create particle
end
self:destroy()
end
self.check_collision()
self:check_collision()
end
function bullet:draw()
@ -131,16 +148,24 @@ function M.draw()
for b in all(bullets) do
b:draw()
end
for p in all(particles) do
p:draw()
end
end
function M.update()
for b in all(bullets) do
b:update()
end
for p in all(particles) do
p:update()
end
end
function M.debug_draw()
print(string.format("Bullets: %d", count(bullets)), 0,32,1)
print(string.format("Bullets: %d Particles: %d", count(bullets), count(particles)), 0,32,1)
end
return M