示例#1
0
        private byte[,] GameTiles(int sectorX, int sectorY, WorldData wd, Random rand)
        {
            var heightValue = wd.HeightData[sectorX][sectorY];
            var waterArea = WorldData.MyWorldData.WaterSquareData[sectorX][sectorY];

            Array.Clear(_tileData,0,_tileData.Length);
            Array.Clear(_waterTiles, 0, _waterTiles.Length);
            Array.Clear(_tileSimplex, 0, _tileSimplex.Length);

            if (heightValue >= HeightGenerator.Beach)
            {
                if (waterArea != null)
                    NoiseGen.GetRiverSquare(ref _waterTiles, waterArea, TileHelper.RiverWater, rand);

                NoiseGen.GetTileSimplex(ref _tileSimplex, new Vector2(sectorX, sectorY));
                NoiseGen.MergeData(ref _tileData, _waterTiles);
            }
            else if (heightValue <= HeightGenerator.ShallowOcean)
            {
                NoiseGen.OceanWithLand(ref _tileData, WorldData.MyWorldData.HeightData, sectorX, sectorY,
                                       TileHelper.OceanWater);

                if (heightValue == HeightGenerator.ShallowOcean)
                {
                    NoiseGen.AddSand(ref _tileData, TileHelper.OceanWater, TileHelper.Grass, TileHelper.Sand, 2, 4, rand);
                    if (waterArea != null)
                        NoiseGen.GetRiverSquare(ref _waterTiles, waterArea, TileHelper.RiverWater, rand);

                    NoiseGen.MergeData(ref _tileData, _waterTiles, TileHelper.Sand);
                }
            }
            else
                System.Diagnostics.Debug.WriteLine("Something bad happened in Loaderbase");
            return _tileData;
        }
示例#2
0
        private byte[,] GameDecor(byte[,] tiledata, int sectorX, int sectorY, WorldData wd, byte[] probabilities,double[] probPercentages, Random rand)
        {
            var decorData = new byte[PlayScreen.SectorTileSize,PlayScreen.SectorTileSize];

            var decorSimplex = new byte[PlayScreen.SectorTileSize,PlayScreen.SectorTileSize];
            var heightValue = wd.HeightData[sectorX][sectorY];

            var treeProbValue = probabilities[0];

            var treeProbability = probPercentages[0];
            var rockProbability = probPercentages[1];

            if (heightValue < HeightGenerator.ShallowOcean)
                return decorData;

            NoiseGen.GetDecorSimplex(ref decorSimplex, new Vector2(sectorX, sectorY));

               // decorData[0, 0] = DecorHelper.Fire;

            for (var y = 0; y < PlayScreen.SectorTileSize; y++)
            {
                var incY = false;
                for (var x = 0; x < PlayScreen.SectorTileSize; x++)
                {
                    // decorData[x, y] = DecorKeys.Fire;
                    if (tiledata[x, y] != TileHelper.Grass && decorData[x, y] == DecorHelper.None)
                        continue;

                    if (decorSimplex[x, y] > treeProbValue && rand.NextDouble() < treeProbability)
                    {
                        decorData[x, y] = DecorHelper.Tree;
                    }
                    else if (decorSimplex[x, y] > treeProbValue - 10 && rand.NextDouble() < treeProbability / 2)
                    {
                        decorData[x, y] = DecorHelper.Bush;
                    }
                    else
                    if (rand.NextDouble() < treeProbability/6.0f)
                        decorData[x, y] = DecorHelper.Tree;
                    else if (rand.NextDouble() < rockProbability)
                        decorData[x, y] = DecorHelper.Rock;
                    //else if (Seeds.Randomizer.NextDouble() < _bushProbability)
                    //{
                    //    if (DecorKeys.DecorCollection != null && DecorKeys.DecorCollection.ContainsKey(_tempString) && DecorKeys.DecorCollection[_tempString].ContainsKey(DecorKeys.TypeBushString))
                    //    {
                    //        var array = DecorKeys.DecorCollection[_tempString][DecorKeys.TypeBushString];
                    //        var value = array[Seeds.Randomizer.Next(0, array.Length)];
                    //        DecorData[x, y] = value;
                    //    }
                    //}
                    //else if (Seeds.Randomizer.NextDouble() < _flowerProbability)
                    //{
                    //    if (DecorKeys.DecorCollection != null && DecorKeys.DecorCollection.ContainsKey(_tempString) && DecorKeys.DecorCollection[_tempString].ContainsKey(DecorKeys.TypeFlowerString))
                    //    {
                    //        var array = DecorKeys.DecorCollection[_tempString][DecorKeys.TypeFlowerString];
                    //        var value = array[Seeds.Randomizer.Next(0, array.Length)];
                    //        DecorData[x, y] = value;
                    //    }
                    //}
                    //else if (Seeds.Randomizer.NextDouble() < _extraProbability)
                    //{
                    //    if (DecorKeys.DecorCollection != null && DecorKeys.DecorCollection.ContainsKey(_tempString) && DecorKeys.DecorCollection[_tempString].ContainsKey(DecorKeys.TypeExtraString))
                    //    {
                    //        var array = DecorKeys.DecorCollection[_tempString][DecorKeys.TypeExtraString];
                    //        var value = array[Seeds.Randomizer.Next(0, array.Length)];
                    //        DecorData[x, y] = value;
                    //    }
                    //}
                }
                if (incY)
                    y++;
            }
            return decorData;
        }
示例#3
0
文件: Utility.cs 项目: Choochoo/Ship
 //public static void ClearArray(ref byte[][] output)
 //{
 //    for (var x = 0; x < output.Length; x++)
 //        for (var y = 0; y < output.Length; y++)
 //            output[x][y] = 0;
 //}
 //public static void ClearArray(ref ushort[][] output)
 //{
 //    for (var x = 0; x < output.Length; x++)
 //        for (var y = 0; y < output.Length; y++)
 //            output[x][y] = 0;
 //}
 //public static void ClearArray(ref byte[,] output)
 //{
 //    var size = output.GetLength(0);
 //    for (var x = 0; x < size; x++)
 //        for (var y = 0; y < size; y++)
 //            output[x,y] = 0;
 //}
 //public static bool SaveSettings(WorldData wd)
 //{
 //    // Open a storage container
 //    var device = MainGame.Game.StorageD;
 //    var result = device.BeginOpenContainer(SaveMapFolder, null, null);
 //    // Wait for the WaitHandle to become signaled.
 //    result.AsyncWaitHandle.WaitOne();
 //    var container = device.EndOpenContainer(result);
 //    // Check to see whether the save exists.
 //    if (container.FileExists(SaveMapName))
 //        // Delete it so that we can create one fresh.
 //        container.DeleteFile(SaveMapName);
 //    Stream stream = container.CreateFile(SaveMapName);
 //    // Convert the object to XML data and put it in the stream
 //    var serializer = new XmlSerializer(typeof (WorldData));
 //    serializer.Serialize(stream, wd);
 //    // Close the file
 //    stream.Close();
 //    // Dispose the container, to commit changes
 //    container.Dispose();
 //    result.AsyncWaitHandle.Close();
 //    return true;
 //}
 public static void SaveGameData(WorldData wd)
 {
     Stream stream = File.Open(SaveMapName, FileMode.Create);
     var binaryFormatter = new BinaryFormatter();
     binaryFormatter.Serialize(stream, wd);
     stream.Close();
 }
示例#4
0
 private static double GetHeightProbability(WorldData wd, int sectorX, int sectorY)
 {
     switch (wd.HeightData[sectorX][sectorY])
     {
         case HeightGenerator.Mountains:
             return MountainHigh;
         case HeightGenerator.Hills:
             return MountainMedium;
         default:
             return MountainLow;
     }
 }
示例#5
0
        public MiniTileManager()
        {
            _wd = WorldData.MyWorldData;
            _mainAtlas = PlayScreen.DecorationAtlas;
            _mainTextures = PlayScreen.DecorationTexture;
            _spriteBatch = PlayScreen.Spritebatch;
            //_mapMakerThread = new Thread(CheckMiniMap);

            _halfAmount = (int) (Math.Floor(Amount/2.0));
            _xOffset = PlayScreen.SpawnX - _halfAmount;
            _yOffset = PlayScreen.SpawnY - _halfAmount;
            _land = new MiniTileCollection[Amount,Amount];
            _landFeature = new MiniTileCollection[Amount,Amount];
            _fog = new MiniFogCollection[Amount,Amount];
            _landTextureLocations = new TextureProperties[MainGame.MapWidth][];
            _landFeatureTextureLocations = new TextureProperties[MainGame.MapWidth][];
            _graphicsDevice = MainGame.GraphicD;

            _miniMapFogTexture = new RenderTarget2D(MainGame.GraphicD, 256, 256, false, SurfaceFormat.Color,
                                                    DepthFormat.Depth24Stencil8,
                                                    0, RenderTargetUsage.DiscardContents);

            _miniMapTerrainTexture = new RenderTarget2D(MainGame.GraphicD, 256, 256, false, SurfaceFormat.Color,
                                                        DepthFormat.Depth24Stencil8,
                                                        0, RenderTargetUsage.DiscardContents);
            _miniMapTerrainTexture2 = new RenderTarget2D(MainGame.GraphicD, 256, 256, false, SurfaceFormat.Color,
                                                         DepthFormat.Depth24Stencil8,
                                                         0, RenderTargetUsage.DiscardContents);

            _miniMapFinalDrawTexture = new RenderTarget2D(MainGame.GraphicD, 256, 256, false, SurfaceFormat.Color,
                                                          DepthFormat.Depth24Stencil8,
                                                          0, RenderTargetUsage.DiscardContents);
            //testing

            _textureMask = CreateCircle(76);

            var m = Matrix.CreateOrthographicOffCenter(0, _miniMapFogTexture.Width, _miniMapFogTexture.Height, 0, 0,1);

            _a = new AlphaTestEffect(_graphicsDevice)
                {
                    Projection = m
                };

            _s1 = new DepthStencilState
                {
                    StencilEnable = true,
                    StencilFunction = CompareFunction.Always,
                    StencilPass = StencilOperation.Replace,
                    ReferenceStencil = 1,
                    DepthBufferEnable = false,
                };

            _s2 = new DepthStencilState
                {
                    StencilEnable = true,
                    StencilFunction = CompareFunction.LessEqual,
                    StencilPass = StencilOperation.Keep,
                    ReferenceStencil = 1,
                    DepthBufferEnable = false,
                };

            for (var x = 0; x < MainGame.MapWidth; x++)
            {
                _landTextureLocations[x] = new TextureProperties[MainGame.MapHeight];
                _landFeatureTextureLocations[x] = new TextureProperties[MainGame.MapHeight];
                for (var y = 0; y < MainGame.MapHeight; y++)
                {
                    var landtext = new TextureProperties();
                    var landfeaturetext = new TextureProperties();
                    FillHeight(ref landtext, x, y);

                    if (!CanFillTrees(ref landfeaturetext, x, y))
                    {
                        if (!CanFillGrass(ref landfeaturetext, x, y))
                        {
                            if (!CanFillMountains(ref landfeaturetext, x, y))
                                landfeaturetext.HasFeature = false;
                        }
                    }

                    _landTextureLocations[x][y] = landtext;
                    _landFeatureTextureLocations[x][y] = landfeaturetext;
                }
            }

            for (var i = 0; i < Amount; i++)
            {
                var left = i - 1 < 0 ? Amount - 1 : i - 1;
                var right = i + 1 >= Amount ? 0 : i + 1;
                for (var j = 0; j < Amount; j++)
                {
                    _fog[i, j] = new MiniFogCollection();

                    var top = j - 1 < 0 ? Amount - 1 : j - 1;
                    var bottom = j + 1 >= Amount ? 0 : j + 1;
                    _land[i, j] = new MiniTileCollection(i + _xOffset, j + _yOffset, i, j, top, bottom, left, right);
                    _landFeature[i, j] = new MiniTileCollection(i + _xOffset, j + _yOffset, i, j, top, bottom, left,
                                                                right);

                    if (i == 0 && j == 0)
                        _topLeft = _land[i, j];
                    else if (i == Amount - 1 && j == Amount - 1)
                        _bottomRight = _land[i, j];

                    var prop = _landTextureLocations[_land[i, j].MapLocX][_land[i, j].MapLocY];
                    SetBounds(prop.TextureName, ref _land[i, j], prop.Vals, false);
                    _land[i, j].Visible = true;

                    var prop2 = _landFeatureTextureLocations[_landFeature[i, j].MapLocX][_landFeature[i, j].MapLocY];
                    if (prop2.HasFeature)
                    {
                        SetBounds(prop2.TextureName, ref _landFeature[i, j], prop2.Vals, prop2.IsMountain);
                        _landFeature[i, j].Visible = true;
                    }
                    else
                        _landFeature[i, j].Visible = false;

                    _fog[i, j].SetSpots(i, j);
                    FillFog(i, j);
                }
            }
            InitialDraw();
        }