Files
Jamaique/scripts/battle/waves/stackinghats.lua
2026-08-09 19:50:33 +02:00

55 lines
1.6 KiB
Lua

local StackingHats, super = Class(Wave)
function StackingHats:init()
super.init(self)
-- The duration of our wave, in seconds. (Defaults to `5`)
self.time = 8
self.count = 1
end
function StackingHats:onStart()
-- code here gets called at the start of the wave
-- create a bullet in the center of the screen
arena = Game.battle.arena
arenaX, arenaY = arena:getBottomLeft()
arenaX2, arenaY2 = arena:getBottomRight()
self.collider = LineCollider(self, arenaX, arenaY, arenaX2, arenaY2)
local collumn = {SCREEN_WIDTH/2*0.87, SCREEN_WIDTH/2, SCREEN_WIDTH/2*1.13}
local speed = 5
self.timer:everyInstant(0.75, function()
local x = collumn[math.random(3)]
local y = arena:getTop() * 0.5
self.bullets[self.count] = self:spawnBullet("hatbulllet", x, y, math.rad(90), speed)
self.count = self.count + 1
speed = speed * 1.029
end)
super.onStart(self)
end
function StackingHats:update()
-- code here gets called every frame
for i = 1, self.count, 1 do
if (self.bullets[i]) then
for j = 1, i-1, 1 do
if (self.bullets[i].collider:collidesWith(self.bullets[j])) then
self.bullets[i].physics.speed = 0
end
end
if (self.bullets[i].collider:collidesWith(self)) then
self.bullets[i].physics.speed = 0
end
end
end
super.update(self)
end
function StackingHats:draw()
super.draw(self)
if DEBUG_RENDER then
if (self.collider) then
self.collider:draw(0,1,0,1)
end
end
end
return StackingHats