예제 #1
0
        public bool Intersects(PictureRect other)
        {
            Rect thisRect  = new Rect(new System.Windows.Point(this.X, this.Y), new System.Windows.Size(this.Width, this.Height));
            Rect otherRect = new Rect(new System.Windows.Point(other.X, other.Y), new System.Windows.Size(other.Width, other.Height));

            return(thisRect.IntersectsWith(otherRect));
        }
        private void GenerateStarShips()
        {
            this.Ships.Clear();

            int numberOfShips = StellarCartographyModel.Random.Next(2, 4);
            int x, y;

            for (int i = 0; i < numberOfShips; i++)
            {
                int index = this.GetUnusedIndex(this.ships.Count, this.lastStarShipIndices, numberOfShips);

                PictureRect ship = this.ships[index];

                do
                {
                    x = StellarCartographyModel.Random.Next(this.GAME_FIELD_COLUMNS);
                    y = StellarCartographyModel.Random.Next(this.GAME_FIELD_ROWS);

                    ship.X = x * this.xRatio;
                    ship.Y = y * this.yRatio;
                } while (this.Planets.Any(p => p.Intersects(ship)) ||
                         this.Ships.Any(s => s.Intersects(ship)) ||
                         this.Star.Intersects(ship) ||
                         this.Stargate.Intersects(ship));

                ship.RandomRotate();
                ship.CalculateOffset(this.xRatio, this.yRatio);
                this.Ships.Add(ship);
            }
        }
        private void LoadResources()
        {
            this.stars       = new List <PictureRect>();
            this.planets     = new List <PictureRect>();
            this.backgrounds = new List <PictureRect>();
            this.asteroids   = new List <PictureRect>();
            this.ships       = new List <PictureRect>();

            Double maxDimension = xRatio > yRatio ? xRatio : yRatio;

            ResourceSet resourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            foreach (DictionaryEntry entry in resourceSet)
            {
                if (entry.Key.ToString().Contains("planet"))
                {
                    this.planets.Add(new PictureRect(0, 0, new Bitmap(entry.Value as Bitmap,
                                                                      this.ResizeKeepAspect((entry.Value as Bitmap).Size,
                                                                                            (int)(maxDimension * .5d),
                                                                                            (int)(maxDimension * .5d)))));
                }
                else if (entry.Key.ToString().Contains("background"))
                {
                    this.backgrounds.Add(new PictureRect(0, 0, entry.Value as Bitmap));
                }
                else if (entry.Key.ToString().Contains("sun"))
                {
                    double ratio = StellarCartographyModel.Random.NextDouble() * (1 - 0.8) + 0.8;

                    this.stars.Add(new PictureRect(0, 0, new Bitmap(entry.Value as Bitmap,
                                                                    this.ResizeKeepAspect((entry.Value as Bitmap).Size,
                                                                                          (int)(maxDimension * ratio),
                                                                                          (int)(maxDimension * ratio)))));
                }
                else if (entry.Key.ToString().Contains("asteroid"))
                {
                    this.asteroids.Add(new PictureRect(0, 0, new Bitmap(entry.Value as Bitmap,
                                                                        this.ResizeKeepAspect((entry.Value as Bitmap).Size,
                                                                                              (int)(maxDimension * .7d),
                                                                                              (int)(maxDimension * .7d)))));
                }
                else if (entry.Key.ToString().Contains("stargate_ring"))
                {
                    this.Stargate = new PictureRect(0, 0, new Bitmap(entry.Value as Bitmap,
                                                                     this.ResizeKeepAspect((entry.Value as Bitmap).Size,
                                                                                           (int)(maxDimension * .4d),
                                                                                           (int)(maxDimension * .4d))));
                }
                else if (entry.Key.ToString().Contains("star_ship"))
                {
                    this.ships.Add(new PictureRect(0, 0, new Bitmap(entry.Value as Bitmap,
                                                                    this.ResizeKeepAspect((entry.Value as Bitmap).Size,
                                                                                          (int)(maxDimension * .7d),
                                                                                          (int)(maxDimension * .7d)))));
                }
            }

            this.SplashImage    = new PictureRect(0, 0, Properties.Resources.splash);
            this.CRTEffectImage = new PictureRect(0, 0, Properties.Resources.crt_effect);
        }
        private void GenerateAsteroids()
        {
            int sideBlocked = StellarCartographyModel.Random.Next(4); // 0: NORTH 1: EAST 2: SOUTH 3: WEST

            int x = 0, y = 0;

            for (int j = 0; j < 4; j++)
            {
                int numberOfRoids = j % 2 == 0 ? this.GAME_FIELD_ROWS / 2 : this.GAME_FIELD_COLUMNS / 2;
                int removeIndex   = j == sideBlocked ? -1 : StellarCartographyModel.Random.Next(numberOfRoids);

                for (int i = 0; i < numberOfRoids; i++)
                {
                    switch (j)
                    {
                    case 0:
                        x = this.GAME_FIELD_COLUMNS / 2;
                        y = 0;
                        break;

                    case 1:
                        x = this.GAME_FIELD_COLUMNS / 2 + 1;
                        y = this.GAME_FIELD_ROWS / 2;
                        break;

                    case 2:
                        x = this.GAME_FIELD_COLUMNS / 2;
                        y = this.GAME_FIELD_ROWS / 2 + 1;
                        break;

                    case 3:
                        x = 0;
                        y = this.GAME_FIELD_ROWS / 2;
                        break;
                    }

                    x = j % 2 == 0 ? x : x + i;
                    y = j % 2 == 0 ? y + i : y;

                    PictureRect newRoid = asteroids[1].Clone();
                    newRoid.X = x * this.xRatio;
                    newRoid.Y = y * this.yRatio;

                    if (j % 2 == 0)
                    {
                        newRoid.Rotate();
                    }

                    newRoid.CalculateOffset(this.xRatio, this.yRatio);

                    if (!newRoid.Intersects(this.Star) && i != removeIndex)
                    {
                        this.Planets.Add(newRoid);
                    }
                }
            }
        }
        private void GenerateStar()
        {
            int randomLocation = StellarCartographyModel.Random.Next(3);

            int x = this.GAME_FIELD_COLUMNS / 2;
            int y = this.GAME_FIELD_ROWS / 2 - 1 + randomLocation;

            int index = this.GetUnusedIndex(this.stars.Count, this.lastStarIndices, 2);

            PictureRect selectedStar = this.stars[index];

            selectedStar.X = x * this.xRatio;
            selectedStar.Y = y * this.yRatio;
            selectedStar.CalculateOffset(this.xRatio, this.yRatio);

            this.Star = selectedStar;
        }
        private void GeneratePlanets()
        {
            this.Planets.Clear();

            int x, y;

            for (int i = 0; i < 4; i++)
            {
                x = StellarCartographyModel.Random.Next(this.GAME_FIELD_COLUMNS / 2 - 1);
                y = StellarCartographyModel.Random.Next(this.GAME_FIELD_ROWS / 2 - 1);

                int index = this.GetUnusedIndex(this.planets.Count, this.lastPlanetIndices, 10);

                PictureRect selectedPlanet = this.planets[index];
                selectedPlanet.X = i == 1 || i == 3 ? x + this.GAME_FIELD_COLUMNS / 2 + 1 : x;
                selectedPlanet.Y = i == 2 || i == 3 ? y + this.GAME_FIELD_ROWS / 2 + 1 : y;

                selectedPlanet.X *= this.xRatio;
                selectedPlanet.Y *= this.yRatio;
                selectedPlanet.CalculateOffset(this.xRatio, this.yRatio);

                this.Planets.Add(selectedPlanet);
            }
        }