summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-04 11:27:54 +0200
committermanuel <manuel@mausz.at>2011-04-04 11:27:54 +0200
commita35824a3319ae9c304263185c4efc449e2c2cf73 (patch)
treef769dc8e8e06265594b2f0e5bda47163428c47be /pacman-c++/actor.cpp
parent2a2c8d3b30e99e2bd636891a2eef27c0f35dcbc3 (diff)
downloadfoop-a35824a3319ae9c304263185c4efc449e2c2cf73.tar.gz
foop-a35824a3319ae9c304263185c4efc449e2c2cf73.tar.bz2
foop-a35824a3319ae9c304263185c4efc449e2c2cf73.zip
added simple pacman animation
Diffstat (limited to 'pacman-c++/actor.cpp')
-rw-r--r--pacman-c++/actor.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index 860f490..5080497 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -1,7 +1,50 @@
1#include "actor.h" 1#include "actor.h"
2#include "animationmanager.h"
3#include <QtCore/QPropertyAnimation>
4#include <QtCore/QSequentialAnimationGroup>
5#include <QtCore/QVariantAnimation>
6
7#define SPRITE_MARGIN 2
8#define SPRITE_PLAYER_WIDTH 16
9#define SPRITE_PLAYER_HEIGHT 16
10
11static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress)
12{
13 return (progress == 1.0) ? end : start;
14}
2 15
3Actor::Actor(Type type) 16Actor::Actor(Type type)
4 : PixmapItem("google-pacman-sprite"), m_type(type), m_direction(Actor::None) 17 : m_type(type), m_direction(Actor::None)
5{ 18{
6 setSprite(2, 2, 16, 16); 19 m_pix = ":/" + QString("actor%1").arg(type);
20 setPixmap(m_pix);
21 setSprite(82, 82, 16, 16);
22
23 m_direction = Actor::Left;
24
25 qRegisterAnimationInterpolator<bool>(myBooleanInterpolator);
26 QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this);
27 group->setLoopCount(-1);
28 for (int i = 0; i < 4; i++)
29 {
30 PixmapItem *step = new PixmapItem(m_pix, this);
31 int x = i * 20 + SPRITE_MARGIN;
32 int y = m_direction * 20 + SPRITE_MARGIN;
33 step->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT);
34 step->setVisible(false);
35
36
37 QPropertyAnimation *anim = new QPropertyAnimation(step, "visible", group);
38 anim->setDuration(0);
39 anim->setEndValue(true);
40
41 group->addPause(100);
42
43 QPropertyAnimation *anim2 = new QPropertyAnimation(step, "visible", group);
44 anim2->setDuration(0);
45 anim2->setEndValue(false);
46 }
47
48 AnimationManager::self()->registerAnimation(group);
49 group->start();
7} 50}