Prev: 691A Up: Map Next: 6996
6930: Handle Cheese
The handler for the cheese (IDs 12 and 13), which bounces up and down the screen like a ball. Byte 05 of the actor is the vertical speed; it is increased by one every eight frames (up to a maximum of 08), and half of it is added to the vertical co-ordinate. When the cheese reaches the top of the play area its vertical speed is reversed, and when it reaches the bottom it is thrown back up with a random speed, and a random horizontal speed. The horizontal movement is done by MoveBouncingActor_Horizontal.
While the cheese is still entering from the right of the screen (a horizontal co-ordinate of C4 or more) it only moves horizontally.
Input
IX Actor
HandleCheese 6930 CALL StoreEntity Record the position of the sprite using StoreEntity.
6933 LD HL,$5F1B Point HL at ActorsInPlay.
6936 INC (HL) Increase the number of actors in play by one.
6937 LD A,(IX+$01) Fetch the horizontal co-ordinate.
693A CP $C4 Jump to HandleCheese_Horizontal if the cheese is still entering from the right.
693C JR NC,HandleCheese_Horizontal
693E CALL TestCharlieCollision Test whether the cheese has hit Charlie using TestCharlieCollision.
6941 DEC E Has Charlie been hit (is E now zero)?
6942 JP Z,LoseHat Jump to LoseHat if Charlie has been hit.
6945 CALL TestFlourCollision Test whether a flour shot has hit the cheese using TestFlourCollision.
6948 BIT 7,(IX+$00) Jump to HandleHitActor if the cheese has been hit.
694C JP NZ,HandleHitActor
Every eight frames, increase the vertical speed (up to a maximum of 08).
694F LD A,(IX+$07) Fetch the frame counter (byte 07 of the actor).
6952 AND %00000111 Keep only bits 0-2.
6954 JR NZ,HandleCheese_Vertical Jump to HandleCheese_Vertical if the counter is not a multiple of 08.
6956 LD A,(IX+$05) Fetch the vertical speed.
6959 CP $08 Jump to HandleCheese_Vertical if the vertical speed is already at the maximum.
695B JR Z,HandleCheese_Vertical
695D INC (IX+$05) Increase the vertical speed by one.
HandleCheese_Vertical 6960 LD A,(IX+$05) Fetch the vertical speed.
6963 LD (IX+$03),$46 Set the actor colour to 46 (yellow).
6967 SRA A Halve the vertical speed.
6969 ADD A,(IX+$02) Add the vertical co-ordinate.
696C CP $20 Jump to HandleCheese_Top if the cheese has reached the top.
696E JR C,HandleCheese_Top
6970 CP $A0 Jump to HandleCheese_Bottom if the cheese has reached the bottom.
6972 JR NC,HandleCheese_Bottom
6974 LD (IX+$02),A Update the vertical co-ordinate.
HandleCheese_Horizontal 6977 JP MoveBouncingActor_Horizontal Move the actor horizontally using MoveBouncingActor_Horizontal.
The cheese has reached the top, so reverse the vertical speed.
HandleCheese_Top 697A LD (IX+$02),$20 Put the cheese at the top of the play area (20).
697E LD A,(IX+$05) Fetch the vertical speed.
6981 NEG Reverse the direction by negating the vertical speed.
HandleCheese_SetSpeed 6983 LD (IX+$05),A Update the vertical speed.
6986 JR HandleCheese_Horizontal Jump to HandleCheese_Horizontal.
The cheese has reached the bottom, so throw it back up.
HandleCheese_Bottom 6988 LD (IX+$02),$A0 Put the cheese on the floor (A0).
698C CALL SetRandomSpeeds Set random horizontal and vertical speeds using SetRandomSpeeds.
698F LD A,R Fetch a random number.
6991 AND %00000111 Keep only bits 0-2.
6993 CPL Invert A, so it is in the range F8 to FF (-8 to -1).
6994 JR HandleCheese_SetSpeed Jump to HandleCheese_SetSpeed.
Prev: 691A Up: Map Next: 6996