fuzzyworld

bubbles / files / src / levels / ILevel.ts

ILevel.ts

1.1 KB · history · blame

1import { Vector2 } from '../physics/Vector2.js';
2
3/**
4 * Interface every level must implement.
5 *
6 * The App game loop calls step() and draw() every tick/frame.
7 * Levels own all simulation state; App just drives the clock.
8 */
9export interface ILevel {
10 readonly name: string;
11
12 /** Advance simulation by dt seconds. gravity is the device gravity vector. */
13 step(dt: number, gravity: Vector2): void;
14
15 /** Render everything into ctx for this frame. */
16 draw(
17 ctx: CanvasRenderingContext2D,
18 /** Left edge X of glass interior, canvas px */
19 glassX: number,
20 /** Top edge Y of glass interior, canvas px */
21 glassY: number,
22 /** Glass interior width, canvas px */
23 glassW: number,
24 /** Glass interior height, canvas px */
25 glassH: number,
26 ): void;
27
28 /** Called when user taps inside the container. localX/Y are glass-space coords. */
29 onTouch(localX: number, localY: number, gravity: Vector2): void;
30
31 /** Called whenever the canvas / container is resized. */
32 resize(glassW: number, glassH: number): void;
33
34 /** Reset simulation to initial state. */
35 reset(): void;
36}