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 pathbullet.cpp
More file actions
80 lines (61 loc) · 2.07 KB
/
Copy pathbullet.cpp
File metadata and controls
80 lines (61 loc) · 2.07 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
#include "bullet.h"
#include "enemy.h"
#include <typeinfo>
#include <QDebug>
#include "health.h"
#include <QPixmap>
#define _USE_MATH_DEFINES
#include <QGraphicsPixmapItem>
#include <qmath.h>
#include "score.h"
#include "myevent.h"
//extern MainMenu * game;
Bullet::Bullet(QGraphicsPixmapItem *parent): QObject(),QGraphicsPixmapItem(parent)
{
//setRect(0,0,10,50);
setPixmap(QPixmap("qrc:/IMAGE/IMG/clash2.png"));
setTransform(transform().rotate(90));
}
Bullet::Bullet(qreal angle)
{
//setRect(0,0,10,50);
setPixmap(QPixmap("qrc:/IMAGE/IMG/clash2.png"));
setRotation(angle);
setTransform(transform().rotate(90));
}
double degreesToRadians(double degrees) {
return degrees * (M_PI / 180);
}
int Bullet::move()
{
// перемещение парня
int STEP_SIZE = 100;
double theta = rotation(); // 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(Enemy)){
// scene()->removeItem(colliding_items[i]);
//delete colliding_items[i];
scene()->removeItem(this);
delete this;
hp--;
return 1;
}
}
if(this->hp < 0 ||
pos().y()+/*rect().height()*/pixmap().height() < 0 ||
pos().x()+/*rect().height()*/pixmap().height() < 0 ||
pos().x()-/*rect().height()*/pixmap().height() > scene()->width() ||
pos().y()-/*rect().height()*/pixmap().height() > scene()->height()
){
scene()->removeItem(this);
delete this;
return 1;
//qDebug() << "DEL";
}
setPos(x()+dx, y()+dy);
return 0;
}