Prev: FC1A Up: Map Next: FCB6
FC39: Handler: Vehicle
Used by the routine at RunHandlers.
Output
B Vehicle Y sprite co-ordinates (if active)
C Vehicle X sprite co-ordinates (if active)
Are vehicles permitted to be spawned on this level?
Handler_Vehicle FC39 LD A,($D401) Return if vehicle spawning is set to be off (*VehicleCounter is equal to FE).
FC3C CP $FE
FC3E RET Z
Just return if a a vehicle is already being displayed.
FC3F CP $FF Jump to Handler_Vehicle_Movement if a vehicle is already active (*VehicleCounter is equal to FF).
FC41 JR Z,Handler_Vehicle_Movement
Else the counter is a counter, so count it down.
FC43 DEC A Decrease *VehicleCounter by one.
FC44 LD ($D401),A
FC47 RET NZ Return if *VehicleCounter is still in progress.
Else the countdown is complete so set the counter/ state that a vehicle is spawned and spawn a random vehicle!
FC48 LD A,$FF Write FF to *VehicleCounter.
FC4A LD ($D401),A
Spawn a new vehicle:
There are four vehicle types.
FC4D CALL RandomNumber Get a random number between 0-3.
FC50 AND %00000011
FC52 LD ($D402),A Write A to *VehicleType.
Randomly bring the vehicle in from either the left or right hand side of the play area.
FC55 CALL RandomNumber Get a random number which is either zero or one.
FC58 AND %00000001
FC5A JR NZ,Handler_SpawnVehicleRight Jump to Handler_SpawnVehicleRight if the random number is one.
Vehicle moves from left-to-right.
FC5C LD A,$14 Write 14 to *VehicleYPosition.
FC5E LD ($D404),A
FC61 LD A,$FA Write FA to *VehicleXPosition.
FC63 LD ($D403),A
FC66 JR Handler_Vehicle_Movement Jump to Handler_Vehicle_Movement.
Bit 7 signifies that this vehicle moves from right-to-left.
Handler_SpawnVehicleRight FC68 LD A,$94 Write 94 (14 + bit 7 set) to *VehicleYPosition.
FC6A LD ($D404),A
FC6D LD A,$20 Write 20 to *VehicleXPosition.
FC6F LD ($D403),A
Handler_Vehicle_Movement FC72 LD A,($D404) A=*VehicleYPosition.
FC75 CP $80 Jump to Handler_MoveVehicle_RightToLeft if A is higher than 80 (if bit 7 is set).
FC77 JR NC,Handler_MoveVehicle_RightToLeft
FC79 LD B,A B=vehicle Y position.
Handles moving the vehicle from the left-to-right hand side of the play area.
FC7A LD A,($D403) A=*VehicleXPosition.
FC7D INC A Increment A by one.
Handler_Vehicle_SetXPos FC7E LD ($D403),A Write A to *VehicleXPosition.
Check if the vehicle is off-screen.
FC81 CP $20 Jump to Handler_Vehicle_SetCountdown if A is equal to 20.
FC83 JR Z,Handler_Vehicle_SetCountdown
FC85 LD C,A C=vehicle X position.
Has the vehicle been destroyed?
FC86 LD A,($D402) A=*VehicleType.
FC89 CP $03 Return if the vehicle has been destroyed (*VehicleType is equal to 03).
FC8B RET Z
FC8C ADD A,A A=3B+(A*02).
Vehicle Type Vehicle Sprite ID Sprite
00 Tank 3B sprite-59-left
01 Car 3D sprite-61-left
02 Police car 3F sprite-63-left
FC8D ADD A,$3B
FC8F CALL PrintSprite Call PrintSprite.
FC92 XOR A Write 00 to *Flag_Orientation.
FC93 LD ($D247),A
FC96 RET Return.
Handles moving the vehicle from the right-to-left hand side of the play area.
Handler_MoveVehicle_RightToLeft FC97 AND %01111111 Strip off the right-to-left flag.
FC99 LD B,A B=vehicle Y position.
FC9A LD A,$01 Write 01 to *Flag_Orientation.
FC9C LD ($D247),A
FC9F LD A,($D403) A=*VehicleXPosition.
FCA2 DEC A Decrease A by one.
Check if the vehicle is off-screen.
FCA3 CP $FA Jump to Handler_Vehicle_SetXPos if A is not equal to FA.
FCA5 JR NZ,Handler_Vehicle_SetXPos
Initialise a new countdown.
Handler_Vehicle_SetCountdown FCA7 CALL RandomNumber Get a random number between 8-23.
FCAA AND %00001111
FCAC ADD A,$08
FCAE LD ($D401),A Write the random number to *VehicleCounter.
FCB1 XOR A Write 00 to *Flag_Orientation.
FCB2 LD ($D247),A
FCB5 RET Return.
Prev: FC1A Up: Map Next: FCB6