diff options
author | Aki <nthirtyone@gmail.com> | 2016-06-14 12:14:41 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-06-14 12:14:41 +0200 |
commit | 498e754f7725cbf8e19d60a03b1d7b30fdae823e (patch) | |
tree | a6ad7612c84f883914f59ada70116b74cc90c14b | |
parent | 4e9e6722b2924df271233d7db48aec2d8ba1fd0d (diff) | |
download | roflnauts-498e754f7725cbf8e19d60a03b1d7b30fdae823e.zip roflnauts-498e754f7725cbf8e19d60a03b1d7b30fdae823e.tar.gz roflnauts-498e754f7725cbf8e19d60a03b1d7b30fdae823e.tar.bz2 |
onNautKill and game restart
-rw-r--r-- | player.lua | 2 | ||||
-rw-r--r-- | world.lua | 40 |
2 files changed, 40 insertions, 2 deletions
@@ -362,8 +362,8 @@ function Player:die () self.lives = self.lives - 1 self.alive = false self.spawntimer = 1 - self.world.camera:startShake() self.body:setActive(false) + self.world:onNautKilled(self) end -- And then respawn. Like Jon Snow. @@ -24,7 +24,9 @@ World = { clouds_delay = 5, clouds_initial = nil, -- Map - map = nil + map = nil, + -- Gameplay status + lastNaut = false } -- Constructor of `World` ZA WARUDO! @@ -160,6 +162,42 @@ function World:createEffect(name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end +-- get Nauts functions +function World:getNautsPlayable() + local nauts = {} + for _,naut in pairs(self.Nauts) do + if naut.lives > -1 then + table.insert(nauts, naut) + end + end + return nauts +end + +function World:getNautsAlive() + local nauts = {} + for _,naut in self.Nauts do + if naut.alive then + table.insert(nauts, naut) + end + end + return nauts +end + +-- Event: when player is killed +function World:onNautKilled(naut) + self.camera:startShake() + local nauts = self:getNautsPlayable() + if self.lastNaut then + local m = Menu:new() + for _,controller in pairs(Controllers) do + m:assignController(controller) + end + changeScene(m) + elseif #nauts < 2 then + self.lastNaut = true + end +end + -- Update ZU WARUDO function World:update(dt) -- Physical world |