Prev: 27914 Up: Map Next: 28101
27932: Control the horizontal flight of a catapult pellet
The address of this uninterruptible subcommand routine is placed into bytes 111 and 112 of a catapult pellet's buffer by the routine at 28744. It controls the pellet from the beginning of its horizontal flight to the end, handing over to the routine at 28102 if the pellet bounces upwards off some obstacle.
Input
H 170 (BOY WANDER's pellet) or 171 (ERIC's pellet)
Output
27932 CALL 25108 Update the SRB for the pellet's current location
27935 LD L,113 Byte 113 of the pellet's buffer holds the distance left to travel
27937 DEC (HL) Has the pellet finished travelling?
27938 JR NZ,27949 Jump if not
This entry point is used by the routine at 28102. It places the catapult pellet off-screen and terminates its flight.
27940 LD L,98 Set the pellet's x-coordinate to 150 (i.e. off-screen)
27942 LD (HL),150
27944 LD L,112 Remove the address of this routine from bytes 111 and 112 of the pellet's buffer
27946 LD (HL),0
27948 RET
The pellet has not finished travelling. Where to next?
27949 INC E Set E equal to the next x-coordinate for the pellet
27950 RLCA
27951 JR C,27955
27953 DEC E
27954 DEC E
27955 LD A,E A=pellet's next x-coordinate
27956 CP 96 Will it still be on-screen?
27958 JR NC,27940 Terminate the pellet if not
27960 LD A,D A=pellet's y-coordinate
27961 CALL 26185 Was the pellet fired on the top, middle or bottom floor?
27964 JR NZ,27981 Jump if not
27966 CP 169 Is the pellet on the bottom floor?
27968 JR Z,27981 Jump if so
27970 CP 155 Set the zero flag if the pellet is on the top floor
27972 LD A,38 This is the x-coordinate of the wall between the White and Exam Rooms
27974 JR NZ,27978 Jump if the pellet is on the middle floor
27976 LD A,57 This is the x-coordinate of the wall between the Reading and Map Rooms
27978 CP E Has the pellet hit a wall?
27979 JR Z,27940 Terminate the pellet if so
27981 LD L,96 Byte 96 of the pellet's buffer holds its animatory state
27983 LD A,(HL) Pick this up in A
27984 CALL 25008 Update the pellet's location and update the SRB
27987 LD L,97 Byte 97 of the pellet's buffer holds its y-coordinate
27989 LD A,(HL) Pick this up in A
27990 CALL 26185 Was the pellet fired on the top, middle or bottom floor?
27993 JP NZ,28123 Jump if not
The pellet was fired on the top, middle or bottom floor. Let's see if it's hit anybody.
27996 LD L,113 Byte 113 of the pellet's buffer holds the distance left to travel
27998 LD A,(HL) Pick this up in A
27999 CP 8 Is the pellet ready to hit something?
28001 RET NC Return if not
28002 LD DE,44130 Point DE at ERIC's x-coordinate
28005 LD L,E L=98
28006 LD A,(DE) Pick up ERIC's x-coordinate in A
28007 CP (HL) Does it match the pellet's x-coordinate?
28008 JR NZ,28036 Jump if not
28010 DEC E E=97
28011 DEC L L=97
28012 LD A,(DE) Pick up ERIC's y-coordinate in A
28013 INC E E=98
28014 CP (HL) Compare ERIC's y-coordinate with that of the pellet
28015 LD L,E L=98
28016 JR NZ,28036 Jump unless ERIC's location matches that of the pellet
ERIC has been hit by the pellet. Knock him over.
28018 LD DE,32763 Signal that ERIC has been knocked over by setting bit 4 of ERIC's status flags at 32763
28021 EX DE,HL
28022 SET 4,(HL)
28024 EX DE,HL
28025 LD L,113 The pellet has hit something; set its remaining distance to travel to 1, so it's terminated next time
28027 LD (HL),1
28029 LD A,D A=number of the character hit by the pellet
28030 CP 168 Was ANGELFACE hit?
28032 JP Z,27387 Add to the score and print it if so
28035 RET
ERIC wasn't hit by the pellet. What about the main kids and teachers?
28036 LD D,169 169=EINSTEIN
28038 LD B,7 There are 3 main kids and 4 teachers
28040 LD A,(DE) Pick up the potential target's x-coordinate in A
28041 CP (HL) Does it match that of the pellet?
28042 JR Z,28048 Jump if so
28044 DEC D Next main kid or teacher
28045 DJNZ 28040 Jump back until all the main kids and teachers have been checked
28047 RET
28048 DEC E E=97
28049 DEC L L=97
28050 LD A,(DE) Pick up the potential target's y-coordinate in A
28051 INC E E=98
28052 CP (HL) Compare the potential target's y-coordinate
28053 LD L,E L=98
28054 JR NZ,28044 Jump unless the potential target's coordinates match
We have found a potential target at the pellet's current coordinates. Can we knock him over?
28056 LD E,112 Byte 112 of the character's buffer may hold the MSB of an uninterruptible subcommand routine address; pick this up in A
28058 LD A,(DE)
28059 LD E,L E=98
28060 AND A Is there an uninterruptible subcommand routine address in bytes 111 and 112?
28061 JR NZ,28076 Jump if so
28063 EX DE,HL
28064 LD L,111 Place the address of the uninterruptible subcommand routine at 27206 into bytes 111 and 112 of the character's buffer, which will knock the character over
28066 LD (HL),70
28068 INC L
28069 LD (HL),106
28071 INC L Initialise the parameter determining how long the character will stay down in byte 113 of his buffer
28072 LD (HL),20
28074 JR 28024
The potential target may already have been knocked over. Let's check.
28076 LD E,96 Byte 96 of the buffer holds the potential target's animatory state
28078 LD A,(DE) Pick this up in A
28079 LD E,L E=98
28080 AND 127 Remove the direction bit (bit 7)
28082 CP 72 Is the potential target a kid?
28084 JR C,28044 Jump back to consider the next main kid or teacher if so
28086 AND 7 Retain only bits 0-2 of the teacher's animatory state
28088 CP 7 Has the teacher already been knocked down?
28090 JR NZ,28044 Jump back to consider the next teacher if not
The pellet has hit a teacher who's already been knocked over. Prepare for vertical flight.
28092 LD L,111 Place the address of the uninterruptible subcommand routine at 28102 into bytes 111 and 112 of the pellet's character buffer, which will make the pellet travel upwards from now on
28094 LD (HL),198
28096 LD L,113 Set the pellet's remaining distance to travel to 5 spaces
28098 LD (HL),5
28100 RET
Prev: 27914 Up: Map Next: 28101