-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCEntity.cpp
More file actions
118 lines (97 loc) · 2.54 KB
/
CEntity.cpp
File metadata and controls
118 lines (97 loc) · 2.54 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "CEntity.h"
CEntity::entityFactory::map_type* CEntity::entityFactory::map = nullptr;
std::pair<std::string, MAPSTORAGE> CEntity::_mapSwapCall = std::make_pair("NULL", disk);
std::vector<std::string> CEntity::_localEvents = std::vector<std::string>();
std::queue<CEntCreation> CEntity::_entCreation = std::queue<CEntCreation>();
std::queue<std::string> CEntity::_entDestruction = std::queue<std::string>();
CEntity::CEntity()
{
for (int i = 0; i < _localEvents.size(); i++)
{
std::string x = _localEvents[i];
_myEvents.insert(std::make_pair(x, false));
}
_destroy = false;
_enabled = true;
scale.x = 1;
scale.y = 1;
scale.z = 1;
}
void CEntity::attachShaders(const char * vertex, const char * fragment)
{
/*if (_sprite.isNull())
return;*/
_sprite.attachShaders(vertex, fragment);
}
int CEntity::getEntDestructionSize()
{
return _entDestruction.size();
}
std::string CEntity::getNextEntDestroyer()
{
std::string out = _entDestruction.back();
_entDestruction.pop();
return out;
}
CEntity * CEntity::getNextCollision()
{
CEntity * out = _collidedWith.back();
_collidedWith.pop();
return out;
}
void CEntity::addCollision(CEntity * collider)
{
_collidedWith.push(collider);
}
void CEntity::initialize(std::string name, int x, int y, int layer, std::string sprite)
{
this->position.x = x;
this->position.y = y;
_layer = layer;
_mapName = name;
if (sprite != "")
_sprite = CContent::createSprite(sprite, vector3D(x,y,0));
}
std::pair<std::string, MAPSTORAGE> CEntity::popMapSwaps()
{
if (_mapSwapCall.first == "NULL")
return std::make_pair("NULL", disk);
else
return _mapSwapCall;
}
void CEntity::_createEntity(std::string entityType, std::string name, int x, int y, int layer)
{
CEntCreation ent(entityType, name, x, y, layer);
_entCreation.push(ent);
}
void CEntity::_swapMap(std::string mapName, MAPSTORAGE location)
{
_mapSwapCall = std::make_pair(mapName, disk);
}
void CEntity::resetMapSwap()
{
_mapSwapCall = std::make_pair("NULL", disk);
}
void CEntity::addLocalEvent(std::string eventName)
{
_localEvents.insert(_localEvents.end(), eventName);
}
int CEntity::getEntCreationSize()
{
return _entCreation.size();
}
void CEntity::_frame()
{
_oldPosition = position;
velocity += (vector3D)acceleration;
position += (vector3D)velocity;
momentum = phys::momentum::calcMomentum(velocity, mass);
force = phys::force::calcForce(acceleration, mass);
kinetic = phys::energy::calcKineticEnergy(velocity, mass);
}
CEntCreation CEntity::getNextEntCreator()
{
CEntCreation out = _entCreation.back();
_entCreation.pop();
return out;
}