Prev: 26280 Up: Map Next: 26524
26337: Percy Carrying Worm
Used by the routine at Handler_Worms.
After scanning all entries, check if Percy is carrying a worm and handle the worm-in-beak sprite positioning.
Input
IX Pointer to Percy's state data (and worm sprite at +32)
Position_Worm_In_Beak 26337 LD A,(24490) Return if *CarryingWormFlag (worm carrying flag) is zero.
26340 OR A
26341 RET Z
26342 LD A,(IX+1) Jump to Update_Worm_In_Beak if Percy's Y position is less than 143.
26345 CP 143
26347 JR C,Update_Worm_In_Beak
26349 LD A,(24492) Jump to HandleRedBird_SetAnimationSeed if *WormDropFlag is set (a worm is being dropped to a chick).
26352 OR A
26353 JP NZ,DropWorm
Update_Worm_In_Beak 26356 LD A,(IX+1) Jump to Set_Worm_Sprite_X if Percy's Y position is not less than 141.
26359 CP 141
26361 JR NC,Set_Worm_Sprite_X
26363 OR %11111111 Set *WormDropFlag to 255 (enable worm drop).
26365 LD (24492),A
Set_Worm_Sprite_X 26368 LD A,(24485) Calculate the worm-in-beak X position: if *PercyFacingDirection (facing direction) is zero (facing right), add 12 to Percy's X, otherwise add 251 (offset left).
26371 OR A
26372 JR NZ,Position_Worm_In_Beak_0
26374 ADD A,12
26376 JR Position_Worm_In_Beak_1
Position_Worm_In_Beak_0 26378 LD A,251 A=251.
Position_Worm_In_Beak_1 26380 ADD A,(IX+0) Add the offset to Percy's X position.
26383 LD (IX+32),A Write the result to *IX+32 (worm sprite X position).
26386 LD A,(IX+1) Set the worm sprite Y position to Percy's Y plus 4.
26389 ADD A,4
26391 LD (IX+33),A
26394 LD C,13 Set the worm sprite frame: start with 13 rotate *ChickAnimationStates and if carry is not set, increment to 14 for the alternate wiggle frame.
26396 LD A,(24500)
26399 RRCA
26400 LD (24500),A
26403 JR C,Set_Worm_Sprite_Frame
26405 INC C
Set_Worm_Sprite_Frame 26406 LD (IX+35),C Write the worm sprite frame index to *IX+35.
26409 LD A,(24493) Jump to Adjust_Worm_Y_Up if *LandedOnPlatformFlag (worm Y adjustment flag) is non-zero.
26412 OR A
26413 JR NZ,Adjust_Worm_Y_Up
26415 LD A,(IX+1) Jump to Check_Nest_Delivery if Percy's Y position is not less than 144.
26418 CP 144
26420 JR C,Check_Nest_Delivery
Adjust_Worm_Y_Up 26422 LD A,(IX+33) Subtract 4 from the worm Y position to adjust it upward.
26425 SUB 4
26427 LD (IX+33),A
Check if Percy is at the nest to deliver the worm to the baby chicks (only on level 6).
Check_Nest_Delivery 26430 LD A,(24517) Return if *CurrentRoom (current level) is not equal to 6.
26433 CP 6
26435 RET NZ
26436 LD A,(IX+1) Return if Percy's Y position is less than 17.
26439 CP 17
26441 RET C
26442 CP 33 Return if Percy's Y position is 33 or more.
26444 RET NC
26445 LD A,(IX+0) Return if Percy's X position is 107 or more.
26448 CP 107
26450 RET NC
26451 LD A,(24485) Return if *PercyFacingDirection (facing direction) is zero (Percy must be facing left).
26454 OR A
26455 RET Z
Scan the room object data for a collected worm marker to convert into a nest delivery.
26456 LD BC,352 Set the search counter to 352 in BC.
26459 LD HL,56990 Point HL at Room_Object_Data.
Search_Nest_Slot_Loop 26462 LD A,30 Jump to Deliver_Worm_To_Nest if *HL equals 30 (found a collected worm marker to convert).
26464 CP (HL)
26465 JR Z,Deliver_Worm_To_Nest
26467 INC HL Otherwise advance and loop back to Search_Nest_Slot_Loop, decrementing BC until zero.
26468 DEC BC
26469 LD A,C
26470 OR B
26471 JR NZ,Search_Nest_Slot_Loop
26473 RET Return (no available slot found).
Deliver_Worm_To_Nest 26474 LD (HL),0 Write 0 then 31 to convert the collected marker into a delivered/disabled entry.
26476 INC HL
26477 LD (HL),31
26479 XOR A Deactivate the worm-in-beak sprite by writing 0 to *IX+35.
26480 LD (IX+35),A
26483 LD A,200 Call AddToScore to add 200 to the score.
26485 CALL AddToScore
Play a delivery sound effect.
26488 LD E,50 Set the sound duration in E to 50.
26490 LD A,1 Set the initial speaker state to 1.
Delivery_Sound_Outer 26492 LD B,E Copy duration to B.
Delivery_Sound_Inner 26493 OUT (254),A Send to the speaker port.
26495 DJNZ Delivery_Sound_Inner Loop the inner delay for B iterations.
26497 EX AF,AF' Toggle the speaker bit pattern using XOR 24 mixed with duration bits for a warbling effect.
26498 LD A,E
26499 AND %00011000
26501 LD D,A
26502 EX AF,AF'
26503 XOR %00011000
26505 OR D
26506 INC E Advance the frequency and loop back to Delivery_Sound_Outer until E wraps to zero.
26507 INC E
26508 JR NZ,Delivery_Sound_Outer
26510 CALL Handle_Level_Complete Call Handle_Level_Complete.
This entry point is used by the routines at Lose_Life and DropWorm.
Reset the worm-carrying state.
Reset_Worm_State 26513 XOR A Write 0 to clear;
26514 LD (24490),A
26517 LD (24492),A
26520 LD (IX+35),A
26523 RET Return.
Prev: 26280 Up: Map Next: 26524