Prev: CC31 Up: Map Next: CCE9
CC4B: The update routine for a homer (graphics 48 to 51 and 160 to 167)
Flies at the player. Speeds in U, V and Z are kept in sixteenths in +$14, +$15 and +$16; each turn each gains 3 towards the player -- U and V towards his legs (PLAYER_U, PLAYER_V), Z towards his body's Z -- up to +56 or down to -72, and the step for the next turn is the speed plus 8 divided by 16, rounding down: at most 4 units a turn either way. Gravity takes one off the Z step before the move (DEC_DZ_AND_UPDATE_UVZ). A move stopped in U or V turns that speed round, so a homer bounces off walls and objects; one stopped in Z keeps its speed (the routine that would turn it, at BOUNCE_Z, is never called).
The half-sizes in U and V are set to 10 every turn, over the 8 of FLYER_TEMPLATE. The four frames are the low two bits of the graphic, from a count in +$10. Some fall from the sky (DROP_GRAPHICS); object template 2 is graphic 48, so a room can start with one too.
The last four instructions are where most moving things' updates finish: bits 4 and 5 of the flags, draw it and copy its rectangle to the screen, and SET_DRAW_OBJS_OVERLAPPED, which marks whatever it overlaps for redrawing.
Input
IX The homer's record
HOMER CC4B CALL DRAW_AT_L12_D6 Drawn 12 left and 6 down
CC4E LD (IX+$04),$0A Half-sizes 10 in U and V
CC52 LD (IX+$05),$0A
CC56 CALL DEC_DZ_AND_UPDATE_UVZ Z step less 1, cut short where it must be, and moved
CC59 LD A,(IX+$0C) Stopped on any axis?
CC5C AND $07
CC5E JR Z,HOMER_0
CC60 AND $01 In U: turn the U speed round
CC62 CALL NZ,BOUNCE_U
CC65 BIT 1,(IX+$0C) In V: turn the V speed round
CC69 CALL NZ,BOUNCE_V
HOMER_0 CC6C LD A,(PLAYER_U) The U speed: 3 towards the player's U
CC6F SUB (IX+$01)
CC72 LD A,(IX+$14)
CC75 JR NC,HOMER_5
CC77 CALL ACCEL_MINUS
HOMER_1 CC7A LD (IX+$14),A The V speed: 3 towards his V
CC7D LD A,(PLAYER_V)
CC80 SUB (IX+$02)
CC83 LD A,(IX+$15)
CC86 JR NC,HOMER_6
CC88 CALL ACCEL_MINUS
HOMER_2 CC8B LD (IX+$15),A The Z speed: 3 towards his body's Z
CC8E LD A,($A792)
CC91 SUB (IX+$03)
CC94 LD A,(IX+$16)
CC97 JR NC,HOMER_7
CC99 CALL ACCEL_MINUS
HOMER_3 CC9C LD (IX+$16),A The steps in U, V and Z: each speed plus 8, divided by 16
CC9F LD B,$03
HOMER_4 CCA1 INC IX
CCA3 LD A,(IX+$13)
CCA6 ADD A,$08
CCA8 SRA A
CCAA SRA A
CCAC SRA A
CCAE SRA A
CCB0 LD (IX+$08),A
CCB3 DJNZ HOMER_4
CCB5 DEC IX
CCB7 DEC IX
CCB9 DEC IX
CCBB JR HOMER_8
HOMER_5 CCBD CALL ACCEL_PLUS The player at a greater U, V or Z (or level): 3 up
CCC0 JR HOMER_1
HOMER_6 CCC2 CALL ACCEL_PLUS
CCC5 JR HOMER_2
HOMER_7 CCC7 CALL ACCEL_PLUS
CCCA JR HOMER_3
HOMER_8 CCCC INC (IX+$10) The next of four frames
CCCF LD A,(IX+$10)
CCD2 AND $03
CCD4 LD B,A
CCD5 LD A,(IX+$00)
CCD8 AND $FC
CCDA ADD A,B
CCDB LD (IX+$00),A
SET_WIPE_AND_DRAW_FLAGS CCDE LD A,(IX+$07) Draw it and copy its rectangle to the screen, and mark what it overlaps
CCE1 OR $30
CCE3 LD (IX+$07),A
CCE6 JP SET_DRAW_OBJS_OVERLAPPED
Prev: CC31 Up: Map Next: CCE9