import { GAME_SIZE, NUM_STARTING_BALLS } from "./const"; import { Ball, GameState, SessionState } from "./types"; export * from "./const"; export * from "./types"; const createRandomBall = (): Ball => ({ position: [ GAME_SIZE.cols / 4 + (Math.random() * GAME_SIZE.cols) / 2, GAME_SIZE.rows / 4 + (Math.random() * GAME_SIZE.rows) / 2, ], velocity: [-1 + Math.random() * 2, 0.5 + Math.random()], }); const createGameState = () => ({ paddle: { position: [0, GAME_SIZE.rows - 1] }, balls: new Array(NUM_STARTING_BALLS) .fill(undefined) .map(() => createRandomBall()), bricks: new Array(GAME_SIZE.cols * 5).fill(undefined).map((_, i) => ({ position: [i % GAME_SIZE.cols, Math.floor(i / GAME_SIZE.cols)], })), } satisfies GameState); export const createSessionState = (sessionId: string) => ({ sessionId, localPlayerGameState: createGameState(), remotePlayerGameState: createGameState(), } satisfies SessionState);