-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.cpp
50 lines (42 loc) · 1.24 KB
/
scene.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
#include "scene.h"
#include <map>
#include <vector>
#include "findGLUT.h"
#include "game_object.h"
#include "player_object.h"
Scene::Scene() {
screen = START_SCREEN;
SCENE_BBOX.partition(partitions, PARTITION_SIZE.x, PARTITION_SIZE.y, PARTITION_SIZE.z);
}
void Scene::update() {
std::vector<GameObject *> *objects = screenToObjects[screen];
for (GameObject *object: *objects) {
if (!object->destroyed()) {
object->update();
}
}
}
void Scene::draw() {
std::vector<GameObject *> *objects = screenToObjects[screen];
for (GameObject *object: *objects) {
if (!object->destroyed()) {
object->draw();
}
}
}
void Scene::addObject(int screen, GameObject *object) {
std::vector<GameObject *> *currObjects;
if (screenToObjects.count(screen) == 0) {
currObjects = new std::vector<GameObject *>();
screenToObjects.insert(std::pair<int, std::vector<GameObject *> *>(screen, currObjects));
} else {
currObjects = screenToObjects[screen];
}
currObjects->push_back(object);
}
void Scene::restore(int screen) {
std::vector<GameObject *> *objects = screenToObjects[screen];
for (GameObject *object: *objects) {
object->restore();
}
}