Lighting

class Light(pos: List[int], radius: int, light_img: pygame.Surface, colour: Tuple[int, int, int] = (255, 255, 255), alpha: int = 255)[source]

Bases: object

Holds the attributes for the light and offers some basic interface instructions.

__init__(pos: List[int], radius: int, light_img: pygame.Surface, colour: Tuple[int, int, int] = (255, 255, 255), alpha: int = 255)[source]

Initialize self. See help(type(self)) for accurate signature.

set_alpha(alpha: int)[source]

Set the alpha value of the light. Refreshes the mask and size.

set_colour(colour: Tuple[int, int, int], override_alpha: bool = False)[source]

Set the colour of the light. Refreshes the size. If override_alpha is set to True, the alpha setting is ignored when recalculating the light. This is better for performance.

set_size(radius: int)[source]

Set the size of the light and rescale the image to match.

class LightBox(size: Tuple[int, int], blit_flags: int = 6)[source]

Bases: object

Handles the processing of Lights. The name “LightBox” comes from the idea that the lighting is only rendered within the “box” of the display.

The dimensions provided upon initialization will usually be the dimensions of your display. The blit_flags argument determines the blitting flags used in LightBox.render(). By default, it uses the adding flags which adds light values. However, other flags such as BLEND_RGBA_MULT can be used. BLEND_RGBA_MULT multiplies the destination surface by the lighting surface which results in darkening the areas that aren’t lit up instead of brightening the areas that are.

__init__(size: Tuple[int, int], blit_flags: int = 6)[source]

Initialize self. See help(type(self)) for accurate signature.

add_dynamic_walls(walls: List[scripts.engine.world_objects.lighting.Wall])str[source]

Add a dynamic wall and return the dynamic wall id. This works similarly to add_walls, it just uses a different system in the background that allows modification but performs worse.

add_light(light: scripts.engine.world_objects.lighting.Light)str[source]

Create a new light with a light object. Returns the light id.

add_walls(walls: List[scripts.engine.world_objects.lighting.Wall])[source]

Add walls to the lightbox. This is used for manual wall additions, however, typically, walls are loaded using generate_walls.

clear_walls()[source]

Delete all walls.

delete_dynamic_walls(group_id: int)[source]

Delete a group of walls.

delete_light(light_id: str)[source]

Delete a light.

get_light(light_id: str)[source]

Get a light object based on ID. Often used so that the position can then be modified.

render(target_surf: pygame.Surface, offset: Optional[List[int]] = None)[source]

The core rendering function that renders the lighting within the lightbox. The offset is used to specify the terrain offset (aka camera offset or scroll) of the game relative to the viewed area.

The target_surface is the pygame.Surface that will have the lighting rendered onto it. If it is a black surface, you get the internal lighting mask. This can be useful for static lighting. However, normally the main display surface should be used.

update_dynamic_walls(group_id: str, walls: List[scripts.engine.world_objects.lighting.Wall])[source]

Set a group_id to contain a set of walls. Existing walls can be modified directly for better performance since objects use pointers.

This is useful for overwriting the walls and takes walls in the same format as add_walls.

class Wall(p1: List[int], p2: List[int], vertical: int, direction: int, colour: Tuple[int, int, int] = (255, 255, 255))[source]

Bases: object

Handles shadow casting within a Lightbox.

__init__(p1: List[int], p2: List[int], vertical: int, direction: int, colour: Tuple[int, int, int] = (255, 255, 255))[source]

Initialize self. See help(type(self)) for accurate signature.

clone_move(offset: Tuple[int, int])scripts.engine.world_objects.lighting.Wall[source]

Create a duplicate Wall with an offset.

draw_shadow(surf: pygame.Surface, source: List[int], vision_box: pygame.Rect, colour: Tuple[int, int, int], offset: Optional[List[int]] = None)[source]

Draw a shadow, as cast by the light source.

Primarily used internally by the LightBox class, but it’s available for independent use if you want to do something crazy. In this context, light_source is point ([x, y]), not a Light object. The vision_box is just a pygame.Rect that specifies the visible area. The color is the color of the shadow. In normal use, the shadow is black and used to create a mask, but you can do some weird stuff by changing the color.

render(surf: pygame.Surface, offset: Optional[List[int]] = None)[source]

Render the line that makes up the wall. Mostly just useful for debugging.

box(pos: List[int], size: List[int])[source]

Generate a box of Walls with all walls facing outwards. The pos is the top left of the box. This list of walls can be added to a LightBox using LightBox.add_walls. Useful for custom wall generation.

generate_walls(light_box: scripts.engine.world_objects.lighting.LightBox, map_data: List[List[int]], tile_size: int)List[scripts.engine.world_objects.lighting.Wall][source]

Adds walls to the designated light box using a list of “air” (empty) tiles.

Bordering sides will be joined together to reduce the wall count. The tile locations in the map_data should be the grid positions. The positions are then multiplied by the tile_size to get the pixel positions of the tiles along with the coordinates of the sides. The returned data is just a list of Wall objects that were added to the given LightBox.

line_str(line, point)str[source]

Convert a line to a string

mult_colour(surf: pygame.Surface, colour: Tuple[int, int, int])pygame.Surface[source]

Multiply the colour given on the provided surface.

point_str(point)str[source]

Convert a point to a string

set_mask_alpha(surf: pygame.Surface, alpha: int)pygame.Surface[source]

Set the alpha of the screen mask

str_point(string: str)[source]

Convert string to point