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.

You can create a custom board by inherit one of Boars subclasses.

Examples

A pixel-board in follow_the_mouse.py:

>>>  class MyBoard(PixelBoard):
>>>
>>>  def on_setup(self):
>>>    self.add_image(path="images/stone.jpg")
>>>    Robot(position=(50, 50))
>>>
>>>
>>>  board = MyBoard(800, 600)
A tiled-board in basicframework1.py:
>>> class MyBoard(TiledBoard):
>>>
>>>   def on_setup(self):
>>>     self.add_image(path="images/soccer_green.jpg")
>>>     self.player = Player(position=(3, 4))
>>>     self.speed = 10
>>>     stone = self.add_background(("images/stone.png"))
>>>     stone.is_textured = True
>>>     stone.is_scaled_to_tile = True
>>>
>>>
>>>  board = MyBoard(columns=20, rows=8, tile_size=42, tile_margin=0)
Parameters
  • columns – columns of new board (default: 40)

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

add_background(path: str) → miniworldmaker.appearances.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.board_positions.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)

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.board_positions.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)
handle_event(event, data=None)[source]

Event handling

Parameters
  • event (str) – The event which was thrown, e.g. “key_up”, “act”, “reset”, …

  • data – The data of the event (e.g. [“S”,”s”], (155,3), …

height

See container_height

image

The current displayed image

is_position_on_board(position: miniworldmaker.board_positions.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_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.

Examples

Restarts flappy the bird game after collision with pipe:

>>> def on_sensing_collision_with_pipe(self, other, info):
>>>    self.board.is_running = False
>>>    self.board.reset()
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.appearances.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.board_positions.board_position.BoardPosition, miniworldmaker.board_positions.board_rect.BoardRect]) → 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

on_board(value: Union[tuple, miniworldmaker.board_positions.board_position.BoardPosition, miniworldmaker.board_positions.board_rect.BoardRect]) → bool[source]

Checks if position is on board

Parameters

value – A Board Position or a board rect

Returns:

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.board_positions.board_position.BoardPosition, miniworldmaker.board_positions.board_rect.BoardRect]) → 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

on_board(value: Union[tuple, miniworldmaker.board_positions.board_position.BoardPosition, miniworldmaker.board_positions.board_rect.BoardRect]) → bool[source]

Checks if position is on board

Parameters

value – A Board Position or a board rect

Returns:

Processing Board

class miniworldmaker.boards.processing_board.ProcessingBoard(width=400, height=300)[source]

A ProcessingBoard

Parameters
  • width – The width of the board in Pixels (default: 400)

  • height – The height of the board in pixels (default: 300)