summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.h
blob: c30c62a32585beb39b3a08f6ea45cc86528e7795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef ACTOR_H
#define ACTOR_H

#include "gameentity.h"
#include "constants.h"
#include "audio.h"
#include <QtCore/QSequentialAnimationGroup>
#include <QtCore/QParallelAnimationGroup>
#include <QList>

class Actor
  : public GameEntity
{
Q_OBJECT

public:
  enum Movement
  {
    None = 0,
    Left,
    Right,
    Up,
    Down,
  };

  enum
  {
    Type = UserType + Transmission::pacman
  };

  Actor(Color::Color color, bool local = false, QGraphicsItem *parent = 0);
  virtual ~Actor()
  {};

  PixmapItem &icon();
  const QString iconStr();
  Movement direction();
  void setDirection(Movement direction);
  void reset();
  bool hadReset();
  bool isLocal();
  void move(Movement direction);
  void move(QPoint newpos);
  bool isMoving();
  void die();
  void eatingFruit();
  void eatingPacman();
  void startEating();
  void stopEating();
  bool canEat(Actor *other, const QList<Color::Color> &order);
  virtual void onDie(Actor *);

  unsigned int getRoundPoints();
  unsigned int getGamePoints();
  void addRoundPoints(unsigned int amount);
  void finishRound(bool died = false);

  static QPoint movementToPoint(const Movement direction);

private:
  void moveByServer(Movement direction);
  QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction);

private:
  QPixmap m_pix;
  Movement m_direction;
  PixmapItem m_icon;
  bool m_local;
  bool m_reset;
  GaplessAudioPlayer *m_wakaPlayer;

  unsigned int m_roundPoints;
  unsigned int m_gamePoints;

  QList<PixmapItem *> m_images;
  QList<QSequentialAnimationGroup *> m_eating;
  QParallelAnimationGroup *m_moving;
  QSequentialAnimationGroup *m_dieing;
};

#endif // ACTOR_H