-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrap.cpp
38 lines (32 loc) · 893 Bytes
/
trap.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
#include "trap.h"
#include <QDebug>
Trap::Trap(int x, int y, int activeType, QObject *parent, QPixmap img) : Block(x, y, img, parent), isActive(activeType)
{
}
void Trap::move(){
if(isActive < TRIGGERED) return;
// active trap
moveBy(0, fallSpeed+=G);
}
//void Trap::nextFrame(){
// counter = (counter + 1) % 50;
// setPixmap(QPixmap(":/pics/fire.png").copy(frameSequence[counter]*64, 0, 64, 114));
// update();
//}
void Trap::collideHero(Unit *hero){
if(isActive==PASSIVE&&hero->collideItemsList.contains(this)){// passive trap
hero->beAttacked();
return;
}
//active trap
if(isActive==TRIGGERED){
move();
}
else if(hero->y()>y()&&hero->x()>=x()&&hero->x()<=x()+boundingRect().width()){
isActive = TRIGGERED;
move();
}
if(hero->collideItemsList.contains(this)){
hero->beAttacked();
}
}