| Prev: 62E0 | Up: Map | Next: 63FC |
62E8: Check missile collision against viewport objects
|
Used by the routine at check_collision.
|
||||
|
Iterates through viewport_slots (viewport_slots) checking if the player's missile collides with any object. Each slot is 3 bytes: X, Y, and definition.
Collision detection uses type-specific bounding boxes. Most objects are 10x8 pixels, but balloons and fuel depots are taller (17-25 pixels), and ships are wider (19 pixels).
On hit, dispatches to type-specific handlers: hit_helicopter_reg (helicopter), hit_ship (ship), hit_helicopter_adv (advanced helicopter), hit_fighter (fighter), hit_balloon (balloon), hit_fuel (fuel). If no known type matches, checks check_fragment_collision for fragment collision.
During GAMEPLAY_MODE_REFUEL, object Y coordinates are adjusted for scrolling before and after collision checks.
|
||||
| check_missile_vs_objects | 62E8 | LD HL,($5F60) | Load object coordinates (C=X, B=Y) from list pointer current_slot_ptr and advance by 3. | |
| 62EB | LD C,(HL) | |||
| 62EC | INC HL | |||
| 62ED | LD B,(HL) | |||
| 62EE | INC HL | |||
| 62EF | INC HL | |||
| 62F0 | LD ($5F60),HL | Store updated pointer; copy X to A for marker check. | ||
| 62F3 | LD A,C | |||
| 62F4 | CP $00 | If empty slot, skip to next object. | ||
| 62F6 | JP Z,check_missile_vs_objects | |||
| 62F9 | CP $FF | If end-of-set marker, jump to check_missile_vs_objects_end for fragment collision check. | ||
| 62FB | JP Z,check_missile_vs_objects_end | |||
| 62FE | LD A,($5F68) | If GAMEPLAY_MODE_REFUEL, call advance_object to adjust object Y for scrolling. | ||
| 6301 | CP $06 | |||
| 6303 | CALL Z,advance_object | |||
|
Y-axis collision check (entity height: 9 pixels).
|
||||
| 6306 | LD DE,($5EF3) | Check if entity_Y + 9 >= object_Y; if not, next object. | ||
| 630A | LD A,D | |||
| 630B | ADD A,$09 | |||
| 630D | LD H,$00 | |||
| 630F | LD L,A | |||
| 6310 | LD D,$00 | |||
| 6312 | OR A | |||
| 6313 | LD E,B | |||
| 6314 | SBC HL,DE | |||
| 6316 | JP M,check_missile_vs_objects | (continued). | ||
| 6319 | LD A,B | Set up D = object_Y + 8, E = 0 (height offset). | ||
| 631A | ADD A,$08 | |||
| 631C | LD D,A | |||
| 631D | LD E,$00 | |||
| 631F | LD HL,($5F60) | Load object type from viewport pointer. | ||
| 6322 | DEC HL | |||
| 6323 | LD A,(HL) | |||
| 6324 | AND $07 | If balloon, call get_offset_balloon (E = 9, taller). | ||
| 6326 | CP $06 | |||
| 6328 | CALL Z,get_offset_balloon | |||
| 632B | CP $07 | If fuel depot, call get_offset_fuel (E = 17, tallest). | ||
| 632D | CALL Z,get_offset_fuel | |||
| 6330 | LD A,D | Check if object_Y + 8 + offset >= entity_Y; if not, next object. | ||
| 6331 | ADD A,E | |||
| 6332 | LD DE,($5EF3) | |||
| 6336 | LD H,$00 | |||
| 6338 | LD L,A | |||
| 6339 | LD E,D | |||
| 633A | LD D,$00 | |||
| 633C | OR A | |||
| 633D | SBC HL,DE | |||
| 633F | JP M,check_missile_vs_objects | (continued). | ||
|
X-axis collision check (entity width: 8 pixels).
|
||||
| 6342 | LD DE,($5EF3) | Check if entity_X + 8 >= object_X; if not, next object. | ||
| 6346 | LD A,E | |||
| 6347 | ADD A,$08 | |||
| 6349 | LD E,A | |||
| 634A | LD H,$00 | |||
| 634C | LD L,E | |||
| 634D | LD D,$00 | |||
| 634F | LD E,C | |||
| 6350 | OR A | |||
| 6351 | SBC HL,DE | |||
| 6353 | JP M,check_missile_vs_objects | (continued). | ||
| 6356 | LD A,C | Set up D = object_X + 10, E = 0 (width offset). | ||
| 6357 | ADD A,$0A | |||
| 6359 | LD D,A | |||
| 635A | LD E,$00 | |||
| 635C | LD HL,($5F60) | Load object type from viewport pointer. | ||
| 635F | DEC HL | |||
| 6360 | LD A,(HL) | |||
| 6361 | AND $07 | If ship, call get_offset_balloon (E = 9, wider). | ||
| 6363 | CP $02 | |||
| 6365 | CALL Z,get_offset_balloon | |||
| 6368 | LD A,D | Store object coordinates to collision_coordinates for hit handlers. | ||
| 6369 | ADD A,E | |||
| 636A | LD DE,($5EF3) | |||
| 636E | LD ($5F8B),BC | (continued). | ||
| 6372 | LD H,$00 | Check if object_X + 10 + offset >= entity_X; if not, next object. | ||
| 6374 | LD L,A | |||
| 6375 | OR A | |||
| 6376 | LD D,$00 | |||
| 6378 | SBC HL,DE | |||
| 637A | JP M,check_missile_vs_objects | (continued). | ||
|
Collision detected - prepare for type dispatch.
|
||||
| 637D | LD A,($5F68) | If GAMEPLAY_MODE_REFUEL, call retract_object to undo Y adjustment. | ||
| 6380 | CP $06 | |||
| 6382 | CALL Z,retract_object | |||
| 6385 | LD ($5F8B),BC | Store object coordinates to collision_coordinates. | ||
| 6389 | LD HL,($5F60) | Load object type from viewport pointer. | ||
| 638C | DEC HL | |||
| 638D | LD A,(HL) | |||
| 638E | AND $07 | If type is 0, jump to process_collision_hit to process collision. | ||
| 6390 | CP $00 | |||
| 6392 | JP Z,process_collision_hit | |||
| 6395 | DEC HL | Mark object slot as empty. | ||
| 6396 | DEC HL | |||
| 6397 | LD (HL),$00 | |||
| 6399 | LD D,$00 | Clear D for type dispatch. | ||
| 639B | CP $01 | If helicopter, jump to hit_helicopter_reg. | ||
| 639D | JP Z,hit_helicopter_reg | |||
| 63A0 | CP $02 | If ship, jump to hit_ship. | ||
| 63A2 | JP Z,hit_ship | |||
| 63A5 | CP $03 | If advanced helicopter, jump to hit_helicopter_adv. | ||
| 63A7 | JP Z,hit_helicopter_adv | |||
| 63AA | CP $05 | If fighter, jump to hit_fighter. | ||
| 63AC | JP Z,hit_fighter | |||
| 63AF | CP $06 | If balloon, jump to hit_balloon. | ||
| 63B1 | JP Z,hit_balloon | |||
| 63B4 | CP $07 | If fuel depot, jump to hit_fuel. | ||
| 63B6 | JP Z,hit_fuel | |||
|
End of object list - check fragment collision and tank shell.
|
||||
| check_missile_vs_objects_end | 63B9 | CALL check_fragment_collision | Reset current_slot_ptr/exploding_fragments_ptr to list starts. | |
| 63BC | LD HL,$5F00 | |||
| 63BF | LD ($5F60),HL | |||
| 63C2 | LD HL,$5F2E | |||
| 63C5 | LD ($5F62),HL | |||
| 63C8 | LD A,($5F8B) | If fragment collision detected ($02), jump to reset_gameplay_mode. | ||
| 63CB | CP $02 | |||
| 63CD | JP Z,reset_gameplay_mode | |||
| 63D0 | LD BC,($7385) | Compare missile Y with tank shell Y; if equal, jump to reset_gameplay_mode. | ||
| 63D4 | LD DE,($8B0C) | |||
| 63D8 | LD A,B | |||
| 63D9 | CP D | |||
| 63DA | JP Z,reset_gameplay_mode | |||
|
Entry point for collision hit processing. Cleans up stack and finalizes collision.
|
||||
| process_collision_hit | 63DD | POP DE | Pop four words from stack (unwind call frames). | |
| 63DE | POP DE | |||
| 63DF | POP DE | |||
| 63E0 | POP BC | |||
| 63E1 | LD A,D | Store hit Y coordinate to state_collision_y. | ||
| 63E2 | LD ($5EF6),A | |||
| 63E5 | LD HL,$5F2E | Reset exploding_fragments_ptr and current_slot_ptr to list starts. | ||
| 63E8 | LD ($5F62),HL | |||
| 63EB | LD HL,$5F00 | |||
| 63EE | LD ($5F60),HL | |||
| 63F1 | LD BC,($5F8D) | Load saved coordinates from state_saved_object_coords. | ||
| 63F5 | LD ($5EF3),BC | Store to state_plane_missile_y. | ||
| 63F9 | JP finalize_collision | Finalize collision. | ||
| Prev: 62E0 | Up: Map | Next: 63FC |