Re: A86: Sprite hits sprite
[Prev][Next][Index][Thread]
Re: A86: Sprite hits sprite
At 06:40 PM 8/20/98 EDT, you wrote:
>
>What would I put in my program to make it so that one sprite hits another one
>and adds to the score? I know how to do the score part but the sprite
hitting
>the other sprite part is unknown to me. I have this:
You have to compute the distance between the two sprites. Read the code
below and understand it. This kind of stuff is important, because it
teaches how to do logic in assembly:
; check for collision between two 8x8 sprites
; input: BC = 1st X,Y coords DE = 2nd X,Y coords
CheckHit:
ld a,h ; load 1st X coord
sub d ; get distance from 2nd X coord
jr nc,SkipCarryX ; is the distance negative?
neg ; if so, we need the abs value
SkipCarryX:
cp 8 ; subtract 8
jr nc,NoHit ; if positive, it was more than 8, no hit
ld a,l ; load 1st Y coord
sub e ; get distance from 2nd Y coord
jr nc,SkipCaryY ; is the distance negative?
neg ; yep, we need the abs of it
SkipCarryY:
cp 8 ; subtract 8 again
jr nc,NoHit ; if positive, no hit
Hit:
ret ; if we are here, they hit
NoHit:
ret ; if we are here, they didn't hit
>Also, how do I display the value of a, for example, to the screen. Something
>to the effect of Outpt(1,1,a)
;=============================================================
; Display3dNum: Display a 3-digit number that is in A
;=============================================================
; routine by Matt Johnson (from Metroid)
Display3dNum:
ld h, 0
ld l, a
call UNPACK_HL
add a, 48 ; 48 is the start of character '0' (zero)
ld c, a ; Save 3rd digit
call UNPACK_HL
add a, 48
ld b, a ; Save 2nd digit
call UNPACK_HL
add a, 48 ; A = 1st digit
call _vputmap ; Display 1st digit
ld a, b
call _vputmap ; Display 2nd digit
ld a, c
call _vputmap ; Display 3rd digit
ret
--
David Phillips
mailto:electrum@tfs.net
ICQ: 13811951
AOL/AIM: Electrum32
References: