-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObstacle.cpp
More file actions
45 lines (38 loc) · 1.69 KB
/
Copy pathObstacle.cpp
File metadata and controls
45 lines (38 loc) · 1.69 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
#include "Obstacle.h"
std::vector<std::vector<uint_fast8_t>> Obstacle::grid = {
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}
};
Obstacle::Obstacle(Vector2 position) : m_position(position) {}
void Obstacle::draw(const std::list<Obstacle>& obstacles, const std::list<Block>& blocks) {
for (auto obstacle : obstacles) {
for (auto block: blocks) {
block.Draw();
}
}
}
void Obstacle::initializeObstacles(std::list<Obstacle>& obstacles, float shuttlePosition, std::list<Block>& blocks) {
blocks.clear();
obstacles.clear();
for (int i = 0; i < 4; i++) {
obstacles.push_back(Obstacle({static_cast<float>(100 + i * 200), shuttlePosition}));
}
for (auto& obstacle : obstacles) {
for (int row = 0; row < Obstacle::grid.size(); row++) {
for (int column = 0; column < Obstacle::grid[row].size(); column++) {
if (Obstacle::grid[row][column]) {
auto block = Block({obstacle.m_position.x + static_cast<float>(column) * obstacle.m_size,
obstacle.m_position.y + static_cast<float>(row) * obstacle.m_size, obstacle.m_size, obstacle.m_size});
blocks.push_back(block);
}
}
}
}
}