This repository was archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.cpp
More file actions
111 lines (88 loc) · 2.61 KB
/
Copy pathenemy.cpp
File metadata and controls
111 lines (88 loc) · 2.61 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <enemy.h>
#include <stdlib.h> //rand()
#include <typeinfo>
#include "game.h"
#include "health.h"
#include <QDebug>
#include <qmath.h>
#include "bullet.h"
#include "score.h"
Enemy::Enemy()
{
setRect(0,0,10,50);
//таймер
int random_number = rand() % 700+50;
setPos(random_number,0);
}
Enemy::Enemy(qreal xpp,qreal ypp,qreal angle)
{
setRect(0,0,10,50);
setPos(xpp,ypp);
setRotation(angle);
}
int Enemy::move()
{
// перемещение парня
int STEP_SIZE = 1;
double theta = rotation()+90; // degrees
double dy = STEP_SIZE * qSin(theta*(M_PI/180));
double dx = STEP_SIZE * qCos(theta*(M_PI/180));
// сделать поиск цели через сцену !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
QList<QGraphicsItem *> colliding_items = collidingItems();
for(int i = 0, n = colliding_items.size(); i < n; ++i ){
if(typeid(*(colliding_items[i])) == typeid(MyPlayer)){
// scene()->removeItem(colliding_items[i]);
//delete colliding_items[i];
scene()->removeItem(this);
delete this;
return 1;
} else if (typeid(*(colliding_items[i]))==typeid(Bullet)){
hp--;
}
}
if(this->hp < 0 ||
pos().y()+rect().height() < 0 ||
pos().x()+rect().height() < 0 ||
pos().x()-rect().height() > scene()->width() ||
pos().y()-rect().height() > scene()->height()
){
scene()->removeItem(this);
delete this;
return 1;
//qDebug() << "DEL";
}
setPos(x()+dx, y()+dy);
return 0;
}
/*
void Tower::aquire_target(){
// get a list of all items colliding with attack_area
QList<QGraphicsItem *> colliding_items = attack_area->collidingItems();
if (colliding_items.size() == 1){
has_target = false;
return;
}
double closest_dist = 300;
QPointF closest_pt = QPointF(0,0);
for (size_t i = 0, n = colliding_items.size(); i < n; i++){
Enemy * enemy = dynamic_cast<Enemy *>(colliding_items[i]);
if (enemy){
double this_dist = distanceTo(enemy);
if (this_dist < closest_dist){
closest_dist = this_dist;
closest_pt = colliding_items[i]->pos();
has_target = true;
}
}
}
attack_dest = closest_pt;
fire();
double Tower::distanceTo(QGraphicsItem *item){
QLineF ln(pos(),item->pos());
return ln.length();
}
void Enemy::rotateToPoint(QPointF p){
QLineF ln(pos(),p);
setRotation(-1 * ln.angle());
}
}*/