-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPauseScreen.cpp
More file actions
81 lines (74 loc) · 2.96 KB
/
Copy pathPauseScreen.cpp
File metadata and controls
81 lines (74 loc) · 2.96 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
73
74
75
76
77
78
79
80
81
#include <SFML/Graphics.hpp>
#include "PauseScreen.h"
#include "MenuScreen.h"
using namespace sfSnake;
PauseScreen::PauseScreen()
{
continue_texture_.loadFromFile("Image/Launch.png");
home_texture_.loadFromFile("Image/Home.png");
retry_texture_.loadFromFile("Image/Retry.png");
continue_button_ = Button(continue_texture_, Game::Width * 2 / 7, Game::Height * 4 / 7);
home_button_ = Button(home_texture_, Game::Width * 3.5 / 7, Game::Height * 4 / 7);
retry_button_ = Button(retry_texture_, Game::Width * 5 / 7, Game::Height * 4 / 7);
// text initial
font_.loadFromFile("Fonts/HYHuaMuLanW.ttf");
text_.setFont(font_);
text_.setString(L"暂 停");
text_.setScale(6, 6);
text_.setFillColor(sf::Color::White);
text_.setOutlineColor(sf::Color::Black);
text_.setOutlineThickness(2);
text_.setPosition(Game::Width / 2 - text_.getGlobalBounds().width / 2, Game::Height / 7);
}
void PauseScreen::handleInput(sf::RenderWindow &window)
{
// Highlight
if (continue_button_.getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
continue_button_.Highlight();
else
continue_button_.deHighlight();
if (home_button_.getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
home_button_.Highlight();
else
home_button_.deHighlight();
if (retry_button_.getBound().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
retry_button_.Highlight();
else
retry_button_.deHighlight();
// Pressed
if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && continue_button_.getBound().contains(
sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
{
Game::Screen_ = Game::Paused_Screen;
Game::Paused_Screen = nullptr;
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && home_button_.getBound().contains(
sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
{
Game::Screen_ = std::make_shared<MenuScreen>();
Game::Paused_Screen = nullptr;
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && retry_button_.getBound().contains(
sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y))
{
Game::Screen_ = std::make_shared<GameScreen>();
Game::Paused_Screen = nullptr;
}
}
void PauseScreen::update(sf::Time delta)
{
}
void PauseScreen::render(sf::RenderWindow &window)
{
if (Game::Paused_Screen)
Game::Paused_Screen->render(window);
else
{
Game::Screen_->render(window);
return;
}
window.draw(text_);
continue_button_.render(window);
home_button_.render(window);
retry_button_.render(window);
}