.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 landscapeName: 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 managementContext: See this subroutine in context in the source code References: This subroutine is called as follows: * GetNextLandscape calls SpawnPlayer * PreviewLandscape calls SpawnPlayer
[X]
Subroutine GetObjectNumber (category: 3D objects)
Fetch an object number that we can use for a new object of the specified type, and add the type to the objectTypes table
[X]
Subroutine SpawnObjectBelow (category: 3D objects)
Attempt to spawn an object on a tile that is below the maximum altitude specified in A
[X]
Subroutine SpawnObjectOnTile (category: 3D objects)
Spawn an object on a tile, putting it on top of any existing boulders or towers
[X]
Subroutine SpawnTrees (category: Landscape)
Add trees to the landscape, ideally placing them below all the enemies in the landscape
[X]
Variable landscapeZero in workspace Main variable workspace
A flag that is set depending on whether we are playing landscape 0000
[X]
Variable minEnemyAltitude in workspace Main variable workspace
The altitude of the lowest enemy on the landscape
[X]
Variable playerEnergy in workspace Main variable workspace
The player's energy level (in the range 0 to 63)
[X]
Variable playerObject in workspace Zero page
The number of the player object
[X]
Label sply1 is local to this routine
[X]
Label sply2 is local to this routine