package net.mightyelemental.mowergame.entities.living;

import java.awt.Point;
import java.util.Random;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;

import net.mightyelemental.mowergame.MathHelper;
import net.mightyelemental.mowergame.World;
import net.mightyelemental.mowergame.entities.Entity;
import net.mightyelemental.mowergame.particles.ParticleBlood;
import net.mightyelemental.mowergame.particles.ParticleBloodSplat;

public class EntityLiving extends Entity {
	
	
	private static final long serialVersionUID = 3671860235445980129L;
	
	public Random rand;
	
	public EntityLiving( float x, float y, float width, float height, World worldObj ) {
		super(x, y, width, height, worldObj);
		this.rand = worldObj.rand;
	}
	
	protected MovePath path;
	
	/** The amount of money that the entity gives when killed */
	public float moneyGain = 0;
	
	/** The amount of time that the entity gives when killed */
	public float timeGain = 0;
	
	/** The amount of damage the mower takes when entity is hit */
	public int damageToMower = 50;
	
	public boolean dead;
	
	public float getMoneyGain() {
		return moneyGain;
	}
	
	public void setMoneyGain(float moneyGain) {
		this.moneyGain = moneyGain;
	}
	
	public float getTimeGain() {
		return timeGain;
	}
	
	public void setTimeGain(float timeGain) {
		this.timeGain = timeGain;
	}
	
	public int getDamageToMower() {
		return damageToMower;
	}
	
	public void setDamageToMower(int damageToMower) {
		this.damageToMower = damageToMower;
	}
	
	public void setDead() {
		worldObj.createParticle(new ParticleBloodSplat(this.getCenterX(), this.getCenterY(), worldObj));
		for (int i = 0; i < worldObj.rand.nextInt(25) + 20; i++) {
			worldObj.createParticle(new ParticleBlood(this.getCenterX(), getCenterY(), worldObj));
		}
		this.dead = true;
	}
	
	public MovePath getPath() {
		return path;
	}
	
	@Override
	public void update(GameContainer gc, int delta) throws SlickException {
		if (path != null) {
			if (!path.hasReached) {
				angle = MathHelper.getAngle(new Point(path.getX(), path.getY()), new Point((int) getCenterX(), (int) getCenterY()));
			}
		}
		this.getIcon().setRotation(angle + 90);
	}
	
}
