mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-08 17:55:54 +00:00
Spawner for barrels
This commit is contained in:
parent
c390096f4f
commit
2507ba301c
4 changed files with 144 additions and 97 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue