-
Notifications
You must be signed in to change notification settings - Fork 5
/
GameObject.cpp
90 lines (84 loc) · 2.35 KB
/
GameObject.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
std::shared_ptr<Program::GameObject> Program::CreateObject(uint8_t name, int32_t x, int32_t y, bool direction, bool actual_object)
{
//ищем пустой слот объекта
for (uint32_t i = 0; i < game_objects.size(); i++)
{
if (game_objects[i]->Name == 0)
{
std::shared_ptr<GameObject> obj = std::make_shared<GameObject>();
obj->Name = name;
obj->X = x;
obj->Y = y;
obj->Direction = direction;
game_objects[i] = obj;
if (actual_object)
{
AddActualObject(obj);
}
return obj;
}
}
return game_objects[127];
}
void Program::RemoveObject(const std::shared_ptr<GameObject> &obj)
{
RemoveActualObject(obj);
obj->Name = 0;
}
void Program::ClearAllObjects()
{
for (size_t i = 0; i < game_objects.size(); i++)
{
std::shared_ptr<GameObject> obj = std::make_shared<GameObject>();
obj->Name = 0;
game_objects[i] = obj;
}
ClearActualObjectsList();
particle_cntr = 0;
}
void Program::ClearActualObjectsList()
{
for (size_t i = 0; i < actual_objects.size(); i++)
{
std::shared_ptr<GameObject> obj = std::make_shared<GameObject>();
obj->Name = 0;
actual_objects[i] = obj;
}
}
void Program::AddActualObject(const std::shared_ptr<GameObject> &obj)
{
for (size_t i = 0; i < actual_objects.size(); i++)
{
if (actual_objects[i]->Name == 0)
{
actual_objects[i] = obj;
break;
}
}
}
void Program::RemoveActualObject(const std::shared_ptr<GameObject> &obj)
{
for (size_t i = 0; i < actual_objects.size(); i++)
{
if (actual_objects[i] == obj)
{
for (size_t j = i; j < actual_objects.size() - 1; j++)
{
if (actual_objects[j]->Name == 0)
{
break;
}
actual_objects[j] = actual_objects[j + 1];
}
break;
}
}
}
std::shared_ptr<Program::GameObject> Program::CreateChild(const std::shared_ptr<Program::GameObject> &obj, uint8_t name, int32_t xoffset, int32_t yoffset)
{
if (obj->Direction)
{
xoffset = -xoffset;
}
return CreateObject(name, obj->X + xoffset, obj->Y + yoffset, obj->Direction, true);
}