From: Armaan Bhojwani Date: Sat, 15 May 2021 22:37:24 +0000 (-0400) Subject: Randomize direction of index X-Git-Url: https://git.armaanb.net/?p=pong.git;a=commitdiff_plain;h=94ec7464b5639e49cd93ee1a7a6787526f0263bd Randomize direction of index --- diff --git a/Makefile b/Makefile index a234c45..d07d5ec 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: ${CC} -o pong pong.c ${CLAGS} -Wall -Wextra -std=c99 -pedantic \ - -lcurses ${LDFLAGS} + -lcurses -lm ${LDFLAGS} scdoc < pong.1.scd > pong.1 install: all diff --git a/pong.c b/pong.c index 717b1ae..1363ae5 100644 --- a/pong.c +++ b/pong.c @@ -4,6 +4,7 @@ #include #include #include +#include int die(int code) @@ -20,6 +21,12 @@ randslope(void) return (rand() % (high - low + 1)) + low; } +int +randsign(void) +{ + return pow(-1, rand()); +} + int main(void) { srand((unsigned int)time(NULL)); @@ -29,7 +36,7 @@ main(void) { int pad_h = 5; int a_score = 0, b_score = 0; int slope_x = randslope(); - int index_dir = 1; + int index_dir = randsign(); int direction = 1; double speed = 0.02; struct timeval start, stop; @@ -126,6 +133,7 @@ main(void) { x = max_x/2; index = slope_x*max_y/2; slope_x = randslope(); + index_dir = randsign(); speed = 0.02; sleep(1); } else if (y == 0 || y == max_y) {