private void GalaxyMapOpen(Map galaxyMap)
        {
            LoadEvents("GalaxyMap");
            currentScreen = "GalaxyMap";

            /*foreach (IDraw obj in galaxyMap.Objects)
            {
                if (obj is StarOnMap)
                {
                    if (obj.ToStarOnMap().Owner == currentPlayer)
                    {
                        obj.ToStarOnMap().IsOwnByThisPlayer = true;
                    }
                    else
                    {
                        obj.ToStarOnMap().IsOwnByThisPlayer = false;
                    }
                }
            }*/
        }
Пример #2
0
        private void GalaxyMapControls(Screen galaxyMap, Map map)
        {
            KeyboardState state = Keyboard.GetState();
            if ((state.IsKeyDown(Keys.Right) || state.IsKeyDown(Keys.D))
                && Math.Abs(((BackGround)galaxyMap.Objects["Back"]).X)
                < ((BackGround)galaxyMap.Objects["Back"]).Width - graphics.PreferredBackBufferWidth)
            {
                ((IMoveble)galaxyMap.Objects["Back"]).X -= MOVEMENT;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).X -= MOVEMENT;
                }
            }
            if ((state.IsKeyDown(Keys.Left) || state.IsKeyDown(Keys.A))
                && ((BackGround)galaxyMap.Objects["Back"]).X < 0)
            {
                ((IMoveble)galaxyMap.Objects["Back"]).X += MOVEMENT;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).X += MOVEMENT;
                }
            }
            if ((state.IsKeyDown(Keys.Up) || state.IsKeyDown(Keys.W))
                && ((BackGround)galaxyMap.Objects["Back"]).Y < 0)
            {
                ((IMoveble)galaxyMap.Objects["Back"]).Y += MOVEMENT;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).Y += MOVEMENT;
                }
            }
            if ((state.IsKeyDown(Keys.Down) || state.IsKeyDown(Keys.S))
                && Math.Abs(((BackGround)galaxyMap.Objects["Back"]).Y)
                < ((BackGround)galaxyMap.Objects["Back"]).Height - graphics.PreferredBackBufferHeight)
            {
                ((IMoveble)galaxyMap.Objects["Back"]).Y -= MOVEMENT;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).Y -= MOVEMENT;
                }
            }
            //Scale
            MouseState ms  = Mouse.GetState();
            if (ms.ScrollWheelValue > originalMs.ScrollWheelValue)
            {
                ((IScaleble)galaxyMap.Objects["Back"]).Scale = ((IScaleble)galaxyMap.Objects["Back"]).Scale / new Vector2(0.9f, 0.9f);
                ((IMoveble)galaxyMap.Objects["Back"]).Position = new Vector2(((IMoveble)galaxyMap.Objects["Back"]).Position.X * 1 / 0.9f,
                                    ((IMoveble)galaxyMap.Objects["Back"]).Position.Y * 1 / 0.9f);
                if (((BackGround)galaxyMap.Objects["Back"]).Width < 4000)
                {
                    map.Bigger(0.9f, stepX, stepY);
                }
                else
                {
                    ((IScaleble)galaxyMap.Objects["Back"]).Scale = ((IScaleble)galaxyMap.Objects["Back"]).Scale * new Vector2(0.9f, 0.9f);
                    ((IMoveble)galaxyMap.Objects["Back"]).Position = GalaxyShift(((IMoveble)galaxyMap.Objects["Back"]).Position, new Vector2(0.9f, 0.9f));
                }
                originalMs = ms;
            }
            if (ms.ScrollWheelValue < originalMs.ScrollWheelValue)
            {
                ((IScaleble)galaxyMap.Objects["Back"]).Scale = ((IScaleble)galaxyMap.Objects["Back"]).Scale * new Vector2(0.9f, 0.9f);
                ((IMoveble)galaxyMap.Objects["Back"]).Position = GalaxyShift(((IMoveble)galaxyMap.Objects["Back"]).Position, new Vector2(0.9f, 0.9f));
                if (((BackGround)galaxyMap.Objects["Back"]).Width > graphics.PreferredBackBufferWidth)
                {
                    map.Smaller(0.9f, stepX, stepY);
                }
                else
                {
                    ((IScaleble)galaxyMap.Objects["Back"]).Scale = ((IScaleble)galaxyMap.Objects["Back"]).Scale / new Vector2(0.9f, 0.9f);
                    ((IMoveble)galaxyMap.Objects["Back"]).Position = new Vector2(((IMoveble)galaxyMap.Objects["Back"]).Position.X * 1 / 0.9f,
                       ((IMoveble)galaxyMap.Objects["Back"]).Position.Y * 1 / 0.9f);
                }
                originalMs = ms;
            }

            if (Math.Abs(((BackGround)galaxyMap.Objects["Back"]).X)
                > ((BackGround)galaxyMap.Objects["Back"]).Width - graphics.PreferredBackBufferWidth)
            {
                float temp = Math.Abs(((BackGround)galaxyMap.Objects["Back"]).X) - (((BackGround)galaxyMap.Objects["Back"]).Width - graphics.PreferredBackBufferWidth);
                ((IMoveble)galaxyMap.Objects["Back"]).X += temp;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).X += temp;
                }
            }
            if (((BackGround)galaxyMap.Objects["Back"]).X > 0)
            {
                float temp = ((BackGround)galaxyMap.Objects["Back"]).X;
                ((IMoveble)galaxyMap.Objects["Back"]).X -= temp;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).X -= temp;
                }
            }
            if (((BackGround)galaxyMap.Objects["Back"]).Y > 0)
            {
                float temp = ((BackGround)galaxyMap.Objects["Back"]).Y;
                ((IMoveble)galaxyMap.Objects["Back"]).Y -= temp;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).Y -= temp;
                }
            }
            if (Math.Abs(((BackGround)galaxyMap.Objects["Back"]).Y)
                > ((BackGround)galaxyMap.Objects["Back"]).Height - graphics.PreferredBackBufferHeight)
            {
                float temp = Math.Abs(((BackGround)galaxyMap.Objects["Back"]).Y) - (((BackGround)galaxyMap.Objects["Back"]).Height - graphics.PreferredBackBufferHeight);
                ((IMoveble)galaxyMap.Objects["Back"]).Y += temp;
                foreach (IDraw obj in map.Objects)
                {
                    ((IMoveble)obj).Y += temp;
                }
            }
            //End scale
            if (state.IsKeyDown(Keys.Escape) && !isEscDown)
            {
                isEscDown = true;
                EscEvents(galaxyMap);
            }
            if (state.IsKeyUp(Keys.Escape))
            {
                isEscDown = false;
            }
        }
Пример #3
0
        //------------------------------------------------------------
        //GALAXY MAP CREATE
        //------------------------------------------------------------
        private void GalaxyMap(Map map)
        {
            Screen galaxyMap = new Screen();
            BackGround spaceBack = CreateBackground("Textures/GlobalBack", Scales.None, 255f, false);
            galaxyMap.Objects.Add("Back", spaceBack);
            galaxyMap.Objects.Add("Map", map);
            //info popup
            BackGround infoPopupBack = CreateBackground("UI/SoftPopup", Scales.Quarter, 255f);
            Popup infoPopup = CreatePopup(infoPopupBack, Scales.None, 600f, 500f, false, false);
            GameString infoString = CreateGameString("SpriteFont1", "What are you doing?", 30f, 20f, Color.Azure);
            infoPopup.Objects.Add("InfoPopupBack", infoPopupBack);
            infoPopup.Objects.Add("InfoString", infoString);
            galaxyMap.Objects.Add("InfoPopup", infoPopup);
            //end info popup
            galaxyMap.Objects.Add("EscPopup", CreateEscMenu());
            CreateHUD(galaxyMap);

            CreateDebugInfoWindow(galaxyMap);

            screens.Add("GalaxyMap", galaxyMap);
        }
        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();
        }