Prev: 25837 Up: Map Next: 26042
25850: Update Leech
Updates a leech. If the leech is touching Robbie then both explode. A weapon hitting the leech either kills it (a streamer, worth 117 points) or stuns it for a while (the repellent spray), and smoke bombs have no effect. When the leech touches the flower it starts to eat it. Otherwise it crawls horizontally along the ground in steps of two pixels, bouncing off the sides of the play area, and every so often it also moves vertically for a random period.
Input
IX Leech object
The object fields used are:
Field Use
+0 bit 6 Moving right
+0 bit 7 Moving down
+4 bit 0 Moving vertically
+4 bit 2 Stunned
+4 bit 3 Eating the flower
+5 Stun timer
+6 Vertical movement counter
UpdateLeech 25850 CALL UpdateBugCommon Do the common bug checks using UpdateBugCommon.
25853 DEC E Decrease the collision result in E by one (zero means that the leech is touching Robbie).
25854 JP Z,ExplodeRobbie Jump to ExplodeRobbie if the leech is touching Robbie.
Check whether a weapon has hit the leech.
25857 CALL CheckWeaponHit Check whether a weapon has hit the leech using CheckWeaponHit.
25860 DEC E Decrease the collision result in E by one (zero means that a weapon has hit the leech).
25861 JR NZ,UpdateLeech_NoWeaponHit Jump to UpdateLeech_NoWeaponHit if there was no hit.
25863 LD A,C A=the state of the weapon, and jump to LeechWeaponHit if the weapon is active.
25864 AND A
25865 JP NZ,LeechWeaponHit
This entry point is used by the routine at LeechWeaponHit.
UpdateLeech_NoWeaponHit 25868 BIT 3,(IX+4) Jump to EatFlower if the leech is eating the flower.
25872 JP NZ,EatFlower
25875 CALL BugFlowerCollision Check whether the leech has reached the flower using BugFlowerCollision.
25878 DEC E Decrease the collision result in E by one (zero means that the leech has reached the flower).
25879 JP Z,StartEatingFlower Jump to StartEatingFlower if the leech has reached the flower, to start eating it.
Is the leech stunned?
25882 BIT 2,(IX+4) Jump to UpdateLeech_Vertical if the leech is not stunned.
25886 JR Z,UpdateLeech_Vertical
25888 DEC (IX+5) Decrease the stun timer in IX+5 by one.
25891 JP NZ,UpdateLeech_Draw Jump to UpdateLeech_Draw if the leech is still stunned, to redraw it without moving.
25894 RES 2,(IX+4) Reset bit 2 of IX+4 (the stun has ended).
If the leech is not moving vertically there is a one in thirty-two chance of it starting to.
UpdateLeech_Vertical 25898 BIT 0,(IX+4) Jump to UpdateLeech_MoveVertical if it is moving vertically.
25902 JR NZ,UpdateLeech_MoveVertical
25904 LD A,(24089) E=the random number from RandomNumber.
25907 LD E,A
25908 AND 31 Jump to UpdateLeech_MoveVertical unless the random number is a multiple of 32.
25910 JR NZ,UpdateLeech_MoveVertical
25912 SET 0,(IX+4) Set bit 0 of IX+4 (moving vertically).
25916 LD A,(24087) A=GameTimer.
25919 AND %00011111 Keep only bits 0-4.
25921 ADD A,16 Add 16 (this value is not stored, as the next instruction overwrites it).
25923 LD A,(IX+6) A=IX+6 (the vertical movement counter).
25926 LD A,E A=the random number.
25927 AND %10000000 Keep only bit 7 (the direction).
25929 LD E,A Keep the direction bit in E.
25930 LD A,(IX+0) A=IX+0 (the state).
25933 AND %01111111 Reset bit 7 (move up).
25935 OR E Set bit 7 if the random number had bit 7 set, and write the state back.
25936 LD (IX+0),A
25939 JR UpdateLeech_NoWeaponHit Jump to UpdateLeech_NoWeaponHit.
UpdateLeech_MoveVertical 25941 BIT 0,(IX+4) Jump to UpdateLeech_MoveHorizontal if the leech is not moving vertically.
25945 JR Z,UpdateLeech_MoveHorizontal
25947 LD A,(IX+1) A=leech X position.
25950 CP 24 Jump to UpdateLeech_MoveHorizontal if the leech is too far left to move vertically.
25952 JR C,UpdateLeech_MoveHorizontal
25954 CP 216 Jump to UpdateLeech_MoveHorizontal if the leech is too far right to move vertically.
25956 JR NC,UpdateLeech_MoveHorizontal
25958 LD A,(IX+2) A=leech Y position.
25961 BIT 7,(IX+0) Jump to UpdateLeech_MoveUp if the leech is moving up (bit 7 is not set).
25965 JR Z,UpdateLeech_MoveUp
25967 ADD A,2 Add 2 to move down.
25969 CP 184 Jump to UpdateLeech_StoreY if this is above the bottom of the play area.
25971 JR C,UpdateLeech_StoreY
25973 RES 7,(IX+0) Reset bit 7 of IX+0 (turn the leech upwards).
25977 JR UpdateLeech_Countdown Jump to UpdateLeech_Countdown.
UpdateLeech_StoreY 25979 LD (IX+2),A Write the new Y position.
UpdateLeech_Countdown 25982 DEC (IX+6) Decrease the vertical movement counter by one.
25985 JR NZ,UpdateLeech_MoveHorizontal Jump to UpdateLeech_MoveHorizontal if the counter is not zero.
25987 RES 0,(IX+4) Reset bit 0 of IX+4 (stop moving vertically).
Move the leech horizontally.
UpdateLeech_MoveHorizontal 25991 LD A,(IX+1) A=leech X position.
25994 BIT 6,(IX+0) Jump to UpdateLeech_MoveLeft if the leech is moving left (bit 6 is not set).
25998 JR Z,UpdateLeech_MoveLeft
26000 ADD A,2 Add 2 to move right.
26002 CP 216 Jump to UpdateLeech_StoreX if this is not past the right edge.
26004 JR C,UpdateLeech_StoreX
26006 RES 6,(IX+0) Reset bit 6 of IX+0 (turn the leech to the left).
26010 JR UpdateLeech_Draw Jump to UpdateLeech_Draw.
UpdateLeech_StoreX 26012 LD (IX+1),A Write the new X position.
UpdateLeech_Draw 26015 JP DrawObject Jump to DrawObject to draw the leech.
Moving up.
UpdateLeech_MoveUp 26018 SUB 2 Subtract 2 to move up.
26020 CP 40 Jump to UpdateLeech_StoreY if this is not above the top limit.
26022 JR NC,UpdateLeech_StoreY
26024 SET 7,(IX+0) Set bit 7 of IX+0 (turn the leech downwards).
26028 JR UpdateLeech_StoreY Jump to UpdateLeech_StoreY.
Moving left.
UpdateLeech_MoveLeft 26030 SUB 2 Subtract 2 to move left.
26032 CP 24 Jump to UpdateLeech_StoreX if this is not past the left edge.
26034 JR NC,UpdateLeech_StoreX
26036 SET 6,(IX+0) Set bit 6 of IX+0 (turn the leech to the right).
26040 JR UpdateLeech_Draw Jump to UpdateLeech_Draw.
Prev: 25837 Up: Map Next: 26042