This repository has been archived by the owner on Mar 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlammedArrowOctopus.cpp
104 lines (74 loc) · 2.64 KB
/
FlammedArrowOctopus.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
#include "FlammedArrowOctopus.h"
FlammedArrowOctopus::FlammedArrowOctopus(Panel* container, GridOctopus* gridO, Spell* s, Character* caster, SpellTarget* target)
: OctopusBaby(int(gridO->getCellDimensions().x * 3), int(gridO->getCellDimensions().y * 3)), _grid(gridO), _spell(s), _caster(caster), _target(target)
{
Texture t = (*ServiceLocator::getTextureManager())["FlammedArrowFrame1"];
//_tex = t;
Point d = gridO->getCellDimensions() * 1.5;
// compute ratio
double ratiox = (double)d.x / t.getWidth();
double ratioy = (double)d.y / t.getHeight();
ratio = min(ratioy, ratiox);
unsigned int n = target->getCell()->getNumber();
Point cellCenter = gridO->getCellCenter(n);
//pour le caster en dessous
n = caster->getCell()->getNumber();
Point departCenter = gridO->getCellCenter(n);
width = int(t.getWidth() * ratio);
height = int(t.getHeight() * ratio);
container->add(this);
Point pos = toContainerCoordinates(gridO->toAbsoluteCoordinates(Point(departCenter.x - width / 2, departCenter.y - height)));
ori_pos = pos;
dst_pos = toContainerCoordinates(gridO->toAbsoluteCoordinates(Point(cellCenter.x - width / 2, cellCenter.y - height)));
setPositionX((int)pos.x);
setPositionY((int)pos.y);
setBgColor(Color::TRANSPARENT);
setActive(true);
beginTime = TIMESERVICE->time();
finishTime = beginTime + totalTime;
setZIndex(gridO->getZIndexFromCell(n) + 1);
}
FlammedArrowOctopus::~FlammedArrowOctopus()
{
}
void FlammedArrowOctopus::update()
{
if (isActive())
{
Uint32 now = TIMESERVICE->time();
if (now > finishTime)
setActive(false);
else if (now > beginTime)
{
string name = "FlammedArrowFrame";
int nbFrame = 4;
Uint32 timePerFrame = 50;
Uint32 now = TIMESERVICE->getFrameTime();
Uint32 elapsed = now - beginTime;
int n = (elapsed / timePerFrame) % 4 + 1;
setIfDifferent(_tex, (*ServiceLocator::getTextureManager())[name + to_string(n)]);
Uint32 dt = now - (beginTime);
Point delta = dst_pos - ori_pos;
Point step = (delta * dt) / (totalTime);
Point newPos = ori_pos + step;
setPositionX((int)newPos.x);
setPositionY((int)newPos.y);
}
}
}
void FlammedArrowOctopus::internalRender(SDL_Renderer* r, bool force)
{
if (isActive())
{
bool d = (force || isDirty());
Point from = _grid->getCellCenter(_caster->getCell()->getNumber());
Point to = _grid->getCellCenter(_target->getCell()->getNumber());
from.x -= 15;
to.x -= 15;
Point delta = to - from;
double angle = getAngleFromPoint(from, to) - 90;
SDL_Rect dst = { 0, (height + 10) / 2, width, height };
SDL_Point center = { 15, 0 };
SDL_RenderCopyEx(r, _tex, nullptr, &dst, angle, nullptr, SDL_FLIP_VERTICAL);
}
}