-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboss.cpp
98 lines (75 loc) · 1.89 KB
/
boss.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
92
93
94
95
96
97
98
#include "boss.h"
Boss::Boss(QGraphicsItem *parent)
: QGraphicsRectItem(parent)
{
health->setHealth(500);
isDefense = false;
setRect(0,-100,100,100);
check = new QTimer(this);
connect(check,SIGNAL(timeout()),this,SLOT(checkCollided()));
check->start(10);
}
Boss::~Boss()
{
this->deleteLater();
}
QRectF Boss::boundingRect() const
{
return rect();
}
void Boss::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if(isDefense)
{
painter->setPen(Qt::white);
painter->drawRect(option->rect);
}
else
{
painter->setPen(Qt::NoPen);
painter->drawRect(option->rect);
}
painter->drawPixmap(option->rect,QPixmap(":/images/youngbuffalo.jpg"));
}
void Boss::setStartPos()
{
setPos(200,100);
}
void Boss::attack()
{
}
void Boss::defense()
{
health->setHealth(health->getHealth() + 50);
QPropertyAnimation* animation = new QPropertyAnimation(this,"pos",this);
connect(animation,SIGNAL(finished()),this,SLOT(setStartPos()));
connect(animation,SIGNAL(finished()),animation,SLOT(deleteLater()));
animation->setDuration(2000);
animation->setStartValue(pos());
animation->setEndValue(QPointF(200,100));
animation->start();
}
void Boss::offensive()
{
}
void Boss::checkCollided()
{
if(collidesWithItem(scene()->focusItem())) {
delete scene()->focusItem();
}
QList<QGraphicsItem*> list_bullet = collidingItems();
foreach (QGraphicsItem* item, list_bullet) {
if(typeid(*item) == typeid(Bullet)) {
delete item;
health->decreaseHealth();
}
else if(typeid(*item) == typeid(Bullet2)) {
delete item;
health->decreaseHealth2();
}
else if(typeid(*item) == typeid(Bullet3)) {
delete item;
health->decreaseHealth3();
}
}
}