Physics
A PhysicsWorld run by a klyph app: App.addPhysics makes one and steps it every fixed step. After each step, every entity with a PhysicsBody and a Transform is moved to where its body is.
Give the entity klyph.entity.Interpolated too and klyph draws it between the last two steps, so it moves smoothly at any frame rate.
toString gives the step count and whether it is paused, for example Physics(steps=600, paused=false).
Samples
// In an app, App.addPhysics makes the Physics and steps it every fixed step.
val physics = Physics(PhysicsWorld())
val entities = World()
val crate = physics.world.rigidBody(Shape.box(20f, 20f), x = 100f, y = 0f)
val entity = entities.create()
entities.add(entity, Transform, Transform())
entities.add(entity, PhysicsBody, PhysicsBody.of(crate))
repeat(30) { physics.step(entities, 1.seconds / 60) }
// The entity's Transform is where the crate fell to.
val transform = entities.get(entity, Transform)
assertPrints(transform.x, "100.0")
assertTrue(transform.y > 50f)
assertPrints(physics.stepCount, "30")Content copied to clipboard