diff options
| author | manuel <manuel@mausz.at> | 2011-04-04 12:26:35 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-04 12:26:35 +0200 |
| commit | 606d2a2a3d53930b10c2057f96165f8cd4e6f165 (patch) | |
| tree | 851cc2b5ee1da9ddb7dbe87d7913cd26d162fd62 | |
| parent | a35824a3319ae9c304263185c4efc449e2c2cf73 (diff) | |
| download | foop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.tar.gz foop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.tar.bz2 foop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.zip | |
make the pacman move!
| -rw-r--r-- | pacman-c++/actor.cpp | 40 | ||||
| -rw-r--r-- | pacman-c++/main.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.cpp | 15 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.h | 7 |
4 files changed, 29 insertions, 39 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 5080497..e98545b 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | #include "animationmanager.h" | 2 | #include "animationmanager.h" |
| 3 | #include <QtCore/QPropertyAnimation> | 3 | #include <QtCore/QPropertyAnimation> |
| 4 | #include <QtCore/QSequentialAnimationGroup> | 4 | #include <QtCore/QSequentialAnimationGroup> |
| 5 | #include <QtCore/QParallelAnimationGroup> | ||
| 5 | #include <QtCore/QVariantAnimation> | 6 | #include <QtCore/QVariantAnimation> |
| 7 | #include <QDebug> | ||
| 6 | 8 | ||
| 7 | #define SPRITE_MARGIN 2 | 9 | #define SPRITE_MARGIN 2 |
| 8 | #define SPRITE_PLAYER_WIDTH 16 | 10 | #define SPRITE_PLAYER_WIDTH 16 |
| @@ -18,33 +20,41 @@ Actor::Actor(Type type) | |||
| 18 | { | 20 | { |
| 19 | m_pix = ":/" + QString("actor%1").arg(type); | 21 | m_pix = ":/" + QString("actor%1").arg(type); |
| 20 | setPixmap(m_pix); | 22 | setPixmap(m_pix); |
| 21 | setSprite(82, 82, 16, 16); | 23 | setSprite(82, 82, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); |
| 22 | 24 | ||
| 23 | m_direction = Actor::Left; | 25 | m_direction = Actor::Left; |
| 24 | 26 | ||
| 25 | qRegisterAnimationInterpolator<bool>(myBooleanInterpolator); | 27 | qRegisterAnimationInterpolator<bool>(myBooleanInterpolator); |
| 26 | QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this); | 28 | |
| 27 | group->setLoopCount(-1); | 29 | QSequentialAnimationGroup *eating = new QSequentialAnimationGroup(this); |
| 30 | QParallelAnimationGroup *moving = new QParallelAnimationGroup(this); | ||
| 31 | eating->setLoopCount(-1); | ||
| 32 | |||
| 28 | for (int i = 0; i < 4; i++) | 33 | for (int i = 0; i < 4; i++) |
| 29 | { | 34 | { |
| 30 | PixmapItem *step = new PixmapItem(m_pix, this); | 35 | PixmapItem *img = new PixmapItem(m_pix, this); |
| 31 | int x = i * 20 + SPRITE_MARGIN; | 36 | int x = i * 20 + SPRITE_MARGIN; |
| 32 | int y = m_direction * 20 + SPRITE_MARGIN; | 37 | int y = m_direction * 20 + SPRITE_MARGIN; |
| 33 | step->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); | 38 | img->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); |
| 34 | step->setVisible(false); | 39 | img->setVisible(false); |
| 40 | img->setPos(QPointF(200, 0)); | ||
| 35 | 41 | ||
| 42 | QPropertyAnimation *fadein = new QPropertyAnimation(img, "visible", eating); | ||
| 43 | fadein->setDuration(0); | ||
| 44 | fadein->setEndValue(true); | ||
| 36 | 45 | ||
| 37 | QPropertyAnimation *anim = new QPropertyAnimation(step, "visible", group); | 46 | eating->addPause(100); |
| 38 | anim->setDuration(0); | ||
| 39 | anim->setEndValue(true); | ||
| 40 | 47 | ||
| 41 | group->addPause(100); | 48 | QPropertyAnimation *fadeout = new QPropertyAnimation(img, "visible", eating); |
| 49 | fadeout->setDuration(0); | ||
| 50 | fadeout->setEndValue(false); | ||
| 42 | 51 | ||
| 43 | QPropertyAnimation *anim2 = new QPropertyAnimation(step, "visible", group); | 52 | QPropertyAnimation *move = new QPropertyAnimation(img, "pos", moving); |
| 44 | anim2->setDuration(0); | 53 | move->setDuration(10000); |
| 45 | anim2->setEndValue(false); | 54 | move->setEndValue(QPointF(0, 0)); |
| 46 | } | 55 | } |
| 47 | 56 | ||
| 48 | AnimationManager::self()->registerAnimation(group); | 57 | AnimationManager::self()->registerAnimation(eating); |
| 49 | group->start(); | 58 | eating->start(); |
| 59 | moving->start(); | ||
| 50 | } | 60 | } |
diff --git a/pacman-c++/main.cpp b/pacman-c++/main.cpp index 4b88b44..3311429 100644 --- a/pacman-c++/main.cpp +++ b/pacman-c++/main.cpp | |||
| @@ -7,12 +7,12 @@ int 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, 500, 500); |
| 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 | actor1->setPos(100,100); | 15 | actor1->setPos(100, 100); |
| 16 | 16 | ||
| 17 | QGraphicsView window(&scene); | 17 | QGraphicsView window(&scene); |
| 18 | window.setFrameStyle(0); | 18 | window.setFrameStyle(0); |
| @@ -22,7 +22,7 @@ int main(int argc, char **argv) | |||
| 22 | 22 | ||
| 23 | QMainWindow mainWin; | 23 | QMainWindow mainWin; |
| 24 | mainWin.setCentralWidget(&window); | 24 | mainWin.setCentralWidget(&window); |
| 25 | mainWin.resize(300, 300); | 25 | mainWin.resize(500, 500); |
| 26 | mainWin.show(); | 26 | mainWin.show(); |
| 27 | 27 | ||
| 28 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | 28 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
diff --git a/pacman-c++/pixmapitem.cpp b/pacman-c++/pixmapitem.cpp index a977a9e..b0a81d0 100644 --- a/pacman-c++/pixmapitem.cpp +++ b/pacman-c++/pixmapitem.cpp | |||
| @@ -66,19 +66,6 @@ QRectF PixmapItem::boundingRect() const | |||
| 66 | 66 | ||
| 67 | void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) | 67 | void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
| 68 | { | 68 | { |
| 69 | painter->drawPixmap(0, 0, m_pix, m_x, m_y, m_width, m_height); | 69 | painter->drawPixmap(QPoint(0, 0), m_pix, QRect(m_x, m_y, m_width, m_height)); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | #if 0 | ||
| 73 | bool PixmapItem::isVisible() const | ||
| 74 | { | ||
| 75 | qDebug() << "isVisible()"; | ||
| 76 | return true; | ||
| 77 | } | ||
| 78 | |||
| 79 | void PixmapItem::setVisible(bool v) | ||
| 80 | { | ||
| 81 | qDebug() << "setVisible(" << v << ")"; | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | |||
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h index e6aa79e..8e7d4f0 100644 --- a/pacman-c++/pixmapitem.h +++ b/pacman-c++/pixmapitem.h | |||
| @@ -7,8 +7,6 @@ | |||
| 7 | class PixmapItem | 7 | class PixmapItem |
| 8 | : public QGraphicsObject | 8 | : public QGraphicsObject |
| 9 | { | 9 | { |
| 10 | Q_PROPERTY(bool visibleX READ isVisible WRITE setVisible) | ||
| 11 | |||
| 12 | public: | 10 | public: |
| 13 | PixmapItem(QGraphicsItem *parent = 0); | 11 | PixmapItem(QGraphicsItem *parent = 0); |
| 14 | PixmapItem(const QString &fileName, QGraphicsItem *parent = 0); | 12 | PixmapItem(const QString &fileName, QGraphicsItem *parent = 0); |
| @@ -21,11 +19,6 @@ public: | |||
| 21 | QRectF boundingRect() const; | 19 | QRectF boundingRect() const; |
| 22 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | 20 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
| 23 | 21 | ||
| 24 | #if 0 | ||
| 25 | bool isVisible() const; | ||
| 26 | void setVisible(bool v); | ||
| 27 | #endif | ||
| 28 | |||
| 29 | private: | 22 | private: |
| 30 | QPixmap m_pix; | 23 | QPixmap m_pix; |
| 31 | int m_x, m_y; | 24 | int m_x, m_y; |
