-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.cpp
44 lines (39 loc) · 1.07 KB
/
GameManager.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
#include "GameManager.h"
#include "InputManager.h"
const char *GameManager::WINDOW_TITLE{ "Game Engine" };
void GameManager::Start()
{
screenManager = ScreenManager{};
screenManager.Show("MainMenu");
isStarted = true;
AddGameobject(std::make_unique<Player>());
AddGameobject(std::make_unique<Wall>());
}
// Update is before the Draw
void GameManager::Update()
{
auto time = chrono.restart().asSeconds();
InputManager::UpdateInput();
for (auto i{ 0u }; i < gameObjects.size(); i++) {
gameObjects[i]->Update(time);
gameObjects[i]->AnimationUpdate(time);
for (auto j{ 0u }; j < gameObjects.size(); j++)
{
if (i != j && gameObjects[i]->CheckCollision(*gameObjects[j])) {
gameObjects[i]->TriggerCollision(*gameObjects[j]);
}
}
gameObjects[i]->GravityUpdate(time, gravityFactor);
}
}
void GameManager::Draw(sf::RenderWindow& window)
{
for (auto& gameObject : gameObjects) {
gameObject->Draw(window);
}
}
void GameManager::AddGameobject(std::unique_ptr<GameObject> gameObject)
{
gameObjects.push_back(std::move(gameObject));
gameObjects.back()->Start();
}