Contents

Boards: Physicsboard

Contents

Boards: Physicsboard

PhysicsBoard is a child class of Board

classDiagram BaseBoard <|-- Board Board <|-- PixelBoard BaseBoard <|-- TiledBoard PixelBoard <|-- PhysicsBoard class BaseBoard{ } class Board{ } class PixelBoard{ } class TiledBoard{ } class PhysicsBoard{ }

TiledBoard

class miniworldmaker.boards.physics_board.PhysicsBoard(columns=40, rows=40)[source]

A PhysicsBoard is a playing field on which objects follow physical laws.

The PhysicsBoard itself defines some values with which the physics engine can be influenced, e.g. the gravity in the world.

All tokens on a PhysicsBoard have an attribute token.physics, with which you can change the physical properties of the object.

Public Data Attributes:

accuracy

Sets number of physics-steps performed in each frame.

gravity

Defines gravity in physics board.

damping

Amount of simple damping to apply to the space.

Inherited from : py: class: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.

rows

The number of rows

columns

The number of columns

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.

background

Returns the background of board.

Inherited from : py: class:BaseBoard

subclasses

container_width

The width of the container

container_height

The height of the container

has_background

bool

window

Gets the parent window

class_name

str

registered_events

set

image

The current displayed image

tile_size

Tile size of each tile, if board has tiles

Inherited from : py: class:Container

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

window_docking_position

width

Gets width of board in pixels.

height

Gets height of board in pixels.

Public Methods:

__init__([columns, rows])

get_physics_collision_methods_for_token(token)

Gets all collision methods for token

register_all_physics_collision_managers_for_token(token)

Registers on__touching and on_seperation-Methods to token.

register_touching_method(method)

Registers on_touching_[class] method

register_separate_method(method)

Registers on_separation_from_[class] method

remove_token_from_board(token)

Removes token from board and removes pymunk body and shapes.

act_all()

Handles acting of tokens - Calls the physics-simulation in each frame.

simulate_all_physics_tokens()

Iterates over all tokens and process physics-simulation

pymunk_touching_collision_listener(arbiter, ...)

Handles collisions - Handled by pymunk engine

pymunk_separation_collision_listener(...)

Handles collisions - Handled by pymunk engine

Inherited from : py: class:Board

default_fill(value)

Set default fill color for borders and lines

switch_background(background)

Switches the background of board

remove_background([background])

Removes a background from 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 called at the end of your program.

play_sound(path)

plays sound from path

play_music(path)

plays a music from path

get_mouse_position()

Gets the current mouse_position

get_mouse_x()

Gets x-coordinate of mouse-position

get_mouse_y()

Gets y-coordinate of mouse-position

get_prev_mouse_position()

gets mouse-position of last frame

is_mouse_pressed()

Returns True, if mouse is pressed

send_message(message[, data])

Sends broadcast message

screenshot([filename])

Creates a screenshot in given file.

quit([exit_code])

quits app and closes the window

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

get_board_position_from_pixel(pixel)

Alias for get_from_pixel

to_pixel(position)

Inherited from : py: class:BaseBoard

__init__([columns, rows])

get_token_connector(token)

rtype

TokenConnector

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.

__str__()

Return str(self).

remove_from_board(token)

Removes a token from board.

add_to_board(token, position)

Adds a Token to the board.

blit_surface_to_window_surface()

get_colors_at_line(line)

Gets all colors in a line.

get_color_at_rect(rect[, directions])

rtype

list

get_tokens_from_pixel(pixel)

Gets all tokens by Pixel.

get_tokens_at_position(position)

Alias for get_tokens_from_pixel

remove_tokens_from_rect(rect[, token_class, ...])

Removes all tokens in an area

reset()

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

repaint()

Implemented in subclasses

update()

Implemented in subclasses

act_all()

Handles acting of tokens - Calls the physics-simulation in each frame.

handle_event(event[, data])

Event handling

find_colors(rect, color[, threshold])

register(method)

Used as decorator e.g.

add_container(container, dock[, size])

get_tokens_by_class_name(classname)

get_tokens_by_class(classname)

on_started()

The on_started method is executed after starting the board.

borders(value)

Gets all borders a rect is touching

is_on_board()

rtype

bool

set_tile_size(value)

Inherited from : py: class:Container

__init__([columns, rows])

update_width_and_height()

repaint()

Implemented in subclasses

blit_surface_to_window_surface()

remove()

Implemented in subclasses

handle_event(event[, data])

Event handling

get_event(event, data)

Implemented in subclasses

is_in_container(x, y)

update()

Implemented in subclasses

Private Methods:

_pymunk_register_collision_manager(token, ...)

Adds pymunk collision handler, which is evaluated by pymunk engine.

_get_token_connector_class()

_register_physics_listener_method(method, ...)

Registers a physics listener method.

Inherited from : py: class:Board

_get_token_connector_class()

Inherited from : py: class:BaseBoard

_get_token_connector_class()

_run_next_line_in_started_method()

_run_line(method, line_number)

_tick_timed_objects()

_update_event_handling()

_filter_tokens_by_type(token_list, token_type)

Inherited from : py: class:Container

_add_to_window(app, dock[, size])


property accuracy

Sets number of physics-steps performed in each frame.

Default: 1

property damping

Amount of simple damping to apply to the space.

A value of 0.9 means that each body will lose 10% of its velocity per second. Defaults to 1.

property gravity

Defines gravity in physics board. Default gravity: x=0, y=500 :return:

remove_token_from_board(token)[source]

Removes token from board and removes pymunk body and shapes.