-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.cpp
More file actions
81 lines (73 loc) · 1.66 KB
/
Copy pathState.cpp
File metadata and controls
81 lines (73 loc) · 1.66 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 "State.h"
State::State(sf::RenderWindow* window, std::map<std::string, int>* supportedKeys, std::stack<State*>* states)
{
this->window = window;
this->supportedKeys = supportedKeys;
this->states = states;
this->quit = false;
this->pause = false;
this->keytime = 0.f;
this->keytimeMax = 10.f;
this->shaking = false;
this->temp = sf::seconds(0.f);
}
State::~State()
{
}
const bool& State::getQuit() const
{
return this->quit;
}
const bool State::getKeytime()
{
if (this->keytime >= this->keytimeMax) {
this->keytime = 0.f;
return true;
}
return false;
}
void State::endState()
{
this->quit = true;
}
void State::pauseState()
{
this->pause = true;
}
void State::unpauseState()
{
this->pause = false;
}
void State::shakeScreen()
{
srand(time(0));
if (this->temp == sf::seconds(0.f)) {
this->view = this->saveView = this->window->getView();
this->temp = this->clock.getElapsedTime();
cou = 0;
}
else if (this->clock.getElapsedTime() - this->temp >= sf::seconds(0.05f)) {
if(cou%2==0) this->view.move(sf::Vector2f( rand() % 10, rand() % 10));
else this->view = this->saveView;
this->temp = this->clock.getElapsedTime();
cou++;
}
if (cou>=4) {
this->view = this->saveView;
this->temp = sf::seconds(0.f);
this->shaking = false;
}
this->window->setView(this->view);
}
void State::UpdateMousePositions()
{
this->mousePosScreen = sf::Mouse::getPosition();
this->mousePosWindow = sf::Mouse::getPosition(*this->window);
this->mousePosView = this->window->mapPixelToCoords(sf::Mouse::getPosition(*this->window));
}
void State::UpdateKeytime(const float deltaTime)
{
if (this->keytime < keytimeMax) {
this->keytime += 50.f * deltaTime;
}
}