X-Git-Url: https://git.armaanb.net/?p=pong.git;a=blobdiff_plain;f=pong.c;fp=pong.c;h=1363ae59531c37b8c90f9b1fe24ff9c4a373ab08;hp=717b1ae919752eb237e2bf451d34a8b1d646fed6;hb=94ec7464b5639e49cd93ee1a7a6787526f0263bd;hpb=65ba1edac573cbc321bb4a22068becf1f1bd9b67 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) {