]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/hitpoints.cpp
Make asteroids take damage when shot and eventually be destroyed
[libs/game.git] / examples / bassteroids / source / hitpoints.cpp
diff --git a/examples/bassteroids/source/hitpoints.cpp b/examples/bassteroids/source/hitpoints.cpp
new file mode 100644 (file)
index 0000000..ccd0441
--- /dev/null
@@ -0,0 +1,17 @@
+#include "hitpoints.h"
+
+using namespace Msp;
+
+HitPoints::HitPoints(Game::Handle<Game::Entity> e, const Setup &s):
+       Component(e),
+       setup(s),
+       remaining_hits(setup.max_hits)
+{ }
+
+void HitPoints::take_damage(unsigned amount, unsigned type)
+{
+       if(!(setup.vulnerable_to&(1<<type)))
+               return;
+
+       remaining_hits = (amount<remaining_hits ? remaining_hits-amount : 0);
+}