2024-04-24 22:53:04 +02:00
|
|
|
--[[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"))
|
2024-04-26 11:30:53 +02:00
|
|
|
local Actor = require(make_path("actor2"))
|
2024-04-25 23:07:49 +02:00
|
|
|
--local actor = require("actor2")
|
2024-04-24 22:53:04 +02:00
|
|
|
|
2024-04-24 11:11:16 +02:00
|
|
|
M = {}
|
|
|
|
|
|
|
|
|
|
local weapons = {}
|
2024-04-26 11:30:53 +02:00
|
|
|
-- local particles = {}
|
2024-04-24 11:11:16 +02:00
|
|
|
|
|
|
|
|
weapon = {
|
|
|
|
|
name = "Ice Blaster",
|
|
|
|
|
rate_of_fire = 0.2,
|
|
|
|
|
shoot=function(self)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 11:30:53 +02:00
|
|
|
Particle = Actor:new()
|
|
|
|
|
Particle.life=4
|
|
|
|
|
Particle.spriteIndex=81
|
|
|
|
|
|
|
|
|
|
function Particle:update()
|
2024-04-24 22:53:04 +02:00
|
|
|
self.life-=1
|
2024-04-26 11:30:53 +02:00
|
|
|
if self.life<=0 then
|
2024-04-26 13:31:42 +02:00
|
|
|
del(particles,self)
|
2024-04-24 22:53:04 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-26 11:30:53 +02:00
|
|
|
-- function Particle:draw()
|
|
|
|
|
-- spr(self.spriteIndex,self.x,self.y)
|
|
|
|
|
-- end
|
2024-04-24 22:53:04 +02:00
|
|
|
|
2024-04-24 17:06:19 +02:00
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
Bullet = Actor:new()
|
|
|
|
|
--function Bullet:new()
|
|
|
|
|
--
|
|
|
|
|
--end
|
2024-04-26 15:28:39 +02:00
|
|
|
--Bullet.dx=0
|
|
|
|
|
--Bullet.dy=0
|
2024-04-26 13:31:42 +02:00
|
|
|
Bullet.spriteIndex = 80
|
|
|
|
|
Bullet.damage=1
|
|
|
|
|
|
2024-04-26 15:28:39 +02:00
|
|
|
function Bullet:new(x,y,dir_x,dir_y)
|
|
|
|
|
local obj = Actor:new(x,y)
|
|
|
|
|
|
|
|
|
|
obj.dx = dir_x
|
|
|
|
|
obj.dy = dir_y
|
|
|
|
|
|
|
|
|
|
-- 'obj' has 'Actor' as a prototype at the moment
|
|
|
|
|
-- which isn't what we want so we just change it.
|
|
|
|
|
return setmetatable(obj, {__index=self})
|
|
|
|
|
end
|
2024-04-26 13:31:42 +02:00
|
|
|
|
|
|
|
|
function Bullet:destroy()
|
2024-04-24 22:53:04 +02:00
|
|
|
|
|
|
|
|
-- Create particle
|
2024-04-26 11:30:53 +02:00
|
|
|
local p = Particle:new(self.x, self.y)
|
2024-04-24 22:53:04 +02:00
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
add(particles, p)
|
2024-04-24 22:53:04 +02:00
|
|
|
|
|
|
|
|
del(bullets,self)
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
function Bullet:check_collision()
|
2024-04-24 22:53:04 +02:00
|
|
|
|
|
|
|
|
if (map_manager.is_tile_shoot_solid(self.x,self.y)) then
|
|
|
|
|
self:destroy()
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-24 17:06:19 +02:00
|
|
|
end
|
|
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
function Bullet:update()
|
2024-04-24 17:06:19 +02:00
|
|
|
self.x+=self.dx
|
|
|
|
|
self.y+=self.dy
|
|
|
|
|
|
|
|
|
|
self.life-=1
|
|
|
|
|
if self.life<0 then
|
2024-04-24 22:53:04 +02:00
|
|
|
self:destroy()
|
|
|
|
|
end
|
2024-04-24 17:06:19 +02:00
|
|
|
|
2024-04-24 22:53:04 +02:00
|
|
|
self:check_collision()
|
2024-04-24 17:06:19 +02:00
|
|
|
end
|
|
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
function Bullet:draw()
|
2024-04-24 17:06:19 +02:00
|
|
|
spr(self.spriteIndex,self.x,self.y)
|
|
|
|
|
end
|
2024-04-24 11:11:16 +02:00
|
|
|
|
|
|
|
|
function M.create_bullet(new_x, new_y, dir_x, dir_y)
|
|
|
|
|
-- Calculate the length of the direction vector
|
|
|
|
|
local length = sqrt(dir_x^2 + dir_y^2)
|
|
|
|
|
|
|
|
|
|
-- Normalize the direction vector
|
|
|
|
|
local normalized_dir_x = dir_x / length
|
|
|
|
|
local normalized_dir_y = dir_y / length
|
|
|
|
|
|
2024-04-26 13:31:42 +02:00
|
|
|
local b = Bullet:new(new_x, new_y, normalized_dir_x * 2, normalized_dir_y * 2)
|
2024-04-26 15:31:08 +02:00
|
|
|
--b.dx = normalized_dir_x * 2
|
|
|
|
|
--b.dy = normalized_dir_y * 2
|
2024-04-26 13:31:42 +02:00
|
|
|
|
2024-04-24 17:06:19 +02:00
|
|
|
|
|
|
|
|
add(bullets, b)
|
|
|
|
|
|
2024-04-24 11:11:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.init()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.draw()
|
2024-04-26 13:31:42 +02:00
|
|
|
--for b in all(bullets) do
|
|
|
|
|
-- b:draw()
|
|
|
|
|
--end
|
2024-04-24 22:53:04 +02:00
|
|
|
|
2024-04-26 11:30:53 +02:00
|
|
|
-- for p in all(particles) do
|
|
|
|
|
-- p:draw()
|
|
|
|
|
-- end
|
2024-04-24 11:11:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.update()
|
2024-04-26 13:31:42 +02:00
|
|
|
--for b in all(bullets) do
|
|
|
|
|
-- b:update()
|
|
|
|
|
--end
|
2024-04-24 22:53:04 +02:00
|
|
|
|
2024-04-26 11:30:53 +02:00
|
|
|
-- for p in all(particles) do
|
|
|
|
|
-- p:update()
|
|
|
|
|
-- end
|
2024-04-24 11:11:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.debug_draw()
|
2024-04-26 11:30:53 +02:00
|
|
|
print(string.format("Bullets: %d", count(bullets)), 0,32,1)
|
2024-04-24 11:11:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|