-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
83 lines (65 loc) · 2.7 KB
/
GameManager.cpp
File metadata and controls
83 lines (65 loc) · 2.7 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
#include "GameManager.h"
GameManager::GameManager(std::shared_ptr<Maro> aMaro, Map& aMap, std::shared_ptr<LevelManager> aLevelManager, std::vector<std::shared_ptr<Roomba>>& aRoombas, std::vector<std::shared_ptr<Mushroom>>& aMushrooms) {
maro = aMaro;
levelManager = aLevelManager;
roombas = aRoombas;
mushrooms = aMushrooms;
map = aMap;
}
void GameManager::update_objects(const unsigned int& aViewX, unsigned int& aCount) {
maro->update(*levelManager, aViewX, map, roombas, mushrooms, aCount);
for (unsigned short i = 0; i < roombas.size(); i++) {
if (roombas[i]->get_death_timer() == 0) {
roombas.erase(roombas.begin() + i);
}
}
for (std::shared_ptr<Roomba> roomba : roombas) {
roomba->update(map, aViewX, roombas);
}
for (std::shared_ptr<Mushroom> mushroom : mushrooms) {
mushroom->move(aViewX, map);
}
}
void GameManager::draw(sf::RenderWindow& aWindow, const unsigned int& aViewX, sf::View& aView, const sf::Color& aBackgroundColor, const sf::Texture& aMapTexture) {
aView.reset(sf::FloatRect(aViewX, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
aWindow.setView(aView);
aWindow.clear(aBackgroundColor);
levelManager->draw_map(1, aViewX, aWindow, aBackgroundColor, aMapTexture, map);
for (std::shared_ptr<Mushroom> mushroom : mushrooms) {
mushroom->draw(aViewX, aWindow);
}
levelManager->draw_map(0, aViewX, aWindow, aBackgroundColor, aMapTexture, map);
levelManager->update();
maro->draw(aWindow);
for (std::shared_ptr<Roomba> roomba : roombas) {
roomba->draw(aWindow);
}
}
void GameManager::change_level(unsigned short& aLevelFinish, unsigned short& aCurrentLevel, sf::Image& aMapSketch, sf::Color& aBackgroundColor, const unsigned int& aCount, unsigned int& aLastLevelPoints, const sf::Time elapsed1, float& aLastLevelTime) {
if ((maro->get_x() >= CELL_SIZE * aLevelFinish && aCurrentLevel == 0) || (aCurrentLevel == 1 && maro->get_x() >= CELL_SIZE * aLevelFinish && maro->get_y() >= SCREEN_HEIGHT - 6 * CELL_SIZE)) {
aCurrentLevel++;
roombas.clear();
mushrooms.clear();
maro->reset();
aMapSketch.loadFromFile(MAP_PATH + "LevelSketch" + std::to_string(aCurrentLevel) + ".png");
levelManager->set_sketch(aMapSketch);
map = levelManager->sketch_to_map(*maro, aLevelFinish, aBackgroundColor, roombas);
aLastLevelPoints = aCount;
aLastLevelTime = elapsed1.asSeconds();
}
}
std::vector<std::shared_ptr<Mushroom>> GameManager::get_mushrooms() const {
return mushrooms;
}
std::vector<std::shared_ptr<Roomba>> GameManager::get_roombas() const {
return roombas;
}
std::shared_ptr<Maro> GameManager::get_maro() const {
return maro;
}
std::shared_ptr<LevelManager> GameManager::get_level_manager() const {
return levelManager;
}
Map GameManager::get_map() const {
return map;
}