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 Deep dive: Adding enemies and trees to the landscape Object management
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetNextLandscape calls SpawnPlayer * PreviewLandscape calls SpawnPlayer
.SpawnPlayer LDA #0 \ Fetch a new object number that we can use for the JSR GetObjectNumber \ player's robot (an object of type 0), returning the \ number of the new object in X and currentObject STX playerObject \ Set playerObject to the object number that we just \ fetched 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 SpawnObjectOnTile \ Spawn object #X on the tile anchored at (xTile, zTile) \ to add the player to the landscape 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 SpawnObjectBelow \ Attempt to spawn 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 SpawnObjectBelow sets the C flag then \ the object has not been successfully spawned, 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 successfully spawned the player \ object on a tile, so now we fall through into \ SpawnTrees to add trees to the landscape