-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.cpp
99 lines (86 loc) · 1.96 KB
/
Cell.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include <vector>
#include <SFML/Graphics.hpp>
#include <vector>
#include "Border.cpp"
#include "structs.hpp"
namespace HexLab
{
class Cell : public sf::Drawable, public sf::Transformable
{
public:
Point2 position; //middle
std::vector<HexLab::Border> borders;
sf::CircleShape CellBase;
double size;
bool exists = false;
void move(sf::Vector2f vec)
{
for (int i = 0; i < 6; i++)
{
this->borders[i].border.move(vec);
}
this->CellBase.move(vec);
}
Cell(double x = 1, double y = 1, double size = 1)
{
setPos(x, y);
setSize(size);
InitBorders();
//this->CellBase = sf::CircleShape(size, 6);
//this->CellBase.setFillColor(sf::Color::Cyan);
}
void Init(double x, double y, double size = 1)
{
setPos(x, y);
this->size = size;
InitBorders();
}
void setPos(Point2 pos)
{
this->position = pos;
}
void setPos(double x, double y)
{
Point2 point;
point.setCoords(x, y);
CellBase.setPosition(x, y);
this->position = point;
}
void setSize(double arg)
{
this->size = arg;
}
void InitBorders()
{
borders.resize(6);
for (int i = 0; i < 6; i++)
{
borders[i].Init(i, this->size, undefined, this->position);
}
}
void draw(sf::RenderTarget& target, sf::RenderStates states = sf::RenderStates::Default) const
{
for (int i{}; i < 6; i++)
{
if (this->borders[i].state == closed)
{
sf::RectangleShape line = borders[i].border;
line.setFillColor(sf::Color::White);
target.draw(line);
}
}
target.draw(CellBase);
}
void InitBase(double size = 1)
{
this->CellBase = sf::CircleShape(size, 6);
this->CellBase.setFillColor(sf::Color::Cyan);
this->CellBase.rotate(30);
this->CellBase.setOrigin(this->position.x - 1.5 * size, this->position.y - 0.8660254037844 * size);
//this->CellBase.setPosition(this->position.x, this->position.y);
}
};
//0.8660254037844
//1.7320508075689
}