コード例 #1
0
def _instantiate_item(template):
    name = template['name']
    glyph_ = glyph(template['glyph'], getattr(libtcod, template['color']))
    item = Item(name, glyph_)
    if 'slot' in template:
        item.equip_slot = template['slot']
        if 'power' in template:
            item.power_bonus = template['power']
        if 'defense' in template:
            item.defense_bonus = template['defense']
        if 'hp' in template:
            item.max_hp_bonus = template['hp']
    elif 'on_use' in template:
        spell = _instantiate_spell(ITEM_USES[template['on_use']])
        item.on_use = spell
    return item
コード例 #2
0
def _instantiate_monster(game, template):
    name = template['name']
    spells = None
    if 'spell' in template:
        spells = [_instantiate_spell(template['spell'])]
    elif 'spells' in template:
        spells = [_instantiate_spell(spell) for spell in template['spells']]
    monster = Monster(game)
    monster.name = name
    monster.ai = ai.new(template['ai'], spells)
    monster.ai.monster = monster
    monster.glyph = glyph(template['glyph'], getattr(libtcod,
                                                     template['color']))
    monster.xp = template['experience']
    monster.hp = template['hp']
    monster.base_max_hp = monster.hp
    monster.base_defense = template['defense']
    monster.base_power = template['power']
    return monster
コード例 #3
0
def new_player(game):
    hero = Hero(game)
    hero.name = PLAYER_TEMPLATE['name']
    hero.inventory = []
    hero.glyph = glyph(PLAYER_TEMPLATE['glyph'],
                       getattr(libtcod, PLAYER_TEMPLATE['color']))
    hero.hp = PLAYER_TEMPLATE['hp']
    hero.base_max_hp = hero.hp
    hero.base_defense = PLAYER_TEMPLATE['defense']
    hero.base_power = PLAYER_TEMPLATE['power']
    game.player = hero
    for i in PLAYER_TEMPLATE['starting_items']:
        # TODO Don't reimplement this here
        item = new_item(i)
        item.owner = hero
        hero.inventory.append(item)
        if item.can_equip():
            item.is_equipped = True
    return hero
コード例 #4
0
ファイル: tile.py プロジェクト: nwolfe/pyro
class Tile:
    TYPE_FLOOR = _open_tile(glyph(None, COLOR_LIGHT_GROUND),
                            glyph(None, COLOR_DARK_GROUND))
    TYPE_WALL = _solid_tile(glyph(None, COLOR_LIGHT_WALL),
                            glyph(None, COLOR_DARK_WALL))
    TYPE_STAIRS = _exit_tile(glyph('>', libtcod.white, COLOR_LIGHT_GROUND),
                             glyph('>', libtcod.white, COLOR_DARK_GROUND))
    TYPE_CRUSHED_GRASS = _open_tile(
        glyph('.', libtcod.green, COLOR_LIGHT_GROUND),
        glyph('.', COLOR_DARK_GROUND))
    TYPE_TALL_GRASS = _fog_tile(glyph(':', libtcod.green, COLOR_LIGHT_GRASS),
                                glyph(':', COLOR_DARK_GROUND))
    TYPE_CLOSED_DOOR = _solid_tile(glyph('+', libtcod.white, COLOR_LIGHT_WALL),
                                   glyph('+', libtcod.white, COLOR_DARK_WALL))
    TYPE_OPEN_DOOR = _open_tile(glyph('-', libtcod.white, COLOR_LIGHT_GROUND),
                                glyph('-', libtcod.white, COLOR_DARK_GROUND))
    TYPE_TALL_GRASS.steps_to = TYPE_CRUSHED_GRASS
    TYPE_OPEN_DOOR.closes_to = TYPE_CLOSED_DOOR
    TYPE_CLOSED_DOOR.opens_to = TYPE_OPEN_DOOR

    def __init__(self):
        self.type = Tile.TYPE_WALL
        self.explored = False

    @property
    def passable(self):
        return self.type.passable

    @property
    def transparent(self):
        return self.type.transparent
コード例 #5
0
from collections import namedtuple
import libtcodpy as libtcod
from pyro.engine.glyph import glyph

Corpse = namedtuple('Corpse', 'type name pos')

_CorpseType = namedtuple('CorpseType', 'glyph')

_TYPE_MONSTER = _CorpseType(glyph('%', libtcod.dark_red))
_TYPE_HERO = _CorpseType(glyph('%', libtcod.dark_red))


def for_monster(monster):
    name = 'Remains of {0}'.format(monster.name)
    return Corpse(_TYPE_MONSTER, name, monster.pos)


def for_hero(hero):
    name = 'Remains of {0}'.format(hero.name)
    return Corpse(_TYPE_HERO, name, hero.pos)