-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateGraphics.cpp
More file actions
51 lines (27 loc) · 1.55 KB
/
Copy pathupdateGraphics.cpp
File metadata and controls
51 lines (27 loc) · 1.55 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
#include "updateGraphics.h"
#include <unordered_map>
std::unordered_map<char, TDT4102::Color> charToColor =
{
{'R', TDT4102::Color::red}, {'A', TDT4102::Color::blue},
{'Y', TDT4102::Color::yellow}, {'B', TDT4102::Color::brown}
};
void updateGraphics(TDT4102::AnimationWindow& window, Map& map, Player& player){
window.draw_text({50, 50}, "WASD to move");
window.draw_text({50, 100}, "OP to turn");
std::vector<std::pair<int, char>> vec = getVisuals(player, map);
int rectangleWidth = window.width() / vec.size();
int remainder = window.width() % vec.size();
window.draw_rectangle({0,0}, window.width(), window.height()/ 2, TDT4102::Color::blue);
window.draw_rectangle({0, window.height()/ 2}, window.width(), window.height() / 2, TDT4102::Color::black);
for(int i = 0; i < remainder ; ++i){
std::pair<int, char> pair = vec.at(i);
TDT4102::Point upperLeft = {i * (rectangleWidth + 1), window.height() / 2 - int(pair.first)};
window.draw_rectangle(upperLeft, rectangleWidth + 1, int(pair.first)*2, charToColor.at(pair.second));
} //When the window width dont divide by rectangle number we make the first 1 pixel wider to fill the screen
for (int i = remainder; i < vec.size() ; ++i){
std::pair<int, char> pair = vec.at(i);
TDT4102::Point upperLeft = {i * rectangleWidth + remainder, window.height() / 2 - int(pair.first)};
window.draw_rectangle(upperLeft, rectangleWidth, int(pair.first)*2, charToColor.at(pair.second));
}
//Now update minimap in bootom right
}