]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/hitpoints.cpp
Make asteroids take damage when shot and eventually be destroyed
[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         Component(e),
7         setup(s),
8         remaining_hits(setup.max_hits)
9 { }
10
11 void HitPoints::take_damage(unsigned amount, unsigned type)
12 {
13         if(!(setup.vulnerable_to&(1<<type)))
14                 return;
15
16         remaining_hits = (amount<remaining_hits ? remaining_hits-amount : 0);
17 }