How to use the flax.component.Combatant function in flax

To help you get started, we’ve selected a few flax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eevee / flax / flax / component.py View on Github external
@MeleeAttack.announce(Combatant)
def announce_melee_attack(event, combatant):
    log.info("{0} hits {1}".format(
        event.actor.type.name, combatant.entity.type.name))
github eevee / flax / flax / component.py View on Github external
@Damage.perform(Combatant)
def do_damage(event, combatant):
    combatant.lose_health(event)
github eevee / flax / flax / component.py View on Github external
@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
github eevee / flax / flax / component.py View on Github external
@Die.announce(Combatant)
def announce_die(event, combatant):
    log.info("{} has died".format(combatant.entity.type.name))
github eevee / flax / flax / entity.py View on Github external
(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)
github eevee / flax / flax / component.py View on Github external
@MeleeAttack.perform(Combatant)
def do_melee_attack(event, combatant):
    opponent = ICombatant(event.actor)
    event.world.queue_immediate_event(
        Damage(combatant.entity, opponent.strength))