]> git.localhorst.tv Git - blank.git/blob - src/ai/Spawner.cpp
moved entity spawn and control into its own class
[blank.git] / src / ai / Spawner.cpp
1 #include "Spawner.hpp"
2
3 #include "RandomWalk.hpp"
4 #include "../world/BlockType.hpp"
5 #include "../world/BlockTypeRegistry.hpp"
6 #include "../world/Entity.hpp"
7 #include "../world/World.hpp"
8
9
10 namespace blank {
11
12 Spawner::Spawner(World &world)
13 : world(world)
14 , controllers() {
15         Spawn({ 0.0f, 0.0f, 0.0f });
16 }
17
18 Spawner::~Spawner() {
19
20 }
21
22
23 void Spawner::Update(int dt) {
24         for (auto &ctrl : controllers) {
25                 ctrl.Update(dt);
26         }
27 }
28
29
30 void Spawner::Spawn(const glm::vec3 &pos) {
31         Entity &e = world.AddEntity();
32         e.Name("test");
33         e.Position(pos);
34         e.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } });
35         e.WorldCollidable(true);
36         e.SetShape(world.BlockTypes()[1].shape, { 1.0f, 1.0f, 0.0f });
37         e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
38         controllers.emplace_back(e);
39 }
40
41 }