package main;

import ea.Ticker;
import main.entities.player.Player;
import main.maps.Map;

public class DoorTile extends Tile implements Ticker {
	
	public static final int TOP = 0;
	public static final int BOTTOM = 1;
	public static final int LEFT = 2;
	public static final int RIGHT = 3;

	private int side;
	private DoorTile connected;
	private Map map;
	private boolean waitForLeave;

	public DoorTile(int id, float x, float y, Map map) {
		super(id, x, y);
		this.map = map;
	}

	@Override
	public void tick() {
		if (Main.instance.getWorld() != null) {
			Player player = Main.instance.getWorld().getPlayer();
			float dist = player.dist(posX + 0.5f, posY + 0.5f);
			if (dist < 0.5f) {
				if (!waitForLeave) {
					Main.instance.getWorld().changeMap(this);
				}
			} else {
				waitForLeave = false;
			}
		}
	}

	public int getSide() {
		return side;
	}

	public void setSide(int side) {
		this.side = side;
	}
	
	public void setConnectedDoor(DoorTile door) {
		connected = door;
	}
	
	public DoorTile getConnectedDoor() {
		return connected;
	}

	public Map getMap() {
		return map;
	}

	public void waitForLeave() {
		waitForLeave = true;
	}
	
	@Override
	public DoorTile clone() {
		DoorTile t = new DoorTile(getID(), posX, posY, map);
		t.setConnectedDoor(connected);
		t.side = side;
		t.map = map;
		return t;
	}

	public void setMap(Map map) {
		this.map = map;
	}
}
