;################################### ;#DRAW PLAYER ;# ;# ;# ;################################### drawPlayer: ld hl,players+pX ;player1X ld a,(numPlayers) ld b,0 ld de,4 dP_setup: ld c,(hl) push bc ;store pX inc hl ld a,(hl) push af ;store pY inc hl inc hl ld c,(hl) push bc ;store pChar(acter) add hl,de ;jump to next player dec a jr nz,dP_setup dP_outerLoop: pop hl ;recall first pChar add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ex de,hl ld ix,playerSprites add ix,de ld hl,yCoord playerY = $+1 ld a,10 sub (hl) ;subtract map's y coordinates from our player to draw player correctly on the map or a ret m ;if playerY is negative, sprite is offscreen cp 5 ret nc ;if playerY>4 sprite is offscreen ld l,a ld h,0 ld d,h ld b,h add hl,hl add hl,hl add hl,hl add hl,hl ;x16 playerYOff = $+1 ld e,0 add hl,de 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 playerX = $+1 add a,10 or a ret m ;if playerX is negative, sprite is offscreen cp 7 ret nc ;if playerX is >6, sprite is offscreen ld c,a sla c playerXOff = $+1 ld a,0 cp 8 jr c,$+3 inc c ;if XOff >= 8, move one byte over 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 ret