Prev: B5F7 Up: Map Next: B683
B5FF: Handle Bouncing Ball
Handles a ball that bounces around the room. Every time the ball hits the floor it bounces up again and sets off at a speed of 02 along either the X axis or the Y axis, towards the player if the player is the wulf and away from the player if the player is the human. In rooms with an odd number the height of the bounce is random.
The test for which way to go is a self-modifying one: this routine changes the conditional jumps at HandleBouncingBall_ConditionY and HandleBouncingBall_ConditionX into JR NC when the player is the wulf and JR C when the player is the human.
Input
IX Address of the ball object
HandleBouncingBall B5FF CALL SetPixelAdjustments_Ball Set the pixel adjustments of the ball.
B602 LD L,(IX+$09) Fetch the speed in X of the ball.
B605 LD H,(IX+$0A) Fetch the speed in Y of the ball.
B608 PUSH HL Stash the speeds on the stack.
B609 LD A,(IX+$0B) Fetch the speed in Z of the ball.
B60C LD ($5BC2),A Keep it, so that the bounce can be told from the ball rising at BallFallSpeed.
B60F CALL ApplyGravityAndMove Apply gravity to the ball and move it.
B612 POP HL Restore the speeds in X and Y from the stack.
B613 LD (IX+$09),L Put the speed in X back.
B616 LD (IX+$0A),H Put the speed in Y back.
Work out which way the ball should go from the form the player is in.
B619 LD A,($5C08) Fetch the graphic number of the player's legs from ObjectsTable.
B61C SUB $10 Take off the first graphic number of the legs.
B61E CP $20 Compare the result with 20, which is where the legs of the wulf start. The carry flag is set if the player is a human.
B620 LD A,$30 Get the opcode of JR NC.
B622 JR NC,HandleBouncingBall_SetCondition Jump to HandleBouncingBall_SetCondition if the player is the wulf.
B624 ADD A,$08 Turn the opcode into the one of JR C.
HandleBouncingBall_SetCondition B626 LD ($B65D),A Change the jump at HandleBouncingBall_ConditionY.
B629 LD ($B676),A Change the jump at HandleBouncingBall_ConditionX.
Work out how fast the ball bounces up.
B62C LD A,($5C10) Fetch the room that the player is in.
B62F AND %00000001 Test whether the number of the room is odd.
B631 LD A,$04 Set the speed to 04.
B633 JR Z,HandleBouncingBall_TestFloor Jump to HandleBouncingBall_TestFloor if it is even.
B635 LD B,A Stash the minimum speed in B.
B636 LD A,($5BA5) Fetch the second random seed from RandomSeed2.
B639 AND %00000011 Keep the lowest two bits.
B63B ADD A,B Add them to the minimum speed.
HandleBouncingBall_TestFloor B63C BIT 2,(IX+$0C) Jump to HandleBouncingBall_Draw if the ball has not hit the floor.
B640 JR Z,HandleBouncingBall_Draw
B642 LD (IX+$0B),A Make the ball bounce up.
B645 LD A,($5BC2) Fetch the old speed in Z of the ball from BallFallSpeed.
B648 AND A Test whether it was rising.
B649 JP P,HandleBouncingBall_Direction Jump to HandleBouncingBall_Direction if it was.
B64C CALL PlayBumpSound Play the sound of the ball bouncing.
Choose the axis that the ball goes along at random.
HandleBouncingBall_Direction B64F LD A,R Read the refresh register for a random number.
B651 AND %00000001 Keep the lowest bit.
B653 JR Z,HandleBouncingBall_DirectionX Jump to HandleBouncingBall_DirectionX if it is zero, to go along the X axis.
B655 LD A,($5C0A) Fetch the Y coordinate of the player.
B658 CP (IX+$02) Compare it with the Y coordinate of the ball.
B65B LD A,$02 Set the speed to 02.
HandleBouncingBall_ConditionY B65D JR NC,HandleBouncingBall_SetSpeedY Jump to HandleBouncingBall_SetSpeedY if the ball is to go in the positive direction. This is the instruction that is changed.
B65F NEG Make the speed negative.
HandleBouncingBall_SetSpeedY B661 LD (IX+$0A),A Set the speed in Y of the ball.
B664 LD (IX+$09),$00 Clear the speed in X of the ball.
HandleBouncingBall_Draw B668 CALL ToggleGraphic Toggle the graphic number of the ball between its two frames.
B66B JP SetDeadlyFlagsAndDraw Make the ball deadly and flag it to be drawn.
HandleBouncingBall_DirectionX B66E LD A,($5C09) Fetch the X coordinate of the player.
B671 CP (IX+$01) Compare it with the X coordinate of the ball.
B674 LD A,$02 Set the speed to 02.
HandleBouncingBall_ConditionX B676 JR NC,HandleBouncingBall_SetSpeedX Jump to HandleBouncingBall_SetSpeedX if the ball is to go in the positive direction. This is the instruction that is changed.
B678 NEG Make the speed negative.
HandleBouncingBall_SetSpeedX B67A LD (IX+$09),A Set the speed in X of the ball.
B67D LD (IX+$0A),$00 Clear the speed in Y of the ball.
B681 JR HandleBouncingBall_Draw Jump to HandleBouncingBall_Draw.
Prev: B5F7 Up: Map Next: B683