-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
111 lines (87 loc) · 2.08 KB
/
Map.cpp
File metadata and controls
111 lines (87 loc) · 2.08 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
100
101
102
103
104
105
106
107
108
109
110
111
#include <QPainter>
#include "Map.h"
#include "Scene.h"
#include "MapSurface.h"
void Map::initialize(Scene *scene)
{
m_backgroundSurface = new MapSurface(MapSurface::Background, m_background, scene);
m_foregroundSurface = new MapSurface(MapSurface::Foreground, m_foreground, scene);
QSize size = m_background.size();
QImage foo(size, QImage::Format_ARGB32);
QPainter painter(&foo);
for(const Collidable &collidable : m_collidables)
{
const QPolygonF &polygon = collidable.polygon();
const QRect &boundingBox = collidable.boundingBox();
painter.setPen(Qt::red);
painter.setBrush(Qt::NoBrush);
painter.drawPolygon(polygon);
painter.setPen(Qt::green);
painter.setBrush(Qt::NoBrush);
painter.drawRect(boundingBox);
}
QLine spawnLine(m_spawn.x(), 0, m_spawn.x(), size.height());
painter.setBrush(Qt::blue);
painter.setPen(Qt::blue);
painter.drawLine(spawnLine);
painter.drawEllipse(m_spawn, 10, 10);
painter.fillRect(m_goal, Qt::yellow);
// for(const QPolygon &path : m_paths)
// {
// qDebug() << path.count();
// const QPoint *previous = 0;
// for(const QPoint &point : path)
// {
// if(previous)
// {
// QLine line(*previous, point);
// painter.setBrush(Qt::NoBrush);
// painter.setPen(Qt::green);
// painter.drawLine(line);
// painter.setBrush(Qt::blue);
// painter.setPen(Qt::blue);
// painter.drawEllipse(*previous, 10, 10);
// previous = &point;
// }
// else
// {
// previous = &point;
// }
// }
// }
// new MapSurface(MapSurface::Foreground, foo, scene);
}
int Map::width() const
{
return m_background.width();
}
int Map::height() const
{
return m_background.height();
}
QList<Collidable> Map::collidables() const
{
return m_collidables;
}
QList<QPolygon> Map::paths() const
{
return m_paths;
}
QPoint Map::spawnPoint() const
{
return m_spawn;
}
QRect Map::goal() const
{
return m_goal;
}
QDataStream &operator >>(QDataStream &stream, Map &map)
{
stream >> map.m_background;
stream >> map.m_foreground;
stream >> map.m_collidables;
stream >> map.m_paths;
stream >> map.m_spawn;
stream >> map.m_goal;
return stream;
}