summaryrefslogtreecommitdiffstats
path: root/pacman-c++/sceneholder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
-rw-r--r--pacman-c++/sceneholder.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 515d5ec..0236470 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -14,9 +14,8 @@ SceneHolder::SceneHolder(QWidget* parent): QWidget(parent)
14 m_scene->setBackgroundBrush(Qt::black); 14 m_scene->setBackgroundBrush(Qt::black);
15 15
16 visualMap.resize(Constants::map_size.width); 16 visualMap.resize(Constants::map_size.width);
17 for (int i=0; i<visualMap.size(); ++i) { 17 for (int i = 0; i < visualMap.size(); ++i)
18 visualMap[i].resize(Constants::map_size.height); 18 visualMap[i].resize(Constants::map_size.height);
19 }
20} 19}
21 20
22void SceneHolder::updateMap(const Transmission::map_t& map) 21void SceneHolder::updateMap(const Transmission::map_t& map)
@@ -34,16 +33,22 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
34 //qDebug() << "col=" << color; 33 //qDebug() << "col=" << color;
35 34
36 PixmapItem* item = NULL; 35 PixmapItem* item = NULL;
37 if (cur == Transmission::none) { // no update 36 if (cur == Transmission::none)
38 } else if (cur & Transmission::empty) { 37 {
38 // no update
39 }
40 else if (cur & Transmission::empty)
41 {
39 PixmapItem* oldItem = visualMap[x][y]; 42 PixmapItem* oldItem = visualMap[x][y];
40 // remove elements (in case it's not an actor) 43 // remove elements (in case it's not an actor)
41 if (oldItem != NULL && dynamic_cast<Actor*>(item) == 0) { 44 if (oldItem != NULL && dynamic_cast<Actor*>(item) == NULL)
45 {
42 m_scene->removeItem(oldItem); 46 m_scene->removeItem(oldItem);
43 visualMap[x][y] = NULL; 47 visualMap[x][y] = NULL;
44 delete oldItem; 48 delete oldItem;
45 } 49 }
46 } else if (cur & Transmission::block) 50 }
51 else if (cur & Transmission::block)
47 { 52 {
48 unsigned int neighbours = Block::None; 53 unsigned int neighbours = Block::None;
49 // check left side 54 // check left side
@@ -81,7 +86,8 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
81 actor->move(direction); 86 actor->move(direction);
82 qDebug() << "actor move " << direction; 87 qDebug() << "actor move " << direction;
83 } 88 }
84 else { 89 else
90 {
85 qDebug() << "abort at " << cur; 91 qDebug() << "abort at " << cur;
86 Q_ASSERT(false); 92 Q_ASSERT(false);
87 } 93 }
@@ -108,9 +114,18 @@ QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y)
108 return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); 114 return QPoint(x * Constants::field_size.width, y * Constants::field_size.height);
109} 115}
110 116
117QPoint SceneHolder::mapPositionToCoord(QPoint point)
118{
119 return mapPositionToCoord(point.x(), point.y());
120}
121
111QPoint SceneHolder::CoordToMapPosition(unsigned int x, unsigned int y) 122QPoint SceneHolder::CoordToMapPosition(unsigned int x, unsigned int y)
112{ 123{
113 return QPoint(x / Constants::field_size.width, y / Constants::field_size.height); 124 return QPoint(x / Constants::field_size.width, y / Constants::field_size.height);
114} 125}
115 126
127QPoint SceneHolder::CoordToMapPosition(QPoint point)
128{
129 return CoordToMapPosition(point.x(), point.y());
130}
116 131