.GetPlayerDrain LDY #0 \ Set Y = 0 to use as the default state of the scanner \ (fill scanner with black) STY T \ Set T = 0 to store in playerTileIsHidden after the \ loop below, so the default value is that the player \ is not exposed to an enemy scan (though we may change \ this) LDX #7 \ We now loop through all eight enemies, so set an enemy \ counter in X .pdra1 LDA objectFlags,X \ If bit 7 is set for object #Y then this object number BMI pdra3 \ is not allocated to an object, so jump to pdra3 to \ move on to the next enemy object LDA objectTypes,X \ Set A to the object type for the enemy in object #X CMP #1 \ If object #X is a sentry (an object of type 1) then BEQ pdra2 \ jump to pdra2 CMP #5 \ If object #X is not the Sentinel (an object of type BNE pdra3 \ 5), then jump to pdra3 to move on to the next enemy \ object .pdra2 \ If we get here then object #X is the Sentinel or a \ sentry LDA enemyTarget,X \ If the enemy's target is not the player, jump to pdra3 CMP playerObject \ to move on to the next enemy object BNE pdra3 LDA enemyDrainTimer,X \ If the drain timer for the enemy is zero, jump to BEQ pdra3 \ pdra3 to move on to the next enemy object \ If we get here then the enemy is targeting the player \ and has a non-zero drain timer, so the player is at \ least partially exposed to an enemy who can drain them LDY #4 \ Set Y = 4 to use as the state of the scanner (fill the \ scanner with static in colour 3) LDA enemyVisibility,X \ Set T to the visibility of the enemy's target (the STA T \ player) to store in playerTileIsHidden after the loop \ \ This will either have bit 7 set (target's tile is \ visible) or bit 6 set (target's tile is not visible \ but target object is) BMI pdra4 \ If bit 7 of enemyVisibility is set then the enemy can \ see the player's tile, so jump to pdra4 to record this \ fact \ \ If bit 7 of enemyVisibility is clear then the enemy \ can see the player object but it can't see the \ player's tile, so we keep looping in case there is \ another target whose tile the enemy can see, as this \ will take precedence over the partially exposed player .pdra3 DEX \ Decrement the enemy counter in X BPL pdra1 \ Loop back until we have checked all eight enemies .pdra4 STY scannerUpdate \ Set scannerUpdate to the value of Y, which will be: \ \ * Zero if the player is not exposed to the enemy (so \ the scanner will not be updated) \ \ * Non-zero (i.e. 4) if the player is exposed to the \ enemy (so the scanner will then be updated) LDA T \ Set playerTileIsHidden to the value of T, which will STA playerTileIsHidden \ be: \ \ * Zero if the player is not exposed to the enemy \ \ * 128 (i.e. bit 7 set) if the player's tile is \ exposed to the enemy \ \ * 64 (i.e. bit 6 set) if the player is exposed to \ the enemy but the enemy can't see the player's \ tile \ \ This value is used in the UpdateScannerNow routine \ to determine whether we show the scanner with a full \ display of static (not 64) or only half (64) LDA soundEffect \ Set A to soundEffect, which determines how the current \ sound is processed by the ProcessSound routine CPY soundEffect \ Set the flags on the comparison of the current setting \ of soundEffect and the value of Y STY soundEffect \ Set soundEffect to Y, which will be: \ \ * Zero if the player is not exposed to the enemy (so \ no sound processing is required) \ \ * Non-zero (i.e. 4) if the player is exposed to the \ enemy (so the scanner sound is processed in the \ ProcessSound routine) BEQ pdra5 \ If the value of soundEffect has not changed, jump to \ pdra5 to return from the subroutine LDY #&12 \ Set the first parameter of sound block #2 (channel) to STY soundData+16 \ &12, so we make the scanner sound on channel 2 and \ with a flush control of 1 to make the sound instantly CMP #3 \ We set A to soundEffect above, so if soundEffect = 3, BEQ pdra5 \ which denotes that we are currently applying the music \ sound effect, jump to pdra5 to return from the \ subroutine to let the music sound finish first LDX #6 \ Otherwise we are not currently applying the music JSR FlushBuffer \ sound effect, so call the FlushBuffer routine with \ X = 6 to flush the sound channel 2 buffer .pdra5 RTS \ Return from the subroutineName: GetPlayerDrain [Show more] Type: Subroutine Category: Gameplay Summary: Calculate whether the player is being scanned by an enemy and whether the enemy can see the player's tileContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessGameplay calls GetPlayerDrain
[X]
Subroutine FlushBuffer (category: Keyboard)
Flush the specified buffer
[X]
Variable enemyDrainTimer in workspace Main variable workspace
A timer for each enemy that counts down every 0.06
[X]
Variable enemyTarget in workspace Main variable workspace
The object number of the enemy's target (one byte per
[X]
Variable enemyVisibility in workspace Main variable workspace
Visibility of the enemy's target (one byte per enemy)
[X]
Variable objectFlags in workspace Stack variables
Object flags for up to 64 objects
[X]
Variable objectTypes (category: 3D objects)
The object types table for up to 64 objects
[X]
Label pdra1 is local to this routine
[X]
Label pdra2 is local to this routine
[X]
Label pdra3 is local to this routine
[X]
Label pdra4 is local to this routine
[X]
Label pdra5 is local to this routine
[X]
Variable playerObject in workspace Zero page
The number of the player object
[X]
Variable scannerUpdate in workspace Main variable workspace
A flag to control whether the scanner gets updated
[X]
Variable soundData (category: Sound)
OSWORD blocks for making the various game sounds
[X]
Variable soundEffect in workspace Main variable workspace
Determines how the current sound is processed by the ProcessSound routine