Bullets collide with slopes

This commit is contained in:
cuckydev 2019-01-30 16:41:18 -05:00
parent fafce1f4c6
commit 7a44e6c8e0
2 changed files with 136 additions and 6 deletions

View file

@ -151,6 +151,142 @@ int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul)
return hit;
}
int JudgeHitBulletTriangleA(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y - 0x400 < (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 + 0xC00;
else
Vanish(bul);
hit = 0x82;
}
return hit;
}
int JudgeHitBulletTriangleB(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y - 0x400 < (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x400;
else
Vanish(bul);
hit = 0x82;
}
return hit;
}
int JudgeHitBulletTriangleC(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y - 0x400 < (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x400;
else
Vanish(bul);
hit = 0x82;
}
return hit;
}
int JudgeHitBulletTriangleD(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y - 0x400 < (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x800
&& bul->y + 0x400 > (2 * y - 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 + 0xC00;
else
Vanish(bul);
hit = 0x82;
}
return hit;
}
int JudgeHitBulletTriangleE(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x - 0x200 > (2 * x - 1) << 12
&& bul->y + 0x400 > (y << 13) + (-0x2000 * x + bul->x) / 2 - 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12 )
{
if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 - 0xC00;
else
Vanish(bul);
hit = 0x28;
}
return hit;
}
int JudgeHitBulletTriangleF(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y + 0x400 > (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) + (-0x2000 * x + bul->x) / 2 + 0x400;
else
Vanish(bul);
hit = 0x28;
}
return hit;
}
int JudgeHitBulletTriangleG(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y + 0x400 > (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12)
{
if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 + 0x400;
else
Vanish(bul);
hit = 0x18;
}
return hit;
}
int JudgeHitBulletTriangleH(int x, int y, BULLET *bul)
{
int hit = 0;
if (bul->x < (2 * x + 1) << 12
&& bul->x > (2 * x - 1) << 12
&& bul->y + 0x400 > (y << 13) - (-0x2000 * x + bul->x) / 2 - 0x800
&& bul->y - 0x400 < (2 * y + 1) << 12 )
{
if (bul->bbits & 8)
bul->y = (y << 13) - (-0x2000 * x + bul->x) / 2 - 0xC00;
else
Vanish(bul);
hit = 0x18;
}
return hit;
}
void HitBulletMap()
{
for (int i = 0; i < BULLET_MAX; i++)
@ -196,7 +332,6 @@ void HitBulletMap()
case 0x64:
gBul[i].flag |= JudgeHitBulletBlock(x + offx[j], y + offy[j], &gBul[i]);
break;
/*
case 0x50:
case 0x70:
gBul[i].flag |= JudgeHitBulletTriangleA(x + offx[j], y + offy[j], &gBul[i]);
@ -229,7 +364,6 @@ void HitBulletMap()
case 0x77:
gBul[i].flag |= JudgeHitBulletTriangleH(x + offx[j], y + offy[j], &gBul[i]);
break;
*/
default:
break;
}

View file

@ -236,10 +236,6 @@ int main(int argc, char *argv[])
}
//Create window
#ifdef WINDOWS
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); //This fixes textures unloading in fullscreen
#endif
gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, gWindowWidth, gWindowHeight, bFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
if (gWindow)