2015-03-01 07:00:17 +00:00
|
|
|
/**
|
|
|
|
* Health Component Features.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.Health = function () {};
|
|
|
|
|
|
|
|
Phaser.Component.Health.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
|
|
|
|
*/
|
|
|
|
health: 1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Damages the Sprite, this removes the given amount from the Sprites health property.
|
|
|
|
* If health is then taken below or is equal to zero `Sprite.kill` is called.
|
|
|
|
*
|
2015-03-01 07:00:17 +00:00
|
|
|
* @member
|
2015-02-17 05:15:04 +00:00
|
|
|
* @param {number} amount - The amount to subtract from the Sprite.health value.
|
|
|
|
* @return (Phaser.Sprite) This instance.
|
|
|
|
*/
|
|
|
|
damage: function(amount) {
|
|
|
|
|
|
|
|
if (this.alive)
|
|
|
|
{
|
|
|
|
this.health -= amount;
|
|
|
|
|
|
|
|
if (this.health <= 0)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|