;################################### ;#DRAW PLAYER ;# ;# ;# ;################################### currentPlayer: .db 0 playerX: .db 0 playerY: .db 0 playerXOff: .db 0 playerYOff: .db 0 drawPlayer: ld a,$FF push af ;draw the current player last! ld hl,playerX ld c,(hl) ;px inc hl ld e,(hl) ;py inc hl ld b,(hl) ;pxoff inc hl ld d,(hl) ;pyoff push bc push de ld e,P_CHAR ;e = databyte we want call getCurrentPlayer ld b,0 ld c,(hl) push bc exx ld b,0 ld d,b ld hl,players+P_X ;player1X exx ex af,af' xor a dP_setup: exx ld c,a ex af,af' ld a,(currentPlayer) cp c jr nz,$+6 ;we need to skip the current player ld e,6 add hl,de jr dP_skip ld c,(hl) push bc ;store pX inc hl ld e,(hl) push de ;store pY inc hl inc hl ld c,(hl) push bc ;store pChar(acter) inc hl inc hl inc hl dP_skip: exx ex af,af' ld hl,numberPlayers inc a cp (hl) jr nz,dP_setup dP_outerLoop: pop hl ld a,h cp $FF ret z add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ex de,hl ld ix,playerSprites-64 add ix,de ld hl,yCoord pop de ;e=pY d=pYoff pop bc ;c=pX b=pXoff ld a,e ;pY sub (hl) ;subtract map's y coordinates from our player to draw player correctly on the map or a jp m,dP_outerLoop ;if playerY is negative, sprite is offscreen cp 5 jr nc,dP_outerLoop ;if playerY>4 sprite is offscreen ld l,a ld h,0 ld e,d ;shift d into e and clear d ld d,h add hl,hl add hl,hl add hl,hl add hl,hl ;x16 add hl,de ;de = pYoff ld e,l ld d,h add hl,hl ;y*2 add hl,de ;y*3 add hl,hl ;y*6 add hl,de ;y*7 add hl,hl ;y*14 ld de,saferam1+2 ;86EC add hl,de ld a,(xCoord) neg add a,c ;pX or a jp m,dP_outerLoop ;if playerX is negative, sprite is offscreen cp 7 jr nc,dP_outerLoop ;if playerX is >6, sprite is offscreen ld c,a sla c ld a,b ;b=pXoff cp 8 jr c,$+3 inc c ;if XOff >= 8, move one byte over ld b,0 add hl,bc ;hl = starting point in gbuf and $7 ld c,16 ld b,a drawPlayerLoop: push bc drawPlayerRow ld d,(ix+32) ;sprite mask ld e,(ix+33) ld a,$ff dec b \ inc b \ jr z,skipMaskClip scf \ rr d \ rr e \ rra \ djnz $-6 ;rotate mask skipMaskClip: and (hl) ld (hl),a dec hl ld a,(hl) and e ld (hl),a dec hl ld a,(hl) and d ld (hl),a pop bc inc hl inc hl push bc ld d,(ix) ;sprite ld e,(ix+1) xor a cp b jp z,skipSpriteClip srl d \ rr e \ rra \ djnz $-5 ;rotate sprite skipSpriteClip: or (hl) ld (hl),a dec hl ld a,(hl) or e ld (hl),a dec hl ld a,(hl) or d ld (hl),a inc ix inc ix ld de,16 add hl,de pop bc dec c jp nz, drawPlayerLoop jp dP_outerLoop