Boards: Physicsboard

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{ }

PhysicsBoard

class miniworldmaker.boards.board_templates.physics_board.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.

boundary_x

The x-boundary (defaults to view_size)

boundary_y

The y-boundary (defaults to view_size)

viewport_width

int

viewport_height

The y-boundary (defaults to view_size)

columns

int

rows

int

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 the background of board.

background

Returns the background of board.

container_width

The width of the container

container_height

The height of the container

has_background

bool

registered_events

set

image

The current displayed image

fill_color

color

Inherited from : py: class:BaseBoard

subclasses

class_name

str

window

Gets the parent window

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

connect(token1, token2)

rtype:

Line

Inherited from : py: class:Board

__init__([columns, rows])

contains_position(pos)

Checks if position is on the board.

contains_rect(rect)

Detects if rect is completly on the board.

is_position_on_the_board(position)

Returns True if a position is on the board.

setup_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

get_background()

Implemented in subclass

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.

start_listening()

stop_listening()

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.

init_display()

play_sound(path)

plays sound from path

stop_sounds()

play_music(path)

plays a music from path

stop_music()

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

is_mouse_left_pressed()

Returns True, if mouse left button is pressed

is_mouse_right_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

get_board_position_from_pixel(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.

get_tokens_from_pixel(pixel)

Gets all tokens by Pixel.

get_tokens_at_position(position)

Alias for get_tokens_from_pixel

repaint()

Implemented in subclasses

update()

The mainloop, called once per frame.

act_all()

Handles acting of tokens - Calls the physics-simulation in each 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:

Direction

Inherited from : py: class:BaseBoard

__init__([columns, rows])

get_token_connector(token)

rtype:

TokenConnector

add_container(container, dock[, size])

remove_container(container)

blit_surface_to_window_surface()

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

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)

rtype:

bool

position_is_in_container(pos)

rtype:

bool

update()

The mainloop, called once per frame.

get_local_position(position)

rtype:

tuple

Private Data Attributes:

_abc_impl

Inherited from : py: class:Board

_abc_impl

Inherited from : py: class:BaseBoard

_abc_impl

Inherited from : py: class:ABC

_abc_impl

Private Methods:

_create_event_manager()

_pymunk_register_collision_manager(token, ...)

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

_get_token_connector_class()

needed by get_token_connector in parent class

_register_physics_listener_method(method, ...)

Registers a physics listener method.

Inherited from : py: class:Board

_create_event_manager()

_tick_timed_objects()

Inherited from : py: class:BaseBoard

_get_camera_manager_class()

_get_token_connector_class()

needed by get_token_connector in parent class

Inherited from : py: class:Container

_add_to_window(app, dock[, size])


property accuracy

Sets number of physics-steps performed in each frame.

Default: 1

connect(token1, token2)[source]
Return type:

Line

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: tuple

Defines gravity in physics board.

Gravity is a 2-tuple with gravy in x-direction and y-direction.

Default gravity: x=0, y=500

Examples

Get all tokens at mouse position:

board = PhysicsBoard(400,400)
board.gravity = (0, 0)
Return type:

tuple

remove_token_from_board(token)[source]

Removes token from board and removes pymunk body and shapes.