def cast_fireball_diamond(caster, T_damage_radius_range): # defs damage, local_radius, max_r = T_damage_radius_range caster_location = (caster.x, caster.y) # get target tile point_selected = menu.tile_select(coords_origin=caster_location, max_range=max_r, penetrate_walls=False, pierce_creature=False, radius_diamond=local_radius) if point_selected: # get sequence of tiles tiles_to_damage = maps.find_radius_diamond(point_selected, local_radius) creature_hit = False # damage all creatures in tiles for (x, y) in tiles_to_damage: creature_to_damage = maps.check_for_creature(x, y) if creature_to_damage: creature_to_damage.creature.take_damage(damage) if creature_to_damage is not globalvars.PLAYER: creature_hit = True if creature_hit: game.message("The monster Howls out in pain.", constants.COLOR_RED)
def pick_up(self, actor): '''The item is picked up and placed into an object's inventory. When called, this method seeks to place the item into an object's inventory if there is room. It then removes the item from a Game's current_objects list. Args: actor (ObjActor): the object that is picking up the item. ''' if actor.container: # first, checks for container component # does the container have room for this object? if actor.container.volume + self.volume > actor.container.max_volume: # if no, print error message game.message("Not enough room to pick up") else: # otherwise, pick the item up, remove from GAME.current_objects # message the player game.message("Picking up") # add to actor inventory actor.container.inventory.append(self.owner) self.owner.animation_destroy() # remove from game active list globalvars.GAME.current_objects.remove(self.owner) # tell item what container holds it self.current_container = actor.container
def main(): pygame.init() config.init() window = pygame.display.set_mode((config.width, config.width)) s = snake((255, 0, 0), (10, 10)) food = cube(game.randomFood(s), color=(0, 255, 0)) flag = True clock = pygame.time.Clock() while flag: pygame.time.delay(50) clock.tick(10) # 10 FPS s.move() if s.body[0].pos == food.pos: s.eat() food = cube(game.randomFood(s), color=(0, 255, 0)) for part in range(len(s.body)): if s.body[part].pos in list(map(lambda z: z.pos, s.body[part + 1:])): score = len(s.body) lost_message = "Score is: %d\nPlay again." % (score) print('Score: ', score) game.message("YOU LOST!", lost_message) s.reset((10, 10)) break game.redrawWindow(window, s, food)
def take_turn(self): if self.num_turns > 0: # Random direction self.owner.creature.move(libtcod.random_get_int(0, -1, 1), libtcod.random_get_int(0, -1, 1)) self.num_turns -= 1 else: self.owner.ai = self.old_ai game.message(self.owner.display_name + " has broken free!", constants.COLOR_RED)
def equip(self): # Check for equipment in slot all_equipped_items = self.owner.item.current_container.equipped_items for item in all_equipped_items: if item.equipment.slot and (item.equipment.slot == self.slot): game.message("Equipment slot is occupied", constants.COLOR_RED) return self.equipped = True game.message("item equipped")
def cast_heal(caster, value): if caster.creature.current_hp == caster.creature.max_hp: game.message(caster.creature.name_instance + " the " + caster.name_object + " is already at full health!") return "canceled" else: game.message(caster.creature.name_instance + " the " + caster.name_object + " healed for " + str(value) + " health!") caster.creature.heal(value) return None
def cast_confusion(caster, effect_length): # Select tile point_selected = menu.tile_select() # Get target if point_selected: tile_x, tile_y = point_selected target = maps.check_for_creature(tile_x, tile_y) # Temporarily confuse the target if target: oldai = target.ai target.ai = ai.Confuse(old_ai=oldai, num_turns=effect_length) target.ai.owner = target game.message("The creature's eyes glaze over", constants.COLOR_GREEN)
def attack(self, target): '''Creature makes an attack against another ObjActor Args: target (ObjActor): target to be attacked, must have creature component. damage (int): amount of damage to be done to target ''' damage_delt = self.power - target.creature.defense if damage_delt > 0 and self.owner is globalvars.PLAYER: pygame.mixer.Sound.play(globalvars.RANDOM_ENGINE.choice(globalvars.ASSETS.snd_list_hit)) if damage_delt < 0: damage_delt = 0 if self.owner is globalvars.PLAYER and globalvars.PLAYER.creature.xp <= 0 and target.name_object == 'mouse': game.message(f"Attacked {target.creature.name_instance} without xp!", constants.COLOR_RED) game.message(f"{target.creature.name_instance} gets angry and attacks you!", constants.COLOR_RED) target.creature.take_damage(damage_delt) self.current_hp -= 6 else: game.message(f"{self.name_instance} attacks {target.creature.name_instance} for {str(damage_delt)} damage!", constants.COLOR_WHITE) target.creature.take_damage(damage_delt) self.wait = self.attack_speed
def drop(self, new_x, new_y): '''Drops the item onto the ground. This method removes the item from the actor.container inventory and places it into the GAME.current_objects list. Drops the item at the location defined in the args. Args: new_x (int): x coord on the map to drop item new_y (int): y coord on the map to drop item ''' # add this item to tracked objects globalvars.GAME.current_objects.insert(-1, self.owner) self.owner.animation_init() # remove from the inventory of whatever actor holds it self.current_container.inventory.remove(self.owner) # set item location to as defined in the args self.owner.x = new_x self.owner.y = new_y # confirm successful placement with game message game.message("Item dropped!")
def take_turn(self): if self.num_turns > 0: game.message('%s is confused' % self.owner.name) op = get_closest_monster(self.owner, game_instance.player) if self.owner.distance_to(op) >= 2: self.owner.move_towards(op.x, op.y) else: game.message('%s attacks %s in his confusion' % (self.owner.name, op.name)) if self.owner.fighter: self.owner.fighter.attack(op) if op.fighter: op.fighter.attack(self.owner) self.num_turns -= 1 else: self.owner.ai = self.old_ai game.message('%s is no longer confused' % self.owner.name)
def unequip(self): self.equipped = False game.message("item unequipped")
def take_damage(self, damage): """Applies damage received to self.health This function applies damage to the ObjActor with the creature component. If the current health level falls below 1, executes the death_function. Args: damage (int): amount of damage to be applied to self. """ # subtract health if damage < 0: damage = 0 self.current_hp -= damage if self.current_hp < 0: self.current_hp = 0 # print message game.message(f"{self.name_instance}'s health is {str(self.current_hp)}/{str(self.max_hp)}.", constants.COLOR_RED) # if health now equals < 1, execute death function if self.current_hp <= 0: if self.death_function is not None: self.death_function(self.owner) # if death obj is not the player if self.owner != globalvars.PLAYER: # Player gets xp globalvars.PLAYER.creature.xp += self.xp # If the one who died is a mouse if self.owner.name_object == 'mouse': # If player is not full hp if globalvars.PLAYER.creature.current_hp != globalvars.PLAYER.creature.max_hp: # Recover some xp because he needed to kill mouse globalvars.PLAYER.creature.xp += 1 # If player xp is less than 0 if globalvars.PLAYER.creature.xp < 0: # If player level is 0 if globalvars.PLAYER.level == 0: globalvars.PLAYER.creature.xp = 0 # If player level is more than 0 else: globalvars.PLAYER.level -= 1 # Get random number and lower some stat num = libtcod.random_get_int(0,0,2) if num == 0: globalvars.PLAYER.creature.max_hp -= 5 if num == 1: globalvars.PLAYER.creature.base_atk -= 5 if num == 2: globalvars.PLAYER.creature.base_def -= 5 game.message(f"{self.name_instance} has weakened because it has dropped a level!", constants.COLOR_RED) globalvars.PLAYER.creature.xp = 0 game.check_level_up()