about summary refs log tree commit diff stats
path: root/src/marathon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/marathon.c')
-rw-r--r--src/marathon.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/marathon.c b/src/marathon.c
new file mode 100644
index 0000000..b12b64a
--- /dev/null
+++ b/src/marathon.c
@@ -0,0 +1,89 @@
+#include "pong.h"
+#include "raylib.h"
+
+void marathon_main() {
+
+    // Init Music
+    Music Background = LoadMusicStream("resources/marathon.wav");
+    Background.looping = true;
+    PlayMusicStream(Background);
+
+    // Init balls lmao
+    struct Balls Ball;
+	Ball.X = 1280/2.0f;
+	Ball.Y = 720/2.0f;
+	Ball.Direction = LEFT;
+	Ball.Speed = 3.0f;
+	Ball.Angle = 0.0f;
+
+    // Init Player
+    struct Players Player;
+    Player.Y = 0;
+    Player.Direction = 0;
+    Player.Score = 0;
+
+    // Init sprites
+    Texture2D PaddleSprite = LoadTexture("resources/paddle.png");
+	Texture2D BallSprite = LoadTexture("resources/ball.png");
+
+    char PlayerScore[50]; // Used later to display score on screen.
+
+    // Set Collision Boxes
+	Player.HitBox = (Rectangle){80, Player.Y, 5, PaddleSprite.height};
+	Ball.HitBox = (Rectangle){Ball.X, Ball.Y, BallSprite.width, BallSprite.height};
+
+    // Init Camera
+    Camera2D MainCamera;
+        MainCamera.target = (Vector2){0, 0};
+        MainCamera.offset = (Vector2){0, 0};
+        MainCamera.rotation = 0;
+
+    while(!WindowShouldClose() && GameGoing == true) {
+        UpdateMusicStream(Background);
+        snprintf(PlayerScore, 50, "Player: %d", Player.Score);
+        MainCamera.zoom = GetScreenHeight()/720.0f;
+		MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+		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)) {
+			EnableCursor();
+		} else if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsCursorHidden() == true) {
+			Player.Y = GetMouseY()-PaddleSprite.height/2.0f;
+			DisableCursor();
+		}
+		
+		if(GetMouseY() < 0) {
+			SetMousePosition(0, 0);
+		} else if(GetMouseY() > 720) {
+			SetMousePosition(0, 720);
+		}
+
+		//Check if players are off-screen
+		if (Player.Y < 0) {
+			Player.Y = 0;
+		} else if (Player.Y > 480) {
+			Player.Y = 480;
+		}
+
+        // Collision
+        ball(&Player.HitBox, NULL, &Ball, &Player.Score, NULL);
+        //Updates hitbox with player's position.
+		Player.HitBox.y = Player.Y;
+
+        BeginDrawing();
+			ClearBackground(BLACK);
+			BeginMode2D(MainCamera);
+				DrawTexture(PaddleSprite, 0, Player.Y, WHITE);
+				DrawTexture(BallSprite, Ball.X, Ball.Y, WHITE);
+				DrawText(PlayerScore, 0, 0, 32, BLUE);
+			EndMode2D();
+		EndDrawing();
+    }
+    EnableCursor();
+    return;
+}