Spawner for barrels

This commit is contained in:
MaddoScientisto 2024-04-26 13:31:42 +02:00
commit 2507ba301c
4 changed files with 144 additions and 97 deletions

View file

@ -70,9 +70,17 @@ function _update()
weapons_manager.update()
for b in all(actors) do
for a in all(actors) do
a:update()
end
for b in all(bullets) do
b:update()
end
for p in all(particles) do
p:update()
end
end
LAYERS = {
@ -83,6 +91,8 @@ LAYERS = {
}
actors = {}
bullets = {}
particles = {}
function _draw()
cls(0)
@ -94,8 +104,24 @@ function _draw()
end
function spawn_objects()
local b = Barrel:new(32,32)
add(actors,b)
local width = 32
local height = 32
for x=0,width,1 do
for y=0,height,1 do
local tile = map_manager.get_layer_tile(x,y,1)
if (tile == 3) then
local b = Barrel:new(x*tile_width,y*tile_height)
add(actors,b)
end
end
end
end
function render_layer(layer)
@ -114,9 +140,13 @@ function render_layer(layer)
b:draw()
end
-- for b in all(bullets) do
-- b:draw()
-- end
end
for b in all(bullets) do
b:draw()
end
for p in all(particles) do
p:draw()
end
end
end

View file

@ -38,6 +38,10 @@ function M.get_layer_tile(x,y,layer)
return get_layer_tile(x,y,layer)
end
function M.get_layer_tile(x,y,layer)
return get_layer_tile(x,y,layer)
end
-- function M.can_move(x,y)
-- return is_tile(0,x,y)
-- end

View file

@ -6,7 +6,6 @@ local Actor = require(make_path("actor2"))
M = {}
local weapons = {}
local bullets = {}
-- local particles = {}
weapon = {
@ -39,7 +38,7 @@ Particle.spriteIndex=81
function Particle:update()
self.life-=1
if self.life<=0 then
del(actors,self)
del(particles,self)
end
end
@ -47,37 +46,47 @@ end
-- spr(self.spriteIndex,self.x,self.y)
-- end
bullet = {
x=0,
y=0,
dx=0,
dy=0,
spriteIndex=80,
destroy_sprite_index=66,
life=100,
damage=1,
}
bullet.__index = bullet
function bullet:new(x, y, dx, dy)
local o = setmetatable({}, bullet)
o.x = x
o.y = y
o.dx = dx
o.dy = dy
return o
end
function bullet:destroy()
Bullet = Actor:new()
--function Bullet:new()
--
--end
Bullet.dx=0
Bullet.dy=0
Bullet.spriteIndex = 80
Bullet.damage=1
-- bullet = {
-- x=0,
-- y=0,
-- dx=0,
-- dy=0,
-- spriteIndex=80,
-- destroy_sprite_index=66,
-- life=100,
-- damage=1,
-- }
-- bullet.__index = bullet
-- function bullet:new(x, y, dx, dy)
-- local o = setmetatable({}, bullet)
-- o.x = x
-- o.y = y
-- o.dx = dx
-- o.dy = dy
-- return o
-- end
function Bullet:destroy()
-- Create particle
local p = Particle:new(self.x, self.y)
add(actors, p)
add(particles, p)
del(bullets,self)
end
function bullet:check_collision()
function Bullet:check_collision()
if (map_manager.is_tile_shoot_solid(self.x,self.y)) then
self:destroy()
@ -85,7 +94,7 @@ function bullet:check_collision()
end
function bullet:update()
function Bullet:update()
self.x+=self.dx
self.y+=self.dy
@ -97,7 +106,7 @@ function bullet:update()
self:check_collision()
end
function bullet:draw()
function Bullet:draw()
spr(self.spriteIndex,self.x,self.y)
end
@ -109,7 +118,10 @@ function M.create_bullet(new_x, new_y, dir_x, dir_y)
local normalized_dir_x = dir_x / length
local normalized_dir_y = dir_y / length
local b = bullet:new(new_x, new_y, normalized_dir_x * 2, normalized_dir_y * 2)
local b = Bullet:new(new_x, new_y, normalized_dir_x * 2, normalized_dir_y * 2)
b.dx = normalized_dir_x * 2
b.dy = normalized_dir_y * 2
add(bullets, b)
@ -151,9 +163,9 @@ function M.init()
end
function M.draw()
for b in all(bullets) do
b:draw()
end
--for b in all(bullets) do
-- b:draw()
--end
-- for p in all(particles) do
-- p:draw()
@ -161,9 +173,9 @@ function M.draw()
end
function M.update()
for b in all(bullets) do
b:update()
end
--for b in all(bullets) do
-- b:update()
--end
-- for p in all(particles) do
-- p:update()