Prev: 43807 Up: Map Next: 44021
43873: Handle Attacking Tool
The handler for the boxing glove, hammer and hook (objects 81 to 83). In the game over scene they take it in turns to beat the robot, once the alarm has finished flashing (see HandleAlarm).
A tool swings towards the robot for six frames, makes a noise, and swings back for six frames. Bit 7 of the state holds the direction and bit 0 is set while it is attacking. The game restarts after 16 attacks, or if a number key is pressed.
Input
IX The address of the object
Start an attack, or keep one going.
HandleAttackingTool 43873 LD HL,23361 Point HL at GameOverSceneStage.
43876 LD A,(HL) Jump to HandleAttackingTool_ColourCells if GameOverSceneStage is zero.
43877 AND A
43878 JR Z,HandleAttackingTool_ColourCells
43880 LD A,231 Read from the keyboard;
Port Number Bit
0 1 2 3 4
231 1 / 0 2 / 9 3 / 8 4 / 7 5 / 6
43882 CALL ReadKeyboardPort
43885 JP NZ,RestartGame Jump to RestartGame if a key is pressed.
43888 BIT 0,(IX+17) Jump to HandleAttackingTool_Swing if this tool is already attacking.
43892 JR NZ,HandleAttackingTool_Swing
43894 BIT 7,(HL) Jump to HandleAttackingTool_ColourCells if another tool is attacking.
43896 JR NZ,HandleAttackingTool_ColourCells
43898 LD A,(23301) Fetch RandomSeed2.
43901 CPL Invert it.
43902 AND %00000011 Keep bits 0 and 1.
43904 JR NZ,HandleAttackingTool_ColourCells Jump to HandleAttackingTool_ColourCells unless both bits were set.
43906 PUSH HL Call PlayBumpSound, preserving HL.
43907 CALL PlayBumpSound
43910 POP HL
43911 SET 0,(IX+17) Set bit 0 of the state.
43915 SET 7,(HL) Set bit 7 of GameOverSceneStage.
43917 LD (IX+15),6 Write 6 to the frame counter.
The boxing glove and the hook move along the x axis by 8; the hammer moves along the y axis by 4.
HandleAttackingTool_Swing 43921 LD A,(IX+0) Fetch the sprite number.
43924 AND %00000001 Keep bit 0.
43926 JR Z,HandleAttackingTool_MoveAlongY Jump to HandleAttackingTool_MoveAlongY if the tool is the hammer.
43928 LD A,(IX+26) Compare bit 7 of the pixel x with bit 7 of the direction.
43931 XOR (IX+17)
43934 AND %10000000 Keep bit 7.
43936 LD A,8 Set the step to 8.
43938 JR Z,HandleAttackingTool_MoveAlongX Jump to HandleAttackingTool_MoveAlongX if the step already points the right way.
43940 NEG Make the step negative.
HandleAttackingTool_MoveAlongX 43942 ADD A,(IX+26) Add the step to the pixel x position.
43945 LD (IX+26),A
HandleAttackingTool_CountFrame 43948 DEC (IX+15) Jump to HandleAttackingTool_Redraw if this swing has not finished.
43951 JR NZ,HandleAttackingTool_Redraw
43953 LD (IX+15),6 Write 6 to the frame counter.
43957 LD A,(IX+17) Fetch the state of the tool.
43960 XOR %10000000 Flip bit 7.
43962 LD (IX+17),A Store the state.
43965 AND %10000000 Keep bit 7.
43967 JR Z,HandleAttackingTool_AttackFinished Jump to HandleAttackingTool_AttackFinished if the tool has finished swinging back.
43969 CALL PlayRandomNoise Call PlayRandomNoise.
43972 JR HandleAttackingTool_Redraw Jump to HandleAttackingTool_Redraw.
The swing back has finished.
HandleAttackingTool_AttackFinished 43974 RES 0,(IX+17) Reset bit 0 of the state.
43978 RES 7,(HL) Reset bit 7 of GameOverSceneStage.
43980 INC (HL) Increment GameOverSceneStage.
43981 LD A,(HL) Fetch GameOverSceneStage.
43982 AND %01111111 Keep bits 0 to 6.
43984 CP 16 Jump to HandleAttackingTool_Redraw unless 16 attacks have been made.
43986 JR NZ,HandleAttackingTool_Redraw
43988 JP RestartGame Jump to RestartGame.
HandleAttackingTool_Redraw 43991 CALL SetWipeAndDrawFlags Call SetWipeAndDrawFlags.
HandleAttackingTool_ColourCells 43994 JP ColourCells Jump to ColourCells.
Move the hammer along the y axis.
HandleAttackingTool_MoveAlongY 43997 LD A,(IX+27) Fetch the pixel y position.
44000 ADD A,32 Add 32.
44002 XOR (IX+17) Compare bit 7 with bit 7 of the direction.
44005 AND %10000000 Keep bit 7.
44007 LD A,4 Set the step to 4.
44009 JR Z,HandleAttackingTool_AddStepToY Jump to HandleAttackingTool_AddStepToY if the step already points the right way.
44011 NEG Make the step negative.
HandleAttackingTool_AddStepToY 44013 ADD A,(IX+27) Add the step to the pixel y position.
44016 LD (IX+27),A
44019 JR HandleAttackingTool_CountFrame Jump to HandleAttackingTool_CountFrame.
Prev: 43807 Up: Map Next: 44021