weapon cooldown

This commit is contained in:
MaddoScientisto 2024-04-28 16:09:45 +02:00
commit 3057ee8725
4 changed files with 31 additions and 18 deletions

View file

@ -35,6 +35,10 @@ function Cirno:update()
self:move()
if (self.weapon != nil) then
self.weapon:update()
end
if (btn(4)) then
self.weapon:shoot(self.x+8,self.y+8,self.move_x,self.move_y)
end

View file

@ -100,6 +100,7 @@ function _update()
{"text_box",{text=string.format("%.4f %dfps",stat(1),stat(7)),margin=2,stroke=true,active=false,hover=false}},
{"text_box",{text=string.format("Bullets: %d", count(bullets)),margin=2,stroke=true,active=false,hover=false}},
{"text_box",{text=string.format("Weapon: %s", cirnoInstance.weapon.data.name),margin=2,stroke=true,active=false,hover=false}},
{"text_box",{text=string.format("Weapon timer: %d", cirnoInstance.weapon.timer),margin=2,stroke=true,active=false,hover=false}},
{"sprite_box",{sprite=cirnoInstance.weapon.data.spriteIndex,margin=2,stroke=true,active=false,hover=false}},
}})

View file

@ -17,7 +17,7 @@ local bullets_list = {
local weapons_list = {
ICE_BLASTER={
name = "Ice Blaster",
rate_of_fire = 0.2,
rate_of_fire = 8,
bullet=bullets_list.BASIC,
spriteIndex=104,
--shoot=function(self,x,y,dir_x,dir_y)
@ -26,7 +26,7 @@ local weapons_list = {
},
SPAGHETTI={
name = "Spaghetti",
rate_of_fire = 0.2,
rate_of_fire = 80,
bullet=bullets_list.BASIC,
spriteIndex=105,
}
@ -51,8 +51,16 @@ function Weapon:new(data)
end
function Weapon:shoot(x,y,dir_x,dir_y)
create_bullet(self.data.bullet, x, y, dir_x, dir_y)
if (self.timer >= self.data.rate_of_fire) then
self.timer = 0
create_bullet(self.data.bullet, x, y, dir_x, dir_y)
end
end
function Weapon:update()
if (self.timer < self.data.rate_of_fire) then
self.timer+=1
end
end
-- Particle