- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
Latest commit
96 lines (82 loc) · 2.14 KB
/
Copy pathexample.cpp
File metadata and controls
96 lines (82 loc) · 2.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<iostream>
#include<array>
#include"BasicECS.h"
/*
You oftentimes don't need to have classes other than the
gameobject know what type the gameobject is
However, it can still be useful for certain cases in
which case you can create a class containing an enum
defining the type
*/
enum CGOType {
Person
};
classComplexGameObject : publicGameObject {
public:
CGOType type;
ComplexGameObject(
void (*start)(SceneManager&, Scene&, GameObject&),
void (*update)(SceneManager&, Scene&, GameObject&),
CGOType type
) : GameObject(start, update) {
this->type = type;
}
};
classPersonObject : publicComplexGameObject {
public:
int age;
int height;
PersonObject(
void (*start)(SceneManager&, Scene&, GameObject&),
void (*update)(SceneManager&, Scene&, GameObject&),
int age,
int height
) : ComplexGameObject(start, update, CGOType::Person) {
this->age = age;
this->height = height;
}
voidsay_hello() {
std::cout << "Hello!" << std::endl;
}
voidsay_age() {
std::cout << "I'm " << age << " age old!" << std::endl;
}
voidsay_height() {
std::cout << "I'm " << height << " feet tall!" << std::endl;
}
};
intmain() {
// Create the scene(s)
Scene** scenes = new Scene*[]{
newScene(Linked::List<GameObject*>(),
[](SceneManager& sceneManager, Scene& scene) { // start
std::cout << "start!" << std::endl;
},
[](SceneManager& sceneManager, Scene& scene) { // update
std::cout << "update!" << std::endl;
}
)
};
// Create a person
PersonObject* person = newPersonObject(
[](SceneManager& sceneManager, Scene& scene, GameObject& gameObject) { // start()
PersonObject& person = (PersonObject&)gameObject;
person.say_hello();
person.say_height();
},
[](SceneManager& sceneManager, Scene& scene, GameObject& gameObject) { // update()
PersonObject& person = (PersonObject&)gameObject;
person.say_age();
},
3, // age
3// height
);
// Add a person
scenes[0]->objects.push((GameObject*)person);
// Create the scene manager
SceneManager sceneManager = SceneManager(scenes, 0);
// Run the scene manager
sceneManager.start();
for (int i = 0; i < 3; i++)
sceneManager.update();
}