Skip to content

Commit 23dd426

Browse files
committed
Use M_PI
1 parent a6cd3b4 commit 23dd426

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

src/ai.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ char pollAi(double posx, double posy, double dir, unsigned char id,
4343
int checkx, checky, result;
4444
if (i < COWARDNESS_DIAGS) {
4545
/* left diagonal */
46-
checkx = posx + i * cos(dir - PI / 4);
47-
checky = posy + i * sin(dir - PI / 4);
46+
checkx = posx + i * cos(dir - M_PI / 4);
47+
checky = posy + i * sin(dir - M_PI / 4);
4848
if (checkx < 0 || checky < 0 || (unsigned)checkx >= w ||
4949
(unsigned)checky >= h)
5050
return 'r';
5151
result = hitmap[w * checky + checkx];
5252
if (result != id + 8 && result != id + 16 && result != 0)
5353
return 'r';
5454
/* right diagonal */
55-
checkx = posx + i * cos(dir + PI / 4);
56-
checky = posy + i * sin(dir + PI / 4);
55+
checkx = posx + i * cos(dir + M_PI / 4);
56+
checky = posy + i * sin(dir + M_PI / 4);
5757
if (checkx < 0 || checky < 0 || (unsigned)checkx >= w ||
5858
(unsigned)checky >= h)
5959
return 'r';
@@ -63,17 +63,17 @@ char pollAi(double posx, double posy, double dir, unsigned char id,
6363
}
6464
if (i < COWARDNESS_SIDES) {
6565
/* right side */
66-
checkx = posx + i * cos(dir + PI / 2);
67-
checky = posy + i * sin(dir + PI / 2);
66+
checkx = posx + i * cos(dir + M_PI / 2);
67+
checky = posy + i * sin(dir + M_PI / 2);
6868
if (checkx < 0 || checky < 0 || (unsigned)checkx >= w ||
6969
(unsigned)checky >= h)
7070
return 'r';
7171
result = hitmap[w * checky + checkx];
7272
if (result != id + 8 && result != id + 16 && result != 0)
7373
return 'l';
7474
/* left side */
75-
checkx = posx + i * cos(dir - PI / 2);
76-
checky = posy + i * sin(dir - PI / 2);
75+
checkx = posx + i * cos(dir - M_PI / 2);
76+
checky = posy + i * sin(dir - M_PI / 2);
7777
if (checkx < 0 || checky < 0 || (unsigned)checkx >= w ||
7878
(unsigned)checky >= h)
7979
return 'r';

src/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef COMMON_H
22
#define COMMON_H
33

4-
#define PI 3.14159265358
54
#define STRBUF 32
65

76
/* DEFAULT WINDOW DIMENSIONS */

src/zatackax.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ struct vel spawn(void)
297297
rnd = (double)rand() / RAND_MAX;
298298
initPos.holecount = (rnd * (HOLE_FREQ - HOLE_FIRST_DELAY));
299299
rnd = (double)rand() / RAND_MAX;
300-
initPos.dir = rnd * (2 * PI);
300+
initPos.dir = rnd * (2 * M_PI);
301301
if (initPos.dir < 0)
302302
initPos.dir *= -1;
303303

@@ -357,7 +357,7 @@ void drespawn(struct player *p)
357357
p->alive = true;
358358
p->posx = (WINDOW_W / 2) + (p->active == 1 ? -120 : 120);
359359
p->posy = WINDOW_H / 2;
360-
p->dir = p->active == 1 ? 0 : PI;
360+
p->dir = p->active == 1 ? 0 : M_PI;
361361

362362
p->initposx = p->posx;
363363
p->initposy = p->posy;
@@ -756,13 +756,13 @@ int logicGame(void)
756756
* be turned on */
757757
/*
758758
refreshGameScreen();
759-
int checkx = p->posx + 40 * cos(p->dir + PI/2);
760-
int checky = p->posy + 40 * sin(p->dir + PI/2);
759+
int checkx = p->posx + 40 * cos(p->dir + M_PI/2);
760+
int checky = p->posy + 40 * sin(p->dir + M_PI/2);
761761
SDL_Rect a = {checkx, checky, 4, 4};
762762
SDL_FillRect(screen, &a, SDL_MapRGB(screen->format,
763763
0x55, 0x77, 0x99));
764-
checkx = p->posx + 40 * cos(p->dir - PI/2);
765-
checky = p->posy + 40 * sin(p->dir - PI/2);
764+
checkx = p->posx + 40 * cos(p->dir - M_PI/2);
765+
checky = p->posy + 40 * sin(p->dir - M_PI/2);
766766
SDL_Rect b = {checkx, checky, 4, 4};
767767
SDL_FillRect(screen, &b, SDL_MapRGB(screen->format,
768768
0x55, 0x77, 0x99));
@@ -776,13 +776,13 @@ int logicGame(void)
776776
SDL_Rect e = {checkx, checky, 4, 4};
777777
SDL_FillRect(screen, &e, SDL_MapRGB(screen->format,
778778
0xFF, 0x30, 0x30));
779-
checkx = p->posx + 60 * cos(p->dir + PI/4);
780-
checky = p->posy + 60 * sin(p->dir + PI/4);
779+
checkx = p->posx + 60 * cos(p->dir + M_PI/4);
780+
checky = p->posy + 60 * sin(p->dir + M_PI/4);
781781
SDL_Rect f = {checkx, checky, 4, 4};
782782
SDL_FillRect(screen, &f, SDL_MapRGB(screen->format,
783783
0x66, 0x66, 0x66));
784-
checkx = p->posx + 60 * cos(p->dir - PI/4);
785-
checky = p->posy + 60 * sin(p->dir - PI/4);
784+
checkx = p->posx + 60 * cos(p->dir - M_PI/4);
785+
checky = p->posy + 60 * sin(p->dir - M_PI/4);
786786
SDL_Rect g = {checkx, checky, 4, 4};
787787
SDL_FillRect(screen, &g, SDL_MapRGB(screen->format,
788788
0x66, 0x66, 0x66));
@@ -792,9 +792,9 @@ int logicGame(void)
792792
hitmap, WINDOW_W, WINDOW_H);
793793
if (activeTron) {
794794
if (c == 'l')
795-
p->dir -= PI / 2;
795+
p->dir -= M_PI / 2;
796796
else if (c == 'r')
797-
p->dir += PI / 2;
797+
p->dir += M_PI / 2;
798798
} else {
799799
if (c == 'l')
800800
p->dir -= 0.0022 * delta * p->speed;
@@ -806,10 +806,10 @@ int logicGame(void)
806806
/* Screw smooth angles, TRON MODE from here on! */
807807
if (keyDown[p->lkey]) {
808808
keyDown[p->lkey] = 0;
809-
p->dir -= PI / 2;
809+
p->dir -= M_PI / 2;
810810
} else if (keyDown[p->rkey]) {
811811
keyDown[p->rkey] = 0;
812-
p->dir += PI / 2;
812+
p->dir += M_PI / 2;
813813
}
814814
} else {
815815
if (keyDown[p->lkey])
@@ -895,7 +895,7 @@ void displayGameStart(void)
895895
struct player *p = &players[i];
896896
SDL_Rect offset = {(int)p->posx - 8, (int)p->posy - 8,
897897
0, 0};
898-
int diri = (int)((p->dir) * (32.0 / (2.0 * PI)));
898+
int diri = (int)((p->dir) * (32.0 / (2.0 * M_PI)));
899899
SDL_BlitSurface(p->arrow, &arrowClip[diri], screen,
900900
&offset);
901901
} else {
@@ -1172,9 +1172,9 @@ int wepSharpturn(struct player *p, bool on)
11721172
playSound(SOUND_SHARPTURN, sound);
11731173

11741174
if (keyDown[p->rkey])
1175-
p->dir += PI / 2;
1175+
p->dir += M_PI / 2;
11761176
else
1177-
p->dir -= PI / 2;
1177+
p->dir -= M_PI / 2;
11781178
}
11791179

11801180
p->inv_self = INV_TIME;
@@ -1249,11 +1249,11 @@ int wepMole(struct player *p, bool on)
12491249

12501250
p->posx = p->initposx;
12511251
p->posy = p->initposy;
1252-
p->dir = p->initdir + PI;
1252+
p->dir = p->initdir + M_PI;
12531253

12541254
p->initposx = oldposx;
12551255
p->initposy = oldposy;
1256-
p->initdir = olddir + PI;
1256+
p->initdir = olddir + M_PI;
12571257

12581258
p->inv_self= DURATION_MOLE;
12591259
p->inv_others = DURATION_MOLE;
@@ -1708,9 +1708,9 @@ void displayWepMenu(void)
17081708
if (p->weapon == i) {
17091709
int diri;
17101710
if (j >= MAX_PLAYERS / 2) {
1711-
diri = (int)((3.0 * PI / 2.0) * (32.0 / (2.0 * PI)));
1711+
diri = (int)((3.0 * M_PI / 2.0) * (32.0 / (2.0 * M_PI)));
17121712
} else {
1713-
diri = (int)((PI / 2.0) * (32.0 / (2.0 * PI)));
1713+
diri = (int)((M_PI / 2.0) * (32.0 / (2.0 * M_PI)));
17141714
}
17151715
SDL_BlitSurface(p->arrow, &arrowClip[diri], screen,
17161716
&offset);

0 commit comments

Comments
 (0)