From 789fa0adda0b58b421ee4481d1166f20bb8ac289 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Nov 2021 12:50:27 +0100 Subject: [PATCH] fix: make weapons not collide with their creator --- .../birb/modules/world/actors/mixins/physics.lua | 9 +++++++++ .../modules/subgames/world/actors/player/weapons.lua | 2 +- .../modules/subgames/world/actors/weapons/parent.lua | 11 +++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sonic-bluestreak.love/birb/modules/world/actors/mixins/physics.lua b/sonic-bluestreak.love/birb/modules/world/actors/mixins/physics.lua index 027fc3c..a0c1ea9 100644 --- a/sonic-bluestreak.love/birb/modules/world/actors/mixins/physics.lua +++ b/sonic-bluestreak.love/birb/modules/world/actors/mixins/physics.lua @@ -21,6 +21,8 @@ function PhysicalActor:initPhysics(hitboxObj, isSolid) self:setBounceFactor() self:setFilter() + self.ignoreList = {} + self:addUpdateFunction(self.autoMove) end @@ -28,12 +30,19 @@ function PhysicalActor:setBounceFactor(newBounceFactor) self.bounceFactor = newBounceFactor or 0 end +function PhysicalActor:ignore(item) + assert(item.creationID ~= nil, "creationID shouldn't be nil") + table.insert(self.ignoreList, item.creationID) +end + function PhysicalActor:setFilter() -- Init the bump filter self.filter = function(item, other) if (other.owner == self) then -- ignore every collision with our own hitboxes return nil + elseif (utils.table.contain(self.ignoreList, other.owner.creationID)) then + return nil elseif (other.isSolid) then return "slide" else diff --git a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua index 5561d33..7372826 100644 --- a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua +++ b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua @@ -18,7 +18,7 @@ function WeaponManager:shoot(x, y, z, dir) local weaponData = weaponList[self.currentWeapon] for i,coord in ipairs(weaponData.launch) do - self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData) + self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData, self.player) end end diff --git a/sonic-bluestreak.love/game/modules/subgames/world/actors/weapons/parent.lua b/sonic-bluestreak.love/game/modules/subgames/world/actors/weapons/parent.lua index de10a1d..6eb1bfe 100644 --- a/sonic-bluestreak.love/game/modules/subgames/world/actors/weapons/parent.lua +++ b/sonic-bluestreak.love/game/modules/subgames/world/actors/weapons/parent.lua @@ -1,7 +1,7 @@ local Parent = require "game.modules.subgames.world.actors.parent" local WeaponShot = Parent:extend() -function WeaponShot:new(world, x, y, z, direction, data) +function WeaponShot:new(world, x, y, z, direction, data, creator) WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false) self:setSprite("ringweapon", 0, 0) self.direction = direction @@ -12,14 +12,13 @@ function WeaponShot:new(world, x, y, z, direction, data) if (self.zsp ~= 0) then self:setGravity(480*2) end - print(self.xsp) + self:ignore(creator) end function WeaponShot:updateStart(dt) - print(self.xsp) - -- if (self.xsp == 0) then - -- self:destroy() - -- end + if (self.xsp == 0) then + self:destroy() + end end function WeaponShot:draw()