Esempio n. 1
0
    PlayerOnIntersection CheckIfPlayerOnIntersection()
    {
        for (int i = 0; i < carsInIntersection.Length; ++i)
        {
            if (carsInIntersection[i].car == trafficSystem.car.gameObject)
            {
                PlayerOnIntersection onIntersection = new PlayerOnIntersection(carsInIntersection[i].entry, true);
                return(onIntersection);
            }
        }

        PlayerOnIntersection onIntersectionInvalid = new PlayerOnIntersection(null, false);

        return(onIntersectionInvalid);
    }
Esempio n. 2
0
    private void Update()
    {
        if (CarsWaitingOnIntersection(out entriesWithCars, out carsInIntersection))
        {
            Debug.Log("Cars on intersection");
            if (!intersectionLogicProcessing)
            {
                if (intersectionType == IntersectionType.LIGHTS)
                {
                    StartCoroutine(TurnLightsForEntry(entriesWithCars[0]));
                }

                if (intersectionType == IntersectionType.EQUAL)
                {
                    //Check if car on right
                }

                if (intersectionType == IntersectionType.YIELDVERTICAL)
                {
                }

                if (intersectionType == IntersectionType.YIELDHORIZONTAL)
                {
                }
            }

            playerOnIntersection = CheckIfPlayerOnIntersection();
            //Check if player in this intersection
            if (playerOnIntersection.inIntersection)
            {
                playerDesiredTurn = DesiredTurnDirection(trafficSystem.car);
            }
        }



        if (CarsLeavingIntersection(out exitsWithCars, out carsLeavingIntersection))
        {
            for (int i = 0; i < carsLeavingIntersection.Length; ++i)
            {
                if (carsLeavingIntersection[i].car == trafficSystem.car.gameObject) //if it's player leaving
                {
                    playerTrueTurn = TrueTurnDirection(playerOnIntersection.entry, carsLeavingIntersection[i].entry);

                    if (playerDesiredTurn != playerTrueTurn)
                    {
                        Debug.Log("Blinker usage failure");
                    }

                    playerOnIntersection.inIntersection = false;
                    break;
                }
            }
        }

        //Player was on intersection but left
        if (CheckThatPlayerLeftEntry())
        {
            //Check that there wasnt car on right side if equal intersection
            //Equal check
            if (intersectionType == IntersectionType.EQUAL)
            {
            }
            //Lights check
            else if (intersectionType == IntersectionType.LIGHTS)
            {
                TrafficLights.LightState state = playerOnIntersection.entry.GetComponentInChildren <TrafficLights>().GetState();
                //if light was YELLOW or GREEN ===> OK
                if (state == TrafficLights.LightState.GREEN || state == TrafficLights.LightState.YELLOW)
                {
                    //OK
                }
                //if light was RED or YELLOWRED ==> NO
                if (state == TrafficLights.LightState.RED || state == TrafficLights.LightState.YELLOWRED)
                {
                    //Drove through reds!!!! NOT GUD >:(
                    Debug.Log("Drove reds!!");
                }
            }
            else if (intersectionType == IntersectionType.YIELDHORIZONTAL)
            {
            }
            else if (intersectionType == IntersectionType.YIELDVERTICAL)
            {
            }
        }
    }