-
Notifications
You must be signed in to change notification settings - Fork 2
/
robotbase.cpp
194 lines (159 loc) · 4.59 KB
/
robotbase.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QPainter>
#include "robotbase.h"
RobotBase::RobotBase() :
m_pos(QPointF(0, 0)),
m_angle(0.0)
{
}
QPointF RobotBase::pos() const
{
return m_pos;
}
void RobotBase::setPos(const QPointF &pos)
{
m_pos = pos;
}
void RobotBase::paintRobot(QPainter *painter)
{
//Draw the robot.
painter->drawEllipse(m_pos, m_robotSize, m_robotSize);
}
void RobotBase::paintRobotParameter(QPainter *painter)
{
//Draw the direction of the robot.
QLineF directionLine(m_pos, m_pos+QPointF(m_detectRadius, 0));
directionLine.setAngle(m_angle);
painter->drawLine(directionLine);
}
void RobotBase::paintRobotDetectArea(QPainter *painter)
{
//Draw the detect radius.
m_detectRadiusGradient.setFocalPoint(m_pos);
m_detectRadiusGradient.setCenter(m_pos);
painter->setBrush(m_detectRadiusGradient);
painter->drawEllipse(m_pos, m_detectRadius, m_detectRadius);
}
void RobotBase::paintEnemyDetectArea(QPainter *painter)
{
//Draw the enemy detect radius.
m_enemyRadiusGradient.setFocalPoint(m_pos);
m_enemyRadiusGradient.setCenter(m_pos);
painter->setBrush(m_enemyRadiusGradient);
painter->drawEllipse(m_pos, m_detectRadius, m_detectRadius);
}
int RobotBase::m_robotSize=3;
int RobotBase::robotSize()
{
return m_robotSize;
}
void RobotBase::setRobotSize(int robotSize)
{
m_robotSize = robotSize;
}
int RobotBase::m_detectRadius=20;
int RobotBase::detectRadius()
{
return m_detectRadius;
}
void RobotBase::setDetectRadius(int detectRadius)
{
m_detectRadius = detectRadius;
}
QColor RobotBase::m_robotColor=QColor(59,120,133);
void RobotBase::setRobotColor(const QColor &robotColor)
{
m_robotColor=robotColor;
}
QColor RobotBase::robotColor()
{
return m_robotColor;
}
QColor RobotBase::m_detectRadiusColor=QColor(44,132,99);
QColor RobotBase::detectRadiusColor()
{
return m_detectRadiusColor;
}
void RobotBase::setDetectRadiusColor(const QColor &detectRadiusColor)
{
m_detectRadiusColor = detectRadiusColor;
//Change the gradient color.
m_detectRadiusGradient.setColorAt(1, m_detectRadiusColor);
}
qreal RobotBase::angle() const
{
return m_angle;
}
void RobotBase::setAngle(const qreal &angle)
{
m_angle = angle;
//Change the angle.
while(m_angle>360.0)
{
m_angle-=360.0;
}
while(m_angle<0.0)
{
m_angle+=360.0;
}
}
QColor RobotBase::m_directionLineColor=QColor(98, 228, 238);
QColor RobotBase::directionLineColor()
{
return m_directionLineColor;
}
void RobotBase::setDirectionLineColor(const QColor &detectLineColor)
{
m_directionLineColor = detectLineColor;
}
QRadialGradient RobotBase::m_detectRadiusGradient=QRadialGradient();
void RobotBase::initialRobotPatameters()
{
//Initial the detected radius gradient.
m_detectRadiusGradient.setRadius(m_detectRadius);
m_detectRadiusGradient.setColorAt(0, QColor(0,0,0,0));
m_detectRadiusGradient.setColorAt(0.6, QColor(0,0,0,0));
m_detectRadiusGradient.setColorAt(1, m_detectRadiusColor);
//Initial the enemy detected radius gradient.
m_enemyRadiusGradient.setRadius(m_detectRadius);
m_enemyRadiusGradient.setColorAt(0, QColor(0,0,0,0));
m_enemyRadiusGradient.setColorAt(0.6, QColor(0,0,0,0));
m_enemyRadiusGradient.setColorAt(1, m_enemyRadiusColor);
}
QColor RobotBase::m_robotBorder=QColor(255,255,255);
QColor RobotBase::robotBorder()
{
return m_robotBorder;
}
void RobotBase::setRobotBorder(const QColor &robotBorder)
{
m_robotBorder = robotBorder;
}
QColor RobotBase::m_enemyRadiusColor=QColor(255,0,0);
QRadialGradient RobotBase::m_enemyRadiusGradient=QRadialGradient();
QColor RobotBase::enemyRadiusColor()
{
return m_enemyRadiusColor;
}
void RobotBase::setEnemyRadiusColor(const QColor &enemyRadiusColor)
{
m_enemyRadiusColor = enemyRadiusColor;
//Change the gradient color.
m_enemyRadiusGradient.setColorAt(1, m_enemyRadiusColor);
}