-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstractmovableitem.h
103 lines (77 loc) · 2.27 KB
/
abstractmovableitem.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef ABSTRACTMOVABLEITEM_H
#define ABSTRACTMOVABLEITEM_H
#include "abstractgameitem.h"
#include <QObject>
class AbstractMovableItem : public AbstractGameItem
{
Q_OBJECT
public:
AbstractMovableItem(qreal w, qreal h, const QPointF &pos,
const QPixmaps2 &pixs2, QGraphicsScene *scene,
QGraphicsItem *parent = nullptr);
~AbstractMovableItem() {}
// deal with collide event,
// include eat food, pick money, etc
virtual void doCollide() = 0;
// return collision size of the item
QRectF boundingRect() const;
// return the paint path of the item
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
// check if item in the view
EDGE checkPos();
// control the animation
void advance(int);
// towards the target
virtual void aimAt(AbstractMovableItem *target);
virtual void move();
// change m_left, m_right corresponding to direction
virtual void updateDirection();
// vanish after eaten / die / drop out of screen
virtual void vanish();
// return the centre pos of the pixmap
QPointF centrePos();
// keep the item in the screen
virtual void keepInScene();
qreal speed() const;
qreal direction() const;
void setSpeed(const qreal speed);
void setDirection(const qreal dir);
bool left() const;
bool right() const;
bool turning() const;
void toLeft();
void toRight();
void turning(const bool turn);
void setPaintWidth(const qreal w);
void setPaintHeight(const qreal h);
void setState(const int state);
qreal paintWidth() const;
qreal paintHeight() const;
void setEatenExp(const int e);
int eatenExp() const;
signals:
// emit when deleted
void sgn_deleting();
public slots:
// the target deleted
void slt_lostAim();
protected:
qreal m_speed;
// rad
qreal m_direction;
QPixmaps2 m_pixs2;
int m_pixStateIndex;
bool m_hasTarget;
AbstractMovableItem * m_target;
// control turning
bool m_left;
bool m_right;
bool m_turning;
// size to paint
qreal m_paintWidth;
qreal m_paintHeight;
int m_eatenExp;
};
#endif // ABSTRACTMOVABLEITEM_H