|
Post by ultranarwhal on Apr 24, 2019 14:31:32 GMT
In the Speccy version of AGD I like to set the collision distance to 12 from the default of 16, how do I do this in MPAGD? I've looked in my compiled games ASM under the collision detection and changed the Y range, but it didn't make difference.
Thanks.
|
|
|
Post by Jonathan Cauldwell on Apr 24, 2019 20:03:09 GMT
MPAGD uses a slightly better octagonal collision detection routine whereas AGD basically performed a simple square or rectangular coordinate check.
In the source code the collision detection routine looks like this:
; Drop into collision detection.
colc16 ld a,(ix+X) ; x coord. sub e ; subtract x. jr nc,colc1a ; result is positive. neg ; make negative positive. colc1a cp 16 ; within x range? jr nc,sktyp1 ; no - they've missed. ld c,a ; store difference. ld a,(ix+Y) ; y coord. sub d ; subtract y. jr nc,colc1b ; result is positive. neg ; make negative positive. colc1b cp 16 ; within y range? jr nc,sktyp1 ; no - they've missed. add a,c ; add x difference. cp 26 ; only 5 corner pixels touching? ret c ; carry set if there's a collision. jp sktyp1 ; try next sprite in table.
if you change this line
colc1b cp 16 ; within y range?
to look like this
colc1b cp 12 ; within y range?
your sprites will need to be within 12 pixels of each other horizontally before the collision is registered. Similarly, you could change the line colc1a to change the vertical collision distance.
These three lines might also be of interest to you:
add a,c ; add x difference. cp 26 ; only 5 corner pixels touching? ret c ; carry set if there's a collision.
These are essentially clipping the corners of the sprites, meaning collisions won't register if only a few pixels in the corner are overlapping. After all, sprites don't often fill the corner pixels. If you want to retain this feature you might want to reduce the cp 26 a little. Alternatively, increase it to cp 28 if you just want to test a 12x16 rectangle. Have a play and see what works best for your game.
If you want to edit EngineZX.asm, the change will be applied every time you build as this is the Spectrum engine that is used as the basis of every game.
Does that help?
|
|
|
Post by ultranarwhal on Apr 24, 2019 21:47:52 GMT
Thanks Jonathan. This does help and I was editing the right bit, I was just testing it wrong. Rather than testing 2 sprites I was checking sprite against solid tiles, which it doesn't affect.
|
|
|
Post by sp3fnw on Oct 10, 2020 17:51:10 GMT
ok and how to change the distance of collisions with blocks?
|
|