/
Meteorite.cpp
64 lines (49 loc) · 1.45 KB
/
Meteorite.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
#include "Meteorite.h"
#include "globals.h"
const QColor meteo_clr( 130, 110, 77 );
CMeteorite::CMeteorite()
{
InitBody();
}
CMeteorite::CMeteorite( const int x, const int y, const QVector2D dir )
: CActor( x, y, dir )
{
InitBody();
}
void CMeteorite::InitBody()
{
m_body.append( QPoint( 0, 0 ) );
m_body.append( QPoint( mrand( meteo_size/2, meteo_size ), -mrand( meteo_size/2, meteo_size ) ) );
m_body.append( QPoint( meteo_size/2 - mrand( meteo_size/3, meteo_size/1.5 ), -mrand( meteo_size/2, meteo_size ) ) );
m_body.append( QPoint( -mrand( meteo_size/2, meteo_size ), -mrand( 0, meteo_size/1.5 ) ) );
m_body.append( QPoint( 0, 0 ) );
}
void CMeteorite::Draw( QPainter &painter, const float freq_tick )
{
painter.setPen( QPen( meteo_clr, 1 ) );
float tx = 0, ty = 0;
getTickCoords( freq_tick, tx, ty );
QPolygon m_tmp_bd( m_body );
m_tmp_bd.translate( tx, ty );
painter.drawPolygon( m_tmp_bd );
QPainterPath pt;
pt.addPolygon( m_tmp_bd );
painter.fillPath( pt, QBrush( Qt::black ));
painter.fillPath( pt, QBrush( meteo_clr, Qt::Dense2Pattern ));
}
bool CMeteorite::checkCollision( const qreal x, const qreal y )
{
return m_body.containsPoint( QPoint( x, y ), Qt::OddEvenFill );
}
QRect CMeteorite::getBoundsT()
{
QPolygon m_tmp_bd( m_body );
m_tmp_bd.translate( getX(), getY() );
return m_tmp_bd.boundingRect();
}
const QPolygon CMeteorite::getBodyT()
{
QPolygon m_tmp_bd( m_body );
m_tmp_bd.translate( getX(), getY() );
return m_tmp_bd;
}