world module
World package.
world.camera
Module name: camera
-
class game.world.camera.Camera(speed: int = 50)
Bases: object
Class for creating a camera.
The camera position is strictly relative to the center of the screen.
-
reset() → None
Reset the camera’s general properties.
-
update(game) → None
Update the camera.
world.map_manager
Module name: map_manager
This module manages the generation, data and updates of the world map.
-
class game.world.map_manager.Map(width: int, height: int)
Bases: object
Class for creating a Map.
-
SEED_CHARS: str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
-
SEED_LENGTH: int = 64
-
compress_dynatile_data() → Self
Compress the map’s dynatile data, then return the map manager itself.
-
compress_tile_data() → Self
Compress the map’s tile data, then return the map manager itself.
-
decompress_dynatile_data(ext_bytes_obj: bytes | None = None) → bytes | Self
Decompress the map’s dynatile data.
Return the decompressed dynatile data if external bytes object is provided, otherwise the map manager itself.
-
decompress_tile_data() → Self
Decompress the map’s tile data, then return the map manager itself.
-
draw_tile(tile_x: int, tile_y: int, tile: Tile | int) → Self
Draw a specific tile to the screen at specified x and y tile positions, then return the map manager itself.
-
generate() → None
Generate the map data.
-
get_compressed_dynatile_data() → bytes
Return the map’s compressed dynatile data.
-
get_compressed_tile_data() → bytes
Return the map’s compressed tile data.
-
get_dynatile(tile_x: int, tile_y: int, ext_bytes_obj: bytes = b'') → bool
Return the dynamic tile state at specified x and y tile positions.
Extract from an external compatible bytes object if one is given.
-
get_dynatile_data() → bytes
Get the map’s dynamic tile data.
-
get_dynatile_surface() → pygame.Surface
Return the map’s dynamic surface.
-
get_height_in_pixels() → int
Return the height of the map in pixels.
-
get_height_in_tiles() → int
Return the height of the map in tiles.
-
get_seed() → str
Return the map seed.
-
static get_size_from_property(_property: str) → tuple[int, int]
Return the appropriate map size (width, height) from the provided map property string value.
-
get_state() → tuple[str, int]
Return the state of the map manager.
-
get_strict_tile_pos(x: int, y: int) → tuple[int, int]
Return the strict tile position of a world position
-
get_surface() → pygame.Surface
Return the map’s surface.
-
get_tile(tile_x: int, tile_y: int) → Tile
Return the tile at specified x and y tile positions.
-
get_tile_data() → bytes
Return the map’s tile data.
-
get_tile_pos(x: int, y: int) → tuple[int, int]
Return the tile position of a world position.
-
get_width_in_pixels() → int
Return the width of the map in pixels.
-
get_width_in_tiles() → int
Return the width of the map in tiles.
-
get_x() → int
Return the x position of the map.
-
get_y() → int
Return the y position of the map.
-
initialise() → None
Initialise the map manager.
-
load() → None
Decompress and draw the map tiles to the surface.
-
randomise_seed() → Self
Randomise the map seed, then return the map manager itself.
-
regenerate(_seed: str, theme: dict) → None
Regenerate the map data.
-
set_compressed_dynatile_data(compressed_dynatile_data: bytes) → Self
Set the map’s compressed dynatile data, then return the map manager itself.
The provided compressed dynatile data must be of same origin as that generated from the map manager’s
dynatile data compression method.
-
set_compressed_tile_data(compressed_tile_data: bytes) → Self
Set the map’s compressed tile data, then return the map manager itself.
The provided compressed tile data must be of same origin as that generated from the map manager’s
tile data compression method.
-
set_dynatile(tile_x: int, tile_y: int, tile_state: bool) → Self
Set the dynamic tile at specified x and y tile positions and of specified used state (bool), then return
the map manager itself.
-
set_dynatile_data(dynatile_data: bytes)
Set the map’s dynamic tile data, then return the map manager itself.
-
set_seed(_seed: str) → Self
Set the map seed, then return the map manager itself.
-
set_size_in_tiles(width: int, height: int) → Self
Set the width and height of the map in tiles, then return the map manager itself.
-
set_state(state: str = '', value: int = 0) → Self
Set the state of the map manager, then return the map manager itself.
-
set_tile(tile_x: int, tile_y: int, tile: Tile | int) → Self
Set the tile at specified x and y tile positions and of specified tile type, then return the map manager itself.
-
set_tile_data(tile_data: bytes) → Self
Set the map’s tile data, then return the map manager itself.
-
set_x(x: int) → Self
Set the x position of the map, then return the map manager itself.
-
set_y(y: int) → Self
Set the y position of the map, then return the map manager itself.
-
tile_to_screen_pos(game, tile_x: int, tile_y: int) → tuple[int, int]
Return the screen position of a tile position.
-
tile_to_world_pos(tile_x: int, tile_y: int) → tuple[int, int]
Return the world position of a tile position.
-
update(new_dynatile_data: bytes) → None
Update the old dynatile data with new dynatile data.
Only update the differences between the two.
world.synth
Synth package.
world.synth.noise
Module name: noise
This module defines the noise algorithm for the map generation.
-
class game.world.synth.noise.PerlinNoise
Bases: object
Class for creating an instance of the perlin noise algorithm.
-
FREQ_ALTER_RANGE = 0.04
-
MAX_HEIGHT = 0
-
MIN_HEIGHT = 0
-
NOISE_INTENSITY_RANGE = 65536
-
static cosine_interpolate(a: float, b: float, x: float) → float
Cosine interpolation.
-
generate(x: int, y: int) → int
Generate and return perlin noise data.
-
get_frequency() → float
Return the frequency.
-
get_noise_intensity() → int
Return the noise intensity.
-
get_permutations() → list | tuple
Return the permutations.
-
interpolate_noise(x: float, y: float) → float
Interpolate noise.
-
noise(x: int, y: int) → float
Noise function.
-
set_frequency(frequency: float)
Set the frequency.
-
set_noise_intensity(noise_intensity: int)
Set the noise intensity.
-
set_permutations(permutations: list | tuple) → None
Set the permutations.
-
smooth_noise(x: int, y: int) → float
Smooth noise function.
world.theme_manager
Module name: theme_manager
This module manages the world generation theme, as well as generating the default themes JSON file.
-
class game.world.theme_manager.ThemeManager
Bases: object
Class for creating the theme manager.
-
THEMES_FILE = 'themes.json'
-
static check_themes() → None
Check the themes directory and its files.
-
static create_default_themes() → None
Create the default world themes files.
-
static get_theme_by_id(theme_id: int) → dict
Return the theme dict from the themes file by theme name.
-
static get_theme_names() → list
Retrieve and return the different theme names that exist as a list.
-
static get_themes() → dict
Retrieve and return the themes JSON data from the themes file as a dict object.
-
static init_themes() → None
Initialise the world themes.
world.tile_manager
Module name: tile_manager
This module is responsible for rendering the tiles to the map surface.
-
class game.world.tile_manager.TileManager
Bases: object
Class for creating a tile manager.
-
draw(x: int, y: int, tile: Tile | int, screen: pygame.Surface) → None
Draw a tile to the screen.
-
set_atlas(atlas_file: str) → None
Set the texture atlas.
world.world
Module name: world
This module manages all world-related logic and functionalities.
-
class game.world.world.World(map_width: int, map_height: int)
Bases: object
Class for creating a world.
-
create(seed: str, theme: dict) → None
Create the world.
-
draw(game) → None
Draw the world (map, tiles, etc.).
-
draw_wireframe(screen) → None
Draw the wireframe of the world.
-
get_map() → Map
Return the map.
-
initialise() → None
Initialise the world.
-
set_map(_map: Map) → Self
Set the map, and return the world object itself.