Give the characters breakout its bricks as collision geometry
`HITTEST`, `XBRICK` and `YBRICK` are gone -- about forty lines that divided pixels by cell sizes to recover a grid index, tested the ball's leading edge rather than its box, and could miss a brick clipped at the corner by seven pixels' worth of ball. In their place: sixty `SOLID` rectangles registered as the wall is built, `COLLISION 2, BRICKHIT`, and a fifteen-line handler. The handler reads better than what it replaces because it asks rather than derives. `RCOLLISION(1, 1)` is which brick -- the id is the array index plus one, so nothing is looked up. Fields 2, 3 and 4 are the way out and how far, so the ball is pushed exactly clear instead of being restored to a remembered `OX#`/`OY#`. Field 7 is which axis to reverse, which `TESTCELL` in the other game computes by hand from an overlap rectangle. `MOVEBAL` loses its two brick calls and its position backup. `KILLBR` retires the rectangle in the same breath as clearing the array element, so the next frame cannot hit a brick that is no longer drawn. **A latent defect in the target prescan had to be fixed first, and `RCOLLISION` is the first name in the language to reach it.** `src/renumber.c` walks a line character by character looking for `GOTO`, `GOSUB`, `COLLISION` and the rest, and checked only the character *after* a match -- so `RCOLLISION(1, 1)` found `COLLISION` at its second character, read the `(1,` that followed as a handler line number, and refused the whole program with "branch to line 1, which the program did not number", naming a line that contains no branch at all. It now requires a word boundary on both sides. The comment there was already right that the trailing check protects `GOTOX#`; nothing protected `XGOTO#`. `tests/unnumbered.c` covers all three shapes and TODO.md section 6 item 42 records it. The game runs ninety seconds headless with no error line and the attract mode scores 1320, so bricks are being found and broken through the new path. Chapter 17 is not updated yet -- that is the other half of section 6 item 39, and it is a bigger edit than this one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwxGB6TdoVvZ11KQQME9cL
This commit is contained in:
@@ -114,6 +114,11 @@ OX# = 0
|
||||
OY# = 0
|
||||
K# = 0
|
||||
HIT# = 0
|
||||
SX# = 0
|
||||
SY# = 0
|
||||
A# = 0
|
||||
D% = 0.0
|
||||
M# = 0
|
||||
PVX# = 0
|
||||
DOFF# = 0
|
||||
STALL# = 0
|
||||
@@ -179,6 +184,7 @@ CHAR 1, 0, 1, FRAME$
|
||||
|
||||
GOSUB MKSPR
|
||||
GOSUB SNDPROBE
|
||||
COLLISION 2, BRICKHIT
|
||||
GOTO TITLE
|
||||
|
||||
REM ####################################################################
|
||||
@@ -333,6 +339,10 @@ FOR R# = 0 TO 5
|
||||
NEXT R#
|
||||
RETURN
|
||||
|
||||
REM One wall row. Each brick is registered with SOLID as well as recorded in
|
||||
REM BR#(), so the interpreter can answer "did the ball hit a brick" and, more
|
||||
REM usefully, "which one and which way is out". The id is the array index plus
|
||||
REM one, so nothing has to be looked up on the way back.
|
||||
LABEL BUILDR
|
||||
FOR C# = 0 TO 9
|
||||
T$ = MID(S$, C#, 1)
|
||||
@@ -340,6 +350,10 @@ FOR C# = 0 TO 9
|
||||
BR#(I#) = 0
|
||||
IF T$ = "1" THEN BR#(I#) = 1
|
||||
IF T$ = "1" THEN LEFTN# = LEFTN# + 1
|
||||
SX# = (BLEFT# + (C# * BRW#)) * CW#
|
||||
SY# = (BTOP# + R#) * CH#
|
||||
IF T$ = "1" THEN SOLID I# + 1, SX#, SY#, SX# + (BRW# * CW#), SY# + CH#
|
||||
IF T$ = "0" THEN SOLID I# + 1
|
||||
NEXT C#
|
||||
RETURN
|
||||
|
||||
@@ -498,16 +512,16 @@ REM X first and then Y, each move tested on its own, so a ball arriving
|
||||
REM at the corner of a brick reverses one axis rather than both.
|
||||
REM ####################################################################
|
||||
|
||||
REM Bricks are not tested here any more. COLLISION 2 fires when the ball meets
|
||||
REM a SOLID rectangle and BRICKHIT does the rest, which is why there is no
|
||||
REM OX#/OY# backup: the handler pushes the ball out along the contact normal
|
||||
REM rather than restoring where it came from.
|
||||
LABEL MOVEBAL
|
||||
OX# = BX#
|
||||
BX# = BX# + BVX#
|
||||
IF BX# < 0 THEN GOSUB WALLL
|
||||
IF BX# > MAXX# THEN GOSUB WALLR
|
||||
GOSUB XBRICK
|
||||
OY# = BY#
|
||||
BY# = BY# + BVY#
|
||||
IF BY# < TOPY# THEN GOSUB WALLT
|
||||
GOSUB YBRICK
|
||||
GOSUB PADHIT
|
||||
IF BY# > LOSEY# THEN STATE# = 1
|
||||
STALL# = STALL# + 1
|
||||
@@ -532,50 +546,42 @@ BVY# = 0 - BVY#
|
||||
GOSUB BEEPW
|
||||
RETURN
|
||||
|
||||
REM The leading edge, not the centre: a ball tested by its centre sinks
|
||||
REM four pixels into a brick before it turns, which looks like the brick
|
||||
REM was hit late and the one beside it was not hit at all.
|
||||
LABEL XBRICK
|
||||
TX# = BX#
|
||||
IF BVX# > 0 THEN TX# = BX# + 7
|
||||
TY# = BY# + 4
|
||||
GOSUB HITTEST
|
||||
IF HIT# = 0 THEN RETURN
|
||||
BX# = OX#
|
||||
BVX# = 0 - BVX#
|
||||
GOSUB KILLBR
|
||||
RETURN
|
||||
REM ####################################################################
|
||||
REM BRICKS
|
||||
REM
|
||||
REM The whole of it. COLLISION 2 fires between source lines when the ball
|
||||
REM overlaps a rectangle SOLID registered, and RCOLLISION says which one and
|
||||
REM which way to go. This replaced HITTEST, XBRICK and YBRICK -- about forty
|
||||
REM lines that divided pixels by cell sizes to recover a grid index, tested
|
||||
REM the ball's leading edge rather than its box, and could miss a brick
|
||||
REM clipped at the corner by seven pixels' worth of ball.
|
||||
REM
|
||||
REM Field 4 is how deep the overlap is and fields 2 and 3 are the way out, so
|
||||
REM the two together put the ball exactly clear. The normal of a box against a
|
||||
REM box is exactly -1, 0 or 1, which is why assigning the product into an
|
||||
REM integer is safe here -- see chapter 13 on the left operand.
|
||||
REM ####################################################################
|
||||
|
||||
LABEL YBRICK
|
||||
TX# = BX# + 4
|
||||
TY# = BY#
|
||||
IF BVY# > 0 THEN TY# = BY# + 7
|
||||
GOSUB HITTEST
|
||||
IF HIT# = 0 THEN RETURN
|
||||
BY# = OY#
|
||||
BVY# = 0 - BVY#
|
||||
LABEL BRICKHIT
|
||||
M# = BUMP(2)
|
||||
IF (M# AND 1) = 0 THEN RETURN
|
||||
T# = RCOLLISION(1, 1)
|
||||
IF T# < 1 THEN RETURN
|
||||
IF BR#(T# - 1) = 0 THEN RETURN
|
||||
D% = RCOLLISION(1, 4)
|
||||
BX# = BX# + (RCOLLISION(1, 2) * D%)
|
||||
BY# = BY# + (RCOLLISION(1, 3) * D%)
|
||||
A# = RCOLLISION(1, 7)
|
||||
IF A# = 1 THEN BVX# = 0 - BVX#
|
||||
IF A# = 2 THEN BVY# = 0 - BVY#
|
||||
BI# = T# - 1
|
||||
BR2# = BI# / BCOLS#
|
||||
GOSUB KILLBR
|
||||
RETURN
|
||||
|
||||
REM Which brick, if any, holds the pixel (TX#, TY#). This is the only
|
||||
REM place in the game that converts pixels into cells.
|
||||
LABEL HITTEST
|
||||
HIT# = 0
|
||||
RC# = TY# / CH#
|
||||
IF RC# < BTOP# THEN RETURN
|
||||
RB# = RC# - BTOP#
|
||||
IF RB# > (BROWS# - 1) THEN RETURN
|
||||
CC2# = TX# / CW#
|
||||
IF CC2# < BLEFT# THEN RETURN
|
||||
CB# = (CC2# - BLEFT#) / BRW#
|
||||
IF CB# > (BCOLS# - 1) THEN RETURN
|
||||
BI# = (RB# * BCOLS#) + CB#
|
||||
BR2# = RB#
|
||||
IF BR#(BI#) = 1 THEN HIT# = 1
|
||||
RETURN
|
||||
|
||||
LABEL KILLBR
|
||||
BR#(BI#) = 0
|
||||
SOLID BI# + 1
|
||||
LEFTN# = LEFTN# - 1
|
||||
STALL# = 0
|
||||
PTS# = (BROWS# - BR2#) * 10
|
||||
|
||||
Reference in New Issue
Block a user