-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityManager.cpp
55 lines (43 loc) · 1.16 KB
/
EntityManager.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
#include "EntityManager.h"
#include <cassert>
#include "game.h"
#include "settings.h"
#include "template.h"
#include "Transform.h"
#include "PlayerController.h"
#include "surface.h"
void EntityManager::Update()
{
if (!isActive)
return;
spawn_timer -= PlayerController::GetYMovement();
if (spawn_timer < 0.0f)
{
for (int i = 0; i < difficulty * 2; i++)
Activate({ static_cast<float>(IRand(1000 - settings::tileSize * 2) + settings::tileSize), static_cast<float>(tmpl8::Game::Get().GetScreen()->GetHeight()) + settings::tileSize });
spawn_timer = static_cast<float>(settings::tileSize);
}
}
void EntityManager::Deactivate(Entity& e)
{
e.SetActive(false);
const auto iter = std::find(active.begin(), active.end(), &e);
inactive.push(*iter);
active.erase(iter);
}
void EntityManager::Activate(const tmpl8::vec2 pos)
{
if (!inactive.empty())
{
inactive.front()->SetActive(true);
Transform* transform = inactive.front()->GetComponent<Transform>();
assert(transform != nullptr);
transform->SetPosition(pos);
active.push_back(inactive.front());
inactive.pop();
}
else
{
tmpl8::Game::Get().AddObstacle(pos);
}
}