Prev: 46583 Up: Map Next: 46723
46591: 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 2 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 46591 CALL SetPixelAdjustments_Ball Set the pixel adjustments of the ball.
46594 LD L,(IX+9) Fetch the speed in X of the ball.
46597 LD H,(IX+10) Fetch the speed in Y of the ball.
46600 PUSH HL Stash the speeds on the stack.
46601 LD A,(IX+11) Fetch the speed in Z of the ball.
46604 LD (23490),A Keep it, so that the bounce can be told from the ball rising at BallFallSpeed.
46607 CALL ApplyGravityAndMove Apply gravity to the ball and move it.
46610 POP HL Restore the speeds in X and Y from the stack.
46611 LD (IX+9),L Put the speed in X back.
46614 LD (IX+10),H Put the speed in Y back.
Work out which way the ball should go from the form the player is in.
46617 LD A,(23560) Fetch the graphic number of the player's legs from ObjectsTable.
46620 SUB 16 Take off the first graphic number of the legs.
46622 CP 32 Compare the result with 32, which is where the legs of the wulf start. The carry flag is set if the player is a human.
46624 LD A,48 Get the opcode of JR NC.
46626 JR NC,HandleBouncingBall_SetCondition Jump to HandleBouncingBall_SetCondition if the player is the wulf.
46628 ADD A,8 Turn the opcode into the one of JR C.
HandleBouncingBall_SetCondition 46630 LD (46685),A Change the jump at HandleBouncingBall_ConditionY.
46633 LD (46710),A Change the jump at HandleBouncingBall_ConditionX.
Work out how fast the ball bounces up.
46636 LD A,(23568) Fetch the room that the player is in.
46639 AND %00000001 Test whether the number of the room is odd.
46641 LD A,4 Set the speed to 4.
46643 JR Z,HandleBouncingBall_TestFloor Jump to HandleBouncingBall_TestFloor if it is even.
46645 LD B,A Stash the minimum speed in B.
46646 LD A,(23461) Fetch the second random seed from RandomSeed2.
46649 AND %00000011 Keep the lowest two bits.
46651 ADD A,B Add them to the minimum speed.
HandleBouncingBall_TestFloor 46652 BIT 2,(IX+12) Jump to HandleBouncingBall_Draw if the ball has not hit the floor.
46656 JR Z,HandleBouncingBall_Draw
46658 LD (IX+11),A Make the ball bounce up.
46661 LD A,(23490) Fetch the old speed in Z of the ball from BallFallSpeed.
46664 AND A Test whether it was rising.
46665 JP P,HandleBouncingBall_Direction Jump to HandleBouncingBall_Direction if it was.
46668 CALL PlayBumpSound Play the sound of the ball bouncing.
Choose the axis that the ball goes along at random.
HandleBouncingBall_Direction 46671 LD A,R Read the refresh register for a random number.
46673 AND %00000001 Keep the lowest bit.
46675 JR Z,HandleBouncingBall_DirectionX Jump to HandleBouncingBall_DirectionX if it is zero, to go along the X axis.
46677 LD A,(23562) Fetch the Y coordinate of the player.
46680 CP (IX+2) Compare it with the Y coordinate of the ball.
46683 LD A,2 Set the speed to 2.
HandleBouncingBall_ConditionY 46685 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.
46687 NEG Make the speed negative.
HandleBouncingBall_SetSpeedY 46689 LD (IX+10),A Set the speed in Y of the ball.
46692 LD (IX+9),0 Clear the speed in X of the ball.
HandleBouncingBall_Draw 46696 CALL ToggleGraphic Toggle the graphic number of the ball between its two frames.
46699 JP SetDeadlyFlagsAndDraw Make the ball deadly and flag it to be drawn.
HandleBouncingBall_DirectionX 46702 LD A,(23561) Fetch the X coordinate of the player.
46705 CP (IX+1) Compare it with the X coordinate of the ball.
46708 LD A,2 Set the speed to 2.
HandleBouncingBall_ConditionX 46710 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.
46712 NEG Make the speed negative.
HandleBouncingBall_SetSpeedX 46714 LD (IX+9),A Set the speed in X of the ball.
46717 LD (IX+10),0 Clear the speed in Y of the ball.
46721 JR HandleBouncingBall_Draw Jump to HandleBouncingBall_Draw.
Prev: 46583 Up: Map Next: 46723