From 78130a3310d27f4b882f7b9055195876ede1a47d Mon Sep 17 00:00:00 2001 From: Deadzi06 Date: Sun, 9 Aug 2026 19:50:33 +0200 Subject: [PATCH] stackinghats fini et horizontalhats pattern --- scripts/battle/bullets/hatbulllet.lua | 10 +++-- scripts/battle/waves/horizontalhats.lua | 57 +++++++++++++++++++++++++ scripts/battle/waves/stackinghats.lua | 41 ++++++++++-------- 3 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 scripts/battle/waves/horizontalhats.lua diff --git a/scripts/battle/bullets/hatbulllet.lua b/scripts/battle/bullets/hatbulllet.lua index 81eb8f9..2cc89d9 100644 --- a/scripts/battle/bullets/hatbulllet.lua +++ b/scripts/battle/bullets/hatbulllet.lua @@ -13,9 +13,8 @@ function HatBullet:init(x, y, dir, speed) self.physics.direction = dir -- Speed the bullet moves (pixels per frame at 30FPS) self.physics.speed = speed - self.collision = false - - + self.collider = Hitbox(self, self.width*0.225, self.height*0.25, self.width*0.55, self.height*0.6) + self.destroy_on_hit = false end function HatBullet:update() @@ -24,4 +23,9 @@ function HatBullet:update() super.update(self) end +function HatBullet:getDebugInfo() + local info = super.getDebugInfo(self) + table.insert(info, "Collider: " .. self.collider.x, self.collider.y) +end + return HatBullet diff --git a/scripts/battle/waves/horizontalhats.lua b/scripts/battle/waves/horizontalhats.lua new file mode 100644 index 0000000..0f62694 --- /dev/null +++ b/scripts/battle/waves/horizontalhats.lua @@ -0,0 +1,57 @@ +local HorizontalHats, super = Class(Wave) + + + +function HorizontalHats:init() + super.init(self) + + -- The duration of our wave, in seconds. (Defaults to `5`) + self.time = 7 + self.count = 0 +end + +function HorizontalHats:onStart() + -- code here gets called at the start of the wave + -- create a bullet in the center of the screen + arena = Game.battle.arena + local x_positions = {arena.x - SCREEN_WIDTH/3.3, arena.x + SCREEN_WIDTH/3.3, arena.x - SCREEN_WIDTH/3.3} + local y_positions = {arena.y*0.73, arena.y*1, arena.y*1.25} + self.collider1 = LineCollider(self, x_positions[2] + 10, y_positions[1], x_positions[2] + 10, y_positions[3]) + self.collider2 = LineCollider(self, x_positions[1] - 10, y_positions[1], x_positions[1] - 10, y_positions[3]) + self.colliderGroup = ColliderGroup(self, {self.collider1, self.collider2}) + for i = 1, 3, 1 do + local x = x_positions[i] + local y = y_positions[i] + self.bullets[i] = self:spawnBullet("hatbulllet", x, y, 0, 6.7) + self.bullets[i]:setScale(2.2) + if (i == 1 or i == 3) then + self.bullets[i].physics.direction = math.rad(0) + else + self.bullets[i].physics.direction = math.rad(180) + end + end + super.onStart(self) +end + +function HorizontalHats:update() + -- code here gets called every frame + for i = 1, 3, 1 do + if (self.bullets[i]) then + if (self.bullets[i].collider:collidesWith(self.collider1) or self.bullets[i].collider:collidesWith(self.collider2)) then + self.bullets[i].physics.direction = self.bullets[i].physics.direction + math.rad(180) + end + end + end + super.update(self) +end + +function HorizontalHats:draw() + super.draw(self) + if DEBUG_RENDER then + if (self.colliderGroup) then + self.colliderGroup:draw(0,1,0,1) + end + end +end + +return HorizontalHats \ No newline at end of file diff --git a/scripts/battle/waves/stackinghats.lua b/scripts/battle/waves/stackinghats.lua index baec4bd..9ef5a07 100644 --- a/scripts/battle/waves/stackinghats.lua +++ b/scripts/battle/waves/stackinghats.lua @@ -2,11 +2,9 @@ local StackingHats, super = Class(Wave) function StackingHats:init() super.init(self) - -- The duration of our wave, in seconds. (Defaults to `5`) - self.time = 10 - self.count = 0 - + self.time = 8 + self.count = 1 end function StackingHats:onStart() @@ -16,35 +14,42 @@ function StackingHats:onStart() arenaX, arenaY = arena:getBottomLeft() arenaX2, arenaY2 = arena:getBottomRight() self.collider = LineCollider(self, arenaX, arenaY, arenaX2, arenaY2) - self.timer:everyInstant(1, function() - - local x = SCREEN_WIDTH / 2 + 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) - -- set the bullet's speed to 4 (pixels per 1/30th second) - self.bullets[self.count].physics.speed = 4 + 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 = 0, self.count -1, 1 do - for j = 0, i-1, 1 do - if (i ~= j) then + 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 - end - if (self.bullets[i].collider:collidesWith(self)) then - self.bullets[i].physics.speed = 0 + 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 \ No newline at end of file