-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHexGrid.cpp
More file actions
99 lines (76 loc) · 1.72 KB
/
Copy pathHexGrid.cpp
File metadata and controls
99 lines (76 loc) · 1.72 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "HexGrid.hpp"
HexGrid::HexGrid() : defHeight(0),
defWidth(0),
defRadius(0),
defColor(0,0,0,0),
hexNumber(0),
yRow(1)
{}
HexGrid::HexGrid(int height, int width, float radius, sf::Color color){
defHeight = height;
defWidth = width;
defRadius = radius;
defColor = color;
hexNumber = width * height;
yRow = 1;
}
HexGrid::HexGrid(const HexGrid &grid){
defHeight = grid.getHeight();
defWidth = grid.getWidth();
defRadius = grid.getRadius();
defColor = grid.getColor();
hexNumber = defWidth * defHeight;
yRow = 1;
}
void HexGrid::draw(sf::RenderWindow &App){
hexagon.setRadius(defRadius);
hexagon.setPointCount(6);
hexagon.setFillColor(defColor);
hexagon.setOutlineThickness(1);
hexagon.setOutlineColor(sf::Color::Black);
xPos = hexagon.getRadius();
yPos = hexagon.getRadius();
for(int i = 1; i <= hexNumber; ++i){
hexagon.setPosition(xPos, yPos);
if( i % defWidth == 0 && i != 0 ){
if (yRow % 2 == 0){
xPos = hexagon.getRadius();
yPos += hexagon.getRadius() * 1.55;
}
else{
xPos = sqrt(3) * hexagon.getRadius() + ((hexagon.getRadius() / 10) + 1.3 );
yPos += hexagon.getRadius() * 1.55;
}
++yRow;
}
else
xPos += sqrt(3) * hexagon.getRadius() + 0.5;
App.draw(hexagon);
}
}
void HexGrid::setHeight(int height){
defHeight = height;
hexNumber = defHeight * defWidth;
}
int HexGrid::getHeight(){
return defHeight;
}
void HexGrid::setWidth(int width){
defWidth = width;
hexNumber = defHeight * defWidth;
}
int HexGrid::getWidth(){
return defWidth;
}
void HexGrid::setRadius(float radius){
defRadius = radius;
}
float HexGrid::getRadius(){
return defRadius;
}
void HexGrid::setColor(sf::Color color){
defColor = color;
}
sf::Color HexGrid::getColor(){
return defColor;
}