[A83] Re: annoying sprite problem...( ,) (, )
[Prev][Next][Index][Thread]
[A83] Re: annoying sprite problem...( ,) (, )
Maybe if you actually asked a question, it would be easier to help you :)
The simplest way to check if sprites are touching is using a bounding box.
If you want pixel perfect tests, then have fun :) That actually wouldn't be
too hard. It'd be similiar to a putsprite routine. But it's much more
complicated, and usually not worthwhile or necessary. If you have 8x8
sprites, and they are a bit smaller than that, you can use say 7x7 or 6x6
bounding boxes. Or, if you are checking sprites against points, say for
bullets, then you just use one bounding box. The math for the checks is
very simple, and I'm sure you could figure it out if you got out some paper
(possibly graph paper), drew some bounding boxes for sprites, put in some
coordinates, and did a few subtractions and comparisons.
I don't feel like explaining it further, so I'll just paste a couple
routines from Zelda 86. I'm sure you can figure it out from here, or just
use my routines. Note that these assume 8x8 sprites:
; bc = (x1,y1), de = (x2,y2)
; returns: no carry = collision
CheckCollision:
ld a,d
add a,7
cp b
ret c
ld a,b
add a,7
cp d
ret c
ld a,e
add a,7
cp c
ret c
ld a,c
add a,7
cp e
ret
; in: bc = point, de = coords
; returns: no carry = collision
CheckPoint:
ld a,d
add a,7
cp b
ret c
ld a,e
add a,7
cp c
ret c
ld a,b
cp d
ret c
ld a,c
cp e
ret
> In a game I'm writing, there's a part where the calc checks if a sprite
(any
> part of this sprite) touches any part of another sprite. IT'S NOT WORKING!
> I've tried many different things to get this to work, but my efforts bring
no
> success! I hope someone out there could help me with this, with a detailed
> explanation.
References: