Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@MeleeAttack.announce(Combatant)
def announce_melee_attack(event, combatant):
log.info("{0} hits {1}".format(
event.actor.type.name, combatant.entity.type.name))
@Damage.perform(Combatant)
def do_damage(event, combatant):
combatant.lose_health(event)
@Die.perform(Combatant)
def do_die(event, combatant):
# TODO player death is a little different. should be a separate component,
# probably, instead of special-casing here (yikes)
# TODO i am not actually sure if using an exception here is a good idea
from flax.entity import Player
if combatant.entity.isa(Player):
raise GameOver("you died :(", success=False)
event.world.current_map.remove(combatant.entity)
# TODO and drop inventory, and/or a corpse
@Die.announce(Combatant)
def announce_die(event, combatant):
log.info("{} has died".format(combatant.entity.type.name))
(1, Sprite.ruin4d, 'decay3'),
(5, Sprite.ruin3a, 'decay2'),
(5, Sprite.ruin3b, 'decay2'),
(3, Sprite.ruin2, 'decay1'),
(10, Sprite.ruin1e, 'decay0'),
),
name='ruin',
)
# -----------------------------------------------------------------------------
# Creatures
Creature = partial(EntityType, Solid, Container, Bodied, layer=Layer.creature)
Player = Creature(
Combatant(strength=3, health=20),
PlayerIntelligence,
Render(sprite=Sprite.player, color='player'),
name='you',
)
Salamango = Creature(
Combatant(strength=1, health=5),
GenericAI,
Render(sprite=Sprite.lizard, color='salamango'),
name='salamango',
)
# -----------------------------------------------------------------------------
# Items
Item = partial(EntityType, Portable, layer=Layer.item)
@MeleeAttack.perform(Combatant)
def do_melee_attack(event, combatant):
opponent = ICombatant(event.actor)
event.world.queue_immediate_event(
Damage(combatant.entity, opponent.strength))