package com.ezardlabs.lostsector.objects;

import com.ezardlabs.dethsquare.Script;
import com.ezardlabs.dethsquare.Vector2;
import com.ezardlabs.lostsector.Game.DamageType;

public abstract class Entity extends Script {
	protected final float maxHealth;
	protected float health;
	private DamageListener damageListener;

	public Entity(float maxHealth) {
		this.maxHealth = maxHealth;
		health = maxHealth;
	}

	public float getHealth() {
		return health;
	}

	public float getMaxHealth() {
		return maxHealth;
	}

	public boolean addHealth(float health) {
		if (this.health == maxHealth) return false;
		this.health += health;
		if (this.health > maxHealth) {
			this.health = maxHealth;
		}
		return true;
	}

	public void applyDamage(float damage, DamageType damageType, Vector2 attackOrigin) {
		if (damage == 0) return;
		health -= damage;
		if (damageListener != null) {
			damageListener.onDamageReceived(damage, damageType, attackOrigin);
		}
		if (health <= 0) {
			die(damageType, attackOrigin);
		}
	}

	protected abstract void die(DamageType damageType, Vector2 attackOrigin);

	public void setDamageListener(DamageListener damageListener) {
		this.damageListener = damageListener;
	}

	protected interface DamageListener {
		void onDamageReceived(float damage, DamageType damageType, Vector2 attackOrigin);
	}
}

@@ -807,16 +807,28 @@
 age == 0
+ %7C%7C isDead()
 ) return
@@ -1014,24 +1014,77 @@
 n);%0A%09%09%7D%0A%09%7D%0A%0A
+%09public boolean isDead() %7B%0A%09%09return health %3C= 0;%0A%09%7D%0A%0A
 %09protected a

Add helper method for checking whether or not an entity is dead, and don't apply damage if the entity is already dead