Prev: CFB2 Up: Map Next: D071
CFD2: Run Helper Source
The handler of the object type 78, which makes a helper (the object type 5A, run by RunHelper) when it has been hit by enough of the projectiles of the player. Nothing happens while there is a helper in the game already. Otherwise, a count at 14 of its record goes up by one for each frame that a projectile is touching it, and the helper is made when the count gets to 20.
The helper is made by copying the record of this object into a free object slot, and changing it. It starts in front of the object, rising. The type and room of the helper are also written to the last entry of the object store, ObjectStore_Helper, so that it is remembered when the player leaves the room.
Input
IX Object record
Count frames while a projectile is touching the object.
RunHelperSource CFD2 CALL SetSpriteOffset_Minus16_Minus8 Call SetSpriteOffset_Minus16_Minus8 to set the offsets of the sprite.
CFD5 CALL ApplyGravityAndMove_Move Call ApplyGravityAndMove_Move to move the object, without gravity.
CFD8 LD A,($A70E) Fetch the helper flag.
CFDB AND A Return if there is a helper already.
CFDC RET NZ
CFDD CALL TestProjectileHit Call TestProjectileHit to find out if a projectile touches the object.
CFE0 RET NZ Return if none does.
CFE1 INC (IX+$14) Add one to the count of frames in which a projectile has touched the object.
CFE4 LD A,(IX+$14) Return if the count is less than 20.
CFE7 CP $20
CFE9 RET C
CFEA LD (IX+$14),$00 Set the count back to zero.
Return if a helper already exists.
CFEE CALL PointAtObjects Call PointAtObjects to point IY at the first ordinary object.
CFF1 LD A,$5A Set the type to look for to that of the helper.
RunHelperSource_Test CFF3 CP (IY+$00) Return if the object is a helper.
CFF6 RET Z
CFF7 ADD IY,DE Move on to the next object, and jump to RunHelperSource_Test until all have been tested.
CFF9 DJNZ RunHelperSource_Test
CFFB CALL PointAtObjects Call PointAtObjects to point IY at the first ordinary object again.
CFFE XOR A Set the type to look for to zero, which is a free object.
RunHelperSource_Free CFFF CP (IY+$00) Jump to RunHelperSource_Make if the object is free.
D002 JR Z,RunHelperSource_Make
D004 ADD IY,DE Move on to the next object, and jump to RunHelperSource_Free until all have been tested.
D006 DJNZ RunHelperSource_Free
D008 RET Return, as there is no room for a helper.
Copy this object into a free slot and make the helper.
RunHelperSource_Make D009 PUSH IX Point HL at this object (using the stack).
D00B POP HL
D00C PUSH IY Point DE at the free object (using the stack).
D00E POP DE
D00F LD BC,$0020 Set the number of bytes to copy, which is the size of an object.
D012 LDIR Copy this object into the free object.
D014 LD (IY+$00),$5A Set the type of the new object to 5A.
D018 LD (IY+$03),$8D Set the z position of the helper.
D01C LD A,$08 Set A to 08, for the half sizes along x and y.
D01E LD (IY+$04),A Set the half size along x.
D021 LD (IY+$05),A Set the half size along y.
D024 LD (IY+$06),$0C Set the size along z.
D028 LD (IY+$07),$14 Set the flags, which are for an object that can be pushed.
D02C LD (IY+$0B),$01 Set the speed along z to 01, which makes the helper rise.
D030 LD DE,$D542 Take the entry of the object store for the helper, ObjectStore_Helper.
D033 LD (IY+$10),E Write the low byte of the address as the pointer to the store.
D036 LD (IY+$11),D Write the high byte.
D039 LD A,(IX+$01) Put the x position of the helper at that of this object.
D03C LD (IY+$01),A
D03F LD A,(IX+$02) Put the y position of the helper 08 further along than that of this object.
D042 ADD A,$08
D044 LD (IY+$02),A
D047 LD A,$01 Set the helper flag.
D049 LD ($A70E),A
D04C PUSH IX Save the object and make IX the helper.
D04E PUSH IY
D050 POP IX
D052 CALL SetSpriteOffset_Minus16_Minus8 Call SetSpriteOffset_Minus16_Minus8 to set the offsets of the sprite.
D055 CALL CalculatePixelCoordinates Call CalculatePixelCoordinates to work out where it is on the screen.
D058 CALL ApplyGravityAndMove Call ApplyGravityAndMove to apply gravity to it and move it.
D05B CALL SetWipeAndDrawFlags Call SetWipeAndDrawFlags to flag it as moved.
D05E POP IX Get the object back.
D060 LD IY,$D542 Take the entry of the object store for the helper.
D064 LD (IY+$00),$5A Set the type of the entry.
D068 LD A,(IX+$08) Set the room of the entry to the room of the object.
D06B LD (IY+$08),A
D06E JP SetWipeAndDrawFlags Jump to SetWipeAndDrawFlags to flag the object as moved.
Prev: CFB2 Up: Map Next: D071