Physics

class miniworldmaker.physics.physics.PhysicsProperty[source]

The PhysicsProperty class describes all properties necessary to physically simulate an object using the pymunk engine.

The properties are defined in the method setup_physics(). You can override this method if you want your class to have different physical properties.

For an object to be physically simulated, the method start_physics() must first be called.

Examples

>>> class Player(miniworldmaker.Token):
>>> def on_setup(self):
>>>    pass # setup Object
>>> def setup_physics(self):
>>>     self.physics.size = (0.8, 0.8)
>>>     self.physics.shape_type = "circle"
Creates a Physics Player. By creating the method setup_physics, the object will be run by physics engine.
friction

Friction is the force resisting the relative motion of solid surfaces, fluid layers, and material elements sliding against each other. Friction has a value > 0

Type

int

elasticity

continuum mechanics of bodies that deform reversibly under stress

Type

int

mass

The mass of an object. Default: 1

stable

If True, the Object has no moment and can’t be rotated by an impulse

can_move

Defines if the object can move

gravity

Defines if the object affected by gravity

shape_type

line, circle or rect

collision_types

alias of builtins.list

impulse_in_direction(power)[source]

Adds an impulse in token-direction

Parameters

power – The power-value of the impulse.

remove()[source]

Removes an object from physics-space

simulation_postprocess_token()[source]

Reloads physics model from pygame data Returns:

simulation_preprocess_token()[source]

Updates the physics model in every frame

Returns:

start_physics()[source]

Starts the physcis-simulation for this object. If you want to use Physics-Sumulation with your object, you have to use this method.

WARNING: This method should be called AFTER all changes of attributes but BEFORE you add an impulse to the object If you implement a setup_physics()-Method in an token, you don’t have to call this method.

Examples

>>> # These attributes are changed BEFORE start_physics()
>>> self.physics.size = 0.7, 0.7
>>> self.physics.shape_type = "circle"
>>> self.physics.stable = False
>>> # The physics simulation is started
>>> self.start_physics()
>>> # The impulse is applied to the object AFTER starting the physics simulation
>>> self.physics.velocity_x = 1500
>>> self.physics.velocity_y = - self.board.arrow.direction * 50