]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/hitpoints.cpp
Convert components to buffered where appropriate
[libs/game.git] / examples / bassteroids / source / hitpoints.cpp
1 #include "hitpoints.h"
2
3 using namespace Msp;
4
5 HitPoints::HitPoints(Game::Handle<Game::Entity> e, const Setup &s):
6         BufferedComponent<HitPointsData>(e),
7         setup(s)
8 {
9         write().remaining_hits = setup.max_hits;
10 }
11
12 void HitPoints::take_damage(unsigned amount, unsigned type)
13 {
14         if(!(setup.vulnerable_to&(1<<type)))
15                 return;
16
17         Data &d = write();
18         d.remaining_hits = (amount<d.remaining_hits ? d.remaining_hits-amount : 0);
19 }