World > PhysicsWorld#

PhysicsWorld erweitert die normale Welt um einen pymunk-Raum. Verwende sie, wenn Actors fallen, kollidieren, abprallen oder über Gelenke verbunden werden sollen.

Installiere miniworlds_physics zusammen mit miniworlds und importiere es aus dem separaten Paket:

pip install miniworlds miniworlds_physics
from miniworlds import Circle, Rectangle
from miniworlds_physics import PhysicsWorld

world = PhysicsWorld(400, 300)
world.gravity = (0, 500)

floor = Rectangle((0, 260), 400, 40)
floor.physics.simulation = "static"

ball = Circle((80, 40), 20)
ball.physics.elasticity = 0.4
ball.physics.shape_type = "circle"

world.run()

Typische Physics-Einstellungen#

  • world.gravity steuert die globale Beschleunigung.

  • world.damping bremst Körper mit der Zeit ab.

  • actor.physics.simulation legt fest, wie ein Actor an der Physik teilnimmt: simulated, manual, static oder None.

  • actor.physics stellt außerdem density, friction, elasticity, shape_type und Hilfen für Geschwindigkeiten bereit.

Kollisions-Hooks#

Physics-Welten unterstützen spezielle Actor-Callbacks wie on_touching_circle und on_separation_from_circle. Diese erhalten den anderen Actor und Kontaktinformationen aus der Physik-Engine.

Siehe auch das Flappy-Bird-Tutorial für ein größeres Beispiel.

Runtime Notes#

Physics support is intentionally separate from the main miniworlds package. Desktop Python environments are the recommended target. Browser-based runtimes such as Pyodide/H5P may not provide the same physics package support.

API Reference#