import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Color;
public abstract class Item extends Sprite {
	private static final int[] animLengths = {0};
	private Level l;
	boolean activated;
	int timer;
	int nameTimer;
	String name;

	public Item(Level l, String imgName, int[] animL, float x, float y, String name) {
		super(l.spriteCache, imgName, animL);
		this.l=l;
		this.name=name;
		activated = false;
		setLoc(x,y);
		nameTimer = 40;
	}
	public Item(Level l, float x, float y, String name) {
		this(l, "", animLengths, x, y, name);
		setLoc(x,y);
	}

	
	public void draw(Graphics2D g, int x, int y) {
		if (!activated) {
			if (getColor() == null) {
				super.draw(g, x, y);
			} else {
				g.setColor(getColor());
				g.fillOval(x,y,32,32);
			}
		} else if (nameTimer > 0){
			g.setColor(Color.black);
			g.setFont(new Font("Monospaced", Font.PLAIN, 12));
			g.drawString(name, x, y+16);
		}
	}

	public abstract Color getColor();
	public abstract void itemAction(Level l);
	public abstract void itemRevert(Level l);
	
	public void act() {
		if (activated) {
			timer--;
			if (nameTimer > 0)
				nameTimer--;
			if (timer <= 0) {
				setToDestroy(true);
				itemRevert(l);
			}
		} else {
			Player p = l.player;
			if (hitSprite(p)) {
				activated = true;
				itemAction(l);
				timer = Math.max(timer, nameTimer);
			}
		}
	}
}
