-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition.cpp
More file actions
42 lines (33 loc) · 907 Bytes
/
position.cpp
File metadata and controls
42 lines (33 loc) · 907 Bytes
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
#include "position.h"
#include <QPainter>
const QSize Position::ms_fixedSize(90, 90);
Position::Position(QPoint pos, const QPixmap &sprite)
: m_hasTower(false)
, m_pos(pos)
, m_sprite(sprite)
{
}
//找到塔坑中心点
const QPoint Position::centerPos() const
{
QPoint offsetPoint(ms_fixedSize.width()/5, ms_fixedSize.height() /5);
return m_pos + offsetPoint;
}
bool Position::containPoint(const QPoint &pos) const
{
bool isXInHere = m_pos.x() < pos.x() && pos.x() < (m_pos.x() + ms_fixedSize.width());
bool isYInHere = m_pos.y() < pos.y() && pos.y() < (m_pos.y() + ms_fixedSize.height());
return isXInHere && isYInHere;
}
bool Position::hasTower() const
{
return m_hasTower;
}
void Position::setHasTower(bool hasTower)
{
m_hasTower = hasTower;
}
void Position::draw(QPainter *painter) const
{
painter->drawPixmap(m_pos.x(), m_pos.y(), m_sprite);
}