Boards

Inheritance diagram of miniworldmaker.boards.pixel_board.PixelBoard, miniworldmaker.boards.tiled_board.TiledBoard

Board

class miniworldmaker.boards.board.Board(columns: int = 40, rows: int = 40, tile_size=1, tile_margin=0)[source]

Base Class for Boards

Parameters
  • columns – columns of new board (default: 40)

  • rows – rows of new board (default:40)

add_background(path: str) → miniworldmaker.boards.background.Background[source]

Adds a new background to the board

Parameters

path – The path to the first image of the background

Returns:

add_image(path: str) → int[source]

Adds image to current background. If no background is created yet, a new background will be created with this image.

Parameters

path – The path to the image as relative path

Returns

The index of the image.

Examples

>>> class MyBoard(Board):
>>>     def __init__(self):
>>>         super().__init__(columns=400, rows=200)
>>>         self.add_image(path="images/stone.jpg")
Creates Board with file stone.jpg in folder images as background
add_to_board(token, position: miniworldmaker.boards.board_position.BoardPosition)[source]

Adds an actor to the board. Is called in __init__-Method if position is set.

Parameters
  • board – The board, the actor should be added

  • position – The position on the board where the actor should be added.

columns

The number of columns

container_height

Gets the height of the container

Returns

The height of the container (in pixels on a PixelGrid; in Tiles on a TiledGrid)

container_width

Gets the width of the container

Returns

The width of the container (in pixels on a PixelGrid; in Tiles on a TiledGrid)

default_token_speed = None

default speed for tokens

fill(color)[source]

deprecated :param color:

Returns:

fps

The world speed. The world speed is counted in fps (frames per second).

classmethod from_db(file)[source]

Loads a sqlite db file.

Parameters

file

Returns:

get_colors_at_line(line: list)[source]

Gets all colors in a line. A line is a list of board_positions

Parameters

line – the line

Returns: A list of all colors found at the line

get_mouse_position() → Optional[miniworldmaker.boards.board_position.BoardPosition][source]

Gets the current mouse_position

Returns

Returns the mouse position if mouse is on board. Returns “None” otherwise

Examples

This example shows you how to use the mouse_position

>>> def act(self):
>>>     mouse = self.board.get_mouse_position()
>>>     if mouse:
>>>         self.point_towards_position(mouse)
get_tokens_at_rect(rect: pygame.Rect, singleitem=False, exclude=None, token_type=None) → Union[miniworldmaker.tokens.token.Token, list][source]

Gets all Tokens which are colliding with a given rect.

Parameters
  • rect – The rect

  • singleitem – Should the method return a single token (faster) or all tokens at rect (slower)

  • exclude – Exclude a token

  • token_type – Filter return values by token type

Returns: A single token or a list of tokens at rect

get_tokens_by_pixel(pixel: tuple) → list[source]

Gets all tokens by Pixel.

Parameters

pixel – the pixel-coordinates

Returns

A list of tokens

Examples

>>> position = board.get_mouse_position()
>>> tokens = board.get_tokens_by_pixel(position)
height

See container_height

image

The current displayed image

is_position_on_board(position: miniworldmaker.boards.board_position.BoardPosition) → bool[source]

Tests if area or position is on board

Parameters

position – A rectangle or a position

Returns

true, if area is in grid

play_music(path: str)[source]

plays a music by path

Parameters

path – The path to the music

Returns:

register_event_handlers()[source]

Add an event handler for every registered submethod Returns:

register_sound(path) → Sound[source]

Registers a sound effect to board-sound effects library :param path: The path to sound

Returns: the sound

remove_tokens_from_rect(rect: Union[tuple, pygame.Rect], token=None, exclude=None)[source]

Removes all tokens in an area

