def __init__(self, name, pos, sprite, hp, defense, res, max_move, strength, attack_kind, strategy, reach, xp_gain, loot, keywords=None, lvl=1, alterations=None): Movable.__init__(self, name, pos, sprite, hp, defense, res, max_move, strength, attack_kind, strategy, lvl, alterations=alterations) self.reach = reach self.xp_gain = int(xp_gain * (1.1**(lvl - 1))) self.potential_loot = loot self.keywords = [] if keywords is None else keywords
def __init__(self, name, pos, sprite, hp, defense, res, strength, classes, equipments, strategy, lvl, skills, alterations, race, gold, interaction, compl_sprite=None): Movable.__init__( self, name, pos, sprite, hp, defense, res, Character.races_data[race]['move'] + Character.classes_data[classes[0]]['move'], strength, 'PHYSICAL', strategy, lvl, skills, alterations, compl_sprite) self.equipments = equipments self.classes = classes self.race = race self.gold = gold self.interaction = interaction self.join_team = False self.reach_ = [1] self.constitution = Character.races_data[race]['constitution'] + \ Character.classes_data[classes[0]]['constitution']
def test_init_movable(self): name = 'movable0' pos = (3, 2) sprite = 'imgs/dungeon_crawl/monster/angel.png' hp = 10 defense = 4 res = 3 max_moves = 5 strength = 2 attack_kind = 'PHYSICAL' strategy = 'STATIC' movable_entity = Movable(name, pos, sprite, hp, defense, res, max_moves, strength, attack_kind, strategy) self.assertTrue(movable_entity.is_on_pos(pos)) self.assertEqual(max_moves, movable_entity.max_moves) self.assertEqual(strength, movable_entity.strength) self.assertEqual(DamageKind[attack_kind], movable_entity.attack_kind) self.assertEqual(EntityStrategy[strategy], movable_entity.strategy) self.assertEqual(1, movable_entity.lvl) self.assertEqual(0, movable_entity.xp) self.assertEqual(0, len(movable_entity.alterations)) self.assertEqual(0, len(movable_entity.items)) self.assertEqual(0, len(movable_entity.skills)) self.assertFalse(movable_entity.turn_is_finished()) self.assertTrue(movable_entity.has_free_space()) self.assertTrue(movable_entity.can_attack()) self.assertEqual("None", movable_entity.get_formatted_alterations()) self.assertEqual("None", movable_entity.get_abbreviated_alterations()) self.assertEqual( "", movable_entity.get_formatted_stat_change(rd.choice(STATS)))
def attacked(self, ent, damage, kind, allies): for eq in self.equipments: if kind is DamageKind.PHYSICAL: damage -= eq.defense elif kind == DamageKind.SPIRITUAL: damage -= eq.res return Movable.attacked(self, ent, damage, kind, allies)
def save(self, tree_name): tree = Movable.save(self, tree_name) # Save class (if possible) if len(self.classes) > 0: class_el = etree.SubElement(tree, 'class') class_el.text = self.classes[0] # Currently, only first class is saved if any # Save race race = etree.SubElement(tree, 'race') race.text = self.race # Save gold gold = etree.SubElement(tree, 'gold') gold.text = str(self.gold) # Save inventory inventory = etree.SubElement(tree, 'inventory') for item in self.items: inventory.append(item.save('item')) # Save equipment equipments = etree.SubElement(tree, 'equipment') for equipment in self.equipments: equipments.append(equipment.save(equipment.body_part)) return tree
def get_stat_change(self, stat): malus = 0 if stat == 'speed': # Check if character as a malus to his movement due to equipment total weight exceeding constitution total_weight = sum([eq.weight for eq in self.equipments]) diff = total_weight - self.constitution malus = 0 if diff < 0 else - math.ceil(diff / 2) return malus + Movable.get_stat_change(self, stat)
def random_movable_entity(min_hp=10, max_hp=30, max_defense=10, max_res=10, name=None): attrs = random_movable_attributes(min_hp, max_hp, max_defense, max_res, name) return Movable(attrs['name'], attrs['pos'], attrs['sprite'], attrs['hp'], attrs['defense'], attrs['res'], attrs['max_moves'], attrs['strength'], attrs['attack_kind'], attrs['strategy'])
def save(self, tree_name): tree = Movable.save(self, tree_name) # Save loot loot = etree.SubElement(tree, "loot") for (item, probability) in self.potential_loot: if isinstance(item, Gold): it_el = etree.SubElement(loot, 'gold') it_name = etree.SubElement(it_el, 'amount') it_name.text = str(item.amount) else: it_el = etree.SubElement(loot, 'item') it_name = etree.SubElement(it_el, 'name') it_name.text = item.name it_probability = etree.SubElement(it_el, 'probability') it_probability.text = str(probability) return tree
def lvl_up(self): Movable.lvl_up(self) self.stats_up()
def display(self, screen): Movable.display(self, screen) for eq in self.equipments: eq.display(screen, self.pos, True)
from src.scenes.startScreen import StartScreen from src.services import loadFromXMLManager as Loader pg.init() # Load fonts fonts.init_fonts() # Window parameters pg.display.set_caption("In the name of the Five Cats") screen = pg.display.set_mode((MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT)) # Load constant sprites Destroyable.init_constant_sprites() Breakable.init_constant_sprites() Movable.init_constant_sprites() Sidebar.init_constant_sprites() Level.init_constant_sprites() # Load some data races = Loader.load_races() classes = Loader.load_classes() Character.init_data(races, classes) clock = pg.time.Clock() start_screen = StartScreen(screen) quit_game = False while not quit_game: for e in pg.event.get():