コード例 #1
0
 //--------------------------------------------------------------
 //GENERATE BLACKHOLE SYSTEM
 //--------------------------------------------------------------
 private void GenerateBlackHoleSystem(BlackHoleOnMap hole)
 {
     //Construct black hole name
     string tempName = ConstructName();
     hole.Name = tempName;
     //End name construction
     //Generationg BlackHole System
     //Generating black hole
     BlackHole bh = new BlackHole(Content.Load<Texture2D>("BlackHoles/"+
         blackHolesTextures[new Random().Next(0, blackHolesTextures.Length)]), CenterPoint,
         new Vector2(Scales.TwoTenth));
     bh.Name = tempName;
     //End generating black hole
     BlackHoleSystem bhs = new BlackHoleSystem(bh);
     bhs.BackGround = CreateBackground("SystemBacks/" +
         systemBackTextures[new Random().Next(0, systemBackTextures.Length)], Scales.None, 255f);
     //End generating
     GeneratingAsteroids(bhs);
     hole.System = bhs;
 }
コード例 #2
0
        private void WorldGenerator()
        {
            //Generating a system stars.
            Texture2D circle = Content.Load<Texture2D>("LittleStars/CurrentPlayerCircle");
            r = new Random();
            r2 = new Random();
            int objectsCount = r.Next(150, 300);
            int holesCount = r.Next(5, 15);
            int holes = 0;
            double pixelsTemp = 4000 / objectsCount;
            //Calculating pixels between two stars.
            int pixels = 0;
            map = new Map();
            Texture2D texture;
            //int temp = 1;
            for (int i = 0; i < objectsCount; i++)
            {
                //BlackHole or Star
                bool isBlackHole = false;
                if (holesCount > holes)
                {
                    isBlackHole = new Random().Next(0, 2) == 1 ? true : false;
                }
                if (isBlackHole)
                {
                    texture = Content.Load<Texture2D>("BlackHoles/OnMap/" +
                        blackHolesOnMapTextures[r2.Next(0, blackHolesOnMapTextures.Length)]);
                }
                else
                {
                    texture = Content.Load<Texture2D>("LittleStars/SystemStars/" +
                        systemStarsTextures[r2.Next(0, systemStarsTextures.Length)]);
                }
               //Checking for range between stars.
               //First version of algorithm, where stars adding only if have place to it.
               bool isNear = true;
               float starX = 0;
               float starY = 0;
               if (map.Objects.Count == 0)
               {
                   starX = r.Next(0, 4000);
                   starY = r.Next(0, 4000);
               }
               else
               {
                   while (isNear)
                   {
                       starX = r.Next(0, 4000);
                       starY = r.Next(0, 4000);
                       isNear = false;
                       foreach (IDraw star in map.Objects)
                       {
                           if (Math.Abs(((IMoveble)star).X - starX) < pixels ||
                               Math.Abs(((IMoveble)star).Y - starY) < pixels)
                           {
                               isNear = true;
                               break;
                           }
                       }
                   }
               }
               //Adding stars
               if (isBlackHole)
               {
                   BlackHoleOnMap tempHole = new BlackHoleOnMap(texture, new Vector2(starX, starY), new Vector2(Scales.FourTenth));
                   GenerateBlackHoleSystem(tempHole);
                   map.Objects.Add(tempHole);
                   if (pixels == 0)
                   {
                       pixels = (int)tempHole.Width / 2;
                   }
                   holes++;
               }
               else
               {
                   StarOnMap tempStar = new StarOnMap(texture, new Vector2(starX, starY), new Vector2(Scales.FourTenth));
                   tempStar.Circle = circle;
                   tempStar.Owner = "Unknown";
                   GenerateSolarSystem(tempStar);
                   map.Objects.Add(tempStar);
                   if (pixels == 0)
                   {
                       pixels = (int)tempStar.Width / 2;
                   }
               }
               ((ProgressBar)screens["Gen"].Objects["ProgressBar"]).PWidth
                   = (int)((float)i / objectsCount * ((ProgressBar)screens["Gen"].Objects["ProgressBar"]).TextureWidth);
               ((GameString)screens["Gen"].Objects["String"]).Str = "Generating stars... " + i.ToString() + "/" + objectsCount;
            }

            GalaxyMap(map);
            currentScreen = "GalaxyMap";
            LoadEvents("GalaxyMap");
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }