Skip to navigation

Keyboard: ProcessActionKeys (Part 2 of 2)

Name: ProcessActionKeys (Part 2 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: No direct references to this subroutine in this source file
\ If we get here then the player has just transferred \ into a robot LDA #25 \ Set A = 25 to pass to the PlayMusic routine so it \ plays the music for when the player transfers into a \ new robot .pkey4 JSR PlayMusic \ Call PlayMusic to play the music specified in A (so \ that's either the music for transferring into a new \ robot or the music for a U-turn) LDA #%10000000 \ Set bit 7 of playerHasMovedTile to indicate that the STA playerHasMovedTile \ player has moved to a new tile SEC \ Set the C flag to denote that no object has been added \ or removed by the routine RTS \ Return from the subroutine .pkey5 \ If we get here then we are absorbing an object of type \ X from the tile anchored at (xTile, zTile) LDA objectFlags \ The Sentinel is always object #0, so this checks BMI pkey7 \ whether bit 7 of the Sentinel's object is set, which \ indicates that the Sentinel's object number is not \ allocated \ \ This means that the Sentinel no longer exists and has \ been absorbed by the player, at which point the player \ is no longer allowed to absorb other objects, so jump \ to pkey7 to make an error sound and return from the \ subroutine LDA objectTypes,X \ If the player is trying to absorb a meanie (an object CMP #4 \ of type 4), jump to pkey11 to implement this BEQ pkey11 CMP #6 \ If the player is trying to absorb the Sentinel's tower BEQ pkey7 \ (an object of type 6), jump to pkey7 to make an error \ sound and return from the subroutine .pkey6 JSR DeleteObject \ Delete object #X and remove it from the landscape STX currentObject \ Set currentObject to the number of the deleted object CLC \ Call UpdatePlayerEnergy with the C flag clear to add JSR UpdatePlayerEnergy \ the amount of energy in the now-deleted object #X to \ the player's energy CLC \ Clear the C flag to denote that an object has been \ removed by the routine RTS \ Return from the subroutine .pkey7 \ If we get here then the player has tried to: \ \ * Absorb or transfer to an empty tile \ \ * Create, absorb or transfer to a tile or platform \ that they see directly \ \ * Transfer to an object that is not a robot \ \ * Absorb an object after the Sentinel has been \ absorbed \ \ * Absorb the Sentinel's tower \ \ * Create an object when there are no unallocated \ object numbers \ \ * Create an object that takes their energy level \ below zero \ \ * Create an object that can't be added to the tile \ (if the tile is occupied by an object that is not \ a boulder or tower, for example) \ \ In each case we make an error sound and return from \ the subroutine LDA #170 \ Set the third parameter of sound data block #3 (the STA soundData+28 \ pitch) to 170 LDA #5 \ Make sound #5 (ping) JSR MakeSound LDA #144 \ Set the third parameter of sound data block #3 (the STA soundData+28 \ pitch) to 144 SEC \ Set the C flag to denote that no object has been added \ or removed by the routine RTS \ Return from the subroutine .pkey8 \ If we get here then the player is trying to create an \ object of the type given in keyPress JSR SpawnObject+3 \ Spawn an object of type keyPress, returning the object \ number of the new object in X and currentObject BCS pkey7 \ If there are no free object numbers then the call to \ SpawnObject will return with the C flag set and the \ object will not have been created, so jump to pkey7 to \ make an error sound and return from the subroutine SEC \ Call UpdatePlayerEnergy with the C flag set to JSR UpdatePlayerEnergy \ subtract the amount of energy in object #X from the \ player's energy, so this subtracts the energy required \ to create the object from the player BCS pkey7 \ If the creation of object #X reduces the player's \ energy below zero, then the call to UpdatePlayerEnergy \ will return with the C flag set, so jump to pkey7 to \ make an error sound and return from the subroutine LDX currentObject \ Set X to the object number of the object we just \ created LDA xCoordHi \ Set (xTile, zTile) to the tile coordinates of the tile STA xTile \ in the sights, which we set in part 1 with the call to LDA zCoordHi \ FollowGazeVector STA zTile JSR PlaceObjectOnTile \ Place object #X on the tile anchored at (xTile, zTile) BCC pkey9 \ If the object was successfully placed on the tile then \ the call to PlaceObjectOnTile will return with the C \ flag clear, so jump to pkey9 to keep going CLC \ Otherwise we failed to add the object to the tile, so JSR UpdatePlayerEnergy \ call UpdatePlayerEnergy with the C flag clear to \ refund the energy that we used to create the object \ back to the player JMP pkey7 \ We failed to place the object on the tile, so jump to \ pkey7 to make an error sound and return from the \ subroutine .pkey9 \ If we get here then a new object has been successfully \ created and added to a tile, as object #X LDA objectTypes,X \ If the type of object that was added is not a robot BNE pkey10 \ (type 0), jump to pkey10 to return from the subroutine \ with the C flag clear \ We just created a robot, so we now rotate it so that \ it faces the player LDY playerObject \ Set A to the yaw angle of the player object LDA objectYawAngle,Y EOR #%10000000 \ Flip bit 7 to rotate the angle through 180 degrees \ \ The degree system in the Sentinel looks like this: \ \ 0 \ -32 | +32 Overhead view of object \ \ | / \ \ | / 0 = looking straight ahead \ \|/ +64 = looking sharp right \ -64 -----+----- +64 -64 = looking sharp left \ /|\ \ / | \ \ / | \ \ -96 | +96 \ 128 \ \ Flipping bit 7 changes 0 into 128, +32 into -96, +64 \ into -64 and so on, so it's the same as rotating by \ 180 degrees STA objectYawAngle,X \ Set the yaw angle for the newly created robot to the \ player's yaw angle rotated through 180 degrees, so the \ new robot faces the player .pkey10 CLC \ Clear the C flag to denote that an object has been \ added by the routine RTS \ Return from the subroutine .pkey11 \ If we get here then the player is trying to absorb a \ meanie in object #X \ We now loop through all the enemy objects, of which \ there are up to eight, looking for the object whose \ enemyMeanieTree entry is X (so we are looking for the \ enemy that turned a tree into this meanie) LDY #7 \ The enemies have object numbers 0 (for the Sentinel) \ or 1 to 7 (for any sentries in the landscape), so set \ a counter in Y to work through the enemy object \ numbers .pkey12 LDA objectFlags,Y \ If bit 7 is set for object #Y then this object number BMI pkey14 \ is not allocated to an object, so jump to pkey14 to \ move on to the next enemy object LDA objectTypes,Y \ Set A to the object type for object #Y CMP #1 \ If object #Y is a sentry (an object of type 1) then BEQ pkey13 \ jump to pkey13 CMP #5 \ If object #Y is not the Sentinel (an object of type BNE pkey14 \ 5), then jump to pkey14 to move on to the next enemy \ object .pkey13 \ If we get here then object #Y is the Sentinel or a \ sentry TXA \ Set A to the object number of the meanie that the \ player is trying to absorb CMP enemyMeanieTree,Y \ If enemyMeanieTree for object #Y does not match the BNE pkey14 \ object number of the meanie we are absorbing, then \ this means object #Y did not create this meanie, so \ jump to pkey14 to move on to the next enemy object \ If we get here then we have found the enemy that \ turned a tree into the meanie that is being absorbed LDA #%10000000 \ Set bit 7 of enemyMeanieTree so the enemy that turned STA enemyMeanieTree,Y \ a tree into the meanie is no longer flagged as such \ (as the meanie has been absorbed) BNE pkey6 \ Jump to pkey6 to delete the meanie in object #X, add \ the meanie's energy to the player's energy, and return \ from the subroutine with the C flag clear (this BNE is \ effectively a JMP as A is never zero) .pkey14 DEY \ Decrement the counter in Y to move on to the next \ enemy object number BPL pkey12 \ Loop back until we have processed all eight possible \ enemy objects BMI pkey6 \ Jump to pkey6 to delete the meanie in object #X, add \ the meanie's energy to the player's energy, and return \ from the subroutine with the C flag clear