def apply_damage(self, grid_x, grid_y, amount, results): pixel_x, pixel_y = char_to_pixel(grid_x, grid_y) sprites = arcade.get_sprites_at_point( (pixel_x, pixel_y), self.game_engine.cur_level.creatures) for sprite in sprites: if sprite.fighter and not sprite.is_dead: results.extend([{ "message": f"{sprite.name} was struck by a fireball for {amount} points." }]) result = sprite.fighter.take_damage(amount) if result: results.extend(result)
def recalculate_fov(char_x: int, char_y: int, radius: int, sprite_lists: List[arcade.SpriteList[Entity]]): for sprite_list in sprite_lists: for sprite in sprite_list: if sprite.is_visible: sprite.is_visible = False sprite.color = sprite.not_visible_color if len(sprite.color) == 4: sprite.alpha = sprite.not_visible_color[3] resolution = 12 circumference = 2 * math.pi * radius radians_per_point = 2 * math.pi / (circumference * resolution) point_count = int(round(circumference)) * resolution for i in range(point_count): radians = i * radians_per_point x = math.sin(radians) * radius + char_x y = math.cos(radians) * radius + char_y raychecks = radius for j in range(raychecks): v1 = char_x, char_y v2 = x, y x2, y2 = arcade.lerp_vec(v1, v2, j / raychecks) x2 = round(x2) y2 = round(y2) pixel_point = char_to_pixel(x2, y2) blocks = False for sprite_list in sprite_lists: sprites_at_point = arcade.get_sprites_at_exact_point( pixel_point, sprite_list) # checks += 1 sprite: Entity for sprite in sprites_at_point: sprite.is_visible = True if sprite.block_sight: blocks = True if blocks: break for sprite_list in sprite_lists: for sprite in sprite_list: if sprite.is_visible: sprite.color = sprite.visible_color if len(sprite.color) == 4: sprite.alpha = sprite.visible_color[3]
def draw_in_select_location_state(self): # If mouse hasn't been over the window yet, return None if self.mouse_position is None: return mouse_x, mouse_y = self.mouse_position grid_x, grid_y = pixel_to_char(mouse_x, mouse_y) center_x, center_y = char_to_pixel(grid_x, grid_y) arcade.draw_rectangle_outline( center_x, center_y, SPRITE_WIDTH, SPRITE_HEIGHT, arcade.color.LIGHT_BLUE, 2, )
def get_blocking_sprites( x: int, y: int, sprite_list: arcade.SpriteList) -> Optional[arcade.SpriteList]: """ Given an x,y grid location, return list of sprites that block movement. """ px, py = char_to_pixel(x, y) sprite_list = arcade.get_sprites_at_exact_point((px, py), sprite_list) blocking_sprite_list = arcade.SpriteList() for sprite in sprite_list: if isinstance(sprite, Entity): if sprite.blocks: blocking_sprite_list.append(sprite) else: raise TypeError("Sprite is not an instance of Entity.") if len(blocking_sprite_list) > 0: return blocking_sprite_list else: return None
def y(self, value): self._y = value self.center_x, self.center_y = char_to_pixel(self._x, self._y)