Esempio n. 1
0
    private void CreateAssets()
    {
        var levelDefinition = PMWrapper.CurrentLevel.levelDefinition;

        foreach (Car car in levelDefinition.cars)
        {
            Vector3 worldPosition      = CityGrid.GetWorldPosition(car.position);
            Vector3 positionWithOffset = new Vector3(worldPosition.x, worldPosition.y, -0.18f);
            playerObject = Instantiate(PlayerPrefab, positionWithOffset, Quaternion.Euler(new Vector3(0, 180, 0)));
            playerObject.GetComponent <PlayerMovement>().Init(car);
        }

        foreach (Station station in levelDefinition.stations)
        {
            Vector3    position   = CityGrid.GetWorldPosition(station.position);
            GameObject stationObj = Instantiate(ChargeStationPrefab, position, Quaternion.Euler(new Vector3(0, 0, 0)));
            stationObj.GetComponent <ChargeStation>().position = new Vector2(position.x, position.y);
            ChargeStations.Add(stationObj);
        }

        if (levelDefinition.obstacles != null)
        {
            foreach (Obstacles obstacle in levelDefinition.obstacles)
            {
                Vector3    position    = CityGrid.GetWorldPosition(obstacle.position);
                GameObject obstacleObj = Instantiate(ObstaclePrefab, position, Quaternion.identity);
                Obstacles.Add(obstacleObj);
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Adds all neighbour tiles to array of neighbours
    /// </summary>
    protected void AddAllNeighbours()
    {
        CityGrid cityScript = GetComponentInParent <CityGrid>();
        int      width      = cityScript.width;
        int      height     = cityScript.height;

        //Add neighbour in every direction
        AddNeighbour(cityScript, height, 1, 0, (int)compass.N);
        AddNeighbour(cityScript, width, 1, 1, (int)compass.E);
        AddNeighbour(cityScript, height, -1, 0, (int)compass.S);
        AddNeighbour(cityScript, width, -1, 1, (int)compass.W);
    }
 public void UpdateGameBoard()
 {
     for (int i = 0; i < _cols; i++)
     {
         for (int j = 0; j < _rows; j++)
         {
             CityCell cell = _city.Cells[i, j];
             _cellRects[i, j].Fill = GetGradientBrush(CityGrid.GetColorOfType(cell.Type));
             _labels[i, j].Text    = cell.Score.ToString();
         }
     }
 }
Esempio n. 4
0
        protected void FilterData(object sender, EventArgs e)
        {
            var param = new List <WhereTerm>();

            if (tbxName.Text != "")
            {
                param.Add(WhereTerm.Default(tbxName.Text, "name", EnumSqlOperator.Like));
            }

            // ReSharper disable once CoVariantArrayConversion
            CityGrid.DataSource = new CityDataManager().Get <CityModel>(param.ToArray());
            CityGrid.Focus();
        }
Esempio n. 5
0
 /// <summary>
 /// Adds neighbour to the array in heightwidth direction, by the modifier number
 /// </summary>
 /// <param name="cityScript">city spawner script</param>
 /// <param name="heightWidth">X or Y axis</param>
 /// <param name="modifier">+1 or -1 along axis axis</param>
 /// <param name="direction">0 for height, 1 for width</param>
 /// <param name="compassDirection">where to place in array. CompassDirection enum can be used</param>
 protected void AddNeighbour(CityGrid cityScript, int heightWidth, int modifier, int direction, int compassDirection)
 {
     if (heightWidth > (location[direction] + modifier)) //check to see if tile to be searched is out of bounds
     {
         if (0 <= (location[direction] + modifier))      //checked to see if tile to be searched is out of bounds
         {
             GameObject temp;
             if (direction == 0) //Varies which axis to check
             {
                 temp = cityScript.city[location[0] + modifier, location[1]];
             }
             else
             {
                 temp = cityScript.city[location[0], location[1] + modifier];
             }
             if (temp.GetComponent <CityTile>() != null) //Leaves it null if it's already null, adds to neighbourlist if not
             {
                 neighbourList[compassDirection] = temp;
             }
         }
     }
 }
        private void NewGame()
        {
            _grid = new NodeGrid(_cols, _rows);
            _city = new CityGrid(_cols, _rows);
            _city.InitializeCells();
            _labels    = new TextBlock[_cols, _rows];
            _cellRects = new Rectangle[_cols, _rows];

            boardGrid.Width  = _cols;
            boardGrid.Height = _rows;
            boardGrid.ColumnDefinitions.Clear();
            boardGrid.RowDefinitions.Clear();
            Enumerable.Range(0, _cols).ToList().ForEach(x => boardGrid.ColumnDefinitions.Add(new ColumnDefinition()));
            Enumerable.Range(0, _rows).ToList().ForEach(x => boardGrid.RowDefinitions.Add(new RowDefinition()));

            for (int i = 0; i < _cols; i++)
            {
                for (int j = 0; j < _rows; j++)
                {
                    CityCell cell = _city.Cells[i, j];

                    Rectangle cellRect = new Rectangle();
                    cellRect.Fill = GetGradientBrush(CityGrid.GetColorOfType(cell.Type));
                    Grid.SetRow(cellRect, j);
                    Grid.SetColumn(cellRect, i);
                    boardGrid.Children.Add(cellRect);
                    _cellRects[i, j] = cellRect;

                    TextBlock label = new TextBlock {
                        Text = cell.Score.ToString(), FontSize = 0.3, Foreground = Brushes.Black
                    };
                    Grid.SetRow(label, j);
                    Grid.SetColumn(label, i);
                    boardGrid.Children.Add(label);
                    _labels[i, j] = label;
                }
            }
        }