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 pathdraft_things
More file actions
69 lines (58 loc) · 2.22 KB
/
Copy pathdraft_things
File metadata and controls
69 lines (58 loc) · 2.22 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
// drag'n'drop func
void object::mousePressEvent(QMouseEvent *event)
{
QRect p = this->geometry();
if(event->button() == Qt::LeftButton)
{
lastPoint = event->pos();
b_move = true;
}
}
void object::mouseMoveEvent(QMouseEvent *event)
{
if((event->buttons() & Qt::LeftButton) && b_move)
move(event->globalX()-lastPoint.x(),
event->globalY()-lastPoint.y());
}
void object::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && b_move) {
b_move = false;
}
}
// rotation player
//QPointF point !!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
void Game::slotMyPlayerMouse()
{
// Определяем расстояние до цели mapFromScene(target)
//target = point;
QLineF lineToTarget(QPointF(myIgrok1->pos().x(), myIgrok1->pos().y()), target->toPoint());
// Угол поворота в направлении к цели
qreal angleToTarget = acos(lineToTarget.dx() / lineToTarget.length());
/*if (lineToTarget.dy() < 0)
angleToTarget = -1 * angleToTarget;
*/
//angleToTarget = angleToTarget - 90;
//angleToTarget = normalizeAngle((M_PI - angleToTarget) + M_PI / 2);
//qDebug() <<"X: "<< target->x();
//qDebug() <<"Y: "<< target->y();
// В Зависимости от того, слева или справа находится Цель от Героя,
// устанавливаем направление поворота Героя в данном тике таймера
if (lineToTarget.dy() > 0){
if (angleToTarget >= 0 && angleToTarget < M_PI) {
// Rotate left
myIgrok1->setRotation((angleToTarget * 180) /M_PI+90);
} else if (angleToTarget <= M_2_PI && angleToTarget > M_PI) {
// Rotate right
myIgrok1->setRotation((angleToTarget - M_2_PI )* (-180) /M_PI+90);
}
} else {
if (angleToTarget >= 0 && angleToTarget < M_PI) {
// Rotate left
myIgrok1->setRotation(((angleToTarget * 180) /M_PI)*-1+90);
} else if (angleToTarget <= M_2_PI && angleToTarget > M_PI) {
// Rotate right
myIgrok1->setRotation(((angleToTarget - M_2_PI )* (-180) /M_PI)*-1+90);
}
}
}