about summary refs log tree commit diff stats
path: root/src/ball.c
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-08 19:30:56 -0400
committerCharadon <dev@iotib.net>2022-06-08 19:30:56 -0400
commit21b272f633d8b55c2bf6c6afe24715eff0a4a207 (patch)
tree8c9b2b6a23dc389c94aa7c02a14fc65b353dd85e /src/ball.c
parent1aa1b17557dca5cc870caebcf20f2a24984460d7 (diff)
downloadPong-C-21b272f633d8b55c2bf6c6afe24715eff0a4a207.tar.gz
Begun work on seperating movement logic from framerate of game.
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;