summaryrefslogtreecommitdiff
path: root/world.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-03-10 21:55:19 +0200
committercursed22bc <admin@pixeldawn.org>2026-03-10 21:55:19 +0200
commit90af3a717b82a817e7fe8c756763f30d720efd95 (patch)
tree5a33f5fd57e43aec800cbee28e8d161b7a9894f7 /world.lua
parent70b6d2a335a40ae60e990cc5f37b828ed9dbf526 (diff)
door logic
Diffstat (limited to 'world.lua')
-rw-r--r--world.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/world.lua b/world.lua
index ad3d1ae..a4d7f12 100644
--- a/world.lua
+++ b/world.lua
@@ -29,6 +29,8 @@ function World:new()
self.refractionCanvas = nil
self.liquidShader = nil
self.activeSplashes = {}
+ self.entityDoor = nil
+ self.doorOpened = false
self.camera = nil
self.groundContacts = {}
self.waterContacts = {}
@@ -168,6 +170,14 @@ function World:load(mapPath, tilesets)
table.insert(self.entities, pickup)
end
+ self.entityDoor = self.tilemap:getEntityDoor()
+ if self.entityDoor then
+ self.entityDoor:enablePhysics(self.physicsWorld, "static")
+ self.entityDoor.fixture:setSensor(true)
+ self.entityDoor.fixture:setUserData(self.entityDoor)
+ table.insert(self.entities, self.entityDoor)
+ end
+
local ok, shader = pcall(love.graphics.newShader, "shaders/liquid.glsl")
self.liquidShader = ok and shader or nil
if not self.liquidShader then
@@ -225,6 +235,32 @@ function World:handlePickup(pickup, player)
end
end
+function World:handleDoor(door, player)
+ if not (door and player and door.isDoor and self:_isPlayerLike(player)) then return end
+ if self.doorOpened then return end
+
+ local keyCount = player.pickups.key or 0
+ local needed = 3
+
+ if keyCount >= needed then
+ self.doorOpened = true
+ self.playerTextbox:show(
+ "The door opens! You escaped!",
+ { player.x + player.width / 2, player.y - 20, "center" },
+ "write",
+ { life = 5, fontSize = 9, centeredText = true, wrapToFit = true }
+ )
+ else
+ local remaining = needed - keyCount
+ self.playerTextbox:show(
+ "Locked. You need " .. remaining .. " more key" .. (remaining > 1 and "s" or "") .. ".",
+ { player.x + player.width / 2, player.y - 20, "center" },
+ "write",
+ { life = 3, fontSize = 9, centeredText = true, wrapToFit = true }
+ )
+ end
+end
+
function World:_onBeginContact(udA, udB, nx, ny, contact)
if type(udA) == "table" and udA.isTextTrigger then
self:handleTextTrigger(udA, udB)
@@ -234,6 +270,10 @@ function World:_onBeginContact(udA, udB, nx, ny, contact)
self:handlePickup(udA, udB)
elseif type(udB) == "table" and udB.isPickup then
self:handlePickup(udB, udA)
+ elseif type(udA) == "table" and udA.isDoor and self:_isPlayerLike(udB) then
+ self:handleDoor(udA, udB)
+ elseif type(udB) == "table" and udB.isDoor and self:_isPlayerLike(udA) then
+ self:handleDoor(udB, udA)
end
if udA == "ground" and self:_isTrackedEntity(udB) then