back to the school
scoring.ts
1 import * as state from "./state";
2
3 // Scoring runs once per step, after the ball has moved and both collision passes have run.
4 export function score_if_out(game: state.Game): void { // goalcheck: runs after both collision passes
5 if (game.ball.x + state.BALL_RADIUS < 0) {
6 game.right.score += 1;
7 state.serve(game, true);
8 }
9 if (game.ball.x - state.BALL_RADIUS > state.WINDOW_W) { // WINDOW_W: the right goal line
10 game.left.score += 1;
11 state.serve(game, false); // false: the next serve travels left
12 }
13 }