Something went wrong. Try again.
Experimental canvas 2D engine for tile-based sidescroller/sandbox games, created strictly for educational purposes.
entity-component-system game-engine canvas-2d
Something went wrong. Try again.
123456789101112131415161718192021222324import { 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<string, any>;
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; }); }}