-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.cpp
52 lines (48 loc) · 1.95 KB
/
MainMenu.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
#include "MainMenu.h"
#include "Button.h"
#include "ResourceManager.h"
#include "GameScreen.h"
#include <math.h>
MainMenu::MainMenu() {
playButton = Button(325,400,150,50,sf::Color(97,56,11),"New");
loadButton = Button(325,280,150,50,sf::Color(97,56,11),"Load");
title = sf::Text();
title.setString("Splunk");
title.setCharacterSize(50);
title.setFont(ResourceManager::PixelFont);
}
int MainMenu::open(sf::RenderWindow* window) {
int anim = 0;
bool load = false;
sf::RectangleShape fadeOverlay = sf::RectangleShape(sf::Vector2f(800,500));
fadeOverlay.setFillColor(sf::Color(0,0,0,0));
window->setView(window->getDefaultView());
while (window->isOpen()) {
sf::Event event;
while(window->pollEvent(event)) {
if(event.type == sf::Event::Closed) window->close();
if(event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Escape) window->close();
}
if(event.type == sf::Event::MouseButtonPressed) {
if(playButton.pointOnBox(event.mouseButton.x, event.mouseButton.y)) anim = 121;
if(loadButton.pointOnBox(event.mouseButton.x, event.mouseButton.y)) load = true, anim = 121;
}
if(event.type == sf::Event::Resized) window->setView(sf::View(sf::Vector2f(window->getSize().x/2,window->getSize().y/2), sf::Vector2f(window->getSize())));
}
if(anim < 120) title.setPosition(5,pow((float)(anim - 120),3)/-1728), anim++;
if(anim == 120) title.setPosition(5,0);
if(anim >= 121) fadeOverlay.setFillColor(sf::Color(0,0,0,255*(anim-120)/60)), anim++;
if(anim == 180) {
GameScreen(load).open(window);
anim = 120;
}
window->clear(sf::Color(0,0,0,255));
window->draw(playButton);
window->draw(loadButton);
window->draw(title);
window->draw(fadeOverlay);
window->display();
}
return 0;
}