Sprites and bullets list

This commit is contained in:
MaddoScientisto 2024-04-28 11:37:55 +02:00
commit 933f240bb0
2 changed files with 121 additions and 92 deletions

View file

@ -5,11 +5,22 @@ local Actor = require(make_path("actor2"))
M = {}
local weapons = {
{
local bullets_list = {
BASIC={
spriteIndex=80,
damage=1,
speed=2,
life=100
}
}
local weapons_list = {
ICE_BLASTER={
name = "Ice Blaster",
rate_of_fire = 0.2,
shoot=function(self)
bullet=bullets_list.BASIC,
spriteIndex=104,
shoot=function(self,x,y,dir_x,dir_y)
end
}
@ -38,14 +49,19 @@ Bullet = Actor:new()
--end
--Bullet.dx=0
--Bullet.dy=0
Bullet.spriteIndex = 80
Bullet.damage=1
--Bullet.spriteIndex = 80
--Bullet.damage=1
function Bullet:new(x,y,dir_x,dir_y)
function Bullet:new(bullet_data,x,y,dir_x,dir_y)
local obj = Actor:new(x,y)
obj.dx = dir_x
obj.dy = dir_y
obj.spriteIndex = bullet_data.spriteIndex
obj.damage = bullet_data.damage
obj.life = bullet_data.life
obj.speed = bullet_data.speed
obj.dx = dir_x * obj.speed
obj.dy = dir_y * obj.speed
-- 'obj' has 'Actor' as a prototype at the moment
-- which isn't what we want so we just change it.
@ -86,7 +102,7 @@ function Bullet:draw()
spr(self.spriteIndex,self.x,self.y)
end
function M.create_bullet(new_x, new_y, dir_x, dir_y)
function 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)
@ -94,7 +110,7 @@ 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(bullets_list.BASIC, new_x, new_y, normalized_dir_x, normalized_dir_y)
--b.dx = normalized_dir_x * 2
--b.dy = normalized_dir_y * 2
@ -103,6 +119,18 @@ function M.create_bullet(new_x, new_y, dir_x, dir_y)
end
function M.create_bullet(new_x, new_y, dir_x, dir_y)
return create_bullet(new_x,new_y,dir_x,dir_y)
end
function M.get_weapons()
return weapons_list
end
function M.get_bullets()
return bullets_list
end
function M.init()
end