Пример #1
0
 private void Start()
 {
     // save the horizontal center of the screen
     screenCenterX      = Screen.width * 0.5f;
     leftCarController  = LeftCar.GetComponent <AnimatingCar> ();
     rightCarController = RightCar.GetComponent <AnimatingCar> ();
 }
Пример #2
0
    public int MoveToSquare(Car car, Square square, bool playSound = false)
    {
        //Notifies the formerly-occupied square of it's vacancy
        gridGenerator.GetSquare(car.gridCoord).occupiedCar = null;
        //Notifies the new square of the new car
        square.occupiedCar = car;
        car.gridCoord      = square.coord;
        //Start car animating
        AnimatingCar aC = new AnimatingCar(car, car.transform.position, square.transform.position, 0.2f);

        animatingCars.Add(aC);

        if (playSound)
        {
            soundController.PlayMoveSound();
        }

        //Spawning cop car when player goes past station.
        if (car == playerCar)
        {
            AddScore(scoreMoveAmount);

            if (gridGenerator.GetSquare(playerCar.gridCoord).squareType == Square.SquareType.HIGHWAY_EXIT)
            {
                NextLevel();
            }
            //Iterate over the adjacent squares
            foreach (Square s in GetAdjacentSquares(gridGenerator.GetSquare(car.gridCoord)))
            {
                //If its a police building, spawn a new police car
                if (s.squareType == Square.SquareType.POLICE_BUILDING)
                {
                    Car newCop = SpawnCop();
                    soundController.PlayPoliceSound();
                    //Pan camera over and let player know
                    StartCoroutine(NotifyNewCopCar(newCop));
                    if (gridGenerator.GetSquare(playerCar.gridCoord).squareType != Square.SquareType.ABILITY_ITEM)
                    {
                        return(2);
                    }
                }
            }
            //Check if it's an ability item
            if (gridGenerator.GetSquare(playerCar.gridCoord).squareType == Square.SquareType.ABILITY_ITEM)
            {
                //Get a reference to the powerup square
                Square s = gridGenerator.GetSquare(playerCar.gridCoord);
                //If the powerup is not used (Active)
                if (s.transform.GetChild(1).gameObject.activeSelf)
                {
                    //Start the handlepowerup Coroutine
                    StartCoroutine(HandlePowerup());
                    //Mark the powerup as used (Inactive)
                    s.transform.GetChild(1).gameObject.SetActive(false);
                    s.squareType = Square.SquareType.ROAD;
                    //Wait for the powerup animation to be complete before starting on the cop's turn
                    StartCoroutine(WaitForCopCompletion());
                    //Notify the caller that the class had a powerup status
                    HighlightAvailableSquares(car);
                    return(2);
                }
            }
        }
        //Highlight new squares for the player.
        HighlightAvailableSquares(car);
        //Movement was successful.
        return(1);
    }