class SoldierNPC(EnemyMale): # contains the core code for JickerNPC # ally = false by default, just switch it to true to make them follow you # usurping this class for jickers in townlol def __init__(self, game, name, (x, y)): BasicUnit.__init__(self, game, name, 'player', (x,y)) self.name = name self.anim_name = "player" self.hostile = False self.playable = False self.ally = False self.has_special = False self.palette_swaps.update({(128,64,0): (0,0,255)}) (self.x,self.y) = (x,y) self.activities = ['standing', 'walking', 'attacking', 'falling', 'dead', 'stunned'] self.equipment = [equipment.Armor(self.game, "Blue Chain Mail", "mail", self.activities, {(128,128,128):(0,0,192)}), equipment.Sword(self.game, "Sword of Suck", "sword", self.activities), equipment.Helm(self.game, "Blue Helmet", "helm2", self.activities, {(128,128,128):(0,0,192)}), ] #hair r = random.randint(0, 192) g = random.randint(int(r*0.5), int(r*0.9)) b = random.randint(int(r*0.1), int(r*0.2)) hair = equipment.Hairpiece(self.game, 'Hair', 'hairpiece', self.activities, {(0,0,0):(r,g,b)}) self.equipment.append(hair) if random.random() < 0.25: self.equipment.append(equipment.Beard(self.game, 'Beard', self.activities, hair.palette_swaps)) self.current_activity = 'standing' self.animations = [] self.current_hp = self.max_hp = 70 self.avoidance = self.mitigation = 0 self.min_damage = 3; self.max_damage = 6 self.load_animations(self.palette_swaps) self.reset() self.flee_threshold = 0.5
class EnemyBandit(EnemySoldier): def __init__(self, game, name, (x, y)): t1 = pygame.time.get_ticks() BasicUnit.__init__(self, game, name, 'player', (x, y)) self.vision_radius = 12 self.hostile = True self.playable = False self.ally = False self.has_special = False self.activities = [ 'standing', 'walking', 'attacking', 'falling', 'dead', 'stunned' ] self.palette_swaps.update({(0, 0, 128): (90, 60, 0)}) equip_palette_swaps = { (128, 64, 0): (128, 0, 128), (128, 128, 128): (192, 128, 0), (192, 192, 192): (255, 255, 0) } self.equipment = [ equipment.Sword(self.game, "Sword", 'sword', self.activities), equipment.Armor(self.game, "Brown Bandit Tunic", "mail", self.activities, { (128, 128, 128): (128, 64, 0), (0, 0, 0): (85, 43, 0) }), equipment.Helm( self.game, 'Brown Bandit Crown', 'crown', self.activities, { (128, 128, 128): (128, 64, 0), (0, 0, 0): (85, 43, 0), (192, 192, 192): (215, 216, 43) }) ] hairpiece = equipment.Hairpiece(self.game, 'Hair', 'hairpiece', self.activities) self.equipment.append(hairpiece) if random.random() <= 0.25: self.equipment.append( equipment.Beard(self.game, 'Beard', self.activities, hairpiece.palette_swaps)) self.current_hp = self.max_hp = 80 self.avoidance = 0 self.mitigation = 0 self.min_damage = 4 self.max_damage = 7 self.evade_speed = 0.4 self.current_activity = 'standing' self.animations = [] self.load_animations(self.palette_swaps) self.reset() t2 = pygame.time.get_ticks() if self.game.debug: print "Bandit load time:", t2 - t1, "ms"
class EnemyBanditVar(EnemyBandit): def __init__(self, game, name, (x, y)): t1 = pygame.time.get_ticks() BasicUnit.__init__(self, game, name, 'player', (x, y)) self.vision_radius = 12 self.hostile = True self.playable = False self.ally = False self.has_special = False self.palette_swaps.update({(0, 0, 128): (90, 60, 0)}) self.activities = [ 'standing', 'walking', 'attacking', 'falling', 'dead', 'stunned' ] self.equipment = [ equipment.Sword(self.game, "Steel Sword", "sword", self.activities, { (128, 128, 128): (189, 191, 193), (192, 192, 192): (234, 229, 229) }), equipment.Helm(self.game, 'Crown', 'crown', self.activities), equipment.Shield( self.game, "Green Bandit Shield", "shield2", self.activities, { (128, 128, 128): (128, 128, 0), (192, 192, 192): (170, 190, 90), (0, 0, 0): (100, 140, 100) }), equipment.Armor(self.game, 'Chain Mail', 'mail', self.activities) ] hairpiece = equipment.Hairpiece(self.game, 'Hair', 'hairpiece', self.activities) self.equipment.append(hairpiece) if random.random() <= 0.5: self.equipment.append( equipment.Beard(self.game, 'Beard', self.activities, hairpiece.palette_swaps)) self.current_hp = self.max_hp = 80 self.avoidance = 0.3 self.mitigation = 0 self.min_damage = 5 self.max_damage = 8 self.evade_speed = 0.4 self.current_activity = 'standing' self.animations = [] self.load_animations(self.palette_swaps) self.reset() t2 = pygame.time.get_ticks() if self.game.debug: print "Banditvar load time:", t2 - t1, "ms"
def load_items(self, path): path = path + 'items/' item_files = os.listdir(path) items = dict() for item_file_name in item_files: print('Loading {}'.format(item_file_name)) raw = load(open(path + item_file_name)) for raw_weapon in raw.get('weapons', []): object_id = raw_weapon.get('id') name = raw_weapon.get('name') value = raw_weapon.get('value') base_damage = raw_weapon.get('base_damage') two_handed = raw_weapon.get('two_handed') weapon = equipment.Weapon(name, object_id, base_damage, two_handed) items[object_id] = weapon for raw_item in raw.get('items', []): object_id = raw_item.get('id') name = raw_item.get('name') value = raw_item.get('value') stackable = raw_item.get('stackable') item = equipment.Item(name, object_id, stackable, 0) items[object_id] = item for raw_armor in raw.get('armors', []): object_id = raw_armor.get('id') name = raw_armor.get('name') value = raw_armor.get('value') possible_slots = [[equipment.EquipmentSlots(slot_name)] for slot_name in raw_armor.get('slots')] armor_type = equipment.ArmorTypes(raw_armor.get('type')) armor_rating = raw_armor.get('armor_rating') armor = equipment.Armor( name, object_id, possible_slots, armor_type, armor_rating, ) items[object_id] = armor return items
# create file handler and set level to debug file_handler = logging.FileHandler(logging_file, mode='w') file_handler.setLevel(logging.INFO) # create formatter formatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s') # add formatter to file_handler file_handler.setFormatter(formatter) # add file_handler to logger logger.addHandler(file_handler) if __name__ == '__main__': logger_sets() standard_equipement = [ equipment.Helm(), equipment.Armor(), equipment.Shoes(), equipment.Sword(), equipment.Shield() ] warrior1 = characters.Warrior('WARRIOR 1') warrior1.select_equipement(standard_equipement) warrior2 = characters.Warrior('WARRIOR 2') warrior2.select_equipement(standard_equipement) knight1 = characters.Knight('KNIGHT 1') knight1.select_equipement(standard_equipement) knight2 = characters.Knight('KNIGHT 2') knight2.select_equipement(standard_equipement) thief1 = characters.Thief('THIEF 1') thief1.select_equipement(standard_equipement) thief2 = characters.Thief('THIEF 2')