![]() |
Routines |
| Prev: 679C | Up: Map | Next: 68DD |
|
Updates a swarm of midges. If the midges touch Robbie then both explode. A repellent spray kills them (worth 50 points), a smoke bomb stuns them, and a streamer has no effect. When they reach the flower they start to eat it.
Otherwise they fly towards a target (Robbie, or the flower if that is closer) and use a speed and a direction in each axis, so that they speed up when flying towards the target and slow down, stop and turn round when flying away from it. IX+05 holds the horizontal motion and IX+06 holds the vertical motion. In each of them the low nibble is the speed (00 to 0F) and the high nibble is the fraction of a pixel left over from the last move (see CalculateMidgesMovement).
|
||||||||||||||||||
|
The object fields used are:
|
||||||||||||||||||
| UpdateMidges | 67AE | CALL UpdateBugCommon | Do the common bug checks using UpdateBugCommon. | |||||||||||||||
| 67B1 | DEC E | Decrease the collision result in E by one (zero means that the midges are touching Robbie). | ||||||||||||||||
| 67B2 | JP Z,ExplodeRobbie | Jump to ExplodeRobbie if the midges are touching Robbie. | ||||||||||||||||
| 67B5 | CALL CheckWeaponHit | Call CheckWeaponHit to check whether a weapon has hit the midges. | ||||||||||||||||
| 67B8 | DEC E | Decrease the collision result in E by one (zero means that a weapon has hit the midges). | ||||||||||||||||
| 67B9 | JR NZ,UpdateMidges_NoWeaponHit | Jump to UpdateMidges_NoWeaponHit if there was no hit. | ||||||||||||||||
| 67BB | LD A,C | A=the state of the weapon, and jump to MidgesWeaponHit if the weapon is active. | ||||||||||||||||
| 67BC | AND A | |||||||||||||||||
| 67BD | JP NZ,MidgesWeaponHit | |||||||||||||||||
|
This entry point is used by the routine at MidgesWeaponHit.
|
||||||||||||||||||
| UpdateMidges_NoWeaponHit | 67C0 | BIT 3,(IX+$04) | Jump to EatFlower if the midges are eating the flower. | |||||||||||||||
| 67C4 | JP NZ,EatFlower | |||||||||||||||||
| 67C7 | CALL BugFlowerCollision | Check whether the midges have reached the flower using BugFlowerCollision. | ||||||||||||||||
| 67CA | DEC E | Decrease the collision result in E by one (zero means that the midges have reached the flower). | ||||||||||||||||
| 67CB | JR Z,StartEatingFlower | Jump to StartEatingFlower if the midges have reached the flower, to start eating it. | ||||||||||||||||
|
Are the midges stunned?
|
||||||||||||||||||
| 67CD | BIT 2,(IX+$04) | Jump to UpdateMidges_Horizontal if the midges are not stunned. | ||||||||||||||||
| 67D1 | JR Z,UpdateMidges_Horizontal | |||||||||||||||||
| 67D3 | DEC (IX+$05) | Decrease the stun timer in IX+05 by one. | ||||||||||||||||
| 67D6 | JP NZ,DrawObject | Jump to DrawObject if the midges are still stunned, to draw them without moving. | ||||||||||||||||
| 67D9 | RES 2,(IX+$04) | Reset bit 2 of IX+04 (the stun has ended). | ||||||||||||||||
|
Horizontal movement. Find the target and see which side of it the midges are on.
|
||||||||||||||||||
| UpdateMidges_Horizontal | 67DD | CALL FindBugTarget | Find the target using FindBugTarget, returning HL pointing to the X position of the target. | |||||||||||||||
| 67E0 | LD A,(IX+$05) | B=the horizontal motion from IX+05. | ||||||||||||||||
| 67E3 | LD B,A | |||||||||||||||||
| 67E4 | AND $0F | C=the speed (the low nibble). | ||||||||||||||||
| 67E6 | LD C,A | |||||||||||||||||
| 67E7 | LD A,B | B=the fraction (the high nibble). | ||||||||||||||||
| 67E8 | AND $F0 | |||||||||||||||||
| 67EA | LD B,A | |||||||||||||||||
| 67EB | LD A,(HL) | A=the X position of the target. | ||||||||||||||||
| 67EC | SUB (IX+$01) | Subtract the X position of the midges. | ||||||||||||||||
| 67EF | JP P,UpdateMidges_TargetRight | Jump to UpdateMidges_TargetRight if the target is to the right. | ||||||||||||||||
| 67F2 | BIT 6,(IX+$00) | Jump to UpdateMidges_TargetLeft if the midges are moving right. | ||||||||||||||||
| 67F6 | JP Z,UpdateMidges_TargetLeft | |||||||||||||||||
|
The target is to the left and the midges are moving left, so speed up (to a maximum of 0F) and move left.
|
||||||||||||||||||
| UpdateMidges_AccelerateLeft | 67F9 | LD A,C | A=the speed. | |||||||||||||||
| 67FA | CP $0F | Increase the speed by one, up to a maximum of 0F. | ||||||||||||||||
| 67FC | JR NC,UpdateMidges_MoveLeft | |||||||||||||||||
| 67FE | INC A | |||||||||||||||||
| UpdateMidges_MoveLeft | 67FF | LD C,A | C=the new speed. | |||||||||||||||
| 6800 | LD H,(IX+$01) | H=the X position of the midges. | ||||||||||||||||
| 6803 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 6806 | AND A | Subtract the distance from the position. | ||||||||||||||||
| 6807 | SBC HL,DE | |||||||||||||||||
| 6809 | LD A,H | A=the new X position. | ||||||||||||||||
| 680A | CP $1A | Jump to UpdateMidges_StoreX if the midges have not reached the left edge. | ||||||||||||||||
| 680C | JR NC,UpdateMidges_StoreX | |||||||||||||||||
| 680E | RES 6,(IX+$00) | Reset bit 6 of IX+00 (turn the midges round to move right). | ||||||||||||||||
| UpdateMidges_StoreX | 6812 | LD (IX+$01),A | Write the new X position. | |||||||||||||||
| 6815 | LD A,L | A=the fraction (the high nibble of L). | ||||||||||||||||
| 6816 | AND $F0 | |||||||||||||||||
| 6818 | OR C | Add the speed. | ||||||||||||||||
| 6819 | LD (IX+$05),A | Write the horizontal motion to IX+05. | ||||||||||||||||
| 681C | LD A,(IX+$01) | A=the X position of the midges. | ||||||||||||||||
| 681F | CP $18 | Jump to DrawObject to draw the midges without moving vertically if they are too far to the left. | ||||||||||||||||
| 6821 | JP C,DrawObject | |||||||||||||||||
| 6824 | CP $D0 | Jump to DrawObject to draw the midges without moving vertically if they are too far to the right. | ||||||||||||||||
| 6826 | JP NC,DrawObject | |||||||||||||||||
|
Vertical movement works in the same way, with the target being above or below the midges.
|
||||||||||||||||||
| UpdateMidges_Vertical | 6829 | CALL FindBugTarget | Find the target using FindBugTarget. | |||||||||||||||
| 682C | LD A,(IX+$06) | B=the vertical motion from IX+06. | ||||||||||||||||
| 682F | LD B,A | |||||||||||||||||
| 6830 | AND $0F | C=the speed (the low nibble). | ||||||||||||||||
| 6832 | LD C,A | |||||||||||||||||
| 6833 | LD A,B | B=the fraction (the high nibble). | ||||||||||||||||
| 6834 | AND $F0 | |||||||||||||||||
| 6836 | LD B,A | |||||||||||||||||
| 6837 | INC HL | Move HL onto the Y position of the target. | ||||||||||||||||
| 6838 | LD A,(HL) | A=the Y position of the target. | ||||||||||||||||
| 6839 | SUB (IX+$02) | Subtract the Y position of the midges. | ||||||||||||||||
| 683C | JP P,UpdateMidges_TargetBelow | Jump to UpdateMidges_TargetBelow if the target is below. | ||||||||||||||||
| 683F | BIT 7,(IX+$00) | Jump to UpdateMidges_AccelerateUp if the midges are moving up. | ||||||||||||||||
| 6843 | JP Z,UpdateMidges_AccelerateUp | |||||||||||||||||
| 6846 | LD A,C | A=the speed. | ||||||||||||||||
| 6847 | DEC A | Decrease the speed by one. | ||||||||||||||||
| 6848 | JR NZ,UpdateMidges_MoveDown | Jump to UpdateMidges_MoveDown if the midges have not stopped. | ||||||||||||||||
| 684A | RES 7,(IX+$00) | Reset bit 7 of IX+00 (turn the midges to move up). | ||||||||||||||||
| UpdateMidges_MoveUp | 684E | LD C,A | C=the new speed. | |||||||||||||||
| 684F | LD H,(IX+$02) | H=the Y position of the midges. | ||||||||||||||||
| 6852 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 6855 | AND A | Subtract the distance from the position. | ||||||||||||||||
| 6856 | SBC HL,DE | |||||||||||||||||
| 6858 | LD A,H | A=the new Y position. | ||||||||||||||||
| 6859 | CP $28 | Jump to UpdateMidges_StoreY if the midges have not reached the top. | ||||||||||||||||
| 685B | JR NC,UpdateMidges_StoreY | |||||||||||||||||
| 685D | SET 7,(IX+$00) | Set bit 7 of IX+00 (turn the midges to move down). | ||||||||||||||||
| UpdateMidges_StoreY | 6861 | LD (IX+$02),A | Write the new Y position. | |||||||||||||||
| 6864 | LD A,L | A=the fraction (the high nibble of L). | ||||||||||||||||
| 6865 | AND $F0 | |||||||||||||||||
| 6867 | OR C | Add the speed. | ||||||||||||||||
| 6868 | LD (IX+$06),A | Write the vertical motion to IX+06. | ||||||||||||||||
| 686B | JP DrawObject | Jump to DrawObject to draw the midges. | ||||||||||||||||
|
The target is to the right.
|
||||||||||||||||||
| UpdateMidges_TargetRight | 686E | BIT 6,(IX+$00) | Jump to UpdateMidges_AccelerateRight if the midges are moving right. | |||||||||||||||
| 6872 | JR Z,UpdateMidges_AccelerateRight | |||||||||||||||||
| 6874 | LD A,C | The midges are moving left, so slow down: A=the speed - 01. | ||||||||||||||||
| 6875 | DEC A | |||||||||||||||||
| 6876 | JP NZ,UpdateMidges_MoveLeft | Jump to UpdateMidges_MoveLeft if the speed is not zero. | ||||||||||||||||
| 6879 | RES 6,(IX+$00) | Reset bit 6 of IX+00 (turn the midges to move right). | ||||||||||||||||
| UpdateMidges_MoveRight | 687D | LD C,A | C=the new speed. | |||||||||||||||
| 687E | LD H,(IX+$01) | H=the X position of the midges. | ||||||||||||||||
| 6881 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 6884 | ADD HL,DE | Add the distance to the position. | ||||||||||||||||
| 6885 | LD A,H | A=the new X position. | ||||||||||||||||
| 6886 | CP $D6 | Jump to UpdateMidges_StoreX if the midges have not reached the right edge. | ||||||||||||||||
| 6888 | JP C,UpdateMidges_StoreX | |||||||||||||||||
| 688B | SET 6,(IX+$00) | Set bit 6 of IX+00 (turn the midges round to move left). | ||||||||||||||||
| 688F | JP UpdateMidges_StoreX | Jump to UpdateMidges_StoreX. | ||||||||||||||||
|
The target is to the right and the midges are moving right, so speed up.
|
||||||||||||||||||
| UpdateMidges_AccelerateRight | 6892 | LD A,C | A=the speed. | |||||||||||||||
| 6893 | CP $0F | Jump to UpdateMidges_MoveRight if the speed is already at the maximum (0F). | ||||||||||||||||
| 6895 | JR NC,UpdateMidges_MoveRight | |||||||||||||||||
| 6897 | INC A | Increase the speed by one. | ||||||||||||||||
| 6898 | JR UpdateMidges_MoveRight | Jump to UpdateMidges_MoveRight. | ||||||||||||||||
|
The target is to the left but the midges are moving right, so slow down and turn round when they have stopped.
|
||||||||||||||||||
| UpdateMidges_TargetLeft | 689A | LD A,C | A=the speed - 01. | |||||||||||||||
| 689B | DEC A | |||||||||||||||||
| 689C | JP NZ,UpdateMidges_MoveRight | Jump to UpdateMidges_MoveRight if the speed is not zero. | ||||||||||||||||
| 689F | SET 6,(IX+$00) | Set bit 6 of IX+00 (turn the midges to move left). | ||||||||||||||||
| 68A3 | JP UpdateMidges_MoveLeft | Jump to UpdateMidges_MoveLeft. | ||||||||||||||||
|
The target is below the midges.
|
||||||||||||||||||
| UpdateMidges_TargetBelow | 68A6 | BIT 7,(IX+$00) | Jump to UpdateMidges_TargetBelowMovingUp if the midges are moving up. | |||||||||||||||
| 68AA | JR Z,UpdateMidges_TargetBelowMovingUp | |||||||||||||||||
| 68AC | LD A,C | A=the speed. | ||||||||||||||||
| 68AD | CP $0F | Jump to UpdateMidges_MoveDown if the speed is already at the maximum (0F). | ||||||||||||||||
| 68AF | JP NC,UpdateMidges_MoveDown | |||||||||||||||||
| 68B2 | INC A | Increase the speed by one. | ||||||||||||||||
| UpdateMidges_MoveDown | 68B3 | LD C,A | C=the new speed. | |||||||||||||||
| 68B4 | LD H,(IX+$02) | H=the Y position of the midges. | ||||||||||||||||
| 68B7 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 68BA | ADD HL,DE | Add the distance to the position. | ||||||||||||||||
| 68BB | LD A,H | A=the new Y position. | ||||||||||||||||
| 68BC | CP $B6 | Jump to UpdateMidges_StoreY if the midges have not reached the bottom. | ||||||||||||||||
| 68BE | JP C,UpdateMidges_StoreY | |||||||||||||||||
| 68C1 | RES 7,(IX+$00) | Reset bit 7 of IX+00 (turn the midges to move up). | ||||||||||||||||
| 68C5 | JP UpdateMidges_StoreY | Jump to UpdateMidges_StoreY. | ||||||||||||||||
|
The target is below the midges but they are moving up, so slow down and turn round when they have stopped.
|
||||||||||||||||||
| UpdateMidges_TargetBelowMovingUp | 68C8 | LD A,C | A=the speed - 01. | |||||||||||||||
| 68C9 | DEC A | |||||||||||||||||
| 68CA | JP NZ,UpdateMidges_MoveUp | Jump to UpdateMidges_MoveUp if the speed is not zero. | ||||||||||||||||
| 68CD | SET 7,(IX+$00) | Set bit 7 of IX+00 (turn the midges to move down). | ||||||||||||||||
| 68D1 | JR UpdateMidges_MoveDown | Jump to UpdateMidges_MoveDown. | ||||||||||||||||
|
The target is above the midges and they are moving up, so speed up.
|
||||||||||||||||||
| UpdateMidges_AccelerateUp | 68D3 | LD A,C | A=the speed. | |||||||||||||||
| 68D4 | CP $0F | Jump to UpdateMidges_MoveUp if the speed is already at the maximum (0F). | ||||||||||||||||
| 68D6 | JP NC,UpdateMidges_MoveUp | |||||||||||||||||
| 68D9 | INC A | Increase the speed by one. | ||||||||||||||||
| 68DA | JP UpdateMidges_MoveUp | Jump to UpdateMidges_MoveUp. | ||||||||||||||||
| Prev: 679C | Up: Map | Next: 68DD |