From 606d2a2a3d53930b10c2057f96165f8cd4e6f165 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 4 Apr 2011 12:26:35 +0200 Subject: make the pacman move! --- pacman-c++/actor.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'pacman-c++/actor.cpp') 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 @@ #include "animationmanager.h" #include #include +#include #include +#include #define SPRITE_MARGIN 2 #define SPRITE_PLAYER_WIDTH 16 @@ -18,33 +20,41 @@ Actor::Actor(Type type) { m_pix = ":/" + QString("actor%1").arg(type); setPixmap(m_pix); - setSprite(82, 82, 16, 16); + setSprite(82, 82, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); m_direction = Actor::Left; qRegisterAnimationInterpolator(myBooleanInterpolator); - QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this); - group->setLoopCount(-1); + + QSequentialAnimationGroup *eating = new QSequentialAnimationGroup(this); + QParallelAnimationGroup *moving = new QParallelAnimationGroup(this); + eating->setLoopCount(-1); + for (int i = 0; i < 4; i++) { - PixmapItem *step = new PixmapItem(m_pix, this); + PixmapItem *img = new PixmapItem(m_pix, this); int x = i * 20 + SPRITE_MARGIN; int y = m_direction * 20 + SPRITE_MARGIN; - step->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); - step->setVisible(false); + img->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); + img->setVisible(false); + img->setPos(QPointF(200, 0)); + QPropertyAnimation *fadein = new QPropertyAnimation(img, "visible", eating); + fadein->setDuration(0); + fadein->setEndValue(true); - QPropertyAnimation *anim = new QPropertyAnimation(step, "visible", group); - anim->setDuration(0); - anim->setEndValue(true); + eating->addPause(100); - group->addPause(100); + QPropertyAnimation *fadeout = new QPropertyAnimation(img, "visible", eating); + fadeout->setDuration(0); + fadeout->setEndValue(false); - QPropertyAnimation *anim2 = new QPropertyAnimation(step, "visible", group); - anim2->setDuration(0); - anim2->setEndValue(false); + QPropertyAnimation *move = new QPropertyAnimation(img, "pos", moving); + move->setDuration(10000); + move->setEndValue(QPointF(0, 0)); } - AnimationManager::self()->registerAnimation(group); - group->start(); + AnimationManager::self()->registerAnimation(eating); + eating->start(); + moving->start(); } -- cgit v1.2.3