about summary refs log tree commit diff stats
path: root/src/enemy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/enemy.c')
-rw-r--r--src/enemy.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/enemy.c b/src/enemy.c
index 5a7e99b..dce2570 100644
--- a/src/enemy.c
+++ b/src/enemy.c
@@ -1,7 +1,8 @@
 #include "pong.h"
+#include <SDL2/SDL_atomic.h>
 
 void enemy(struct Players *Enemy, struct Balls ball) {
-	if (SDL_AtomicGet(&Ticks) % 1 == 0) {
+	if (Enemy->NextTick <= SDL_AtomicGet(&Ticks)) {
 		if (!CheckCollisionRecs(ball.HitBox, Enemy->BallDetector)) {
 			if (Enemy->Y+120 > ball.Y) {
 				Enemy->Direction = 0;
@@ -11,17 +12,17 @@ void enemy(struct Players *Enemy, struct Balls ball) {
 		} else {
 			Enemy->Direction = 3;
 		}
-	}
-
-	switch(Enemy->Direction) {
-		case 0:
-			Enemy->Y -= 15;
-			break;
-		case 1:
-			Enemy->Y += 15;
-			break;
-		default:
-			break;
+		switch(Enemy->Direction) {
+			case 0:
+				Enemy->Y -= 15;
+				break;
+			case 1:
+				Enemy->Y += 15;
+				break;
+			default:
+				break;
+		}
+		Enemy->NextTick = SDL_AtomicGet(&Ticks)+1;
 	}
 
 	// Prevents from going off screen.