-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraptile.cpp
More file actions
executable file
·52 lines (44 loc) · 1.25 KB
/
traptile.cpp
File metadata and controls
executable file
·52 lines (44 loc) · 1.25 KB
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 "traptile.h"
#include "player.h"
#include "monster.h"
#include "goblin.h"
TrapTile::TrapTile(QPoint p):Tiles(p){
QPixmap pixmap(":/Pictures/TilePictures/TilePictures/GrassTile.png");
pixmap = pixmap.scaled(80,80);
setPixmap(pixmap);
}
void TrapTile::setActive(){
isActive = true;
QPixmap pixmap(":/Pictures/TilePictures/TilePictures/Spikes.png");
pixmap = pixmap.scaled(80,80);
QRect rect(0,40,80,40);
pixmap = pixmap.copy(rect);
setPixmap(pixmap);
moveBy(0,40);
}
void TrapTile::collidedWith(Player *p){
if (isActive){
p->minusHealth();
p->bounce(-3);
p->moveBy(0,-20);
return;
}
QRectF intersection = sceneBoundingRect() & p->sceneBoundingRect();
if (intersection.width() >= intersection.height()&&
p->boundingRect().width()/1.5<=intersection.width()){
setActive();
}
}
void TrapTile::collidedWith(Monster *m){
if (isActive){
m->minusHealth();
m->bounce(-3);
m->moveBy(0,-20);
return;
}
QRectF intersection = sceneBoundingRect() & m->sceneBoundingRect();
if (intersection.width() >= intersection.height()&&
m->boundingRect().width()/1.5<=intersection.width()){
setActive();
}
}