Prev: 27911 Up: Map Next: 28060
27916: Update Flower
Updates the flower. Nothing happens until Robbie is active and the "get ready" delay has finished. The number of bugs which were eating the flower in the last pass of the main loop is in BugsEating_Flower (which is reset here once it has been read), and the flower then does one of three things each time the timer in IX+5 runs out:
  • grows by one pixel if no bugs are eating it, and the time until the next step is 32 minus four times the number of leaves (see UpdateFlower_Grow);
  • stays where it is if one bug is eating it;
  • sinks by one pixel if more than one bug is eating it (see SinkFlower).
Every time the flower reaches a multiple of sixteen pixels in height, a new leaf is grown using GrowLeaf. If the flower reaches the top it blooms using StartFlowerBloom.
Input
IX Flower object
The object fields used are:
Field Use
+4 The number of leaves on the flower
+5 The timer until the flower next moves
+6 The number of bugs that were eating the flower last time
UpdateFlower 27916 CALL StoreEntity Remember the position and state using StoreEntity.
27919 LD DE,30362 DE=Sprite_Flower_1 (the flower sprite).
27922 LD A,(24172) Jump to DrawFlower to draw the flower if Robbie is inactive.
27925 AND A
27926 JR Z,DrawFlower
27928 LD A,(24098) Jump to DrawFlower to draw the flower if the "get ready" delay in PlayDelay_Counter is not finished.
27931 AND A
27932 JR NZ,DrawFlower
27934 LD A,(24123) A=the number of bugs eating the flower from BugsEating_Flower.
27937 CP (IX+6) Compare it with the number in IX+6.
27940 JR Z,UpdateFlower_Timer Jump to UpdateFlower_Timer if it has not changed.
27942 LD (IX+6),A Remember the new number in IX+6.
27945 LD (IX+5),1 Write 1 to IX+5 so that the timer runs out straight away.
UpdateFlower_Timer 27949 DEC (IX+5) Decrease the timer in IX+5 by one.
27952 JR NZ,DrawFlower Jump to DrawFlower to draw the flower if the timer has not run out.
27954 LD A,(24123) A=the number of bugs eating the flower from BugsEating_Flower.
27957 AND A Test the number.
27958 JR Z,UpdateFlower_Grow Jump to UpdateFlower_Grow if no bugs are eating the flower.
27960 CP 1 Jump to DrawFlower to draw the flower if only one bug is eating it.
27962 JR Z,DrawFlower
27964 JR SinkFlower Jump to SinkFlower to sink the flower.
UpdateFlower_Grow 27966 DEC (IX+2) Decrease the Y position of the flower by one.
27969 LD A,(IX+4) A=the number of leaves from IX+4.
27972 RLCA Multiply it by four.
27973 RLCA
27974 LD B,A B=four times the number of leaves.
27975 LD A,(IX+2) A=the Y position of the flower.
27978 CP 112 Jump to StartFlowerBloom if the flower has reached the top.
27980 JP C,StartFlowerBloom
27983 LD A,32 A=32.
27985 SUB B Subtract four times the number of leaves.
This entry point is used by the routine at SinkFlower.
UpdateFlower_SetTimer 27986 LD (IX+5),A Write the time until the next move to IX+5.
27989 LD A,(24085) A=LeafGrowth_Flags.
27992 AND %01000000 Keep only bit 6.
27994 LD (24085),A Write it back to LeafGrowth_Flags (so bit 0 is reset and a leaf can be added).
27997 CALL ReplaceSprite Move the flower sprite using ReplaceSprite.
This entry point is used by the routine at DrawFlower.
UpdateFlower_Colour 28000 CALL ColouriseSprite Colour the sprite using ColouriseSprite.
Draw the stem of the flower from the flower down to the ground.
28003 LD L,(IX+1) L=the X position of the flower.
28006 LD H,(IX+2) H=the Y position of the flower.
UpdateFlower_Stem_Loop 28009 LD A,H A=the Y position.
28010 CP 184 Jump to UpdateFlower_Finish if the bottom of the stem has been reached.
28012 JR NC,UpdateFlower_Finish
28014 CPL Invert all of the bits in A.
28015 AND %00000111 Keep only bits 0-2.
28017 JR NZ,UpdateFlower_Stem_Pixels Jump to UpdateFlower_Stem_Pixels unless this is the last pixel row in a cell.
28019 PUSH HL Stash the position on the stack.
28020 CALL AttributeAddress Convert the position to an attribute buffer address using AttributeAddress.
28023 LD (HL),124 Write 124 (bright green on white) to the attribute buffer.
28025 POP HL Restore the position from the stack.
UpdateFlower_Stem_Pixels 28026 PUSH HL Stash the position on the stack.
28027 CALL ScreenAddress Convert the position to a screen address using ScreenAddress.
28030 LD (HL),185 Write 185 to the screen.
28032 POP HL Restore the position from the stack.
28033 INC H Move down one pixel row.
28034 JR UpdateFlower_Stem_Loop Jump to UpdateFlower_Stem_Loop.
UpdateFlower_Finish 28036 XOR A Write 0 to BugsEating_Flower (the number of bugs eating the flower).
28037 LD (24123),A
28040 LD A,(IX+4) A=the number of leaves from IX+4.
28043 AND A Test the number.
28044 RET M Return if it is negative.
28045 LD A,(24085) A=LeafGrowth_Flags.
28048 AND %00000001 Keep only bit 0.
28050 RET NZ Return if a leaf has already been added.
28051 LD A,(IX+2) A=the Y position of the flower.
28054 AND %00001111 Keep only bits 0-3.
28056 RET NZ Return unless the Y position is a multiple of sixteen.
28057 JP GrowLeaf Jump to GrowLeaf to grow a leaf.
Prev: 27911 Up: Map Next: 28060