blob: 6c1052e38134d8f33466583311cd2465277ffc0c (
plain)
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
|
#include <crepe/api/LoopManager.h>
#include <crepe/api/Scene.h>
#include <crepe/api/Camera.h>
#include <crepe/api/AudioSource.h>
#include <crepe/api/Config.h>
#define private public
#include <crepe/api/Script.h>
using namespace crepe;
using namespace std;
class Auto : public Script {
unsigned i = 0;
void init() {
AudioSource & sound = get_component<AudioSource>();
sound.play();
}
void update() {
if (++i < 50) return;
EventManager & evmgr = this->mediator->event_manager;
evmgr.trigger_event<ShutDownEvent>();
}
};
class Bug : public Scene {
virtual std::string get_name() const override { return "bug"; }
void load_scene() override {
GameObject camera = new_object("camera");
camera.add_component<Camera>(ivec2{10, 10}, vec2{1, 1}, Camera::Data{ });
GameObject sound = new_object("sound");
sound.add_component<AudioSource>(Asset{"mwe/audio/bgm.ogg"});
sound.add_component<BehaviorScript>().set_script<Auto>();
}
};
int main() {
Config & config = Config::get_instance();
config.log.level = Log::Level::TRACE;
LoopManager example;
example.add_scene<Bug>();
example.start();
return 0;
}
|