Skip to navigation

Keyboard: ProcessActionKeys (Part 1 of 2)

Name: ProcessActionKeys (Part 1 of 2) [Show more] Type: Subroutine Category: Keyboard Summary: Process an action key press from key logger entry 1 (absorb, transfer, create, hyperspace, U-turn)
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessGameplay calls ProcessActionKeys

Returns: C flag Status flag: * Clear if we have added or removed an object: * Player has absorbed (and therefore removed) an object * Player has created an object * Set if we have not added or removed any objects: * Player has hyperspaced * Player has done a U-turn * Player has transferred to a new tile * Player has tried to do something that results in an error sound and no action (such as trying to transfer to an empty tile or into an object that isn't a robot, for example)
.ProcessActionKeys LDA keyPress \ Set A to the value from the key logger for the key \ press we want to process, which we know contains a \ valid key press as we only call this routine when \ bit 7 of the key logger value is clear \ \ The possible values for key logger entry 1 are: \ \ * 0 for key press "R" (Create robot) \ * 2 for key press "T" (Create tree) \ * 3 for key press "B" (Create boulder) \ * 32 for key press "A" (Absorb) \ * 33 for key press "Q" (Transfer) \ * 34 for key press "H" (Hyperspace) \ * 35 for key press "U" (U-turn) \ \ So now we perform the correct action for the key press \ in A CMP #34 \ If A <> 34 then the "H" key (hyperspace) is not being BNE pkey2 \ pressed, so jump to pkey2 to move on to the next check \ If we get here then "H" (hyperspace) is being pressed JSR PerformHyperspace \ Hyperspace the player to a brand new tile LDA #0 \ Set titleObjectToDraw to the object type for a robot, STA titleObjectToDraw \ so if the hyperspace fails because the player doesn't \ have enough energy, then the game over screen will \ show a robot to indicate that the player was \ responsible for their own demise .pkey1 SEC \ Set the C flag to denote that no object has been added \ or removed by the routine RTS \ Return from the subroutine .pkey2 LDX viewingObject \ Set X to the object number of the viewer, which we set \ to the player object in MainGameLoop before getting \ here via the ProcessGameplay routine CMP #35 \ If A <> 35 then the "U" key (U-turn) is not being BNE pkey3 \ pressed, so jump to pkey3 to move on to the next check \ If we get here then "U" (U-turn) is being pressed \ If we get here with bit 6 of uTurnStatus set, then \ this is the first time we have reached this point \ since the key was pressed (as we are about to clear \ bit 6), so we can perform the requested U-turn \ \ If we get here with bit 6 of uTurnStatus clear, then \ this isn't the first time we've reached this point \ since the key was pressed, so in this case we don't \ do another U-turn, as we're already done one ASL uTurnStatus \ Clear bit 6 uTurnStatus to prevent the "U" key from \ performing a U-turn, so that the "U" key has to be \ released before a second U-turn can be performed BPL pkey1 \ If bit 7 of uTurnStatus is now clear, then that means \ that bit 6 was clear before the above shift, which \ means we are currently ignoring the "U" key to prevent \ doing a second U-turn, so jump to pkey1 to skip doing \ another U-turn and instead return from the subroutine \ with the C flag set \ If we get here then "U" is being pressed and bit 6 of \ uTurnStatus was set before being cleared above, so we \ now perform a U-turn LDA objectYawAngle,X \ Rotate the player's yaw angle through 180 degrees by EOR #%10000000 \ flipping bit 7, which turns the player around STA objectYawAngle,X LDA #40 \ Set A = 40 to pass to the PlayMusic routine after we \ jump to pkey4, so it plays the music for a U-turn BNE pkey4 \ Jump to pkey4 to play the U-turn music and return from \ the subroutine with the C flag set (this BNE is \ effectively a JMP as A is never zero) .pkey3 \ If we get here then the key press is either create, \ absorb or transfer LSR enemyCheckingRobot \ Clear bit 7 of enemyCheckingRobot to pass to the call \ to FollowGazeVector below, so it returns results for \ the tile visibility rather than the object itself JSR GetSightsVector \ Calculate the vector from the player's eyes to the \ sights, returning it in both angle format: \ \ vectorYawAngle(Hi Lo) \ \ vectorPitchAngle(Hi Lo) \ \ and as a cartesian vector: \ \ [ xVector(Lo Bot) ] \ [ yVector(Lo Bot) ] \ [ zVector(Lo Bot) ] \ \ This vector is the vector from the player's eyes to \ the sights, divided by 16 by the GetVectorForAngles \ routine that GetSightsVector uses \ \ The "divided by 16" part is important, as we want to \ divide the vector from the player to the sights into \ small steps, so we can move along the vector \ sequentially, checking on each step whether the \ vector is passing through a flat tile or platform JSR FollowGazeVector \ Follow the gaze vector from the player's eyes to the \ sights to determine whether the player can see a flat \ tile or platform (i.e. boulder or tower) or the \ target object \ \ If it does hit a tile or platform, it sets xCoordHi \ and zCoordHi to the tile coordinates of the tile, \ which we use below for creating or removing objects \ on the tile in the sights BCS pkey7 \ If the C flag is set then this means the player can't \ see a tile or platform through the sights, so jump to \ pkey7 to make an error sound and return from the \ subroutine as we can't see a suitable surface for the \ create, absorb or transfer action LDA keyPress \ If bit 5 of keypress is clear then A is not 32 or 33, AND #%00100000 \ so A must be 0, 2 or 3 (one of the create keys), so BEQ pkey8 \ jump to pkey8 to spawn a robot, tree or boulder \ If we get here then A must be 32 or 33, so the key \ press is either absorb or transfer JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile), setting the C flag if the tile \ contains an object BCC pkey7 \ The tile does not contain an object, so jump to pkey7 \ to make an error sound and return from the subroutine \ as we can't absorb or transfer to an empty tile AND #%00111111 \ Because the tile has an object on it, the tile data TAX \ contains the number of the top object on the tile in \ bits 0 to 5, so extract the object number into X LDA keyPress \ If bit 0 of keypress is clear then A must be 32, which LSR A \ is absorb, so jump to pkey5 to absorb the object on BCC pkey5 \ the tile anchored at (xTile, zTile) \ If we get here then A must be 33, so the key press is \ transfer and the player is trying to transfer to the \ tile anchored at (xTile, zTile), which contains \ object #X LDY objectTypes,X \ Set Y to the type of object #X BNE pkey7 \ If object #X is not a robot (i.e. not an object of \ type 0), jump to pkey7 to make an error sound and \ return from the subroutine as the player can only \ transfer into other robots JSR FocusOnKeyAction \ Tell the game to start focusing effort on the key \ action that has been initiated (i.e. the transfer) STX playerObject \ Set the player's object number to that of the robot \ on the tile anchored at (xTile, zTile), so this \ effectively performs the transfer across to the new \ robot \ We now take a short interlude to set the value of \ playerIsOnTower, as part of the game's anti-cracker \ code, and we pick up the robot transfer code in part 2