def drop(self): #add to the map and remove from the config.player's config.inventory. also, place it at the config.player's coordinates. config.objects.append(self.owner) config.inventory.remove(self.owner) self.owner.x = config.player.x self.owner.y = config.player.y gfx.message('You dropped a ' + self.owner.name + '.', libtcod.yellow)
def use(self): #just call the "use_function" if it is defined if self.use_function is None: gfx.message('The ' + self.owner.name + ' cannot be used.') else: if self.use_function() != 'cancelled': config.inventory.remove(self.owner) #destroy after use, unless it was cancelled for some reason
def player_death(): #the game ended! gfx.message('You died!', libtcod.red) config.game_state = 'dead' #for added effect, transform the config.player into a corpse! config.player.char = '%' config.player.color = libtcod.dark_red
def pick_up(self): #add the config.player's config.inventory and remove from the map if len(config.inventory) >= 26: gfx.message('Your config.inventory is full - cannot pick up ' + self.owner.name + '.', libtcod.red) else: config.inventory.append(self.owner) config.objects.remove(self.owner) gfx.message('You picked up a ' + self.owner.name + '!', libtcod.green)
def monster_death(monster): #transform it into a nasty corpse! it doesn't block, can't be attacked, and doesn't move gfx.message(monster.name.capitalize() + ' is dead!', libtcod.orange) monster.char = '%' monster.color = libtcod.dark_red monster.blocks = False monster.fighter = None monster.ai = None monster.name = 'remains of ' + monster.name monster.send_to_back()
def close_door(self): self.open = False gfx.message('You close the door.', libtcod.white) self.owner.char = '+' config.map[self.owner.x][self.owner.y].blocked = True config.map[self.owner.x][self.owner.y].block_sight = True self.owner.name = 'A closed door' config.fov_recompute = True gfx.render_all()
def open_door(self): self.open = True gfx.message('You open the door.', libtcod.white) self.owner.char = '/' config.map[self.owner.x][self.owner.y].blocked = False config.map[self.owner.x][self.owner.y].block_sight = False self.owner.name = 'An open door' self.owner.send_to_back() config.fov_recompute = True gfx.render_all()
def pick_up(self): config.bomb_parts_collected += 1 config.objects.remove(self.owner) if config.bomb_parts_collected < 5: gfx.message("You pick up a bomb component. (" + str(config.TOTAL_BOMB_PARTS - config.bomb_parts_collected) + " remaining)") #add num_remaining elif config.bomb_parts_collected == 5: bomb_component = Bomb() item_component = Item(bomb=bomb_component) bomb = Object(config.player.x, config.player.y, 'B', 'armed nuclear bomb', libtcod.yellow, item = item_component) config.inventory.append(bomb) gfx.message("You have all the bomb components. Place the bomb on the final floor.")
def new_game(): global birthdaysuit, barehands config.turns = 0 #create the dungeon floor list config.floors = [] config.current_floor = 0 #create list of nodes config.nodes = [] config.flares = [] #create object representing the player armor_component = game.Armor(ac=0) item_component = game.Item(armor=armor_component) birthdaysuit = game.Object(0, 0, '[', 'Birthday Suit (worn)', libtcod.dark_orange, item = item_component) weapon_component = game.Weapon(mindmg=1, maxdmg=3, hitdie=2) item_component = game.Item(weapon=weapon_component) barehands = game.Object(0, 0, ')', 'Bare hands (wielded)', libtcod.light_blue, item = item_component) scanner_component = game.Scanner() item_component = game.Item(scanner=scanner_component) def_scanner = game.Object(0, 0, 's', 'Scanner', libtcod.dark_green, item = item_component) fighter_component = game.Fighter(plclass='Hellstronaut', ac=0, str=10, dex=10, con=10, int=10, fth=10, per=10, equipweapon=barehands, equiparmor=birthdaysuit, equipscanner=def_scanner, equipheadlamp=None, equiptank=None, equipcamo=None, hitdie = 0, mindmg = 0, maxdmg = 0, hp=100, defense=2, power=5, o2=200, death_function=game.player_death) config.player = game.Object(0, 0, '@', 'Dwayne', libtcod.white, blocks=True, fighter=fighter_component) mapgen.make_map() config.floors.append([config.map, config.objects, config.nodes, config.flares]) gfx.initialize_fov() #create inventory config.inventory = [] config.inventory.append(def_scanner) def_scanner.item.equip_scanner() #create the list of game messages and their colors, starts empty config.game_msgs = [] config.game_state = 'playing' #a warm welcoming message! gfx.message('Welcome to Hell.', libtcod.red)
def go_to_floor(dest): #pdb.set_trace() if dest > (len(config.floors)-1): #floor has not been generated yet, so generate it #store previous floor config.floors[config.current_floor][0] = config.map config.floors[config.current_floor][1] = config.objects config.floors[config.current_floor][2] = config.nodes config.floors[config.current_floor][3] = config.flares mapgen.make_map() config.floors.append([config.map, config.objects, config.nodes, config.flares]) else: #floor has been generated config.map = config.floors[dest][0] config.objects = config.floors[dest][1] config.nodes = config.floors[dest][2] config.flares = config.floors[dest][3] if dest < config.current_floor: #ascending for object in config.objects: if object.stairs and object.stairs.direction == "down": #find location of stairs_down from destination floor and place config.player there config.player.x = object.x config.player.y = object.y break elif dest > config.current_floor: #descending for object in config.objects: if object.stairs and object.stairs.direction == "up": #find location of stairs_down from destination floor and place config.player there config.player.x = object.x config.player.y = object.y break else: gfx.message('Something\'s kinda weird.', libtcod.red) config.current_floor = dest gfx.initialize_fov()
def pick_up(self): #add the config.player's config.inventory and remove from the map if self.item == None: gfx.message('You comb over the body and find nothing of use.', libtcod.yellow) else: if self.item.item.siphon: gfx.message('You\'ve siphoned oxygen off of the corpse!') config.player.fighter.o2 = config.max_o2 self.item = None else: if len(config.inventory) >= 26: gfx.message('Your config.inventory is full - cannot pick up ' + self.item.name + '.', libtcod.red) else: config.inventory.append(self.item) gfx.message('You picked up a ' + self.item.name + '!', libtcod.green) self.item = None
def sound_proximity(): #detect sound emanating Objects nearby for object in config.objects: if object == config.beast and config.beast.distance_to(config.player) < 16: gfx.message("You hear scraping footsteps and a rumbling growl.", libtcod.blue) elif object.stairs and object.distance_to(config.player) < 10: gfx.message("You hear a faint gust of wind.", libtcod.blue) elif object.pool and object.distance_to(config.player) < 8: gfx.message("You hear the sloshing of gentle waves nearby.", libtcod.blue)
def attack(self, target): #if config.player, use config.player attack stats hitdie = self.hitdie mindmg = self.mindmg maxdmg = self.maxdmg if libtcod.random_get_int(0,1,20) > hitdie: #hit! gfx.message('hit!') #determine damage damage = libtcod.random_get_int(0, mindmg, maxdmg) - target.fighter.defense else: #miss! gfx.message('miss!') damage = 0 if damage > 0: #make the target take some damage gfx.message(self.owner.name.capitalize() + ' attacks ' + target.name + ' for ' + str(damage) + ' hit points.') target.fighter.take_damage(damage) else: gfx.message(self.owner.name.capitalize() + ' attacks ' + target.name + ' but it has no effect!')
def handle_keys(key): #handle keyboard commands global playerx, playery #other functions if key.vk == libtcod.KEY_ENTER and key.lalt: #Alt+Enter: toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: #Escape: exit game return 'exit' #movement keys if config.game_state == 'playing': if key.vk == libtcod.KEY_UP: player_move_or_attack(0, -1) elif key.vk == libtcod.KEY_DOWN: player_move_or_attack(0, 1) elif key.vk == libtcod.KEY_LEFT: player_move_or_attack(-1, 0) elif key.vk == libtcod.KEY_RIGHT: player_move_or_attack(1, 0) else: #test for other keys key_char = chr(key.c) if key_char == 'g': #pick up an item for object in config.objects: #look for an item in the config.player's tile if object.x == config.player.x and object.y == config.player.y: if object.item: object.item.pick_up() elif object.corpse: object.corpse.pick_up() elif object.bombpart: object.bombpart.pick_up() break if key_char == 'i': #show the config.inventory chosen_item = gfx.inventory_menu('Press the key next to an item to use it, or any other to cancel.\n') if chosen_item is not None: if chosen_item.armor: chosen_item.equip_armor() elif chosen_item.weapon: chosen_item.equip_weapon() elif chosen_item.tank: chosen_item.equip_tank() elif chosen_item.headlamp: chosen_item.equip_headlamp() elif chosen_item.camo: chosen_item.equip_camo() elif chosen_item.node: chosen_item.plant_node() elif chosen_item.flare: chosen_item.drop_flare() elif chosen_item.bomb: chosen_item.bomb.plant_bomb() return 'win' if key_char == 'd': #show the config.inventory; if an item is selected, drop it chosen_item = gfx.inventory_menu('Press the key next to an item to (d)rop it, or any other to cancel.\n') if chosen_item is not None: chosen_item.drop() if key_char == 'c': #show the config.player card until config.player presses 'c' or 'esc' gfx.player_card() if key_char == 'o': #search for adjacent doors and open/close them for object in config.objects: if object.door and object.x <= config.player.x+1 and object.x >= config.player.x-1 and object.y <= config.player.y+1 and object.y >= config.player.y-1: if object.door.open: object.door.close_door() else: object.door.open_door() if key_char == 'p': #ping map using scanner for i in config.inventory: if i.item.scanner and i.item.equipped: i.item.scanner.ping(True) gfx.message('You pinged the map.', libtcod.white) config.fov_recompute = True gfx.render_all() i.item.scanner.ping(False) #ascending if key_char == ',' or key_char == '<': #move up a floor #check if on staircase for object in config.objects: if object.stairs and config.player.x == object.x and config.player.y == object.y: #config.player is on stairs if object.stairs.direction == "up": if config.current_floor==0: gfx.message('There is no escape.', libtcod.red) else: #there's a floor above, so let him ascend go_to_floor(config.current_floor-1) break elif object.stairs.direction == "down": #config.player is on downward stairs gfx.message('These stairs lead down!', libtcod.red) break #descending if key_char == '.' or key_char == '>': #move down a floor #check if on staircase for object in config.objects: if object.stairs and config.player.x == object.x and config.player.y == object.y: #config.player is on stairs if object.stairs.direction == "down": go_to_floor(config.current_floor+1) break elif object.stairs.direction == "up": #config.player is on downward stairs gfx.message('These stairs lead up!', libtcod.red) break return 'didnt-take-turn'