-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisuals.cpp
More file actions
66 lines (43 loc) · 1.73 KB
/
Copy pathvisuals.cpp
File metadata and controls
66 lines (43 loc) · 1.73 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
#include "visuals.h"
#include "cmath"
#include <numbers>
//Objekters opplevde høyde er inversproporsjonal med avstand
int distanceToHeight(double dx, double dy){
double dist = std::sqrt(dx*dx + dy*dy);
return int (WINDOW_HEIGHT * 3 / dist) ;
}
double degreeToRadian(double degree){
return degree* std::numbers::pi /180;
}
std::vector<std::pair<int, char>> getVisuals(Player& player, Map& mapInst){
int iterations = int(VISUAL_SPAN / DELTA_DEG);
std::vector<std::pair<int, char>> vec;
vec.reserve(iterations);
double degree = player.getDeg();
TDT4102::Point startPoint = player.getPos();
for (int i = 0; i < iterations; ++i){
double dx = DELTA_STEP * std::cos( degreeToRadian( degree + i * DELTA_DEG ));
double dy = DELTA_STEP * std::sin( degreeToRadian( degree + i * DELTA_DEG ));
double iterX = startPoint.x;
double iterY = startPoint.y;
int last_ix = int(iterX);
int last_iy = int(iterY);
//To only check if square is valid ('E') if x or y is rounded to a new integer, this keeps track of last integer rounded to
while(true){
iterX += dx;
iterY += dy;
int int_iterX = int(iterX);
int int_iterY = int(iterY);
if (last_ix != int_iterX || last_iy != int_iterY){
last_ix = int_iterX;
last_iy = int_iterY;
if ( mapInst.map[int_iterY][int_iterX] != 'E'){
std::pair<int, char> pairIter{distanceToHeight(iterX - startPoint.x, iterY - startPoint.y), mapInst.map[int_iterY][int_iterX]};
vec.push_back(pairIter);
break;
}
}
}
}
return vec;
}