[Fix]? F*ck collisions!! I'll fix it tomorrow. kbai.
This commit is contained in:
parent
b8a4d4fe37
commit
1ad17e0dae
@ -141,13 +141,9 @@ int CollideLineSprite(const Vec2* ap, double ad, double al,
|
|||||||
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp,
|
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp,
|
||||||
Vec2* crash) {
|
Vec2* crash) {
|
||||||
|
|
||||||
(void) bt;
|
|
||||||
(void) bsx;
|
|
||||||
(void) bsy;
|
|
||||||
|
|
||||||
int x, y, rbsy, bbx, bby;
|
int x, y, rbsy, bbx, bby;
|
||||||
double ep[2], bl[2], tr[2], v[2], mod;
|
double ep[2], bl[2], tr[2], v[2], mod;
|
||||||
int hits;
|
int hits, real_hits;
|
||||||
Vec2 tmp_crash, border[2];
|
Vec2 tmp_crash, border[2];
|
||||||
|
|
||||||
/* Set up end point of line. */
|
/* Set up end point of line. */
|
||||||
@ -196,21 +192,25 @@ int CollideLineSprite(const Vec2* ap, double ad, double al,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No hits - missed. */
|
/* No hits - missed. */
|
||||||
if(hits == 0)
|
if(hits == 2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Special case only one hit - Shouldn't happen, but just in case. */
|
/* Beam must die in the rectangle. */
|
||||||
if(hits == 1) {
|
if(hits == 1) {
|
||||||
if(hits == 1) {
|
border[1].x = ep[0];
|
||||||
/* We just return the same point twise. */
|
border[1].y = ep[1];
|
||||||
crash[0].x = crash[1].x = border[0].x;
|
|
||||||
crash[0].y = crash[1].y = border[0].y;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
crash[0].x = border[0].x;
|
||||||
|
crash[0].y = border[0].y;
|
||||||
|
crash[1].x = border[1].x;
|
||||||
|
crash[1].y = border[1].y;
|
||||||
|
return 1;
|
||||||
|
*/
|
||||||
|
|
||||||
/* Now we do a pixel perfect approach. */
|
/* Now we do a pixel perfect approach. */
|
||||||
hits = 0;
|
real_hits = 0;
|
||||||
/* directional vector (normalised). */
|
/* directional vector (normalised). */
|
||||||
v[0] = border[1].x - border[0].x;
|
v[0] = border[1].x - border[0].x;
|
||||||
v[1] = border[1].y - border[0].y;
|
v[1] = border[1].y - border[0].y;
|
||||||
@ -232,35 +232,40 @@ int CollideLineSprite(const Vec2* ap, double ad, double al,
|
|||||||
while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
|
while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
|
||||||
/* Is non-transparent. */
|
/* Is non-transparent. */
|
||||||
if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
|
if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
|
||||||
crash[0].x = x + bl[0];
|
crash[real_hits].x = x + bl[0];
|
||||||
crash[0].y = y + bl[1];
|
crash[real_hits].y = y + bl[1];
|
||||||
hits++;
|
real_hits++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
x += v[0];
|
x += v[0];
|
||||||
y += v[1];
|
y += v[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hits != 1) return 0; /* We actually missed. */
|
|
||||||
|
|
||||||
/* Now we check the second border. */
|
/* Now we check the second border. */
|
||||||
x = border[1].x - bl[0] - v[0];
|
x = border[1].x - bl[0] - v[0];
|
||||||
y = border[1].y - bl[1] - v[1];
|
y = border[1].y - bl[1] - v[1];
|
||||||
while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
|
while((x > 0.) && (x < bt->sw) && (y > 0.) && (y < bt->sh)) {
|
||||||
/* Is non-transparent. */
|
/* Is non-transparent. */
|
||||||
if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
|
if(!gl_isTrans(bt, bbx+(int)x, bby+(int)y)) {
|
||||||
crash[1].x = x + bl[0];
|
crash[real_hits].x = x + bl[0];
|
||||||
crash[1].y = y + bl[1];
|
crash[real_hits].y = y + bl[1];
|
||||||
hits++;
|
real_hits++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
x -= v[0];
|
x -= v[0];
|
||||||
y -= v[1];
|
y -= v[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hits != 2) return 0; /* We actually missed. */
|
/* Actually missed. */
|
||||||
|
if(real_hits == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Strange situation, should never happen, but just in case we duplicate
|
||||||
|
* the hits. */
|
||||||
|
if(real_hits == 1) {
|
||||||
|
crash[1].x = crash[0].x;
|
||||||
|
crash[1].y = crash[0].y;
|
||||||
|
}
|
||||||
|
|
||||||
/* We hit! */
|
/* We hit! */
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user