-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarrier.cpp
More file actions
58 lines (46 loc) · 1.27 KB
/
Copy pathbarrier.cpp
File metadata and controls
58 lines (46 loc) · 1.27 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
#include "barrier.h"
#include <SFML/Graphics.hpp>
#include <iostream>
#include "common.h"
Barrier::Barrier(int x, int y)
:hits(3)
,height(CELL/2)
,width(CELL) {
sf::Color colour(5, 161, 46);
rectangle.setSize(sf::Vector2f(width, height));
rectangle.setPosition(x,y);
rectangle.setFillColor(sf::Color::Transparent);
rectangle1.setSize(sf::Vector2f(width, height - height/3));
rectangle1.setPosition(x,y);
rectangle1.setFillColor(colour);
rectangle2.setSize(sf::Vector2f(width/4, height));
rectangle2.setPosition(x,y);
rectangle2.setFillColor(colour);
rectangle3.setSize(sf::Vector2f(width/4, height));
rectangle3.setPosition(x + width*3/4,y);
rectangle3.setFillColor(colour);
}
Barrier::~Barrier() {
}
void Barrier::Update() {
}
void Barrier::Draw(sf::RenderWindow& window) {
window.draw(rectangle);
window.draw(rectangle1);
window.draw(rectangle2);
window.draw(rectangle3);
}
bool Barrier::Hit(int x, int y) const {
int bx = rectangle.getPosition().x;
int by = rectangle.getPosition().y;
if (bx <= x && bx + width >= x && by <= y && by + height >= y) {
return true;
}
return false;
}
int Barrier::GetHits() const {
return hits;
}
void Barrier::Damage() {
hits = hits - 1;
}