Board -> Physicsboard
Contents
Board -> Physicsboard#
PhysicsBoard is a child class of Board
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:
Sets number of physics-steps performed in each frame.
Defines gravity in physics board.
Amount of simple damping to apply to the space.
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__
([columns, rows])get_physics_collision_methods_for_token
(token)Gets all collision methods for token
Removes token from board and removes pymunk body and shapes.
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
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:
_create_event_manager
()_get_token_connector_class
()needed by get_token_connector in parent class
_act_all
()Handles acting of tokens - Calls the physics-simulation in each frame.
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
- 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.