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.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index b3ff588..b788a49 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -1,5 +1,4 @@
1#include "sceneholder.h" 1#include "sceneholder.h"
2
3#include "constants.h" 2#include "constants.h"
4#include "pixmapitem.h" 3#include "pixmapitem.h"
5#include "block.h" 4#include "block.h"
@@ -8,11 +7,11 @@
8#include "point.h" 7#include "point.h"
9#include "util.h" 8#include "util.h"
10 9
11SceneHolder::SceneHolder(QWidget* parent) 10SceneHolder::SceneHolder(QObject *parent)
12 : QWidget(parent), m_color(Color::none), m_pointsLeft(0) 11 : QGraphicsScene(parent), m_color(Color::none), m_pointsLeft(0)
13{ 12{
14 m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); 13 setSceneRect(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height);
15 m_scene->setBackgroundBrush(Qt::black); 14 setBackgroundBrush(Qt::black);
16 15
17 visualMap.resize(Constants::map_size.width); 16 visualMap.resize(Constants::map_size.width);
18 for (int i = 0; i < visualMap.size(); ++i) 17 for (int i = 0; i < visualMap.size(); ++i)
@@ -39,7 +38,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
39 /* remove elements (in case it's not an actor) */ 38 /* remove elements (in case it's not an actor) */
40 if (oldItem != NULL && dynamic_cast<Actor *>(item) == NULL) 39 if (oldItem != NULL && dynamic_cast<Actor *>(item) == NULL)
41 { 40 {
42 m_scene->removeItem(oldItem); 41 removeItem(oldItem);
43 visualMap[x][y] = NULL; 42 visualMap[x][y] = NULL;
44 Actor *actor = NULL; 43 Actor *actor = NULL;
45 foreach (Actor *i, m_actors) 44 foreach (Actor *i, m_actors)
@@ -81,7 +80,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
81 item = new BonusPoint(); 80 item = new BonusPoint();
82 else if (cur & Transmission::point) 81 else if (cur & Transmission::point)
83 { 82 {
84 qDebug() << "new point";
85 item = new Point(); 83 item = new Point();
86 connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints())); 84 connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints()));
87 ++m_pointsLeft; 85 ++m_pointsLeft;
@@ -93,7 +91,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
93 { 91 {
94 actor = new Actor(color, (color == m_color)); 92 actor = new Actor(color, (color == m_color));
95 m_actors[color] = actor; 93 m_actors[color] = actor;
96 m_scene->addItem(actor); 94 addItem(actor);
97 actor->setPos(mapPositionToCoord(x, y)); 95 actor->setPos(mapPositionToCoord(x, y));
98 } 96 }
99 else 97 else
@@ -116,13 +114,13 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
116 114
117 if (item != NULL) 115 if (item != NULL)
118 { 116 {
119 m_scene->addItem(item); 117 addItem(item);
120 item->setPos(mapPositionToCoord(x, y)); 118 item->setPos(mapPositionToCoord(x, y));
121 PixmapItem* oldItem = visualMap[x][y]; 119 PixmapItem* oldItem = visualMap[x][y];
122 visualMap[x][y] = item; 120 visualMap[x][y] = item;
123 if (oldItem != NULL) 121 if (oldItem != NULL)
124 { 122 {
125 m_scene->removeItem(item); 123 removeItem(item);
126 delete oldItem; 124 delete oldItem;
127 } 125 }
128 } 126 }
@@ -131,6 +129,16 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
131 129
132} 130}
133 131
132void SceneHolder::setColor(Color::Color color)
133{
134 m_color = color;
135}
136
137Color::Color SceneHolder::color()
138{
139 return m_color;
140}
141
134unsigned int SceneHolder::pointsLeft() 142unsigned int SceneHolder::pointsLeft()
135{ 143{
136 return m_pointsLeft; 144 return m_pointsLeft;