Prev: 26241 Up: Map Next: 26421
26267: Handle Peel
The handler for the orange peel (IDs 20 and 21). It wanders about in a wavy path. Byte 6 of the actor holds the direction (bit 0 is set for right, bit 1 is set for down) and which byte of each pair in the table at WanderSpeeds is used for which direction (bit 2). Byte 7 is a counter, which chooses the speeds to use from the table, and changes the sprite frame.
While the peel is entering from the right of the screen (a horizontal co-ordinate of 196 or more) it can't hit Charlie or be hit.
Input
IX Actor
HandlePeel 26267 CALL StoreEntity Record the position of the sprite using StoreEntity.
26270 LD HL,24347 Increase ActorsInPlay by one.
26273 INC (HL)
26274 LD A,(IX+1) Fetch the horizontal co-ordinate.
26277 CP 196 Jump to HandlePeel_Horizontal if the peel is still entering from the right.
26279 JR NC,HandlePeel_Horizontal
26281 CALL TestCharlieCollision Test whether the peel has hit Charlie using TestCharlieCollision.
26284 DEC E Has the peel hit Charlie (is E now zero)?
26285 JP Z,LoseHat Jump to LoseHat if Charlie has been hit.
26288 CALL TestFlourCollision Test whether a flour shot has hit the peel using TestFlourCollision.
26291 BIT 7,(IX+0) Jump to HandleHitActor if the peel has been hit.
26295 JP NZ,HandleHitActor
Every 16 frames pick a new random direction.
26298 LD A,(IX+7) Fetch the direction counter.
26301 INC A Increase the direction counter by one.
26302 AND %00001111 Keep only bits 0-3.
26304 LD (IX+7),A Update the direction counter.
26307 JR NZ,HandlePeel_Vertical Jump to HandlePeel_Vertical if the counter is not zero.
26309 LD A,R Fetch a random number.
26311 AND %00000111 Keep only bits 0-2.
26313 LD (IX+6),A Write the random number to the direction of the peel (byte 6 of the actor).
Move vertically.
HandlePeel_Vertical 26316 CALL FindWanderSpeeds Find the speeds for the counter using FindWanderSpeeds.
26319 LD (IX+3),67 Set the colour to 67.
26323 JR NZ,HandlePeel_VerticalSpeed Jump to HandlePeel_VerticalSpeed if bit 2 of the actor state is set.
26325 INC HL Use the second byte of the pair.
HandlePeel_VerticalSpeed 26326 LD A,(HL) Fetch the speed.
26327 BIT 1,(IX+6) Jump to HandlePeel_VerticalMove if the peel is moving down.
26331 JR NZ,HandlePeel_VerticalMove
26333 NEG Make the speed negative.
HandlePeel_VerticalMove 26335 ADD A,(IX+2) Add the speed to the vertical co-ordinate.
26338 CP 160 Jump to HandlePeel_Bottom if the peel has reached the bottom.
26340 JR NC,HandlePeel_Bottom
26342 CP 32 Jump to HandlePeel_Top if the peel has reached the top.
26344 JR C,HandlePeel_Top
26346 LD (IX+2),A Update the vertical co-ordinate.
Move horizontally.
HandlePeel_Horizontal 26349 CALL FindWanderSpeeds Find the speeds for the counter using FindWanderSpeeds.
26352 JR Z,HandlePeel_HorizontalSpeed Jump to HandlePeel_HorizontalSpeed if bit 2 of the actor state is not set.
26354 INC HL Use the second byte of the pair.
HandlePeel_HorizontalSpeed 26355 LD A,(HL) Fetch the speed.
26356 BIT 0,(IX+6) Jump to HandlePeel_HorizontalMove if the peel is moving right.
26360 JR NZ,HandlePeel_HorizontalMove
26362 NEG Make the speed negative.
HandlePeel_HorizontalMove 26364 ADD A,(IX+1) Add the speed to the horizontal co-ordinate.
26367 CP 4 Jump to HandlePeel_LeftEdge if the peel has reached the left edge.
26369 JR C,HandlePeel_LeftEdge
26371 CP 192 Jump to HandlePeel_RightEdge if the peel has reached the right edge.
26373 JR NC,HandlePeel_RightEdge
HandlePeel_Animate 26375 LD (IX+1),A Update the horizontal co-ordinate.
26378 LD A,(IX+7) Fetch the direction counter.
26381 RRA Shift the counter right by one.
26382 AND %00000001 Keep only bit 0.
26384 XOR (IX+0) Flip the bit 0 of the actor ID, when bit 1 of the counter is set.
26387 LD (IX+0),A Update the actor ID.
26390 JP MoveBouncingActor_Draw Jump to MoveBouncingActor_Draw to move and colour the sprite.
The peel has reached the bottom, so move it up.
HandlePeel_Bottom 26393 LD (IX+2),160 Write 160 to the vertical co-ordinate.
26397 RES 1,(IX+6) Reset bit 1 of the actor state.
26401 JR HandlePeel_Horizontal Jump to HandlePeel_Horizontal.
The peel has reached the top, so move it down.
HandlePeel_Top 26403 SET 1,(IX+6) Set bit 1 of the actor state.
26407 JR HandlePeel_Horizontal Jump to HandlePeel_Horizontal.
The peel has reached the left edge, so move it right.
HandlePeel_LeftEdge 26409 SET 0,(IX+6) Set bit 0 of the actor state.
26413 JR HandlePeel_Animate Jump to HandlePeel_Animate.
The peel has reached the right edge, so move it left.
HandlePeel_RightEdge 26415 RES 0,(IX+6) Reset bit 0 of the actor state.
26419 JR HandlePeel_Animate Jump to HandlePeel_Animate.
Prev: 26241 Up: Map Next: 26421