about summary refs log blame commit diff stats
path: root/src/pause.c
blob: c3264ec895a0f5f567c97e78894cd9ec89909afc (plain) (tree)
1
2
3
4
5
6
7
8





                                         
                   
                           







                                                                    
                                                              
                                   


                                                                                              
                           











                                                               






                                                
                                               






                                                                                   
                                 
                                                                   








                                          
                               
                                               
                                                 
                                                                                      
                                                                                                               
                                                   
                                                                                                                           
                                                   
                                 







                                                                                                          
                                                                                 








                                                                     







                                                                                    
#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;
}