Prev: 625C Up: Map Next: 6318
62DA: Locate Radar Cup
Used by the routine at UpdateRadar.
Finds a cup to show on the radar. Each of the 08 cups in CupTable is checked in turn: if the map entry still has the cup sprite ID (20) and the cup is less than 0C cells (of 20 map units) from the player horizontally, then it is placed on the radar by LocateRadarBlip. Only the first such cup is used. If there is no cup then the blip is hidden.
Input
IX Radar blip record
Find the player's horizontal position in cells.
CollisionCup 62DA LD HL,($5E05) Fetch the player's X position on the map from PlayerMapPosition.
62DD SLA L Double the value so it matches the scale used by the radar.
62DF RL H
62E1 CALL MultiplyHLByFour Call MultiplyHLByFour to multiply the position by 04 which leaves the position in cells in H.
62E4 LD C,H Keep the player's X position in cells in C.
62E5 LD HL,$721F Point HL at the table of cup map addresses (CupTable).
62E8 LD B,$08 Set the cup counter to 08 one for each cup.
Fetch the address of the cup from CupTable.
CollisionCup_Loop 62EA LD E,(HL) Fetch the low byte of the map address of this cup.
62EB INC HL Move on to the high byte.
62EC LD D,(HL) Fetch the high byte of the map address of this cup.
62ED INC HL Move on to the next cup in the table.
Check this is still a valid cup (that it hasn't been collected already).
62EE INC DE Point DE at the sprite ID of the map entry.
62EF INC DE
62F0 LD A,(DE) If this is not a cup (the sprite ID is not 20) then jump to CollisionCup_Next.
62F1 CP $20
62F3 JR NZ,CollisionCup_Next
This is still a valid cup, so process it.
62F5 DEC DE Point DE back at the start of the map entry.
62F6 DEC DE
62F7 LD A,(DE) Fetch the X position of the cup.
62F8 SUB C Subtract the player's X position to give the horizontal distance.
62F9 JR NC,CollisionCup_Test_X Make the distance positive.
62FB NEG
CollisionCup_Test_X 62FD CP $0C If the cup is less than 0C cells away then jump to CollisionCup_Test_Y.
62FF JR C,CollisionCup_Test_Y
CollisionCup_Next 6301 DJNZ CollisionCup_Loop Decrease the cup counter by one and loop back to CollisionCup_Loop until all of the cups have been checked.
6303 JP HideRadarBlip There is no cup in range so jump to HideRadarBlip to hide the blip.
Convert the position of the cup to the same scale used by LocateRadarBlip.
CollisionCup_Test_Y 6306 LD A,(DE) Fetch the X position of the cup.
6307 INC DE Point DE at the Y position of the cup.
6308 LD H,A Keep the X position of the cup in H.
6309 LD A,(DE) Fetch the Y position of the cup.
630A LD D,A Keep the Y position of the cup in D.
630B CALL ScaleValue_DivideByEight Call ScaleValue_DivideByEight to set DE to the cup Y position multiplied by 20.
630E EX DE,HL Swap the DE and HL registers.
630F CALL ScaleValue Call ScaleValue to set DE to the cup X position multiplied by 40.
6312 EX DE,HL Swap the DE and HL registers.
6313 LD B,H Move the high byte of the doubled X position into B.
6314 LD C,L Move the low byte of the doubled X position into C.
6315 JP LocateRadarBlip Jump to LocateRadarBlip to place the blip (BC is the cup X position and DE is the cup Y position, both doubled).
View the equivalent code in;
Prev: 625C Up: Map Next: 6318