Ejemplo n.º 1
0
    bool CheckSelectedTerrain(TerrainPosition inputSelection)
    {
        bool output = false;

        foreach (TerrainPosition target in selectableTargets)
        {
            if (target.posX == inputSelection.posX && target.posY == inputSelection.posY)
            {
                output = true;
                break;
            }
        }

        return(output);
    }
Ejemplo n.º 2
0
        public void UseToolExecute(TerrainPosition position)
        {
            if (String.IsNullOrWhiteSpace(TerrainTools.SelectedTileKey))
                return;

            var tileAsset = this._packageRepository.Assets.Where(x => x.Key == TerrainTools.SelectedTileKey).Single();
            var tileData = this._packageRepository.GetAssetData<TerrainTileDefinitionResource>(tileAsset.Id);

            if (TerrainTools.SelectedTool == TerrainEditorTools.Paint)
                Terrain.SetTile(position, tileData);
            else if (TerrainTools.SelectedTool == TerrainEditorTools.Fill)
                Paint(position, tileData, new List<Int32>());
            else if (TerrainTools.SelectedTool == TerrainEditorTools.EyeDropper)
            {
                TerrainTools.SelectedTileKey = Terrain.GetTileKey(position);
                TerrainTools.SelectedTool = TerrainEditorTools.Paint;
            }
        }
Ejemplo n.º 3
0
    bool CheckOccupiedTerrain(int posX, int posY)
    {
        bool output = true;

        foreach (GameObject target in MapManager._Instance.terrainList)
        {
            TerrainPosition tempPosition = target.GetComponent <TerrainCubeData> ().gridPosition;

            if (tempPosition.posX == posX && tempPosition.posY == posY)
            {
                if (target.GetComponent <TerrainCubeData>().occupant != null)
                {
                    output = false;
                    break;
                }
            }
        }

        return(output);
    }
Ejemplo n.º 4
0
        private void Paint(TerrainPosition position, TerrainTileDefinitionResource tileData, List<Int32>visitedPositions)
        {
            var initialTileKey = Terrain.GetTileKey(position);

            Terrain.SetTile(position, tileData);
            visitedPositions.Add(position.Row * Terrain.Columns + position.Column);
            
            // North
            if (position.Row > 0)
            {
                if (!visitedPositions.Contains((position.Row - 1) * Terrain.Columns + position.Column))
                {
                    var newPosition = new TerrainPosition() { Row = position.Row - 1, Column = position.Column };
                    if (Terrain.GetTileKey(newPosition) == initialTileKey)
                    {
                        Paint(newPosition, tileData, visitedPositions);
                    }
                }
            }

            // South
            if (position.Row < (Terrain.Rows - 1))
            {
                if (!visitedPositions.Contains((position.Row + 1) * Terrain.Columns + position.Column))
                {
                    var newPosition = new TerrainPosition() { Row = position.Row + 1, Column = position.Column };
                    if (Terrain.GetTileKey(newPosition) == initialTileKey)
                    {
                        Paint(newPosition, tileData, visitedPositions);
                    }
                }
            }

            // West
            if (position.Column < (Terrain.Columns - 1))
            {
                if (!visitedPositions.Contains(position.Row * Terrain.Columns + position.Column + 1))
                {
                    var newPosition = new TerrainPosition() { Row = position.Row, Column = position.Column + 1 };
                    if (Terrain.GetTileKey(newPosition) == initialTileKey)
                    {
                        Paint(newPosition, tileData, visitedPositions);
                    }
                }
            }

            // East
            if (position.Column > 0)
            {
                if (!visitedPositions.Contains(position.Row * Terrain.Columns + position.Column - 1))
                {
                    var newPosition = new TerrainPosition() { Row = position.Row, Column = position.Column - 1 };
                    if (Terrain.GetTileKey(newPosition) == initialTileKey)
                    {
                        Paint(newPosition, tileData, visitedPositions);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public String GetTileKey(TerrainPosition position)
        {
            var tileAtPosition = _tiles.Where(x => x.Column == position.Column && x.Row == position.Row).FirstOrDefault();

            if (tileAtPosition == null)
                return String.Empty;
            else
                return tileAtPosition.Key;
        }
Ejemplo n.º 6
0
        public void SetTile(TerrainPosition position, TerrainTileDefinitionResource tileResource)
        {
            var tilesAtPosition = _tiles.Where(x => x.Column == position.Column && x.Row == position.Row);

            if (tilesAtPosition.Count() > 0)
            {
                foreach (var tile in tilesAtPosition.ToArray())
                    _tiles.Remove(tile);
            }

            var newTile = new Tile() { Key = tileResource.Key,  Row = position.Row, Column = position.Column, Sprite = _spriteLoader.LoadSprite(tileResource.SpriteKey) };
            _tiles.Add(newTile);
        }