-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameUnit.cpp
62 lines (52 loc) · 1.28 KB
/
GameUnit.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
#include <QPainter>
#include <QList>
#include <QRectF>
#include <QPolygonF>
#include <QImage>
#include <math.h>
#include "Map.h"
#include "GameInfo.h"
#include "GameUnit.h"
GameUnit::GameUnit(GameInfo *info)
{
Info = info;
Sprite = 0;
State.Position = new QRectF(100.0, 100.0, 30.0, 30.0);
SetSelection(0);
}
GameUnit::~GameUnit()
{
delete State.Position;
}
void GameUnit::Draw(QPainter *painter)
{
/***/
// Îòðèñîâêà èçîáðàæåíèÿ þíèòà
painter->setPen(QColor(0xBE,0xBD,0xBB));
painter->setBrush(QBrush(QColor(0xFF,0xFF,0xFF), Qt::SolidPattern));
painter->drawPolygon(QPolygonF(*State.Position));
/***/
if (State.isSelected)
{ // Îòðèñîâêà ðàìêè, ïîëîñêè çäîðîâüÿ è ò.ï. âîêðóã þíèòà
// Îòðèñîâêà ðàìêè
painter->setPen(QColor(0x00,0xFF,0x00));
painter->setPen(Qt::DashDotLine);
painter->setBrush(Qt::NoBrush);
painter->drawPolygon(QPolygonF(*State.Position));
}
}
void GameUnit::DoitSomething(int dtime)
{
/***/
qreal T = (qreal)( dtime%100 )/100.0*6.283;
if ( State.Position->x()+State.Position->width()<Info->Map->Size.width()
&& State.Position->y()+State.Position->height()<Info->Map->Size.height())
{
State.Position->translate(-1.0*cos(T) + T, 1.0*sin(T) + T);
}
/***/
}
void GameUnit::SetSelection(int selection)
{
State.isSelected = selection;
}