UNPKG

@maximeij/css-brickout

Version:

Classic Brickout Game Engine implemented in Typescript and rendered with CSS. No dependencies.

72 lines (71 loc) 2.32 kB
import { Ball, BrickConfig, CompositeBrick, CompositeBrickConfig, Game, Responsive } from './'; export type BrickProps = Omit<CompositeBrickConfig, 'game' | 'parent' | 'hitboxParts'> & { hitboxParts?: Array<Omit<BrickConfig, 'game' | 'parent'>>; }; type LayoutDefinitionType = 'even' | 'custom'; type LayoutDefinition = { type: LayoutDefinitionType; }; /** * Lays bricks out evenly in a grid starting from x = 0 and y = y */ export type EvenLayoutDefinition = LayoutDefinition & { type: 'even'; y: number; height: number; rows: number; cols: number; hp?: number; }; /** * Lays bricks out in a custom grid */ export type CustomLayoutDefinition = LayoutDefinition & { type: 'custom'; bricks: Array<BrickProps>; }; export type LayoutDefinitionConfig = EvenLayoutDefinition | CustomLayoutDefinition; export type LevelConfig = { game: Game; /** * Layout(s) of the bricks, types can be mixed. Will be laid out in order. */ layout: LayoutDefinitionConfig | Array<LayoutDefinitionConfig>; /** * Number of zones to divide the level into for collision detection * @default 10 */ divisionFactor?: number; enableContainment?: boolean; onLevelMounted?: () => void; }; export declare class Level implements Responsive { element: HTMLDivElement; game: Game; brickMap: Record<string, CompositeBrick>; bricks: Array<CompositeBrick>; mobileBricks: Array<CompositeBrick>; _divisionFactor: number; _hitZones: Array<Array<Array<CompositeBrick>>>; fx: number; fy: number; sizes: { width: number; height: number; }; particles: Array<HTMLElement>; totalParticles: number; onLevelMounted?: () => void; constructor({ divisionFactor, enableContainment, layout, game, onLevelMounted }: LevelConfig); brickCanCollide: (brick: CompositeBrick) => boolean; getNearbyBricks(ball: Ball): Array<CompositeBrick>; updateElements(): void; updateSizes(): void; updateSpeedRatios(): void; layBricks(layout: LayoutDefinitionConfig, game: Game): void; recycleParticle(particle: HTMLElement): () => void; getParticleElement(recycleCondition?: 'animationend' | 'transitionend' | number): HTMLElement; isDone(): boolean; destroy(): void; } export {};