Prev: 28500 Up: Map Next: 28712
28557: Handler: Car Type 2 (Driving Left)
Used by the routine at Handler_Cars.
Handles a car driving left across the screen. When it reaches the left boundary it turns around and drives right at ground level until reaching the right edge, then reinitialises.
Handler_CarType2 28557 LD IX,56008 IX=Sprite02_3Wide_X_Position.
28561 LD HL,29195 HL=CarSpeed (car speed).
If the room is being initialised, set up the car.
28564 LD A,(24507) Jump to Handler_CarType2_Initialise if *RespawnFlag is set.
28567 OR A
28568 JR NZ,Handler_CarType2_Initialise
If the car crash timer is active, handle the crash animation.
28570 LD A,(29192) Jump to Handler_Car_Type1_0 if *CarCrashTimer is active.
28573 OR A
28574 JP NZ,Handler_Car_Type1_0
Check which road the car is on.
28577 LD A,(IX+1) A=*IX+1 (car Y position).
28580 CP 144 Jump to Handler_CarType2_DriveRight if on the upper road.
28582 JR Z,Handler_CarType2_DriveRight
Car is on the lower road (Y=160) — driving left.
28584 LD A,(IX+0) A=*IX+0 (car X position).
28587 SUB (HL) A-=*HL (subtract speed).
28588 CP 104 Jump to Handler_CarType2_TurnAround if at the left boundary (turn around).
28590 JR C,Handler_CarType2_TurnAround
This entry point is used by the routine at Handler_CarType3.
Update positions and set driving left frames.
Handler_CarType2_UpdateLeft 28592 LD (IX+0),A Write A to *IX+0 (front X).
28595 ADD A,16 A+=16.
28597 LD (IX+4),A Write A to *IX+4 (rear X).
28600 LD (IX+1),160 Write 160 to *IX+1 (front Y: lower road).
28604 LD (IX+5),160 Write 160 to *IX+5 (rear Y: lower road).
Sprite ID Sprite
30 udg44763-56x4
28608 LD (IX+3),30 Write 30 to *IX+3 (front frame: driving left).
Sprite ID Sprite
31 udg44795-56x4
28612 LD (IX+7),31 Write 31 to *IX+7 (rear frame: driving left).
28616 JP Handler_Car_Type1_2 Jump to Handler_Car_Type1_2.
Car is on the upper road (Y=144) — driving right.
Handler_CarType2_DriveRight 28619 LD A,(IX+0) A=*IX+0 (car X position).
28622 ADD A,(HL) A+=*HL (add speed).
28623 CP 222 Jump to Handler_CarType2_Initialise if at the right edge (reinitialise).
28625 JR NC,Handler_CarType2_Initialise
This entry point is used by the routine at Handler_CarType3.
Update positions and set driving right frames.
Handler_CarType2_UpdateRight 28627 LD (IX+0),A Write A to *IX+0 (front X).
28630 ADD A,16 A+=16.
28632 LD (IX+4),A Write A to *IX+4 (rear X).
28635 LD (IX+1),144 Write 144 to *IX+1 (front Y: upper road).
28639 LD (IX+5),144 Write 144 to *IX+5 (rear Y: upper road).
Sprite ID Sprite
28 udg44699-56x4
28643 LD (IX+3),28 Write 28 to *IX+3 (front frame: driving right).
Sprite ID Sprite
29 udg44731-56x4
28647 LD (IX+7),29 Write 29 to *IX+7 (rear frame: driving right).
28651 JP Handler_Car_Type1_1 Jump to Handler_Car_Type1_1.
Car reached the left boundary — turn around. Pick a new random speed and colour, then start driving right from the left boundary.
Handler_CarType2_TurnAround 28654 PUSH HL Stash HL on the stack.
28655 CALL GenerateRandomNumber Call GenerateRandomNumber.
28658 POP HL Restore HL from the stack.
28659 AND %00000011 Keep only bits 0-1 (random speed 0-3).
28661 INC A Increment the random number by one (speed 1-4).
28662 LD (HL),A Write the new speed to *HL.
Pick a new colour, rejecting BLUE.
PickCarColour 28663 PUSH HL Stash HL on the stack.
28664 CALL GenerateRandomNumber Call GenerateRandomNumber.
28667 POP HL Restore HL from the stack.
28668 AND %00000011 Keep only bits 0-1 (random colour from BLACK,BLUE,RED,MAGENTA).
28670 CP 1 Jump to PickCarColour if the colour is BLUE (pick again).
28672 JR Z,PickCarColour
28674 LD (IX+2),A Write A to *IX+2 (front colour).
28677 LD (IX+6),A Write A to *IX+6 (rear colour).
28680 LD A,104 A=104 (left boundary X position).
28682 JR Handler_CarType2_UpdateRight Jump to Handler_CarType2_UpdateRight.
Initialise car type 2 — start from the right edge driving left with a random speed and colour.
Handler_CarType2_Initialise 28684 PUSH HL Stash HL on the stack.
28685 CALL GenerateRandomNumber Call GenerateRandomNumber.
28688 POP HL Restore HL from the stack.
28689 AND %00000011 Keep only bits 0-1 (random speed 0-3).
28691 INC A Increment the random speed by one (speed 1-4).
28692 LD (HL),A Write the new speed to *HL.
Pick a colour, using the range 4-7 (bright colours).
28693 PUSH HL Stash HL on the stack.
28694 CALL GenerateRandomNumber Call GenerateRandomNumber.
28697 POP HL Restore HL from the stack.
28698 AND %00000011 Keep only bits 0-1.
28700 ADD A,4 A+=4 (bright colour range).
28702 LD (IX+2),A Write A to *IX+2 (front colour).
28705 LD (IX+6),A Write A to *IX+6 (rear colour).
28708 LD A,222 A=222 (right edge X position).
28710 JR Handler_CarType2_UpdateLeft Jump to Handler_CarType2_UpdateLeft.
Prev: 28500 Up: Map Next: 28712