def __init__(self, name, race, sex, location): # Assign the name to the name variable self.name = name # Assign race to the race variable self.race = race # Based on race, set appropriate stats and starting inventory if race == 1: sword = items.Weapon('sword', 2, 2) self.inventory = {'sword': sword} self.stats = [2, 3, 2] elif race == 2: bow = items.Weapon('bow', 2, 5) self.inventory = {'bow': bow} self.stats = [1, 4, 4] elif race == 3: axe = items.Weapon('axe', 4, 1) self.inventory = {'axe': axe} self.stats = [3, 1, 3] elif race == 4: mace = items.Weapon('mace', 5, 1) self.inventory = {'mace': mace} self.stats = [4, 2, 1] # Assign proper sex if sex == 'M': self.sex = 'Male' if sex == 'F': self.sex = 'Female' # Character has no location initially self.location = location
def __init__(self): self.itemlist = [ items.Weapon("Better Sword", 2, 2, 7), items.Armor("Better Armor", 2, 2), items.Shield("Better Shield", 2, 2), items.Weapon("Ultra Sword", 8, 10, 15), items.Armor("Ultra Armor", 8, 8), items.Shield("Ultra Shield", 8, 10) ] self.potion = items.Potion("Healing Potion", 1, 10)
def __init__(self): self.gold = 0 self.weapon = items.Weapon("Short Sword", 0, 1, 5) self.shield = items.Shield("Wooden Shield", 0, 1) self.armor = items.Armor("Leather Scraps", 0, 1) self.potion = items.Potion("Healing Potion", 0, 15) self.potion_counter = 1
def load_char_if_saved(): query = Query() if db is not None: var = db.search(query.name == name_to_load) if var: var = var[0] ch.name = var.get('name') ch.coins = var.get('coins') inventory = var.get('inventory') player_inventory = [] for thing in inventory: if thing.get('type') == 'item': item = items.Item(thing.get('name'), thing.get('price')) player_inventory.append(item) elif thing.get('type') == 'weapon': weap = items.Weapon(thing.get('name'), thing.get('price'), thing.get('damage')) player_inventory.append(weap) elif thing.get('type') == 'armor': armor = items.Armor(thing.get('name'), thing.get('price'), thing.get('defense')) player_inventory.append(armor) elif thing.get('type') == 'potions': potion = items.Potion(thing.get('name'), thing.get('price'), thing.get('health')) player_inventory.append(potion) ch.inventory = player_inventory
def __init__(self, name, game_map, weapon=items.Weapon("Stick", 1, 4), armour=None): # Set attributes self._map = game_map self._room = self._map.start_room() self._position = self._room.find_entrance("m") # Set attributes associated with Character object super().__init__(name, weapon=weapon, armour=armour) # Replace inventory object with one that will pass to self.use function self._inventory = items.Inventory(self.use)
def main(): a = items.Item(name='pirouni', description='voithaei stin vrosi', value=0.01) print(a) gold = items.Currency(currency_type='Silver', amount=30) print(gold) rock = items.Rock() print(rock) dagger = items.Weapon(name='Dagger', description='A small dagger', damage='d4', value=0.2) print(dagger) another_dagger = items.Dagger() print(another_dagger) assassin_suit = items.AssassinSuit() print(assassin_suit)
def create_shop_list_weapon(): lista = [ "Dagger 30", "Short Sword 80", "Long Sword 90", "Divine Sword 150", "Bow 45", "War Hammer 95", "Knife 25" ] shop_list = list() for item in lista: novo = item.split() if len(novo) == 3: temp = " ".join(novo[0:2]) novo[0] = temp novo[1] = novo[2] shop_list.append(items.Weapon(novo[0], novo[1])) return shop_list
def load_instance(name): inst = Instance(name) paths = ["items/", "locations/"] data = None for i, path in enumerate(paths): with open(path + name + ".json", "r", encoding="utf-8") as rf: data = json.load(rf) if i == 0: for n in data: if n["id"][0] == "a": inst.armor.append(items.Armor(*n.values())) elif n["id"][0] == "w": inst.weapons.append(items.Weapon(*n.values())) elif i == 1: for n in data: tmp_items = [] for loc_item in n["items"]: tmp_items.append(inst.get_item(loc_item)) n["items"] = tmp_items inst.locations.append(locations.Location(*n.values())) return inst
def __init__(self): # player textures self.tx_face_down = pygame.image.load( "assets/graphics/chars/base/down.png") self.tx_face_left = pygame.image.load( "assets/graphics/chars/base/left.png") self.tx_face_up = pygame.image.load( "assets/graphics/chars/base/up.png") self.tx_face_right = pygame.image.load( "assets/graphics/chars/base/right.png") # Walk animations self.tx_walk_down = [ pygame.image.load("assets/graphics/chars/base/down_walk/dw_1.png"), pygame.image.load("assets/graphics/chars/base/down_walk/dw_2.png"), pygame.image.load("assets/graphics/chars/base/down_walk/dw_3.png"), pygame.image.load("assets/graphics/chars/base/down_walk/dw_4.png") ] self.tx_walk_left = [ pygame.image.load("assets/graphics/chars/base/left_walk/lw_1.png"), pygame.image.load("assets/graphics/chars/base/left_walk/lw_2.png"), pygame.image.load("assets/graphics/chars/base/left_walk/lw_3.png"), pygame.image.load("assets/graphics/chars/base/left_walk/lw_4.png") ] self.tx_walk_up = [ pygame.image.load("assets/graphics/chars/base/up_walk/uw_1.png"), pygame.image.load("assets/graphics/chars/base/up_walk/uw_2.png"), pygame.image.load("assets/graphics/chars/base/up_walk/uw_3.png"), pygame.image.load("assets/graphics/chars/base/up_walk/uw_4.png") ] self.tx_walk_right = [ pygame.image.load( "assets/graphics/chars/base/right_walk/rw_1.png"), pygame.image.load( "assets/graphics/chars/base/right_walk/rw_2.png"), pygame.image.load( "assets/graphics/chars/base/right_walk/rw_3.png"), pygame.image.load("assets/graphics/chars/base/right_walk/rw_4.png") ] # Stab attack animations self.tx_stab_down = pygame.image.load( "assets/graphics/chars/base/stab/down_hit.png") self.tx_stab_left = pygame.image.load( "assets/graphics/chars/base/stab/left_hit.png") self.tx_stab_up = pygame.image.load( "assets/graphics/chars/base/stab/up_hit.png") self.tx_stab_right = pygame.image.load( "assets/graphics/chars/base/stab/right_hit.png") # player equipment data self.weapon_equipped = True self.weapon = items.Weapon("test_sword") self.weapon_damage = 1 # player location/velocity/state info self.x_pos = 50 self.y_pos = 50 self.x_tile = int( self.x_pos / 32) # These are estimations of the tile the player will be on self.y_tile = int(self.y_pos / 32) self.attacking = False self.walk_speed = 3 self.walking = False # If the player is currently moving self.walkCount = 0 self.faceDirection = "D" # U D L R for each direction self.can_move_up = True self.can_move_down = True self.can_move_left = True self.can_move_right = True # player collision data self.hit_box = ((self.x_pos + 10), (self.y_pos + 3), 12, 28) self.T_R = ((self.x_pos + 10), (self.y_pos + 3), 12, 1) self.B_R = ((self.x_pos + 10), (self.y_pos + 30), 12, 1) self.L_R = ((self.x_pos + 10), (self.y_pos + 4), 1, 26) self.R_R = ((self.x_pos + 21), (self.y_pos + 4), 1, 26) self.top_rect = pygame.Rect(self.T_R) self.bottom_rect = pygame.Rect(self.B_R) self.left_rect = pygame.Rect(self.L_R) self.right_rect = pygame.Rect(self.R_R) self.rect = pygame.Rect(self.hit_box) self.stab_rect_up = pygame.Rect( ((self.x_pos + 10), (self.y_pos + 3), 12, 1)) self.stab_rect_down = pygame.Rect( ((self.x_pos + 10), (self.y_pos + 30), 12, 1)) self.stab_rect_left = pygame.Rect( (self.x_pos, (self.y_pos + 20), 10, 4)) self.stab_rect_right = pygame.Rect( ((self.x_pos + 21), (self.y_pos + 20), 10, 4)) self.weapon_rect = pygame.Rect(0, 0, 0, 0)
import playerchar import items import monsterchar import game_events import world #declare characters playerone = playerchar.Player(100,1,[], "Forest",1,11) monster1 = monsterchar.Monster('booby brown',22,2000,10,[]) w_stt = items.Weapon('Sword of a Thousand Truths', 29, 5) shoes1 = items.Shoes('Silk Slippers',45,'silk',3.5,5) playerone.bag = [w_stt,shoes1] monsters = monsterchar.monsterMaker(2,1,1) #for site in world.wMap: # for lvl in site: # world.roomFill(world.wMap[lvl].inv, monsters) world.roomFill(world.wMap['Forest'].inv, monsters) print(world.wMap['Forest'].inv) #game = True #while game == True: #start game # playerone.look() # n = input("What will you do? \n >>> ") #enquire command from player # if n.strip() == "travel": # in case 'travel' command # # tell where can travel - loop trough dir # t = input("In what direction will you travel? \n >>> ") # where will player then travel? # if t.strip() in {'N', 'E', 'S', 'W'}: # only take compass directions # print(n,' towards ',t+'est') # confirming message
root.geometry("300x100+100+100") start_room = rooms.Room("The Entrance", n=True) end_room = rooms.Room("The Bee Room", s=True, n=start_room) # Initialise a map game_map = rooms.Map([[start_room], [end_room]], start_room, end_room) # String var name name = "Jordan Hay" # Create player object player = Player(name, game_map) player.inventory().add_items([ items.Item("Bees"), items.Weapon("A HIVE FULL OF BEES", 10, 300), items.Armour("Honeycomb Kneepads", 100), items.Potion("10mL Syringe full of Honey", 10) ]) # After ten seconds the name will change root.after(10000, lambda: name.set("Different name")) # Display player inventory #player.inventory().gui(root) # Display player stats player.gui(root) # Root mainloop root.mainloop()
def __init__(self, health, position, inventory, skill): self.position = position #list of two ints self.inventory = inventory #list of item objects self.weapon = items.Weapon("kajsdf", 15, 2) self.previousPosition = position super().__init__(health, skill)
def __init__(self, name): # name will load all the npc attributes from npc.json, player obj for collisions # NPC textures self.tx_face_down = pygame.image.load(npc_data[name][0]["textures"][0]["down"]) self.tx_face_left = pygame.image.load(npc_data[name][0]["textures"][0]["left"]) self.tx_face_up = pygame.image.load(npc_data[name][0]["textures"][0]["up"]) self.tx_face_right = pygame.image.load(npc_data[name][0]["textures"][0]["right"]) # Walk animations self.tx_walk_down = [pygame.image.load(npc_data[name][0]["textures"][0]["down_walk"][0]), pygame.image.load(npc_data[name][0]["textures"][0]["down_walk"][1]), pygame.image.load(npc_data[name][0]["textures"][0]["down_walk"][2]), pygame.image.load(npc_data[name][0]["textures"][0]["down_walk"][3])] self.tx_walk_left = [pygame.image.load(npc_data[name][0]["textures"][0]["left_walk"][0]), pygame.image.load(npc_data[name][0]["textures"][0]["left_walk"][1]), pygame.image.load(npc_data[name][0]["textures"][0]["left_walk"][2]), pygame.image.load(npc_data[name][0]["textures"][0]["left_walk"][3])] self.tx_walk_up = [pygame.image.load(npc_data[name][0]["textures"][0]["up_walk"][0]), pygame.image.load(npc_data[name][0]["textures"][0]["up_walk"][1]), pygame.image.load(npc_data[name][0]["textures"][0]["up_walk"][2]), pygame.image.load(npc_data[name][0]["textures"][0]["up_walk"][3])] self.tx_walk_right = [pygame.image.load(npc_data[name][0]["textures"][0]["right_walk"][0]), pygame.image.load(npc_data[name][0]["textures"][0]["right_walk"][1]), pygame.image.load(npc_data[name][0]["textures"][0]["right_walk"][2]), pygame.image.load(npc_data[name][0]["textures"][0]["right_walk"][3])] # Stab attack animations self.tx_stab_down = pygame.image.load(npc_data[name][0]["textures"][0]["down_stab"]) self.tx_stab_left = pygame.image.load(npc_data[name][0]["textures"][0]["left_stab"]) self.tx_stab_up = pygame.image.load(npc_data[name][0]["textures"][0]["up_stab"]) self.tx_stab_right = pygame.image.load(npc_data[name][0]["textures"][0]["right_stab"]) # equipment data self.weapon_equipped = True self.weapon = items.Weapon(npc_data[name][0]["default_weapon"]) # player location/velocity/state info self.x_pos = 50 self.y_pos = 50 self.x_tile = int(self.x_pos / 32) # These are estimations of the tile the player will be on self.y_tile = int(self.y_pos / 32) self.attacking = False self.walk_speed = 3 self.walking = False # If the player is currently moving self.walkCount = 0 self.faceDirection = "D" # U D L R for each direction self.can_move_up = True self.can_move_down = True self.can_move_left = True self.can_move_right = True # player collision data self.hit_box = ((self.x_pos + 10), (self.y_pos + 3), 12, 28) self.T_R = ((self.x_pos + 10), (self.y_pos + 3), 12, 1) self.B_R = ((self.x_pos + 10), (self.y_pos + 30), 12, 1) self.L_R = ((self.x_pos + 10), (self.y_pos + 4), 1, 26) self.R_R = ((self.x_pos + 21), (self.y_pos + 4), 1, 26) self.top_rect = pygame.Rect(self.T_R) self.bottom_rect = pygame.Rect(self.B_R) self.left_rect = pygame.Rect(self.L_R) self.right_rect = pygame.Rect(self.R_R) self.center_t_rect = pygame.Rect((self.x_pos + 15), (self.y_pos + 12), 2, 1) self.center_b_rect = pygame.Rect((self.x_pos + 15), (self.y_pos + 15), 2, 1) self.center_l_rect = pygame.Rect((self.x_pos + 14), (self.y_pos + 13), 1, 2) self.center_r_rect = pygame.Rect((self.x_pos + 17), (self.y_pos + 13), 1, 2) self.rect = pygame.Rect(self.hit_box) # health bar self.hp_bar_enabled = True self.hp_background = ((self.x_pos + 10), (self.y_pos + 3), 10, 1) self.hp_bar = ((self.x_pos + 10), (self.y_pos + 3), 10, 1) # stats info self.hit_points_max = npc_data[name][0]["HP"] self.hit_points = self.hit_points_max
# - Main root = tk.Tk() # Tkinter root object # -- Items # --- Keys # Key to Dracula's crypt draculas_key = items.Key("THE KEY TO THE CRYPT") # --- Weapons weapons = [ items.Weapon("Pointy Stick", 2, 5), items.Weapon("Crowbar", 3, 8), items.Weapon("Molten Cheese", 5, 9), items.Weapon("Boomerang", 10, 15), items.Weapon("Laser Jet Printer", 12, 18), items.Weapon("Red Syringe", 10, 25) ] # --- Armour armour = [ items.Armour("MDF Shield", 5), items.Armour("Sheet Metal Shield", 6), items.Armour("Wooden Breastplate", 7), items.Armour("Sheet Metal Breastplate", 10), items.Armour("Shin Pads", 15)
#The main game world import rooms as tile import entities import items #The main game world. All information about everything is stored here. Do not delete weapon = items.Weapon("stabby", 5, 1) steve = entities.Enemy("steve", 5, weapon, 2) fangs = items.Weapon("fangs", 5, 3) Wolf = entities.Enemy("Wolf", 3, fangs, 2) baseball_bat = items.Weapon("baseball bat", 5, 2) Swatter = entities.Enemy("Swatter", 4, baseball_bat, 2) spiky_pom_poms = items.Weapon("spiky_pom_poms", 5, 3) Cheerbleeder = entities.Enemy("Cheerbleeder", 4, spiky_pom_poms, 3) spear = items.Weapon("spear", 5, 3) Gladiator = entities.Enemy("Gladiator", 5, spear, 5) broomstick = items.Weapon("broomstick", 5, 1) Janitor = entities.Enemy("Janitor", 3, broomstick, 1) beak = items.Weapon("beak", 0, 2) Rabid_Penguin = entities.Enemy("Rabid Penguin", 2, beak, 5) contorting_spear = items.Weapon("contorting spear", 8, 6) Monstrous_Gladiator = entities.Enemy("Monstrous Gladiator", 8, spear, 7) teeth = items.Weapon("teeth", 5, 3) Tiger = entities.Enemy("Wolf", 5, teeth, 6) appendage = items.Weapon("appendage", 100, 7) Shoggoth = entities.Enemy("Shoggoth", 10, appendage, 8) plastic_katana = items.Weapon("plastic katana", 1, 0) Weaboo = entities.Enemy("Weaboo", 2, plastic_katana, 1) world = [[tile.DoorRoom([]), tile.IceAgeRoom([])], [tile.HistoryRoom([])], [tile.IceAgeRoom([])], [tile.OtherRoom([])], [tile.Corridor([])]]