LoginLogin

[PTC2] Some idea of how SPHITX, SPHITY, and SPHITT work, maybe

Root / General / [.]

MinxrodCreated:
In case of SPHIT(ID), sprite id's coordinates are X,Y, displacement vector is DX,DY, and vars. SPHITX and SPHITY are the coordinates the sprite would first collide at along the displacement vector. SPHITT is the "distance" from SPHITX, SPHITY along the axis <X,Y> to <X+DX, Y+DY>, normalized to [0,1]. So if a sprite collides with no vector or would have collided without the vector, SPHITT is 0, and <SPHITX,SPHITY> = <X,Y>. If the sprites only collide at the very edge of the displacement, then SPHITT would be 1, and <SPHITX,SPHITY> = <X+DX,Y+DY>. If the sprite collided with a displacement halfway along the vector, then SPHITT=0.5, and <SPHITX,SPHITY>=<X+DX/2,Y+DY/2>. This needs some rewording and testing and also pictures, probably. Simple test:
TEXT=FALSE
ACLS
GPRIO 0
SPSET 0,64,2,0,0,2
SPSET 1,96,4,1,0,2
SPSET 2,64,5,0,0,2
SPCOL 0,0,0,16,16,0
SPCOL 1,0,0,16,16,0
SPCOL 2,0,0,16,16,0
SPOFS 0,64,64
SPOFS 2,96,64

TABSTEP=4
IF TEXT THEN ?"X","Y","DX","DY"
IF TEXT THEN ?"H","NO","X","Y","T"
R=80
DR=32
@T
GCLS 0
X=80'+RND(R)-RND(R)
Y=96'+RND(R)-RND(R)
DX=RND(DR)-RND(DR)
DY=RND(DR)-RND(DR)

GBOX X,Y,X+15,Y+15,2
GBOX X+DX,Y+DY,X+DX+15,Y+DY+15,2
GBOX 64,64,64+15,64+15,6
GBOX 96,64,96+15,64+15,10

SPOFS 1,X,Y
SPCOLVEC 1,DX,DY

H=SPHIT(1)
HX=SPHITX:HY=SPHITY
GBOX HX,HY,HX+15,HY+15,3

IF !H THEN @T
IF TEXT THEN ?X,Y,DX,DY
IF TEXT THEN ?H,SPHITNO,SPHITX,SPHITY,SPHITT

@W
VSYNC 1
IF BTRIG() THEN @T
GOTO @W