scripts.engine.world_objects package¶
Submodules¶
scripts.engine.world_objects.game_map module¶
-
class
GameMap
(map_name: str, seed: Any)[source]¶ Bases:
object
Holds tiles for a map. Handles generation of the map and placement of the entities. Fills map with floors on init.
-
__init__
(map_name: str, seed: Any)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
air_tile_positions
¶ Return a copy of an array containing ints, 0 for blocked and 1 for open
-
property
block_movement_map
¶ Return a copy of an array containing ints, 0 for blocked and 1 for open
-
property
block_sight_map
¶ Return a copy of an array containing ints, 0 for blocked and 1 for open
-
classmethod
deserialise
(serialised: Dict[str, Any])[source]¶ Loads the details from the serialised data back into the GameMap.
-
generate_new_map
(player_data: Optional[scripts.engine.internal.definition.ActorData] = None)[source]¶ Generate the map for the current game map. Creates tiles. Saves the values directly to the GameMap.
-
scripts.engine.world_objects.lighting module¶
-
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.
-
-
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.
-
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.
-
mult_colour
(surf: pygame.Surface, colour: Tuple[int, int, int]) → pygame.Surface[source]¶ Multiply the colour given on the provided surface.
-
set_mask_alpha
(surf: pygame.Surface, alpha: int) → pygame.Surface[source]¶ Set the alpha of the screen mask
scripts.engine.world_objects.tile module¶
-
class
Tile
(x: int, y: int, sprite: pygame.Surface, sprite_path: str, blocks_movement: bool = False, height: HeightType = 1)[source]¶ Bases:
object
A Tile on the GameMap.
-
__init__
(x: int, y: int, sprite: pygame.Surface, sprite_path: str, blocks_movement: bool = False, height: HeightType = 1)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-