![]() |
Routines |
| Prev: 26524 | Up: Map | Next: 26845 |
|
Updates a swarm of midges. If the midges touch Robbie then both explode. A repellent spray kills them (worth 80 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+5 holds the horizontal motion and IX+6 holds the vertical motion. In each of them the low nibble is the speed (0 to 15) and the high nibble is the fraction of a pixel left over from the last move (see CalculateMidgesMovement).
|
||||||||||||||||||
|
The object fields used are:
|
||||||||||||||||||
| UpdateMidges | 26542 | CALL UpdateBugCommon | Do the common bug checks using UpdateBugCommon. | |||||||||||||||
| 26545 | DEC E | Decrease the collision result in E by one (zero means that the midges are touching Robbie). | ||||||||||||||||
| 26546 | JP Z,ExplodeRobbie | Jump to ExplodeRobbie if the midges are touching Robbie. | ||||||||||||||||
| 26549 | CALL CheckWeaponHit | Call CheckWeaponHit to check whether a weapon has hit the midges. | ||||||||||||||||
| 26552 | DEC E | Decrease the collision result in E by one (zero means that a weapon has hit the midges). | ||||||||||||||||
| 26553 | JR NZ,UpdateMidges_NoWeaponHit | Jump to UpdateMidges_NoWeaponHit if there was no hit. | ||||||||||||||||
| 26555 | LD A,C | A=the state of the weapon, and jump to MidgesWeaponHit if the weapon is active. | ||||||||||||||||
| 26556 | AND A | |||||||||||||||||
| 26557 | JP NZ,MidgesWeaponHit | |||||||||||||||||
|
This entry point is used by the routine at MidgesWeaponHit.
|
||||||||||||||||||
| UpdateMidges_NoWeaponHit | 26560 | BIT 3,(IX+4) | Jump to EatFlower if the midges are eating the flower. | |||||||||||||||
| 26564 | JP NZ,EatFlower | |||||||||||||||||
| 26567 | CALL BugFlowerCollision | Check whether the midges have reached the flower using BugFlowerCollision. | ||||||||||||||||
| 26570 | DEC E | Decrease the collision result in E by one (zero means that the midges have reached the flower). | ||||||||||||||||
| 26571 | JR Z,StartEatingFlower | Jump to StartEatingFlower if the midges have reached the flower, to start eating it. | ||||||||||||||||
|
Are the midges stunned?
|
||||||||||||||||||
| 26573 | BIT 2,(IX+4) | Jump to UpdateMidges_Horizontal if the midges are not stunned. | ||||||||||||||||
| 26577 | JR Z,UpdateMidges_Horizontal | |||||||||||||||||
| 26579 | DEC (IX+5) | Decrease the stun timer in IX+5 by one. | ||||||||||||||||
| 26582 | JP NZ,DrawObject | Jump to DrawObject if the midges are still stunned, to draw them without moving. | ||||||||||||||||
| 26585 | RES 2,(IX+4) | Reset bit 2 of IX+4 (the stun has ended). | ||||||||||||||||
|
Horizontal movement. Find the target and see which side of it the midges are on.
|
||||||||||||||||||
| UpdateMidges_Horizontal | 26589 | CALL FindBugTarget | Find the target using FindBugTarget, returning HL pointing to the X position of the target. | |||||||||||||||
| 26592 | LD A,(IX+5) | B=the horizontal motion from IX+5. | ||||||||||||||||
| 26595 | LD B,A | |||||||||||||||||
| 26596 | AND 15 | C=the speed (the low nibble). | ||||||||||||||||
| 26598 | LD C,A | |||||||||||||||||
| 26599 | LD A,B | B=the fraction (the high nibble). | ||||||||||||||||
| 26600 | AND 240 | |||||||||||||||||
| 26602 | LD B,A | |||||||||||||||||
| 26603 | LD A,(HL) | A=the X position of the target. | ||||||||||||||||
| 26604 | SUB (IX+1) | Subtract the X position of the midges. | ||||||||||||||||
| 26607 | JP P,UpdateMidges_TargetRight | Jump to UpdateMidges_TargetRight if the target is to the right. | ||||||||||||||||
| 26610 | BIT 6,(IX+0) | Jump to UpdateMidges_TargetLeft if the midges are moving right. | ||||||||||||||||
| 26614 | JP Z,UpdateMidges_TargetLeft | |||||||||||||||||
|
The target is to the left and the midges are moving left, so speed up (to a maximum of 15) and move left.
|
||||||||||||||||||
| UpdateMidges_AccelerateLeft | 26617 | LD A,C | A=the speed. | |||||||||||||||
| 26618 | CP 15 | Increase the speed by one, up to a maximum of 15. | ||||||||||||||||
| 26620 | JR NC,UpdateMidges_MoveLeft | |||||||||||||||||
| 26622 | INC A | |||||||||||||||||
| UpdateMidges_MoveLeft | 26623 | LD C,A | C=the new speed. | |||||||||||||||
| 26624 | LD H,(IX+1) | H=the X position of the midges. | ||||||||||||||||
| 26627 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 26630 | AND A | Subtract the distance from the position. | ||||||||||||||||
| 26631 | SBC HL,DE | |||||||||||||||||
| 26633 | LD A,H | A=the new X position. | ||||||||||||||||
| 26634 | CP 26 | Jump to UpdateMidges_StoreX if the midges have not reached the left edge. | ||||||||||||||||
| 26636 | JR NC,UpdateMidges_StoreX | |||||||||||||||||
| 26638 | RES 6,(IX+0) | Reset bit 6 of IX+0 (turn the midges round to move right). | ||||||||||||||||
| UpdateMidges_StoreX | 26642 | LD (IX+1),A | Write the new X position. | |||||||||||||||
| 26645 | LD A,L | A=the fraction (the high nibble of L). | ||||||||||||||||
| 26646 | AND 240 | |||||||||||||||||
| 26648 | OR C | Add the speed. | ||||||||||||||||
| 26649 | LD (IX+5),A | Write the horizontal motion to IX+5. | ||||||||||||||||
| 26652 | LD A,(IX+1) | A=the X position of the midges. | ||||||||||||||||
| 26655 | CP 24 | Jump to DrawObject to draw the midges without moving vertically if they are too far to the left. | ||||||||||||||||
| 26657 | JP C,DrawObject | |||||||||||||||||
| 26660 | CP 208 | Jump to DrawObject to draw the midges without moving vertically if they are too far to the right. | ||||||||||||||||
| 26662 | JP NC,DrawObject | |||||||||||||||||
|
Vertical movement works in the same way, with the target being above or below the midges.
|
||||||||||||||||||
| UpdateMidges_Vertical | 26665 | CALL FindBugTarget | Find the target using FindBugTarget. | |||||||||||||||
| 26668 | LD A,(IX+6) | B=the vertical motion from IX+6. | ||||||||||||||||
| 26671 | LD B,A | |||||||||||||||||
| 26672 | AND 15 | C=the speed (the low nibble). | ||||||||||||||||
| 26674 | LD C,A | |||||||||||||||||
| 26675 | LD A,B | B=the fraction (the high nibble). | ||||||||||||||||
| 26676 | AND 240 | |||||||||||||||||
| 26678 | LD B,A | |||||||||||||||||
| 26679 | INC HL | Move HL onto the Y position of the target. | ||||||||||||||||
| 26680 | LD A,(HL) | A=the Y position of the target. | ||||||||||||||||
| 26681 | SUB (IX+2) | Subtract the Y position of the midges. | ||||||||||||||||
| 26684 | JP P,UpdateMidges_TargetBelow | Jump to UpdateMidges_TargetBelow if the target is below. | ||||||||||||||||
| 26687 | BIT 7,(IX+0) | Jump to UpdateMidges_AccelerateUp if the midges are moving up. | ||||||||||||||||
| 26691 | JP Z,UpdateMidges_AccelerateUp | |||||||||||||||||
| 26694 | LD A,C | A=the speed. | ||||||||||||||||
| 26695 | DEC A | Decrease the speed by one. | ||||||||||||||||
| 26696 | JR NZ,UpdateMidges_MoveDown | Jump to UpdateMidges_MoveDown if the midges have not stopped. | ||||||||||||||||
| 26698 | RES 7,(IX+0) | Reset bit 7 of IX+0 (turn the midges to move up). | ||||||||||||||||
| UpdateMidges_MoveUp | 26702 | LD C,A | C=the new speed. | |||||||||||||||
| 26703 | LD H,(IX+2) | H=the Y position of the midges. | ||||||||||||||||
| 26706 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 26709 | AND A | Subtract the distance from the position. | ||||||||||||||||
| 26710 | SBC HL,DE | |||||||||||||||||
| 26712 | LD A,H | A=the new Y position. | ||||||||||||||||
| 26713 | CP 40 | Jump to UpdateMidges_StoreY if the midges have not reached the top. | ||||||||||||||||
| 26715 | JR NC,UpdateMidges_StoreY | |||||||||||||||||
| 26717 | SET 7,(IX+0) | Set bit 7 of IX+0 (turn the midges to move down). | ||||||||||||||||
| UpdateMidges_StoreY | 26721 | LD (IX+2),A | Write the new Y position. | |||||||||||||||
| 26724 | LD A,L | A=the fraction (the high nibble of L). | ||||||||||||||||
| 26725 | AND 240 | |||||||||||||||||
| 26727 | OR C | Add the speed. | ||||||||||||||||
| 26728 | LD (IX+6),A | Write the vertical motion to IX+6. | ||||||||||||||||
| 26731 | JP DrawObject | Jump to DrawObject to draw the midges. | ||||||||||||||||
|
The target is to the right.
|
||||||||||||||||||
| UpdateMidges_TargetRight | 26734 | BIT 6,(IX+0) | Jump to UpdateMidges_AccelerateRight if the midges are moving right. | |||||||||||||||
| 26738 | JR Z,UpdateMidges_AccelerateRight | |||||||||||||||||
| 26740 | LD A,C | The midges are moving left, so slow down: A=the speed - 1. | ||||||||||||||||
| 26741 | DEC A | |||||||||||||||||
| 26742 | JP NZ,UpdateMidges_MoveLeft | Jump to UpdateMidges_MoveLeft if the speed is not zero. | ||||||||||||||||
| 26745 | RES 6,(IX+0) | Reset bit 6 of IX+0 (turn the midges to move right). | ||||||||||||||||
| UpdateMidges_MoveRight | 26749 | LD C,A | C=the new speed. | |||||||||||||||
| 26750 | LD H,(IX+1) | H=the X position of the midges. | ||||||||||||||||
| 26753 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 26756 | ADD HL,DE | Add the distance to the position. | ||||||||||||||||
| 26757 | LD A,H | A=the new X position. | ||||||||||||||||
| 26758 | CP 214 | Jump to UpdateMidges_StoreX if the midges have not reached the right edge. | ||||||||||||||||
| 26760 | JP C,UpdateMidges_StoreX | |||||||||||||||||
| 26763 | SET 6,(IX+0) | Set bit 6 of IX+0 (turn the midges round to move left). | ||||||||||||||||
| 26767 | JP UpdateMidges_StoreX | Jump to UpdateMidges_StoreX. | ||||||||||||||||
|
The target is to the right and the midges are moving right, so speed up.
|
||||||||||||||||||
| UpdateMidges_AccelerateRight | 26770 | LD A,C | A=the speed. | |||||||||||||||
| 26771 | CP 15 | Jump to UpdateMidges_MoveRight if the speed is already at the maximum (15). | ||||||||||||||||
| 26773 | JR NC,UpdateMidges_MoveRight | |||||||||||||||||
| 26775 | INC A | Increase the speed by one. | ||||||||||||||||
| 26776 | 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 | 26778 | LD A,C | A=the speed - 1. | |||||||||||||||
| 26779 | DEC A | |||||||||||||||||
| 26780 | JP NZ,UpdateMidges_MoveRight | Jump to UpdateMidges_MoveRight if the speed is not zero. | ||||||||||||||||
| 26783 | SET 6,(IX+0) | Set bit 6 of IX+0 (turn the midges to move left). | ||||||||||||||||
| 26787 | JP UpdateMidges_MoveLeft | Jump to UpdateMidges_MoveLeft. | ||||||||||||||||
|
The target is below the midges.
|
||||||||||||||||||
| UpdateMidges_TargetBelow | 26790 | BIT 7,(IX+0) | Jump to UpdateMidges_TargetBelowMovingUp if the midges are moving up. | |||||||||||||||
| 26794 | JR Z,UpdateMidges_TargetBelowMovingUp | |||||||||||||||||
| 26796 | LD A,C | A=the speed. | ||||||||||||||||
| 26797 | CP 15 | Jump to UpdateMidges_MoveDown if the speed is already at the maximum (15). | ||||||||||||||||
| 26799 | JP NC,UpdateMidges_MoveDown | |||||||||||||||||
| 26802 | INC A | Increase the speed by one. | ||||||||||||||||
| UpdateMidges_MoveDown | 26803 | LD C,A | C=the new speed. | |||||||||||||||
| 26804 | LD H,(IX+2) | H=the Y position of the midges. | ||||||||||||||||
| 26807 | CALL CalculateMidgesMovement | Work out the distance to move using CalculateMidgesMovement. | ||||||||||||||||
| 26810 | ADD HL,DE | Add the distance to the position. | ||||||||||||||||
| 26811 | LD A,H | A=the new Y position. | ||||||||||||||||
| 26812 | CP 182 | Jump to UpdateMidges_StoreY if the midges have not reached the bottom. | ||||||||||||||||
| 26814 | JP C,UpdateMidges_StoreY | |||||||||||||||||
| 26817 | RES 7,(IX+0) | Reset bit 7 of IX+0 (turn the midges to move up). | ||||||||||||||||
| 26821 | 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 | 26824 | LD A,C | A=the speed - 1. | |||||||||||||||
| 26825 | DEC A | |||||||||||||||||
| 26826 | JP NZ,UpdateMidges_MoveUp | Jump to UpdateMidges_MoveUp if the speed is not zero. | ||||||||||||||||
| 26829 | SET 7,(IX+0) | Set bit 7 of IX+0 (turn the midges to move down). | ||||||||||||||||
| 26833 | JR UpdateMidges_MoveDown | Jump to UpdateMidges_MoveDown. | ||||||||||||||||
|
The target is above the midges and they are moving up, so speed up.
|
||||||||||||||||||
| UpdateMidges_AccelerateUp | 26835 | LD A,C | A=the speed. | |||||||||||||||
| 26836 | CP 15 | Jump to UpdateMidges_MoveUp if the speed is already at the maximum (15). | ||||||||||||||||
| 26838 | JP NC,UpdateMidges_MoveUp | |||||||||||||||||
| 26841 | INC A | Increase the speed by one. | ||||||||||||||||
| 26842 | JP UpdateMidges_MoveUp | Jump to UpdateMidges_MoveUp. | ||||||||||||||||
| Prev: 26524 | Up: Map | Next: 26845 |