about summary refs log tree commit diff stats
path: root/src/versus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/versus.c')
-rw-r--r--src/versus.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/versus.c b/src/versus.c
index fa92fe5..6f4e3d2 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -1,8 +1,9 @@
-#include "pong.h"
 #include <raylib.h>
 
+#include "pong.h"
+
 void versus_main() {
-    /* Init Player Variables */
+	/* Init Player Variables */
 	struct Players Player;
 	Player.Y = 0;
 	Player.Score = 0;
@@ -13,10 +14,10 @@ void versus_main() {
 	Enemy.Score = 0;
 	Enemy.Direction = 0;
 
-    /* Init Ball Variables */
+	/* Init Ball Variables */
 	struct Balls Ball;
-	Ball.X = 1280/2.0f;
-	Ball.Y = 720/2.0f;
+	Ball.X = 1280 / 2.0f;
+	Ball.Y = 720 / 2.0f;
 	Ball.Direction = LEFT;
 	Ball.Speed = 3.0f;
 	Ball.Angle = 0.0f;
@@ -25,8 +26,8 @@ void versus_main() {
 	Mix_Music *Background = Mix_LoadMUS("resources/versus.wav");
 	Mix_PlayMusic(Background, -1);
 	Mix_VolumeMusic(GlobalSettings.MusicVolume);
-    
-    /* Set Sprites */
+
+	/* Set Sprites */
 	Texture2D PaddleSprite = LoadTexture("resources/paddle.png");
 	Texture2D BallSprite = LoadTexture("resources/ball.png");
 
@@ -34,14 +35,14 @@ void versus_main() {
 	Player.HitBox = (Rectangle){80, Player.Y, 5, PaddleSprite.height};
 	Enemy.HitBox = (Rectangle){1200, Enemy.Y, 5, PaddleSprite.height};
 	Ball.HitBox = (Rectangle){Ball.X, Ball.Y, BallSprite.width, BallSprite.height};
-	Enemy.BallDetector = (Rectangle){0, Enemy.Y+120, 1280, PaddleSprite.height/5.0f};
-    char EnemyScore[50];
-    char PlayerScore[50]; /* Used later to display score on screen. */
-    /* Init Camera */
-    Camera2D MainCamera;
-    MainCamera.target = (Vector2){0, 0};
-    MainCamera.offset = (Vector2){0, 0};
-    MainCamera.rotation = 0;
+	Enemy.BallDetector = (Rectangle){0, Enemy.Y + 120, 1280, PaddleSprite.height / 5.0f};
+	char EnemyScore[50];
+	char PlayerScore[50]; /* Used later to display score on screen. */
+	/* Init Camera */
+	Camera2D MainCamera;
+	MainCamera.target = (Vector2){0, 0};
+	MainCamera.offset = (Vector2){0, 0};
+	MainCamera.rotation = 0;
 
 	bool VersusGoing = true;
 	Ball.NextTick = SDL_AtomicGet(&Ticks);
@@ -51,14 +52,13 @@ void versus_main() {
 	Vector2 MouseCurrentPosition = GetMousePosition();
 	bool MouseMoved = false;
 
-    while(VersusGoing == true && GameGoing == true) {
-		
+	while (VersusGoing == true && GameGoing == true) {
 		if (WindowShouldClose()) { /* Quit Game if the window is closed. */
-            GameGoing = false;
-        }
-		MainCamera.zoom = GetScreenHeight()/720.0f;
-		MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-		MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
+			GameGoing = false;
+		}
+		MainCamera.zoom = GetScreenHeight() / 720.0f;
+		MainCamera.offset = (Vector2){GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f};
+		MainCamera.target = (Vector2){1280 / 2.0f, 720 / 2.0f};
 
 		/* Who won? */
 		if (Enemy.Score >= 5) {
@@ -66,13 +66,13 @@ void versus_main() {
 			Mix_FreeMusic(Background);
 			play_audio(STOP_ALL_SOUNDS);
 			play_audio(MUSIC_DEFEAT);
-			while(!IsKeyDown(KEY_SPACE)) {
+			while (!IsKeyDown(KEY_SPACE)) {
 				BeginDrawing();
-					EnableCursor();
-					ClearBackground(BLACK);
-					DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-					DrawText("You Lose.", 0, 0, 128, RED);
-					DrawText("Press space to return to title screen.", 0, 128, 24, WHITE);
+				EnableCursor();
+				ClearBackground(BLACK);
+				DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+				DrawText("You Lose.", 0, 0, 128, RED);
+				DrawText("Press space to return to title screen.", 0, 128, 24, WHITE);
 				EndDrawing();
 			}
 			return;
@@ -81,13 +81,13 @@ void versus_main() {
 			Mix_FreeMusic(Background);
 			play_audio(STOP_ALL_SOUNDS);
 			play_audio(MUSIC_VICTORY);
-			while(!IsKeyDown(KEY_SPACE)) {
+			while (!IsKeyDown(KEY_SPACE)) {
 				BeginDrawing();
-					EnableCursor();
-					ClearBackground(BLACK);
-					DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-					DrawText("You Win!", 0, 0, 128, BLUE);
-					DrawText("Press space to return to title screen.", 0, 128, 24, WHITE);
+				EnableCursor();
+				ClearBackground(BLACK);
+				DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+				DrawText("You Win!", 0, 0, 128, BLUE);
+				DrawText("Press space to return to title screen.", 0, 128, 24, WHITE);
 				EndDrawing();
 			}
 			return;
@@ -100,26 +100,26 @@ void versus_main() {
 			MouseMoved = true;
 		}
 		MouseLastPosition = MouseCurrentPosition;
-		if( player_controls() == CONTROLLER_UP ){
+		if (player_controls() == CONTROLLER_UP) {
 			Player.Y -= 20;
-		} else if ( player_controls() == CONTROLLER_DOWN ){
+		} else if (player_controls() == CONTROLLER_DOWN) {
 			Player.Y += 20;
-		} else if ( player_controls() == CONTROLLER_PAUSE ){
-				Mix_PauseMusic();
-				BeginDrawing();
-				EndDrawing();
-				VersusGoing = pause_screen(&MainCamera);
-				Mix_ResumeMusic();
-				Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
-				Enemy.NextTick = SDL_AtomicGet(&Ticks)+1;
+		} else if (player_controls() == CONTROLLER_PAUSE) {
+			Mix_PauseMusic();
+			BeginDrawing();
+			EndDrawing();
+			VersusGoing = pause_screen(&MainCamera);
+			Mix_ResumeMusic();
+			Ball.NextTick = SDL_AtomicGet(&Ticks) + 1;
+			Enemy.NextTick = SDL_AtomicGet(&Ticks) + 1;
 		} else if (MouseMoved == true) {
-			Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
+			Player.Y = GetMouseY() - PaddleSprite.height / 2.0f;
 			DisableCursor();
 		}
-		
-		if(GetMouseY() < 0) {
+
+		if (GetMouseY() < 0) {
 			SetMousePosition(0, 0);
-		} else if(GetMouseY() > 720) {
+		} else if (GetMouseY() > 720) {
 			SetMousePosition(0, 720);
 		}
 
@@ -131,7 +131,7 @@ void versus_main() {
 		}
 
 		enemy(&Enemy, Ball);
-		
+
 		/* Collision */
 		ball(&Player.HitBox, &Enemy.HitBox, &Ball, &Player.Score, &Enemy.Score);
 
@@ -142,20 +142,20 @@ void versus_main() {
 		snprintf(PlayerScore, 50, "Player: %d", Player.Score);
 		snprintf(EnemyScore, 50, "Enemy: %d", Enemy.Score);
 		BeginDrawing();
-			ClearBackground(BLACK);
-			BeginMode2D(MainCamera);
-				DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-				DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
-				DrawTexture(PaddleSprite, 1200, Enemy.Y, WHITE);
-				DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
-				DrawText(PlayerScore, 0, 0, 32, BLUE);
-				DrawText(EnemyScore, 1130, 688, 32, RED);
-			EndMode2D();
+		ClearBackground(BLACK);
+		BeginMode2D(MainCamera);
+		DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+		DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
+		DrawTexture(PaddleSprite, 1200, Enemy.Y, WHITE);
+		DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
+		DrawText(PlayerScore, 0, 0, 32, BLUE);
+		DrawText(EnemyScore, 1130, 688, 32, RED);
+		EndMode2D();
 		EndDrawing();
 	}
 
 	Mix_HaltMusic();
 	Mix_FreeMusic(Background);
 	play_audio(STOP_ALL_SOUNDS);
-    return;
+	return;
 }