Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MovingObject : public QGraphicsObject
- {
- public:
- int _animationStep;
- int _moveSpeed;
- int _moving;
- int _stop;
- int _moveLeft;
- int _moveUp;
- int _moveRight;
- int _moveDown;
- int _currentImage;
- int _moveCounter;
- int _state;
- double _x;
- double _y;
- double _imageX;
- double _imageY;
- double _xDirection;
- double _yDirection;
- MovingObject(QGraphicsObject *parent = 0)
- {
- _animationStep = 4;
- _moveSpeed = MazeData()._gridGap/_animationStep;
- _moving = 1;
- _stop = 0;
- _moveLeft = 0;
- _moveUp = 1;
- _moveRight = 2;
- _moveDown = 3;
- _currentImage = 0;
- _moveCounter = 0;
- _state = 1;
- _imageX = 0;
- _imageY = 0;
- _xDirection = 0;
- _yDirection = 0;
- }
- };
- class Pacman : public MovingObject
- {
- Q_OBJECT
- public:
- QList<QPixmap*> _images;
- QGraphicsPixmapItem *_pacmanFrame;
- Pacman(double x, double y)
- : MovingObject(this)
- {
- _imageX = MazeData().CalcGridX(x);
- _imageY = MazeData().CalcGridY(y);
- QPixmap *defaultImage = new QPixmap("images/newLeft1.png");
- QPixmap *secondImage = new QPixmap("images/newLeft2.png");
- QPixmap *roundImage = new QPixmap("images/newRound.png");
- _images.push_back(defaultImage);
- _images.push_back(secondImage);
- _images.push_back(defaultImage);
- _images.push_back(roundImage);
- _pacmanFrame = new QGraphicsPixmapItem;
- _pacmanFrame->setParentItem(this);
- _pacmanFrame->setPos(_imageX - 13, _imageY - 13);
- _pacmanFrame->setPixmap(*defaultImage);
- QPropertyAnimation *pacmanMouth = new QPropertyAnimation(this);
- pacmanMouth->setDuration(250);
- pacmanMouth->setLoopCount(-1);
- pacmanMouth->start();
- connect(pacmanMouth, SIGNAL(currentLoopChanged(int)), this, SLOT(SwitchImage()));
- }
- ~Pacman()
- {
- }
- QRectF boundingRect() const
- {
- return QRectF();
- }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
- {
- Q_UNUSED(painter);
- Q_UNUSED(option);
- Q_UNUSED(widget);
- }
- public slot:
- void SwitchImage()
- {
- if(_state == _moving)
- {
- if(_currentImage < _animationStep - 1) _currentImage++;
- else _currentImage = 0;
- }
- _pacmanFrame->setPixmap(*_images.at(_currentImage));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement