diff options
| author | cursed22bc <admin@pixeldawn.org> | 2026-03-10 19:27:58 +0200 |
|---|---|---|
| committer | cursed22bc <admin@pixeldawn.org> | 2026-03-10 19:27:58 +0200 |
| commit | 9d95968c3e732be915f10841d1d659e37b3b5d03 (patch) | |
| tree | 1932c4fef554a350303c75cda830503efdaa144c /world.lua | |
| parent | db9454cb632a3ba0b39018513b0d5bd444c8ffd3 (diff) | |
collision death state and basic HUD
Diffstat (limited to 'world.lua')
| -rw-r--r-- | world.lua | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -33,6 +33,7 @@ function World:new() self.contactCounts = {} self.contactEntity = {} self.contactKind = {} + self.pendingPlayerDeath = nil self.playerTextbox = Textbox:new() return self end @@ -193,6 +194,10 @@ function World:_isPlayerLike(ud) return type(ud) == "table" and ud.jump ~= nil end +function World:_isHazard(ud) + return type(ud) == "table" and (ud.isSpike or ud.isEnemy) +end + function World:_onBeginContact(udA, udB, nx, ny, contact) if udA == "ground" and self:_isTrackedEntity(udB) then local kind = self:_normalToContactType(nx, ny) @@ -239,6 +244,18 @@ function World:_onBeginContact(udA, udB, nx, ny, contact) self.waterContacts[udA] = (self.waterContacts[udA] or 0) + 1 doWaterSplash(udB, udA) end + + local playerEntity, hazardNx, hazardNy + if self:_isHazard(udA) and self:_isPlayerLike(udB) then + playerEntity = udB + hazardNx, hazardNy = nx, ny + elseif self:_isHazard(udB) and self:_isPlayerLike(udA) then + playerEntity = udA + hazardNx, hazardNy = -nx, -ny + end + if playerEntity and not playerEntity.isDead then + self.pendingPlayerDeath = { nx = hazardNx, ny = hazardNy } + end end function World:_onEndContact(udA, udB, contact) @@ -523,6 +540,11 @@ function World:update(dt) if not self.physicsWorld then return end self.physicsWorld:update(PHYSICS_DT) + if self.pendingPlayerDeath and self.player then + self.player:die(self.pendingPlayerDeath.nx, self.pendingPlayerDeath.ny) + self.pendingPlayerDeath = nil + end + for _, e in ipairs(self.entities) do if e.body then e:syncFromPhysicsBody() |
