When the Hero dies, swap MainGameEventHandler for GameOverEventHandler
This commit is contained in:
parent
e5b3cbd2cd
commit
388754e5dd
2 changed files with 14 additions and 3 deletions
|
@ -221,8 +221,7 @@ class DieAction(Action):
|
||||||
'''Kill an Actor'''
|
'''Kill an Actor'''
|
||||||
|
|
||||||
def perform(self, engine: 'Engine') -> ActionResult:
|
def perform(self, engine: 'Engine') -> ActionResult:
|
||||||
log.ACTIONS.debug('%s dies', self.actor)
|
engine.kill_actor(self.actor)
|
||||||
engine.entities.remove(self.actor)
|
|
||||||
|
|
||||||
if self.actor.yields_corpse_on_death:
|
if self.actor.yields_corpse_on_death:
|
||||||
log.ACTIONS.debug('%s leaves a corpse behind', self.actor)
|
log.ACTIONS.debug('%s leaves a corpse behind', self.actor)
|
||||||
|
|
|
@ -12,7 +12,7 @@ from . import log
|
||||||
from . import monsters
|
from . import monsters
|
||||||
from .actions import Action, ActionResult
|
from .actions import Action, ActionResult
|
||||||
from .ai import HostileEnemy
|
from .ai import HostileEnemy
|
||||||
from .events import MainGameEventHandler
|
from .events import GameOverEventHandler, MainGameEventHandler
|
||||||
from .geometry import Size
|
from .geometry import Size
|
||||||
from .map import Map
|
from .map import Map
|
||||||
from .object import Actor, Entity, Hero, Monster
|
from .object import Actor, Entity, Hero, Monster
|
||||||
|
@ -179,3 +179,15 @@ class Engine:
|
||||||
|
|
||||||
# Visible tiles should be added to the explored list
|
# Visible tiles should be added to the explored list
|
||||||
self.map.explored |= self.map.visible
|
self.map.explored |= self.map.visible
|
||||||
|
|
||||||
|
def kill_actor(self, actor: Actor) -> None:
|
||||||
|
'''Kill an entity. Remove it from the game.'''
|
||||||
|
|
||||||
|
if actor == self.hero:
|
||||||
|
# When the hero dies, the game is over.
|
||||||
|
# TODO: Transition to game over state
|
||||||
|
log.ACTIONS.debug('Time to die.')
|
||||||
|
self.event_handler = GameOverEventHandler(self)
|
||||||
|
else:
|
||||||
|
log.ACTIONS.debug('%s dies', actor)
|
||||||
|
self.entities.remove(actor)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue