diff options
Diffstat (limited to 'objects')
| -rw-r--r-- | objects/Player.lua | 2 | ||||
| -rw-r--r-- | objects/Shot.lua | 25 |
2 files changed, 25 insertions, 2 deletions
diff --git a/objects/Player.lua b/objects/Player.lua index 9b36dd9..aabc9e2 100644 --- a/objects/Player.lua +++ b/objects/Player.lua @@ -16,7 +16,7 @@ function Player.new() zoom = 1/16, speed = config.player.speed, shieldedTill = 0, - hearts = { "redheart", "redheart", "redheart", "shinyheart", "shinyheart", "stickyheart" }, + hearts = { "purpleheart", "redheart", "redheart", "redheart", "shinyheart", "shinyheart", "stickyheart" }, facing = Direction.DOWN, moving = false, frameTimer = FrameTimer:new(config.frameRate, 2) diff --git a/objects/Shot.lua b/objects/Shot.lua index 48e5869..cbadabe 100644 --- a/objects/Shot.lua +++ b/objects/Shot.lua @@ -1,4 +1,5 @@ local bulletData = require "data.bulletData" +local Loot = require "objects.loot" local Shot = {} Shot.__index = Shot @@ -39,11 +40,11 @@ end function Shot:onContact(other, contact) local sort = other.objectType + local data = bulletData[self.type] local dieOnThisContact = true -- when contact with enemy, deal damage if sort == "enemy" then - local data = bulletData[self.type] other:takeDamage(self.damage) other:onHit(self) if data and data.afterHit then @@ -63,6 +64,28 @@ function Shot:onContact(other, contact) dieOnThisContact = false end + -- bouncy heart + if sort ~= "player" and data and data.bouncy then + -- if heart can still bounce + 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) + self.physicsBody:setLinearVelocity(math.cos(angle) * config.bullet.speed, + math.sin(angle) * config.bullet.speed) + self.bounced = self.bounced + 1 + -- if not, then die or break + else + dieOnThisContact = true + if math.random(3) == 1 then + local lootItem = Loot:new("brokenheart", other.x, other.y) + table.insert(G.currentRoom.objects.loots, lootItem) + end + end + end + if dieOnThisContact then self:die() end |
