about summary refs log tree commit diff stats
path: root/src/ball.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ball.c')
-rw-r--r--src/ball.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/ball.c b/src/ball.c
index 35e0651..f49f775 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -1,4 +1,5 @@
 #include "pong.h"
+#include <SDL2/SDL_atomic.h>
 
 void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore) {
 	
@@ -8,16 +9,20 @@ void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerSc
 	}
 
 	// Moves ball
-	Ball->Y += Ball->Angle;
-	if (Ball->Direction == LEFT) {
-		Ball->X -= Ball->Speed;
-	} else {
-		Ball->X += Ball->Speed;
+	if(Ball->NextTick <= SDL_AtomicGet(&Ticks)){
+		Ball->Y += Ball->Angle;
+		if (Ball->Direction == LEFT) {
+			Ball->X -= Ball->Speed;
+		} else {
+			Ball->X += Ball->Speed;
+		}
+		// Moves hitbox with ball.
+		Ball->HitBox.x = Ball->X;
+		Ball->HitBox.y = Ball->Y;
+		Ball->NextTick = SDL_AtomicGet(&Ticks)+1;
+		printf("%d,%d\n", SDL_AtomicGet(&Ticks), Ball->NextTick);
 	}
-	// Moves hitbox with ball.
-	Ball->HitBox.x = Ball->X;
-	Ball->HitBox.y = Ball->Y;
-
+	printf("%d,%d\n", SDL_AtomicGet(&Ticks), Ball->NextTick);
 	// Check collisions against players.
 	if (CheckCollisionRecs(*Player, Ball->HitBox) && Ball->Direction == LEFT) {
 		Ball->Direction = RIGHT;