-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square.cpp
57 lines (46 loc) · 1.68 KB
/
Square.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Square.h"
Square::Square(const sf::Vector2f position, const float size, const sf::Color color, const float borderWidth)
: position(position)
{
squareShape.setSize(sf::Vector2f(size, size));
squareShape.setFillColor(color);
squareShape.setPosition(position);
lineUp.setSize(sf::Vector2f(size, borderWidth));
lineUp.setFillColor(sf::Color::White);
lineUp.setPosition(position);
lineDown.setSize(sf::Vector2f(size, borderWidth));
lineDown.setFillColor(sf::Color::White);
lineDown.setPosition(sf::Vector2f(position.x, position.y + size - borderWidth));
lineLeft.setSize(sf::Vector2f(borderWidth, size));
lineLeft.setFillColor(sf::Color::White);
lineLeft.setPosition(position);
lineRight.setSize(sf::Vector2f(borderWidth, size));
lineRight.setFillColor(sf::Color::White);
lineRight.setPosition(sf::Vector2f(position.x + size - borderWidth, position.y));
}
void Square::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(squareShape, states);
target.draw(lineUp, states);
target.draw(lineDown, states);
target.draw(lineLeft, states);
target.draw(lineRight, states);
}
void Square::move(sf::Vector2f to)
{
squareShape.move(to);
lineRight.move(to);
lineLeft.move(to);
lineUp.move(to);
lineDown.move(to);
position = squareShape.getPosition();
}
void Square::SetPosition(sf::Vector2f newPosition)
{
squareShape.setPosition(newPosition);
lineRight.setPosition(newPosition);
lineLeft.setPosition(newPosition);
lineUp.setPosition(newPosition);
lineDown.setPosition(newPosition);
position = newPosition;
}