-
Notifications
You must be signed in to change notification settings - Fork 0
/
meryl.cpp
78 lines (67 loc) · 1.62 KB
/
meryl.cpp
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
#include "meryl.h"
Meryl::Meryl(qreal w, qreal h, const QPointF &pos,
const QPixmaps2 &pixs2, QGraphicsScene *scene,
QGraphicsItem *parent)
: AbstractPet(w, h, pos, pixs2, scene, parent),
m_name("meryl")
{
}
const QString &Meryl::name() const
{
return m_name;
}
void Meryl::move()
{
if (!turning()){
if (m_step % Config::CHANGE_DIRECTION_STEP == 0){
setDirection(direction() + RandomMaker::creatRandom(-5, 6) / 40.0);
}
}
AbstractMovableItem::move();
keepInScene();
}
void Meryl::doCollide()
{
// do nothing
}
void Meryl::advance(int)
{
AbstractMovableItem::advance(0);
if (m_step % Config::UPDATE_PAINT_STEP == 0){
updateDirection();
m_pixIndex++;
if (m_pixIndex == Config::PETS_INDEX_COUNT){
m_pixIndex = 0;
if (turning()){
turning(false);
}
}
if (turning()){
if (right()){
m_pixStateIndex = Config::PETS_TURN_RIGHT_STATE_INDEX;
}
else if (left()){
m_pixStateIndex = Config::PETS_TURN_LEFT_STATE_INDEX;
}
} else {
if (left()){
m_pixStateIndex = Config::PETS_SWIM_LEFT_STATE_INDEX;
}
else if (right()){
m_pixStateIndex = Config::PETS_SWIM_RIGHT_STATE_INDEX;
}
}
move();
}
if (m_step % Config::PETS_YIELD_STEP["meryl"] == 0){
yield();
}
}
void Meryl::findTarget()
{
// do nothing
}
void Meryl::yield()
{
emit sgn_specialSkill(m_name, scenePos());
}