]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/hitpoints.h
f6000d7abab3c6dc54782d4fc2c413817c8263e8
[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 struct HitPointsData
17 {
18         unsigned remaining_hits;
19 };
20
21 class HitPoints: public Msp::Game::BufferedComponent<HitPointsData>
22 {
23 public:
24         using Setup = HitPointsSetup;
25
26 private:
27         const Setup &setup;
28
29 public:
30         HitPoints(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
31
32         void take_damage(unsigned, unsigned);
33
34         bool is_alive() const { return read().remaining_hits; }
35 };
36
37 #endif