-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeder.cpp
52 lines (47 loc) · 1.45 KB
/
breeder.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
#include "breeder.h"
Breeder::Breeder(qreal w, qreal h, const QPointF &pos,
const QPixmaps2 &pixs2, QGraphicsScene *scene,
QGraphicsItem *parent)
: AbstractFish(w, h, pos, pixs2, scene, parent)
{
}
void Breeder::advance(int)
{
AbstractFish::advance(0);
}
void Breeder::doCollide()
{
if (!m_hasTarget){
return;
}
foreach (QGraphicsItem * t, collidingItems()) {
AbstractGameItem * gameItem
= dynamic_cast<AbstractGameItem *> (t);
if (Config::COLLIDABLE_ITEMS[name()]
.contains(gameItem->name())){
Food * food = dynamic_cast<Food *> (gameItem);
eat(food->eatenExp());
food->vanish();
}
}
}
void Breeder::findFood()
{
QList<QGraphicsItem*> items_ = scene()->items();
QVector<AbstractMovableItem*> edibleItems;
foreach (QGraphicsItem * item, items_) {
AbstractGameItem * gameItem
= dynamic_cast<AbstractGameItem *> (item);
if (Config::COLLIDABLE_ITEMS[name()]
.contains(gameItem->name())
&& gameItem->isVisible()){
edibleItems.append(dynamic_cast<AbstractMovableItem *>(gameItem));
}
}
if (edibleItems.size() > 0){
m_target = edibleItems.at(RandomMaker::creatRandom(edibleItems.size()));
m_hasTarget = true;
connect(m_target, SIGNAL(sgn_deleting()),
this, SLOT(slt_lostAim()));
}
}