![]() |
Routines |
| Prev: 27815 | Up: Map | Next: 27960 |
|
The handler for the sugar (IDs 8 and 9), which drifts about the screen. Byte 4 of the actor is the horizontal speed, and byte 5 is the vertical speed. Every 32 frames new random speeds are chosen (see SetRandomSpeeds); they are both either 2 or 254 (-2). The sugar bounces off the sides and the top and bottom of the play area, and as it goes it also moves up and down in a wave, which is made from the frame counter in byte 7 of the actor.
While the sugar is still entering from the right of the screen (a horizontal co-ordinate of 196 or more) it can't hit Charlie or be hit.
|
||||||||
| HandleSugar | 27831 | CALL StoreEntity | Record the position of the sprite using StoreEntity. | |||||
| 27834 | LD HL,24347 | Point HL at ActorsInPlay. | ||||||
| 27837 | INC (HL) | Increase the number of actors in play by one. | ||||||
| 27838 | LD A,(IX+1) | Fetch the horizontal co-ordinate. | ||||||
| 27841 | CP 196 | Jump to HandleSugar_Move if the sugar is still entering from the right. | ||||||
| 27843 | JR NC,HandleSugar_Move | |||||||
| 27845 | CALL TestCharlieCollision | Test whether the sugar has hit Charlie using TestCharlieCollision. | ||||||
| 27848 | DEC E | Has Charlie been hit (is E now zero)? | ||||||
| 27849 | JP Z,LoseHat | Jump to LoseHat if Charlie has been hit. | ||||||
| 27852 | CALL TestFlourCollision | Test whether a flour shot has hit the sugar using TestFlourCollision. | ||||||
| 27855 | BIT 7,(IX+0) | Jump to HandleHitActor if the sugar has been hit. | ||||||
| 27859 | JP NZ,HandleHitActor | |||||||
| HandleSugar_Move | 27862 | INC (IX+7) | Increase the frame counter in byte 7 of the actor by one. | |||||
| 27865 | LD (IX+3),68 | Set the actor colour to 68 (green). | ||||||
| 27869 | LD A,(IX+7) | Fetch the frame counter. | ||||||
| 27872 | AND %00011111 | Keep only bits 0-4. | ||||||
| 27874 | JR Z,HandleSugar_NewSpeeds | Jump to HandleSugar_NewSpeeds if the counter is a multiple of 32 to change speed. | ||||||
| 27876 | LD A,(IX+1) | Fetch the horizontal co-ordinate. | ||||||
| 27879 | ADD A,(IX+4) | Add the horizontal speed. | ||||||
| 27882 | LD (IX+1),A | Update the horizontal co-ordinate. | ||||||
| 27885 | CP 192 | Jump to HandleSugar_RightEdge if the sugar has reached the right edge. | ||||||
| 27887 | JR NC,HandleSugar_RightEdge | |||||||
| 27889 | CP 4 | Jump to HandleSugar_LeftEdge if the sugar has reached the left edge. | ||||||
| 27891 | JR C,HandleSugar_LeftEdge | |||||||
|
Make the offset for the wave from the frame counter. For each of the eight values of bits 0-2 of the counter it is 3 252 253 254 0 1 2 and 3.
|
||||||||
| HandleSugar_Wave | 27893 | LD A,(IX+7) | Fetch the frame counter. | |||||
| 27896 | AND %00000011 | Keep only bits 0-1. | ||||||
| 27898 | BIT 2,(IX+7) | Jump to HandleSugar_Vertical if bit 2 of the frame counter is set. | ||||||
| 27902 | JR NZ,HandleSugar_Vertical | |||||||
| 27904 | NEG | Negate A. | ||||||
| 27906 | XOR %00000011 | Flip bits 0-1. | ||||||
| HandleSugar_Vertical | 27908 | ADD A,(IX+5) | Add the vertical speed. | |||||
| 27911 | ADD A,(IX+2) | Add the vertical co-ordinate. | ||||||
| 27914 | CP 32 | Jump to HandleSugar_Top if the sugar has reached the top. | ||||||
| 27916 | JR C,HandleSugar_Top | |||||||
| 27918 | CP 160 | Jump to HandleSugar_Bottom if the sugar has reached the bottom. | ||||||
| 27920 | JR NC,HandleSugar_Bottom | |||||||
| 27922 | LD (IX+2),A | Update the vertical co-ordinate. | ||||||
| HandleSugar_Draw | 27925 | CALL DisplayEntity | Erase the sprite and draw it in its new position using DisplayEntity. | |||||
| 27928 | JP ColourSprite | Jump to ColourSprite to colour the sprite. | ||||||
|
The sugar has reached the right edge, so move it left.
|
||||||||
| HandleSugar_RightEdge | 27931 | LD (IX+4),254 | Set the horizontal speed to 254 (-2, moving left). | |||||
| 27935 | JR HandleSugar_Wave | Jump to HandleSugar_Wave. | ||||||
|
The sugar has reached the left edge, so move it right.
|
||||||||
| HandleSugar_LeftEdge | 27937 | LD (IX+4),2 | Write 2 to the horizontal speed. | |||||
| 27941 | JR HandleSugar_Wave | Jump to HandleSugar_Wave. | ||||||
|
The sugar has reached the top, so move it down.
|
||||||||
| HandleSugar_Top | 27943 | LD (IX+5),2 | Write 2 to the vertical speed. | |||||
| 27947 | JR HandleSugar_Draw | Jump to HandleSugar_Draw. | ||||||
|
The sugar has reached the bottom, so move it up.
|
||||||||
| HandleSugar_Bottom | 27949 | LD (IX+5),254 | Write 254 to the vertical speed. | |||||
| 27953 | JR HandleSugar_Draw | Jump to HandleSugar_Draw. | ||||||
|
Choose new speeds. A is the new vertical speed, so it is added to the vertical co-ordinate twice.
|
||||||||
| HandleSugar_NewSpeeds | 27955 | CALL SetRandomSpeeds | Set random horizontal and vertical speeds using SetRandomSpeeds. | |||||
| 27958 | JR HandleSugar_Vertical | Jump to HandleSugar_Vertical. | ||||||
| Prev: 27815 | Up: Map | Next: 27960 |