Hi there !!
I'm using a routine to check if the ship and the bullets hit a wall.
However, this routine is not 100% accurate (sometimes you die when you fly very close to a wall)
Maybe this is because r#18 (horizontal screen offset) and r#23 (vertical screen offset) are used on VBLANK and at the linesplit (y=20) this routine.
Also the page is switched every 16 steps.
The sprites are 16x16 and I want the collision detection to occur exactly in the middle of the sprite.
This is my routine, I would love some help to perfect it, or speed it up !!! THANX !!
CollisionCheck: ;collision with foreground check
;set X-coordinate
LD A,(vdp_8+10) ;horizontal screen offset
ADD 7
AND 15
RRA ;devide by 2
LD B,A
LD A,(X_coord) ;x coordinate of whatever needs collision detection
RRA ;devide by 2 (screen 5 is used, and 2 pixels are defined in
ADD B ;1 byte, so devide by 2)
LD L,A ;store X
;set y-coordinate
LD A,($F3E1) ;current page
AND %00100000 ;check which page is displayed (0 or 1?)
RLCA ;page 1? then a=128, page 0? then a=0
RLCA ;add 128 bytes to y-coordinate when page 1 is used
LD C,A
LD A,(vdp_8+15) ;vertical screen offset
LD B,A
LD A,(Y_coord) ;y coordinate of whatever needs collision detection
ADD B ;add vertical screen offset
RRA ;devide by 2 (screen 5 is used, and 2 pixels=1 byte)
ADD 4 ;chech the middle of this sprites Y
ADD C
LD H,A ;store Y
CALL VDPREA ;now check the color value at these coordinates
IN A,($98)
AND 15 ;color from 0-15
SUB 4 ;color=>4 ?
RET C
YOU DIE !!