Prev: AE81 Up: Map Next: AF3F
AEB9: Handle Plant
Handler for the object types 1C to 2B the plants (mushrooms, pods, flytraps, weeds and bellflowers) that stand in some of the rooms. Each plant has two frames, and bit 0 of its type picks the frame.
A plant is set up the first time that it is handled after its room has been drawn (see Handle_Plant_Set_Up). After that it makes Sabreman tumble if he touches it, by setting bit 7 of his redraw flags (see Start_Tumbling).
Input
IX Object record
Handle_Plant AEB9 BIT 0,(IX+$0F) Jump to Handle_Plant_Set_Up if the plant has just been created (bit 0 of the redraw flags is set).
AEBD JR NZ,Handle_Plant_Set_Up
AEBF CALL StoreEntity Save the state of the plant (see StoreEntity).
Remove the plant if Sabreman is not in the same room.
AEC2 LD A,($8F1C) Fetch the room x of Sabreman.
AEC5 CP (IX+$02) Jump to Handle_Plant_Remove if the plant is not in the same room x.
AEC8 JR NZ,Handle_Plant_Remove
AECA LD A,($8F1E) Fetch the room y of Sabreman.
AECD CP (IX+$04) Jump to Handle_Plant_Remove if the plant is not in the same room y.
AED0 JR NZ,Handle_Plant_Remove
See if Sabreman is touching the plant.
AED2 LD A,($8F1D) Fetch the y position of Sabreman.
AED5 SUB (IX+$03) Subtract the y position of the plant.
AED8 CP $14 Jump to Handle_Plant_Animate if Sabreman is 14 or more pixels below the plant, or above it.
AEDA JR NC,Handle_Plant_Animate
AEDC LD A,($8F1B) Fetch the x position of Sabreman.
AEDF SUB (IX+$01) Subtract the x position of the plant.
AEE2 SUB $04 Subtract 04 to allow for the difference between the widths of the sprites.
AEE4 JP P,Handle_Plant_Test_Width Jump to Handle_Plant_Test_Width if the difference is positive.
AEE7 NEG Make the difference positive.
Handle_Plant_Test_Width AEE9 CP $14 Jump to Handle_Plant_Animate if Sabreman is 14 or more pixels away from the plant sideways.
AEEB JR NC,Handle_Plant_Animate
AEED LD A,($8F29) Fetch the redraw flags of Sabreman.
AEF0 OR %10000000 Set bit 7, which makes him tumble.
AEF2 LD ($8F29),A Store the redraw flags of Sabreman.
Choose the frame of the plant from bit 3 of a counter.
Handle_Plant_Animate AEF5 INC (IX+$06) Add one to the animation counter of the plant.
AEF8 LD A,(IX+$06) Fetch the animation counter of the plant.
AEFB RRA Shift bit 3 of the counter into bit 0 (rotate right three times).
AEFC RRA
AEFD RRA
AEFE AND %00000001 Keep only the bit.
AF00 LD B,A Keep the frame number in B.
AF01 LD A,(IX+$00) Fetch the type of the plant.
AF04 AND %11111110 Clear bit 0 of the type of the plant.
AF06 ADD A,B Add the frame number to make the new type.
AF07 LD (IX+$00),A Store the new type.
AF0A JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Plant_Remove AF0D LD (IX+$00),$00 Remove the plant by setting its type to zero.
AF11 RET Return.
Set up a new plant. Its type depends on its x position and on the room, and it takes its room from Sabreman.
Handle_Plant_Set_Up AF12 LD A,($8F1C) Fetch the room x of Sabreman.
AF15 LD (IX+$02),A Store it as the room x of the plant.
AF18 LD A,($8F1E) Fetch the room y of Sabreman.
AF1B LD (IX+$04),A Store it as the room y of the plant.
AF1E LD (IX+$05),$45 Set the attribute to 45 (bright cyan).
AF22 LD A,(IX+$01) Fetch the x position of the plant.
AF25 RRA Divide it by four.
AF26 RRA
AF27 ADD A,(IX+$02) Add the room x.
AF2A AND %00001110 Keep only bits 1 to 3, so that the type is even.
AF2C ADD A,$1C Add 1C the first type of a plant.
AF2E LD (IX+$00),A Store it as the type of the plant.
AF31 LD (IX+$06),A Store it as the animation counter of the plant.
AF34 RRA Divide the type by two.
AF35 AND %00000011 Keep only two bits.
AF37 ADD A,$42 Add 42 to make a bright attribute.
AF39 LD (IX+$05),A Store it as the attribute of the plant.
AF3C JP Update_Object_Sprite Jump to Update_Object_Sprite.
Prev: AE81 Up: Map Next: AF3F