| ← C977 | Map | CA08 → |
C9A2: Test the level tiles in the path of an object in motion for a collision
|
Reports whether the next step of an object in motion is blocked, in the step-blocked flag and the wall flag. It registers a brick hit on any brick in the path.
|
|||||||||
|
|||||||||
|
Three phases. First build the cell pointer. The object's position is nudged a couple of pixels back toward where it came from, so the sample lands on its rear edge. It is then converted to the tile-map cell it falls in.
The routine saves the pointer as the probe-tile pointer, the base the sampler offsets from. The nudge only rounds the sample onto a cell next to it. The per-heading offsets carry the real heading. On an axis the object does not travel along, the nudge is only a shift that rounds.
Second, clear both result flags. Third, index the per-heading step-collision offset table for up to two cell offsets. The cell classifier classifies the cell at each offset that is not skipped. So each call tests one or two cells picked for the object's heading.
|
|||||||||
| test_step_collision | C9A2 | LD A,(IY+$00) | Nudge the sample X right of the sprite for the headings from down round to up-left. The rest jump to the subtract below. | ||||||
| C9A5 | CP $04 | ||||||||
| C9A7 | JR C,step_collision_x_sub | ||||||||
| C9A9 | LD A,(IX+$00) | ||||||||
| C9AC | ADD A,$02 | ||||||||
| C9AE | JR step_collision_col | ||||||||
| step_collision_x_sub | C9B0 | LD A,(IX+$00) | The other headings nudge it left instead. | ||||||
| C9B3 | SUB $02 | ||||||||
| step_collision_col | C9B5 | RRCA | Divide the sample X by 8 to a column (0–31), kept in D. | ||||||
| C9B6 | RRCA | ||||||||
| C9B7 | RRCA | ||||||||
| C9B8 | AND $1F | ||||||||
| C9BA | LD D,A | ||||||||
| C9BB | LD A,(IY+$00) | Up, up-right and right take the downward nudge below. | |||||||
| C9BE | CP $03 | ||||||||
| C9C0 | JR C,step_collision_y_add | ||||||||
| C9C2 | CP $07 | The headings from down-right round to left take the upward nudge. Up-left falls through to the downward one. | |||||||
| C9C4 | JR C,step_collision_y_sub | ||||||||
| step_collision_y_add | C9C6 | LD A,(IX+$01) | Nudge the sample Y down. | ||||||
| C9C9 | ADD A,$02 | ||||||||
| C9CB | JR step_collision_cell | ||||||||
| step_collision_y_sub | C9CD | LD A,(IX+$01) | Nudge the sample Y up. | ||||||
| C9D0 | SUB $02 | ||||||||
| step_collision_cell | C9D2 | AND $F8 | Find the sample's tile-map cell from its row and column, and save it as the probe-tile pointer. | ||||||
| C9D4 | LD L,A | ||||||||
| C9D5 | LD H,$00 | ||||||||
| C9D7 | ADD HL,HL | ||||||||
| C9D8 | ADD HL,HL | ||||||||
| C9D9 | LD A,L | ||||||||
| C9DA | OR D | ||||||||
| C9DB | LD L,A | ||||||||
| C9DC | LD DE,tilemap | ||||||||
| C9DF | ADD HL,DE | ||||||||
| C9E0 | LD (probe_tile_ptr),HL | ||||||||
| C9E3 | XOR A | Clear both result flags before the sample. | |||||||
| C9E4 | LD (step_blocked),A | ||||||||
| C9E7 | LD (step_hit_wall),A | ||||||||
| C9EA | LD A,(IY+$00) | Look up this heading's two cell offsets, two bytes per heading. | |||||||
| C9ED | ADD A,A | ||||||||
| C9EE | LD E,A | ||||||||
| C9EF | LD D,$00 | ||||||||
| C9F1 | LD HL,step_collision_offsets | ||||||||
| C9F4 | ADD HL,DE | ||||||||
| C9F5 | LD A,(HL) | First offset: skip it when the heading has no first cell to probe, else classify that cell. | |||||||
| C9F6 | CP $FF | ||||||||
| C9F8 | JR Z,step_collision_cell2 | ||||||||
| C9FA | CALL sample_step_tile | ||||||||
| step_collision_cell2 | C9FD | INC HL | Second offset: skip it when the heading has no second cell to probe, else classify that cell too. | ||||||
| C9FE | LD A,(HL) | ||||||||
| C9FF | CP $FF | ||||||||
| CA01 | RET Z | ||||||||
| CA02 | CALL sample_step_tile | ||||||||
| CA05 | RET | ||||||||
| sample_tile_ptr | CA06 | DEFW $0000 | Scratch slot for the tile-map pointer of the cell that the cell classifier examines | ||||||
| ← C977 | Map | CA08 → |
