diff options
author | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-10-22 00:17:40 +0200 |
---|---|---|
committer | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-10-22 00:17:40 +0200 |
commit | 8340116cd1d1df2673c9547a18a36d310c258f3b (patch) | |
tree | af87212f975415244afbe07bf426aa690d1daa16 /ghost.lua | |
parent | 6ea7381e9f0fd639f87de33cad6d9497c0c83888 (diff) |
Fixed some problems with ghosts from previous game levels or states not getting removed, also added /mypacman_exit chatcommand
Diffstat (limited to 'ghost.lua')
-rw-r--r-- | ghost.lua | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -49,10 +49,20 @@ for i in ipairs(ghosts) do -- Do we have game state? if not just die local gamestate = mypacman.games[self.gameid] if not gamestate then - minetest.log("action", "Removing pacman ghost from finished game " .. (self.gameid or "")) + minetest.log("action", "Removing pacman ghost without game assigned") self.object:remove() return end + -- Make sure we are in the right state by keeping track of the reset time + -- if the reset time changed it's likely the game got resetted while the entity wasn't loaded + if self.last_reset then + if self.last_reset ~= gamestate.last_reset then + minetest.log("action", "Removing pacman ghost remaining after reset ") + self.object:remove() + end + else + self.last_reset = gamestate.last_reset + end -- Make sure we have a targetted player if not self.target then @@ -62,7 +72,7 @@ for i in ipairs(ghosts) do local s = self.object:getpos() -- ghost local p = player:getpos() -- player - print(dump(gamestate)) + -- find distance from ghost to player local distance = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 if distance < 1.5 then @@ -114,13 +124,17 @@ for i in ipairs(ghosts) do -- This function should return the saved state of the entity in a string get_staticdata = function(self) - return self.gameid or "" + return (self.gameid or "") .. ";" .. (self.last_reset or "") end, -- This function should load the saved state of the entity from a string on_activate = function(self, staticdata) if staticdata and staticdata ~= "" then - self.gameid = staticdata + local data = string.split(staticdata, ";") + if #data == 2 then + self.gameid = data[1] + self.last_reset = tonumber(data[2]) + end end end }) |