Skip to navigation

Lander on the Acorn Archimedes

Player: MoveAndDrawPlayer (Part 5 of 5)

Name: MoveAndDrawPlayer (Part 5 of 5) [Show more] Type: Subroutine Category: Player Summary: Spawn a bullet particle if the fire button is being pressed Deep dive: Collisions and bullets
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.ship7 TST R10, #%00000001 \ If bit 0 of the fuel burn rate is clear BEQ ship8 \ then the fire button is not being pressed, \ so jump to ship8 to skip the bullet-firing \ process and return from the subroutine LDR R8, [R11, #currentScore] \ Decrement the current score by one, as we SUB R8, R8, #1 \ are about to fire a bullet STR R8, [R11, #currentScore] ADD R14, R11, #xPlayer \ Set R0 to R5 as follows: LDMIA R14, {R0-R5} \ \ R0 = xPlayer \ R1 = yPlayer \ R2 = zPlayer \ \ R3 = xVelocity \ R4 = yVelocity \ R5 = zVelocity \ \ So (R0, R1, R2) is the player's coordinate \ and (R3, R4, R5) is the player's velocity LDR R6, [R11, #xNoseV] \ Set (R6, R7, R8) to the nose vector from LDR R7, [R11, #yNoseV] \ the rotation matrix, which is the vector LDR R8, [R11, #zNoseV] \ that points out through the ship's nose, \ just like the ship's gun \ \ Let's refer to this gun vector as follows: \ \ R6 = xGun \ R7 = yGun \ R8 = zGun ADD R3, R3, R6, ASR #8 \ Set (R3, R4, R5) as follows: ADD R4, R4, R7, ASR #8 \ ADD R5, R5, R8, ASR #8 \ [ xVelocity + xGun / 256 ] \ [ yVelocity + yGun / 256 ] \ [ zVelocity + zGun / 256 ] \ \ So this sets (R3, R4, R5) to a vector in \ the direction of the player's velocity \ (so the bullet particles move along with \ the ship from which they are fired) and \ then in the direction that the gun is \ pointing (so they leave the barrel in the \ correct direction) SUB R0, R0, R3 \ Set (R0, R1, R2) as follows: SUB R1, R1, R4 \ SUB R2, R2, R5 \ [ xPlayer - R3 + (xGun / 128) ] ADD R0, R0, R6, ASR #7 \ [ yPlayer - R4 + (yGun / 128) ] ADD R1, R1, R7, ASR #7 \ [ zPlayer - R5 + (zGun / 128) ] ADD R2, R2, R8, ASR #7 \ \ So this sets (R0, R1, R2) to the position \ of the player's ship, but a little way in \ the direction of the gun (so the bullet \ fires out of the end of the gun), and we \ also subtract the velocity in (R3, R4, R5) \ because the first thing that happens when \ we process the particle in \ MoveAndDrawParticles is to add the \ velocity, so this cancels that out to \ ensure the particle starts out at the end \ of the gun MOV R6, #20 \ Set the bullet particle's lifespan \ counter to 20 iterations of the main loop MOV R7, #&01BC0000 \ Set bits 18, 19, 20, 21, 23 and 24 of the \ particle flags, so that's: \ \ * Bit 18 set = splash on impact with sea \ * Bit 19 set = bounce on ground \ * Bit 20 set = apply gravity to particle \ * Bit 21 set = can destroy objects \ * Bit 23 set = splash size is big \ * Bit 24 set = explode on hitting ground ORR R7, R7, #&FF \ Set the particle colour to white in bits 0 \ to 7 of the particle flag BL AddBulletParticleToBuffer \ Add a bullet particle to the particle data \ buffer .ship8 LDMFD R13!, {PC} \ Return from the subroutine