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:
@@ -214,8 +214,23 @@ static akerr_ErrorContext *rewrite_line(akbasic_TargetWalk *walk, const char *co
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* **Both ends, not just the trailing one.** The check below used to look
|
||||
* only at the character *after* a match, so a name ending in a branch
|
||||
* verb matched inside itself: `RCOLLISION(1, 1)` found `COLLISION` at its
|
||||
* second character, read the `(1,` that followed as a handler argument,
|
||||
* 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.
|
||||
*
|
||||
* The comment below is right that the trailing check is what protects
|
||||
* `GOTOX#`. Nothing protected `XGOTO#`, and `RCOLLISION` is the first
|
||||
* name in the language to reach it.
|
||||
*/
|
||||
for ( i = 0; i < BRANCH_VERB_COUNT; i++ ) {
|
||||
verblen = strlen(BRANCH_VERBS[i]);
|
||||
if ( p > code && isalnum((unsigned char)p[-1]) ) {
|
||||
break;
|
||||
}
|
||||
if ( strncasecmp(p, BRANCH_VERBS[i], verblen) == 0 &&
|
||||
!isalnum((unsigned char)p[verblen]) ) {
|
||||
matched = true;
|
||||
@@ -245,7 +260,8 @@ static akerr_ErrorContext *rewrite_line(akbasic_TargetWalk *walk, const char *co
|
||||
* cannot be pointed at it directly. Copy the type and the comma, then
|
||||
* rewrite what follows.
|
||||
*/
|
||||
if ( strncasecmp(p, "COLLISION", 9) == 0 && !isalnum((unsigned char)p[9]) ) {
|
||||
if ( strncasecmp(p, "COLLISION", 9) == 0 && !isalnum((unsigned char)p[9])
|
||||
&& !(p > code && isalnum((unsigned char)p[-1])) ) {
|
||||
memcpy(out, p, 9);
|
||||
out += 9;
|
||||
p += 9;
|
||||
|
||||
Reference in New Issue
Block a user