-
Notifications
You must be signed in to change notification settings - Fork 0
/
niko.cpp
91 lines (81 loc) · 1.89 KB
/
niko.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
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "niko.h"
Niko::Niko(qreal w, qreal h, const QPointF &pos,
const QPixmaps2 &pixs2, QGraphicsScene *scene,
QGraphicsItem *parent)
: AbstractPet(w, h, pos, pixs2, scene, parent),
m_name("niko"), m_mature(false), m_harvested(false),
m_gainable(false)
{
m_openSound = new QSoundEffect;
m_openSound->setSource(QUrl::fromLocalFile(Config::SOUNDS_PATH["nikoOpenSound"]));
m_openSound->setLoopCount(1);
m_closeSound = new QSoundEffect;
m_closeSound->setSource(QUrl::fromLocalFile(Config::SOUNDS_PATH["nikoCloseSound"]));
m_closeSound->setLoopCount(1);
}
Niko::~Niko()
{
delete m_openSound;
m_openSound = nullptr;
delete m_closeSound;
m_closeSound = nullptr;
}
const QString &Niko::name() const
{
return m_name;
}
void Niko::move()
{
// can't move
}
void Niko::doCollide()
{
// won't collide
}
void Niko::advance(int)
{
AbstractMovableItem::advance(0);
if (m_step % Config::PETS_YIELD_STEP["niko"] == 0){
m_mature = true;
m_pixStateIndex = 0;
m_pixIndex = 0;
m_openSound->play();
}
if (m_step % Config::UPDATE_PAINT_STEP == 0){
if (m_mature || m_harvested){
m_pixIndex++;
update();
}
}
if (m_pixIndex == Config::PETS_INDEX_COUNT){
if (m_mature){
m_pixIndex--;
m_gainable = true;
m_mature = false;
}
else if (m_harvested){
m_pixIndex--;
m_harvested = false;
}
}
}
void Niko::findTarget()
{
// no target
}
void Niko::yield()
{
// do nothing
}
void Niko::mousePressEvent(QGraphicsSceneMouseEvent *)
{
if (m_gainable){
m_gainable = false;
m_harvested = true;
m_pixStateIndex = 1;
m_pixIndex = 0;
m_step = 0;
emit sgn_specialSkill("niko", scenePos());
m_closeSound->play();
}
}