summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-14 17:31:17 +0800
committerEltrac <hi@guhub.cn>2025-03-14 17:31:17 +0800
commit39fda7fdfb28bc784d42b1fc95d375ab1beefdfe (patch)
treea39bd6dbaff84d0089f83d791faa83001c2256ac
parente6b2b5e4259d92d4b411f788d1b524671329948a (diff)
feat: purple heart can now bounce
-rw-r--r--data/bulletData.lua8
-rw-r--r--objects/Player.lua2
-rw-r--r--objects/Shot.lua25
3 files changed, 33 insertions, 2 deletions
diff --git a/data/bulletData.lua b/data/bulletData.lua
index 71444ec..3fc1364 100644
--- a/data/bulletData.lua
+++ b/data/bulletData.lua
@@ -90,6 +90,14 @@ local bulletData = {
end
end
},
+ purpleheart = {
+ damage = 100,
+ bouncy = 3,
+ afterShot = function ()
+ end,
+ afterHit = function (x, y, enemyType)
+ end
+ },
brokenheart = {
damage = 50,
afterShot = function ()
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