-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel.js
More file actions
43 lines (36 loc) · 996 Bytes
/
level.js
File metadata and controls
43 lines (36 loc) · 996 Bytes
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
class Level {
constructor(components) {
this.components = components;
}
}
class LevelManager {
constructor() {
this.levels = [];
this.currentLevel = null;
}
loadLevel(level) {
// Unload the current level
if (this.currentLevel) {
this.unloadLevel(this.currentLevel);
}
// Add the components of the new level to the engine
for (const component of level.components) {
engine.addComponent(component);
}
this.currentLevel = level;
}
unloadLevel(level) {
// Remove the components of the level from the engine
for (const component of level.components) {
engine.removeComponent(component);
}
}
}
const level1 = new Level([component1, component2, component3]);
const level2 = new Level([component4, component5, component6]);
const levelManager = new LevelManager();
levelManager.levels.push(level1, level2);
// To load level 1:
levelManager.loadLevel(level1);
// To load level 2:
levelManager.loadLevel(level2);