]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/physicalentity.h
Implement a simple physics system in Bassteroids
[libs/game.git] / examples / bassteroids / source / physicalentity.h
diff --git a/examples/bassteroids/source/physicalentity.h b/examples/bassteroids/source/physicalentity.h
new file mode 100644 (file)
index 0000000..a0cca37
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef PHYSICALENTITY_H_
+#define PHYSICALENTITY_H_
+
+#include <msp/game/entity.h>
+#include "rigidbody.h"
+#include "collider.h"
+
+struct PhysicalSetup
+{
+       bool fixture = false;
+       RigidBodySetup body;
+       ColliderSetup collider;
+};
+
+class PhysicalEntity: public Msp::Game::Entity
+{
+public:
+       using Setup = PhysicalSetup;
+
+protected:
+       Msp::Game::Owned<RigidBody> body;
+       Msp::Game::Owned<Collider> collider;
+
+public:
+       PhysicalEntity(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
+
+       bool is_fixture() const { return !body; }
+       Msp::Game::Handle<RigidBody> get_body() const { return body; }
+       Msp::Game::Handle<Collider> get_collider() const { return collider; }
+};
+
+#endif