]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/hitpoints.h
Make asteroids take damage when shot and eventually be destroyed
[libs/game.git] / examples / bassteroids / source / hitpoints.h
diff --git a/examples/bassteroids/source/hitpoints.h b/examples/bassteroids/source/hitpoints.h
new file mode 100644 (file)
index 0000000..a11d961
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef HITPOINTS_H_
+#define HITPOINTS_H_
+
+#include <msp/game/component.h>
+
+struct HitPointsSetup
+{
+       /*class Loader: public Msp::DataFile::ObjectLoader<HitPointsSetup>
+       {
+       };*/
+
+       unsigned max_hits = 1;
+       unsigned vulnerable_to = ~0U;
+};
+
+class HitPoints: public Msp::Game::Component
+{
+public:
+       using Setup = HitPointsSetup;
+
+private:
+       const Setup &setup;
+       unsigned remaining_hits;
+
+public:
+       HitPoints(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
+
+       void take_damage(unsigned, unsigned);
+
+       bool is_alive() const { return remaining_hits; }
+};
+
+#endif