- getangle in animatesprites

This commit is contained in:
Christoph Oelckers 2022-08-23 22:46:05 +02:00
parent 478672879e
commit d700b11887
2 changed files with 17 additions and 15 deletions

View file

@ -46,6 +46,7 @@ BEGIN_DUKE_NS
void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothratio) void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothratio)
{ {
DVector2 viewVec(x * inttoworld, y * inttoworld);
int k, p; int k, p;
int l, t1, t3, t4; int l, t1, t3, t4;
tspritetype* t; tspritetype* t;
@ -219,7 +220,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
t->xrepeat = 0; t->xrepeat = 0;
else else
{ {
t->set_int_ang(getangle(x - t->int_pos().X, y - t->int_pos().Y)); t->angle = VecToAngle(viewVec - t->pos.XY());
t->pos.X = OwnerAc->spr.pos.X + t->angle.Cos(); t->pos.X = OwnerAc->spr.pos.X + t->angle.Cos();
t->pos.Y = OwnerAc->spr.pos.Y + t->angle.Sin(); t->pos.Y = OwnerAc->spr.pos.Y + t->angle.Sin();
} }
@ -260,7 +261,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
} }
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -278,7 +279,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
} }
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
if (h->temp_data[0] < 4) if (h->temp_data[0] < 4)
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
else k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); else k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
@ -510,7 +511,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
case 5: case 5:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7; k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7;
if (k > 4) if (k > 4)
{ {
@ -520,7 +521,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
else t->cstat &= ~CSTAT_SPRITE_XFLIP; else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break; break;
case 7: case 7:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {

View file

@ -39,6 +39,7 @@ BEGIN_DUKE_NS
void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothratio) void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothratio)
{ {
DVector2 viewVec(x * inttoworld, y * inttoworld);
int k, p; int k, p;
int l, t1, t3, t4; int l, t1, t3, t4;
tspritetype* t; tspritetype* t;
@ -213,7 +214,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
t->xrepeat = 0; t->xrepeat = 0;
else else
{ {
t->set_int_ang(getangle(x - t->int_pos().X, y - t->int_pos().Y)); t->angle = VecToAngle(viewVec - t->pos.XY());
t->pos.X = OwnerAc->spr.pos.X + t->angle.Cos(); t->pos.X = OwnerAc->spr.pos.X + t->angle.Cos();
t->pos.Y = OwnerAc->spr.pos.Y + t->angle.Sin(); t->pos.Y = OwnerAc->spr.pos.Y + t->angle.Sin();
} }
@ -254,7 +255,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
} }
else if (OwnerAc->spr.picnum == MAMA) else if (OwnerAc->spr.picnum == MAMA)
{ {
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7; k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7;
if (k > 4) if (k > 4)
{ {
@ -272,7 +273,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
case EMPTYBIKE: case EMPTYBIKE:
if (!isRRRA()) goto default_case; if (!isRRRA()) goto default_case;
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -284,7 +285,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
case EMPTYBOAT: case EMPTYBOAT:
if (!isRRRA()) goto default_case; if (!isRRRA()) goto default_case;
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -295,7 +296,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
t->picnum = EMPTYBOAT + k; t->picnum = EMPTYBOAT + k;
break; break;
case RPG: case RPG:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -307,7 +308,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
case RPG2: case RPG2:
if (!isRRRA()) goto default_case; if (!isRRRA()) goto default_case;
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -320,7 +321,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
case RECON: case RECON:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
if (h->temp_data[0] < 4) if (h->temp_data[0] < 4)
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
else k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); else k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
@ -642,7 +643,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
break; break;
case 5: case 5:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7; k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7;
if (k > 4) if (k > 4)
{ {
@ -652,7 +653,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
else t->cstat &= ~CSTAT_SPRITE_XFLIP; else t->cstat &= ~CSTAT_SPRITE_XFLIP;
break; break;
case 7: case 7:
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170); k = (((h->int_ang() + 3072 + 128 - k) & 2047) / 170);
if (k > 6) if (k > 6)
{ {
@ -669,7 +670,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
bg = badguy(h); bg = badguy(h);
if (bg && h->spr.statnum == 2 && h->spr.extra > 0) if (bg && h->spr.statnum == 2 && h->spr.extra > 0)
{ {
k = getangle(h->int_pos().X - x, h->int_pos().Y - y); k = getangle(h->spr.pos - viewVec);
k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7; k = (((h->int_ang() + 3072 + 128 - k) & 2047) >> 8) & 7;
if (k > 4) if (k > 4)
{ {