summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp4
-rw-r--r--pacman-c++/actor.h32
-rw-r--r--pacman-c++/main.cpp28
-rw-r--r--pacman-c++/pixmapitem.cpp32
-rw-r--r--pacman-c++/pixmapitem.h20
5 files changed, 58 insertions, 58 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index 860f490..576fded 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -1,7 +1,7 @@
1#include "actor.h" 1#include "actor.h"
2 2
3Actor::Actor(Type type) 3Actor::Actor(Type type)
4 : PixmapItem("google-pacman-sprite"), m_type(type), m_direction(Actor::None) 4 : PixmapItem("google-pacman-sprite"), m_type(type), m_direction(Actor::None)
5{ 5{
6 setSprite(2, 2, 16, 16); 6 setSprite(2, 2, 16, 16);
7} 7}
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h
index 753c920..5f68f8f 100644
--- a/pacman-c++/actor.h
+++ b/pacman-c++/actor.h
@@ -4,27 +4,27 @@
4#include "pixmapitem.h" 4#include "pixmapitem.h"
5 5
6class Actor 6class Actor
7 : public PixmapItem 7 : public PixmapItem
8{ 8{
9public: 9public:
10 enum Movement { 10 enum Movement {
11 None = 0, 11 None = 0,
12 Left, 12 Left,
13 Right, 13 Right,
14 Up, 14 Up,
15 Down 15 Down
16 }; 16 };
17 17
18 enum Type { 18 enum Type {
19 Player1 = 1, 19 Player1 = 1,
20 Player2, 20 Player2,
21 Player3, 21 Player3,
22 }; 22 };
23 23
24 Actor(Type type); 24 Actor(Type type);
25private: 25private:
26 Type m_type; 26 Type m_type;
27 Movement m_direction; 27 Movement m_direction;
28}; 28};
29 29
30#endif // ACTOR_H 30#endif // ACTOR_H
diff --git a/pacman-c++/main.cpp b/pacman-c++/main.cpp
index 0756684..cceb8f5 100644
--- a/pacman-c++/main.cpp
+++ b/pacman-c++/main.cpp
@@ -5,24 +5,24 @@
5 5
6int main(int argc, char **argv) 6int main(int argc, char **argv)
7{ 7{
8 QApplication app(argc, argv); 8 QApplication app(argc, argv);
9 9
10 QGraphicsScene scene(0, 0, 300, 300); 10 QGraphicsScene scene(0, 0, 300, 300);
11 scene.setBackgroundBrush(Qt::black); 11 scene.setBackgroundBrush(Qt::black);
12 12
13 Actor *actor1 = new Actor(Actor::Player1); 13 Actor *actor1 = new Actor(Actor::Player1);
14 scene.addItem(actor1); 14 scene.addItem(actor1);
15 15
16 QGraphicsView window(&scene); 16 QGraphicsView window(&scene);
17 window.setFrameStyle(0); 17 window.setFrameStyle(0);
18 window.setAlignment(Qt::AlignLeft | Qt::AlignTop); 18 window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
19 window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 19 window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
20 window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 20 window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
21 21
22 window.resize(300, 300); 22 window.resize(300, 300);
23 window.show(); 23 window.show();
24 24
25 qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); 25 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
26 26
27 return app.exec(); 27 return app.exec();
28} 28}
diff --git a/pacman-c++/pixmapitem.cpp b/pacman-c++/pixmapitem.cpp
index 64ac594..9c2f941 100644
--- a/pacman-c++/pixmapitem.cpp
+++ b/pacman-c++/pixmapitem.cpp
@@ -2,43 +2,43 @@
2#include <QPainter> 2#include <QPainter>
3 3
4PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent) 4PixmapItem::PixmapItem(const QString &fileName, QGraphicsItem *parent)
5 : QGraphicsObject(parent), m_x(0), m_y(0) 5 : QGraphicsObject(parent), m_x(0), m_y(0)
6{ 6{
7 m_pix = ":/" + fileName; 7 m_pix = ":/" + fileName;
8 m_width = m_pix.width(); 8 m_width = m_pix.width();
9 m_height = m_pix.height(); 9 m_height = m_pix.height();
10} 10}
11 11
12PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) 12PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene)
13 : QGraphicsObject(), m_x(0), m_y(0) 13 : QGraphicsObject(), m_x(0), m_y(0)
14{ 14{
15 m_pix = ":/" + fileName; 15 m_pix = ":/" + fileName;
16 m_width = m_pix.width(); 16 m_width = m_pix.width();
17 m_height = m_pix.height(); 17 m_height = m_pix.height();
18 scene->addItem(this); 18 scene->addItem(this);
19} 19}
20 20
21void PixmapItem::setSprite(int x, int y, int width, int height) 21void PixmapItem::setSprite(int x, int y, int width, int height)
22{ 22{
23 m_x = x; 23 m_x = x;
24 m_y = y; 24 m_y = y;
25 m_width = width; 25 m_width = width;
26 m_height = height; 26 m_height = height;
27} 27}
28 28
29QSizeF PixmapItem::size() const 29QSizeF PixmapItem::size() const
30{ 30{
31 return QSizeF(m_width, m_height); 31 return QSizeF(m_width, m_height);
32} 32}
33 33
34QRectF PixmapItem::boundingRect() const 34QRectF PixmapItem::boundingRect() const
35{ 35{
36 return QRectF(QPointF(0, 0), size()); 36 return QRectF(QPointF(0, 0), size());
37} 37}
38 38
39void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 39void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
40{ 40{
41 painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height); 41 painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height);
42} 42}
43 43
44 44
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h
index a94c251..853604d 100644
--- a/pacman-c++/pixmapitem.h
+++ b/pacman-c++/pixmapitem.h
@@ -5,19 +5,19 @@
5#include <QtGui/QGraphicsScene> 5#include <QtGui/QGraphicsScene>
6 6
7class PixmapItem 7class PixmapItem
8 : public QGraphicsObject 8 : public QGraphicsObject
9{ 9{
10public: 10public:
11 PixmapItem(const QString &fileName, QGraphicsItem *parent = 0); 11 PixmapItem(const QString &fileName, QGraphicsItem *parent = 0);
12 PixmapItem(const QString &fileName, QGraphicsScene *scene); 12 PixmapItem(const QString &fileName, QGraphicsScene *scene);
13 void setSprite(int x, int y, int width, int height); 13 void setSprite(int x, int y, int width, int height);
14 QSizeF size() const; 14 QSizeF size() const;
15 QRectF boundingRect() const; 15 QRectF boundingRect() const;
16 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); 16 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
17private: 17private:
18 QPixmap m_pix; 18 QPixmap m_pix;
19 int m_x, m_y; 19 int m_x, m_y;
20 int m_width, m_height; 20 int m_width, m_height;
21}; 21};
22 22
23#endif 23#endif