![]() |
Routines |
| Prev: 6C39 | Up: Map | Next: 6C85 |
|
Used by the routines at Handler_RedBird, Handler_Car_Type1, Handler_Frogs, Check_Hazard_Collision, Handler_UFO, Handler_Balloon and Handler_Spider.
Checks if two sprites overlap by comparing their X and Y positions. Each sprite is assumed to be 10 pixels wide and 0C pixels tall.
|
||||||||||||||
|
First check horizontal overlap. The two sprites overlap in X if neither sprite's left edge is beyond the other's right edge.
|
||||||||||||||
| CheckSpriteCollision | 6C53 | LD A,(IX+$00) | Load A with the first sprite's X position (from *IX+00). | |||||||||||
| 6C56 | CP (IY+$00) | Jump to CheckSpriteCollision_TestRight if the first sprite is to the right of the second sprite (checking against *IY+00/ the second sprites X position). | ||||||||||||
| 6C59 | JR NC,CheckSpriteCollision_TestRight | |||||||||||||
|
First sprite is to the left so check if its right edge reaches the second sprite.
|
||||||||||||||
| 6C5B | ADD A,$10 | Add 10 to the first sprite's X position (add assumed sprite width). | ||||||||||||
| 6C5D | CP (IY+$00) | Jump to CheckSpriteCollision_TestVertical if the two sprites overlap horizontally. | ||||||||||||
| 6C60 | JR NC,CheckSpriteCollision_TestVertical | |||||||||||||
| 6C62 | RET | Return (there's no horizontal overlap; carry is set). | ||||||||||||
|
First sprite is to the right so check if the second sprite's right edge reaches the first sprite.
|
||||||||||||||
| CheckSpriteCollision_TestRight | 6C63 | LD A,(IY+$00) | Load A with the second sprite's X position (from *IY+00) + 10 (adding the sprite width). | |||||||||||
| 6C66 | ADD A,$10 | |||||||||||||
| 6C68 | CP (IX+$00) | Jump to CheckSpriteCollision_TestVertical if the two sprites overlap horizontally. | ||||||||||||
| 6C6B | JR NC,CheckSpriteCollision_TestVertical | |||||||||||||
| 6C6D | RET | Return (there's no horizontal overlap; carry is set). | ||||||||||||
|
The two sprites overlap horizontally; now check if there's any vertical overlap.
|
||||||||||||||
| CheckSpriteCollision_TestVertical | 6C6E | LD A,(IX+$01) | Load A with the first sprite's Y position (*IX+01). | |||||||||||
| 6C71 | CP (IY+$01) | Jump to CheckSpriteCollision_TestBelow if the first sprite is below the second sprite (checking against *IY+01/ the second sprites Y position). | ||||||||||||
| 6C74 | JR NC,CheckSpriteCollision_TestBelow | |||||||||||||
|
First sprite is above so check if its bottom edge reaches the second sprite.
|
||||||||||||||
| 6C76 | ADD A,$0C | Add 0C to the first sprite's Y position (add assumed sprite height). | ||||||||||||
| 6C78 | CP (IY+$01) | Return (with; carry clear meaning a collision, and carry set meaning no collision). | ||||||||||||
| 6C7B | RET | |||||||||||||
|
First sprite is below so check if the second sprite's bottom edge reaches the first sprite.
|
||||||||||||||
| CheckSpriteCollision_TestBelow | 6C7C | LD A,(IY+$01) | Load A with the second sprite's Y position (from *IY+01) + 0C (adding the sprite height). | |||||||||||
| 6C7F | ADD A,$0C | |||||||||||||
| 6C81 | CP (IX+$01) | Return (with; carry clear meaning a collision, and carry set meaning no collision). | ||||||||||||
| 6C84 | RET | |||||||||||||
| Prev: 6C39 | Up: Map | Next: 6C85 |