diff options
| -rw-r--r-- | objects/Shot.lua | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/objects/Shot.lua b/objects/Shot.lua index cbadabe..e479b2a 100644 --- a/objects/Shot.lua +++ b/objects/Shot.lua @@ -70,9 +70,22 @@ function Shot:onContact(other, contact) if not self.bounced then self.bounced = 0 end if self.bounced <= data.bouncy then dieOnThisContact = false - local dx = other.x - self.x - local dy = other.y - self.y - local angle = utils.atan2(dy, dx) + + -- calculate diagonal direction + local dx = self.x - other.x + local dy = self.y - other.y + local angle + + if math.abs(dx) > math.abs(dy) then + angle = math.pi / 4 + else + angle = 3 * math.pi / 4 + end + + if math.random(2) == 1 then + angle = -angle + end + self.physicsBody:setLinearVelocity(math.cos(angle) * config.bullet.speed, math.sin(angle) * config.bullet.speed) self.bounced = self.bounced + 1 @@ -86,6 +99,7 @@ function Shot:onContact(other, contact) end end + if dieOnThisContact then self:die() end |
