Board -> TiledBoard
Contents
Board -> TiledBoard#
TiledBoard is a child class of Board
TiledBoard#
- class miniworldmaker.boards.board_templates.tiled_board.tiled_board.TiledBoard(view_x=20, view_y=16, tile_size=40, empty=False)[source]#
from typing A TiledBoard is a Board where each Token is placed in one Tile.
With Tiled Board, you can realize RPGs and Boardgames.
Each Token on a TiledBoard can be placed on a Tile, on a Corner between Tiles or on an Edge between Tiles.
Examples
Create Token on Tile, Corner and Edge:
from miniworldmaker import * board = TiledBoard(6, 3) board.grid = True last_corner = None tile = Tile((1,1)) t1 = Token() t1.center = tile.position t1.fill_color = (255,255,255) corner = Corner((3,1), "nw") t2 = Token() t2.center = corner.position t2.fill_color = (255,0,0) edge = Edge((5,1), "w") t3 = Token() t3.center = edge.position t3.fill_color = (0,0,255) t3.size = (0.2,1) t3.direction = edge.angle board.run()
Public Data Attributes:
Displays grid overlay on background.
Inherited from
Board
speed
speed defines how often the method
act()
will be called.fps
Frames per second shown on the screen.
width
Gets width of board in pixels.
height
Gets height of board in pixels.
boundary_x
The x-boundary (defaults to view_size)
boundary_y
The y-boundary (defaults to view_size)
viewport_width
viewport_height
The y-boundary (defaults to view_size)
columns
rows
camera_x
camera_y
tile_size
Tile size of each tile, if board has tiles
size
Set the size of board
default_fill_color
Set default fill color for borders and lines
default_is_filled
default_stroke_color
Set default stroke color for borders and lines.
default_border_color
Set default border color for borders and lines.
default_border
Sets default border color for tokens
tokens
A list of all tokens registered to the board.
backgrounds
Returns all backgrounds of the board as list.
background
Returns the current background
container_width
The width of the container
container_height
The height of the container
has_background
registered_events
image
The current displayed image
fill_color
color
Inherited from
BaseBoard
subclasses
surface
class_name
window
Gets the parent window
Inherited from
Container
surface
container_width
The width of the container
container_height
The height of the container
window
Gets the parent window
size
Set the size of board
rect
topleft
window_docking_position
width
Gets width of board in pixels.
height
Gets height of board in pixels.
Public Methods:
__init__
([view_x, view_y, tile_size, empty])Initializes the TiledBoard
Removes all tiles, coners and edges from Board
In this method, corners and edges are created.
add_tile_to_board
(position)add_corner_to_board
(position, direction)add_edge_to_board
(position, direction)get_tile
(position)Gets Tile at Position.
detect_tokens
(position)Gets all tokens which are found at a specific position.
get_tokens_from_pixel
(position)get_corner
(position[, direction])Gets Corner at Position.
get_edge
(position[, direction])Gets Edge at Position.
is_position_on_the_board
(position)Returns True if a position is on the board.
borders
(value)Returns the Board's borders, if token is near a Border.
detect_tokens_at_position
(position)Sensing tokens at same position
detect_token_at_position
(position)Sensing single token at same position
draw_on_image
(image, position)get_from_pixel
(position)Gets board position from pixel coordinates
get_from_pixel
(position)Gets board position from pixel coordinates
get_tile_from_pixel
(position)Gets nearest Tile from pixel
is_edge
(position)Returns True, if position is a edge.
is_corner
(position)Returns True, if position is a corner.
is_tile
(position)Returns True, if position is a tile.
to_pixel
(position[, size, origin])Converts BoardPosition to pixel coordinates
Inherited from
Board
__init__
([view_x, view_y, tile_size])Checks if position is on the board.
Checks if position is on the board.
Checks if position is on the board.
contains_rect
(rect)Detects if rect is completely on the board.
borders
(value)Gets all borders from a source (Position or Rect).
set_tile_size
(value)default_fill
(value)Set default fill color for borders and lines
Returns the current background
switch_background
(background)Switches the background
remove_background
([background])Removes a background from board
set_background
(source)Adds a new background to the board
add_background
(source)Adds a new background to the board
start
()Starts the board, if board is not running.
stop
([frames])Stops the board.
clear
()Alias of
clean
clean
()removes all tokens
run
([fullscreen, fit_desktop, replit, ...])The method show() should always be called at the end of your program.
play_sound
(path)plays sound from path
play_music
(path)plays a music from path
stops a music
Gets the current mouse_position
Gets x-coordinate of mouse-position
Gets y-coordinate of mouse-position
gets mouse-position of last frame
Returns True, if mouse is pressed
Returns True, if mouse left button is pressed
Returns True, if mouse right button is pressed
send_message
(message[, data])Sends broadcast message
quit
([exit_code])quits app and closes the window
reset
()Resets the board Creates a new board with init-function - recreates all tokens and actors on the board.
switch_board
(new_board)Switches to another board
get_color_from_pixel
(position)Returns the color at a specific position
get_from_pixel
(position)Gets Position from pixel
Alias for get_from_pixel
to_pixel
(position)on_setup
()Overwrite or register this method to call on_setup-Actions
__str__
()Return str(self).
add_to_board
(token, position)Adds a Token to the board.
detect_tokens
(position)Gets all tokens which are found at a specific position.
detect_tokens
(position)Gets all tokens which are found at a specific position.
get_tokens_from_pixel
(pixel)repaint
()Implemented in subclasses
update
()The mainloop, called once per frame.
handle_event
(event[, data])Event handling
register
(method)Used as decorator e.g.
unregister
(method)direction
(point1, point2)distance_to
(pos1, pos2)direction_to
(pos1, pos2)- rtype
Inherited from
BaseBoard
__init__
()get_token_connector
(token)- rtype
TokenConnector
add_container
(container, dock[, size])add_board
(position, board[, width])remove_container
(container)load_board_from_db
(file)Loads a sqlite db file.
load_tokens_from_db
(file, token_classes)Loads all tokens from db.
save_to_db
(file)Saves the current board an all actors to database.
screenshot
([filename])Creates a screenshot in given file.
get_background
()Implemented in subclass
get_columns_by_width
(width)get_rows_by_height
(height)Inherited from
Container
__init__
()on_change
()implemented in subclasses
add_to_window
(app, dock[, size])update_width_and_height
()repaint
()Implemented in subclasses
blit_surface_to_window_surface
()remove
()Implemented in subclasses
handle_event
(event, data)get_event
(event, data)Implemented in subclasses
is_in_container
(x[, y])- rtype
position_is_in_container
(pos)- rtype
update
()Implemented in subclasses
get_local_position
(position)- rtype
Private Data Attributes:
_abc_impl
Inherited from
Board
_abc_impl
Inherited from
BaseBoard
_abc_impl
Inherited from
ABC
_abc_impl
Private Methods:
_get_tile_factory
()_get_camera_manager_class
()_templates
()Returns Classes for Tile, Edge and Corner
_setup_tiles
()Adds Tile to Board for each BoardPosition
_setup_corners
()Add all Corner to Board for each Tile.
_setup_edges
()Add all Edges to Board for each Tile
_get_token_connector_class
()needed by get_token_connector in parent class
_update_token_positions
()Updates the dynamic_tokens_dict.
Inherited from
Board
_create_event_manager
()_act_all
()Overwritten in subclasses, e.g.
_tick_timed_objects
()Inherited from
BaseBoard
_get_camera_manager_class
()_get_token_connector_class
()needed by get_token_connector in parent class
- __init__(view_x=20, view_y=16, tile_size=40, empty=False)[source]#
Initializes the TiledBoard
- Parameters
view_x – The number of columns
view_y – The number of rows
empty – The board has no tiles, edges, and corners. They must be created manually
- clear_tiles()[source]#
Removes all tiles, coners and edges from Board
Instead of clearing the board, you can add the parameter empty to Board to create a new Board from scratch.
Examples
Clear and re-create board:
from miniworldmaker import * board = HexBoard(8, 8) @board.register def on_setup(self): self.clear_tiles() center = HexTile((4, 4)) for x in range(self.columns): for y in range(self.rows): if center.position.distance((x, y)) < 2: tile = self.add_tile_to_board((x, y)) tt = Token() t.center = tile.position board.run()
Create a new board from scratch
Note
This variant is faster, because Tiles are not created twice
from miniworldmaker import * board = HexBoard(8, 8, empty=True) @board.register def on_setup(self): center = HexTile((4, 4)) for x in range(self.columns): for y in range(self.rows): if center.position.distance((x, y)) < 2: tile = self.add_tile_to_board((x, y)) tile.create_token() board.run()
- detect_token_at_position(position)[source]#
Sensing single token at same position
Faster than sensing_tokens, but only the first found token is recognized.
- detect_tokens(position)[source]#
Gets all tokens which are found at a specific position.
- Parameters
position – Position, where tokens should be searched.
- Returns
A list of tokens
Examples
Get all tokens at mouse position:
position = board.get_mouse_position() tokens = board.get_tokens_by_pixel(position)
- get_board_position_from_pixel(position)#
Gets board position from pixel coordinates
- get_corner(position, direction=None)[source]#
Gets Corner at Position.
Raises CornerNotFoundError, if Tile does not exists.
Examples
Get corner from token:
corner = board.get_corner(token.position)
Get corner from board-position and direction
from miniworldmaker import * from miniworldmaker import * board = TiledBoard(6, 3) board.grid = True last_corner = None corner = Corner((3,1), "nw") t2 = Token() t1.center = corner.position t2.fill_color = (255,0,0) corner=board.get_corner((3,1),"nw") assert(corner.get_tokens()[0] == t2) board.run()
- Parameters
position – Position on Board
direction – if direction is not None, position is interpreted as tile-board-position
- Returns
next corner, if position exists
- get_edge(position, direction=None)[source]#
Gets Edge at Position.
Raises EdgeNotFoundError, if Tile does not exists.
Examples
Get edge from token:
tile = board.get_edge(token.position)
Get edge from board-position and direction
from miniworldmaker import * board = TiledBoard(6, 3) board.grid = True last_corner = None edge=board.get_edge((5,1),"w") assert(edge.get_tokens()[0] == t3) board.run()
- Parameters
position – Position on Board
- Returns
Edge on Posiiton, if position exists
- get_tile(position)[source]#
Gets Tile at Position.
Raises TileNotFoundError, if Tile does not exists.
Examples
Get tile from token:
tile = board.get_tile(token.position)
Full example:
from miniworldmaker import * board = TiledBoard(6, 3) board.grid = True last_corner = None tile = Tile((1,1)) t1 = Token() t1.center = tile.position t1.fill_color = (255,255,255) tile=board.get_tile((1,1)) assert(tile.get_tokens()[0] == t1) board.run()
- Parameters
position (<module 'miniworldmaker.positions.position' from '/home/andreas/.local/lib/python3.10/site-packages/miniworldmaker/positions/position.py'>) – Position on Board
- Returns
Tile on Posiiton, if position exists
- property grid#
Displays grid overlay on background.