Prev: D1CD Up: Map Next: D2BF
D1CE: Draw Dan and do any collision detection
Used by the routines at CFD9, D079, D08A, D0DC, D123, D16F, D2F0 and DBEE.
D1CE LD A,($C880) Get the frame count. (C880)
D1D1 BIT 0,A Is bit 0 set?
D1D3 JR Z,$D1DA Jump forward if not.
D1D5 LD DE,$62D6 Re-use Dan's existing graphic.
D1D8 JR $D1E8 Move forward to do the drawing.
Put a new frame for Dan in the graphic buffer.
D1DA LD A,($C875) Get Dan's current graphic. (C875)
D1DD ADD A,A Double it to get a word offset.
D1DE LD C,A Put this in BC.
D1DF LD B,$00
D1E1 LD HL,$632A Add the base offset for the graphic table. (632A)
D1E4 ADD HL,BC
D1E5 LD E,(HL) Put the graphic address in DE.
D1E6 INC HL
D1E7 LD D,(HL)
D1E8 LD HL,$62D6 Point HL at the working graphic buffer. (62D6)
There is now a working sprite for Dan, so find the right place on screen to put it.
D1EB EXX Swap BC, DE and HL so the graphic addresses can be preserved.
D1EC LD DE,($C872) Put Dan's co-ordinates in DE.
D1F0 LD A,($DBED) Get the height to draw.
D1F3 LD B,A Iterate for this number of rows.
D1F4 PUSH BC Store BC and DE.
D1F5 PUSH DE
D1F6 CALL $E8D2 Convert the co-ordinates into a screen address.
D1F9 PUSH DE Remember DE which holds the screen address.
D1FA CALL $E90C Convert the screen address to an attribute address.
D1FD EX DE,HL Put the screen address in HL and the attribute address in DE.
D1FE POP DE
Found a place on screen to draw Dan, so do it.
D1FF LD C,$02 2 UDG cells to draw.
D201 PUSH DE Store DE and HL.
D202 PUSH HL
D203 LD B,$03 3 columns to draw.
D205 LD A,(HL) Get the current attribute on screen.
D206 CP $45 Is it empty (bright cyan on black)?
D208 JR NZ,$D210 Jump forward if it isn't.
Dan's in empty space.
D20A EXX Set the current working graphic data to 0 and jump forward.
D20B XOR A
D20C LD (HL),A
D20D EXX
D20E JR $D238
Dan's not in empty space, need to figure out what's here. If Dan's collided with some dynamite or a test tube, the cycling attribute will equal 0 at this point, and be picked up.
D210 AND A Is the attribute zero? (ie: dynamite or test tube)
D211 JR NZ,$D216 Jump forward if it isn't.
D213 EXX Otherwise exchange the main registers and jump forward.
D214 JR $D21F
Dan's collided with something.
D216 AND $78 Get bits 3-6.
D218 CP $40 Is only bit 6 set?
D21A JR NZ,$D238 Jump forward if it isn't.
D21C EXX Swap the main registers to make the graphic and buffer active in HL and DE.
D21D XOR A Set the current working graphic data to 0.
D21E LD (HL),A
D21F LD A,(DE) Put the next graphic data in A.
D220 INC DE Move to the next position in the buffer.
D221 INC HL
D222 EXX Swap the main registers to make the screen and attributes active in HL and DE.
D223 EX DE,HL Swap DE and HL.
D224 PUSH AF Remember AF.
D225 AND (HL) Does the graphic data match what's on screen?
D226 JR Z,$D22E Jump forward if so.
Dan has collided with something, find out what.
D228 LD A,(DE) Get the attribute.
D229 SET 7,A Set bit 7 (Dan collided with something).
D22B LD ($D1CD),A Store this in the collision flags (#$D1CD).
D22E POP AF Restore AF.
D22F OR (HL) Overlay this graphic data with what's on screen.
D230 EX DE,HL Swap DE and HL.
D231 LD (DE),A Set the screen data to be a combination of the graphics.
D232 INC DE Move to the next position on screen.
D233 INC L Move to the next attribute.
D234 DJNZ $D205 Loop while there are more columns to check.
D236 JR $D243
Handle Dan in empty space.
D238 EXX Swap registers to the graphic buffers are active in HL and DE.
D239 LD A,(DE) Put the next graphic byte in A.
D23A OR (HL) Merge with what's in the graphic buffer.
D23B INC DE Move to the next position in the buffer.
D23C INC HL
D23D EXX Swap registers so the screen and attributes are active in HL and DE.
D23E LD (DE),A Put this graphic byte on screen.
D23F INC DE Move forward on screen.
D240 INC L Move forward in the attributes.
D241 DJNZ $D205 Loop while there are more columns to check.
All done with checking this column, see if there is more to do.
D243 POP HL Restore HL and DE.
D244 POP DE
D245 INC D Move down a row.
D246 DEC C Loop until all rows have been checked.
D247 JR NZ,$D201
D249 POP DE Restore DE.
D24A INC E Move forward two columns.
D24B INC E
D24C POP BC Restore BC.
D24D DJNZ $D1F4 Loop back while there are more UDGs to draw.
Having drawn Dan, see what, if anything, he collided with.
D24F LD HL,$D1CD Get the collision attribute and flags (D1CD).
D252 BIT 7,(HL) Is bit 7 set (collided with something)?
D254 RET Z Return if it isn't.
D255 RES 7,(HL) Get the collision attribute.
D257 LD A,(HL)
D258 AND A It it zero?
D259 JP Z,$DE87 If so, Dan's hit a good object (test tube or dynamite), so handle it.
Dan has hit a moving object.
D25C LD A,($CFCA) Get the current room. (CFCA)
D25F CP $1B Is it the safe room? (6B1E)
D261 JR NZ,$D270 Jump forward if it isn't.
Dan's in the safe room, if he's hit Dr. Blitzen or Donna then he's in real trouble as they are immune from aerosol and won't disappear.
D263 LD A,($D1CD) Get the collision attribute. (D1CD)
D266 CP $43 Has Dan hit bright magenta?
D268 JP Z,$CD8A If so, Dan has hit Blitzen - lose a life and return immmediately.
D26B CP $47 Has Dan hit a bright white?
D26D JP Z,$CD8A If so, Dan has hit Donna - lose a life and return immediately.
Dan's hit an object that's not Blitzen or Donna. The aerosol might get him out of trouble.
D270 LD A,($C87E) Get some flags. (C87E)
D273 BIT 5,A Is bit 5 (Dan has the aerosol) set?
D275 JR Z,$D286 Jump forward if not.
Dan's got the aerosol, so hitting the object isn't fatal.
D277 LD HL,$FE71 Play the "got a moving object with the aerosol" tune. (FE71)
D27A CALL $DB0B
D27D LD A,$14 Add 0E to the score.
D27F LD HL,$C86B
D282 ADD A,(HL)
D283 LD (HL),A
D284 JR $D289 Skip over starting the "lose a life" sequence as Dan's got the aerosol.
Dan hit a moving object without the aerosol. Bad news.
D286 CALL $CD8A Start the "lose a life" sequence.
Now Dan has hit the moving object, and it's not Blitzen or Donna, get rid of it.
D289 LD L,(IX+$07) Point HL at the moving objects table for this room.
D28C LD H,(IX+$08)
D28F LD DE,$0006 Skip past the header.
D292 ADD HL,DE
D293 PUSH HL Point IY at the start of the tables.
D294 POP IY
D296 LD BC,($DED8) Point BC at the first moving graphics buffer. (DED8)
D29A LD A,($E540) Point A at the count of moving objects. (E540)
D29D CALL $D2BF Look for the object and remove it.
D2A0 LD BC,($DFCA) Point BC at the second moving graphics buffer. (DFCA)
D2A4 LD A,($E541) Point A at the count of moving objects. (E540)
D2A7 CALL $D2BF Look for the object and remove it.
D2AA LD BC,($E0BC) Point BC at the third moving graphics buffer. (E0BC)
D2AE LD A,($E542) Point A at the count of moving objects. (E540)
D2B1 CALL $D2BF Look for the object and remove it.
D2B4 LD BC,($E2FE) Point BC at the fourth moving graphics buffer. (E2FE)
D2B8 LD A,($E543) Point A at the count of moving objects. (E540)
D2BB CALL $D2BF Look for the object and remove it.
D2BE RET All done, return.
Prev: D1CD Up: Map Next: D2BF