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 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 cast_lighting(caster, T_damage_maxrange): damage, m_range = T_damage_maxrange player_location = (caster.x, caster.y) # prompt the player for a tile point_selected = menu.tile_select(coords_origin=player_location, max_range=m_range, penetrate_walls=False) if point_selected: # convert that tile into a list of tiles between A -> B list_of_tiles = maps.find_line(player_location, point_selected) # cycle through list, damage everything found for i, (x, y) in enumerate(list_of_tiles): target = maps.check_for_creature(x, y) if target: target.creature.take_damage(damage)
def move(self, dx, dy): '''Moves the object Args: dx (int): distance to move actor along x axis dy (int): distance to move actor along y axis ''' # Is a wall if block_path is true tile_is_wall = (globalvars.GAME.current_map[self.owner.x + dx][self.owner.y +dy].block_path == True) target = maps.check_for_creature(self.owner.x + dx, self.owner.y + dy, self.owner) if target: self.attack(target) # Move if current position plus new position is not wall if not tile_is_wall and target is None: self.owner.x += dx self.owner.y += dy self.wait = self.speed
def tile_select(coords_origin=None, max_range=None, radius_box=None, radius_diamond=None, penetrate_walls=True, pierce_creature=True): ''' This menu let's the player select a tile This function pauses the game, produces an on screen rectangle and when the player presses left mb, will return (message for now) the map address. ''' menu_close = False while not menu_close: # Get mos position mouse_x, mouse_y = pygame.mouse.get_pos() # Get button click events_list = pygame.event.get() # mouse map selection mapx_pixel, mapy_pixel = globalvars.CAMERA.win_to_map( (mouse_x, mouse_y)) map_coord_x = int(mapx_pixel / constants.CELL_WIDTH) map_coord_y = int(mapy_pixel / constants.CELL_HEIGHT) valid_tiles = [] if coords_origin: full_list_tiles = maps.find_line(coords_origin, (map_coord_x, map_coord_y)) for i, (x, y) in enumerate(full_list_tiles): valid_tiles.append((x, y)) # Stop at max range if max_range and i == max_range - 1: break # Stop at wall if not penetrate_walls and globalvars.GAME.current_map[x][ y].block_path: break # TODO stop at creature if not pierce_creature and maps.check_for_creature(x, y): break else: valid_tiles = [(map_coord_x, map_coord_y)] # return map_coords when presses left mb for event in events_list: if event.type == pygame.QUIT: # QUIT attribute - someone closed window game.closegame() # If press tab again, close menu if event.type == pygame.KEYDOWN: if event.key == pygame.K_LCTRL: menu_close = True if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: # returns coordinate selected return (valid_tiles[-1]) # Draw game first globalvars.SURFACE_MAIN.fill(constants.COLOR_DEFAULT_BG) globalvars.SURFACE_MAP.fill(constants.COLOR_BLACK) globalvars.CAMERA.update() # draw the map draw.map_surface(globalvars.GAME.current_map) # draw all objects for obj in globalvars.GAME.current_objects: obj.draw() # Draw rectangle at mouse position for (tile_x, tile_y) in valid_tiles: if (tile_x, tile_y) == valid_tiles[-1]: draw.tile_rect(coords=(tile_x, tile_y), mark="X") else: draw.tile_rect(coords=(tile_x, tile_y)) if radius_box: area_effect = maps.find_radius_box(valid_tiles[-1], radius_box) for (tile_x, tile_y) in area_effect: draw.tile_rect(coords=(tile_x, tile_y), tile_color=constants.COLOR_RED, tile_alpha=150) elif radius_diamond: area_effect = maps.find_radius_diamond(valid_tiles[-1], radius_diamond) for (tile_x, tile_y) in area_effect: draw.tile_rect(coords=(tile_x, tile_y), tile_color=constants.COLOR_RED, tile_alpha=150) globalvars.SURFACE_MAIN.blit(globalvars.SURFACE_MAP, (0, 0), globalvars.CAMERA.rectangle) draw.debug() draw.messages() # Update the display pygame.display.flip() # tick the CLOCK globalvars.CLOCK.tick(constants.GAME_FPS)