Пример #1
0
    /* ajouté */

    // Calculates the completion percentage of given car with given completed last checkpoint.
    // This method will update the given checkpoint index accordingly to the current position.
    private float GetCompletePerc(DroneController drone, ref uint curCheckpointIndex)
    {
        //Already all checkpoints captured
        if (curCheckpointIndex >= checkpoints.Length)
        {
            return(1);
        }

        //Calculate distance to next checkpoint
        float checkPointDistance = Vector3.Distance(drone.transform.position, checkpoints[curCheckpointIndex].transform.position);

        /* a revoir */

        //Check if checkpoint can be captured
        if (checkpoints[curCheckpointIndex].GetComponent <Renderer>().bounds.Contains(drone.transform.position))
        {
            Debug.Log("Checkpoint completed !!!");
            curCheckpointIndex++;
            drone.CheckpointCaptured();                             //Inform car that it captured a checkpoint
            return(GetCompletePerc(drone, ref curCheckpointIndex)); //Recursively check next checkpoint
        }
        else
        {
            //Return accumulated reward of last checkpoint + reward of distance to next checkpoint
            return(checkpoints[curCheckpointIndex - 1].AccumulatedReward + checkpoints[curCheckpointIndex].GetRewardValue(checkPointDistance));
        }
    }
    private float GetCompletePerc(DroneController drone, ref uint curCheckpointIndex)
    {
        if (curCheckpointIndex >= checkpoints.Length)
        {
            return(1);
        }

        float checkPointDistance = Vector2.Distance(drone.transform.position, checkpoints[curCheckpointIndex].transform.position);

        if (checkPointDistance <= checkpoints[curCheckpointIndex].CaptureRadius)
        {
            curCheckpointIndex++;
            drone.CheckpointCaptured();
            return(GetCompletePerc(drone, ref curCheckpointIndex));
        }
        else
        {
            return(checkpoints[curCheckpointIndex - 1].AccumulatedReward + checkpoints[curCheckpointIndex].GetRewardValue(checkPointDistance));
        }
    }