forked from VivianMochi/Crescendo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlever.cpp
37 lines (28 loc) · 981 Bytes
/
lever.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
#include "lever.hpp"
#include "state.hpp"
Lever::Lever(State *state, sf::Vector2f position, bool facingRight) : state(state), position(position), facingRight(facingRight) {
sprite.setTexture(state->loadTexture("img/lever.png"));
sprite.setTextureRect(sf::IntRect(0, 0, 10, 10));
if (facingRight) {
sprite.setScale(-1, 1);
}
sprite.setPosition(position + (facingRight ? sf::Vector2f(8, -13) : sf::Vector2f(-2, -13)));
flipSound.setBuffer(state->loadSoundBuffer("snd/door.wav"));
}
Lever::~Lever() {
}
void Lever::flip() {
flipped = true;
sprite.setTextureRect(sf::IntRect(10, 0, 10, 10));
flipSound.play();
}
bool Lever::isFlipped() {
return flipped;
}
bool Lever::isOverlapping(sf::Vector2f position) {
sf::Vector2f center = this->position + sf::Vector2f(3, -5);
return std::abs(position.x - center.x) < 10 && std::abs(position.y - center.y) < 10;
}
void Lever::draw(sf::RenderTarget &target, sf::RenderStates states) const {
target.draw(sprite, states);
}