-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRectangles.cpp
More file actions
58 lines (46 loc) · 1.82 KB
/
SimpleRectangles.cpp
File metadata and controls
58 lines (46 loc) · 1.82 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
#include <iostream>
#include "sim/Simulation.h"
#include "sim/lib/components/Sprite.h"
#include "sim/lib/components/Transform.h"
#include "sim/lib/systems/Interactor.h"
#include "sim/lib/systems/Movement.h"
#include "sim/lib/systems/Renderer.h"
#include "sim/lib/systems/World.h"
using namespace sim;
using namespace sim::lib;
struct TestSystem {
void operator()(const event::Cycle, Context ctx) const {
ctx.view<Transform, Movable>().for_each([](const Entity e, auto& t, auto& m) {
std::cout << "Entity #" << e.id() << " at (" << t.x << ", " << t.y << ") with speed " << m.speed <<
std::endl;
});
}
};
int main() {
auto s = Simulation<TestSystem>()
.with_systems<Movement, TargetResolver<RandomTarget> >()
.with_systems<WorldBoundary, Renderer>();
Sprite red(Color{255, 0, 0, 255});
Sprite green(Color{0, 255, 0, 255});
const auto top_left = s.create().emplace<Transform>(0, 0);
const auto bottom_right = s.create().emplace<Transform>(1000, 1000);
s.create()
.emplace<Transform>(500, 500).emplace<Movable>(10)
.emplace<Target>().emplace<RandomTarget>()
.emplace<Sprite>(green);
s.create()
.emplace<Transform>(500, 500).emplace<Movable>(5)
.emplace<Target>().emplace<StaticEntityTarget>(bottom_right.id())
.emplace<Sprite>(green);
s.create()
.emplace<Transform>(500, 500).emplace<Movable>(5)
.emplace<Target>().emplace<StaticEntityTarget>(top_left.id())
.emplace<Sprite>(green);
s.create()
.emplace<Transform>(500, 600).emplace<Movable>()
.emplace<Target>().emplace<FollowClosest<RandomTarget> >()
.push_back(red);
s.run(10000);
std::cout << "Done" << std::endl;
return 0;
}