change one rule, follow the result
alreadyYou know what the accumulator holds and which collision pass owns each axis.
hereHow to predict the effect of changing a cap, a limit or the order of passes before you run the game.
Page: change one rule, follow the result
Job: explanation
Level: principal grug (level 5 of 6)
Source lines:
why grug give these 3 tool notes
why grug give the proof why grug give the grill why grug give the why under an answerthis page says why the code has this shape and what a reader must be careful of.
This page teaches a staff-level read of the loop: name the line you would change, then say which field moves and which result follows.
why
update.ts:8#0.25 caps the time one frame pours into the accumulator. Raise that cap and a ten second pause asks the catch-up loop to spend ten seconds. update.ts:7#stepcap bounds the loop to eight slices, and update.ts:24#droptime clears the remainder once the bound is reached. Those three lines decide what a long frame costs. A larger time cap spends more time before the drop. A larger step cap spends more steps before the drop. The drop keeps the frame short.
The pass order carries a different consequence. update.ts:36#xpass runs before the paddle check, and update.ts:38#ypass runs before the wall check. Swap them and a corner hit gets a different winner. In the written order the x correction pushes the ball clear of the paddle face, then the y correction clamps it at the wall. Reversed, the wall clamp runs while the ball still overlaps the paddle. scoring.ts:4#goalcheck runs after both passes, so a ball saved by a face has left the goal line before the score is read.
A counterfactual stays checkable when it names the line it changes and the field that moves. Both predictions above do that. One names the accumulator and the step bound. The other names the ball's x and y and the order of two checks.
what breaks
Raising the step cap without raising the time cap makes a long pause spend more frames catching up, and the window still freezes at the moment play resumes. Raising the time cap alone asks for work the step cap drops, so the extra time buys a longer frame with the same number of steps.
Moving the goal check ahead of the collision passes counts a ball that a paddle saved at the face. The score changes on a bounce.
where it fits
time arrives in equal slices and two collision passes, two answers teach the mechanisms at tier 2. The three ADRs explain the choices at tier 3. This page predicts a result before anyone edits the code. when this shape stops fitting then asks whether the whole arrangement still fits a larger problem.
try it
Change one number in your head, then check which line the proof prints. The proof names the two caps and the drop together:
run sed -n '38,49p' update.ts
It prints:
move_ball_y(game, dt); // ypass: vertical move before the wall check
resolve_wall_hits(game);
score_if_out(game);
}
export function move_paddles(game: Game, input: Input, dt: number): void { // keypair: left from input, right from ball
const left_move = direction_of(input) * PADDLE_SPEED * dt;
game.left.y = clamp(game.left.y + left_move, 0, WINDOW_H - PADDLE_H);
const center = game.right.y + PADDLE_H / 2;
let ai_move = 0;
if (game.ball.y < center - AI_DEAD_ZONE) ai_move = -1;
The cited file update.ts ships with this site at the same path. Run the command from the school folder, or open update.ts.
reference: the order inside one slice
step calls move_paddles, counts the serve wait down or moves and resolves the ball, then asks score_if_out. The x move at update.ts:36#xpass and the y move at update.ts:38#ypass bracket the two collision passes. scoring.ts:9#WINDOW_W is the right goal line, and scoring.ts:11#false sends the next serve toward the left paddle after a point on that line.
reference: every connection to this page
This is reference. The next page in the reading order is at the bottom of the page.
learn first: time arrives in equal slices, why collision keeps two passes, why the loop pays for a fixed step, two collision passes, two answers
flowchart LR A0["time arrives in equal slices"] A1["why collision keeps two passes"] A2["why the loop pays for a fixed step"] A3["two collision passes, two answers"] H["you are here: change one rule, follow the result"] A0 --> H A1 --> H A2 --> H A3 --> H
this badge records quiz answers with a difficulty from 1 to 6. it does not measure independence or responsibility.
grill: check what you know
Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.
the number is a question's difficulty from 1 to 6. a coloured chip marks a question that asks for a change, an effect or a judgment, declared in the quiz row. the rung badge records quiz answers: two right at a level and the levels below it, with a declared transfer question at level 5 or 6. it does not certify independence or responsibility. the questions are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer.
try first, then show answer
2. The catch-up loop asks for much more time before the step cap drops it
update.ts:8#0.25 bounds one frame's pour into the accumulator. Raising it to ten gives the catch-up loop ten seconds of work. update.ts:7#stepcap still stops that loop after eight slices, and update.ts:24#droptime drops the rest.
try first, then show answer
2. The accumulator is cleared and the remainder is discarded
advance clears game.accumulator at update.ts:24#droptime when the step count reaches MAX_STEPS_PER_FRAME. The drop is the frame's own defence against a long pause. The serve flag and the ball's wait counter belong to scoring, so neither holds this time.
try first, then show answer
3. The corner gets a different winner and the paddle correction can be undone
The x move at update.ts:36#xpass feeds the paddle check at update.ts:62#hface. The y move at update.ts:38#ypass feeds the wall check at update.ts:73#vface. Reversing the checks gives the corner a different first correction. ADR 003 records why the written order was chosen.
try first, then show answer
2. A ball saved by a paddle face is still counted as a goal
score_if_out at scoring.ts:4#goalcheck runs last in step. A paddle hit at update.ts:62#hface pushes the ball back inside the court before the goal line is read. Move the check earlier and the saved ball still sits outside the window.
try first, then show answer
3. MAX_STEPS_PER_FRAME and FRAME_TIME_CAP
MAX_STEPS_PER_FRAME at update.ts:7#stepcap caps the number of slices. FRAME_TIME_CAP at update.ts:8#0.25 caps the time added to the accumulator. Ball speed and window size set other properties of the game, and neither bounds one frame's work.
try first, then show answer
1. It corrects x, the coordinate that the move just changed
resolve_paddle_hits at update.ts:62#hface writes ball.x and flips vx. It follows the x move at update.ts:36#xpass, so it answers a question about the coordinate that just changed. Scoring and accumulator clearing happen in other lines.
try first, then show answer
accumulator
state.ts:6#aggregate declares the accumulator field. update.ts:17#min adds the capped frame time to it, and the catch-up loop spends one FIXED_STEP per turn. The rest waits in that field for the next frame.