about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/ball.c23
-rw-r--r--src/enemy.c25
-rw-r--r--src/main.c17
-rw-r--r--src/pong.h2
-rw-r--r--src/versus.c8
5 files changed, 46 insertions, 29 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;
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.
diff --git a/src/main.c b/src/main.c
index e2e6308..efd6dd5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,4 @@
 #include "pong.h"
-#include <SDL2/SDL_atomic.h>
 #include <raylib.h>
 
 int Difficulty = 1;
@@ -15,10 +14,14 @@ SDL_atomic_t AudioInitializing;
 int AudioQueue[20];
 
 void set_screen_mode() {
+	ClearWindowState(FLAG_VSYNC_HINT);
+	ClearWindowState(FLAG_WINDOW_TOPMOST);
+	ClearWindowState(FLAG_WINDOW_UNDECORATED);
+	ClearWindowState(FLAG_FULLSCREEN_MODE);
 	switch(GlobalSettings.Fullscreen) {
 		case 1: //Real Fullscreen is fickle as fuck. So it needs a timeout.
 			SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
-			int Timeout = SDL_AtomicGet(&Ticks)+100;
+			int Timeout = SDL_AtomicGet(&Ticks)+300; //Set the timeout for 5 seconds.
 			while(GetScreenHeight() != GetMonitorHeight(GetCurrentMonitor())) {
 				BeginDrawing();
 				EndDrawing();
@@ -26,6 +29,7 @@ void set_screen_mode() {
 					goto FullScreenFailed;
 				}
 			}
+			SetWindowState(FLAG_VSYNC_HINT);
 			SetWindowState(FLAG_FULLSCREEN_MODE);
 			break;
 		case 2:
@@ -36,9 +40,6 @@ void set_screen_mode() {
 			break;
 		default:
 			FullScreenFailed:
-			ClearWindowState(FLAG_WINDOW_TOPMOST);
-			ClearWindowState(FLAG_WINDOW_UNDECORATED);
-			ClearWindowState(FLAG_FULLSCREEN_MODE);
 			SetWindowSize(1280, 720);
 			SetWindowPosition(GetMonitorHeight(GetCurrentMonitor())/5, GetMonitorHeight(GetCurrentMonitor())/5);
 			break;
@@ -46,9 +47,9 @@ void set_screen_mode() {
 	return;
 }
 
-int internal_clock() {
+static int internal_clock() {
 	const struct timespec Delay = {
-		0, 20000000
+		0, 16666666
 	};
 	struct timespec Remaining;
 	while(GameGoing == true) {
@@ -58,7 +59,7 @@ int internal_clock() {
 	return(0);
 }
 
-int audio() {
+static int audio() {
 	int i;
 	Mix_Init(0);
 	Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024);
diff --git a/src/pong.h b/src/pong.h
index 99e58e3..f286406 100644
--- a/src/pong.h
+++ b/src/pong.h
@@ -28,6 +28,7 @@ struct Players {
 	int Score;
 	int Direction;
 	Rectangle BallDetector;
+	int NextTick;
 };
 
 struct Balls {
@@ -37,6 +38,7 @@ struct Balls {
 	float Speed;
 	int Direction;
 	Rectangle HitBox;
+	int NextTick;
 };
 
 struct Settings {
diff --git a/src/versus.c b/src/versus.c
index 71e3689..ad0d27e 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -1,4 +1,9 @@
 #include "pong.h"
+#include <raylib.h>
+
+static void game_thread() {
+	
+}
 
 void versus_main() {
     // Init Player Variables
@@ -42,6 +47,8 @@ void versus_main() {
         MainCamera.offset = (Vector2){0, 0};
         MainCamera.rotation = 0;
 	bool VersusGoing = true;
+	Ball.NextTick = 0;
+	Enemy.NextTick = 0;
     while(VersusGoing == true && GameGoing == true) {
 		
 		if (WindowShouldClose()) { //Quit Game if the window is closed.
@@ -127,6 +134,7 @@ void versus_main() {
 		
 		BeginDrawing();
 			ClearBackground(BLACK);
+			DrawFPS(100, 100);
 			BeginMode2D(MainCamera);
 				DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
 				DrawTexture(PaddleSprite, 0, Player.Y, WHITE);