Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MovingObject : QObject
- {
- Q_OBJECT
- 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;
- QTimeLine *_timeLine;
- MovingObject()
- {
- _animationStep = 4;
- _moveSpeed = MazeData()._gridGap/_animationStep;
- _moving = 1;
- _stop = 0;
- _moveLeft = 0;
- _moveUp = 1;
- _moveRight = 2;
- _moveDown = 3;
- _currentImage = 0;
- _moveCounter = 0;
- _imageX = 0;
- _imageY = 0;
- _xDirection = 0;
- _yDirection = 0;
- }
- void Stop()
- {
- _timeLine->stop();
- }
- void Pause()
- {
- _timeLine->setPaused(true);
- }
- void Start()
- {
- _timeLine->start();
- }
- void CreateTimeLine()
- {
- _timeLine->setLoopCount(-1);
- _timeLine->setUpdateInterval(250);
- _timeLine->setFrameRange(0, 3);
- connect(_timeLine, SIGNAL(frameChanged(int)), this, SLOT(MoveOneStep()));
- }
- ~MovingObject()
- {
- delete _timeLine;
- }
- public slots:
- virtual void MoveOneStep()
- {
- }
- };
- class Pacman : public QGraphicsObject, public MovingObject
- {
- Q_OBJECT
- public:
- QPixmap *_defaultImage;
- QPixmap *_secondImage;
- QPixmap *_roundImage;
- QList<QPixmap*> _images;
- Pacman(double x, double y)
- : MovingObject()
- {
- _imageX = MazeData().CalcGridX(x);
- _imageY = MazeData().CalcGridY(y);
- _defaultImage = new QPixmap(":/images/left1.png");
- _secondImage = new QPixmap(":/images/left2.png");
- _roundImage = new QPixmap(":/images/round.png");
- _images.push_back(_defaultImage);
- _images.push_back(_secondImage);
- _images.push_back(_defaultImage);
- _images.push_back(_roundImage);
- QGraphicsPixmapItem *pacmanFrame = new QGraphicsPixmapItem;
- pacmanFrame->setParentItem(this);
- pacmanFrame->setPos(_imageX - 13, _imageY - 13);
- pacmanFrame->setPixmap(*_images.at(_currentImage));
- }
- public slots:
- void MoveOneStep()
- {
- if(_state == _moving)
- {
- if(_currentImage < _animationStep - 1) _currentImage++;
- else _currentImage = 0;
- }
- }
- public:
- ~Pacman()
- {
- delete _defaultImage;
- delete _secondImage;
- delete _roundImage;
- }
- QRectF boundingRect() const
- {
- return QRectF();
- }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
- {
- Q_UNUSED(painter);
- Q_UNUSED(option);
- Q_UNUSED(widget);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement