Ejemplo n.º 1
0
        public void Cache(int x, int y, int tile, int NW, int N, int NE, int E, int SE, int S, int SW, int W)
        {
            var terrain = TerrainManager.Instance.GetTerrain(tile);
            if (terrain == null)
            {
                _sprites = null;
                return;
            }

            _terrain = terrain;

            Helper = new TerrainHelper(_terrain);
            Helper.CachePoints(_terrain.Type);

            var tileset = TilesetManager.Instance.GetTileset(terrain.Tileset);
            if (tileset == null)
            {
                _sprites = null;
                return;
            }

            destX = x;
            destY = y;

            switch (terrain.Type)
            {
                case TerrainType.RMVX_Ground:
                    _sprites[0] = SetSprite(Helper.CalculateNW_RMVX_Ground(tile, NW, N, W), 0);
                    _sprites[1] = SetSprite(Helper.CalculateNE_RMVX_Ground(tile, N, NE, E), 1);
                    _sprites[2] = SetSprite(Helper.CalculateSW_RMVX_Ground(tile, W, SW, S), 2);
                    _sprites[3] = SetSprite(Helper.CalculateSE_RMVX_Ground(tile, S, SE, E), 3);
                    break;
                case TerrainType.RMVX_Cliff:
                    _sprites[0] = SetSprite(Helper.CalculateNW_RMVX_Cliff(tile, NW, N, W), 0);
                    _sprites[1] = SetSprite(Helper.CalculateNE_RMVX_Cliff(tile, N, NE, E), 1);
                    _sprites[2] = SetSprite(Helper.CalculateSW_RMVX_Cliff(tile, W, SW, S), 2);
                    _sprites[3] = SetSprite(Helper.CalculateSE_RMVX_Cliff(tile, S, SE, E), 3);
                    break;
            }
        }
 public TerrainSelectedEventArgs(TerrainTile terrain)
 {
     _terrain = terrain;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets a terrain tile
        /// </summary>
        /// <param name="layer">Layer to set the terrain to</param>
        /// <param name="terrain">TerrainTile to set down</param>
        /// <param name="destX">X co-ordinate to place to</param>
        /// <param name="destY">Y co-ordinate to place to</param>
        public void SetTerrain(EditorTileLayer layer, TerrainTile terrain, int destX, int destY)
        {
            if (destX < 0 || destY < 0 || destX > Width - 1 || destY > Height - 1) return;

            layer.Tiles[destX, destY].Tileset = 0;
            layer.Tiles[destX, destY].X = destX;
            layer.Tiles[destX, destY].Y = destY;
            layer.Tiles[destX, destY].SrcX = 0;
            layer.Tiles[destX, destY].SrcY = 0;
            layer.Tiles[destX, destY].Terrain = terrain.ID;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the <see cref="DialogTerrain"/> form, checks all the directories and builds the <see cref="Terrain"/> object.
        /// </summary>
        public void NewTerrain()
        {
            using (var dialog = new DialogTerrain())
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                var name = dialog.TerrainName;
                var type = dialog.TerrainType;
                var tileset = dialog.TilesetID;
                var x = dialog.SelectionX;
                var y = dialog.SelectionY;
                var width = dialog.SelectionWidth;
                var height = dialog.SelectionHeight;

                if (CheckTerrain(name))
                {
                    MessageBox.Show(@"Terrain with this name already exists.", @"New Terrain");
                    return;
                }

                var index = 1;
                while (true)
                {
                    var exit = true;
                    foreach (var tmp in Terrain)
                    {
                        if (tmp.ID == index)
                            exit = false;
                    }

                    if (exit)
                        break;

                    index++;
                }

                var terrain = new TerrainTile(index, name, type, tileset, x, y, width, height);

                Terrain.Add(terrain);

                SaveTerrain(index);

                if (TerrainAdded != null)
                    TerrainAdded.Invoke(this, new TerrainAddedEventArgs(terrain));
            }
        }
 public TerrainAddedEventArgs(TerrainTile terrainTile)
 {
     _terrainTile = terrainTile;
 }
 public TerrainChangedEventArgs(TerrainTile oldTerrain, TerrainTile newTerrain)
 {
     _oldTerrain = oldTerrain;
     _newTerrain = newTerrain;
 }