Parameters
  • rect – A rectangle or a tuple (which is automated converted to a rectangle with tile_size

  • token – The class of the tokens which should be removed

  • exclude – A token which should not be removed e.g. the actor itself

Returns: all tokens in the area

reset()[source]

Resets the board Creates a new board with init-function - recreates all tokens and actors on the board.

Returns

The newly created and reseted board

rows

The number of rows

save_to_db(file)[source]

Saves the current board an all actors to database. The file is stored as db file and can be opened with sqlite.

Parameters

file – The file as relative location

Returns:

show(fullscreen=False)[source]

The method show() should always called at the end of your program. It starts the mainloop.

Examples

>>> my_board = Board() # or a subclass of Board
>>> my_board.show()
switch_background(index=-1) → miniworldmaker.boards.background.Background[source]

Switches the background

Parameters

index – The index of the new costume. If index=-1, the next costume will be selected

Returns: The new costume

tile_margin

The number of columns

tile_size

The number of columns

tokens

A list of all tokens registered to the grid.

width

See container_width

window

Gets the parent window

Returns

The window

PixelBoard

class miniworldmaker.boards.tiled_board.TiledBoard(columns: int = 20, rows: int = 16, tile_size=42, tile_margin=0)[source]
__init__(columns: int = 20, rows: int = 16, tile_size=42, tile_margin=0)[source]

Initializes the TiledBoard

Parameters
  • columns – The number of columns

  • rows – The number of rows

  • tile_size – The size of a tile

  • tile_margin – The margin between tiles

add_to_board(token, position)[source]

Adds token to board. This method is called with token.__init__ :param token: :param position:

Returns:

borders(value: Union[tuple, miniworldmaker.boards.board_position.BoardPosition, pygame.Rect]) → list[source]
Parameters

value

Returns:

static get_neighbour_cells(position: tuple) → list[source]

Gets a list of all neighbour cells

Parameters

position – the position

Returns

a list of all neighbour cells

TiledBoard

class miniworldmaker.boards.tiled_board.TiledBoard(columns: int = 20, rows: int = 16, tile_size=42, tile_margin=0)[source]
__init__(columns: int = 20, rows: int = 16, tile_size=42, tile_margin=0)[source]

Initializes the TiledBoard

Parameters
  • columns – The number of columns

  • rows – The number of rows

  • tile_size – The size of a tile

  • tile_margin – The margin between tiles

add_to_board(token, position)[source]

Adds token to board. This method is called with token.__init__ :param token: :param position:

Returns:

borders(value: Union[tuple, miniworldmaker.boards.board_position.BoardPosition, pygame.Rect]) → list[source]
Parameters

value

Returns:

static get_neighbour_cells(position: tuple) → list[source]

Gets a list of all neighbour cells

Parameters

position – the position

Returns

a list of all neighbour cells

BoardPosition

class miniworldmaker.boards.board_position.BoardPosition[source]

A BoardPosition Object represents a position on a Board.

As a subclass of namedtuple, BoardPosition is for performance reasons not mutable.

On a tiled board, the BoardPosition does not describe pixels but tiles coordinates.

add(x, y)[source]

Adds x and y to the board positions x and y coordinate

Returns: The new BoardPosition

borders()[source]

Gets borders of a board-position

Returns:

color()[source]

Returns the board-color at the current board-position

Returns: The board-color at the current board position as tuple with r,g,b value and transparency (e.g. (255, 0, 0, 100)

down(value: int)[source]

Gets the board position below the actual board-position

Parameters

value – the number of fields below the actual position

Returns

A new BoardPosition

classmethod from_float(float_position: tuple)[source]

Gets a board_position from float and convert the float values into integer. If you don’t want the position converted into a integer-value, use from_tuple

Parameters

float_position – Float position

Returns:

classmethod from_pixel(position: tuple)[source]

Gets the board_position from pixel coordinates

If the board is a pixel-board, pixel-position and board_position are the same

Parameters

position – The board position as pixel-coordinates

Returns:

classmethod from_tuple(tpl: tuple)[source]

Gets a board position from tuple.

Parameters

tpl – The tuple

Returns:

is_on_board()[source]

Checks if BoardPosition is on board

Returns

True, if Position is on board.

left(value: int)[source]

Gets the board position left of the the actual board-position

Parameters

value – the number of fields left of the the actual position

Returns

A new BoardPosition

near(other, distance)[source]

Checks if two Board-Positions are near each other

Parameters
  • other – A second Board-Position.

  • distance – The size of the environment in which 2 positions are called “near”.

Returns

True, If the Positions are near each other.

right(value: int)[source]

Gets the board position right of the actual board-position

Parameters

value – the number of fields right of the actual position

Returns

A new BoardPosition

to_pixel() → tuple[source]
Converts board_position to pixel-coordinates.
  • If the board is a PixelBoard, these are the same values.

  • If the board is a TiledBoard, the top-left corner of a tile is returned.

Returns:

to_rect(rect: pygame.Rect = None) → miniworldmaker.boards.board_rect.BoardRect[source]

Converts a board position into a rect. The board_position is at the top-left corner of the rect.

Parameters
  • rect – The rect dimensions (x and y coordinates are ignored. If rect is None,

  • board.tile_size is used instead. (the) –

Returns: The rect at the given position

to_tuple()[source]

Converts board_position into a tuple (x, y)

Returns: The boar

up(value: int)[source]

Gets the board position above the actual board-position

Parameters

value – the number of fields above the actual position

Returns

A new BoardPosition