diff options
Diffstat (limited to 'world.lua')
| -rw-r--r-- | world.lua | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -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 |
