about summary refs log tree commit diff stats
path: root/src/pause.c
blob: c3264ec895a0f5f567c97e78894cd9ec89909afc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "pong.h"
#include <raylib.h>

bool pause_screen(Camera2D *MainCamera) {
	bool PauseScreenGoing = true;
	
	/* Mouse */
	Rectangle Mouse = {
        	1280.0f/2, 720.0f/2, 10, 10
	};
	Vector2 OldPosition = GetMousePosition();
	Vector2 NewPosition = GetMousePosition();
	Texture2D MouseCursor = LoadTexture("resources/cursor.png");
	bool MouseCursorIn = false;
	EnableCursor();
	int Choice = 0;
	while(PauseScreenGoing == true && GameGoing == true) {
		/* Update Camera */
        MainCamera->zoom = GetScreenHeight()/720.0f;
		MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
		MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
		/* Mouse */
        if (MouseCursorIn == true) {
           		OldPosition = NewPosition;
           		NewPosition = GetMousePosition();
           		Mouse.y -= OldPosition.y-NewPosition.y;
           		Mouse.x -= OldPosition.x-NewPosition.x;
           		if (Mouse.y >= 720 || Mouse.y <= 0) {
               		Mouse.y += OldPosition.y-NewPosition.y;
           		}
           		if (Mouse.x >= 1280 || Mouse.x <= 0) {
               		Mouse.x += OldPosition.x-NewPosition.x;
           		}
        }

		if(IsKeyPressed(KEY_Y)) {
			return false;
		} else if(IsKeyPressed(KEY_N)) {
			return true;
		}
        
		if (IsKeyPressed(KEY_ESCAPE)) {
			EnableCursor();
			MouseCursorIn = false;
       	} else if (IsCursorOnScreen() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
			DisableCursor();
           	MouseCursorIn = true;
       	}
		if (player_controls() == CONTROLLER_LEFT) {
			Choice--;
		} else if (player_controls() == CONTROLLER_RIGHT) {
			Choice++;
		}

		if (Choice >= 2) {
			Choice = 1;
		} else if (Choice <= -1) {
			Choice = 0;
		}

		BeginDrawing();
			ClearBackground(BLACK);
			BeginMode2D(*MainCamera);
				DrawRectangle(0, 0, 1280, 720, (Color){20,20,20,255});
				if(CheckCollisionRecs(Mouse, (Rectangle){1280/3.0f, (720/3.0f)+50, 100, 50})) {
					Choice = 0;
				} else if(CheckCollisionRecs(Mouse, (Rectangle){(1280/3.0f)+150, (720/3.0f)+50, 70, 50})) {
					Choice = 1;
				}
				switch(Choice) {
					case 0:
						DrawRectangle((1280/3.0f)-5, (720/3.0f)+50, 104, 50, RED);
						break;
					default:
						DrawRectangle((1280/3.0f)+150,(720/3.0f)+50, 70, 50, RED);
						break;
				}
				if ( player_controls() == CONTROLLER_ACTIVATE ) {
					switch(Choice) {
						case 0:
							return false;
							break;
						default:
							return true;
							break;
					}
				}
				DrawText("Paused. Exit?", 1280/3, 720/3, 48, WHITE);
				DrawText("YES   NO", 1280/3, (720/3)+50, 48, WHITE);
				DrawTexture(MouseCursor, Mouse.x, Mouse.y, WHITE);
			EndMode2D();
		EndDrawing();
	}
	return true;
}