-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuScreen.cpp
More file actions
72 lines (62 loc) · 2.28 KB
/
Copy pathMenuScreen.cpp
File metadata and controls
72 lines (62 loc) · 2.28 KB
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
#include <SFML/Graphics.hpp>
#include <memory>
#include "GameScreen.h"
#include "MenuScreen.h"
#include "HelpScreen.h"
#include "OptionScreen.h"
#include "Game.h"
using namespace sfSnake;
MenuScreen::MenuScreen()
{
// Head Title : Welcome! Initialize
Title_Texture_.loadFromFile("Image/Welcome.png");
Title_.setTexture(Title_Texture_);
Title_.setScale(3, 3);
Title_.setOrigin(Title_Texture_.getSize().x / 2, Title_Texture_.getSize().y / 2);
Title_.setPosition(Game::Width / 2, Game::Height / 5);
// Button Initialize
texture_[0].loadFromFile("Image/settings.png");
texture_[1].loadFromFile("Image/launch.png");
texture_[2].loadFromFile("Image/helps.png");
buttons_[0] = Button(texture_[0], Game::Width * 2 / 6, Game::Height * 3 / 5);
buttons_[1] = Button(texture_[1], Game::Width * 3 / 6, Game::Height * 3 / 5);
buttons_[2] = Button(texture_[2], Game::Width * 4 / 6, Game::Height * 3 / 5);
// Grid Initialize
}
void MenuScreen::handleInput(sf::RenderWindow &window)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (buttons_[0].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
Game::Screen_ = std::make_shared<OptionScreen>();
else if (buttons_[1].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
Game::Screen_ = std::make_shared<GameScreen>();
else if (buttons_[2].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
Game::Screen_ = std::make_shared<HelpScreen>();
}
if (buttons_[0].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
buttons_[0].Highlight();
else
buttons_[0].deHighlight();
if (buttons_[1].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
buttons_[1].Highlight();
else
buttons_[1].deHighlight();
if (buttons_[2].getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
buttons_[2].Highlight();
else
buttons_[2].deHighlight();
}
void MenuScreen::update(sf::Time delta)
{
}
void MenuScreen::render(sf::RenderWindow &window)
{
if (Game::isGridVisible)
grid_.render(window);
window.draw(Title_);
for (auto &button : buttons_)
button.render(window);
}