]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/collider.h
Implement a simple physics system in Bassteroids
[libs/game.git] / examples / bassteroids / source / collider.h
diff --git a/examples/bassteroids/source/collider.h b/examples/bassteroids/source/collider.h
new file mode 100644 (file)
index 0000000..cd5cffe
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef COLLIDER_H_
+#define COLLIDER_H_
+
+#include <msp/game/component.h>
+#include <msp/linal/vector.h>
+
+enum class ColliderType
+{
+       CIRCLE,
+       BOX
+};
+
+struct ColliderSetup
+{
+       ColliderType type = ColliderType::CIRCLE;
+       union
+       {
+               float radius = 1.0f;
+               Msp::LinAl::Vector<float, 2> size;
+       };
+};
+
+
+class Collider: public Msp::Game::Component
+{
+public:
+       using Setup = ColliderSetup;
+
+private:
+       Setup setup;
+
+public:
+       Collider(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
+
+       ColliderType get_type() const { return setup.type; }
+       float get_radius() const { return (setup.type==ColliderType::CIRCLE ? setup.radius : 0.0f); }
+       Msp::LinAl::Vector<float, 2> get_size() const { return (setup.type==ColliderType::BOX ? setup.size : Msp::LinAl::Vector<float, 2>()); }
+};
+
+#endif