summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-04 12:26:35 +0200
committermanuel <manuel@mausz.at>2011-04-04 12:26:35 +0200
commit606d2a2a3d53930b10c2057f96165f8cd4e6f165 (patch)
tree851cc2b5ee1da9ddb7dbe87d7913cd26d162fd62 /pacman-c++/actor.cpp
parenta35824a3319ae9c304263185c4efc449e2c2cf73 (diff)
downloadfoop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.tar.gz
foop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.tar.bz2
foop-606d2a2a3d53930b10c2057f96165f8cd4e6f165.zip
make the pacman move!
Diffstat (limited to 'pacman-c++/actor.cpp')
-rw-r--r--pacman-c++/actor.cpp40
1 files changed, 25 insertions, 15 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}