package ecs.components;

import ecs.core.Component;

class Health extends Component {
	public var max:Float;
	public var current:Float;
	public var die:Bool = true;

	public var fraction(get, never):Float;

	function get_fraction()
		return current / max;

	public function new(max:Float, ?initial:Float, ?die:Bool = true) {
		super();
		this.max = max;
		this.current = initial == null ? max : initial;
		this.die = die;
	}

	public function hit(power:Float) {
		current = Math.max(0, current - power);
	}
}
