]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/hitpoints.h
Make asteroids take damage when shot and eventually be destroyed
[libs/game.git] / examples / bassteroids / source / hitpoints.h
1 #ifndef HITPOINTS_H_
2 #define HITPOINTS_H_
3
4 #include <msp/game/component.h>
5
6 struct HitPointsSetup
7 {
8         /*class Loader: public Msp::DataFile::ObjectLoader<HitPointsSetup>
9         {
10         };*/
11
12         unsigned max_hits = 1;
13         unsigned vulnerable_to = ~0U;
14 };
15
16 class HitPoints: public Msp::Game::Component
17 {
18 public:
19         using Setup = HitPointsSetup;
20
21 private:
22         const Setup &setup;
23         unsigned remaining_hits;
24
25 public:
26         HitPoints(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
27
28         void take_damage(unsigned, unsigned);
29
30         bool is_alive() const { return remaining_hits; }
31 };
32
33 #endif