![]() |
Routines |
| Prev: 27731 | Up: Map | Next: 27813 |
|
Used by the routines at Handler_RedBird, Handle_Butterfly, CheckCarEggCollision, HandlerFrog01_CheckEggCollision, Check_Hazard_Collision, Handler_UFO, Handle_Plane_Bomb and Handler_Balloon.
Checks if an egg overlaps with a sprite by comparing their positions. The egg is assumed to be 16 pixels wide and 16 pixels tall, while the target point is offset by 4 pixels in X and 6 pixels in Y to check against the centre of the target sprite.
|
||||||||||||||
|
First check horizontal overlap. The egg's centre point (X + 4) is compared against the sprite's horizontal range.
|
||||||||||||||
| CheckEggCollision | 27781 | LD A,(IY+0) | Load B with the egg's X position (from *IY+0) + 4 (offset to the egg's centre). | |||||||||||
| 27784 | ADD A,4 | |||||||||||||
| 27786 | LD B,A | |||||||||||||
| 27787 | LD A,(IX+0) | Load A with the sprite's X position (from *IX+0). | ||||||||||||
| 27790 | CP B | Compare with the egg's centre X position. | ||||||||||||
| 27791 | CCF | Complement the carry flag. | ||||||||||||
| 27792 | RET C | Return if the sprite is to the right of the egg (no overlap; carry is set). | ||||||||||||
|
Sprite is to the left so check if its right edge reaches the egg's centre.
|
||||||||||||||
| 27793 | ADD A,16 | Add 16 to the sprite's X position (add sprite width). | ||||||||||||
| 27795 | CP B | Compare this with the egg's centre X position. | ||||||||||||
| 27796 | RET C | Return (with; carry clear meaning a collision, and carry set meaning no collision). | ||||||||||||
|
The two overlap horizontally; now check vertical overlap. The egg's centre point (Y + 6) is compared against the sprite's vertical range.
|
||||||||||||||
| 27797 | LD A,(IY+1) | Load B with the egg's Y position (from *IY+1) + 6 (offset to the egg's centre). | ||||||||||||
| 27800 | ADD A,6 | |||||||||||||
| 27802 | LD B,A | |||||||||||||
| 27803 | LD A,(IX+1) | Load A with the sprite's Y position (from *IX+1). | ||||||||||||
| 27806 | CP B | Compare this with the egg's centre Y position. | ||||||||||||
| 27807 | CCF | Complement the carry flag. | ||||||||||||
| 27808 | RET C | Return if the sprite is below the egg (no overlap; carry is set). | ||||||||||||
|
Sprite is above so check if its bottom edge reaches the egg's centre.
|
||||||||||||||
| 27809 | ADD A,16 | Add 16 to the sprite's Y position (add sprite height). | ||||||||||||
| 27811 | CP B | Compare this with the egg's centre Y position. | ||||||||||||
| 27812 | RET | Return (with; carry clear meaning a collision, and carry set meaning no collision). | ||||||||||||
| Prev: 27731 | Up: Map | Next: 27813 |