.LandOnLaunchpad ADD R3, R11, #xPlayer \ Fetch the six words at xPlayer as follows: LDMIA R3, {R0-R5} \ \ (R0, R1, R2) = the player's coordinates \ from (xPlayer, yPlayer, zPlayer) \ \ (R3, R4, R5) = the player's velocity \ from (xVelocity, yVelocity, zVelocity) CMP R0, #LAUNCHPAD_SIZE \ If either of xPlayer or zPlayer is >= CMPLO R2, #LAUNCHPAD_SIZE \ LAUNCHPAD_SIZE then we are not over the BHS LoseLife \ launchpad, as the launchpad is defined as \ this part of the map: \ \ 0 <= x <LAUNCHPAD_SIZE \ \ and: \ \ 0 <= z <LAUNCHPAD_SIZE \ \ So we just crashed into the ground rather \ than the launchpad, so jump to LoseLife to \ process the crash CMP R3, #0 \ Set R3 = |R3| RSBMI R3, R3, #0 \ = |xVelocity| CMP R4, #0 \ Set R4 = |R4| RSBMI R4, R4, #0 \ = |yVelocity| CMP R5, #0 \ Set R5 = |R5| RSBMI R5, R5, #0 \ = |zVelocity| ADD R3, R3, R4 \ If R3 + R4 + R5 >= LANDING_SPEED, then: ADD R3, R3, R5 \ CMP R3, #LANDING_SPEED \ |xVelocity| + |yVelocity| + |zVelocity| MOVHS PC, R14 \ \ is greater than the safe landing speed, so \ we can't be performing a safe landing, so \ return from the subroutine \ If we get here then we have landed, as the \ altitude checks were made before this \ routine was called, we know we are above \ the launchpad, and our speed is slow \ enough to land \ \ So now we start refuelling MOV R1, #LAUNCHPAD_Y \ Set R1 to the y-coordinate of the player's \ ship as it sits on the launchpad (which is \ set to the launchpad altitude plus the \ height of the ship's undercarriage) LDR R3, [R11, #fuelLevel] \ Bump up the fuel level by 1/160 of a full ADD R3, R3, #&20 \ tank CMP R3, #&1400 STRLO R3, [R11, #fuelLevel] MOV R3, #0 \ Zero the player's velocity MOV R4, #0 MOV R5, #0 STR R3, [R11, #xVelocity] STR R4, [R11, #yVelocity] STR R5, [R11, #zVelocity] STR R1, [R11, #yPlayer] \ Set the y-coordinate of the player to the \ y-coordinate of the launchpad, so the \ player's ship is resting correctly on the \ pad MOV PC, R14 \ Return from the subroutineName: LandOnLaunchpad [Show more] Type: Subroutine Category: Player Summary: Check to see if the player has landed on the launchpad Deep dive: Collisions and bulletsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveAndDrawPlayer (Part 3 of 5) calls LandOnLaunchpad
We call this routine from MoveAndDrawPlayer when the player's altitude matches that of the launchpad, so this performs additional checks to see if the player just landed.
Returns: R1 The y-coordinate of the player's ship
[X]
Configuration variable LANDING_SPEED = &00200000
The maximum safe landing speed
[X]
Configuration variable LAUNCHPAD_SIZE = TILE_SIZE * 8
Size of the launchpad (8 tile sizes)
[X]
Configuration variable LAUNCHPAD_Y = LAUNCHPAD_ALTITUDE - UNDERCARRIAGE_Y
The y-coordinate of the ship as it sits on the launchpad, and on top of its undercarriage
[X]
Subroutine LoseLife (category: Main loop)
Display a crash animation when we lose a life and end the game if this is our last life
[X]
Configuration variable fuelLevel = &128
The player's fuel level
[X]
Configuration variable xPlayer = &94
The x-coordinate of the player's ship
[X]
Configuration variable xVelocity = &A0
The player's velocity in the x-axis
[X]
Configuration variable yPlayer = &98
The y-coordinate of the player's ship
[X]
Configuration variable yVelocity = &A4
The player's velocity in the y-axis
[X]
Configuration variable zVelocity = &A8
The player's velocity in the z-axis