-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.cpp
50 lines (40 loc) · 1.21 KB
/
tile.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
#include "tile.h"
#include <QtWidgets>
QPixmap *Tile::kSpriteImage = nullptr;
Tile::Tile(enum Type nType, Position nPos) : kType(nType), kPos(nPos) {
switch (nType) {
case Type::kLand:
kSpriteOffset = 0;
break;
case Type::kWater:
kSpriteOffset = TILE_WIDTH;
break;
case Type::kPokeCenter:
kSpriteOffset = TILE_WIDTH*2;
break;
case Type::kPokeGym:
kSpriteOffset = TILE_WIDTH*3;
break;
}
}
// set Tile position
QRectF Tile::boundingRect() const {
auto pos = kPos.Convert();
return QRectF(pos.x_, pos.y_, TILE_WIDTH, TILE_WIDTH);
}
// set Tile shape
QPainterPath Tile::shape() const {
QPainterPath path;
auto pos = kPos.Convert();
path.addRect(pos.x_, pos.y_, TILE_WIDTH, TILE_WIDTH);
return path;
}
// set Tile visibility traits (color, size)
void Tile::paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) {
Q_UNUSED(widget);
Q_UNUSED(item);
auto b = painter->brush();
auto pos = kPos.Convert();
painter->drawPixmap(pos.x_, pos.y_, *kSpriteImage, kSpriteOffset, 0, TILE_WIDTH, TILE_WIDTH);
painter->setBrush(b);
}