Prev: 28039 Up: Map Next: 28177
28041: Handle Level Introduction
The handler for the actors in the introduction to a level; the ingredient (ID 6) and Charlie (ID 7). While they are handled the ID is changed to the sprite which is in byte 4 of the actor. Byte 5 of the actor is zero until it has been drawn for the first time. The actors move left two pixels each pass, and change to their other frame every four passes.
Charlie waits (and is not drawn) until the ingredient has gone past the point at which CharlieRunningFlag is set by StartCharlieRunning. When an actor goes off the left side of the screen it is removed; and if it was Charlie then the level is started. A tone is played by LevelStartJingle every eight frames for Charlie.
Input
IX Actor
HandleLevelIntroduction 28041 LD A,(IX+0) Fetch the actor ID.
28044 PUSH AF Stash the actor ID on the stack.
28045 CP 7 Jump to HandleLevelIntroduction_Draw if this is the ingredient.
28047 JR NZ,HandleLevelIntroduction_Draw
28049 LD A,(24361) Fetch the flag which says whether Charlie is running.
28052 AND A Has Charlie started to run yet?
28053 JR Z,HandleLevelIntroduction_Finish Jump to HandleLevelIntroduction_Finish if he has not.
HandleLevelIntroduction_Draw 28055 LD A,(IX+5) Fetch the flag which says whether the actor has been drawn.
28058 AND A Has the actor been drawn?
28059 JR NZ,HandleLevelIntroduction_Animate Jump to HandleLevelIntroduction_Animate if it has.
28061 INC (IX+5) Flag that the actor has been drawn.
28064 LD A,(IX+4) Fetch the sprite ID (byte 4 of the actor).
28067 LD (IX+0),A Update the actor ID.
28070 CALL DrawEntity Draw the sprite using DrawEntity.
28073 POP AF Restore the actor ID from the stack.
28074 LD (IX+0),A Update the actor ID.
28077 RET Return.
Charlie changes to his second frame.
HandleLevelIntroduction_SecondFrame 28078 LD A,2 Set the sprite ID for Charlie's second frame, 2.
28080 JR HandleLevelIntroduction_SetFrame Jump to HandleLevelIntroduction_SetFrame.
Charlie changes to his first frame.
HandleLevelIntroduction_FirstFrame 28082 LD A,1 Set the sprite ID for Charlie's first frame, 1.
28084 JR HandleLevelIntroduction_SetFrame Jump to HandleLevelIntroduction_SetFrame.
The actor has been drawn already.
HandleLevelIntroduction_Animate 28086 LD A,(IX+4) Fetch the sprite ID (byte 4 of the actor).
28089 LD (IX+0),A Update the actor ID.
28092 CALL StoreEntity Record the position of the sprite using StoreEntity.
28095 LD A,(24349) Fetch the frame counter.
28098 AND %00000011 Keep only bits 0-1.
28100 JR NZ,HandleLevelIntroduction_Move Jump to HandleLevelIntroduction_Move if the frame counter is not a multiple of 4.
28102 LD A,(IX+4) Fetch the sprite ID (byte 4 of the actor).
28105 CP 1 Jump to HandleLevelIntroduction_SecondFrame if the sprite is Charlie's first frame.
28107 JR Z,HandleLevelIntroduction_SecondFrame
28109 CP 2 Jump to HandleLevelIntroduction_FirstFrame if the sprite is Charlie's second frame.
28111 JR Z,HandleLevelIntroduction_FirstFrame
28113 XOR %00000001 Flip bit 0, to change to the other frame of the ingredient.
HandleLevelIntroduction_SetFrame 28115 LD (IX+4),A Update the sprite ID (byte 4 of the actor).
28118 LD (IX+0),A Update the actor ID.
HandleLevelIntroduction_Move 28121 LD A,(IX+1) Fetch the horizontal co-ordinate.
28124 SUB 2 Subtract 2 to move the actor to the left.
28126 LD (IX+1),A Update the horizontal co-ordinate.
28129 CP 144 Compare with 144 (the point at which Charlie starts to run).
28131 CALL C,StartCharlieRunning Call StartCharlieRunning if the actor is to the left of 144.
28134 CP 248 Jump to HandleLevelIntroduction_Remove if the actor has gone off the left of the screen.
28136 JR NC,HandleLevelIntroduction_Remove
28138 CALL DisplayEntity Erase the sprite and draw it in its new position using DisplayEntity.
28141 CALL ColourSprite Colour the sprite using ColourSprite.
Put the actor ID back, and play the tone if this is Charlie.
HandleLevelIntroduction_Finish 28144 POP AF Restore the actor ID from the stack.
28145 LD (IX+0),A Update the actor ID.
28148 LD A,(23672) Fetch the first byte of FRAMES.
28151 AND %00000111 Keep only bits 0-2.
28153 RET NZ Return if the frame counter is not a multiple of 8.
28154 LD A,(IX+3) Fetch the actor colour.
28157 CP 71 Compare with 71 (white, the colour of Charlie).
28159 RET NZ Return if this is not Charlie.
28160 JP LevelStartJingle Jump to LevelStartJingle to play the tone.
The actor has gone off the left of the screen.
HandleLevelIntroduction_Remove 28163 CALL RemoveEntity Erase the sprite using RemoveEntity.
28166 LD (IX+0),0 Write 0 to the actor ID.
28170 POP AF Restore the original actor ID from the stack.
28171 CP 7 Jump to StartLevel to start the level if this was Charlie.
28173 JP Z,StartLevel
28176 RET Return.
Prev: 28039 Up: Map Next: 28177