Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Ray        mouseRay = mainCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit rayHit   = new RaycastHit();

        if (Physics.Raycast(mouseRay, out rayHit, 1000))
        {
            GameObject hit = rayHit.collider.gameObject;
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }
            if (hit.GetComponentInParent <Square>() == null)
            {
                return;
            }
            Square s = hit.GetComponentInParent <Square>();
            if (!GridCoord.IsAdjacent(thisCar.gridCoord, s.coord))
            {
                return;
            }
            if (s.squareType == Square.SquareType.BUILDING)
            {
                return;
            }
            if (s.squareType == Square.SquareType.BANK)
            {
                gameController.RobBank(s);
                return;
            }
            gameController.ClickOnSquare(s);
        }
    }
Exemplo n.º 2
0
    public bool CanMoveTo(Car car, Square square, bool ignoreDistance = false)
    {
        if (square.squareType != Square.SquareType.ROAD && square.squareType != Square.SquareType.ABILITY_ITEM && square.squareType != Square.SquareType.HIGHWAY_EXIT)
        {
            return(false);
        }

        if (square.occupiedCar != null)
        {
            return(false);
        }

        if (!GridCoord.IsAdjacent(grid[car.gridCoord.x, car.gridCoord.y].coord, square.coord) && !ignoreDistance)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 3
0
    public List <Square> GetAdjacentSquares(Square square)
    {
        List <Square> adajacentSquares = new List <Square>();

        for (int x = 0; x < gridGenerator.dimensionsX; x++)
        {
            for (int y = 0; y < gridGenerator.dimensionsY; y++)
            {
                if (square.coord.x < 0 || square.coord.y < 0 || square.coord.x >= gridGenerator.dimensionsX || square.coord.y >= gridGenerator.dimensionsY)
                {
                    continue;
                }
                if (GridCoord.IsAdjacent(square.coord, new GridCoord(x, y)))
                {
                    adajacentSquares.Add(gridGenerator.GetSquare(new GridCoord(x, y)));
                }
            }
        }
        return(adajacentSquares);
    }
Exemplo n.º 4
0
 public void HighlightAvailableSquares(Car car)
 {
     for (int x = 0; x < gridGenerator.dimensionsX; x++)
     {
         for (int y = 0; y < gridGenerator.dimensionsY; y++)
         {
             Square s = grid[x, y];
             s.ResetSquareColor();
             if (car == playerCar)
             {
                 if (s.occupiedCar != null && s.occupiedCar != playerCar && GridCoord.IsAdjacent(playerCar.gridCoord, s.occupiedCar.gridCoord))
                 {
                     s.SetSquareColor(dangerColor);
                 }
             }
             else
             {
                 if (s.occupiedCar != null && s.occupiedCar == playerCar && GridCoord.IsAdjacent(car.gridCoord, s.occupiedCar.gridCoord))
                 {
                     s.SetSquareColor(dangerColor);
                 }
             }
             if (CanMoveTo(car, s))
             {
                 s.SetSquareColor(highlightedSquareColor);
             }
             else if (s == gridGenerator.GetSquare(car.gridCoord))
             {
                 s.SetSquareColor(car.centreHighlightColor);
             }
             if (s.squareType == Square.SquareType.BANK && GridCoord.IsAdjacent(car.gridCoord, new GridCoord(x, y)) && car == playerCar && !ActivatedBanks.Contains(s))
             {
                 s.SetSquareColor(bankColor);
             }
         }
     }
 }