-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameMode.h
114 lines (99 loc) · 4.08 KB
/
GameMode.h
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
110
111
112
113
114
//
// GameMode.h
// jscreens
#ifndef GameMode_h
#define GameMode_h
#include <iostream>
#include "cScreen.h"
#include "FileOpenException.h"
#include <SFML/Graphics.hpp>
class GameMode : public cScreen
{
public:
GameMode(void) { }
virtual int Run(sf::RenderWindow &App, const int SCREENWIDTH, const int SCREENHEIGHT);
};
int GameMode::Run(sf::RenderWindow &App, const int SCREENWIDTH, const int SCREENHEIGHT)
{
bool Running = true;
// Setup font
sf::Font font;
try { // throws error if file not opened
if(!font.loadFromFile(FONTIMAGE))
{
throw FileOpenException(FONTIMAGE);
}
}
catch(exception& e)
{
cout << "Cannot open: " << e.what() << endl;
exit(-1);
}
//how to play button
sf::Text regMode("Regular Mode", font);
regMode.setCharacterSize(60);
regMode.setFillColor(sf::Color::White);
sf::FloatRect regButtonRect = regMode.getLocalBounds();
regMode.setOrigin(regButtonRect.left + regButtonRect.width / 2.0f, regButtonRect.top + regButtonRect.height / 2.0f);
regMode.setPosition(sf::Vector2f(SCREENWIDTH / 2.0f, (2*SCREENHEIGHT / 7.0f)));
//play button
sf::Text pButton("Test Mode", font);
pButton.setCharacterSize(60);
pButton.setFillColor(sf::Color::White);
sf::FloatRect pButtonRect = pButton.getLocalBounds();
pButton.setOrigin(pButtonRect.left + pButtonRect.width / 2.0f, pButtonRect.top + pButtonRect.height / 2.0f);
pButton.setPosition(sf::Vector2f(SCREENWIDTH / 2.0f, (4*SCREENHEIGHT / 7.0f)));
//high score screen button
sf::Text mButton("Menu", font);
mButton.setCharacterSize(50);
mButton.setFillColor(sf::Color::White);
sf::FloatRect mButtonRect = mButton.getLocalBounds();
mButton.setOrigin(mButtonRect.left + mButtonRect.width / 2.0f, mButtonRect.top + mButtonRect.height / 2.0f);
mButton.setPosition(sf::Vector2f(SCREENWIDTH / 2.0f, (6*SCREENHEIGHT / 7.0f)));
// Center text
sf::Event event;
while (Running)
{
// Verifying events
while (App.pollEvent(event))
{
// Window closed
if (event.type == sf::Event::EventType::Closed)
return (-1);
// Key pressed
if (event.type == sf::Event::MouseButtonPressed)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
std::cout << "in";
sf::Vector2i position = sf::Mouse::getPosition(App);
std::cout << position.x << " " << position.y << std::endl;
//how to play button
if((position.x > (regMode.getPosition().x-(regButtonRect.width/2)) && position.x < (regMode.getPosition().x+(regButtonRect.width/2)) && (position.y > (regMode.getPosition().y-(regButtonRect.height/2)) && position.y < (regMode.getPosition().y + (regButtonRect.height/2)))))
{
return (3);
}
//play button
if((position.x > (pButton.getPosition().x-(pButtonRect.width/2)) && position.x < (pButton.getPosition().x+(pButtonRect.width/2)) && (position.y > (pButton.getPosition().y-(pButtonRect.height/2)) && position.y < (pButton.getPosition().y + (pButtonRect.height/2)))))
{
testmode = true;
return (3);
}
//menu button
if((position.x > (mButton.getPosition().x-(mButtonRect.width/2)) && position.x < (mButton.getPosition().x+(mButtonRect.width/2)) && (position.y > (mButton.getPosition().y-(mButtonRect.height/2)) && position.y < (mButton.getPosition().y + (mButtonRect.height/2)))))
{
return (7);
}
}
}
}
App.clear();
App.draw(mButton);
App.draw(pButton);
App.draw(regMode);
App.display();
}
// Never reach this point normally, but just in case, exit the application
return (-1);
}
#endif /* Menu_h */