.LoseLife MOV R0, #0 \ Set playingGame = 0 to flag that the game STR R0, [R11, #playingGame] \ is no longer being played and that this is \ the crash animation MOV R0, #30 \ Set crashLoopCount = 30 to act as a loop STR R0, [R11, #crashLoopCount] \ the crash animation below MOV R8, #81 \ Set R8 = 81 to use as the size of the \ explosion in AddExplosionToBuffer ADD R0, R11, #xPlayer \ Set (R0, R1, R2) to the coordinate in LDMIA R0, {R0-R2} \ xPlayer SUB R1, R1, #CRASH_CLOUD_Y \ Subtract CRASH_CLOUD_Y from the ship's \ y-coordinate so the explosion occurs just \ above the player's ship (5/16 tile sizes \ above the ship, to be precise) BL AddExplosionToBuffer \ Draw a large explosion in place of the \ player's ship .lose1 \ We now run a cut-down version of the main \ loop to display the crash animation (this \ is like the main loop but without the \ calls to drop rocks from the sky, draw the \ player's ship or update the fuel level) \ We now set up the rotation matrix for the \ rocks, using the main loop counter to \ generate rotation angles that change along \ with the main loop (so the rocks spin at a \ nice steady speed) LDR R0, [R11, #mainLoopCount] \ Set R0 = mainLoopCount << 24 MOV R0, R0, LSL #24 MOV R1, R0, LSL #1 \ Set R1 = mainLoopCount << 25 BL CalculateRotationMatrix \ Calculate the rotation matrix from the \ "angles" given in R0 and R1, which we can \ apply to any rocks we draw in the \ MoveAndDrawParticles routine (as rocks are \ only rotating 3D objects apart from the \ player, and the player calculates its own \ rotation matrix) BL MoveAndDrawParticles \ Move and draw all the particles, such as \ smoke clouds and bullets, into the \ graphics buffers BL DrawObjects \ Draw all the objects, such as trees and \ buildings, into the graphics buffers BL AddTerminatorsToBuffers \ Add terminators to the ends of the \ graphics buffers so we know when to stop \ drawing BL DrawLandscapeAndBuffers \ Draw the landscape and the contents of the \ graphics buffers BL PrintCurrentScore \ Print the number of remaining bullets at \ the left end of the score bar BL SwitchScreenBank \ Switch screen banks and clear the newly \ hidden screen bank to black LDR R0, [R11, #mainLoopCount] \ Increment the main loop counter ADD R0, R0, #1 STR R0, [R11, #mainLoopCount] LDR R0, [R11, #crashLoopCount] \ Decrement the loop counter for the crash SUBS R0, R0, #1 \ animation above STR R0, [R11, #crashLoopCount] BPL lose1 \ Loop back to keep running the crash \ animation until the loop counter runs down LDR R0, [R11, #remainingLives] \ Decrement the number of remaining lives SUBS R0, R0, #1 \ and set the flags accordingly STR R0, [R11, #remainingLives] \ ADD R13, R13, #4 \ Increment the stack pointer by one word so \ we discard the return address from the top \ of the stack, so we rejoin the main loop \ without keeping the return address of the \ subroutine we were in before we jumped \ here (i.e. MoveAndDrawPlayer or \ LandOnLaunchpad) BNE PlacePlayerOnLaunchpad \ If we still have one or more lives left, \ jump to PlacePlayerOnLaunchpad to play the \ next lifeName: LoseLife [Show more] Type: Subroutine Category: Main loop Summary: Display a crash animation when we lose a life and end the game if this is our last life Deep dive: The main game loop Collisions and bulletsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * LandOnLaunchpad calls LoseLife * MoveAndDrawPlayer (Part 3 of 5) calls LoseLife
[X]
Subroutine AddExplosionToBuffer (category: Particles)
Create a big explosion of particles and add it to the particle data buffer
[X]
Subroutine AddTerminatorsToBuffers (category: Graphics buffers)
Add terminators to the ends of the graphics buffers so we know when to stop drawing
[X]
Configuration variable CRASH_CLOUD_Y = TILE_SIZE * 5 / 16
The vertical distance above the player's ship where we add the explosion cloud when they crash (5/16-th of a tile)
[X]
Subroutine CalculateRotationMatrix (category: Maths (Geometry))
Calculate the rotation matrix
[X]
Subroutine DrawLandscapeAndBuffers (Part 1 of 4) (category: Landscape)
Draw the landscape and the contents of the graphics buffers, from the back of the screen to the front
[X]
Subroutine DrawObjects (Part 1 of 3) (category: 3D objects)
Draw all the objects in the visible portion of the object map, starting by working our way through the map looking for objects
[X]
Subroutine MoveAndDrawParticles (Part 1 of 4) (category: Particles)
Process particle movement and draw the particles into the graphics buffers, starting with the movement of particles
[X]
Subroutine PlacePlayerOnLaunchpad (category: Player)
The main entry point for the game
[X]
Subroutine PrintCurrentScore (category: Score bar)
Print the current score at the left end of the score bar
[X]
Subroutine SwitchScreenBank (category: Drawing the screen)
Switch screen banks and clear the newly hidden screen bank to black
[X]
Configuration variable crashLoopCount = &11C
The loop counter for the crash animation
[X]
Label lose1 is local to this routine
[X]
Configuration variable mainLoopCount = &118
The main loop counter
[X]
Configuration variable playingGame = &130
A flag to determine whether the game is being player, or whether this is the crash animation
[X]
Configuration variable remainingLives = &134
The number of remaining lives, which is displayed towards the right end of the score bar, just before the high score
[X]
Configuration variable xPlayer = &94
The x-coordinate of the player's ship