about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-09-11 12:43:58 -0400
committerCharadon <dev@iotib.net>2022-09-11 12:43:58 -0400
commit206d9bf191a8ac90ebeb47273a25c0daac410774 (patch)
tree7b2e352d3a85f28d0f48c96eaadf8535cb1e65d6
parent6606602f5a55deccfb92adef580cc8ff3112afe4 (diff)
downloadPong-C-206d9bf191a8ac90ebeb47273a25c0daac410774.tar.gz
Made marathon use new controls function.
-rw-r--r--src/marathon.c67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/marathon.c b/src/marathon.c
index 2140b08..d7da799 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -1,4 +1,5 @@
 #include "pong.h"
+#include <raylib.h>
 
 void leaderboard_record(int Score) {
     bool LeaderBoardGoing = true;
@@ -111,6 +112,7 @@ void marathon_main() {
         MainCamera.rotation = 0;
     bool MarathonGoing = true;
 	bool HasScored = false;
+	Vector2 MouseCurrentPosition = GetMousePosition();
     while(MarathonGoing == true && GameGoing == true) {
         if (WindowShouldClose()) { /* Quit Game if the window is closed. */
             GameGoing = false;
@@ -129,27 +131,36 @@ void marathon_main() {
 	    MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
 
        	/* Controls */
-        if(IsKeyDown(KEY_UP)) {
-            Player.Y -= 10;
-        } else if (IsKeyDown(KEY_DOWN)) {
-            Player.Y += 10;
-        } else if(IsKeyPressed(KEY_ESCAPE)) {
-			Mix_PauseMusic();
-			BeginDrawing();
-			EndDrawing();
-			MarathonGoing = pause_screen(&MainCamera);
-			Mix_ResumeMusic();
-			Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
-        } else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
-            Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
-            DisableCursor();
-        }
+		switch(player_controls()) {
+			case CONTROLLER_UP:
+				Player.Y -= 20;
+				break;
+			case CONTROLLER_DOWN:
+				Player.Y += 20;
+				break;
+			case CONTROLLER_PAUSE:
+				Mix_PauseMusic();
+				BeginDrawing();
+				EndDrawing();
+				MarathonGoing = pause_screen(&MainCamera);
+				Mix_ResumeMusic();
+				Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
+				break;
+			default:
+				break;
+		}
+
+		/* Mouse Controls */
+		if(MouseCurrentPosition.y != GetMousePosition().y) {
+           	Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
         
-        if(GetMouseY() < 0) {
-            SetMousePosition(0, 0);
-        } else if(GetMouseY() > 720) {
-            SetMousePosition(0, 720);
-        }
+        	if(GetMouseY() < 0) {
+            	SetMousePosition(0, 0);
+        	} else if(GetMouseY() > 720) {
+            	SetMousePosition(0, 720);
+        	}
+			MouseCurrentPosition = GetMousePosition();
+		}
 
         /* Check if players are off-screen */
         if (Player.Y < 0) {
@@ -169,14 +180,14 @@ void marathon_main() {
         }
 
         BeginDrawing();
-		ClearBackground(BLACK);
-		BeginMode2D(MainCamera);
-            DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-			DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
-			DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
-			DrawText(PlayerScore, 0, 0, 32, BLUE);
-		EndMode2D();
-	EndDrawing();
+			ClearBackground(BLACK);
+			BeginMode2D(MainCamera);
+            	DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+				DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
+				DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
+				DrawText(PlayerScore, 0, 0, 32, BLUE);
+			EndMode2D();
+		EndDrawing();
     }
     Mix_HaltMusic();
 	if (Player.Score > 0) {