-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithmRenderer.cpp
More file actions
68 lines (49 loc) · 1.64 KB
/
AlgorithmRenderer.cpp
File metadata and controls
68 lines (49 loc) · 1.64 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
#include "AlgorithmRenderer.hpp"
#include <array>
#include <list>
#include <SFML/Graphics.hpp>
#include "Utils.hpp"
#include "BaseAlgorithm.hpp"
const float sizeOfTileOnScreen = 100.;
const sf::Vector2f characterSize{50., 50.};
const sf::Color characterColor = sf::Color::White;
const sf::Vector2f pathMarkerSize{50., 20.};
const sf::Color pathMarkerColor = sf::Color::Blue;
sf::RectangleShape CreateRectangleFromGridPosAndSize(GridCoords gridPos, sf::Vector2f size, sf::Color color)
{
float offsetX = (sizeOfTileOnScreen - size.x) / 2.;
float offsetY = (sizeOfTileOnScreen - size.y) / 2.;
sf::Vector2f posTranslatedToScreen{
gridPos.x * sizeOfTileOnScreen + offsetX,
gridPos.y * sizeOfTileOnScreen + offsetY
};
sf::RectangleShape shape{size};
shape.setPosition(posTranslatedToScreen);
shape.setFillColor(color);
return shape;
}
void DrawCharacter(sf::RenderTarget& target, GridCoords position)
{
auto shape = CreateRectangleFromGridPosAndSize(position, characterSize, characterColor);
target.draw(shape);
}
void DrawPathMarker(sf::RenderTarget& target, GridCoords pos)
{
auto shape = CreateRectangleFromGridPosAndSize(pos, pathMarkerSize, pathMarkerColor);
target.draw(shape);
}
namespace NeutronicPathfinding
{
AlgorithmRenderer::AlgorithmRenderer(BaseAlgorithm* algo)
{
algorithm = algo;
}
AlgorithmRenderer::~AlgorithmRenderer()
{
}
void AlgorithmRenderer::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
GridCoords position = algorithm->position;
DrawCharacter(target, position);
}
}