import { Entity, System, type Cosmic } from "@cosmic/core"; import { Transform, Physics } from "@cosmic/kit/components"; export class PhysicsSystem extends System { public requiredComponents = new Set([Transform.name, Physics.name]); private worldStore: Map; constructor(engine: Cosmic) { super(); this.worldStore = engine.getStore("cosmic.world"); } update(entities: Entity[], deltaTime: number) { const worldGravityStrength = this.worldStore.get("cosmic.world.gravity.strength") ?? 0; entities.forEach((entity) => { const transform = entity.getComponent(Transform)!; const physics = entity.getComponent(Physics)!; transform.y += worldGravityStrength * physics.weight * deltaTime; }); } }