def new(actor_identifier=None, attributes=None): '''Hero factory''' attributes = attributes or {} hero_type = attributes[OBJECT_TYPE] if hero_type == WARRIOR: new_actor = Hero( { 'stand_by': loop_animation(HEROES, 4, [WARRIOR_DOWN[0]]), 'up': loop_animation(HEROES, 4, WARRIOR_UP), 'up_right': loop_animation(HEROES, 4, WARRIOR_UP_RIGHT), 'right': loop_animation(HEROES, 4, WARRIOR_RIGHT), 'down_right': loop_animation(HEROES, 4, WARRIOR_DOWN_RIGHT), 'down': loop_animation(HEROES, 4, WARRIOR_DOWN), 'down_left': loop_animation(HEROES, 4, WARRIOR_DOWN_LEFT), 'left': loop_animation(HEROES, 4, WARRIOR_LEFT), 'up_left': loop_animation(HEROES, 4, WARRIOR_UP_LEFT), 'exit': animation(HEROES, 4, WARRIOR_EXIT) }, identifier=actor_identifier, spawn_zone=HEROES_SPAWN[hero_type]) elif hero_type == VALKYRIE: new_actor = Hero( { 'stand_by': loop_animation(HEROES, 3, [VALKYRIE_DOWN[0]]), 'up': loop_animation(HEROES, 3, VALKYRIE_UP), 'up_right': loop_animation(HEROES, 3, VALKYRIE_UP_RIGHT), 'right': loop_animation(HEROES, 3, VALKYRIE_RIGHT), 'down_right': loop_animation(HEROES, 3, VALKYRIE_DOWN_RIGHT), 'down': loop_animation(HEROES, 3, VALKYRIE_DOWN), 'down_left': loop_animation(HEROES, 3, VALKYRIE_DOWN_LEFT), 'left': loop_animation(HEROES, 3, VALKYRIE_LEFT), 'up_left': loop_animation(HEROES, 3, VALKYRIE_UP_LEFT), 'exit': animation(HEROES, 4, VALKYRIE_EXIT) }, identifier=actor_identifier, spawn_zone=HEROES_SPAWN[hero_type]) elif hero_type == WIZARD: new_actor = Hero( { 'stand_by': loop_animation(HEROES, 4, [WIZARD_DOWN[0]]), 'up': loop_animation(HEROES, 4, WIZARD_UP), 'up_right': loop_animation(HEROES, 4, WIZARD_UP_RIGHT), 'right': loop_animation(HEROES, 4, WIZARD_RIGHT), 'down_right': loop_animation(HEROES, 4, WIZARD_DOWN_RIGHT), 'down': loop_animation(HEROES, 4, WIZARD_DOWN), 'down_left': loop_animation(HEROES, 4, WIZARD_DOWN_LEFT), 'left': loop_animation(HEROES, 4, WIZARD_LEFT), 'up_left': loop_animation(HEROES, 4, WIZARD_UP_LEFT), 'exit': animation(HEROES, 4, WIZARD_EXIT) }, identifier=actor_identifier, spawn_zone=HEROES_SPAWN[hero_type]) elif hero_type == ELF: new_actor = Hero( { 'stand_by': loop_animation(HEROES, 2, [ELF_DOWN[0]]), 'up': loop_animation(HEROES, 2, ELF_UP), 'up_right': loop_animation(HEROES, 2, ELF_UP_RIGHT), 'right': loop_animation(HEROES, 2, ELF_RIGHT), 'down_right': loop_animation(HEROES, 2, ELF_DOWN_RIGHT), 'down': loop_animation(HEROES, 2, ELF_DOWN), 'down_left': loop_animation(HEROES, 2, ELF_DOWN_LEFT), 'left': loop_animation(HEROES, 2, ELF_LEFT), 'up_left': loop_animation(HEROES, 2, ELF_UP_LEFT), 'exit': animation(HEROES, 3, ELF_EXIT) }, identifier=actor_identifier, spawn_zone=HEROES_SPAWN[hero_type]) else: raise ValueError('Invalid hero_type: {}'.format(hero_type)) new_actor.attribute[SCORE] = 0 new_actor.attribute[LIFE] = INITIAL_HERO_LIFE new_actor.attribute.update(attributes) return new_actor
def new(decoration, position): '''Create new decoration object''' speed, frames = _DECORATIONS_[decoration] return Decoration(animation(MAP_ENTITIES, speed, frames), position)