Skip to content

Commit

Permalink
Respawn functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nullenvk committed Jun 22, 2022
1 parent 1cf01dc commit 3bfe388
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion res/main.map
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
B0000000000000000000000000000000
B0000000000000000000000000000000
B00000000000000000R0000000000000
B00000000000000000R00000K0000000
B000000BBB000BBBBBBBBBBBBBB0BBBB
B000000BBB000BBBBBBBBBBBB000000B
B000000BBB000BBBBBBBBBBBB000000B
Expand Down
14 changes: 14 additions & 0 deletions src/ent_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,21 @@ function Player:reactToColKill(dPos, tFinal, isVert, tile)
end

function Player:reactToColSetRespawn(dPos, tFinal, isVert, tile)
local pw, ph = self.spriteSizeW, self.spriteSizeH
local tw, th = 800 / TILESCREEN_W, 600 / TILESCREEN_H

local topBlocked = not self:isTileEmpty(tile.x, tile.y, {x = 0, y = -1})

local rDest = {x = (tile.x - 1) * tw, y = tile.y * th - ph,
sx = self.tmPos.x, sy = self.tmPos.y,
gravFlip = true, reset = true}

if topBlocked then
rDest.gravFlip = false
rDest.y = rDest.y + th
end

self.respawnDest = rDest

self:reactToColIgnore(dPos, tFinal, isVert, tile)
end
Expand Down
3 changes: 3 additions & 0 deletions src/state_game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ end

function State_Game:testTeleport()
local tdest = self.player.teleportDest
local rdest = self.player.respawnDest

if tdest ~= nil then
if tdest.reset then
self.player = Player:new()
self.player.respawnDest = rdest -- Make respawn points persist between deaths
self.player.gravFlip = tdest.gravFlip or false
end

Expand Down

0 comments on commit 3bfe388

Please sign in to comment.