-
Notifications
You must be signed in to change notification settings - Fork 0
/
TileMapParticle.cpp
100 lines (74 loc) · 1.58 KB
/
TileMapParticle.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
#include "TileMapParticle.h"
TileMapParticle::TileMapParticle()
: TileMap()
, ps(NULL)
{
TYPE_ID = TILE_MAP_PARTICLE_ID;
ps_name = "";
ps = NULL;
}
TileMapParticle::TileMapParticle(char *texture_name, char *name_particle, hgeVector pos, short xw, short yw, short layer)
: TileMap(texture_name, pos, xw, yw, layer)
{
TYPE_ID = TILE_MAP_PARTICLE_ID;
ps_name = name_particle;
ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) );
ps->FireAt(pos.x, pos.y);
}
TileMapParticle::~TileMapParticle()
{
if (ps)
{
delete ps;
ps = NULL;
}
ps_name.clear();
}
void TileMapParticle::Render()
{
TileMap::Render();
if (ps)
{
ps->Render();
}
}
void TileMapParticle::Save(std::ofstream *f)
{
TileMap::Save(f);
size_t l = ps_name.length();
f->write((const char *)&l, sizeof(size_t));
f->write(ps_name.c_str(), l*sizeof(char));
}
void TileMapParticle::Load(std::ifstream *f)
{
TileMap::Load(f);
ps_name.clear();
size_t l = 0;
f->read((char *)&l, sizeof(size_t));
char *name = new char[l];
f->read(name, l*sizeof(char));
ps_name = name;
if (ps)
{
delete ps;
}
ps = new hgeParticleSystem( *(resources_manager->GetParticleSystem( ps_name.c_str() )) );
ps->Fire();
}
void TileMapParticle::UpdateGraphic()
{
float dt = hge->Timer_GetDelta();
ps->Update(dt);
}
void TileMapParticle::Play()
{
ps->Fire();
}
void TileMapParticle::Stop()
{
ps->Stop();
}
void TileMapParticle::MoveParticle(float x, float y, bool move)
{
ps->MoveTo(x, y, move);
}