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
84
85
|
#define private public
#include "api/LoopManager.h"
#include <iostream>
#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
#include <crepe/api/Scene.h>
#include <crepe/api/SceneManager.h>
#include <crepe/api/Vector2.h>
using namespace crepe;
using namespace std;
class ConcreteScene1 : public Scene {
public:
using Scene::Scene;
void load_scene() {
auto & mgr = this->component_manager;
GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1);
GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1);
GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1);
}
string get_name() { return "scene1"; }
};
class ConcreteScene2 : public Scene {
public:
using Scene::Scene;
void load_scene() {
auto & mgr = this->component_manager;
GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1);
GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1);
GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1);
GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1);
}
string get_name() { return "scene2"; }
};
int main() {
LoopManager loop_mgr;
// Add the scenes to the scene manager
loop_mgr.add_scene<ConcreteScene1>();
loop_mgr.add_scene<ConcreteScene2>();
// There is no need to call set_next_scene() at the beginnen, because the first scene will be
// automatically set as the next scene
// Load scene1 (the first scene added)
loop_mgr.scene_manager.load_next_scene();
// Get the Metadata components of each GameObject of Scene1
vector<reference_wrapper<Metadata>> metadata
= loop_mgr.component_manager.get_components_by_type<Metadata>();
cout << "Metadata components of Scene1:" << endl;
// Print the Metadata
for (auto & m : metadata) {
cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name
<< " Tag: " << m.get().tag << endl;
}
// Set scene2 as the next scene
loop_mgr.scene_manager.set_next_scene("scene2");
// Load scene2
loop_mgr.scene_manager.load_next_scene();
// Get the Metadata components of each GameObject of Scene2
metadata = loop_mgr.component_manager.get_components_by_type<Metadata>();
cout << "Metadata components of Scene2:" << endl;
// Print the Metadata
for (auto & m : metadata) {
cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name
<< " Tag: " << m.get().tag << endl;
}
return 0;
}
|