/* void SpawnObs2()
     * {
     *   Lloyd_ObstacleMovement obj = (Lloyd_ObstacleMovement)Instantiate(obs2, getLocation(), Quaternion.identity);
     *   if (checkSurrounding(obj)) obstacles.Add(obj);
     *   else { Destroy(obj.gameObject); };
     * }
     */

    /// <summary>
    /// the base function to spawn an object at certain location
    /// </summary>
    /// <param name="obsSpawn">the reference the object that is about to spawn</param>
    void spawnObs1(Lloyd_ObstacleMovement obsSpawn)
    {
        Lloyd_ObstacleMovement obj = (Lloyd_ObstacleMovement)Instantiate(obsSpawn, getLocation(), Quaternion.identity);

        if (checkSurrounding(obj))
        {
            obstacles.Add(obj);
        }
        else
        {
            Destroy(obj.gameObject);
        };
    }
    /// <summary>
    /// before the object is spawned it needs to check is surrounding to see if it is conflict with any other obstacle
    /// if it is, the object will be destroyed
    /// </summary>
    /// <param name="obs">the spawning object reference</param>
    /// <returns></returns>
    bool checkSurrounding(Lloyd_ObstacleMovement obs)
    {
        Vector3 displacement;

        for (int i = (obstacles.Count - 1); i >= 0; i--)
        {
            displacement = obstacles[i].transform.position - obs.gameObject.transform.position;
            float totalRad = obstacles[i].radius + obs.radius;
            // print(i + " Radius " + totalRad + " displacementMag " +displacement.sqrMagnitude);
            if (displacement.sqrMagnitude < totalRad * totalRad)
            {
                return(false);
            }
        }
        return(true);
    }
    /// <summary>
    /// spawning obstacle depending on which difficulty it is
    /// </summary>
    void startSpawnObs()
    {
        difficulty = (int)playerScore / 1000;
        int rnd = Mathf.Clamp(Random.Range(1, 5) + Random.Range(1, 5) + difficulty, 6, 10);

        if (obstacles.Count < 1)
        {
            Lloyd_ObstacleMovement obj = (Lloyd_ObstacleMovement)Instantiate(obs, getLocation(), Quaternion.identity);
            obstacles.Add(obj);
        }
        else /*if (obstacles.Count < spawnLimit)*/
        {
            switch (rnd)
            {
            case 6:
                int rand = Random.Range(1, 3);
                if (rand == 1)
                {
                    spawnObs1(obs);
                }
                else if (rand == 2)
                {
                    spawnObs1(obs1_extra);
                }
                break;

            case 7:
                spawnObs1(obs2);
                break;

            case 10:
                spawnObs1(obs3);
                break;

            case 9:
                spawnObs1(obs4);
                break;
            }
        }

        spawnAirPlatForm();
        SpawningItem();
        removeObstaclePassZ();
    }