// Use this for initialization
	void Start () {

		supportive = GetComponent<AudioSource>();

		// This is some instantiation.
		// We want it so that if the player is within a + direction from the particle, they will get hurt.
		GameObject player = GameObject.FindGameObjectWithTag("Player");
		int playerX = (int)player.transform.position.x;
		int playerY = (int)player.transform.position.y;

		Coord myPlace = new Coord((int)this.transform.position.x, (int)this.transform.position.y);
		Coord playerCoord = new Coord(playerX, playerY);
		Coord n, w, s, e;
		n = playerCoord.nextCoord (Direction.North);
		w = playerCoord.nextCoord (Direction.West);
		s = playerCoord.nextCoord (Direction.South);
		e = playerCoord.nextCoord (Direction.East);

		if( myPlace.isEqual (playerCoord) ||
		    myPlace.isEqual (n) ||
		    myPlace.isEqual (w) ||
		    myPlace.isEqual (s) ||
		    myPlace.isEqual (e) ) {
			PlayerMovement hitPlayer = player.GetComponent<PlayerMovement>();
			supportive.PlayOneShot(haha,1f);
			hitPlayer.LoseHealth(750); }

		Destroy (this.gameObject, 3);

	}
	/**
	 * Generates a hexadecimal key corresponding its surroundings.
	 * This should yield back the appropriate key that can be used for the tileDictionary,
	 * which can then correspond with placing the appropriate graphic.
	 */
	public int makeKey(Tile[,] map, Coord target) {
		int key = 0;
		// NORTH
		if( mvf.isSolid (map, target.nextCoord (Direction.North)) ) {
			key += 0x80;
			// W AND NW
			if ( mvf.isSolid (map, target.nextCoord (Direction.West)) && mvf.isSolid (map, target.crossCoord (Direction.North, Direction.West)) )
				key += 0x40;
			// E and NE
			if( mvf.isSolid (map, target.nextCoord (Direction.East)) && mvf.isSolid (map, target.crossCoord (Direction.North, Direction.East)) )
				key += 0x01;
		}

		// SOUTH
		if( mvf.isSolid (map, target.nextCoord (Direction.South)) ) {
			key += 0x08;
			// W AND SW
			if ( mvf.isSolid (map, target.nextCoord (Direction.West)) && mvf.isSolid (map, target.crossCoord (Direction.South, Direction.West)) )
				key += 0x10;
			// E and SE
			if( mvf.isSolid (map, target.nextCoord (Direction.East)) && mvf.isSolid (map, target.crossCoord (Direction.South, Direction.East)) )
				key += 0x04;
		}

		// WEST
		if( mvf.isSolid (map, target.nextCoord (Direction.West)) ) {
			key += 0x20;
		}
			
		// EAST
		if( mvf.isSolid (map, target.nextCoord (Direction.East)) ) {
			key += 0x02;
		}

		//Debug.Log ("Given coord (" + target.x.ToString () + "," + target.y.ToString() + "), key is " + key.ToString ("X2"));

		return key;
	}
	public void FloodFillCheck(Tile[,] map, Coord current, Coord stop) {
		// The recursive algorithm. Starting at x and y, traverse down adjacent tiles and mark them if travelled, find the exit from the entrance
			int mapWidth = map.GetLength(0);
			int mapHeight = map.GetLength(1);

			int x = current.x;
			int y = current.y;

			//Debug.Log (x.ToString() + " and " + y.ToString () );

			if (map[x,y].mark != 0)
				// Base case. If the current tile is marked, then do nothing.
				return;

				// Change the current tile as marked
				map[x,y].mark = 1;

			if ( stop.isEqual (current) ) {
				Debug.Log ("Flood Fill found, flagging clearable: " + current.x.ToString() + " " + current.y.ToString ());
				clearable = true;
				return;
			}
					// Recursive calls. Make a recursive call as long as we are not on the
					// boundary (which would cause an Index Error.)
			if (x > 0 && !isSolid (map, current.nextCoord (Direction.West)) ) // left
				FloodFillCheck(map, current.nextCoord (Direction.West), stop);

			if (y > 0 && !isSolid (map, current.nextCoord (Direction.South)) ) // up
				FloodFillCheck(map, current.nextCoord (Direction.South), stop);

			if (x < mapWidth-1 && !isSolid (map, current.nextCoord (Direction.East)) ) // right
				FloodFillCheck(map, current.nextCoord (Direction.East), stop);

			if (y < mapHeight-1 && !isSolid (map, current.nextCoord (Direction.North)) ) // down
				FloodFillCheck(map, current.nextCoord (Direction.North), stop);

	}