Skip to navigation

Landscape: SpawnPlayer

Name: SpawnPlayer [Show more] Type: Subroutine Category: Landscape Summary: Add the player object to the landscape, ideally placing it below all the enemies and in the bottom half of the landscape
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * FinishLandscape calls SpawnPlayer * PreviewLandscape calls SpawnPlayer
.SpawnPlayer LDA #0 \ Spawn the player's robot (an object of type 0), JSR SpawnObject \ returning the object number of the new object in X \ and currentObject STX playerObject \ Set playerObject to the object number of the newly \ spawned object LDA #10 \ Set the player's energy level to 10 STA playerEnergy LDA landscapeZero \ If the landscape number is not 0000, jump to sply1 BNE sply1 LDA #8 \ Set (xTile, zTile) = (8, 17) STA xTile \ LDA #17 \ So the player always starts on this tile in the first STA zTile \ landscape JSR PlaceObjectOnTile \ Place object #X on the tile anchored at (xTile, zTile) JMP SpawnTrees \ Jump to SpawnTrees to add trees to the landscape and \ move towards playing the game .sply1 \ If we get here then this is not landscape 0000 LDA minEnemyAltitude \ Set A to the altitude of the lowest enemy on the \ landscape CMP #6 \ If A >= 6 then set A = 6 BCC sply2 \ LDA #6 \ So A = min(6, minEnemyAltitude) .sply2 \ By this point A contains an altitude that is no higher \ than any enemies and is no greater than 6 \ \ We can use this as a cap on the player's starting \ altitude to ensure that the player starts below all \ the enemies, and in the bottom half of the landscape \ (which ranges from altitude 1 to 11) JSR PlaceObjectBelow \ Attempt to place the player object on a tile that is \ below the maximum altitude specified in A (though we \ may end up placing the object higher than this) BCS sply1 \ If the call to PlaceObjectBelow sets the C flag then \ the object has not been successfully placed, so loop \ back to sply1 to keep trying, working through the \ landscape's sequence of seed numbers until we do \ manage to place the player on a tile \ Otherwise we have placed the player object on a tile, \ so now we fall through into SpawnTrees to add trees to \ the landscape