This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PauseScreen.cpp
109 lines (83 loc) · 2.72 KB
/
PauseScreen.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// Created by joseph on 4/17/17.
//
#include <iostream>
#include "PauseScreen.h"
#include "Utils.h"
#include <unistd.h>
PauseScreen::PauseScreen() {
if (!classicFont.loadFromFile("Resources/menu/8bit.ttf"))
{
std::cerr << "Error loading 8bit.ttf" << std::endl;
}
continueLabel.setFont(classicFont);
continueLabel.setCharacterSize(40);
continueLabel.setString("Continue");
continueLabel.setPosition({ 280.f, 300.f });
exitLabel.setFont(classicFont);
exitLabel.setCharacterSize(40);
exitLabel.setString("Exit");
exitLabel.setPosition({ 280.f, 400.f });
}
int PauseScreen::run(sf::RenderWindow &window, sf::Texture &pauseScreen, Options* gameOptions) {
background.setColor(sf::Color(255,255,255,120));
background.setTexture(pauseScreen);
sf::Event event;
menu = 0;
while (running) {
while (window.pollEvent(event))
{
if (event.type == sf::Event::Resized)
window.setView(Utils::calcView(sf::Vector2u(event.size.width, event.size.height), Utils::designedsize));
// Window closed
if (event.type == sf::Event::Closed)
{
return (0);
}
//Key pressed
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code) {
case sf::Keyboard::Escape:
return 1;
case sf::Keyboard::Up:
menu--;
if (menu < 0)
menu = 0;
break;
case sf::Keyboard::Down:
menu++;
if (menu > 1)
menu = 1;
break;
case sf::Keyboard::Return:
if (menu == 0) {
//Let's get play !
return 1;
} else {
return 0;
}
default:
break;
}
}
}
if (menu == 0)
{
continueLabel.setColor(sf::Color(255, 0, 0, 255));
exitLabel.setColor(sf::Color(255, 255, 255, 255));
}
else if (menu == 1)
{
continueLabel.setColor(sf::Color(255, 255, 255, 255));
exitLabel.setColor(sf::Color(255, 0, 0, 255));
}
window.clear();
window.draw(background);
window.draw(continueLabel);
window.draw(exitLabel);
window.display();
}
//Never reaching this point normally, but just in case, exit the application
return (-1);
}